]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
small up/down tweaking
[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 MathFracInset const * MathFracInset::asFracInset() const
33 {
34         return atop_ ? 0 : this;
35 }
36
37
38 void MathFracInset::metrics(MathMetricsInfo & mi) const
39 {
40         MathFracChanger dummy(mi.base);
41         cell(0).metrics(mi);
42         cell(1).metrics(mi);
43         dim_.w = max(cell(0).width(), cell(1).width()) + 2;
44         dim_.a = cell(0).height() + 2 + 5;
45         dim_.d = cell(1).height() + 2 - 5;
46 }
47
48
49 void MathFracInset::draw(MathPainterInfo & pi, int x, int y) const
50 {
51         int m = x + width() / 2;
52         MathFracChanger dummy(pi.base);
53         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
54         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
55         if (!atop_)
56                 pi.pain.line(x + 1, y - 5, x + width() - 2, y - 5, LColor::math);
57 }
58
59
60 void MathFracInset::metricsT(TextMetricsInfo const & mi) const
61 {
62         cell(0).metricsT(mi);
63         cell(1).metricsT(mi);
64         dim_.w = max(cell(0).width(), cell(1).width());
65         dim_.a = cell(0).height() + 1;
66         dim_.d = cell(1).height();
67 }
68
69
70 void MathFracInset::drawT(TextPainter & pain, int x, int y) const
71 {
72         int m = x + width() / 2;
73         cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
74         cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
75         if (!atop_)
76                 pain.horizontalLine(x, y, width());
77 }
78
79
80 void MathFracInset::write(WriteStream & os) const
81 {
82         if (atop_)
83                 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
84         else // it's \\frac
85                 MathNestInset::write(os);
86 }
87
88
89 string MathFracInset::name() const
90 {
91         return atop_ ? "atop" : "frac";
92 }
93
94
95 void MathFracInset::maplize(MapleStream & os) const
96 {
97         os << '(' << cell(0) << ")/(" << cell(1) << ')';
98 }
99
100
101 void MathFracInset::mathematicize(MathematicaStream & os) const
102 {
103         os << '(' << cell(0) << ")/(" << cell(1) << ')';
104 }
105
106
107 void MathFracInset::octavize(OctaveStream & os) const
108 {
109         os << '(' << cell(0) << ")/(" << cell(1) << ')';
110 }
111
112
113 void MathFracInset::mathmlize(MathMLStream & os) const
114 {
115         os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
116 }