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"
28 InsetMathXArrow::InsetMathXArrow(Buffer * buf, docstring const & name)
29 : InsetMathFracBase(buf), name_(name)
33 Inset * InsetMathXArrow::clone() const
35 return new InsetMathXArrow(*this);
39 void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
41 ScriptChanger dummy(mi.base);
43 cell(0).metrics(mi, dim0);
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();
53 void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
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);
67 void InsetMathXArrow::write(WriteStream & os) const
69 MathEnsurer ensurer(os);
72 os << '[' << cell(1) << ']';
73 os << '{' << cell(0) << '}';
77 void InsetMathXArrow::normalize(NormalStream & os) const
79 os << "[xarrow " << name_ << ' ' << cell(0) << ' ' << cell(1) << ']';
83 void InsetMathXArrow::mathmlize(MathStream & ms) const
87 if (name_ == "xleftarrow")
89 else if (name_ == "xrightarrow")
91 else if (name_ == "xhookleftarrow")
93 else if (name_ == "xhookrightarrow")
95 else if (name_ == "xLeftarrow")
97 else if (name_ == "xRightarrow")
99 else if (name_ == "xleftrightarrow")
100 arrow = "↔";
101 else if (name_ == "xLeftrightarrow")
102 arrow = "⇔";
103 else if (name_ == "xleftharpoondown")
104 arrow = "↽";
105 else if (name_ == "xleftharpoonup")
106 arrow = "↼";
107 else if (name_ == "xleftrightharpoons")
108 arrow = "⇋";
109 else if (name_ == "xrightharpoondown")
110 arrow = "⇁";
111 else if (name_ == "xrightharpoonup")
112 arrow = "⇀";
113 else if (name_ == "xrightleftharpoons")
114 arrow = "⇌";
115 else if (name_ == "xmapsto")
118 lyxerr << "mathmlize conversion for '" << name_ << "' not implemented" << endl;
119 LASSERT(false, arrow = "→");
121 ms << "<munderover accent='false' accentunder='false'>"
122 << arrow << cell(1) << cell(0)
127 void InsetMathXArrow::htmlize(HtmlStream & os) const
131 if (name_ == "xleftarrow")
133 else if (name_ == "xrightarrow")
135 else if (name_ == "xhookleftarrow")
137 else if (name_ == "xhookrightarrow")
139 else if (name_ == "xLeftarrow")
141 else if (name_ == "xRightarrow")
143 else if (name_ == "xleftrightarrow")
144 arrow = "↔";
145 else if (name_ == "xLeftrightarrow")
146 arrow = "⇔";
147 else if (name_ == "xleftharpoondown")
148 arrow = "↽";
149 else if (name_ == "xleftharpoonup")
150 arrow = "↼";
151 else if (name_ == "xleftrightharpoons")
152 arrow = "⇋";
153 else if (name_ == "xrightharpoondown")
154 arrow = "⇁";
155 else if (name_ == "xrightharpoonup")
156 arrow = "⇀";
157 else if (name_ == "xrightleftharpoons")
158 arrow = "⇌";
159 else if (name_ == "xmapsto")
162 lyxerr << "htmlize conversion for '" << name_ << "' not implemented" << endl;
163 LASSERT(false, arrow = "→");
165 os << MTag("span", "class='xarrow'")
166 << MTag("span", "class='xatop'") << cell(0) << ETag("span")
167 << MTag("span", "class='xabottom'") << arrow << ETag("span")
172 void InsetMathXArrow::validate(LaTeXFeatures & features) const
174 if (name_ == "xleftarrow" || name_ == "xrightarrow")
175 features.require("amsmath");
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);