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"
16 MathScriptInset::MathScriptInset()
17 : MathNestInset(2), limits_(0)
24 MathScriptInset::MathScriptInset(bool up)
25 : MathNestInset(2), limits_(0)
32 MathInset * MathScriptInset::clone() const
34 return new MathScriptInset(*this);
38 MathScriptInset const * MathScriptInset::asScriptInset() const
44 MathScriptInset * MathScriptInset::asScriptInset()
50 MathXArray const & MathScriptInset::up() const
56 MathXArray const & MathScriptInset::down() const
62 MathXArray & MathScriptInset::up()
68 MathXArray & MathScriptInset::down()
74 void MathScriptInset::ensure(bool up)
80 int MathScriptInset::dy0(MathInset const * nuc) const
85 int des = down().ascent();
94 int MathScriptInset::dy1(MathInset const * nuc) const
99 int asc = up().descent();
104 asc = max(asc, mathed_char_ascent(font_, 'I'));
109 int MathScriptInset::dx0(MathInset const * nuc) const
111 lyx::Assert(hasDown());
112 return hasLimits(nuc) ? (width2(nuc) - down().width()) / 2 : nwid(nuc);
116 int MathScriptInset::dx1(MathInset const * nuc) const
118 lyx::Assert(hasUp());
119 return hasLimits(nuc) ? (width2(nuc) - up().width()) / 2 : nwid(nuc);
123 int MathScriptInset::dxx(MathInset const * nuc) const
125 //lyx::Assert(nuc());
126 return hasLimits(nuc) ? (width2(nuc) - nwid(nuc)) / 2 : 0;
130 int MathScriptInset::ascent2(MathInset const * nuc) const
132 return dy1(nuc) + (hasUp() ? up().ascent() : 0);
136 int MathScriptInset::descent2(MathInset const * nuc) const
138 return dy0(nuc) + (hasDown() ? down().descent() : 0);
142 int MathScriptInset::width2(MathInset const * nuc) const
145 if (hasLimits(nuc)) {
148 wid = max(wid, up().width());
150 wid = max(wid, down().width());
153 wid = max(wid, up().width());
155 wid = max(wid, down().width());
162 int MathScriptInset::nwid(MathInset const * nuc) const
164 return nuc ? nuc->width() : mathed_char_width(font_, '.');
168 int MathScriptInset::nasc(MathInset const * nuc) const
170 return nuc ? nuc->ascent() : mathed_char_ascent(font_, 'I');
174 int MathScriptInset::ndes(MathInset const * nuc) const
176 return nuc ? nuc->descent() : mathed_char_descent(font_, 'I');
180 void MathScriptInset::metrics(MathMetricsInfo & mi) const
186 void MathScriptInset::metrics(MathInset const * nuc, MathMetricsInfo & mi) const
188 MathScriptChanger dummy(mi.base);
189 MathNestInset::metrics(mi);
192 ascent_ = ascent2(nuc);
193 descent_ = descent2(nuc);
194 width_ = width2(nuc);
198 void MathScriptInset::draw(MathPainterInfo & pi, int x, int y) const
200 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
201 MathScriptChanger dummy(pi.base);
206 void MathScriptInset::metricsT(TextMetricsInfo const & mi) const
212 void MathScriptInset::metricsT(MathInset const * nuc,
213 TextMetricsInfo const & mi) const
221 //ascent_ = ascent2(nuc);
222 //descent_ = descent2(nuc);
223 //width_ = width2(nuc);
227 void MathScriptInset::draw(MathInset const * nuc, MathPainterInfo & pi,
230 MathScriptChanger dummy(pi.base);
232 nuc->draw(pi, x + dxx(nuc), y);
234 drawStr(pi, font_, x + dxx(nuc), y, ".");
237 up().draw(pi, x + dx1(nuc), y - dy1(nuc));
239 down().draw(pi, x + dx0(nuc), y + dy0(nuc));
243 void MathScriptInset::drawT(TextPainter & pain, int x, int y) const
245 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
246 drawT(0, pain, x, y);
250 void MathScriptInset::drawT(MathInset const * nuc, TextPainter & pain,
254 nuc->drawT(pain, x + dxx(nuc), y);
256 up().drawT(pain, x + dx1(nuc), y - dy1(nuc));
258 down().drawT(pain, x + dx0(nuc), y + dy0(nuc));
263 bool MathScriptInset::hasLimits(MathInset const * nuc) const
271 // we can only display limits if the nucleus wants some
274 if (!nuc->isScriptable())
277 // per default \int has limits beside the \int even in displayed formulas
278 if (nuc->asSymbolInset())
279 if (nuc->asSymbolInset()->name().find("int") != string::npos)
282 // assume "real" limits for everything else
287 void MathScriptInset::removeEmptyScripts()
289 for (int i = 0; i <= 1; ++i)
290 if (script_[i] && cell(i).size() == 0) {
297 void MathScriptInset::removeScript(bool up)
304 bool MathScriptInset::has(bool up) const
310 bool MathScriptInset::empty() const
312 return !script_[0] && !script_[1];
316 bool MathScriptInset::hasUp() const
322 bool MathScriptInset::hasDown() const
328 bool MathScriptInset::idxRight(MathInset::idx_type &,
329 MathInset::pos_type &) const
335 bool MathScriptInset::idxLeft(MathInset::idx_type &,
336 MathInset::pos_type &) const
342 void MathScriptInset::write(WriteStream & os) const
344 //lyxerr << "unexpected call to MathScriptInset::write()\n";
349 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
353 if (nuc->takesLimits()) {
361 lyxerr[Debug::MATHED] << "suppressing {} when writing\n";
365 if (hasDown() && down().data_.size())
366 os << "_{" << down().data_ << '}';
368 if (hasUp() && up().data_.size())
369 os << "^{" << up().data_ << '}';
373 void MathScriptInset::normalize(NormalStream & os) const
375 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
380 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
382 bool d = hasDown() && down().data_.size();
383 bool u = hasUp() && up().data_.size();
396 os << down().data_ << ']';
398 os << up().data_ << ']';
402 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
406 if (hasDown() && down().data_.size())
407 os << '[' << down().data_ << ']';
408 if (hasUp() && up().data_.size())
409 os << "^(" << up().data_ << ')';
413 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
415 bool d = hasDown() && down().data_.size();
416 bool u = hasUp() && up().data_.size();
419 os << MTag("msubsup");
431 os << down().data_ << up().data_ << ETag("msubsup");
433 os << up().data_ << ETag("msup");
435 os << down().data_ << ETag("msub");
439 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
443 if (hasDown() && down().data_.size())
444 os << '[' << down().data_ << ']';
445 if (hasUp() && up().data_.size())
446 os << "^(" << up().data_ << ')';