5 #include "math_scriptinset.h"
6 #include "support/LOstream.h"
10 MathScriptInset::MathScriptInset()
11 : MathNestInset(2), up_(false), down_(false), limits_(0), symbol_(0)
15 MathScriptInset::MathScriptInset(bool up, bool down, MathInset * symbol)
16 : MathNestInset(2), up_(up), down_(down), limits_(0), symbol_(symbol)
20 MathScriptInset::MathScriptInset(MathScriptInset const & p)
21 : MathNestInset(p), up_(p.up_), down_(p.down_),
22 limits_(p.limits_), symbol_(p.symbol_ ? p.symbol_->clone() : 0)
26 MathScriptInset::~MathScriptInset()
32 MathInset * MathScriptInset::clone() const
34 return new MathScriptInset(*this);
38 bool MathScriptInset::up() const
44 bool MathScriptInset::down() const
50 void MathScriptInset::up(bool b)
56 void MathScriptInset::down(bool b)
62 bool MathScriptInset::idxRight(int &, int &) const
68 bool MathScriptInset::idxLeft(int &, int &) const
74 bool MathScriptInset::idxUp(int & idx, int & pos) const
76 if (idx == 0 || !up())
83 bool MathScriptInset::idxDown(int & idx, int & pos) const
85 if (idx == 1 || !down())
92 bool MathScriptInset::idxFirst(int & idx, int & pos) const
99 bool MathScriptInset::idxLast(int & idx, int & pos) const
101 idx = down() ? 1 : 0;
102 pos = cell(idx).size();
107 bool MathScriptInset::idxFirstUp(int & idx, int & pos) const
117 bool MathScriptInset::idxFirstDown(int & idx, int & pos) const
127 bool MathScriptInset::idxLastUp(int & idx, int & pos) const
132 pos = cell(idx).size();
137 bool MathScriptInset::idxLastDown(int & idx, int & pos) const
142 pos = cell(idx).size();
147 void MathScriptInset::write(std::ostream & os, bool fragile) const
150 symbol_->write(os, fragile);
152 os << (limits() == 1 ? "\\limits" : "\\nolimits");
156 cell(0).write(os, fragile);
161 cell(1).write(os, fragile);
168 void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
175 deleteit = !(up() || down());
179 int MathScriptInset::limits() const
185 void MathScriptInset::limits(int limits)
191 bool MathScriptInset::hasLimits() const
194 symbol_ && (limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY));
198 void MathScriptInset::writeNormal(std::ostream & os) const
200 if (limits() && symbol_)
201 os << "[" << (limits() ? "limits" : "nolimits") << "]";
203 os << "[superscript ";
204 cell(0).writeNormal(os);
209 cell(1).writeNormal(os);
215 void MathScriptInset::metrics(MathStyles st) const
218 MathStyles tt = smallerStyleScript(st);
220 xcell(0).metrics(tt);
221 xcell(1).metrics(tt);
223 width_ = std::max(xcell(0).width(), xcell(1).width());
226 symbol_->metrics(st);
227 int wid = symbol_->width();
228 ascent_ = symbol_->ascent();
229 descent_ = symbol_->descent();
230 width_ = std::max(width_, wid);
232 ascent_ += xcell(0).height() + 2;
233 dy0_ = - (ascent_ - xcell(0).ascent());
236 descent_ += xcell(1).height() + 2;
237 dy1_ = descent_ - xcell(1).descent();
239 dxx_ = (width_ - wid) / 2;
240 dx0_ = (width_ - xcell(0).width()) / 2;
241 dx1_ = (width_ - xcell(1).width()) / 2;
246 mathed_char_height(LM_TC_VAR, st, 'I', asc, des);
248 symbol_->metrics(st);
249 wid = symbol_->width();
250 asc = symbol_->ascent();
251 des = symbol_->descent();
253 ascent_ = up() ? xcell(0).height() + asc : 0;
254 descent_ = down() ? xcell(1).height() + des : 0;
256 dy0_ = - asc - xcell(0).descent();
257 dy1_ = des + xcell(1).ascent();
265 void MathScriptInset::draw(Painter & pain, int x, int y) const
271 symbol_->draw(pain, x + dxx_, y);
273 xcell(0).draw(pain, x + dx0_, y + dy0_);
275 xcell(1).draw(pain, x + dx1_, y + dy1_);