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 "support/std_ostream.h"
26 MathDecorationInset::MathDecorationInset(latexkeys const * key)
27 : MathNestInset(1), key_(key)
31 auto_ptr<InsetBase> MathDecorationInset::clone() const
33 return auto_ptr<InsetBase>(new MathDecorationInset(*this));
37 bool MathDecorationInset::upper() const
39 return key_->name.substr(0, 5) != "under";
43 bool MathDecorationInset::isScriptable() const
46 key_->name == "overbrace" ||
47 key_->name == "underbrace" ||
48 key_->name == "overleftarrow" ||
49 key_->name == "overrightarrow" ||
50 key_->name == "overleftrightarrow" ||
51 key_->name == "underleftarrow" ||
52 key_->name == "underrightarrow" ||
53 key_->name == "underleftrightarrow";
57 bool MathDecorationInset::protect() const
60 key_->name == "overbrace" ||
61 key_->name == "underbrace" ||
62 key_->name == "overleftarrow" ||
63 key_->name == "overrightarrow" ||
64 key_->name == "overleftrightarrow" ||
65 key_->name == "underleftarrow" ||
66 key_->name == "underrightarrow" ||
67 key_->name == "underleftrightarrow";
71 bool MathDecorationInset::wide() const
74 key_->name == "overline" ||
75 key_->name == "underline" ||
76 key_->name == "overbrace" ||
77 key_->name == "underbrace" ||
78 key_->name == "overleftarrow" ||
79 key_->name == "overrightarrow" ||
80 key_->name == "overleftrightarrow" ||
81 key_->name == "widehat" ||
82 key_->name == "widetilde" ||
83 key_->name == "underleftarrow" ||
84 key_->name == "underrightarrow" ||
85 key_->name == "underleftrightarrow";
89 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
91 cell(0).metrics(mi, dim);
93 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
94 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
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 + (cell(0).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;