2 * \file InsetMathDecoration.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 "InsetMathDecoration.h"
16 #include "MathSupport.h"
17 #include "MathParser.h"
18 #include "MathMLStream.h"
19 #include "MathStream.h"
21 #include "LaTeXFeatures.h"
24 #include "support/std_ostream.h"
27 InsetMathDecoration::InsetMathDecoration(latexkeys const * key)
28 : InsetMathNest(1), key_(key)
30 // lyxerr << " creating deco " << key->name << std::endl;
34 std::auto_ptr<InsetBase> InsetMathDecoration::doClone() const
36 return std::auto_ptr<InsetBase>(new InsetMathDecoration(*this));
40 bool InsetMathDecoration::upper() const
42 return key_->name.substr(0, 5) != "under";
46 bool InsetMathDecoration::isScriptable() const
49 key_->name == "overbrace" ||
50 key_->name == "underbrace" ||
51 key_->name == "overleftarrow" ||
52 key_->name == "overrightarrow" ||
53 key_->name == "overleftrightarrow" ||
54 key_->name == "underleftarrow" ||
55 key_->name == "underrightarrow" ||
56 key_->name == "underleftrightarrow";
60 bool InsetMathDecoration::protect() const
63 key_->name == "overbrace" ||
64 key_->name == "underbrace" ||
65 key_->name == "overleftarrow" ||
66 key_->name == "overrightarrow" ||
67 key_->name == "overleftrightarrow" ||
68 key_->name == "underleftarrow" ||
69 key_->name == "underrightarrow" ||
70 key_->name == "underleftrightarrow";
74 bool InsetMathDecoration::wide() const
77 key_->name == "overline" ||
78 key_->name == "underline" ||
79 key_->name == "overbrace" ||
80 key_->name == "underbrace" ||
81 key_->name == "overleftarrow" ||
82 key_->name == "overrightarrow" ||
83 key_->name == "overleftrightarrow" ||
84 key_->name == "widehat" ||
85 key_->name == "widetilde" ||
86 key_->name == "underleftarrow" ||
87 key_->name == "underrightarrow" ||
88 key_->name == "underleftrightarrow";
92 bool InsetMathDecoration::ams() const
95 key_->name == "overleftrightarrow" ||
96 key_->name == "underleftarrow" ||
97 key_->name == "underrightarrow" ||
98 key_->name == "underleftrightarrow";
102 void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
104 cell(0).metrics(mi, dim);
106 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
107 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
110 dy_ = -dim.asc - dh_;
122 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
124 cell(0).draw(pi, x + 1, y);
126 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
128 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
129 y + dy_, dw_, dh_, key_->name);
130 drawMarkers(pi, x, y);
131 setPosCache(pi, x, y);
135 void InsetMathDecoration::write(WriteStream & os) const
137 if (os.fragile() && protect())
139 os << '\\' << key_->name << '{' << cell(0) << '}';
143 void InsetMathDecoration::normalize(NormalStream & os) const
145 os << "[deco " << key_->name << ' ' << cell(0) << ']';
149 void InsetMathDecoration::infoize(std::ostream & os) const
151 os << "Deco: " << key_->name;
155 void InsetMathDecoration::validate(LaTeXFeatures & features) const
158 features.require("amsmath");
159 InsetMathNest::validate(features);