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"
20 #include "support/std_ostream.h"
25 MathDecorationInset::MathDecorationInset(latexkeys const * key)
26 : MathNestInset(1), key_(key)
30 auto_ptr<InsetBase> MathDecorationInset::clone() const
32 return auto_ptr<InsetBase>(new MathDecorationInset(*this));
36 bool MathDecorationInset::upper() const
38 return key_->name.substr(0, 5) != "under";
42 bool MathDecorationInset::isScriptable() const
45 key_->name == "overbrace" ||
46 key_->name == "underbrace" ||
47 key_->name == "overleftarrow" ||
48 key_->name == "overrightarrow" ||
49 key_->name == "overleftrightarrow" ||
50 key_->name == "underleftarrow" ||
51 key_->name == "underrightarrow" ||
52 key_->name == "underleftrightarrow";
56 bool MathDecorationInset::protect() const
59 key_->name == "overbrace" ||
60 key_->name == "underbrace" ||
61 key_->name == "overleftarrow" ||
62 key_->name == "overrightarrow" ||
63 key_->name == "overleftrightarrow" ||
64 key_->name == "underleftarrow" ||
65 key_->name == "underrightarrow" ||
66 key_->name == "underleftrightarrow";
70 bool MathDecorationInset::wide() const
73 key_->name == "overline" ||
74 key_->name == "underline" ||
75 key_->name == "overbrace" ||
76 key_->name == "underbrace" ||
77 key_->name == "overleftarrow" ||
78 key_->name == "overrightarrow" ||
79 key_->name == "overleftrightarrow" ||
80 key_->name == "widehat" ||
81 key_->name == "widetilde" ||
82 key_->name == "underleftarrow" ||
83 key_->name == "underrightarrow" ||
84 key_->name == "underleftrightarrow";
88 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
93 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
94 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
97 dy_ = -dim_.asc - dh_;
109 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
111 cell(0).draw(pi, x + 1, y);
113 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
115 mathed_draw_deco(pi, x + 1 + (pi.width - dw_) / 2,
116 y + dy_, dw_, dh_, key_->name);
117 drawMarkers(pi, x, y);
121 void MathDecorationInset::write(WriteStream & os) const
123 if (os.fragile() && protect())
125 os << '\\' << key_->name << '{' << cell(0) << '}';
129 void MathDecorationInset::normalize(NormalStream & os) const
131 os << "[deco " << key_->name << ' ' << cell(0) << ']';
135 void MathDecorationInset::infoize(std::ostream & os) const
137 os << "Deco: " << key_->name;