2 #include "math_fracinset.h"
3 #include "math_support.h"
4 #include "frontends/Painter.h"
5 #include "math_mathmlstream.h"
6 #include "textpainter.h"
12 MathFracInset::MathFracInset(bool atop)
17 InsetBase * MathFracInset::clone() const
19 return new MathFracInset(*this);
23 MathFracInset * MathFracInset::asFracInset()
25 return atop_ ? 0 : this;
29 MathFracInset const * MathFracInset::asFracInset() const
31 return atop_ ? 0 : this;
35 void MathFracInset::metrics(MetricsInfo & mi, Dimension & dim) const
37 FracChanger dummy(mi.base);
40 dim_.wid = max(cell(0).width(), cell(1).width()) + 2;
41 dim_.asc = cell(0).height() + 2 + 5;
42 dim_.des = cell(1).height() + 2 - 5;
47 void MathFracInset::draw(PainterInfo & pi, int x, int y) const
49 int m = x + dim_.wid / 2;
50 FracChanger dummy(pi.base);
51 cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
52 cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5);
54 pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, LColor::math);
58 void MathFracInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
60 cell(0).metricsT(mi, dim);
61 cell(1).metricsT(mi, dim);
62 dim.wid = max(cell(0).width(), cell(1).width());
63 dim.asc = cell(0).height() + 1;
64 dim.des = cell(1).height();
69 void MathFracInset::drawT(TextPainter & pain, int x, int y) const
71 int m = x + dim_.width() / 2;
72 cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
73 cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
75 pain.horizontalLine(x, y, dim_.width());
79 void MathFracInset::write(WriteStream & os) const
82 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
84 MathNestInset::write(os);
88 string MathFracInset::name() const
90 return atop_ ? "atop" : "frac";
94 void MathFracInset::maple(MapleStream & os) const
96 os << '(' << cell(0) << ")/(" << cell(1) << ')';
100 void MathFracInset::mathematica(MathematicaStream & os) const
102 os << '(' << cell(0) << ")/(" << cell(1) << ')';
106 void MathFracInset::octave(OctaveStream & os) const
108 os << '(' << cell(0) << ")/(" << cell(1) << ')';
112 void MathFracInset::mathmlize(MathMLStream & os) const
114 os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");