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 "MathStream.h"
19 #include "MathStream.h"
21 #include "LaTeXFeatures.h"
24 #include "support/std_ostream.h"
30 InsetMathDecoration::InsetMathDecoration(latexkeys const * key)
31 : InsetMathNest(1), key_(key)
33 // lyxerr << " creating deco " << key->name << std::endl;
37 std::auto_ptr<InsetBase> InsetMathDecoration::doClone() const
39 return std::auto_ptr<InsetBase>(new InsetMathDecoration(*this));
43 bool InsetMathDecoration::upper() const
45 return key_->name.substr(0, 5) != "under";
49 bool InsetMathDecoration::isScriptable() const
52 key_->name == "overbrace" ||
53 key_->name == "underbrace" ||
54 key_->name == "overleftarrow" ||
55 key_->name == "overrightarrow" ||
56 key_->name == "overleftrightarrow" ||
57 key_->name == "underleftarrow" ||
58 key_->name == "underrightarrow" ||
59 key_->name == "underleftrightarrow";
63 bool InsetMathDecoration::protect() const
66 key_->name == "overbrace" ||
67 key_->name == "underbrace" ||
68 key_->name == "overleftarrow" ||
69 key_->name == "overrightarrow" ||
70 key_->name == "overleftrightarrow" ||
71 key_->name == "underleftarrow" ||
72 key_->name == "underrightarrow" ||
73 key_->name == "underleftrightarrow";
77 bool InsetMathDecoration::wide() const
80 key_->name == "overline" ||
81 key_->name == "underline" ||
82 key_->name == "overbrace" ||
83 key_->name == "underbrace" ||
84 key_->name == "overleftarrow" ||
85 key_->name == "overrightarrow" ||
86 key_->name == "overleftrightarrow" ||
87 key_->name == "widehat" ||
88 key_->name == "widetilde" ||
89 key_->name == "underleftarrow" ||
90 key_->name == "underrightarrow" ||
91 key_->name == "underleftrightarrow";
95 bool InsetMathDecoration::ams() const
98 key_->name == "overleftrightarrow" ||
99 key_->name == "underleftarrow" ||
100 key_->name == "underrightarrow" ||
101 key_->name == "underleftrightarrow";
105 void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
107 cell(0).metrics(mi, dim);
109 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
110 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
113 dy_ = -dim.asc - dh_;
125 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
127 cell(0).draw(pi, x + 1, y);
129 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
131 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
132 y + dy_, dw_, dh_, key_->name);
133 drawMarkers(pi, x, y);
134 setPosCache(pi, x, y);
138 void InsetMathDecoration::write(WriteStream & os) const
140 if (os.fragile() && protect())
142 os << '\\' << key_->name << '{' << cell(0) << '}';
146 void InsetMathDecoration::normalize(NormalStream & os) const
148 os << "[deco " << key_->name << ' ' << cell(0) << ']';
152 void InsetMathDecoration::infoize(odocstream & os) const
154 os << "Deco: " << key_->name;
158 void InsetMathDecoration::validate(LaTeXFeatures & features) const
161 features.require("amsmath");
162 InsetMathNest::validate(features);