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 "MathExtern.h"
18 #include "MathParser.h"
19 #include "MathSupport.h"
20 #include "MathStream.h"
21 #include "MetricsInfo.h"
23 #include "LaTeXFeatures.h"
25 #include "support/debug.h"
26 #include "support/lassert.h"
35 InsetMathDecoration::InsetMathDecoration(Buffer * buf, latexkeys const * key)
36 : InsetMathNest(buf, 1), key_(key)
38 // lyxerr << " creating deco " << key->name << endl;
42 Inset * InsetMathDecoration::clone() const
44 return new InsetMathDecoration(*this);
48 bool InsetMathDecoration::upper() const
50 return key_->name.substr(0, 5) != "under";
54 bool InsetMathDecoration::isScriptable() const
57 key_->name == "overbrace" ||
58 key_->name == "underbrace" ||
59 key_->name == "overleftarrow" ||
60 key_->name == "overrightarrow" ||
61 key_->name == "overleftrightarrow" ||
62 key_->name == "underleftarrow" ||
63 key_->name == "underrightarrow" ||
64 key_->name == "underleftrightarrow";
68 bool InsetMathDecoration::protect() const
71 key_->name == "overbrace" ||
72 key_->name == "underbrace" ||
73 key_->name == "overleftarrow" ||
74 key_->name == "overrightarrow" ||
75 key_->name == "overleftrightarrow" ||
76 key_->name == "underleftarrow" ||
77 key_->name == "underrightarrow" ||
78 key_->name == "underleftrightarrow";
82 bool InsetMathDecoration::wide() const
85 key_->name == "overline" ||
86 key_->name == "underline" ||
87 key_->name == "overbrace" ||
88 key_->name == "underbrace" ||
89 key_->name == "overleftarrow" ||
90 key_->name == "overrightarrow" ||
91 key_->name == "overleftrightarrow" ||
92 key_->name == "widehat" ||
93 key_->name == "widetilde" ||
94 key_->name == "underleftarrow" ||
95 key_->name == "underrightarrow" ||
96 key_->name == "underleftrightarrow";
100 void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
102 cell(0).metrics(mi, dim);
104 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
105 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
108 dy_ = -dim.asc - dh_;
119 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
121 cell(0).draw(pi, x + 1, y);
122 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
124 mathed_draw_deco(pi, x + 1, y + dy_, dim0.wid, dh_, key_->name);
126 mathed_draw_deco(pi, x + 1 + (dim0.wid - dw_) / 2,
127 y + dy_, dw_, dh_, key_->name);
128 drawMarkers(pi, x, y);
129 setPosCache(pi, x, y);
133 void InsetMathDecoration::write(WriteStream & os) const
135 MathEnsurer ensurer(os);
136 if (os.fragile() && protect())
138 os << '\\' << key_->name << '{' << cell(0) << '}';
142 void InsetMathDecoration::normalize(NormalStream & os) const
144 os << "[deco " << key_->name << ' ' << cell(0) << ']';
148 void InsetMathDecoration::infoize(odocstream & os) const
150 os << "Deco: " << key_->name;
154 void InsetMathDecoration::validate(LaTeXFeatures & features) const
156 if (!key_->requires.empty())
157 features.require(to_utf8(key_->requires));
158 InsetMathNest::validate(features);
164 Attributes(bool o, string t)
170 typedef map<string, Attributes> Translator;
172 void buildTranslator(Translator & t) {
173 // the decorations we need to support are listed in lib/symbols
174 t["acute"] = Attributes(true, "´");
175 t["bar"] = Attributes(true, "‾");
176 t["breve"] = Attributes(true, "˘");
177 t["check"] = Attributes(true, "ˇ");
178 t["ddddot"] = Attributes(true, "⃜");
179 t["dddot"] = Attributes(true, "⃛");
180 t["ddot"] = Attributes(true, "¨");
181 t["dot"] = Attributes(true, "˙");
182 t["grave"] = Attributes(true, "`");
183 t["hat"] = Attributes(true, "ˆ");
184 t["mathring"] = Attributes(true, "˚");
185 t["overbrace"] = Attributes(true, "⏞");
186 t["overleftarrow"] = Attributes(true, "⟵");
187 t["overleftrightarrow"] = Attributes(true, "⟷");
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 t["underline"] = Attributes(false, "&;");
195 t["underrightarrow"] = Attributes(false, "⟶");
196 t["vec"] = Attributes(true, "→");
197 t["widehat"] = Attributes(true, "^");
198 t["widetilde"] = Attributes(true, "∼");
201 Translator const & translator() {
209 docstring InsetMathDecoration::mathmlize(MathStream & os) const
211 Translator const & t = translator();
212 Translator::const_iterator cur = t.find(to_utf8(key_->name));
213 LASSERT(cur != t.end(), return docstring());
214 char const * const outag = cur->second.over ? "mover" : "munder";
215 os << MTag(outag) << MTag("mrow");
216 docstring const rv = lyx::mathmlize(cell(0), os);
218 << from_ascii("<mo stretchy=\"true\">" + cur->second.tag + "</mo>")