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