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_support.h"
16 #include "math_parser.h"
17 #include "math_mathmlstream.h"
18 #include "math_streamstr.h"
19 #include "support/LOstream.h"
24 MathDecorationInset::MathDecorationInset(latexkeys const * key)
25 : MathNestInset(1), key_(key)
29 auto_ptr<InsetBase> MathDecorationInset::clone() const
31 return auto_ptr<InsetBase>(new MathDecorationInset(*this));
35 bool MathDecorationInset::upper() const
37 return key_->name.substr(0, 5) != "under";
41 bool MathDecorationInset::isScriptable() const
44 key_->name == "overbrace" ||
45 key_->name == "underbrace" ||
46 key_->name == "overleftarrow" ||
47 key_->name == "overrightarrow" ||
48 key_->name == "overleftrightarrow" ||
49 key_->name == "underleftarrow" ||
50 key_->name == "underrightarrow" ||
51 key_->name == "underleftrightarrow";
55 bool MathDecorationInset::protect() const
58 key_->name == "overbrace" ||
59 key_->name == "underbrace" ||
60 key_->name == "overleftarrow" ||
61 key_->name == "overrightarrow" ||
62 key_->name == "overleftrightarrow" ||
63 key_->name == "underleftarrow" ||
64 key_->name == "underrightarrow" ||
65 key_->name == "underleftrightarrow";
69 bool MathDecorationInset::wide() const
72 key_->name == "overline" ||
73 key_->name == "underline" ||
74 key_->name == "overbrace" ||
75 key_->name == "underbrace" ||
76 key_->name == "overleftarrow" ||
77 key_->name == "overrightarrow" ||
78 key_->name == "overleftrightarrow" ||
79 key_->name == "widehat" ||
80 key_->name == "widetilde" ||
81 key_->name == "underleftarrow" ||
82 key_->name == "underrightarrow" ||
83 key_->name == "underleftrightarrow";
87 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
92 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
93 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
96 dy_ = -dim_.asc - dh_;
108 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
110 cell(0).draw(pi, x + 1, y);
112 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
114 mathed_draw_deco(pi, x + 1 + (pi.width - dw_) / 2,
115 y + dy_, dw_, dh_, key_->name);
116 drawMarkers(pi, x, y);
120 void MathDecorationInset::write(WriteStream & os) const
122 if (os.fragile() && protect())
124 os << '\\' << key_->name << '{' << cell(0) << '}';
128 void MathDecorationInset::normalize(NormalStream & os) const
130 os << "[deco " << key_->name << ' ' << cell(0) << ']';
134 void MathDecorationInset::infoize(std::ostream & os) const
136 os << "Deco: " << key_->name;