2 * \file InsetMathOverset.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 "InsetMathOverset.h"
16 #include "MathStream.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
22 #include "support/lassert.h"
28 Inset * InsetMathOverset::clone() const
30 return new InsetMathOverset(*this);
34 void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & dim) const
36 Changer dummy2 = mi.base.changeEnsureMath();
38 cell(0).metrics(mi, dim0);
39 Changer dummy = mi.base.changeScript();
41 cell(1).metrics(mi, dim1);
42 dim.wid = max(dim1.width(), dim0.wid) + 4;
43 dim.asc = dim0.asc + dim1.height() + 4;
48 void InsetMathOverset::draw(PainterInfo & pi, int x, int y) const
50 Changer dummy2 = pi.base.changeEnsureMath();
51 Dimension const dim = dimension(*pi.base.bv);
52 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
53 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
54 int m = x + dim.wid / 2;
55 int yo = y - dim0.asc - dim1.des - 1;
56 cell(0).draw(pi, m - dim0.wid / 2, y);
57 Changer dummy = pi.base.changeScript();
58 cell(1).draw(pi, m - dim1.width() / 2, yo);
62 bool InsetMathOverset::idxUpDown(Cursor & cur, bool up) const
64 idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
65 if (cur.idx() == target)
68 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target());
73 bool InsetMathOverset::idxFirst(Cursor & cur) const
75 LASSERT(&cur.inset() == this, return false);
82 bool InsetMathOverset::idxLast(Cursor & cur) const
84 LASSERT(&cur.inset() == this, return false);
86 cur.pos() = cur.lastpos();
91 void InsetMathOverset::write(TeXMathStream & os) const
93 MathEnsurer ensurer(os);
96 os << "\\overset{" << cell(1) << "}{" << cell(0) << '}';
100 void InsetMathOverset::normalize(NormalStream & os) const
102 os << "[overset " << cell(1) << ' ' << cell(0) << ']';
106 void InsetMathOverset::mathmlize(MathMLStream & ms) const
108 ms << "<" << from_ascii(ms.namespacedTag("mover")) << " accent='false'>"
109 << cell(0) << cell(1)
110 << "</" << from_ascii(ms.namespacedTag("mover")) << ">";
114 void InsetMathOverset::htmlize(HtmlStream & os) const
116 os << MTag("span", "class='overset'")
117 << MTag("span", "class='top'") << cell(1) << ETag("span")
118 << MTag("span") << cell(0) << ETag("span")
123 void InsetMathOverset::validate(LaTeXFeatures & features) const
125 if (features.runparams().isLaTeX())
126 features.require("amsmath");
127 else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
128 features.addCSSSnippet(
129 "span.overset{display: inline-block; vertical-align: bottom; text-align:center;}\n"
130 "span.overset span {display: block;}\n"
131 "span.top{font-size: 66%;}");
133 InsetMathNest::validate(features);