5 #include "math_scriptinset.h"
6 #include "support/LOstream.h"
9 MathScriptInset::MathScriptInset()
10 : MathInset(2), up_(false), down_(false), limits_(0), symbol_(0)
14 MathScriptInset::MathScriptInset(bool up, bool down, MathInset * symbol)
15 : MathInset(2), up_(up), down_(down), limits_(0), symbol_(symbol)
19 MathScriptInset::MathScriptInset(MathScriptInset const & p)
20 : MathInset(p), up_(p.up_), down_(p.down_),
21 limits_(p.limits_), symbol_(p.symbol_ ? p.symbol_->clone() : 0)
25 MathScriptInset::~MathScriptInset()
31 MathInset * MathScriptInset::clone() const
33 return new MathScriptInset(*this);
37 bool MathScriptInset::up() const
43 bool MathScriptInset::down() const
49 void MathScriptInset::up(bool b)
55 void MathScriptInset::down(bool b)
61 bool MathScriptInset::idxRight(int &, int &) const
67 bool MathScriptInset::idxLeft(int &, int &) const
73 bool MathScriptInset::idxUp(int & idx, int & pos) const
75 if (idx == 0 || !up())
82 bool MathScriptInset::idxDown(int & idx, int & pos) const
84 if (idx == 1 || !down())
91 bool MathScriptInset::idxFirst(int & idx, int & pos) const
98 bool MathScriptInset::idxLast(int & idx, int & pos) const
100 idx = down() ? 1 : 0;
101 pos = cell(idx).size();
106 bool MathScriptInset::idxFirstUp(int & idx, int & pos) const
116 bool MathScriptInset::idxFirstDown(int & idx, int & pos) const
126 bool MathScriptInset::idxLastUp(int & idx, int & pos) const
131 pos = cell(idx).size();
136 bool MathScriptInset::idxLastDown(int & idx, int & pos) const
141 pos = cell(idx).size();
146 void MathScriptInset::Write(std::ostream & os, bool fragile) const
149 symbol_->Write(os, fragile);
151 os << (limits() == 1 ? "\\limits" : "\\nolimits");
155 cell(0).Write(os, fragile);
160 cell(1).Write(os, fragile);
167 void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
174 deleteit = !(up() || down());
178 int MathScriptInset::limits() const
184 void MathScriptInset::limits(int limits)
190 bool MathScriptInset::hasLimits() const
193 symbol_ && (limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY));
197 void MathScriptInset::WriteNormal(std::ostream & os) const
199 if (limits() && symbol_)
200 os << "[" << (limits() ? "limits" : "nolimits") << "]";
202 os << "[superscript ";
203 cell(0).WriteNormal(os);
208 cell(1).WriteNormal(os);
214 void MathScriptInset::Metrics(MathStyles st)
217 MathStyles tt = smallerStyleScript(st);
219 xcell(0).Metrics(tt);
220 xcell(1).Metrics(tt);
222 width_ = std::max(xcell(0).width(), xcell(1).width());
225 symbol_->Metrics(st);
226 int wid = symbol_->width();
227 ascent_ = symbol_->ascent();
228 descent_ = symbol_->descent();
229 width_ = std::max(width_, wid);
231 ascent_ += xcell(0).height() + 2;
232 dy0_ = - (ascent_ - xcell(0).ascent());
235 descent_ += xcell(1).height() + 2;
236 dy1_ = descent_ - xcell(1).descent();
238 dxx_ = (width_ - wid) / 2;
239 dx0_ = (width_ - xcell(0).width()) / 2;
240 dx1_ = (width_ - xcell(1).width()) / 2;
245 mathed_char_height(LM_TC_VAR, st, 'I', asc, des);
247 symbol_->Metrics(st);
248 wid = symbol_->width();
249 asc = symbol_->ascent();
250 des = symbol_->descent();
252 ascent_ = up() ? xcell(0).height() + asc : 0;
253 descent_ = down() ? xcell(1).height() + des : 0;
255 dy0_ = - asc - xcell(0).descent();
256 dy1_ = des + xcell(1).ascent();
264 void MathScriptInset::draw(Painter & pain, int x, int y)
270 symbol_->draw(pain, x + dxx_, y);
272 xcell(0).draw(pain, x + dx0_, y + dy0_);
274 xcell(1).draw(pain, x + dx1_, y + dy1_);