4 #include "support/LOstream.h"
5 #include "support/LAssert.h"
11 #include "math_scriptinset.h"
14 MathScriptInset::MathScriptInset()
15 : MathNestInset(2), limits_(0)
22 MathScriptInset::MathScriptInset(bool up)
23 : MathNestInset(2), limits_(0)
31 MathInset * MathScriptInset::clone() const
33 return new MathScriptInset(*this);
37 MathScriptInset const * MathScriptInset::asScriptInset() const
43 MathScriptInset * MathScriptInset::asScriptInset()
49 MathXArray const & MathScriptInset::up() const
55 MathXArray const & MathScriptInset::down() const
61 MathXArray & MathScriptInset::up()
67 MathXArray & MathScriptInset::down()
73 void MathScriptInset::ensure(bool up)
79 int MathScriptInset::dy0(MathInset const * nuc) const
84 int des = down().ascent();
88 des = std::max(des, nd);
93 int MathScriptInset::dy1(MathInset const * nuc) const
98 int asc = up().descent();
102 asc = std::max(asc, na);
103 asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, size_, 'I'));
108 int MathScriptInset::dx0(MathInset const * nuc) const
110 lyx::Assert(hasDown());
111 return hasLimits(nuc) ? (width(nuc) - down().width()) / 2 : nwid(nuc);
115 int MathScriptInset::dx1(MathInset const * nuc) const
117 lyx::Assert(hasUp());
118 return hasLimits(nuc) ? (width(nuc) - up().width()) / 2 : nwid(nuc);
122 int MathScriptInset::dxx(MathInset const * nuc) const
124 //lyx::Assert(nuc());
125 return hasLimits(nuc) ? (width(nuc) - nwid(nuc)) / 2 : 0;
129 int MathScriptInset::ascent(MathInset const * nuc) const
131 return dy1(nuc) + (hasUp() ? up().ascent() : 0);
135 int MathScriptInset::descent(MathInset const * nuc) const
137 return dy0(nuc) + (hasDown() ? down().descent() : 0);
141 int MathScriptInset::width(MathInset const * nuc) const
144 if (hasLimits(nuc)) {
147 wid = std::max(wid, up().width());
149 wid = std::max(wid, down().width());
152 wid = std::max(wid, up().width());
154 wid = std::max(wid, down().width());
161 int MathScriptInset::nwid(MathInset const * nuc) const
165 mathed_char_width(LM_TC_TEX, size_, '.');
169 int MathScriptInset::nasc(MathInset const * nuc) const
171 return nuc ? nuc->ascent()
172 : mathed_char_ascent(LM_TC_VAR, size_, 'I');
176 int MathScriptInset::ndes(MathInset const * nuc) const
178 return nuc ? nuc->descent()
179 : mathed_char_descent(LM_TC_VAR, size_, 'I');
183 void MathScriptInset::metrics(MathMetricsInfo const & st) const
189 void MathScriptInset::metrics(MathInset const * nuc,
190 MathMetricsInfo const & st) const
192 MathNestInset::metrics(st);
196 ascent_ = ascent(nuc);
197 descent_ = descent(nuc);
202 void MathScriptInset::draw(Painter & pain, int x, int y) const
204 //lyxerr << "unexpected call to MathScriptInset::draw()\n";
209 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
216 nuc->draw(pain, x + dxx(nuc), y);
218 drawStr(pain, LM_TC_TEX, size_, x + dxx(nuc), y, ".");
221 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
224 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
228 void MathScriptInset::write(MathWriteInfo & os) const
230 //lyxerr << "unexpected call to MathScriptInset::write()\n";
235 void MathScriptInset::write(MathInset const * nuc, MathWriteInfo & os) const
239 if (nuc->takesLimits()) {
249 if (hasDown() && down().data_.size())
250 os << "_{" << down().data_ << '}';
252 if (hasUp() && up().data_.size())
253 os << "^{" << up().data_ << '}';
257 bool MathScriptInset::hasLimits(MathInset const * nuc) const
259 return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());
263 void MathScriptInset::removeEmptyScripts()
265 for (int i = 0; i <= 1; ++i)
266 if (script_[i] && !cell(i).size())
271 void MathScriptInset::removeScript(bool up)
278 bool MathScriptInset::has(bool up) const
284 bool MathScriptInset::hasUp() const
290 bool MathScriptInset::hasDown() const
296 bool MathScriptInset::idxRight(MathInset::idx_type &,
297 MathInset::pos_type &) const
303 bool MathScriptInset::idxLeft(MathInset::idx_type &,
304 MathInset::pos_type &) const