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 "InsetMathXArrow.h"
15 #include "MathStream.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
19 #include "LaTeXFeatures.h"
26 InsetMathXArrow::InsetMathXArrow(Buffer * buf, docstring const & name)
27 : InsetMathFracBase(buf), name_(name)
31 Inset * InsetMathXArrow::clone() const
33 return new InsetMathXArrow(*this);
37 void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
39 ScriptChanger dummy(mi.base);
41 cell(0).metrics(mi, dim0);
43 cell(1).metrics(mi, dim1);
44 dim.wid = max(dim0.width(), dim1.width()) + 10;
45 dim.asc = dim0.height() + 10;
46 dim.des = dim1.height();
51 void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
53 ScriptChanger dummy(pi.base);
54 Dimension const dim = dimension(*pi.base.bv);
55 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
56 // center the cells with the decoration
57 cell(0).draw(pi, x + dim.width()/2 - dim0.width()/2, y - 10);
58 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
59 cell(1).draw(pi, x + dim.width()/2 - dim1.width()/2, y + dim1.height());
60 mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
61 drawMarkers(pi, x, y);
65 void InsetMathXArrow::write(WriteStream & os) const
67 MathEnsurer ensurer(os);
70 os << '[' << cell(1) << ']';
71 os << '{' << cell(0) << '}';
75 void InsetMathXArrow::normalize(NormalStream & os) const
77 os << "[xarrow " << name_ << ' ' << cell(0) << ' ' << cell(1) << ']';
81 void InsetMathXArrow::mathmlize(MathStream & ms) const
85 if (name_ == "xleftarrow")
87 else if (name_ == "xrightarrow")
89 else if (name_ == "xhookleftarrow")
91 else if (name_ == "xhookrightarrow")
93 else if (name_ == "xLeftarrow")
95 else if (name_ == "xRightarrow")
97 else if (name_ == "xleftrightarrow")
98 arrow = "↔";
99 else if (name_ == "xLeftrightarrow")
100 arrow = "⇔";
101 else if (name_ == "xleftharpoondown")
102 arrow = "↽";
103 else if (name_ == "xleftharpoonup")
104 arrow = "↼";
105 else if (name_ == "xleftrightharpoons")
106 arrow = "⇋";
107 else if (name_ == "xrightharpoondown")
108 arrow = "⇁";
109 else if (name_ == "xrightharpoonup")
110 arrow = "⇀";
111 else if (name_ == "xrightleftharpoons")
112 arrow = "⇌";
113 else if (name_ == "xmapsto")
115 ms << "<munderover accent='false' accentunder='false'>"
116 << arrow << cell(1) << cell(0)
121 void InsetMathXArrow::htmlize(HtmlStream & os) const
125 if (name_ == "xleftarrow")
127 else if (name_ == "xrightarrow")
129 else if (name_ == "xhookleftarrow")
131 else if (name_ == "xhookrightarrow")
133 else if (name_ == "xLeftarrow")
135 else if (name_ == "xRightarrow")
137 else if (name_ == "xleftrightarrow")
138 arrow = "↔";
139 else if (name_ == "xLeftrightarrow")
140 arrow = "⇔";
141 else if (name_ == "xleftharpoondown")
142 arrow = "↽";
143 else if (name_ == "xleftharpoonup")
144 arrow = "↼";
145 else if (name_ == "xleftrightharpoons")
146 arrow = "⇋";
147 else if (name_ == "xrightharpoondown")
148 arrow = "⇁";
149 else if (name_ == "xrightharpoonup")
150 arrow = "⇀";
151 else if (name_ == "xrightleftharpoons")
152 arrow = "⇌";
153 else if (name_ == "xmapsto")
155 os << MTag("span", "class='xarrow'")
156 << MTag("span", "class='xatop'") << cell(0) << ETag("span")
157 << MTag("span", "class='xabottom'") << arrow << ETag("span")
162 void InsetMathXArrow::validate(LaTeXFeatures & features) const
164 if (name_ == "xleftarrow" || name_ == "xrightarrow")
165 features.require("amsmath");
167 features.require("mathtools");
168 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
169 // CSS adapted from eLyXer
170 features.addCSSSnippet(
171 "span.xarrow{display: inline-block; vertical-align: middle; text-align:center;}\n"
172 "span.xatop{display: block;}\n"
173 "span.xabottom{display: block;}");
174 InsetMathNest::validate(features);