2 * \file math_fracinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "math_fracinset.h"
15 #include "math_data.h"
16 #include "math_mathmlstream.h"
17 #include "textpainter.h"
19 #include "frontends/Painter.h"
27 MathFracInset::MathFracInset(bool atop)
32 auto_ptr<InsetBase> MathFracInset::doClone() const
34 return auto_ptr<InsetBase>(new MathFracInset(*this));
38 MathFracInset * MathFracInset::asFracInset()
40 return atop_ ? 0 : this;
44 MathFracInset const * MathFracInset::asFracInset() const
46 return atop_ ? 0 : this;
50 void MathFracInset::metrics(MetricsInfo & mi, Dimension & dim) const
52 FracChanger dummy(mi.base);
55 dim.wid = max(cell(0).width(), cell(1).width()) + 2;
56 dim.asc = cell(0).height() + 2 + 5;
57 dim.des = cell(1).height() + 2 - 5;
63 void MathFracInset::draw(PainterInfo & pi, int x, int y) const
65 setPosCache(pi, x, y);
66 int m = x + dim_.wid / 2;
67 FracChanger dummy(pi.base);
68 cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
69 cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5);
71 pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, LColor::math);
72 drawMarkers(pi, x, y);
76 void MathFracInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
78 cell(0).metricsT(mi, dim);
79 cell(1).metricsT(mi, dim);
80 dim.wid = max(cell(0).width(), cell(1).width());
81 dim.asc = cell(0).height() + 1;
82 dim.des = cell(1).height();
87 void MathFracInset::drawT(TextPainter & pain, int x, int y) const
89 int m = x + dim_.width() / 2;
90 cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
91 cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
93 pain.horizontalLine(x, y, dim_.width());
97 void MathFracInset::write(WriteStream & os) const
100 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
102 MathNestInset::write(os);
106 string MathFracInset::name() const
108 return atop_ ? "atop" : "frac";
112 void MathFracInset::maple(MapleStream & os) const
114 os << '(' << cell(0) << ")/(" << cell(1) << ')';
118 void MathFracInset::mathematica(MathematicaStream & os) const
120 os << '(' << cell(0) << ")/(" << cell(1) << ')';
124 void MathFracInset::octave(OctaveStream & os) const
126 os << '(' << cell(0) << ")/(" << cell(1) << ')';
130 void MathFracInset::mathmlize(MathMLStream & os) const
132 os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");