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"
13 MathScriptInset::MathScriptInset()
14 : MathNestInset(2), limits_(0)
21 MathScriptInset::MathScriptInset(bool up)
22 : MathNestInset(2), limits_(0)
29 MathInset * MathScriptInset::clone() const
31 return new MathScriptInset(*this);
35 MathScriptInset const * MathScriptInset::asScriptInset() const
41 MathScriptInset * MathScriptInset::asScriptInset()
47 MathXArray const & MathScriptInset::up() const
53 MathXArray const & MathScriptInset::down() const
59 MathXArray & MathScriptInset::up()
65 MathXArray & MathScriptInset::down()
71 void MathScriptInset::ensure(bool up)
77 int MathScriptInset::dy0(MathInset const * nuc) const
82 int des = down().ascent();
86 des = std::max(des, nd);
91 int MathScriptInset::dy1(MathInset const * nuc) const
96 int asc = up().descent();
100 asc = std::max(asc, na);
101 asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I'));
106 int MathScriptInset::dx0(MathInset const * nuc) const
108 lyx::Assert(hasDown());
109 return hasLimits(nuc) ? (width(nuc) - down().width()) / 2 : nwid(nuc);
113 int MathScriptInset::dx1(MathInset const * nuc) const
115 lyx::Assert(hasUp());
116 return hasLimits(nuc) ? (width(nuc) - up().width()) / 2 : nwid(nuc);
120 int MathScriptInset::dxx(MathInset const * nuc) const
122 //lyx::Assert(nuc());
123 return hasLimits(nuc) ? (width(nuc) - nwid(nuc)) / 2 : 0;
127 int MathScriptInset::ascent(MathInset const * nuc) const
129 return dy1(nuc) + (hasUp() ? up().ascent() : 0);
133 int MathScriptInset::descent(MathInset const * nuc) const
135 return dy0(nuc) + (hasDown() ? down().descent() : 0);
139 int MathScriptInset::width(MathInset const * nuc) const
142 if (hasLimits(nuc)) {
145 wid = std::max(wid, up().width());
147 wid = std::max(wid, down().width());
150 wid = std::max(wid, up().width());
152 wid = std::max(wid, down().width());
159 int MathScriptInset::nwid(MathInset const * nuc) const
163 mathed_char_width(LM_TC_TEX, mi_, '.');
167 int MathScriptInset::nasc(MathInset const * nuc) const
169 return nuc ? nuc->ascent()
170 : mathed_char_ascent(LM_TC_VAR, mi_, 'I');
174 int MathScriptInset::ndes(MathInset const * nuc) const
176 return nuc ? nuc->descent()
177 : mathed_char_descent(LM_TC_VAR, mi_, 'I');
181 void MathScriptInset::metrics(MathMetricsInfo const & mi) const
187 void MathScriptInset::metrics(MathInset const * nuc,
188 MathMetricsInfo const & mi) const
190 MathNestInset::metrics(mi);
194 ascent_ = ascent(nuc);
195 descent_ = descent(nuc);
200 void MathScriptInset::draw(Painter & pain, int x, int y) const
202 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
207 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
211 nuc->draw(pain, x + dxx(nuc), y);
213 drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
216 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
219 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
223 bool MathScriptInset::hasLimits(MathInset const * nuc) const
231 // we can only display limits if the nucleus wants some
234 if (!nuc->isScriptable())
237 // per default \int has limits beside the \int even in displayed formulas
238 if (nuc->asSymbolInset())
239 if (nuc->asSymbolInset()->name().find("int") != string::npos)
242 // assume "real" limits for everything else
247 void MathScriptInset::removeEmptyScripts()
249 for (int i = 0; i <= 1; ++i)
250 if (script_[i] && !cell(i).size())
255 void MathScriptInset::removeScript(bool up)
262 bool MathScriptInset::has(bool up) const
268 bool MathScriptInset::hasUp() const
274 bool MathScriptInset::hasDown() const
280 bool MathScriptInset::idxRight(MathInset::idx_type &,
281 MathInset::pos_type &) const
287 bool MathScriptInset::idxLeft(MathInset::idx_type &,
288 MathInset::pos_type &) const
294 void MathScriptInset::write(WriteStream & os) const
296 //lyxerr << "unexpected call to MathScriptInset::write()\n";
301 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
305 if (nuc->takesLimits()) {
313 lyxerr << "suppressing {} \n";
317 if (hasDown() && down().data_.size())
318 os << "_{" << down().data_ << '}';
320 if (hasUp() && up().data_.size())
321 os << "^{" << up().data_ << '}';
325 void MathScriptInset::normalize(NormalStream & os) const
327 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
332 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
334 bool d = hasDown() && down().data_.size();
335 bool u = hasUp() && up().data_.size();
348 os << down().data_ << ']';
350 os << up().data_ << ']';
354 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
358 if (hasDown() && down().data_.size())
359 os << '[' << down().data_ << ']';
360 if (hasUp() && up().data_.size())
361 os << "^(" << up().data_ << ')';
365 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
367 bool d = hasDown() && down().data_.size();
368 bool u = hasUp() && up().data_.size();
371 os << MTag("msubsup");
383 os << down().data_ << up().data_ << ETag("msubsup");
385 os << up().data_ << ETag("msup");
387 os << down().data_ << ETag("msub");
391 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
395 if (hasDown() && down().data_.size())
396 os << '[' << down().data_ << ']';
397 if (hasUp() && up().data_.size())
398 os << "^(" << up().data_ << ')';