2 * \file InsetMathDecoration.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "InsetMathDecoration.h"
17 #include "MathParser.h"
18 #include "MathSupport.h"
19 #include "MathStream.h"
20 #include "MetricsInfo.h"
22 #include "LaTeXFeatures.h"
24 #include "support/debug.h"
25 #include "support/lassert.h"
34 InsetMathDecoration::InsetMathDecoration(Buffer * buf, latexkeys const * key)
35 : InsetMathNest(buf, 1), key_(key)
37 // lyxerr << " creating deco " << key->name << endl;
41 Inset * InsetMathDecoration::clone() const
43 return new InsetMathDecoration(*this);
47 bool InsetMathDecoration::upper() const
49 return key_->name.substr(0, 5) != "under";
53 bool InsetMathDecoration::isScriptable() const
56 key_->name == "overbrace" ||
57 key_->name == "underbrace" ||
58 key_->name == "overleftarrow" ||
59 key_->name == "overrightarrow" ||
60 key_->name == "overleftrightarrow" ||
61 key_->name == "underleftarrow" ||
62 key_->name == "underrightarrow" ||
63 key_->name == "underleftrightarrow";
67 bool InsetMathDecoration::protect() const
70 key_->name == "overbrace" ||
71 key_->name == "underbrace" ||
72 key_->name == "overleftarrow" ||
73 key_->name == "overrightarrow" ||
74 key_->name == "overleftrightarrow" ||
75 key_->name == "underleftarrow" ||
76 key_->name == "underrightarrow" ||
77 key_->name == "underleftrightarrow";
81 bool InsetMathDecoration::wide() const
84 key_->name == "overline" ||
85 key_->name == "underline" ||
86 key_->name == "overbrace" ||
87 key_->name == "underbrace" ||
88 key_->name == "overleftarrow" ||
89 key_->name == "overrightarrow" ||
90 key_->name == "overleftrightarrow" ||
91 key_->name == "widehat" ||
92 key_->name == "widetilde" ||
93 key_->name == "underleftarrow" ||
94 key_->name == "underrightarrow" ||
95 key_->name == "underleftrightarrow";
99 void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
101 cell(0).metrics(mi, dim);
103 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
104 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
107 dy_ = -dim.asc - dh_;
118 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
120 cell(0).draw(pi, x + 1, y);
121 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
123 mathed_draw_deco(pi, x + 1, y + dy_, dim0.wid, dh_, key_->name);
125 mathed_draw_deco(pi, x + 1 + (dim0.wid - dw_) / 2,
126 y + dy_, dw_, dh_, key_->name);
127 drawMarkers(pi, x, y);
128 setPosCache(pi, x, y);
132 void InsetMathDecoration::write(WriteStream & os) const
134 MathEnsurer ensurer(os);
135 if (os.fragile() && protect())
137 os << '\\' << key_->name << '{' << cell(0) << '}';
141 void InsetMathDecoration::normalize(NormalStream & os) const
143 os << "[deco " << key_->name << ' ' << cell(0) << ']';
147 void InsetMathDecoration::infoize(odocstream & os) const
149 os << "Deco: " << key_->name;
153 void InsetMathDecoration::validate(LaTeXFeatures & features) const
155 if (!key_->requires.empty())
156 features.require(to_utf8(key_->requires));
157 InsetMathNest::validate(features);
163 Attributes(bool o, string t)
169 typedef map<string, Attributes> Translator;
171 void buildTranslator(Translator & t) {
172 // the decorations we need to support are listed in lib/symbols
173 t["acute"] = Attributes(true, "´");
174 t["bar"] = Attributes(true, "‾");
175 t["breve"] = Attributes(true, "˘");
176 t["check"] = Attributes(true, "ˇ");
177 t["ddddot"] = Attributes(true, "⃜");
178 t["dddot"] = Attributes(true, "⃛");
179 t["ddot"] = Attributes(true, "¨");
180 t["dot"] = Attributes(true, "˙");
181 t["grave"] = Attributes(true, "`");
182 t["hat"] = Attributes(true, "ˆ");
183 t["mathring"] = Attributes(true, "˚");
184 t["overbrace"] = Attributes(true, "⏞");
185 t["overleftarrow"] = Attributes(true, "⟵");
186 t["overleftrightarrow"] = Attributes(true, "⟷");
187 t["overline"] = Attributes(false, "¯");
188 t["overrightarrow"] = Attributes(true, "⟶");
189 t["tilde"] = Attributes(true, "˜");
190 t["underbar"] = Attributes(false, "_");
191 t["underbrace"] = Attributes(false, "⏟");
192 t["underleftarrow"] = Attributes(false, "⟵");
193 t["underleftrightarrow"] = Attributes(false, "⟷");
194 // this is the macron, again, but it works
195 t["underline"] = Attributes(false, "¯");
196 t["underrightarrow"] = Attributes(false, "⟶");
197 t["vec"] = Attributes(true, "→");
198 t["widehat"] = Attributes(true, "^");
199 t["widetilde"] = Attributes(true, "∼");
202 Translator const & translator() {
210 void InsetMathDecoration::mathmlize(MathStream & os) const
212 Translator const & t = translator();
213 Translator::const_iterator cur = t.find(to_utf8(key_->name));
214 LASSERT(cur != t.end(), return);
215 char const * const outag = cur->second.over ? "mover" : "munder";
217 << MTag("mrow") << cell(0) << ETag("mrow")
218 << from_ascii("<mo stretchy=\"true\">" + cur->second.tag + "</mo>")