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"
15 #include "LaTeXFeatures.h"
17 #include "MathStream.h"
18 #include "TextPainter.h"
19 #include "frontends/Painter.h"
24 InsetMathSqrt::InsetMathSqrt(Buffer * buf)
25 : InsetMathNest(buf, 1)
29 Inset * InsetMathSqrt::clone() const
31 return new InsetMathSqrt(*this);
35 void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
37 cell(0).metrics(mi, dim);
45 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
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();
53 pi.pain.line(x + dim.width(), y - a + 1,
54 x + 8, y - a + 1, Color_math);
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, Color_math);
59 drawMarkers(pi, x, y);
63 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
65 cell(0).metricsT(mi, dim);
71 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
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(), '\\');
83 void InsetMathSqrt::write(WriteStream & os) const
85 MathEnsurer ensurer(os);
86 os << "\\sqrt{" << cell(0) << '}';
90 void InsetMathSqrt::normalize(NormalStream & os) const
92 os << "[sqrt " << cell(0) << ']';
95 void InsetMathSqrt::maple(MapleStream & os) const
97 os << "sqrt(" << cell(0) << ')';
100 void InsetMathSqrt::mathematica(MathematicaStream & os) const
102 os << "Sqrt[" << cell(0) << ']';
106 void InsetMathSqrt::octave(OctaveStream & os) const
108 os << "sqrt(" << cell(0) << ')';
112 void InsetMathSqrt::mathmlize(MathStream & os) const
114 os << MTag("msqrt") << cell(0) << ETag("msqrt");
118 void InsetMathSqrt::htmlize(HtmlStream & os) const
120 os << MTag("span", "class='sqrt'")
121 << from_ascii("√")
122 << MTag("span", "class='sqrtof'") << cell(0) << ETag("span")
127 void InsetMathSqrt::validate(LaTeXFeatures & features) const
129 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
130 features.addPreambleSnippet("<style type=\"text/css\">\n"
131 "span.sqrtof{border-top: thin solid black;}\n"
133 InsetMathNest::validate(features);