7 #include "math_scriptinset.h"
8 #include "math_support.h"
9 #include "frontends/Painter.h"
10 #include "textpainter.h"
18 extern MathScriptInset const * asScript(MathArray::const_iterator it);
21 MathXArray::MathXArray()
22 : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_(),
23 clean_(false), drawn_(false)
27 void MathXArray::touch() const
34 void MathXArray::metrics(MathMetricsInfo const & mi) const
45 whichFont(font, LM_TC_VAR, mi);
46 mathed_char_dim(font, 'I', ascent_, descent_, width_);
54 for (const_iterator it = begin(); it != end(); ++it) {
55 MathInset const * p = it->nucleus();
56 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
59 ascent_ = max(ascent_, q->ascent2(p));
60 descent_ = max(descent_, q->descent2(p));
61 width_ += q->width2(p);
65 ascent_ = max(ascent_, p->ascent());
66 descent_ = max(descent_, p->descent());
70 //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
71 // << descent_ << " " << width_ << "'\n";
75 void MathXArray::draw(Painter & pain, int x, int y) const
77 //if (drawn_ && x == xo_ && y == yo_)
80 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
86 if (y + descent_ <= 0) // don't draw above the workarea
88 if (y - ascent_ >= pain.paperHeight()) // don't draw below the workarea
90 if (x + width_ <= 0) // don't draw left of workarea
92 if (x >= pain.paperWidth()) // don't draw right of workarea
95 const_iterator it = begin(), et = end();
98 pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
102 for (; it != et; ++it) {
103 MathInset const * p = it->nucleus();
104 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
106 q->draw(p, pain, x, y);
117 void MathXArray::metricsT(TextMetricsInfo const & mi) const
126 for (const_iterator it = begin(); it != end(); ++it) {
127 MathInset const * p = it->nucleus();
128 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
131 ascent_ = max(ascent_, q->ascent2(p));
132 descent_ = max(descent_, q->descent2(p));
133 width_ += q->width2(p);
137 ascent_ = max(ascent_, p->ascent());
138 descent_ = max(descent_, p->descent());
139 width_ += p->width();
145 void MathXArray::drawT(TextPainter & pain, int x, int y) const
147 //if (drawn_ && x == xo_ && y == yo_)
150 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
156 const_iterator it = begin(), et = end();
158 for (; it != et; ++it) {
159 MathInset const * p = it->nucleus();
160 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
162 q->drawT(p, pain, x, y);
166 p->drawT(pain, x, y);
173 int MathXArray::pos2x(size_type targetpos) const
176 const_iterator target = min(begin() + targetpos, end());
177 for (const_iterator it = begin(); it < target; ++it) {
178 MathInset const * p = it->nucleus();
179 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
184 else // "half" position
185 x += q->dxx(p) + q->nwid(p);
193 MathArray::size_type MathXArray::x2pos(int targetx) const
195 const_iterator it = begin();
198 for (; currx < targetx && it < end(); ++it) {
202 MathInset const * p = it->nucleus();
203 MathScriptInset const * q = 0;
214 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
220 int MathXArray::dist(int x, int y) const
227 else if (x > xo_ + width_)
228 xx = x - xo_ - width_;
230 if (y < yo_ - ascent_)
231 yy = yo_ - ascent_ - y;
232 else if (y > yo_ + descent_)
233 yy = y - yo_ - descent_;
239 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
248 void MathXArray::findPos(MathPosFinder & f) const
252 for (const_iterator it = begin(); it < end(); ++it) {
253 // check this position in the cell first
258 MathInset const * p = it->nucleus();
262 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
274 void MathXArray::center(int & x, int & y) const
276 x = xo_ + width_ / 2;
277 y = yo_ + (descent_ - ascent_) / 2;
281 void MathXArray::towards(int & x, int & y) const
288 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
290 x = cx + int(r * (x - cx));
291 y = cy + int(r * (y - cy));