]> git.lyx.org Git - lyx.git/blob - src/mathed/math_sqrtinset.C
replace (ascent, descent, width) triples by a structure 'dimension'
[lyx.git] / src / mathed / math_sqrtinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_sqrtinset.h"
6 #include "math_mathmlstream.h"
7 #include "LColor.h"
8 #include "frontends/Painter.h"
9 #include "textpainter.h"
10
11
12 MathSqrtInset::MathSqrtInset()
13         : MathNestInset(1)
14 {}
15
16
17 MathInset * MathSqrtInset::clone() const
18 {
19         return new MathSqrtInset(*this);
20 }
21
22
23 void MathSqrtInset::metrics(MathMetricsInfo & mi) const
24 {
25         xcell(0).metrics(mi);
26         dim_.a = xcell(0).ascent()  + 4;
27         dim_.d = xcell(0).descent() + 2;
28         dim_.w = xcell(0).width()   + 12;
29 }
30
31
32 void MathSqrtInset::draw(MathPainterInfo & pain, int x, int y) const
33 {
34         xcell(0).draw(pain, x + 10, y);
35         int const a = ascent();
36         int const d = descent();
37         int xp[4];
38         int yp[4];
39         xp[0] = x + width(); yp[0] = y - a + 1;
40         xp[1] = x + 8;       yp[1] = y - a + 1;
41         xp[2] = x + 5;       yp[2] = y + d - 1;
42         xp[3] = x;           yp[3] = y + (d - a)/2;
43         pain.pain.lines(xp, yp, 4, LColor::math);
44 }
45
46
47 void MathSqrtInset::metricsT(TextMetricsInfo const & mi) const
48 {
49         xcell(0).metricsT(mi);
50         dim_.a = xcell(0).ascent()  + 1;
51         dim_.d = xcell(0).descent();
52         dim_.w = xcell(0).width()   + 2;
53 }
54
55
56 void MathSqrtInset::drawT(TextPainter & pain, int x, int y) const
57 {
58         xcell(0).drawT(pain, x + 2, y);
59         pain.horizontalLine(x + 2, y - xcell(0).ascent(), xcell(0).width(), '_');
60         pain.verticalLine  (x + 1, y - xcell(0).ascent() + 1, xcell(0).height());
61         pain.draw(x, y + xcell(0).descent(), '\\');
62 }
63
64
65 void MathSqrtInset::write(WriteStream & os) const
66 {
67         os << "\\sqrt{" << cell(0) << '}';
68 }
69
70
71 void MathSqrtInset::normalize(NormalStream & os) const
72 {
73         os << "[sqrt " << cell(0) << ']';
74 }
75
76 void MathSqrtInset::maplize(MapleStream & os) const
77 {
78         os << "sqrt(" << cell(0) << ')';
79 }
80
81 void MathSqrtInset::mathematicize(MathematicaStream & os) const
82 {
83         os << "Sqrt[" << cell(0) << ']';
84 }
85
86
87 void MathSqrtInset::octavize(OctaveStream & os) const
88 {
89         os << "sqrt(" << cell(0) << ')';
90 }
91
92
93 void MathSqrtInset::mathmlize(MathMLStream & os) const
94 {
95         os << MTag("msqrt") << cell(0) << ETag("msqrt");
96 }