5 #include "math_scriptinset.h"
8 #include "math_mathmlstream.h"
9 #include "support/LAssert.h"
12 MathScriptInset::MathScriptInset()
13 : MathNestInset(2), limits_(0)
20 MathScriptInset::MathScriptInset(bool up)
21 : MathNestInset(2), limits_(0)
28 MathInset * MathScriptInset::clone() const
30 return new MathScriptInset(*this);
34 MathScriptInset const * MathScriptInset::asScriptInset() const
40 MathScriptInset * MathScriptInset::asScriptInset()
46 MathXArray const & MathScriptInset::up() const
52 MathXArray const & MathScriptInset::down() const
58 MathXArray & MathScriptInset::up()
64 MathXArray & MathScriptInset::down()
70 void MathScriptInset::ensure(bool up)
76 int MathScriptInset::dy0(MathInset const * nuc) const
81 int des = down().ascent();
85 des = std::max(des, nd);
90 int MathScriptInset::dy1(MathInset const * nuc) const
95 int asc = up().descent();
99 asc = std::max(asc, na);
100 asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I'));
105 int MathScriptInset::dx0(MathInset const * nuc) const
107 lyx::Assert(hasDown());
108 return hasLimits(nuc) ? (width(nuc) - down().width()) / 2 : nwid(nuc);
112 int MathScriptInset::dx1(MathInset const * nuc) const
114 lyx::Assert(hasUp());
115 return hasLimits(nuc) ? (width(nuc) - up().width()) / 2 : nwid(nuc);
119 int MathScriptInset::dxx(MathInset const * nuc) const
121 //lyx::Assert(nuc());
122 return hasLimits(nuc) ? (width(nuc) - nwid(nuc)) / 2 : 0;
126 int MathScriptInset::ascent(MathInset const * nuc) const
128 return dy1(nuc) + (hasUp() ? up().ascent() : 0);
132 int MathScriptInset::descent(MathInset const * nuc) const
134 return dy0(nuc) + (hasDown() ? down().descent() : 0);
138 int MathScriptInset::width(MathInset const * nuc) const
141 if (hasLimits(nuc)) {
144 wid = std::max(wid, up().width());
146 wid = std::max(wid, down().width());
149 wid = std::max(wid, up().width());
151 wid = std::max(wid, down().width());
158 int MathScriptInset::nwid(MathInset const * nuc) const
162 mathed_char_width(LM_TC_TEX, mi_, '.');
166 int MathScriptInset::nasc(MathInset const * nuc) const
168 return nuc ? nuc->ascent()
169 : mathed_char_ascent(LM_TC_VAR, mi_, 'I');
173 int MathScriptInset::ndes(MathInset const * nuc) const
175 return nuc ? nuc->descent()
176 : mathed_char_descent(LM_TC_VAR, mi_, 'I');
180 void MathScriptInset::metrics(MathMetricsInfo const & mi) const
186 void MathScriptInset::metrics(MathInset const * nuc,
187 MathMetricsInfo const & mi) const
189 MathNestInset::metrics(mi);
193 ascent_ = ascent(nuc);
194 descent_ = descent(nuc);
199 void MathScriptInset::draw(Painter & pain, int x, int y) const
201 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
206 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
210 nuc->draw(pain, x + dxx(nuc), y);
212 drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
215 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
218 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
222 bool MathScriptInset::hasLimits(MathInset const * nuc) const
224 return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());
228 void MathScriptInset::removeEmptyScripts()
230 for (int i = 0; i <= 1; ++i)
231 if (script_[i] && !cell(i).size())
236 void MathScriptInset::removeScript(bool up)
243 bool MathScriptInset::has(bool up) const
249 bool MathScriptInset::hasUp() const
255 bool MathScriptInset::hasDown() const
261 bool MathScriptInset::idxRight(MathInset::idx_type &,
262 MathInset::pos_type &) const
268 bool MathScriptInset::idxLeft(MathInset::idx_type &,
269 MathInset::pos_type &) const
275 void MathScriptInset::write(MathWriteInfo & os) const
277 //lyxerr << "unexpected call to MathScriptInset::write()\n";
282 void MathScriptInset::write(MathInset const * nuc, MathWriteInfo & os) const
286 if (nuc->takesLimits()) {
296 if (hasDown() && down().data_.size())
297 os << "_{" << down().data_ << '}';
299 if (hasUp() && up().data_.size())
300 os << "^{" << up().data_ << '}';
304 void MathScriptInset::writeNormal(NormalStream & os) const
306 //lyxerr << "unexpected call to MathScriptInset::writeNormal()\n";
311 void MathScriptInset::writeNormal(MathInset const * nuc, NormalStream & os) const
313 bool d = hasDown() && down().data_.size();
314 bool u = hasUp() && up().data_.size();
327 os << down().data_ << ']';
329 os << up().data_ << ']';
333 void MathScriptInset::maplize(MathInset const * nuc, MapleStream & os) const
337 if (hasDown() && down().data_.size())
338 os << '[' << down().data_ << ']';
339 if (hasUp() && up().data_.size())
340 os << "^(" << up().data_ << ')';
344 void MathScriptInset::mathmlize(MathInset const * nuc, MathMLStream & os) const
346 bool d = hasDown() && down().data_.size();
347 bool u = hasUp() && up().data_.size();
350 os << MTag("msubsup");
362 os << down().data_ << up().data_ << ETag("msubsup");
364 os << up().data_ << ETag("msup");
366 os << down().data_ << ETag("msub");
370 void MathScriptInset::octavize(MathInset const * nuc, OctaveStream & os) const
374 if (hasDown() && down().data_.size())
375 os << '[' << down().data_ << ']';
376 if (hasUp() && up().data_.size())
377 os << "^(" << up().data_ << ')';