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