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"
18 #include "LaTeXFeatures.h"
19 #include "MetricsInfo.h"
20 #include "TextPainter.h"
22 #include "frontends/Painter.h"
27 InsetMathSqrt::InsetMathSqrt(Buffer * buf)
28 : InsetMathNest(buf, 1)
32 Inset * InsetMathSqrt::clone() const
34 return new InsetMathSqrt(*this);
38 void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
40 cell(0).metrics(mi, dim);
48 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
50 cell(0).draw(pi, x + 10, y);
51 Dimension const dim = dimension(*pi.base.bv);
52 int const a = dim.ascent();
53 int const d = dim.descent();
56 pi.pain.line(x + dim.width(), y - a + 1,
57 x + 8, y - a + 1, pi.base.font.color());
58 xp[0] = x + 8; yp[0] = y - a + 1;
59 xp[1] = x + 5; yp[1] = y + d - 1;
60 xp[2] = x; yp[2] = y + (d - a)/2;
61 pi.pain.lines(xp, yp, 3, pi.base.font.color());
62 drawMarkers(pi, x, y);
66 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
68 cell(0).metricsT(mi, dim);
74 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
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(), '\\');
86 void InsetMathSqrt::write(WriteStream & os) const
88 MathEnsurer ensurer(os);
89 os << "\\sqrt{" << cell(0) << '}';
93 void InsetMathSqrt::normalize(NormalStream & os) const
95 os << "[sqrt " << cell(0) << ']';
98 void InsetMathSqrt::maple(MapleStream & os) const
100 os << "sqrt(" << cell(0) << ')';
103 void InsetMathSqrt::mathematica(MathematicaStream & os) const
105 os << "Sqrt[" << cell(0) << ']';
109 void InsetMathSqrt::octave(OctaveStream & os) const
111 os << "sqrt(" << cell(0) << ')';
115 void InsetMathSqrt::mathmlize(MathStream & os) const
117 os << MTag("msqrt") << cell(0) << ETag("msqrt");
121 void InsetMathSqrt::htmlize(HtmlStream & os) const
123 os << MTag("span", "class='sqrt'")
124 << from_ascii("√")
125 << MTag("span", "class='sqrtof'") << cell(0) << ETag("span")
130 void InsetMathSqrt::validate(LaTeXFeatures & features) const
132 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
133 features.addCSSSnippet("span.sqrtof{border-top: thin solid black;}");
134 InsetMathNest::validate(features);