2 * \file InsetMathXArrow.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "support/lassert.h"
15 #include "InsetMathXArrow.h"
18 #include "MathStream.h"
19 #include "MathStream.h"
20 #include "MathSupport.h"
22 #include "LaTeXFeatures.h"
23 #include "MetricsInfo.h"
33 InsetMathXArrow::InsetMathXArrow(Buffer * buf, docstring const & name)
34 : InsetMathFracBase(buf), name_(name)
38 Inset * InsetMathXArrow::clone() const
40 return new InsetMathXArrow(*this);
44 void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
46 Changer dummy2 = mi.base.changeEnsureMath();
47 Changer dummy = mi.base.changeScript();
49 cell(0).metrics(mi, dim0);
51 cell(1).metrics(mi, dim1);
52 dim.wid = max(dim0.width(), dim1.width()) + 10;
53 dim.asc = dim0.height() + 10;
54 dim.des = dim1.height();
55 metricsMarkers(mi, dim);
59 void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
61 Changer dummy2 = pi.base.changeEnsureMath();
62 Changer dummy = pi.base.changeScript();
63 Dimension const dim = dimension(*pi.base.bv);
64 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
65 // center the cells with the decoration
66 cell(0).draw(pi, x + dim.width()/2 - dim0.width()/2, y - 10);
67 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
68 cell(1).draw(pi, x + dim.width()/2 - dim1.width()/2, y + dim1.height());
69 mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
70 drawMarkers(pi, x, y);
74 void InsetMathXArrow::write(WriteStream & os) const
76 MathEnsurer ensurer(os);
79 os << '[' << cell(1) << ']';
80 os << '{' << cell(0) << '}';
84 void InsetMathXArrow::normalize(NormalStream & os) const
86 os << "[xarrow " << name_ << ' ' << cell(0) << ' ' << cell(1) << ']';
90 void InsetMathXArrow::mathmlize(MathStream & ms) const
94 if (name_ == "xleftarrow")
96 else if (name_ == "xrightarrow")
98 else if (name_ == "xhookleftarrow")
100 else if (name_ == "xhookrightarrow")
102 else if (name_ == "xLeftarrow")
104 else if (name_ == "xRightarrow")
106 else if (name_ == "xleftrightarrow")
107 arrow = "↔";
108 else if (name_ == "xLeftrightarrow")
109 arrow = "⇔";
110 else if (name_ == "xleftharpoondown")
111 arrow = "↽";
112 else if (name_ == "xleftharpoonup")
113 arrow = "↼";
114 else if (name_ == "xleftrightharpoons")
115 arrow = "⇋";
116 else if (name_ == "xrightharpoondown")
117 arrow = "⇁";
118 else if (name_ == "xrightharpoonup")
119 arrow = "⇀";
120 else if (name_ == "xrightleftharpoons")
121 arrow = "⇌";
122 else if (name_ == "xmapsto")
125 lyxerr << "mathmlize conversion for '" << name_ << "' not implemented" << endl;
126 LASSERT(false, arrow = "→");
128 ms << "<munderover accent='false' accentunder='false'>"
129 << arrow << cell(1) << cell(0)
134 void InsetMathXArrow::htmlize(HtmlStream & os) const
138 if (name_ == "xleftarrow")
140 else if (name_ == "xrightarrow")
142 else if (name_ == "xhookleftarrow")
144 else if (name_ == "xhookrightarrow")
146 else if (name_ == "xLeftarrow")
148 else if (name_ == "xRightarrow")
150 else if (name_ == "xleftrightarrow")
151 arrow = "↔";
152 else if (name_ == "xLeftrightarrow")
153 arrow = "⇔";
154 else if (name_ == "xleftharpoondown")
155 arrow = "↽";
156 else if (name_ == "xleftharpoonup")
157 arrow = "↼";
158 else if (name_ == "xleftrightharpoons")
159 arrow = "⇋";
160 else if (name_ == "xrightharpoondown")
161 arrow = "⇁";
162 else if (name_ == "xrightharpoonup")
163 arrow = "⇀";
164 else if (name_ == "xrightleftharpoons")
165 arrow = "⇌";
166 else if (name_ == "xmapsto")
169 lyxerr << "htmlize conversion for '" << name_ << "' not implemented" << endl;
170 LASSERT(false, arrow = "→");
172 os << MTag("span", "class='xarrow'")
173 << MTag("span", "class='xatop'") << cell(0) << ETag("span")
174 << MTag("span", "class='xabottom'") << arrow << ETag("span")
179 void InsetMathXArrow::validate(LaTeXFeatures & features) const
181 if (name_ == "xleftarrow" || name_ == "xrightarrow")
182 features.require("amsmath");
184 features.require("mathtools");
185 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
186 // CSS adapted from eLyXer
187 features.addCSSSnippet(
188 "span.xarrow{display: inline-block; vertical-align: middle; text-align:center;}\n"
189 "span.xatop{display: block;}\n"
190 "span.xabottom{display: block;}");
191 InsetMathNest::validate(features);