2 * \file InsetMathSqrt.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathSqrt.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
21 #include "TextPainter.h"
23 #include "frontends/Painter.h"
28 InsetMathSqrt::InsetMathSqrt(Buffer * buf)
29 : InsetMathNest(buf, 1)
33 Inset * InsetMathSqrt::clone() const
35 return new InsetMathSqrt(*this);
39 void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
41 Changer dummy = mi.base.changeEnsureMath();
42 cell(0).metrics(mi, dim);
43 // make sure that the dim is high enough for any character
45 math_font_max_dim(mi.base.font, fontDim.asc, fontDim.des);
47 // Some room for the decoration
53 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
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();
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());
71 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
73 cell(0).metricsT(mi, dim);
79 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
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(), '\\');
91 void InsetMathSqrt::write(WriteStream & os) const
93 MathEnsurer ensurer(os);
94 os << "\\sqrt{" << cell(0) << '}';
98 void InsetMathSqrt::normalize(NormalStream & os) const
100 os << "[sqrt " << cell(0) << ']';
103 void InsetMathSqrt::maple(MapleStream & os) const
105 os << "sqrt(" << cell(0) << ')';
108 void InsetMathSqrt::mathematica(MathematicaStream & os) const
110 os << "Sqrt[" << cell(0) << ']';
114 void InsetMathSqrt::octave(OctaveStream & os) const
116 os << "sqrt(" << cell(0) << ')';
120 void InsetMathSqrt::mathmlize(MathStream & os) const
122 os << MTag("msqrt") << cell(0) << ETag("msqrt");
126 void InsetMathSqrt::htmlize(HtmlStream & os) const
128 os << MTag("span", "class='sqrt'")
129 << from_ascii("√")
130 << MTag("span", "class='sqrtof'") << cell(0) << ETag("span")
135 void InsetMathSqrt::validate(LaTeXFeatures & features) const
137 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
138 features.addCSSSnippet("span.sqrtof{border-top: thin solid black;}");
139 InsetMathNest::validate(features);