]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
more IU
[lyx.git] / src / mathed / math_fracinset.C
1 /**
2  * \file math_fracinset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "math_fracinset.h"
15 #include "math_data.h"
16 #include "math_mathmlstream.h"
17 #include "textpainter.h"
18 #include "LColor.h"
19 #include "frontends/Painter.h"
20
21
22 using std::string;
23 using std::max;
24 using std::auto_ptr;
25
26
27 MathFracInset::MathFracInset(bool atop)
28         : atop_(atop)
29 {}
30
31
32 auto_ptr<InsetBase> MathFracInset::clone() const
33 {
34         return auto_ptr<InsetBase>(new MathFracInset(*this));
35 }
36
37
38 MathFracInset * MathFracInset::asFracInset()
39 {
40         return atop_ ? 0 : this;
41 }
42
43
44 MathFracInset const * MathFracInset::asFracInset() const
45 {
46         return atop_ ? 0 : this;
47 }
48
49
50 void MathFracInset::metrics(MetricsInfo & mi, Dimension & dim) const
51 {
52         FracChanger dummy(mi.base);
53         cell(0).metrics(mi);
54         cell(1).metrics(mi);
55         dim_.wid = max(cell(0).width(), cell(1).width()) + 2;
56         dim_.asc = cell(0).height() + 2 + 5;
57         dim_.des = cell(1).height() + 2 - 5;
58         dim = dim_;
59 }
60
61
62 void MathFracInset::draw(PainterInfo & pi, int x, int y) const
63 {
64         setPosCache(pi, x, y);
65         int m = x + dim_.wid / 2;
66         FracChanger dummy(pi.base);
67         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
68         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
69         if (!atop_)
70                 pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, LColor::math);
71 }
72
73
74 void MathFracInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
75 {
76         cell(0).metricsT(mi, dim);
77         cell(1).metricsT(mi, dim);
78         dim.wid = max(cell(0).width(), cell(1).width());
79         dim.asc = cell(0).height() + 1;
80         dim.des = cell(1).height();
81         //dim = dim_;
82 }
83
84
85 void MathFracInset::drawT(TextPainter & pain, int x, int y) const
86 {
87         int m = x + dim_.width() / 2;
88         cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
89         cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
90         if (!atop_)
91                 pain.horizontalLine(x, y, dim_.width());
92 }
93
94
95 void MathFracInset::write(WriteStream & os) const
96 {
97         if (atop_)
98                 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
99         else // it's \\frac
100                 MathNestInset::write(os);
101 }
102
103
104 string MathFracInset::name() const
105 {
106         return atop_ ? "atop" : "frac";
107 }
108
109
110 void MathFracInset::maple(MapleStream & os) const
111 {
112         os << '(' << cell(0) << ")/(" << cell(1) << ')';
113 }
114
115
116 void MathFracInset::mathematica(MathematicaStream & os) const
117 {
118         os << '(' << cell(0) << ")/(" << cell(1) << ')';
119 }
120
121
122 void MathFracInset::octave(OctaveStream & os) const
123 {
124         os << '(' << cell(0) << ")/(" << cell(1) << ')';
125 }
126
127
128 void MathFracInset::mathmlize(MathMLStream & os) const
129 {
130         os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
131 }