7 #include "math_scriptinset.h"
8 #include "math_support.h"
9 #include "frontends/Painter.h"
10 #include "textpainter.h"
19 extern MathScriptInset const * asScript(MathArray::const_iterator it);
22 MathXArray::MathXArray()
23 : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0),
24 clean_(false), drawn_(false)
28 void MathXArray::touch() const
35 void MathXArray::metrics(MathMetricsInfo & mi) const
45 mathed_char_dim(mi.base.font, 'I', ascent_, descent_, width_);
53 for (const_iterator it = begin(); it != end(); ++it) {
54 MathInset const * p = it->nucleus();
55 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
59 a = max(a, q->ascent2(p));
60 d = max(d, q->descent2(p));
65 a = max(a, p->ascent());
66 d = max(d, p->descent());
76 //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
77 // << descent_ << " " << width_ << "'\n";
83 if (mi.base.restrictwidth) {
84 width_ = mi.base.textwidth;
85 lyxerr << "restricting width to " << width_ << " pixel\n";
90 void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
92 //if (drawn_ && x == xo_ && y == yo_)
95 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
101 if (y + descent_ <= 0) // don't draw above the workarea
103 if (y - ascent_ >= pi.pain.paperHeight()) // don't draw below the workarea
105 if (x + width_ <= 0) // don't draw left of workarea
107 if (x >= pi.pain.paperWidth()) // don't draw right of workarea
110 const_iterator it = begin(), et = end();
113 pi.pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
117 for (; it != et; ++it) {
118 MathInset const * p = it->nucleus();
119 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
121 q->draw(p, pi, x, y);
131 // re-break paragraph
133 if (pi.base.restrictwidth) {
138 void MathXArray::metricsT(TextMetricsInfo const & mi) const
147 for (const_iterator it = begin(); it != end(); ++it) {
148 MathInset const * p = it->nucleus();
149 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
152 ascent_ = max(ascent_, q->ascent2(p));
153 descent_ = max(descent_, q->descent2(p));
154 width_ += q->width2(p);
158 ascent_ = max(ascent_, p->ascent());
159 descent_ = max(descent_, p->descent());
160 width_ += p->width();
166 void MathXArray::drawT(TextPainter & pain, int x, int y) const
168 //if (drawn_ && x == xo_ && y == yo_)
171 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
177 const_iterator it = begin(), et = end();
179 for (; it != et; ++it) {
180 MathInset const * p = it->nucleus();
181 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
183 q->drawT(p, pain, x, y);
187 p->drawT(pain, x, y);
194 int MathXArray::pos2x(size_type targetpos) const
197 const_iterator target = min(begin() + targetpos, end());
198 for (const_iterator it = begin(); it < target; ++it) {
199 MathInset const * p = it->nucleus();
200 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
205 else // "half" position
206 x += q->dxx(p) + q->nwid(p);
214 MathArray::size_type MathXArray::x2pos(int targetx) const
216 const_iterator it = begin();
219 for (; currx < targetx && it < end(); ++it) {
223 MathInset const * p = it->nucleus();
224 MathScriptInset const * q = 0;
235 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
241 int MathXArray::dist(int x, int y) const
248 else if (x > xo_ + width_)
249 xx = x - xo_ - width_;
251 if (y < yo_ - ascent_)
252 yy = yo_ - ascent_ - y;
253 else if (y > yo_ + descent_)
254 yy = y - yo_ - descent_;
260 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
269 void MathXArray::findPos(MathPosFinder & f) const
273 for (const_iterator it = begin(); it < end(); ++it) {
274 // check this position in the cell first
279 MathInset const * p = it->nucleus();
283 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
295 void MathXArray::center(int & x, int & y) const
297 x = xo_ + width_ / 2;
298 y = yo_ + (descent_ - ascent_) / 2;
302 void MathXArray::towards(int & x, int & y) const
309 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
311 x = cx + int(r * (x - cx));
312 y = cy + int(r * (y - cy));