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, LM_ST_TEXT, '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, LM_ST_TEXT, '.');
169 int MathScriptInset::nasc(MathInset const * nuc) const
171 return nuc ? nuc->ascent()
172 : mathed_char_ascent(LM_TC_VAR, LM_ST_TEXT, 'I');
176 int MathScriptInset::ndes(MathInset const * nuc) const
178 return nuc ? nuc->descent()
179 : mathed_char_descent(LM_TC_VAR, LM_ST_TEXT, 'I');
183 void MathScriptInset::metrics(MathStyles st) const
189 void MathScriptInset::metrics(MathInset const * nuc, MathStyles st) const
191 MathNestInset::metrics(st);
195 ascent_ = ascent(nuc);
196 descent_ = descent(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,
214 nuc->draw(pain, x + dxx(nuc), y);
216 drawStr(pain, LM_TC_TEX, LM_ST_TEXT, x + dxx(nuc), y, ".");
218 up().draw(pain, x + dx1(nuc), y - dy1(nuc));
220 down().draw(pain, x + dx0(nuc), y + dy0(nuc));
224 void MathScriptInset::write(std::ostream & os, bool fragile) const
226 //lyxerr << "unexpected call to MathScriptInset::write()\n";
227 write(0, os, fragile);
231 void MathScriptInset::write(MathInset const * nuc, std::ostream & os,
235 nuc->write(os, fragile);
236 if (nuc->takesLimits()) {
246 if (hasDown() && down().data_.size()) {
248 down().data_.write(os, fragile);
252 if (hasUp() && up().data_.size()) {
254 up().data_.write(os, fragile);
260 bool MathScriptInset::hasLimits(MathInset const * nuc) const
262 return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());
266 void MathScriptInset::removeEmptyScripts()
268 for (int i = 0; i <= 1; ++i)
269 if (script_[i] && !cell(i).size())
274 void MathScriptInset::removeScript(bool up)
281 bool MathScriptInset::has(bool up) const
287 bool MathScriptInset::hasUp() const
293 bool MathScriptInset::hasDown() const