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(3), limits_(0)
24 MathScriptInset::MathScriptInset(bool up)
25 : MathNestInset(3), limits_(0)
32 MathScriptInset::MathScriptInset(MathAtom const & at, bool up)
33 : MathNestInset(3), limits_(0)
37 cell(2).push_back(at);
42 MathInset * MathScriptInset::clone() const
44 return new MathScriptInset(*this);
48 MathScriptInset const * MathScriptInset::asScriptInset() const
54 MathScriptInset * MathScriptInset::asScriptInset()
60 bool MathScriptInset::idxFirst(idx_type & idx, pos_type & pos) const
68 bool MathScriptInset::idxLast(idx_type & idx, pos_type & pos) const
76 MathArray const & MathScriptInset::down() const
82 MathArray & MathScriptInset::down()
88 MathArray const & MathScriptInset::up() const
94 MathArray & MathScriptInset::up()
100 void MathScriptInset::ensure(bool up)
106 MathArray const & MathScriptInset::nuc() const
112 MathArray & MathScriptInset::nuc()
118 int MathScriptInset::dy0() const
123 int des = down().ascent();
132 int MathScriptInset::dy1() const
137 int asc = up().descent();
147 int MathScriptInset::dx0() const
149 lyx::Assert(hasDown());
150 return hasLimits() ? (dim_.w - down().width()) / 2 : nwid();
154 int MathScriptInset::dx1() const
156 lyx::Assert(hasUp());
157 return hasLimits() ? (dim_.w - up().width()) / 2 : nwid();
161 int MathScriptInset::dxx() const
163 return hasLimits() ? (dim_.w - nwid()) / 2 : 0;
167 int MathScriptInset::nwid() const
169 return nuc().size() ? nuc().width() : 2;
173 int MathScriptInset::nasc() const
175 return nuc().size() ? nuc().ascent() : 5;
179 int MathScriptInset::ndes() const
181 return nuc().size() ? nuc().descent() : 0;
185 void MathScriptInset::metrics(MathMetricsInfo & mi) const
188 MathScriptChanger dummy(mi.base);
195 dim_.w = max(dim_.w, up().width());
197 dim_.w = max(dim_.w, down().width());
200 dim_.w = max(dim_.w, up().width());
202 dim_.w = max(dim_.w, down().width());
205 dim_.a = dy1() + (hasUp() ? up().ascent() : 0);
206 dim_.d = dy0() + (hasDown() ? down().descent() : 0);
211 void MathScriptInset::draw(MathPainterInfo & pi, int x, int y) const
214 nuc().draw(pi, x + dxx(), y);
216 drawStr(pi, pi.base.font, x + dxx(), y, ".");
217 MathScriptChanger dummy(pi.base);
219 up().draw(pi, x + dx1(), y - dy1());
221 down().draw(pi, x + dx0(), y + dy0());
222 drawMarkers2(pi, x, y);
226 void MathScriptInset::metricsT(TextMetricsInfo const & mi) const
236 void MathScriptInset::drawT(TextPainter & pain, int x, int y) const
239 nuc().drawT(pain, x + dxx(), y);
241 up().drawT(pain, x + dx1(), y - dy1());
243 down().drawT(pain, x + dx0(), y + dy0());
248 bool MathScriptInset::hasLimits() const
256 // we can only display limits if the nucleus wants some
259 if (!nuc().back()->isScriptable())
262 // per default \int has limits beside the \int even in displayed formulas
263 if (nuc().back()->asSymbolInset())
264 if (nuc().back()->asSymbolInset()->name().find("int") != string::npos)
267 // assume "real" limits for everything else
272 void MathScriptInset::removeEmptyScripts()
274 for (int i = 0; i <= 1; ++i)
275 if (script_[i] && cell(i).size() == 0) {
282 void MathScriptInset::removeScript(bool up)
289 bool MathScriptInset::has(bool up) const
295 bool MathScriptInset::empty() const
297 return !script_[0] && !script_[1] && cell(2).empty();
301 bool MathScriptInset::hasUp() const
307 bool MathScriptInset::hasDown() const
313 bool MathScriptInset::idxRight(idx_type &, pos_type &) const
319 bool MathScriptInset::idxLeft(idx_type &, pos_type &) const
325 bool MathScriptInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
329 // if we are 'up' we can't go further up
332 // otherwise go to last base position
334 pos = cell(2).size();
338 // if we are 'down' we can't go further down
342 pos = cell(2).size();
347 // don't go up/down unless in last position
348 if (pos != cell(2).size())
350 // don't go up/down if there is no cell.
353 // otherwise move into the first position
361 void MathScriptInset::write(WriteStream & os) const
365 if (nuc().back()->takesLimits()) {
373 lyxerr[Debug::MATHED] << "suppressing {} when writing\n";
378 if (hasDown() && down().size())
379 os << "_{" << down() << '}';
381 if (hasUp() && up().size())
382 os << "^{" << up() << '}';
384 if (lock_ && !os.latex())
389 void MathScriptInset::normalize(NormalStream & os) const
391 bool d = hasDown() && down().size();
392 bool u = hasUp() && up().size();
407 os << down() << ' ' << up() << ']';
415 void MathScriptInset::maplize(MapleStream & os) const
419 if (hasDown() && down().size())
420 os << '[' << down() << ']';
421 if (hasUp() && up().size())
422 os << "^(" << up() << ')';
426 void MathScriptInset::mathematicize(MathematicaStream & os) const
428 bool d = hasDown() && down().size();
429 bool u = hasUp() && up().size();
433 os << "Subscript[" << nuc();
439 os << "^(" << up() << ")";
443 os << "," << down() << "]";
447 void MathScriptInset::mathmlize( MathMLStream & os) const
449 bool d = hasDown() && down().size();
450 bool u = hasUp() && up().size();
453 os << MTag("msubsup");
465 os << down() << up() << ETag("msubsup");
467 os << up() << ETag("msup");
469 os << down() << ETag("msub");
473 void MathScriptInset::octavize(OctaveStream & os) const
477 if (hasDown() && down().size())
478 os << '[' << down() << ']';
479 if (hasUp() && up().size())
480 os << "^(" << up() << ')';
484 void MathScriptInset::infoize(std::ostream & os) const
488 os << (limits_ == 1 ? ", Displayed limits" : ", Inlined limits");