]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
ws cleanup
[lyx.git] / src / mathed / math_deliminset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_deliminset.h"
8 #include "math_parser.h"
9 #include "math_support.h"
10 #include "math_mathmlstream.h"
11 #include "math_streamstr.h"
12 #include "math_extern.h"
13
14
15 using std::max;
16
17
18 MathDelimInset::MathDelimInset(string const & l, string const & r)
19         : MathNestInset(1), left_(l), right_(r)
20 {}
21
22
23 MathInset * MathDelimInset::clone() const
24 {
25         return new MathDelimInset(*this);
26 }
27
28
29 void MathDelimInset::write(WriteStream & os) const
30 {
31         os << "\\left" << convertDelimToLatexName(left_) << cell(0)
32            << "\\right" << convertDelimToLatexName(right_);
33 }
34
35
36 void MathDelimInset::normalize(NormalStream & os) const
37 {
38         os << "[delim " << convertDelimToLatexName(left_) << ' '
39            << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
40 }
41
42
43 int MathDelimInset::dw() const
44 {
45         int w = height() / 5;
46         if (w > 8)
47                 w = 8;
48         if (w < 4)
49                 w = 4;
50         return w;
51 }
52
53
54 void MathDelimInset::metrics(MathMetricsInfo const & mi) const
55 {
56         xcell(0).metrics(mi);
57         int a, d, w;
58         LyXFont font;
59         whichFont(font, LM_TC_VAR, mi);
60         mathed_char_dim(font, 'I', a, d, w);
61         int h0   = (a + d) / 2;
62         int a0   = max(xcell(0).ascent(), a)   - h0;
63         int d0   = max(xcell(0).descent(), d)  + h0;
64         ascent_  = max(a0, d0) + h0;
65         descent_ = max(a0, d0) - h0;
66         width_   = xcell(0).width() + 2 * dw() + 8;
67 }
68
69
70 void MathDelimInset::draw(Painter & pain, int x, int y) const
71 {
72         int const w = dw();
73         int const b = y - ascent_;
74         xcell(0).draw(pain, x + w + 4, y);
75         mathed_draw_deco(pain, x + 4, b, w, height(), left_);
76         mathed_draw_deco(pain, x + width() - w - 4, b, w, height(), right_);
77 }
78
79
80 bool MathDelimInset::isParanthesis() const
81 {
82         return left_ == "(" && right_ == ")";
83 }
84
85
86 bool MathDelimInset::isBrackets() const
87 {
88         return left_ == "[" && right_ == "]";
89 }
90
91
92 bool MathDelimInset::isAbs() const
93 {
94         return left_ == "|" && right_ == "|";
95 }
96
97
98 void MathDelimInset::maplize(MapleStream & os) const
99 {
100         if (isAbs()) {
101                 bool mat =
102                         cell(0).size() == 1 && cell(0).begin()->nucleus()
103                                         && cell(0).begin()->nucleus()->asMatrixInset();
104                 if (mat)
105                         os << "linalg[det](" << cell(0) << ")";
106                 else
107                         os << "abs(" << cell(0) << ")";
108         }
109         else
110                 os << left_ << cell(0) << right_;
111 }
112
113
114 void MathDelimInset::mathmlize(MathMLStream & os) const
115 {
116         os << "<fenced open=\"" << left_ << "\" close=\""
117                 << right_ << "\">" << cell(0) << "</fenced>";
118 }
119
120
121 void MathDelimInset::octavize(OctaveStream & os) const
122 {
123         if (isAbs())
124                 os << "det(" << cell(0) << ")";
125         else
126                 os << left_ << cell(0) << right_;
127 }