]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
eaf207f71be5c93ef2e0cf5ecf64ee9acaa48e7a
[lyx.git] / src / mathed / InsetMathSqrt.cpp
1 /**
2  * \file InsetMathSqrt.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathSqrt.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "TextPainter.h"
17 #include "Color.h"
18 #include "frontends/Painter.h"
19
20
21 namespace lyx {
22
23 InsetMathSqrt::InsetMathSqrt()
24         : InsetMathNest(1)
25 {}
26
27
28 Inset * InsetMathSqrt::clone() const
29 {
30         return new InsetMathSqrt(*this);
31 }
32
33
34 void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
35 {
36         cell(0).metrics(mi, dim);
37         dim.asc += 4;
38         dim.des += 2;
39         dim.wid += 12;
40         metricsMarkers(dim);
41         // Cache the inset dimension. 
42         setDimCache(mi, dim);
43 }
44
45
46 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
47 {
48         cell(0).draw(pi, x + 10, y);
49         Dimension const dim = dimension(*pi.base.bv);
50         int const a = dim.ascent();
51         int const d = dim.descent();
52         int xp[3];
53         int yp[3];
54         pi.pain.line(x + dim.width(), y - a + 1,
55                 x + 8, y - a + 1, Color::math);
56         xp[0] = x + 8;            yp[0] = y - a + 1;
57         xp[1] = x + 5;            yp[1] = y + d - 1;
58         xp[2] = x;                yp[2] = y + (d - a)/2;
59         pi.pain.lines(xp, yp, 3, Color::math);
60         drawMarkers(pi, x, y);
61 }
62
63
64 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
65 {
66         cell(0).metricsT(mi, dim);
67         dim.asc += 1;
68         dim.wid += 2;
69 }
70
71
72 void InsetMathSqrt::drawT(TextPainter & pain, int x, int y) const
73 {
74         /*
75         cell(0).drawT(pain, x + 2, y);
76         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
77         pain.horizontalLine(x + 2, y - dim0.ascent(), dim0.width(), '_');
78         pain.verticalLine  (x + 1, y - dim0.ascent() + 1, dim0.height());
79         pain.draw(x, y + dim0.descent(), '\\');
80         */
81 }
82
83
84 void InsetMathSqrt::write(WriteStream & os) const
85 {
86         os << "\\sqrt{" << cell(0) << '}';
87 }
88
89
90 void InsetMathSqrt::normalize(NormalStream & os) const
91 {
92         os << "[sqrt " << cell(0) << ']';
93 }
94
95 void InsetMathSqrt::maple(MapleStream & os) const
96 {
97         os << "sqrt(" << cell(0) << ')';
98 }
99
100 void InsetMathSqrt::mathematica(MathematicaStream & os) const
101 {
102         os << "Sqrt[" << cell(0) << ']';
103 }
104
105
106 void InsetMathSqrt::octave(OctaveStream & os) const
107 {
108         os << "sqrt(" << cell(0) << ')';
109 }
110
111
112 void InsetMathSqrt::mathmlize(MathStream & os) const
113 {
114         os << MTag("msqrt") << cell(0) << ETag("msqrt");
115 }
116
117
118 } // namespace lyx