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 "math_decorationinset.h"
15 #include "math_data.h"
16 #include "math_support.h"
17 #include "math_parser.h"
18 #include "math_mathmlstream.h"
19 #include "math_streamstr.h"
21 #include "LaTeXFeatures.h"
24 #include "support/std_ostream.h"
27 MathDecorationInset::MathDecorationInset(latexkeys const * key)
28 : MathNestInset(1), key_(key)
30 // lyxerr << " creating deco " << key->name << std::endl;
34 std::auto_ptr<InsetBase> MathDecorationInset::doClone() const
36 return std::auto_ptr<InsetBase>(new MathDecorationInset(*this));
40 bool MathDecorationInset::upper() const
42 return key_->name.substr(0, 5) != "under";
46 bool MathDecorationInset::isScriptable() const
49 key_->name == "overbrace" ||
50 key_->name == "underbrace" ||
51 key_->name == "overleftarrow" ||
52 key_->name == "overrightarrow" ||
53 key_->name == "overleftrightarrow" ||
54 key_->name == "underleftarrow" ||
55 key_->name == "underrightarrow" ||
56 key_->name == "underleftrightarrow";
60 bool MathDecorationInset::protect() const
63 key_->name == "overbrace" ||
64 key_->name == "underbrace" ||
65 key_->name == "overleftarrow" ||
66 key_->name == "overrightarrow" ||
67 key_->name == "overleftrightarrow" ||
68 key_->name == "underleftarrow" ||
69 key_->name == "underrightarrow" ||
70 key_->name == "underleftrightarrow";
74 bool MathDecorationInset::wide() const
77 key_->name == "overline" ||
78 key_->name == "underline" ||
79 key_->name == "overbrace" ||
80 key_->name == "underbrace" ||
81 key_->name == "overleftarrow" ||
82 key_->name == "overrightarrow" ||
83 key_->name == "overleftrightarrow" ||
84 key_->name == "widehat" ||
85 key_->name == "widetilde" ||
86 key_->name == "underleftarrow" ||
87 key_->name == "underrightarrow" ||
88 key_->name == "underleftrightarrow";
92 bool MathDecorationInset::ams() const
95 key_->name == "overleftrightarrow" ||
96 key_->name == "underleftarrow" ||
97 key_->name == "underrightarrow" ||
98 key_->name == "underleftrightarrow";
102 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
104 cell(0).metrics(mi, dim);
106 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
107 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
110 dy_ = -dim.asc - dh_;
122 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
124 cell(0).draw(pi, x + 1, y);
126 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
128 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
129 y + dy_, dw_, dh_, key_->name);
130 drawMarkers(pi, x, y);
131 setPosCache(pi, x, y);
135 void MathDecorationInset::write(WriteStream & os) const
137 if (os.fragile() && protect())
139 os << '\\' << key_->name << '{' << cell(0) << '}';
143 void MathDecorationInset::normalize(NormalStream & os) const
145 os << "[deco " << key_->name << ' ' << cell(0) << ']';
149 void MathDecorationInset::infoize(std::ostream & os) const
151 os << "Deco: " << key_->name;
155 void MathDecorationInset::validate(LaTeXFeatures & features) const
158 features.require("amsmath");
159 MathNestInset::validate(features);