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