5 #include "math_scriptinset.h"
7 #include "math_support.h"
8 #include "math_mathmlstream.h"
9 #include "support/LAssert.h"
12 MathScriptInset::MathScriptInset()
13 : MathNestInset(2), limits_(0)
20 MathScriptInset::MathScriptInset(bool up)
21 : MathNestInset(2), limits_(0)
28 MathInset * MathScriptInset::clone() const
30 return new MathScriptInset(*this);
34 MathScriptInset const * MathScriptInset::asScriptInset() const
40 MathScriptInset * MathScriptInset::asScriptInset()
46 MathXArray const & MathScriptInset::up() const
52 MathXArray const & MathScriptInset::down() const
58 MathXArray & MathScriptInset::up()
64 MathXArray & MathScriptInset::down()
70 void MathScriptInset::ensure(bool up)
76 bool MathScriptInset::covers(int x, int y) const
78 for (idx_type i = 0; i < 2; ++i)
79 if (has(i) && xcell(i).covers(x, y))
85 int MathScriptInset::dy0(MathInset const * nuc) const
90 int des = down().ascent();
94 des = std::max(des, nd);
99 int MathScriptInset::dy1(MathInset const * nuc) const
104 int asc = up().descent();
108 asc = std::max(asc, na);
109 asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I'));
114 int MathScriptInset::dx0(MathInset const * nuc) const
116 lyx::Assert(hasDown());
117 return hasLimits(nuc) ? (width(nuc) - down().width()) / 2 : nwid(nuc);
121 int MathScriptInset::dx1(MathInset const * nuc) const
123 lyx::Assert(hasUp());
124 return hasLimits(nuc) ? (width(nuc) - up().width()) / 2 : nwid(nuc);
128 int MathScriptInset::dxx(MathInset const * nuc) const
130 //lyx::Assert(nuc());
131 return hasLimits(nuc) ? (width(nuc) - nwid(nuc)) / 2 : 0;
135 int MathScriptInset::ascent(MathInset const * nuc) const
137 return dy1(nuc) + (hasUp() ? up().ascent() : 0);
141 int MathScriptInset::descent(MathInset const * nuc) const
143 return dy0(nuc) + (hasDown() ? down().descent() : 0);
147 int MathScriptInset::width(MathInset const * nuc) const
150 if (hasLimits(nuc)) {
153 wid = std::max(wid, up().width());
155 wid = std::max(wid, down().width());
158 wid = std::max(wid, up().width());
160 wid = std::max(wid, down().width());
167 int MathScriptInset::nwid(MathInset const * nuc) const
171 mathed_char_width(LM_TC_TEX, mi_, '.');
175 int MathScriptInset::nasc(MathInset const * nuc) const
177 return nuc ? nuc->ascent()
178 : mathed_char_ascent(LM_TC_VAR, mi_, 'I');
182 int MathScriptInset::ndes(MathInset const * nuc) const
184 return nuc ? nuc->descent()
185 : mathed_char_descent(LM_TC_VAR, mi_, 'I');
189 void MathScriptInset::metrics(MathMetricsInfo const & mi) const
195 void MathScriptInset::metrics(MathInset const * nuc,
196 MathMetricsInfo const & mi) const
198 MathNestInset::metrics(mi);
202 ascent_ = ascent(nuc);
203 descent_ = descent(nuc);
208 void MathScriptInset::draw(Painter & pain, int x, int y) const
210 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
215 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
219 nuc->draw(pain, x + dxx(nuc), y);
221 drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
224 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
227 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
231 bool MathScriptInset::hasLimits(MathInset const * nuc) const
233 return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());
237 void MathScriptInset::removeEmptyScripts()
239 for (int i = 0; i <= 1; ++i)
240 if (script_[i] && !cell(i).size())
245 void MathScriptInset::removeScript(bool up)
252 bool MathScriptInset::has(bool up) const
258 bool MathScriptInset::hasUp() const
264 bool MathScriptInset::hasDown() const
270 bool MathScriptInset::idxRight(MathInset::idx_type &,
271 MathInset::pos_type &) const
277 bool MathScriptInset::idxLeft(MathInset::idx_type &,
278 MathInset::pos_type &) const
284 bool MathScriptInset::idxFirstUp(idx_type & idx, pos_type & pos) const
294 bool MathScriptInset::idxFirstDown(idx_type & idx, pos_type & pos) const
304 bool MathScriptInset::idxLastUp(idx_type & idx, pos_type & pos) const
309 pos = up().data_.size();
314 bool MathScriptInset::idxLastDown(idx_type & idx, pos_type & pos) const
319 pos = down().data_.size();
324 void MathScriptInset::write(WriteStream & os) const
326 //lyxerr << "unexpected call to MathScriptInset::write()\n";
331 void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
335 if (nuc->takesLimits()) {
343 lyxerr << "suppressing {} \n";
347 if (hasDown() && down().data_.size())
348 os << "_{" << down().data_ << '}';
350 if (hasUp() && up().data_.size())
351 os << "^{" << up().data_ << '}';
355 void MathScriptInset::normalize(NormalStream & os) const
357 //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
362 void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
364 bool d = hasDown() && down().data_.size();
365 bool u = hasUp() && up().data_.size();
378 os << down().data_ << ']';
380 os << up().data_ << ']';
384 void MathScriptInset::maplize2(MathInset const * nuc, MapleStream & os) const
388 if (hasDown() && down().data_.size())
389 os << '[' << down().data_ << ']';
390 if (hasUp() && up().data_.size())
391 os << "^(" << up().data_ << ')';
395 void MathScriptInset::mathmlize2(MathInset const * nuc, MathMLStream & os) const
397 bool d = hasDown() && down().data_.size();
398 bool u = hasUp() && up().data_.size();
401 os << MTag("msubsup");
413 os << down().data_ << up().data_ << ETag("msubsup");
415 os << up().data_ << ETag("msup");
417 os << down().data_ << ETag("msub");
421 void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
425 if (hasDown() && down().data_.size())
426 os << '[' << down().data_ << ']';
427 if (hasUp() && up().data_.size())
428 os << "^(" << up().data_ << ')';