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 void MathScriptInset::dimensions2
131 (MathInset const * nuc, int & w, int & a, int & d) const
133 a = dy1(nuc) + (hasUp() ? up().ascent() : 0);
134 d = dy0(nuc) + (hasDown() ? down().descent() : 0);
139 int MathScriptInset::width2(MathInset const * nuc) const
142 if (hasLimits(nuc)) {
145 w = max(w, up().width());
147 w = max(w, down().width());
150 w = max(w, up().width());
152 w = max(w, down().width());
159 int MathScriptInset::nwid(MathInset const * nuc) const
161 return nuc ? nuc->width() : mathed_char_width(font_, '.');
165 int MathScriptInset::nasc(MathInset const * nuc) const
167 return nuc ? nuc->ascent() : mathed_char_ascent(font_, 'I');
171 int MathScriptInset::ndes(MathInset const * nuc) const
173 return nuc ? nuc->descent() : mathed_char_descent(font_, 'I');
177 void MathScriptInset::metrics(MathMetricsInfo & mi) const
183 void MathScriptInset::metrics(MathInset const * nuc, MathMetricsInfo & mi) const
187 MathNestInset::metrics(mi);
188 MathScriptChanger dummy(mi.base);
189 dimensions2(nuc, width_, ascent_, descent_);
193 void MathScriptInset::draw(MathPainterInfo & pi, int x, int y) const
195 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
200 void MathScriptInset::draw(MathInset const * nuc, MathPainterInfo & pi,
204 nuc->draw(pi, x + dxx(nuc), y);
206 drawStr(pi, font_, x + dxx(nuc), y, ".");
208 MathScriptChanger dummy(pi.base);
210 up().draw(pi, x + dx1(nuc), y - dy1(nuc));
212 down().draw(pi, x + dx0(nuc), y + dy0(nuc));
216 void MathScriptInset::metricsT(TextMetricsInfo const & mi) const
222 void MathScriptInset::metricsT(MathInset const * nuc,
223 TextMetricsInfo const & mi) const
231 //ascent_ = ascent2(nuc);
232 //descent_ = descent2(nuc);
233 //width_ = width2(nuc);
237 void MathScriptInset::drawT(TextPainter & pain, int x, int y) const
239 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
240 drawT(0, pain, x, y);
244 void MathScriptInset::drawT(MathInset const * nuc, TextPainter & pain,
248 nuc->drawT(pain, x + dxx(nuc), y);
250 up().drawT(pain, x + dx1(nuc), y - dy1(nuc));
252 down().drawT(pain, x + dx0(nuc), y + dy0(nuc));
257 bool MathScriptInset::hasLimits(MathInset const * nuc) const
265 // we can only display limits if the nucleus wants some
268 if (!nuc->isScriptable())
271 // per default \int has limits beside the \int even in displayed formulas
272 if (nuc->asSymbolInset())
273 if (nuc->asSymbolInset()->name().find("int") != string::npos)
276 // assume "real" limits for everything else
281 void MathScriptInset::removeEmptyScripts()
283 for (int i = 0; i <= 1; ++i)
284 if (script_[i] && cell(i).size() == 0) {
291 void MathScriptInset::removeScript(bool up)
298 bool MathScriptInset::has(bool up) const
304 bool MathScriptInset::empty() const
306 return !script_[0] && !script_[1];
310 bool MathScriptInset::hasUp() const
316 bool MathScriptInset::hasDown() const
322 bool MathScriptInset::idxRight(MathInset::idx_type &,
323 MathInset::pos_type &) const
329 bool MathScriptInset::idxLeft(MathInset::idx_type &,
330 MathInset::pos_type &) const
336 void MathScriptInset::write(WriteStream & os) const
338 //lyxerr << "unexpected call to MathScriptInset::write()\n";
343 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
347 if (nuc->takesLimits()) {
355 lyxerr[Debug::MATHED] << "suppressing {} when writing\n";
359 if (hasDown() && down().data().size())
360 os << "_{" << down().data() << '}';
362 if (hasUp() && up().data().size())
363 os << "^{" << up().data() << '}';
367 void MathScriptInset::normalize(NormalStream & os) const
369 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
374 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
376 bool d = hasDown() && down().data().size();
377 bool u = hasUp() && up().data().size();
390 os << down().data() << ']';
392 os << up().data() << ']';
396 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
400 if (hasDown() && down().data().size())
401 os << '[' << down().data() << ']';
402 if (hasUp() && up().data().size())
403 os << "^(" << up().data() << ')';
407 void MathScriptInset::mathematicize2(MathInset const * nuc, MathematicaStream & os) const
409 bool d = hasDown() && down().data().size();
410 bool u = hasUp() && up().data().size();
413 if (d) //subscript only if nuc !
414 os << "Subscript[" << nuc;
418 os << "^(" << up().data() << ")";
422 os << "," << down().data() << "]";
426 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
428 bool d = hasDown() && down().data().size();
429 bool u = hasUp() && up().data().size();
432 os << MTag("msubsup");
444 os << down().data() << up().data() << ETag("msubsup");
446 os << up().data() << ETag("msup");
448 os << down().data() << ETag("msub");
452 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
456 if (hasDown() && down().data().size())
457 os << '[' << down().data() << ']';
458 if (hasUp() && up().data().size())
459 os << "^(" << up().data() << ')';
463 void MathScriptInset::infoize(std::ostream & os) const
466 os << (limits_ == 1 ? "Displayed limits" : "Inlined limits");