]> git.lyx.org Git - lyx.git/blob - src/mathed/math_deliminset.C
Strip out redundant #includes
[lyx.git] / src / mathed / math_deliminset.C
1 /**
2  * \file math_deliminset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "math_deliminset.h"
15 #include "math_support.h"
16 #include "math_mathmlstream.h"
17 #include "math_streamstr.h"
18
19
20 using std::max;
21 using std::auto_ptr;
22
23 namespace {
24
25 string convertDelimToLatexName(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         if (name == "/")
42                 return name;
43         if (name == "|")
44                 return name;
45         return '\\' + name + ' ';
46 }
47
48 }
49
50
51
52 MathDelimInset::MathDelimInset(string const & l, string const & r)
53         : MathNestInset(1), left_(l), right_(r)
54 {}
55
56
57 MathDelimInset::MathDelimInset
58                 (string const & l, string const & r, MathArray const & ar)
59         : MathNestInset(1), left_(l), right_(r)
60 {
61         cell(0) = ar;
62 }
63
64
65 auto_ptr<InsetBase> MathDelimInset::clone() const
66 {
67         return auto_ptr<InsetBase>(new MathDelimInset(*this));
68 }
69
70
71 void MathDelimInset::write(WriteStream & os) const
72 {
73         os << "\\left" << convertDelimToLatexName(left_) << cell(0)
74            << "\\right" << convertDelimToLatexName(right_);
75 }
76
77
78 void MathDelimInset::normalize(NormalStream & os) const
79 {
80         os << "[delim " << convertDelimToLatexName(left_) << ' '
81            << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
82 }
83
84
85 void MathDelimInset::metrics(MetricsInfo & mi, Dimension & dim) const
86 {
87         cell(0).metrics(mi);
88         Dimension t;
89         mathed_char_dim(mi.base.font, 'I', t);
90         int h0 = (t.asc + t.des) / 2;
91         int a0 = max(cell(0).ascent(), t.asc)   - h0;
92         int d0 = max(cell(0).descent(), t.des)  + h0;
93         dw_ = cell(0).height() / 5;
94         if (dw_ > 8)
95                 dw_ = 8;
96         if (dw_ < 4)
97                 dw_ = 4;
98         dim_.wid = cell(0).width() + 2 * dw_ + 8;
99         dim_.asc = max(a0, d0) + h0;
100         dim_.des = max(a0, d0) - h0;
101         dim = dim_;
102 }
103
104
105 void MathDelimInset::draw(PainterInfo & pi, int x, int y) const
106 {
107         int const b = y - dim_.asc;
108         cell(0).draw(pi, x + dw_ + 4, y);
109         mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
110         mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
111                 b, dw_, dim_.height(), right_);
112 }
113
114
115 bool MathDelimInset::isParanthesis() const
116 {
117         return left_ == "(" && right_ == ")";
118 }
119
120
121 bool MathDelimInset::isBrackets() const
122 {
123         return left_ == "[" && right_ == "]";
124 }
125
126
127 bool MathDelimInset::isAbs() const
128 {
129         return left_ == "|" && right_ == "|";
130 }
131
132
133 void MathDelimInset::maple(MapleStream & os) const
134 {
135         if (isAbs()) {
136                 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
137                         os << "linalg[det](" << cell(0) << ')';
138                 else
139                         os << "abs(" << cell(0) << ')';
140         }
141         else
142                 os << left_ << cell(0) << right_;
143 }
144
145 void MathDelimInset::maxima(MaximaStream & os) const
146 {
147         if (isAbs()) {
148                 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
149                         os << "determinant(" << cell(0) << ')';
150                 else
151                         os << "abs(" << cell(0) << ')';
152         }
153         else
154                 os << left_ << cell(0) << right_;
155 }
156
157
158 void MathDelimInset::mathematica(MathematicaStream & os) const
159 {
160         if (isAbs()) {
161                 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
162                         os << "Det" << cell(0) << ']';
163                 else
164                         os << "Abs[" << cell(0) << ']';
165         }
166         else
167                 os << left_ << cell(0) << right_;
168 }
169
170
171 void MathDelimInset::mathmlize(MathMLStream & os) const
172 {
173         os << "<fenced open=\"" << left_ << "\" close=\""
174                 << right_ << "\">" << cell(0) << "</fenced>";
175 }
176
177
178 void MathDelimInset::octave(OctaveStream & os) const
179 {
180         if (isAbs())
181                 os << "det(" << cell(0) << ')';
182         else
183                 os << left_ << cell(0) << right_;
184 }