]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
IU of drawing phase one without 'semantic changes' as requested by John
[lyx.git] / src / mathed / math_deliminset.C
1 #include <config.h>
2
3 #include "math_deliminset.h"
4 #include "math_parser.h"
5 #include "math_support.h"
6 #include "math_mathmlstream.h"
7 #include "math_streamstr.h"
8 #include "math_extern.h"
9
10
11 using std::max;
12
13 namespace {
14
15 string convertDelimToLatexName(string const & name)
16 {
17         if (name == "<")
18                 return name;
19         if (name == "(")
20                 return name;
21         if (name == "[")
22                 return name;
23         if (name == ".")
24                 return name;
25         if (name == ">")
26                 return name;
27         if (name == ")")
28                 return name;
29         if (name == "]")
30                 return name;
31         if (name == "/")
32                 return name;
33         if (name == "|")
34                 return name;
35         return '\\' + name + ' ';
36 }
37
38 }
39
40
41
42 MathDelimInset::MathDelimInset(string const & l, string const & r)
43         : MathNestInset(1), left_(l), right_(r)
44 {}
45
46
47 MathDelimInset::MathDelimInset
48                 (string const & l, string const & r, MathArray const & ar)
49         : MathNestInset(1), left_(l), right_(r)
50 {
51         cell(0) = ar;
52 }
53
54
55 MathInset * MathDelimInset::clone() const
56 {
57         return new MathDelimInset(*this);
58 }
59
60
61 void MathDelimInset::write(WriteStream & os) const
62 {
63         os << "\\left" << convertDelimToLatexName(left_) << cell(0)
64            << "\\right" << convertDelimToLatexName(right_);
65 }
66
67
68 void MathDelimInset::normalize(NormalStream & os) const
69 {
70         os << "[delim " << convertDelimToLatexName(left_) << ' '
71            << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
72 }
73
74
75 void MathDelimInset::metrics(MetricsInfo & mi, Dimension & dim) const
76 {
77         cell(0).metrics(mi);
78         Dimension t;
79         mathed_char_dim(mi.base.font, 'I', t);
80         int h0 = (t.asc + t.des) / 2;
81         int a0 = max(cell(0).ascent(), t.asc)   - h0;
82         int d0 = max(cell(0).descent(), t.des)  + h0;
83         dw_ = cell(0).height() / 5;
84         if (dw_ > 8)
85                 dw_ = 8;
86         if (dw_ < 4)
87                 dw_ = 4;
88         dim_.wid = cell(0).width() + 2 * dw_ + 8;
89         dim_.asc = max(a0, d0) + h0;
90         dim_.des = max(a0, d0) - h0;
91         dim = dim_;
92 }
93
94
95 void MathDelimInset::draw(PainterInfo & pi, int x, int y) const
96 {
97         int const b = y - dim_.asc;
98         cell(0).draw(pi, x + dw_ + 4, y);
99         mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
100         mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
101                 b, dw_, dim_.height(), right_);
102 }
103
104
105 bool MathDelimInset::isParanthesis() const
106 {
107         return left_ == "(" && right_ == ")";
108 }
109
110
111 bool MathDelimInset::isBrackets() const
112 {
113         return left_ == "[" && right_ == "]";
114 }
115
116
117 bool MathDelimInset::isAbs() const
118 {
119         return left_ == "|" && right_ == "|";
120 }
121
122
123 void MathDelimInset::maple(MapleStream & os) const
124 {
125         if (isAbs()) {
126                 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
127                         os << "linalg[det](" << cell(0) << ')';
128                 else
129                         os << "abs(" << cell(0) << ')';
130         }
131         else
132                 os << left_ << cell(0) << right_;
133 }
134
135 void MathDelimInset::maxima(MaximaStream & os) const
136 {
137         if (isAbs()) {
138                 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
139                         os << "determinant(" << cell(0) << ')';
140                 else
141                         os << "abs(" << cell(0) << ')';
142         }
143         else
144                 os << left_ << cell(0) << right_;
145 }
146
147
148 void MathDelimInset::mathematica(MathematicaStream & os) const
149 {
150         if (isAbs()) {
151                 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
152                         os << "Det" << cell(0) << ']';
153                 else
154                         os << "Abs[" << cell(0) << ']';
155         }
156         else
157                 os << left_ << cell(0) << right_;
158 }
159
160
161 void MathDelimInset::mathmlize(MathMLStream & os) const
162 {
163         os << "<fenced open=\"" << left_ << "\" close=\""
164                 << right_ << "\">" << cell(0) << "</fenced>";
165 }
166
167
168 void MathDelimInset::octave(OctaveStream & os) const
169 {
170         if (isAbs())
171                 os << "det(" << cell(0) << ')';
172         else
173                 os << left_ << cell(0) << right_;
174 }