]> git.lyx.org Git - lyx.git/blob - src/mathed/math_rootinset.C
fix #1073
[lyx.git] / src / mathed / math_rootinset.C
1 /*
2  *  File:        math_root.C
3  *  Purpose:     Implementation of the root object
4  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5  *  Created:     January 1999
6  *  Description: Root math object
7  *
8  *  Copyright: 1999 Alejandro Aguilar Sierra
9  *
10  *   You are free to use and modify this code under the terms of
11  *   the GNU General Public Licence version 2 or later.
12  */
13
14
15 #include "math_rootinset.h"
16 #include "math_mathmlstream.h"
17 #include "frontends/Painter.h"
18
19
20 using std::max;
21
22
23 MathRootInset::MathRootInset()
24         : MathNestInset(2)
25 {}
26
27
28 MathInset * MathRootInset::clone() const
29 {
30         return new MathRootInset(*this);
31 }
32
33
34 void MathRootInset::metrics(MetricsInfo & mi) const
35 {
36         MathNestInset::metrics(mi);
37         dim_.a = max(cell(0).ascent()  + 5, cell(1).ascent())  + 2;
38         dim_.d = max(cell(1).descent() + 5, cell(0).descent()) + 2;
39         dim_.w = cell(0).width() + cell(1).width() + 10;
40         metricsMarkers();
41 }
42
43
44 void MathRootInset::draw(PainterInfo & pi, int x, int y) const
45 {
46         int const w = cell(0).width();
47         // the "exponent"
48         cell(0).draw(pi, x, y - 5 - cell(0).descent());
49         // the "base"
50         cell(1).draw(pi, x + w + 8, y);
51         int const a = ascent();
52         int const d = descent();
53         int xp[5];
54         int yp[5];
55         xp[0] = x + width();  yp[0] = y - a + 1;
56         xp[1] = x + w + 4;    yp[1] = y - a + 1;
57         xp[2] = x + w;        yp[2] = y + d;
58         xp[3] = x + w - 2;    yp[3] = y + (d - a)/2 + 2;
59         //xp[4] = x;            yp[4] = y + (d - a)/2 + 2;
60         xp[4] = x + w - 5;    yp[4] = y + (d - a)/2 + 4;
61         pi.pain.lines(xp, yp, 5, LColor::math);
62         drawMarkers(pi, x, y);
63 }
64
65
66 void MathRootInset::write(WriteStream & os) const
67 {
68         os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
69 }
70
71
72 void MathRootInset::normalize(NormalStream & os) const
73 {
74         os << "[root " << cell(0) << ' ' << cell(1) << ']';
75 }
76
77
78 bool MathRootInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, int) const
79 {
80         bool target = !up; // up ? 0 : 1;
81         if (idx == target)
82                 return false;
83         idx = target;
84         pos = target ? 0 : cell(0).size();
85         return true;
86 }
87
88
89 void MathRootInset::maple(MapleStream & os) const
90 {
91         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
92 }
93
94
95 void MathRootInset::octave(OctaveStream & os) const
96 {
97         os << "root(" << cell(1) << ',' << cell(0) << ')';
98 }
99
100
101 void MathRootInset::mathmlize(MathMLStream & os) const
102 {
103         os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
104 }