]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
5b560c88a35804c8f9fa83583f0780f61c662f7d
[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
10
11 MathFracInset::MathFracInset(bool atop)
12         : atop_(atop)
13 {}
14
15
16 MathInset * MathFracInset::clone() const
17 {   
18         return new MathFracInset(*this);
19 }
20
21
22 MathFracInset * MathFracInset::asFracInset()
23 {
24         return atop_ ? 0 : this;
25 }
26
27
28 void MathFracInset::metrics(MathMetricsInfo const & mi) const
29 {
30         MathMetricsInfo m = mi;
31         smallerStyleFrac(m);
32         xcell(0).metrics(m);
33         xcell(1).metrics(m);
34         width_   = std::max(xcell(0).width(), xcell(1).width()) + 4; 
35         ascent_  = xcell(0).height() + 2 + 5;
36         descent_ = xcell(1).height() + 2 - 5; 
37 }
38
39
40 void MathFracInset::draw(Painter & pain, int x, int y) const
41 {
42         int m = x + width() / 2;
43         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
44         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 2 - 5);
45         if (!atop_)
46                 pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::math);
47 }
48
49
50 void MathFracInset::write(WriteStream & os) const
51 {
52         if (atop_)
53                 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
54         else
55                 os << "\\frac{" << cell(0) << "}{" << cell(1) << '}';
56 }
57
58
59 void MathFracInset::normalize(NormalStream & os) const
60 {
61         if (atop_) 
62                 os << "[atop ";
63         else
64                 os << "[frac ";
65         os << cell(0) << ' ' << cell(1) << ']';
66 }
67
68
69 void MathFracInset::maplize(MapleStream & os) const
70 {
71         os << '(' << cell(0) << ")/(" << cell(1) << ')';
72 }
73
74
75 void MathFracInset::mathmlize(MathMLStream & os) const
76 {
77         os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
78 }