]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
disable some of the speedup thingies until I found aproper solution for the
[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         mathed_char_dim(LM_TC_VAR, mi, 'I', a, d, w);
59         int h0   = (a + d) / 2;
60         int a0   = max(xcell(0).ascent(), a)   - h0;
61         int d0   = max(xcell(0).descent(), d)  + h0;
62         ascent_  = max(a0, d0) + h0;
63         descent_ = max(a0, d0) - h0;
64         width_   = xcell(0).width() + 2 * dw() + 8;
65 }
66
67
68 void MathDelimInset::draw(Painter & pain, int x, int y) const
69
70         int const w = dw();
71         int const b = y - ascent_;
72         xcell(0).draw(pain, x + w + 4, y);
73         mathed_draw_deco(pain, x + 4, b, w, height(), left_);
74         mathed_draw_deco(pain, x + width() - w - 4, b, w, height(), right_);
75 }
76
77
78 bool MathDelimInset::isParanthesis() const
79 {
80         return left_ == "(" && right_ == ")";
81 }
82
83
84 bool MathDelimInset::isBrackets() const
85 {
86         return left_ == "[" && right_ == "]";
87 }
88
89
90 bool MathDelimInset::isAbs() const
91 {
92         return left_ == "|" && right_ == "|";
93 }
94
95
96 void MathDelimInset::maplize(MapleStream & os) const
97 {
98         if (isAbs()) {
99                 bool mat =
100                         cell(0).size() == 1 && cell(0).begin()->nucleus()
101                                         && cell(0).begin()->nucleus()->asMatrixInset();
102                 if (mat)        
103                         os << "linalg[det](" << cell(0) << ")";
104                 else
105                         os << "abs(" << cell(0) << ")";
106         }
107         else
108                 os << left_ << cell(0) << right_;
109 }
110
111
112 void MathDelimInset::mathmlize(MathMLStream & os) const
113 {
114         os << "<fenced open=\"" << left_ << "\" close=\""
115                 << right_ << "\">" << cell(0) << "</fenced>";
116 }
117
118
119 void MathDelimInset::octavize(OctaveStream & os) const
120 {
121         if (isAbs())
122                 os << "det(" << cell(0) << ")";
123         else
124                 os << left_ << cell(0) << right_;
125 }