2 * \file math_decorationinset.C
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 "LaTeXFeatures.h"
15 #include "math_decorationinset.h"
16 #include "math_data.h"
17 #include "math_support.h"
18 #include "math_parser.h"
19 #include "math_mathmlstream.h"
20 #include "math_streamstr.h"
24 #include "support/std_ostream.h"
29 MathDecorationInset::MathDecorationInset(latexkeys const * key)
30 : MathNestInset(1), key_(key)
32 // lyxerr << " creating deco " << key->name << std::endl;
36 auto_ptr<InsetBase> MathDecorationInset::doClone() const
38 return auto_ptr<InsetBase>(new MathDecorationInset(*this));
42 bool MathDecorationInset::upper() const
44 return key_->name.substr(0, 5) != "under";
48 bool MathDecorationInset::isScriptable() const
51 key_->name == "overbrace" ||
52 key_->name == "underbrace" ||
53 key_->name == "overleftarrow" ||
54 key_->name == "overrightarrow" ||
55 key_->name == "overleftrightarrow" ||
56 key_->name == "underleftarrow" ||
57 key_->name == "underrightarrow" ||
58 key_->name == "underleftrightarrow";
62 bool MathDecorationInset::protect() const
65 key_->name == "overbrace" ||
66 key_->name == "underbrace" ||
67 key_->name == "overleftarrow" ||
68 key_->name == "overrightarrow" ||
69 key_->name == "overleftrightarrow" ||
70 key_->name == "underleftarrow" ||
71 key_->name == "underrightarrow" ||
72 key_->name == "underleftrightarrow";
76 bool MathDecorationInset::wide() const
79 key_->name == "overline" ||
80 key_->name == "underline" ||
81 key_->name == "overbrace" ||
82 key_->name == "underbrace" ||
83 key_->name == "overleftarrow" ||
84 key_->name == "overrightarrow" ||
85 key_->name == "overleftrightarrow" ||
86 key_->name == "widehat" ||
87 key_->name == "widetilde" ||
88 key_->name == "underleftarrow" ||
89 key_->name == "underrightarrow" ||
90 key_->name == "underleftrightarrow";
94 bool MathDecorationInset::ams() const
97 key_->name == "overleftrightarrow" ||
98 key_->name == "underleftarrow" ||
99 key_->name == "underrightarrow" ||
100 key_->name == "underleftrightarrow";
104 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
106 cell(0).metrics(mi, dim);
108 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
109 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
112 dy_ = -dim.asc - dh_;
124 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
126 cell(0).draw(pi, x + 1, y);
128 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
130 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
131 y + dy_, dw_, dh_, key_->name);
132 drawMarkers(pi, x, y);
136 void MathDecorationInset::validate(LaTeXFeatures & features) const
139 features.require("amsmath");
143 void MathDecorationInset::write(WriteStream & os) const
145 if (os.fragile() && protect())
147 os << '\\' << key_->name << '{' << cell(0) << '}';
151 void MathDecorationInset::normalize(NormalStream & os) const
153 os << "[deco " << key_->name << ' ' << cell(0) << ']';
157 void MathDecorationInset::infoize(std::ostream & os) const
159 os << "Deco: " << key_->name;