]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
fix drawing glitch
[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_extern.h"
12
13
14 MathDelimInset::MathDelimInset(string const & l, string const & r)
15         : MathNestInset(1), left_(l), right_(r)
16 {}
17
18
19 MathInset * MathDelimInset::clone() const
20 {   
21         return new MathDelimInset(*this);
22 }
23
24
25 string MathDelimInset::latexName(string const & name)
26 {
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         if (name == "]")
36                 return name;
37         if (name == "/")
38                 return name;
39         if (name == "|")
40                 return name;
41         return "\\" + name + " ";
42 }
43
44
45 void MathDelimInset::write(WriteStream & os) const
46 {
47         os << "\\left" << latexName(left_).c_str() << cell(0)
48            << "\\right" << latexName(right_).c_str();
49 }
50
51
52 void MathDelimInset::normalize(NormalStream & os) const
53 {
54         os << "[delim " << latexName(left_).c_str() << ' '
55                 << latexName(right_).c_str() << ' ' << cell(0) << ']';
56 }
57
58
59 int MathDelimInset::dw() const
60 {
61         int w = height() / 5;
62         if (w > 12)
63                 w = 12;
64         if (w < 4)
65                 w = 4;
66         return w;
67 }
68
69
70 void MathDelimInset::metrics(MathMetricsInfo const & mi) const
71 {
72         xcell(0).metrics(mi);
73         int a, d, w;
74         mathed_char_dim(LM_TC_VAR, mi, 'I', a, d, w);
75         int h0   = (a + d) / 2;
76         int a0   = std::max(xcell(0).ascent(), a)   - h0;
77         int d0   = std::max(xcell(0).descent(), d)  + h0;
78         ascent_  = std::max(a0, d0) + h0;
79         descent_ = std::max(a0, d0) - h0;
80         width_   = xcell(0).width() + 2 * dw() + 4;
81 }
82
83
84 void MathDelimInset::draw(Painter & pain, int x, int y) const
85
86         int const w = dw();
87         int const b = y - ascent_;
88         xcell(0).draw(pain, x + w + 2, y);
89         mathed_draw_deco(pain, x + 1, b, w, height(), left_);
90         mathed_draw_deco(pain, x + width() - w - 1, b, w, height(), right_);
91 }
92
93
94 bool MathDelimInset::isParanthesis() const
95 {
96         return left_ == "(" && right_ == ")";
97 }
98
99
100 bool MathDelimInset::isBrackets() const
101 {
102         return left_ == "[" && right_ == "]";
103 }
104
105
106 bool MathDelimInset::isAbs() const
107 {
108         return left_ == "|" && right_ == "|";
109 }
110
111
112 void MathDelimInset::maplize(MapleStream & os) const
113 {
114         if (isAbs()) {
115                 bool mat =
116                         cell(0).size() == 1 && cell(0).begin()->nucleus()
117                                         && cell(0).begin()->nucleus()->asMatrixInset();
118                 if (mat)        
119                         os << "linalg[det](" << cell(0) << ")";
120                 else
121                         os << "abs(" << cell(0) << ")";
122         }
123         else
124                 os << left_.c_str() << cell(0) << right_.c_str();
125 }
126
127
128 void MathDelimInset::mathmlize(MathMLStream & os) const
129 {
130         os << "<fenced open=\"" << left_.c_str() << "\" close=\""
131                 << right_.c_str() << "\">" << cell(0) << "</fenced>";
132 }
133
134
135 void MathDelimInset::octavize(OctaveStream & os) const
136 {
137         if (isAbs())
138                 os << "det(" << cell(0) << ")";
139         else
140                 os << left_.c_str() << cell(0) << right_.c_str();
141 }