]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathXArrow.cpp
Cmake export tests: Added sublabel handling also to revertedTests
[lyx.git] / src / mathed / InsetMathXArrow.cpp
1 /**
2  * \file InsetMathXArrow.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/lassert.h"
14
15 #include "InsetMathXArrow.h"
16 #include "MathData.h"
17 #include "MathStream.h"
18 #include "MathStream.h"
19 #include "MathSupport.h"
20
21 #include "LaTeXFeatures.h"
22
23 using namespace std;
24
25 namespace lyx {
26
27
28 InsetMathXArrow::InsetMathXArrow(Buffer * buf, docstring const & name)
29         : InsetMathFracBase(buf), name_(name)
30 {}
31
32
33 Inset * InsetMathXArrow::clone() const
34 {
35         return new InsetMathXArrow(*this);
36 }
37
38
39 void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
40 {
41         ScriptChanger dummy(mi.base);
42         Dimension dim0;
43         cell(0).metrics(mi, dim0);
44         Dimension dim1;
45         cell(1).metrics(mi, dim1);
46         dim.wid = max(dim0.width(), dim1.width()) + 10;
47         dim.asc = dim0.height() + 10;
48         dim.des = dim1.height();
49         metricsMarkers(dim);
50 }
51
52
53 void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
54 {
55         ScriptChanger dummy(pi.base);
56         Dimension const dim = dimension(*pi.base.bv);
57         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
58         // center the cells with the decoration
59         cell(0).draw(pi, x + dim.width()/2 - dim0.width()/2, y - 10);
60         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
61         cell(1).draw(pi, x + dim.width()/2 - dim1.width()/2, y + dim1.height());
62         mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
63         drawMarkers(pi, x, y);
64 }
65
66
67 void InsetMathXArrow::write(WriteStream & os) const
68 {
69         MathEnsurer ensurer(os);
70         os << '\\' << name_;
71         if (!cell(1).empty())
72                 os << '[' << cell(1) << ']';
73         os << '{' << cell(0) << '}';
74 }
75
76
77 void InsetMathXArrow::normalize(NormalStream & os) const
78 {
79         os << "[xarrow " << name_ << ' ' <<  cell(0) << ' ' << cell(1) << ']';
80 }
81
82
83 void InsetMathXArrow::mathmlize(MathStream & ms) const
84 {
85         char const * arrow;
86         
87         if (name_ == "xleftarrow")
88                 arrow = "&larr;";
89         else if (name_ == "xrightarrow")
90                 arrow = "&rarr;";
91         else if (name_ == "xhookleftarrow")
92                 arrow = "&larrhk;";
93         else if (name_ == "xhookrightarrow")
94                 arrow = "&rarrhk;";
95         else if (name_ == "xLeftarrow")
96                 arrow = "&lArr;";
97         else if (name_ == "xRightarrow")
98                 arrow = "&rArr;";
99         else if (name_ == "xleftrightarrow")
100                 arrow = "&leftrightarrow;";
101         else if (name_ == "xLeftrightarrow")
102                 arrow = "&Leftrightarrow;";
103         else if (name_ == "xleftharpoondown")
104                 arrow = "&leftharpoondown;";
105         else if (name_ == "xleftharpoonup")
106                 arrow = "&leftharpoonup;";
107         else if (name_ == "xleftrightharpoons")
108                 arrow = "&leftrightharpoons;";
109         else if (name_ == "xrightharpoondown")
110                 arrow = "&rightharpoondown;";
111         else if (name_ == "xrightharpoonup")
112                 arrow = "&rightharpoonup;";
113         else if (name_ == "xrightleftharpoons")
114                 arrow = "&rightleftharpoons;";
115         else if (name_ == "xmapsto")
116                 arrow = "&mapsto;";
117         else {
118                 lyxerr << "mathmlize conversion for '" << name_ << "' not implemented" << endl;
119                 LASSERT(false, arrow = "&rarr;");
120         }
121         ms << "<munderover accent='false' accentunder='false'>"
122            << arrow << cell(1) << cell(0)
123            << "</munderover>";
124 }
125
126
127 void InsetMathXArrow::htmlize(HtmlStream & os) const
128 {
129         char const * arrow;
130
131         if (name_ == "xleftarrow")
132                 arrow = "&larr;";
133         else if (name_ == "xrightarrow")
134                 arrow = "&rarr;";
135         else if (name_ == "xhookleftarrow")
136                 arrow = "&larrhk;";
137         else if (name_ == "xhookrightarrow")
138                 arrow = "&rarrhk;";
139         else if (name_ == "xLeftarrow")
140                 arrow = "&lArr;";
141         else if (name_ == "xRightarrow")
142                 arrow = "&rArr;";
143         else if (name_ == "xleftrightarrow")
144                 arrow = "&leftrightarrow;";
145         else if (name_ == "xLeftrightarrow")
146                 arrow = "&Leftrightarrow;";
147         else if (name_ == "xleftharpoondown")
148                 arrow = "&leftharpoondown;";
149         else if (name_ == "xleftharpoonup")
150                 arrow = "&leftharpoonup;";
151         else if (name_ == "xleftrightharpoons")
152                 arrow = "&leftrightharpoons;";
153         else if (name_ == "xrightharpoondown")
154                 arrow = "&rightharpoondown;";
155         else if (name_ == "xrightharpoonup")
156                 arrow = "&rightharpoonup;";
157         else if (name_ == "xrightleftharpoons")
158                 arrow = "&rightleftharpoons;";
159         else if (name_ == "xmapsto")
160                 arrow = "&mapsto;";
161         else {
162                 lyxerr << "htmlize conversion for '" << name_ << "' not implemented" << endl;
163                 LASSERT(false, arrow = "&rarr;");
164         }
165         os << MTag("span", "class='xarrow'")
166                  << MTag("span", "class='xatop'") << cell(0) << ETag("span")
167                  << MTag("span", "class='xabottom'") << arrow << ETag("span")
168                  << ETag("span");
169 }
170
171
172 void InsetMathXArrow::validate(LaTeXFeatures & features) const
173 {
174         if (name_ == "xleftarrow" || name_ == "xrightarrow")
175                 features.require("amsmath");
176         else
177                 features.require("mathtools");
178         if (features.runparams().math_flavor == OutputParams::MathAsHTML)
179                 // CSS adapted from eLyXer
180                 features.addCSSSnippet(
181                         "span.xarrow{display: inline-block; vertical-align: middle; text-align:center;}\n"
182                         "span.xatop{display: block;}\n"
183                         "span.xabottom{display: block;}");
184         InsetMathNest::validate(features);
185 }
186
187
188 } // namespace lyx