]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
1157dd8b6f43e993a682e5cb1a551b0b97f70a99
[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         dim_ = dim;
42 }
43
44
45 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
46 {
47         cell(0).draw(pi, x + 10, y);
48         int const a = dim_.ascent();
49         int const d = dim_.descent();
50         int xp[3];
51         int yp[3];
52         pi.pain.line(x + dim_.width(), y - a + 1,
53                                                          x + 8, y - a + 1, Color::math);
54         xp[0] = x + 8;            yp[0] = y - a + 1;
55         xp[1] = x + 5;            yp[1] = y + d - 1;
56         xp[2] = x;                yp[2] = y + (d - a)/2;
57         pi.pain.lines(xp, yp, 3, Color::math);
58         drawMarkers(pi, x, y);
59 }
60
61
62 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
63 {
64         cell(0).metricsT(mi, dim);
65         dim.asc += 1;
66         dim.wid += 2;
67 }
68
69
70 void InsetMathSqrt::drawT(TextPainter & pain, int x, int y) const
71 {
72         cell(0).drawT(pain, x + 2, y);
73         pain.horizontalLine(x + 2, y - cell(0).ascent(), cell(0).width(), '_');
74         pain.verticalLine  (x + 1, y - cell(0).ascent() + 1, cell(0).height());
75         pain.draw(x, y + cell(0).descent(), '\\');
76 }
77
78
79 void InsetMathSqrt::write(WriteStream & os) const
80 {
81         os << "\\sqrt{" << cell(0) << '}';
82 }
83
84
85 void InsetMathSqrt::normalize(NormalStream & os) const
86 {
87         os << "[sqrt " << cell(0) << ']';
88 }
89
90 void InsetMathSqrt::maple(MapleStream & os) const
91 {
92         os << "sqrt(" << cell(0) << ')';
93 }
94
95 void InsetMathSqrt::mathematica(MathematicaStream & os) const
96 {
97         os << "Sqrt[" << cell(0) << ']';
98 }
99
100
101 void InsetMathSqrt::octave(OctaveStream & os) const
102 {
103         os << "sqrt(" << cell(0) << ')';
104 }
105
106
107 void InsetMathSqrt::mathmlize(MathStream & os) const
108 {
109         os << MTag("msqrt") << cell(0) << ETag("msqrt");
110 }
111
112
113 } // namespace lyx