]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
replace (ascent, descent, width) triples by a structure 'dimension'
[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 "frontends/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 & mi) const
33 {
34         MathFracChanger dummy(mi.base);
35         xcell(0).metrics(mi);
36         xcell(1).metrics(mi);
37         dim_.w = max(xcell(0).width(), xcell(1).width()) + 2;
38         dim_.a = xcell(0).height() + 2 + 5;
39         dim_.d = xcell(1).height() + 2 - 5;
40 }
41
42
43 void MathFracInset::draw(MathPainterInfo & pi, int x, int y) const
44 {
45         int m = x + width() / 2;
46         MathFracChanger dummy(pi.base);
47         xcell(0).draw(pi, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
48         xcell(1).draw(pi, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 2 - 5);
49         if (!atop_)
50                 pi.pain.line(x + 1, y - 5, x + width() - 2, 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         dim_.w = max(xcell(0).width(), xcell(1).width());
59         dim_.a = xcell(0).height() + 1;
60         dim_.d = 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 void MathFracInset::maplize(MapleStream & os) const
93 {
94         os << '(' << cell(0) << ")/(" << cell(1) << ')';
95 }
96
97 void MathFracInset::mathematicize(MathematicaStream & os) const
98 {
99         os << '(' << cell(0) << ")/(" << cell(1) << ')';
100 }
101
102 void MathFracInset::octavize(OctaveStream & os) const
103 {
104         os << '(' << cell(0) << ")/(" << cell(1) << ')';
105 }
106
107
108 void MathFracInset::mathmlize(MathMLStream & os) const
109 {
110         os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
111 }