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