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"
18 #include "frontends/Painter.h"
25 MathFracInset::MathFracInset(bool atop)
30 auto_ptr<InsetBase> MathFracInset::clone() const
32 return auto_ptr<InsetBase>(new MathFracInset(*this));
36 MathFracInset * MathFracInset::asFracInset()
38 return atop_ ? 0 : this;
42 MathFracInset const * MathFracInset::asFracInset() const
44 return atop_ ? 0 : this;
48 void MathFracInset::metrics(MetricsInfo & mi, Dimension & dim) const
50 FracChanger dummy(mi.base);
53 dim_.wid = max(cell(0).width(), cell(1).width()) + 2;
54 dim_.asc = cell(0).height() + 2 + 5;
55 dim_.des = cell(1).height() + 2 - 5;
60 void MathFracInset::draw(PainterInfo & pi, int x, int y) const
62 int m = x + dim_.wid / 2;
63 FracChanger dummy(pi.base);
64 cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
65 cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5);
67 pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, LColor::math);
71 void MathFracInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
73 cell(0).metricsT(mi, dim);
74 cell(1).metricsT(mi, dim);
75 dim.wid = max(cell(0).width(), cell(1).width());
76 dim.asc = cell(0).height() + 1;
77 dim.des = cell(1).height();
82 void MathFracInset::drawT(TextPainter & pain, int x, int y) const
84 int m = x + dim_.width() / 2;
85 cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
86 cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
88 pain.horizontalLine(x, y, dim_.width());
92 void MathFracInset::write(WriteStream & os) const
95 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
97 MathNestInset::write(os);
101 string MathFracInset::name() const
103 return atop_ ? "atop" : "frac";
107 void MathFracInset::maple(MapleStream & os) const
109 os << '(' << cell(0) << ")/(" << cell(1) << ')';
113 void MathFracInset::mathematica(MathematicaStream & os) const
115 os << '(' << cell(0) << ")/(" << cell(1) << ')';
119 void MathFracInset::octave(OctaveStream & os) const
121 os << '(' << cell(0) << ")/(" << cell(1) << ')';
125 void MathFracInset::mathmlize(MathMLStream & os) const
127 os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");