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"
17 #include "MathStream.h"
18 #include "MathStream.h"
19 #include "MathSupport.h"
21 #include "LaTeXFeatures.h"
30 InsetMathXArrow::InsetMathXArrow(Buffer * buf, docstring const & name)
31 : InsetMathFracBase(buf), name_(name)
35 Inset * InsetMathXArrow::clone() const
37 return new InsetMathXArrow(*this);
41 void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
43 ScriptChanger dummy(mi.base);
45 cell(0).metrics(mi, dim0);
47 cell(1).metrics(mi, dim1);
48 dim.wid = max(dim0.width(), dim1.width()) + 10;
49 dim.asc = dim0.height() + 10;
50 dim.des = dim1.height();
55 void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
57 ScriptChanger dummy(pi.base);
58 Dimension const dim = dimension(*pi.base.bv);
59 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
60 // center the cells with the decoration
61 cell(0).draw(pi, x + dim.width()/2 - dim0.width()/2, y - 10);
62 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
63 cell(1).draw(pi, x + dim.width()/2 - dim1.width()/2, y + dim1.height());
64 mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
65 drawMarkers(pi, x, y);
69 void InsetMathXArrow::write(WriteStream & os) const
71 MathEnsurer ensurer(os);
74 os << '[' << cell(1) << ']';
75 os << '{' << cell(0) << '}';
79 void InsetMathXArrow::normalize(NormalStream & os) const
81 os << "[xarrow " << name_ << ' ' << cell(0) << ' ' << cell(1) << ']';
85 void InsetMathXArrow::mathmlize(MathStream & ms) const
89 if (name_ == "xleftarrow")
91 else if (name_ == "xrightarrow")
93 else if (name_ == "xhookleftarrow")
95 else if (name_ == "xhookrightarrow")
97 else if (name_ == "xLeftarrow")
99 else if (name_ == "xRightarrow")
101 else if (name_ == "xleftrightarrow")
102 arrow = "↔";
103 else if (name_ == "xLeftrightarrow")
104 arrow = "⇔";
105 else if (name_ == "xleftharpoondown")
106 arrow = "↽";
107 else if (name_ == "xleftharpoonup")
108 arrow = "↼";
109 else if (name_ == "xleftrightharpoons")
110 arrow = "⇋";
111 else if (name_ == "xrightharpoondown")
112 arrow = "⇁";
113 else if (name_ == "xrightharpoonup")
114 arrow = "⇀";
115 else if (name_ == "xrightleftharpoons")
116 arrow = "⇌";
117 else if (name_ == "xmapsto")
120 lyxerr << "mathmlize conversion for '" << name_ << "' not implemented" << endl;
121 LASSERT(false, arrow = "→");
123 ms << "<munderover accent='false' accentunder='false'>"
124 << arrow << cell(1) << cell(0)
129 void InsetMathXArrow::htmlize(HtmlStream & os) const
133 if (name_ == "xleftarrow")
135 else if (name_ == "xrightarrow")
137 else if (name_ == "xhookleftarrow")
139 else if (name_ == "xhookrightarrow")
141 else if (name_ == "xLeftarrow")
143 else if (name_ == "xRightarrow")
145 else if (name_ == "xleftrightarrow")
146 arrow = "↔";
147 else if (name_ == "xLeftrightarrow")
148 arrow = "⇔";
149 else if (name_ == "xleftharpoondown")
150 arrow = "↽";
151 else if (name_ == "xleftharpoonup")
152 arrow = "↼";
153 else if (name_ == "xleftrightharpoons")
154 arrow = "⇋";
155 else if (name_ == "xrightharpoondown")
156 arrow = "⇁";
157 else if (name_ == "xrightharpoonup")
158 arrow = "⇀";
159 else if (name_ == "xrightleftharpoons")
160 arrow = "⇌";
161 else if (name_ == "xmapsto")
164 lyxerr << "htmlize conversion for '" << name_ << "' not implemented" << endl;
165 LASSERT(false, arrow = "→");
167 os << MTag("span", "class='xarrow'")
168 << MTag("span", "class='xatop'") << cell(0) << ETag("span")
169 << MTag("span", "class='xabottom'") << arrow << ETag("span")
174 void InsetMathXArrow::validate(LaTeXFeatures & features) const
176 if (name_ == "xleftarrow" || name_ == "xrightarrow")
177 features.require("amsmath");
179 features.require("mathtools");
180 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
181 // CSS adapted from eLyXer
182 features.addCSSSnippet(
183 "span.xarrow{display: inline-block; vertical-align: middle; text-align:center;}\n"
184 "span.xatop{display: block;}\n"
185 "span.xabottom{display: block;}");
186 InsetMathNest::validate(features);