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"
23 #include "support/std_ostream.h"
28 MathDecorationInset::MathDecorationInset(latexkeys const * key)
29 : MathNestInset(1), key_(key)
31 // lyxerr << " creating deco " << key->name << std::endl;
35 auto_ptr<InsetBase> MathDecorationInset::clone() const
37 return auto_ptr<InsetBase>(new MathDecorationInset(*this));
41 bool MathDecorationInset::upper() const
43 return key_->name.substr(0, 5) != "under";
47 bool MathDecorationInset::isScriptable() const
50 key_->name == "overbrace" ||
51 key_->name == "underbrace" ||
52 key_->name == "overleftarrow" ||
53 key_->name == "overrightarrow" ||
54 key_->name == "overleftrightarrow" ||
55 key_->name == "underleftarrow" ||
56 key_->name == "underrightarrow" ||
57 key_->name == "underleftrightarrow";
61 bool MathDecorationInset::protect() const
64 key_->name == "overbrace" ||
65 key_->name == "underbrace" ||
66 key_->name == "overleftarrow" ||
67 key_->name == "overrightarrow" ||
68 key_->name == "overleftrightarrow" ||
69 key_->name == "underleftarrow" ||
70 key_->name == "underrightarrow" ||
71 key_->name == "underleftrightarrow";
75 bool MathDecorationInset::wide() const
78 key_->name == "overline" ||
79 key_->name == "underline" ||
80 key_->name == "overbrace" ||
81 key_->name == "underbrace" ||
82 key_->name == "overleftarrow" ||
83 key_->name == "overrightarrow" ||
84 key_->name == "overleftrightarrow" ||
85 key_->name == "widehat" ||
86 key_->name == "widetilde" ||
87 key_->name == "underleftarrow" ||
88 key_->name == "underrightarrow" ||
89 key_->name == "underleftrightarrow";
93 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
95 cell(0).metrics(mi, dim);
97 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
98 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
101 dy_ = -dim.asc - dh_;
113 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
115 cell(0).draw(pi, x + 1, y);
117 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
119 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
120 y + dy_, dw_, dh_, key_->name);
121 drawMarkers(pi, x, y);
125 void MathDecorationInset::write(WriteStream & os) const
127 if (os.fragile() && protect())
129 os << '\\' << key_->name << '{' << cell(0) << '}';
133 void MathDecorationInset::normalize(NormalStream & os) const
135 os << "[deco " << key_->name << ' ' << cell(0) << ']';
139 void MathDecorationInset::infoize(std::ostream & os) const
141 os << "Deco: " << key_->name;