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