7 #include "math_arrayinset.h"
8 #include "math_parser.h"
9 #include "math_mathmlstream.h"
10 #include "math_metricsinfo.h"
11 #include "math_streamstr.h"
17 using std::istringstream;
19 using std::istream_iterator;
22 MathArrayInset::MathArrayInset(string const & name, int m, int n)
23 : MathGridInset(m, n), name_(name)
27 MathArrayInset::MathArrayInset(string const & name, int m, int n,
28 char valign, string const & halign)
29 : MathGridInset(m, n, valign, halign), name_(name)
33 MathArrayInset::MathArrayInset(string const & name, char valign,
34 string const & halign)
35 : MathGridInset(valign, halign), name_(name)
39 MathArrayInset::MathArrayInset(string const & name, string const & str)
40 : MathGridInset(1, 1), name_(name)
42 vector< vector<string> > dat;
43 istringstream is(str.c_str());
45 while (getline(is, line)) {
46 istringstream ls(line.c_str());
47 typedef istream_iterator<string> iter;
48 vector<string> v = vector<string>(iter(ls), iter());
53 for (row_type row = 1; row < dat.size(); ++row)
55 for (col_type col = 1; col < dat[0].size(); ++col)
57 for (row_type row = 0; row < dat.size(); ++row)
58 for (col_type col = 0; col < dat[0].size(); ++col)
59 mathed_parse_cell(cell(index(row, col)), dat[row][col]);
63 MathInset * MathArrayInset::clone() const
65 return new MathArrayInset(*this);
69 void MathArrayInset::metrics(MathMetricsInfo & mi) const
71 MathArrayChanger dummy(mi.base);
72 MathGridInset::metrics(mi);
76 void MathArrayInset::draw(MathPainterInfo & pi, int x, int y) const
78 MathArrayChanger dummy(pi.base);
79 MathGridInset::draw(pi, x, y);
83 void MathArrayInset::write(WriteStream & os) const
87 os << "\\begin{" << name_ << "}";
89 if (v_align_ == 't' || v_align_ == 'b')
90 os << '[' << char(v_align_) << ']';
91 os << '{' << halign() << "}\n";
93 MathGridInset::write(os);
97 os << "\\end{" << name_ << "}";
98 // adding a \n here is bad if the array is the last item
103 void MathArrayInset::normalize(NormalStream & os) const
105 os << "[" << name_ << " ";
106 MathGridInset::normalize(os);
111 void MathArrayInset::maplize(MapleStream & os) const
114 MathGridInset::maplize(os);