5 #include "math_scriptinset.h"
6 #include "math_support.h"
7 #include "math_symbolinset.h"
8 #include "math_mathmlstream.h"
9 #include "support/LAssert.h"
13 MathScriptInset::MathScriptInset()
14 : MathNestInset(2), limits_(0)
21 MathScriptInset::MathScriptInset(bool up)
22 : MathNestInset(2), limits_(0)
29 MathInset * MathScriptInset::clone() const
31 return new MathScriptInset(*this);
35 MathScriptInset const * MathScriptInset::asScriptInset() const
41 MathScriptInset * MathScriptInset::asScriptInset()
47 MathXArray const & MathScriptInset::up() const
53 MathXArray const & MathScriptInset::down() const
59 MathXArray & MathScriptInset::up()
65 MathXArray & MathScriptInset::down()
71 void MathScriptInset::ensure(bool up)
77 bool MathScriptInset::covers(int x, int y) const
79 for (idx_type i = 0; i < 2; ++i)
80 if (has(i) && xcell(i).covers(x, y))
86 int MathScriptInset::dy0(MathInset const * nuc) const
91 int des = down().ascent();
95 des = std::max(des, nd);
100 int MathScriptInset::dy1(MathInset const * nuc) const
105 int asc = up().descent();
109 asc = std::max(asc, na);
110 asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I'));
115 int MathScriptInset::dx0(MathInset const * nuc) const
117 lyx::Assert(hasDown());
118 return hasLimits(nuc) ? (width(nuc) - down().width()) / 2 : nwid(nuc);
122 int MathScriptInset::dx1(MathInset const * nuc) const
124 lyx::Assert(hasUp());
125 return hasLimits(nuc) ? (width(nuc) - up().width()) / 2 : nwid(nuc);
129 int MathScriptInset::dxx(MathInset const * nuc) const
131 //lyx::Assert(nuc());
132 return hasLimits(nuc) ? (width(nuc) - nwid(nuc)) / 2 : 0;
136 int MathScriptInset::ascent(MathInset const * nuc) const
138 return dy1(nuc) + (hasUp() ? up().ascent() : 0);
142 int MathScriptInset::descent(MathInset const * nuc) const
144 return dy0(nuc) + (hasDown() ? down().descent() : 0);
148 int MathScriptInset::width(MathInset const * nuc) const
151 if (hasLimits(nuc)) {
154 wid = std::max(wid, up().width());
156 wid = std::max(wid, down().width());
159 wid = std::max(wid, up().width());
161 wid = std::max(wid, down().width());
168 int MathScriptInset::nwid(MathInset const * nuc) const
172 mathed_char_width(LM_TC_TEX, mi_, '.');
176 int MathScriptInset::nasc(MathInset const * nuc) const
178 return nuc ? nuc->ascent()
179 : mathed_char_ascent(LM_TC_VAR, mi_, 'I');
183 int MathScriptInset::ndes(MathInset const * nuc) const
185 return nuc ? nuc->descent()
186 : mathed_char_descent(LM_TC_VAR, mi_, 'I');
190 void MathScriptInset::metrics(MathMetricsInfo const & mi) const
196 void MathScriptInset::metrics(MathInset const * nuc,
197 MathMetricsInfo const & mi) const
199 MathNestInset::metrics(mi);
203 ascent_ = ascent(nuc);
204 descent_ = descent(nuc);
209 void MathScriptInset::draw(Painter & pain, int x, int y) const
211 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
216 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
220 nuc->draw(pain, x + dxx(nuc), y);
222 drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
225 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
228 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
232 bool MathScriptInset::hasLimits(MathInset const * nuc) const
240 // we can only display limits if the nucleus wants some
243 if (!nuc->isScriptable())
246 // per default \int has limits beside the \int even in displayed formulas
247 if (nuc->asSymbolInset())
248 if (nuc->asSymbolInset()->name().find("int") != string::npos)
251 // assume "real" limits for everything else
256 void MathScriptInset::removeEmptyScripts()
258 for (int i = 0; i <= 1; ++i)
259 if (script_[i] && !cell(i).size())
264 void MathScriptInset::removeScript(bool up)
271 bool MathScriptInset::has(bool up) const
277 bool MathScriptInset::hasUp() const
283 bool MathScriptInset::hasDown() const
289 bool MathScriptInset::idxRight(MathInset::idx_type &,
290 MathInset::pos_type &) const
296 bool MathScriptInset::idxLeft(MathInset::idx_type &,
297 MathInset::pos_type &) const
303 bool MathScriptInset::idxFirstUp(idx_type & idx, pos_type & pos) const
313 bool MathScriptInset::idxFirstDown(idx_type & idx, pos_type & pos) const
323 bool MathScriptInset::idxLastUp(idx_type & idx, pos_type & pos) const
328 pos = up().data_.size();
333 bool MathScriptInset::idxLastDown(idx_type & idx, pos_type & pos) const
338 pos = down().data_.size();
343 void MathScriptInset::write(WriteStream & os) const
345 //lyxerr << "unexpected call to MathScriptInset::write()\n";
350 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
354 if (nuc->takesLimits()) {
362 lyxerr << "suppressing {} \n";
366 if (hasDown() && down().data_.size())
367 os << "_{" << down().data_ << '}';
369 if (hasUp() && up().data_.size())
370 os << "^{" << up().data_ << '}';
374 void MathScriptInset::normalize(NormalStream & os) const
376 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
381 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
383 bool d = hasDown() && down().data_.size();
384 bool u = hasUp() && up().data_.size();
397 os << down().data_ << ']';
399 os << up().data_ << ']';
403 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
407 if (hasDown() && down().data_.size())
408 os << '[' << down().data_ << ']';
409 if (hasUp() && up().data_.size())
410 os << "^(" << up().data_ << ')';
414 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
416 bool d = hasDown() && down().data_.size();
417 bool u = hasUp() && up().data_.size();
420 os << MTag("msubsup");
432 os << down().data_ << up().data_ << ETag("msubsup");
434 os << up().data_ << ETag("msup");
436 os << down().data_ << ETag("msub");
440 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
444 if (hasDown() && down().data_.size())
445 os << '[' << down().data_ << ']';
446 if (hasUp() && up().data_.size())
447 os << "^(" << up().data_ << ')';