]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
Avoid full metrics computation with Update:FitCursor
[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 "InsetMathRoot.h"
16 #include "MathData.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
22 #include "TextPainter.h"
23
24 #include "frontends/Painter.h"
25
26
27 namespace lyx {
28
29 InsetMathSqrt::InsetMathSqrt(Buffer * buf)
30         : InsetMathNest(buf, 1)
31 {}
32
33
34 Inset * InsetMathSqrt::clone() const
35 {
36         return new InsetMathSqrt(*this);
37 }
38
39
40 void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
41 {
42         mathed_root_metrics(mi, cell(0), nullptr, dim);
43 }
44
45
46 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
47 {
48         mathed_draw_root(pi, x, y, cell(0), nullptr, dimension(*pi.base.bv));
49 }
50
51
52 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
53 {
54         cell(0).metricsT(mi, dim);
55         dim.asc += 1;
56         dim.wid += 2;
57 }
58
59
60 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
61 {
62         /*
63         cell(0).drawT(pain, x + 2, y);
64         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
65         pain.horizontalLine(x + 2, y - dim0.ascent(), dim0.width(), '_');
66         pain.verticalLine  (x + 1, y - dim0.ascent() + 1, dim0.height());
67         pain.draw(x, y + dim0.descent(), '\\');
68         */
69 }
70
71
72 void InsetMathSqrt::write(TeXMathStream & os) const
73 {
74         MathEnsurer ensurer(os);
75         os << "\\sqrt{" << cell(0) << '}';
76 }
77
78
79 void InsetMathSqrt::normalize(NormalStream & os) const
80 {
81         os << "[sqrt " << cell(0) << ']';
82 }
83
84 void InsetMathSqrt::maple(MapleStream & os) const
85 {
86         os << "sqrt(" << cell(0) << ')';
87 }
88
89 void InsetMathSqrt::mathematica(MathematicaStream & os) const
90 {
91         os << "Sqrt[" << cell(0) << ']';
92 }
93
94
95 void InsetMathSqrt::octave(OctaveStream & os) const
96 {
97         os << "sqrt(" << cell(0) << ')';
98 }
99
100
101 void InsetMathSqrt::mathmlize(MathMLStream & ms) const
102 {
103         ms << MTag("msqrt") << cell(0) << ETag("msqrt");
104 }
105
106
107 void InsetMathSqrt::htmlize(HtmlStream & os) const
108 {
109         os << MTag("span", "class='sqrt'")
110            << from_ascii("&#8730;")
111            << MTag("span", "class='sqrtof'")    << cell(0) << ETag("span")
112                  << ETag("span");
113 }
114
115
116 void InsetMathSqrt::validate(LaTeXFeatures & features) const
117 {
118         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
119                 features.addCSSSnippet("span.sqrtof{border-top: thin solid black;}");
120         InsetMathNest::validate(features);
121 }
122
123 } // namespace lyx