]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
Move some Cursor methods to CursorData
[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
15 #include "MathData.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
18
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
21 #include "TextPainter.h"
22
23 #include "frontends/Painter.h"
24
25
26 namespace lyx {
27
28 InsetMathSqrt::InsetMathSqrt(Buffer * buf)
29         : InsetMathNest(buf, 1)
30 {}
31
32
33 Inset * InsetMathSqrt::clone() const
34 {
35         return new InsetMathSqrt(*this);
36 }
37
38
39 void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
40 {
41         Changer dummy = mi.base.changeEnsureMath();
42         cell(0).metrics(mi, dim);
43         // make sure that the dim is high enough for any character
44         Dimension fontDim;
45         math_font_max_dim(mi.base.font, fontDim.asc, fontDim.des);
46         dim += fontDim;
47         // Some room for the decoration
48         dim.asc += 1;
49         dim.wid += 7;
50 }
51
52
53 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
54 {
55         Changer dummy = pi.base.changeEnsureMath();
56         cell(0).draw(pi, x + 9, y);
57         Dimension const dim = dimension(*pi.base.bv);
58         int const a = dim.ascent();
59         int const d = dim.descent();
60         int xp[3];
61         int yp[3];
62         pi.pain.line(x + dim.width(), y - a + 1,
63                 x + 7, y - a + 1, pi.base.font.color());
64         xp[0] = x + 7;            yp[0] = y - a + 1;
65         xp[1] = x + 4;            yp[1] = y + d - 1;
66         xp[2] = x;                yp[2] = y + (d - a)/2;
67         pi.pain.lines(xp, yp, 3, pi.base.font.color());
68 }
69
70
71 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
72 {
73         cell(0).metricsT(mi, dim);
74         dim.asc += 1;
75         dim.wid += 2;
76 }
77
78
79 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
80 {
81         /*
82         cell(0).drawT(pain, x + 2, y);
83         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
84         pain.horizontalLine(x + 2, y - dim0.ascent(), dim0.width(), '_');
85         pain.verticalLine  (x + 1, y - dim0.ascent() + 1, dim0.height());
86         pain.draw(x, y + dim0.descent(), '\\');
87         */
88 }
89
90
91 void InsetMathSqrt::write(WriteStream & os) const
92 {
93         MathEnsurer ensurer(os);
94         os << "\\sqrt{" << cell(0) << '}';
95 }
96
97
98 void InsetMathSqrt::normalize(NormalStream & os) const
99 {
100         os << "[sqrt " << cell(0) << ']';
101 }
102
103 void InsetMathSqrt::maple(MapleStream & os) const
104 {
105         os << "sqrt(" << cell(0) << ')';
106 }
107
108 void InsetMathSqrt::mathematica(MathematicaStream & os) const
109 {
110         os << "Sqrt[" << cell(0) << ']';
111 }
112
113
114 void InsetMathSqrt::octave(OctaveStream & os) const
115 {
116         os << "sqrt(" << cell(0) << ')';
117 }
118
119
120 void InsetMathSqrt::mathmlize(MathStream & os) const
121 {
122         os << MTag("msqrt") << cell(0) << ETag("msqrt");
123 }
124
125
126 void InsetMathSqrt::htmlize(HtmlStream & os) const
127 {
128         os << MTag("span", "class='sqrt'")
129            << from_ascii("&radic;")
130            << MTag("span", "class='sqrtof'")    << cell(0) << ETag("span")
131                  << ETag("span");
132 }
133
134
135 void InsetMathSqrt::validate(LaTeXFeatures & features) const
136 {
137         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
138                 features.addCSSSnippet("span.sqrtof{border-top: thin solid black;}");
139         InsetMathNest::validate(features);
140 }
141
142 } // namespace lyx