]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
Generalise the deletion protection mechanism from math to text (#9540)
[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 }
46
47
48 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
49 {
50         Changer dummy = pi.base.changeEnsureMath();
51         cell(0).draw(pi, x + 9, y);
52         Dimension const dim = dimension(*pi.base.bv);
53         int const a = dim.ascent();
54         int const d = dim.descent();
55         int xp[3];
56         int yp[3];
57         pi.pain.line(x + dim.width(), y - a + 1,
58                 x + 7, y - a + 1, pi.base.font.color());
59         xp[0] = x + 7;            yp[0] = y - a + 1;
60         xp[1] = x + 4;            yp[1] = y + d - 1;
61         xp[2] = x;                yp[2] = y + (d - a)/2;
62         pi.pain.lines(xp, yp, 3, pi.base.font.color());
63 }
64
65
66 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
67 {
68         cell(0).metricsT(mi, dim);
69         dim.asc += 1;
70         dim.wid += 2;
71 }
72
73
74 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
75 {
76         /*
77         cell(0).drawT(pain, x + 2, y);
78         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
79         pain.horizontalLine(x + 2, y - dim0.ascent(), dim0.width(), '_');
80         pain.verticalLine  (x + 1, y - dim0.ascent() + 1, dim0.height());
81         pain.draw(x, y + dim0.descent(), '\\');
82         */
83 }
84
85
86 void InsetMathSqrt::write(WriteStream & os) const
87 {
88         MathEnsurer ensurer(os);
89         os << "\\sqrt{" << cell(0) << '}';
90 }
91
92
93 void InsetMathSqrt::normalize(NormalStream & os) const
94 {
95         os << "[sqrt " << cell(0) << ']';
96 }
97
98 void InsetMathSqrt::maple(MapleStream & os) const
99 {
100         os << "sqrt(" << cell(0) << ')';
101 }
102
103 void InsetMathSqrt::mathematica(MathematicaStream & os) const
104 {
105         os << "Sqrt[" << cell(0) << ']';
106 }
107
108
109 void InsetMathSqrt::octave(OctaveStream & os) const
110 {
111         os << "sqrt(" << cell(0) << ')';
112 }
113
114
115 void InsetMathSqrt::mathmlize(MathStream & os) const
116 {
117         os << MTag("msqrt") << cell(0) << ETag("msqrt");
118 }
119
120
121 void InsetMathSqrt::htmlize(HtmlStream & os) const
122 {
123         os << MTag("span", "class='sqrt'")
124            << from_ascii("&radic;") 
125            << MTag("span", "class='sqrtof'")    << cell(0) << ETag("span") 
126                  << ETag("span");
127 }
128
129
130 void InsetMathSqrt::validate(LaTeXFeatures & features) const
131 {
132         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
133                 features.addCSSSnippet("span.sqrtof{border-top: thin solid black;}");
134         InsetMathNest::validate(features);
135 }
136
137 } // namespace lyx