]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
Merge branch 'master' of git.lyx.org:lyx
[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 "LaTeXFeatures.h"
16 #include "MathData.h"
17 #include "MathStream.h"
18 #include "TextPainter.h"
19 #include "frontends/Painter.h"
20
21
22 namespace lyx {
23
24 InsetMathSqrt::InsetMathSqrt(Buffer * buf)
25         : InsetMathNest(buf, 1)
26 {}
27
28
29 Inset * InsetMathSqrt::clone() const
30 {
31         return new InsetMathSqrt(*this);
32 }
33
34
35 void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
36 {
37         cell(0).metrics(mi, dim);
38         dim.asc += 4;
39         dim.des += 2;
40         dim.wid += 12;
41         metricsMarkers(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         Dimension const dim = dimension(*pi.base.bv);
49         int const a = dim.ascent();
50         int const d = dim.descent();
51         int xp[3];
52         int yp[3];
53         pi.pain.line(x + dim.width(), y - a + 1,
54                 x + 8, y - a + 1, pi.base.font.color());
55         xp[0] = x + 8;            yp[0] = y - a + 1;
56         xp[1] = x + 5;            yp[1] = y + d - 1;
57         xp[2] = x;                yp[2] = y + (d - a)/2;
58         pi.pain.lines(xp, yp, 3, pi.base.font.color());
59         drawMarkers(pi, x, y);
60 }
61
62
63 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
64 {
65         cell(0).metricsT(mi, dim);
66         dim.asc += 1;
67         dim.wid += 2;
68 }
69
70
71 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
72 {
73         /*
74         cell(0).drawT(pain, x + 2, y);
75         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
76         pain.horizontalLine(x + 2, y - dim0.ascent(), dim0.width(), '_');
77         pain.verticalLine  (x + 1, y - dim0.ascent() + 1, dim0.height());
78         pain.draw(x, y + dim0.descent(), '\\');
79         */
80 }
81
82
83 void InsetMathSqrt::write(WriteStream & os) const
84 {
85         MathEnsurer ensurer(os);
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 void InsetMathSqrt::htmlize(HtmlStream & os) const
119 {
120         os << MTag("span", "class='sqrt'")
121            << from_ascii("&radic;") 
122            << MTag("span", "class='sqrtof'")    << cell(0) << ETag("span") 
123                  << ETag("span");
124 }
125
126
127 void InsetMathSqrt::validate(LaTeXFeatures & features) const
128 {
129         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
130                 features.addCSSSnippet("span.sqrtof{border-top: thin solid black;}");
131         InsetMathNest::validate(features);
132 }
133
134 } // namespace lyx