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
191 smallerStyleScript(mi_);
192 MathNestInset::metrics(mi_);
195 ascent_ = ascent2(nuc);
196 descent_ = descent2(nuc);
197 width_ = width2(nuc);
201 void MathScriptInset::draw(Painter & pain, int x, int y) const
203 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
208 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
212 nuc->draw(pain, x + dxx(nuc), y);
214 drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
217 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
220 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
224 bool MathScriptInset::hasLimits(MathInset const * nuc) const
232 // we can only display limits if the nucleus wants some
235 if (!nuc->isScriptable())
238 // per default \int has limits beside the \int even in displayed formulas
239 if (nuc->asSymbolInset())
240 if (nuc->asSymbolInset()->name().find("int") != string::npos)
243 // assume "real" limits for everything else
248 void MathScriptInset::removeEmptyScripts()
250 for (int i = 0; i <= 1; ++i)
251 if (script_[i] && !cell(i).size())
256 void MathScriptInset::removeScript(bool up)
263 bool MathScriptInset::has(bool up) const
269 bool MathScriptInset::empty() const
271 return !script_[0] && !script_[1];
275 bool MathScriptInset::hasUp() const
281 bool MathScriptInset::hasDown() const
287 bool MathScriptInset::idxRight(MathInset::idx_type &,
288 MathInset::pos_type &) const
294 bool MathScriptInset::idxLeft(MathInset::idx_type &,
295 MathInset::pos_type &) const
301 void MathScriptInset::write(WriteStream & os) const
303 //lyxerr << "unexpected call to MathScriptInset::write()\n";
308 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
312 if (nuc->takesLimits()) {
320 lyxerr << "suppressing {} \n";
324 if (hasDown() && down().data_.size())
325 os << "_{" << down().data_ << '}';
327 if (hasUp() && up().data_.size())
328 os << "^{" << up().data_ << '}';
332 void MathScriptInset::normalize(NormalStream & os) const
334 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
339 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
341 bool d = hasDown() && down().data_.size();
342 bool u = hasUp() && up().data_.size();
355 os << down().data_ << ']';
357 os << up().data_ << ']';
361 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
365 if (hasDown() && down().data_.size())
366 os << '[' << down().data_ << ']';
367 if (hasUp() && up().data_.size())
368 os << "^(" << up().data_ << ')';
372 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
374 bool d = hasDown() && down().data_.size();
375 bool u = hasUp() && up().data_.size();
378 os << MTag("msubsup");
390 os << down().data_ << up().data_ << ETag("msubsup");
392 os << up().data_ << ETag("msup");
394 os << down().data_ << ETag("msub");
398 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
402 if (hasDown() && down().data_.size())
403 os << '[' << down().data_ << ']';
404 if (hasUp() && up().data_.size())
405 os << "^(" << up().data_ << ')';