5 #include "math_scriptinset.h"
7 #include "math_support.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(WriteStream & os) const
277 //lyxerr << "unexpected call to MathScriptInset::write()\n";
282 void MathScriptInset::write(MathInset const * nuc, WriteStream & os) const
286 if (nuc->takesLimits()) {
294 lyxerr << "suppressing {} \n";
298 if (hasDown() && down().data_.size())
299 os << "_{" << down().data_ << '}';
301 if (hasUp() && up().data_.size())
302 os << "^{" << up().data_ << '}';
306 void MathScriptInset::normalize(NormalStream & os) const
308 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
313 void MathScriptInset::normalize(MathInset const * nuc, NormalStream & os) const
315 bool d = hasDown() && down().data_.size();
316 bool u = hasUp() && up().data_.size();
329 os << down().data_ << ']';
331 os << up().data_ << ']';
335 void MathScriptInset::maplize(MathInset const * nuc, MapleStream & os) const
339 if (hasDown() && down().data_.size())
340 os << '[' << down().data_ << ']';
341 if (hasUp() && up().data_.size())
342 os << "^(" << up().data_ << ')';
346 void MathScriptInset::mathmlize(MathInset const * nuc, MathMLStream & os) const
348 bool d = hasDown() && down().data_.size();
349 bool u = hasUp() && up().data_.size();
352 os << MTag("msubsup");
364 os << down().data_ << up().data_ << ETag("msubsup");
366 os << up().data_ << ETag("msup");
368 os << down().data_ << ETag("msub");
372 void MathScriptInset::octavize(MathInset const * nuc, OctaveStream & os) const
376 if (hasDown() && down().data_.size())
377 os << '[' << down().data_ << ']';
378 if (hasUp() && up().data_.size())
379 os << "^(" << up().data_ << ')';