]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathRoot.cpp
Revert some recent test changes
[lyx.git] / src / mathed / InsetMathRoot.cpp
1 /**
2  * \file InsetMathRoot.cpp
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 "InsetMathRoot.h"
15
16 #include "LaTeXFeatures.h"
17 #include "MathData.h"
18 #include "MathStream.h"
19 #include "Cursor.h"
20
21 #include "frontends/Painter.h"
22
23 using namespace std;
24
25 namespace lyx {
26
27
28 InsetMathRoot::InsetMathRoot(Buffer * buf)
29         : InsetMathNest(buf, 2)
30 {}
31
32
33 Inset * InsetMathRoot::clone() const
34 {
35         return new InsetMathRoot(*this);
36 }
37
38
39 void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
40 {
41         InsetMathNest::metrics(mi);
42         Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
43         Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
44         dim.asc = max(dim0.ascent()  + 5, dim1.ascent())  + 2;
45         dim.des = max(dim0.descent() - 5, dim1.descent()) + 2;
46         dim.wid = dim0.width() + dim1.width() + 10;
47         metricsMarkers(dim);
48 }
49
50
51 void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
52 {
53         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
54         int const w = dim0.width();
55         // the "exponent"
56         cell(0).draw(pi, x, y - 5 - dim0.descent());
57         // the "base"
58         cell(1).draw(pi, x + w + 8, y);
59         Dimension const dim = dimension(*pi.base.bv);
60         int const a = dim.ascent();
61         int const d = dim.descent();
62         int xp[4];
63         int yp[4];
64         pi.pain.line(x + dim.width(), y - a + 1,
65                                 x + w + 4, y - a + 1, pi.base.font.color());
66         xp[0] = x + w + 4;         yp[0] = y - a + 1;
67         xp[1] = x + w;             yp[1] = y + d;
68         xp[2] = x + w - 2;         yp[2] = y + (d - a)/2 + 2;
69         xp[3] = x + w - 5;         yp[3] = y + (d - a)/2 + 4;
70         pi.pain.lines(xp, yp, 4, pi.base.font.color());
71         drawMarkers(pi, x, y);
72 }
73
74
75 void InsetMathRoot::write(WriteStream & os) const
76 {
77         MathEnsurer ensurer(os);
78         os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
79 }
80
81
82 void InsetMathRoot::normalize(NormalStream & os) const
83 {
84         os << "[root " << cell(0) << ' ' << cell(1) << ']';
85 }
86
87
88 bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const
89 {
90         Cursor::idx_type const target = up ? 0 : 1;
91         if (cur.idx() == target)
92                 return false;
93         cur.idx() = target;
94         cur.pos() = up ? cur.lastpos() : 0;
95         return true;
96 }
97
98
99 void InsetMathRoot::maple(MapleStream & os) const
100 {
101         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
102 }
103
104
105 void InsetMathRoot::mathematica(MathematicaStream & os) const
106 {
107         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
108 }
109
110
111 void InsetMathRoot::octave(OctaveStream & os) const
112 {
113         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
114 }
115
116
117 void InsetMathRoot::mathmlize(MathStream & os) const
118 {
119         os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
120 }
121
122
123 void InsetMathRoot::htmlize(HtmlStream & os) const
124 {
125         os << MTag("span", "class='root'")
126            << MTag("sup") << cell(0) << ETag("sup")
127            << from_ascii("&radic;") 
128            << MTag("span", "class='rootof'")    << cell(1) << ETag("span") 
129                  << ETag("span");
130 }
131
132
133 void InsetMathRoot::validate(LaTeXFeatures & features) const
134 {
135         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
136                 features.addCSSSnippet(
137                         "span.rootof{border-top: thin solid black;}\n"
138                         "span.root sup{font-size: 75%;}");
139         InsetMathNest::validate(features);
140 }
141
142 } // namespace lyx