2 * \file InsetMathStackrel.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 "InsetMathStackrel.h"
16 #include "MathStream.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
26 InsetMathStackrel::InsetMathStackrel(Buffer * buf, bool sub)
27 : InsetMathFracBase(buf, sub ? 3 : 2)
31 Inset * InsetMathStackrel::clone() const
33 return new InsetMathStackrel(*this);
37 bool InsetMathStackrel::idxUpDown(Cursor & cur, bool up) const
43 if (cur.idx() + 1 == nargs())
46 InsetMath::idx_type target = up ? cur.idx() - 1 : cur.idx() + 1;
47 if (cur.idx() == target)
50 cur.pos() = cell(target).x2pos(&cur.bv(), cur.x_target());
55 MathClass InsetMathStackrel::mathClass() const
57 // FIXME: update this when/if \stackbin is supported
62 void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
65 cell(1).metrics(mi, dim1);
66 Changer dummy = mi.base.changeFrac();
68 cell(0).metrics(mi, dim0);
71 cell(2).metrics(mi, dim2);
72 dim.wid = max(max(dim0.width(), dim1.width()), dim2.width()) + 4;
73 dim.asc = dim1.ascent() + dim0.height() + 4;
74 dim.des = dim1.descent() + dim2.height() + dim2.descent() + 1;
76 dim.wid = max(dim0.width(), dim1.width()) + 4;
77 dim.asc = dim1.ascent() + dim0.height() + 4;
78 dim.des = dim1.descent();
80 metricsMarkers(mi, dim);
84 void InsetMathStackrel::draw(PainterInfo & pi, int x, int y) const
86 Dimension const dim = dimension(*pi.base.bv);
87 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
88 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
89 int m = x + dim.width() / 2;
90 int yo = y - dim1.ascent() - dim0.descent() - 1;
91 cell(1).draw(pi, m - dim1.width() / 2, y);
92 Changer dummy = pi.base.changeFrac();
93 cell(0).draw(pi, m - dim0.width() / 2, yo);
95 Dimension const & dim2 = cell(2).dimension(*pi.base.bv);
96 int y2 = y + dim1.descent() + dim2.ascent() + 1;
97 cell(2).draw(pi, m - dim2.width() / 2, y2);
99 drawMarkers(pi, x, y);
103 void InsetMathStackrel::write(WriteStream & os) const
105 MathEnsurer ensurer(os);
108 os << '[' << cell(2) << ']';
109 os << '{' << cell(0) << "}{" << cell(1) << '}';
113 void InsetMathStackrel::normalize(NormalStream & os) const
115 os << "[stackrel " << cell(0) << ' ' << cell(1);
117 os << ' ' << cell(2);
122 void InsetMathStackrel::mathmlize(MathStream & ms) const
125 ms << "<munderover>" << cell(1) << cell(2) << cell(0) << "</munderover>";
127 ms << "<mover accent='false'>" << cell(1) << cell(0) << "</mover>";
131 void InsetMathStackrel::htmlize(HtmlStream & os) const
134 os << MTag("span", "class='underoverset'")
135 << MTag("span", "class='top'") << cell(0) << ETag("span")
136 << MTag("span") << cell(1) << ETag("span")
137 << MTag("span", "class='bottom'") << cell(2) << ETag("span");
139 // at the moment, this is exactly the same as overset
140 os << MTag("span", "class='overset'")
141 << MTag("span", "class='top'") << cell(0) << ETag("span")
142 << MTag("span") << cell(1) << ETag("span");
148 void InsetMathStackrel::validate(LaTeXFeatures & features) const
150 if (features.runparams().math_flavor == OutputParams::MathAsHTML) {
152 // FIXME: "vertical-align: middle" works only if the
153 // height of sub and super script is approximately equal.
154 features.addCSSSnippet(
155 "span.underoverset{display: inline-block; vertical-align: middle; text-align:center;}\n"
156 "span.underoverset span {display: block;}\n"
157 "span.bottom{font-size: 66%;}\n"
158 "span.top{font-size: 66%;}");
161 features.addCSSSnippet(
162 "span.overset{display: inline-block; vertical-align: bottom; text-align:center;}\n"
163 "span.overset span {display: block;}\n"
164 "span.top{font-size: 66%;}");
168 features.require("stackrel");
170 InsetMathNest::validate(features);