]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
oh well
[lyx.git] / src / mathed / math_fracinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_fracinset.h"
6 #include "math_support.h"
7 #include "Painter.h"
8 #include "math_mathmlstream.h"
9 #include "textpainter.h"
10
11
12 using std::max;
13
14
15 MathFracInset::MathFracInset(bool atop)
16         : atop_(atop)
17 {}
18
19
20 MathInset * MathFracInset::clone() const
21 {
22         return new MathFracInset(*this);
23 }
24
25
26 MathFracInset * MathFracInset::asFracInset()
27 {
28         return atop_ ? 0 : this;
29 }
30
31
32 void MathFracInset::metrics(MathMetricsInfo const & mi) const
33 {
34         MathMetricsInfo m = mi;
35         smallerStyleFrac(m);
36         xcell(0).metrics(m);
37         xcell(1).metrics(m);
38         width_   = max(xcell(0).width(), xcell(1).width()) + 2;
39         ascent_  = xcell(0).height() + 2 + 5;
40         descent_ = xcell(1).height() + 2 - 5;
41 }
42
43
44 void MathFracInset::draw(Painter & pain, int x, int y) const
45 {
46         int m = x + width() / 2;
47         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
48         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 2 - 5);
49         if (!atop_)
50                 pain.line(x, y - 5, x + width(), y - 5, LColor::math);
51 }
52
53
54 void MathFracInset::metricsT(TextMetricsInfo const & mi) const
55 {
56         xcell(0).metricsT(mi);
57         xcell(1).metricsT(mi);
58         width_   = max(xcell(0).width(), xcell(1).width());
59         ascent_  = xcell(0).height() + 1;
60         descent_ = xcell(1).height();
61 }
62
63
64 void MathFracInset::drawT(TextPainter & pain, int x, int y) const
65 {
66         int m = x + width() / 2;
67         xcell(0).drawT(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 1);
68         xcell(1).drawT(pain, m - xcell(1).width() / 2, y + xcell(1).ascent());
69         if (!atop_)
70                 pain.horizontalLine(x, y, width());
71 }
72
73
74 void MathFracInset::write(WriteStream & os) const
75 {
76         if (atop_)
77                 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
78         else
79                 os << "\\frac{" << cell(0) << "}{" << cell(1) << '}';
80 }
81
82
83 void MathFracInset::normalize(NormalStream & os) const
84 {
85         if (atop_)
86                 os << "[atop ";
87         else
88                 os << "[frac ";
89         os << cell(0) << ' ' << cell(1) << ']';
90 }
91
92
93 void MathFracInset::maplize(MapleStream & os) const
94 {
95         os << '(' << cell(0) << ")/(" << cell(1) << ')';
96 }
97
98
99 void MathFracInset::octavize(OctaveStream & os) const
100 {
101         os << '(' << cell(0) << ")/(" << cell(1) << ')';
102 }
103
104
105 void MathFracInset::mathmlize(MathMLStream & os) const
106 {
107         os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
108 }