2 * \file InsetMathDecoration.cpp
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 "InsetMathDecoration.h"
16 #include "MathParser.h"
17 #include "MathSupport.h"
18 #include "MathStream.h"
20 #include "LaTeXFeatures.h"
23 #include "support/std_ostream.h"
29 InsetMathDecoration::InsetMathDecoration(latexkeys const * key)
30 : InsetMathNest(1), key_(key)
32 // lyxerr << " creating deco " << key->name << std::endl;
36 std::auto_ptr<InsetBase> InsetMathDecoration::doClone() const
38 return std::auto_ptr<InsetBase>(new InsetMathDecoration(*this));
42 bool InsetMathDecoration::upper() const
44 return key_->name.substr(0, 5) != "under";
48 bool InsetMathDecoration::isScriptable() const
51 key_->name == "overbrace" ||
52 key_->name == "underbrace" ||
53 key_->name == "overleftarrow" ||
54 key_->name == "overrightarrow" ||
55 key_->name == "overleftrightarrow" ||
56 key_->name == "underleftarrow" ||
57 key_->name == "underrightarrow" ||
58 key_->name == "underleftrightarrow";
62 bool InsetMathDecoration::protect() const
65 key_->name == "overbrace" ||
66 key_->name == "underbrace" ||
67 key_->name == "overleftarrow" ||
68 key_->name == "overrightarrow" ||
69 key_->name == "overleftrightarrow" ||
70 key_->name == "underleftarrow" ||
71 key_->name == "underrightarrow" ||
72 key_->name == "underleftrightarrow";
76 bool InsetMathDecoration::wide() const
79 key_->name == "overline" ||
80 key_->name == "underline" ||
81 key_->name == "overbrace" ||
82 key_->name == "underbrace" ||
83 key_->name == "overleftarrow" ||
84 key_->name == "overrightarrow" ||
85 key_->name == "overleftrightarrow" ||
86 key_->name == "widehat" ||
87 key_->name == "widetilde" ||
88 key_->name == "underleftarrow" ||
89 key_->name == "underrightarrow" ||
90 key_->name == "underleftrightarrow";
94 bool InsetMathDecoration::ams() const
97 key_->name == "overleftrightarrow" ||
98 key_->name == "underleftarrow" ||
99 key_->name == "underrightarrow" ||
100 key_->name == "underleftrightarrow";
104 bool InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
106 cell(0).metrics(mi, dim);
108 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
109 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
112 dy_ = -dim.asc - dh_;
127 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
129 cell(0).draw(pi, x + 1, y);
131 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
133 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
134 y + dy_, dw_, dh_, key_->name);
135 drawMarkers(pi, x, y);
136 setPosCache(pi, x, y);
140 void InsetMathDecoration::write(WriteStream & os) const
142 if (os.fragile() && protect())
144 os << '\\' << key_->name << '{' << cell(0) << '}';
148 void InsetMathDecoration::normalize(NormalStream & os) const
150 os << "[deco " << key_->name << ' ' << cell(0) << ']';
154 void InsetMathDecoration::infoize(odocstream & os) const
156 os << "Deco: " << key_->name;
160 void InsetMathDecoration::validate(LaTeXFeatures & features) const
163 features.require("amsmath");
164 InsetMathNest::validate(features);