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();
58 void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
60 Changer dummy2 = pi.base.changeEnsureMath();
61 Changer dummy = pi.base.changeScript();
62 Dimension const dim = dimension(*pi.base.bv);
63 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
64 // center the cells with the decoration
65 cell(0).draw(pi, x + dim.width()/2 - dim0.width()/2, y - 10);
66 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
67 cell(1).draw(pi, x + dim.width()/2 - dim1.width()/2, y + dim1.height());
68 mathed_draw_deco(pi, x, y - 7, dim.wid, 5, name_);
72 void InsetMathXArrow::write(WriteStream & os) const
74 MathEnsurer ensurer(os);
77 os << '[' << cell(1) << ']';
78 os << '{' << cell(0) << '}';
82 void InsetMathXArrow::normalize(NormalStream & os) const
84 os << "[xarrow " << name_ << ' ' << cell(0) << ' ' << cell(1) << ']';
88 void InsetMathXArrow::mathmlize(MathStream & ms) const
92 if (name_ == "xleftarrow")
94 else if (name_ == "xrightarrow")
96 else if (name_ == "xhookleftarrow")
98 else if (name_ == "xhookrightarrow")
100 else if (name_ == "xLeftarrow")
102 else if (name_ == "xRightarrow")
104 else if (name_ == "xleftrightarrow")
105 arrow = "↔";
106 else if (name_ == "xLeftrightarrow")
107 arrow = "⇔";
108 else if (name_ == "xleftharpoondown")
109 arrow = "↽";
110 else if (name_ == "xleftharpoonup")
111 arrow = "↼";
112 else if (name_ == "xleftrightharpoons")
113 arrow = "⇋";
114 else if (name_ == "xrightharpoondown")
115 arrow = "⇁";
116 else if (name_ == "xrightharpoonup")
117 arrow = "⇀";
118 else if (name_ == "xrightleftharpoons")
119 arrow = "⇌";
120 else if (name_ == "xmapsto")
123 lyxerr << "mathmlize conversion for '" << name_ << "' not implemented" << endl;
124 LASSERT(false, arrow = "→");
126 ms << "<munderover accent='false' accentunder='false'>"
127 << arrow << cell(1) << cell(0)
132 void InsetMathXArrow::htmlize(HtmlStream & os) const
136 if (name_ == "xleftarrow")
138 else if (name_ == "xrightarrow")
140 else if (name_ == "xhookleftarrow")
142 else if (name_ == "xhookrightarrow")
144 else if (name_ == "xLeftarrow")
146 else if (name_ == "xRightarrow")
148 else if (name_ == "xleftrightarrow")
149 arrow = "↔";
150 else if (name_ == "xLeftrightarrow")
151 arrow = "⇔";
152 else if (name_ == "xleftharpoondown")
153 arrow = "↽";
154 else if (name_ == "xleftharpoonup")
155 arrow = "↼";
156 else if (name_ == "xleftrightharpoons")
157 arrow = "⇋";
158 else if (name_ == "xrightharpoondown")
159 arrow = "⇁";
160 else if (name_ == "xrightharpoonup")
161 arrow = "⇀";
162 else if (name_ == "xrightleftharpoons")
163 arrow = "⇌";
164 else if (name_ == "xmapsto")
167 lyxerr << "htmlize conversion for '" << name_ << "' not implemented" << endl;
168 LASSERT(false, arrow = "→");
170 os << MTag("span", "class='xarrow'")
171 << MTag("span", "class='xatop'") << cell(0) << ETag("span")
172 << MTag("span", "class='xabottom'") << arrow << ETag("span")
177 void InsetMathXArrow::validate(LaTeXFeatures & features) const
179 if (name_ == "xleftarrow" || name_ == "xrightarrow")
180 features.require("amsmath");
182 features.require("mathtools");
183 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
184 // CSS adapted from eLyXer
185 features.addCSSSnippet(
186 "span.xarrow{display: inline-block; vertical-align: middle; text-align:center;}\n"
187 "span.xatop{display: block;}\n"
188 "span.xabottom{display: block;}");
189 InsetMathNest::validate(features);