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) ? (width2(nuc) - down().width()) / 2 : nwid(nuc);
113 int MathScriptInset::dx1(MathInset const * nuc) const
115 lyx::Assert(hasUp());
116 return hasLimits(nuc) ? (width2(nuc) - up().width()) / 2 : nwid(nuc);
120 int MathScriptInset::dxx(MathInset const * nuc) const
122 //lyx::Assert(nuc());
123 return hasLimits(nuc) ? (width2(nuc) - nwid(nuc)) / 2 : 0;
127 int MathScriptInset::ascent2(MathInset const * nuc) const
129 return dy1(nuc) + (hasUp() ? up().ascent() : 0);
133 int MathScriptInset::descent2(MathInset const * nuc) const
135 return dy0(nuc) + (hasDown() ? down().descent() : 0);
139 int MathScriptInset::width2(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);
193 ascent_ = ascent2(nuc);
194 descent_ = descent2(nuc);
195 width_ = width2(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
230 // we can only display limits if the nucleus wants some
233 if (!nuc->isScriptable())
236 // per default \int has limits beside the \int even in displayed formulas
237 if (nuc->asSymbolInset())
238 if (nuc->asSymbolInset()->name().find("int") != string::npos)
241 // assume "real" limits for everything else
246 void MathScriptInset::removeEmptyScripts()
248 for (int i = 0; i <= 1; ++i)
249 if (script_[i] && !cell(i).size())
254 void MathScriptInset::removeScript(bool up)
261 bool MathScriptInset::has(bool up) const
267 bool MathScriptInset::hasUp() const
273 bool MathScriptInset::hasDown() const
279 bool MathScriptInset::idxRight(MathInset::idx_type &,
280 MathInset::pos_type &) const
286 bool MathScriptInset::idxLeft(MathInset::idx_type &,
287 MathInset::pos_type &) const
293 void MathScriptInset::write(WriteStream & os) const
295 //lyxerr << "unexpected call to MathScriptInset::write()\n";
300 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
304 if (nuc->takesLimits()) {
312 lyxerr << "suppressing {} \n";
316 if (hasDown() && down().data_.size())
317 os << "_{" << down().data_ << '}';
319 if (hasUp() && up().data_.size())
320 os << "^{" << up().data_ << '}';
324 void MathScriptInset::normalize(NormalStream & os) const
326 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
331 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
333 bool d = hasDown() && down().data_.size();
334 bool u = hasUp() && up().data_.size();
347 os << down().data_ << ']';
349 os << up().data_ << ']';
353 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
357 if (hasDown() && down().data_.size())
358 os << '[' << down().data_ << ']';
359 if (hasUp() && up().data_.size())
360 os << "^(" << up().data_ << ')';
364 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
366 bool d = hasDown() && down().data_.size();
367 bool u = hasUp() && up().data_.size();
370 os << MTag("msubsup");
382 os << down().data_ << up().data_ << ETag("msubsup");
384 os << up().data_ << ETag("msup");
386 os << down().data_ << ETag("msub");
390 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
394 if (hasDown() && down().data_.size())
395 os << '[' << down().data_ << ']';
396 if (hasUp() && up().data_.size())
397 os << "^(" << up().data_ << ')';