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"
17 #include "MathParser.h"
18 #include "MathSupport.h"
19 #include "MathStream.h"
20 #include "MetricsInfo.h"
22 #include "LaTeXFeatures.h"
24 #include "support/debug.h"
32 InsetMathDecoration::InsetMathDecoration(latexkeys const * key)
33 : InsetMathNest(1), key_(key)
35 // lyxerr << " creating deco " << key->name << endl;
39 Inset * InsetMathDecoration::clone() const
41 return new InsetMathDecoration(*this);
45 bool InsetMathDecoration::upper() const
47 return key_->name.substr(0, 5) != "under";
51 bool InsetMathDecoration::isScriptable() const
54 key_->name == "overbrace" ||
55 key_->name == "underbrace" ||
56 key_->name == "overleftarrow" ||
57 key_->name == "overrightarrow" ||
58 key_->name == "overleftrightarrow" ||
59 key_->name == "underleftarrow" ||
60 key_->name == "underrightarrow" ||
61 key_->name == "underleftrightarrow";
65 bool InsetMathDecoration::protect() const
68 key_->name == "overbrace" ||
69 key_->name == "underbrace" ||
70 key_->name == "overleftarrow" ||
71 key_->name == "overrightarrow" ||
72 key_->name == "overleftrightarrow" ||
73 key_->name == "underleftarrow" ||
74 key_->name == "underrightarrow" ||
75 key_->name == "underleftrightarrow";
79 bool InsetMathDecoration::wide() const
82 key_->name == "overline" ||
83 key_->name == "underline" ||
84 key_->name == "overbrace" ||
85 key_->name == "underbrace" ||
86 key_->name == "overleftarrow" ||
87 key_->name == "overrightarrow" ||
88 key_->name == "overleftrightarrow" ||
89 key_->name == "widehat" ||
90 key_->name == "widetilde" ||
91 key_->name == "underleftarrow" ||
92 key_->name == "underrightarrow" ||
93 key_->name == "underleftrightarrow";
97 bool InsetMathDecoration::ams() const
100 key_->name == "overleftrightarrow" ||
101 key_->name == "underleftarrow" ||
102 key_->name == "underrightarrow" ||
103 key_->name == "underleftrightarrow";
107 void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
109 cell(0).metrics(mi, dim);
111 dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
112 dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
115 dy_ = -dim.asc - dh_;
126 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
128 cell(0).draw(pi, x + 1, y);
129 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
131 mathed_draw_deco(pi, x + 1, y + dy_, dim0.wid, dh_, key_->name);
133 mathed_draw_deco(pi, x + 1 + (dim0.wid - 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);