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(font_, '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
164 return nuc ? nuc->width() : mathed_char_width(font_, '.');
168 int MathScriptInset::nasc(MathInset const * nuc) const
170 return nuc ? nuc->ascent() : mathed_char_ascent(font_, 'I');
174 int MathScriptInset::ndes(MathInset const * nuc) const
176 return nuc ? nuc->descent() : mathed_char_descent(font_, 'I');
180 void MathScriptInset::metrics(MathMetricsInfo const & mi) const
186 void MathScriptInset::metrics(MathInset const * nuc,
187 MathMetricsInfo const & mi) const
189 MathMetricsInfo m = mi;
190 smallerStyleScript(m);
191 MathNestInset::metrics(m);
192 whichFont(font_, LM_TC_VAR, m);
195 ascent_ = ascent2(nuc);
196 descent_ = descent2(nuc);
197 width_ = width2(nuc);
201 void MathScriptInset::metrics(TextMetricsInfo const & mi) const
207 void MathScriptInset::metrics(MathInset const * nuc,
208 TextMetricsInfo const & mi) const
216 //ascent_ = ascent2(nuc);
217 //descent_ = descent2(nuc);
218 //width_ = width2(nuc);
222 void MathScriptInset::draw(Painter & pain, int x, int y) const
224 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
229 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
233 nuc->draw(pain, x + dxx(nuc), y);
234 else // if (editing())
235 drawStr(pain, font_, x + dxx(nuc), y, ".");
238 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
241 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
244 void MathScriptInset::draw(TextPainter & pain, int x, int y) const
246 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
251 void MathScriptInset::draw(MathInset const * nuc, TextPainter & pain,
255 nuc->draw(pain, x + dxx(nuc), y);
257 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
259 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
264 bool MathScriptInset::hasLimits(MathInset const * nuc) const
272 // we can only display limits if the nucleus wants some
275 if (!nuc->isScriptable())
278 // per default \int has limits beside the \int even in displayed formulas
279 if (nuc->asSymbolInset())
280 if (nuc->asSymbolInset()->name().find("int") != string::npos)
283 // assume "real" limits for everything else
288 void MathScriptInset::removeEmptyScripts()
290 for (int i = 0; i <= 1; ++i)
291 if (script_[i] && cell(i).size() == 0) {
298 void MathScriptInset::removeScript(bool up)
305 bool MathScriptInset::has(bool up) const
311 bool MathScriptInset::empty() const
313 return !script_[0] && !script_[1];
317 bool MathScriptInset::hasUp() const
323 bool MathScriptInset::hasDown() const
329 bool MathScriptInset::idxRight(MathInset::idx_type &,
330 MathInset::pos_type &) const
336 bool MathScriptInset::idxLeft(MathInset::idx_type &,
337 MathInset::pos_type &) const
343 void MathScriptInset::write(WriteStream & os) const
345 //lyxerr << "unexpected call to MathScriptInset::write()\n";
350 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
354 if (nuc->takesLimits()) {
362 lyxerr << "suppressing {} \n";
366 if (hasDown() && down().data_.size())
367 os << "_{" << down().data_ << '}';
369 if (hasUp() && up().data_.size())
370 os << "^{" << up().data_ << '}';
374 void MathScriptInset::normalize(NormalStream & os) const
376 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
381 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
383 bool d = hasDown() && down().data_.size();
384 bool u = hasUp() && up().data_.size();
397 os << down().data_ << ']';
399 os << up().data_ << ']';
403 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
407 if (hasDown() && down().data_.size())
408 os << '[' << down().data_ << ']';
409 if (hasUp() && up().data_.size())
410 os << "^(" << up().data_ << ')';
414 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
416 bool d = hasDown() && down().data_.size();
417 bool u = hasUp() && up().data_.size();
420 os << MTag("msubsup");
432 os << down().data_ << up().data_ << ETag("msubsup");
434 os << up().data_ << ETag("msup");
436 os << down().data_ << ETag("msub");
440 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
444 if (hasDown() && down().data_.size())
445 os << '[' << down().data_ << ']';
446 if (hasUp() && up().data_.size())
447 os << "^(" << up().data_ << ')';