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
190 MathNestInset::metrics(mi);
191 MathScriptChanger dummy(mi.base);
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";
205 void MathScriptInset::draw(MathInset const * nuc, MathPainterInfo & pi,
209 nuc->draw(pi, x + dxx(nuc), y);
211 drawStr(pi, font_, x + dxx(nuc), y, ".");
213 MathScriptChanger dummy(pi.base);
215 up().draw(pi, x + dx1(nuc), y - dy1(nuc));
217 down().draw(pi, x + dx0(nuc), y + dy0(nuc));
221 void MathScriptInset::metricsT(TextMetricsInfo const & mi) const
227 void MathScriptInset::metricsT(MathInset const * nuc,
228 TextMetricsInfo const & mi) const
236 //ascent_ = ascent2(nuc);
237 //descent_ = descent2(nuc);
238 //width_ = width2(nuc);
242 void MathScriptInset::drawT(TextPainter & pain, int x, int y) const
244 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
245 drawT(0, pain, x, y);
249 void MathScriptInset::drawT(MathInset const * nuc, TextPainter & pain,
253 nuc->drawT(pain, x + dxx(nuc), y);
255 up().drawT(pain, x + dx1(nuc), y - dy1(nuc));
257 down().drawT(pain, x + dx0(nuc), y + dy0(nuc));
262 bool MathScriptInset::hasLimits(MathInset const * nuc) const
270 // we can only display limits if the nucleus wants some
273 if (!nuc->isScriptable())
276 // per default \int has limits beside the \int even in displayed formulas
277 if (nuc->asSymbolInset())
278 if (nuc->asSymbolInset()->name().find("int") != string::npos)
281 // assume "real" limits for everything else
286 void MathScriptInset::removeEmptyScripts()
288 for (int i = 0; i <= 1; ++i)
289 if (script_[i] && cell(i).size() == 0) {
296 void MathScriptInset::removeScript(bool up)
303 bool MathScriptInset::has(bool up) const
309 bool MathScriptInset::empty() const
311 return !script_[0] && !script_[1];
315 bool MathScriptInset::hasUp() const
321 bool MathScriptInset::hasDown() const
327 bool MathScriptInset::idxRight(MathInset::idx_type &,
328 MathInset::pos_type &) const
334 bool MathScriptInset::idxLeft(MathInset::idx_type &,
335 MathInset::pos_type &) const
341 void MathScriptInset::write(WriteStream & os) const
343 //lyxerr << "unexpected call to MathScriptInset::write()\n";
348 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
352 if (nuc->takesLimits()) {
360 lyxerr[Debug::MATHED] << "suppressing {} when writing\n";
364 if (hasDown() && down().data().size())
365 os << "_{" << down().data() << '}';
367 if (hasUp() && up().data().size())
368 os << "^{" << up().data() << '}';
372 void MathScriptInset::normalize(NormalStream & os) const
374 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
379 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
381 bool d = hasDown() && down().data().size();
382 bool u = hasUp() && up().data().size();
395 os << down().data() << ']';
397 os << up().data() << ']';
401 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
405 if (hasDown() && down().data().size())
406 os << '[' << down().data() << ']';
407 if (hasUp() && up().data().size())
408 os << "^(" << up().data() << ')';
412 void MathScriptInset::mathematicize2(MathInset const * nuc, MathematicaStream & os) const
414 bool d = hasDown() && down().data().size();
415 bool u = hasUp() && up().data().size();
418 if (d) //subscript only if nuc !
419 os << "Subscript[" << nuc;
423 os << "^(" << up().data() << ")";
427 os << "," << down().data() << "]";
431 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
433 bool d = hasDown() && down().data().size();
434 bool u = hasUp() && up().data().size();
437 os << MTag("msubsup");
449 os << down().data() << up().data() << ETag("msubsup");
451 os << up().data() << ETag("msup");
453 os << down().data() << ETag("msub");
457 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
461 if (hasDown() && down().data().size())
462 os << '[' << down().data() << ']';
463 if (hasUp() && up().data().size())
464 os << "^(" << up().data() << ')';
468 void MathScriptInset::infoize(std::ostream & os) const
471 os << (limits_ == 1 ? "Displayed limits " : "Inlined limits ");