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