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"
16 MathScriptInset::MathScriptInset()
17 : MathNestInset(2), limits_(0)
24 MathScriptInset::MathScriptInset(bool up)
25 : MathNestInset(2), limits_(0)
32 MathInset * MathScriptInset::clone() const
34 return new MathScriptInset(*this);
38 MathScriptInset const * MathScriptInset::asScriptInset() const
44 MathScriptInset * MathScriptInset::asScriptInset()
50 MathXArray const & MathScriptInset::up() const
56 MathXArray const & MathScriptInset::down() const
62 MathXArray & MathScriptInset::up()
68 MathXArray & MathScriptInset::down()
74 void MathScriptInset::ensure(bool up)
80 int MathScriptInset::dy0(MathInset const * nuc) const
85 int des = down().ascent();
94 int MathScriptInset::dy1(MathInset const * nuc) const
99 int asc = up().descent();
104 asc = max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I'));
109 int MathScriptInset::dx0(MathInset const * nuc) const
111 lyx::Assert(hasDown());
112 return hasLimits(nuc) ? (width2(nuc) - down().width()) / 2 : nwid(nuc);
116 int MathScriptInset::dx1(MathInset const * nuc) const
118 lyx::Assert(hasUp());
119 return hasLimits(nuc) ? (width2(nuc) - up().width()) / 2 : nwid(nuc);
123 int MathScriptInset::dxx(MathInset const * nuc) const
125 //lyx::Assert(nuc());
126 return hasLimits(nuc) ? (width2(nuc) - nwid(nuc)) / 2 : 0;
130 int MathScriptInset::ascent2(MathInset const * nuc) const
132 return dy1(nuc) + (hasUp() ? up().ascent() : 0);
136 int MathScriptInset::descent2(MathInset const * nuc) const
138 return dy0(nuc) + (hasDown() ? down().descent() : 0);
142 int MathScriptInset::width2(MathInset const * nuc) const
145 if (hasLimits(nuc)) {
148 wid = max(wid, up().width());
150 wid = max(wid, down().width());
153 wid = max(wid, up().width());
155 wid = max(wid, down().width());
162 int MathScriptInset::nwid(MathInset const * nuc) const
166 mathed_char_width(LM_TC_TEX, mi_, '.');
170 int MathScriptInset::nasc(MathInset const * nuc) const
172 return nuc ? nuc->ascent()
173 : mathed_char_ascent(LM_TC_VAR, mi_, 'I');
177 int MathScriptInset::ndes(MathInset const * nuc) const
179 return nuc ? nuc->descent()
180 : mathed_char_descent(LM_TC_VAR, mi_, 'I');
184 void MathScriptInset::metrics(MathMetricsInfo const & mi) const
190 void MathScriptInset::metrics(MathInset const * nuc,
191 MathMetricsInfo const & mi) const
194 smallerStyleScript(mi_);
195 MathNestInset::metrics(mi_);
198 ascent_ = ascent2(nuc);
199 descent_ = descent2(nuc);
200 width_ = width2(nuc);
204 void MathScriptInset::draw(Painter & pain, int x, int y) const
206 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
211 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
215 nuc->draw(pain, x + dxx(nuc), y);
217 drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
220 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
223 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
227 bool MathScriptInset::hasLimits(MathInset const * nuc) const
235 // we can only display limits if the nucleus wants some
238 if (!nuc->isScriptable())
241 // per default \int has limits beside the \int even in displayed formulas
242 if (nuc->asSymbolInset())
243 if (nuc->asSymbolInset()->name().find("int") != string::npos)
246 // assume "real" limits for everything else
251 void MathScriptInset::removeEmptyScripts()
253 for (int i = 0; i <= 1; ++i)
254 if (script_[i] && !cell(i).size())
259 void MathScriptInset::removeScript(bool up)
266 bool MathScriptInset::has(bool up) const
272 bool MathScriptInset::empty() const
274 return !script_[0] && !script_[1];
278 bool MathScriptInset::hasUp() const
284 bool MathScriptInset::hasDown() const
290 bool MathScriptInset::idxRight(MathInset::idx_type &,
291 MathInset::pos_type &) const
297 bool MathScriptInset::idxLeft(MathInset::idx_type &,
298 MathInset::pos_type &) const
304 void MathScriptInset::write(WriteStream & os) const
306 //lyxerr << "unexpected call to MathScriptInset::write()\n";
311 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
315 if (nuc->takesLimits()) {
323 lyxerr << "suppressing {} \n";
327 if (hasDown() && down().data_.size())
328 os << "_{" << down().data_ << '}';
330 if (hasUp() && up().data_.size())
331 os << "^{" << up().data_ << '}';
335 void MathScriptInset::normalize(NormalStream & os) const
337 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
342 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
344 bool d = hasDown() && down().data_.size();
345 bool u = hasUp() && up().data_.size();
358 os << down().data_ << ']';
360 os << up().data_ << ']';
364 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
368 if (hasDown() && down().data_.size())
369 os << '[' << down().data_ << ']';
370 if (hasUp() && up().data_.size())
371 os << "^(" << up().data_ << ')';
375 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
377 bool d = hasDown() && down().data_.size();
378 bool u = hasUp() && up().data_.size();
381 os << MTag("msubsup");
393 os << down().data_ << up().data_ << ETag("msubsup");
395 os << up().data_ << ETag("msup");
397 os << down().data_ << ETag("msub");
401 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
405 if (hasDown() && down().data_.size())
406 os << '[' << down().data_ << ']';
407 if (hasUp() && up().data_.size())
408 os << "^(" << up().data_ << ')';