]> git.lyx.org Git - lyx.git/blob - src/mathed/math_arrayinset.C
whichFont down to 5.3%
[lyx.git] / src / mathed / math_arrayinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_arrayinset.h"
8 #include "math_parser.h"
9 #include "math_mathmlstream.h"
10 #include "math_streamstr.h"
11 #include "Lsstream.h"
12
13 #include <iterator>
14
15 using std::vector;
16 using std::istringstream;
17 using std::getline;
18
19
20 MathArrayInset::MathArrayInset(string const & name, int m, int n)
21         : MathGridInset(m, n), name_(name)
22 {}
23
24
25 MathArrayInset::MathArrayInset(string const & name, int m, int n,
26                 char valign, string const & halign)
27         : MathGridInset(m, n, valign, halign), name_(name)
28 {}
29
30
31 MathArrayInset::MathArrayInset(string const & name, char valign,
32                 string const & halign)
33         : MathGridInset(valign, halign), name_(name)
34 {}
35
36
37 MathArrayInset::MathArrayInset(string const & name, string const & str)
38         : MathGridInset(1, 1), name_(name)
39 {
40         vector< vector<string> > dat;
41         istringstream is(str.c_str());
42         while (is) {
43                 string line;
44                 getline(is, line);
45                 istringstream ls(line.c_str());
46                 typedef std::istream_iterator<string> iter;
47                 vector<string> v = vector<string>(iter(ls), iter());
48                 if (v.size())
49                         dat.push_back(v);
50         }
51
52         for (row_type row = 1; row < dat.size(); ++row)
53                 addRow(0);
54         for (col_type col = 1; col < dat[0].size(); ++col)
55                 addCol(0);
56         for (row_type row = 0; row < dat.size(); ++row)
57                 for (col_type col = 0; col < dat[row].size(); ++col)
58                         mathed_parse_cell(cell(index(row, col)), dat[row][col]);
59 }
60
61
62 MathInset * MathArrayInset::clone() const
63 {
64         return new MathArrayInset(*this);
65 }
66
67
68 void MathArrayInset::metrics(MathMetricsInfo const & st) const
69 {
70         MathMetricsInfo mi = st;
71         if (mi.style == LM_ST_DISPLAY)
72                 mi.style = LM_ST_TEXT;
73         MathGridInset::metrics(mi);
74 }
75
76
77 void MathArrayInset::write(WriteStream & os) const
78 {
79         if (os.fragile())
80                 os << "\\protect";
81         os << "\\begin{" << name_ << "}";
82
83         if (v_align_ == 't' || v_align_ == 'b') 
84                 os << '[' << char(v_align_) << ']';
85         os << '{' << halign() << "}\n";
86
87         MathGridInset::write(os);
88
89         if (os.fragile())
90                 os << "\\protect";
91         os << "\\end{" << name_ << "}\n";
92 }
93
94
95 void MathArrayInset::normalize(NormalStream & os) const
96 {
97         os << "[" << name_ << " ";
98         MathGridInset::normalize(os);
99         os << "]";
100 }
101
102
103 void MathArrayInset::maplize(MapleStream & os) const
104 {
105         os << "array(";
106         MathGridInset::maplize(os);
107         os << ")";
108 }