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_);
52 for (const_iterator it = begin(); it != end(); ++it) {
53 MathInset const * p = it->nucleus();
54 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
58 q->dimensions2(p, ww, aa, dd);
63 ascent_ = max(ascent_, aa);
64 descent_ = max(descent_, dd);
68 //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
69 // << descent_ << " " << width_ << "'\n";
75 if (mi.base.restrictwidth) {
76 width_ = mi.base.textwidth;
77 lyxerr << "restricting width to " << width_ << " pixel\n";
82 void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
84 //if (drawn_ && x == xo_ && y == yo_)
87 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
93 if (y + descent_ <= 0) // don't draw above the workarea
95 if (y - ascent_ >= pi.pain.paperHeight()) // don't draw below the workarea
97 if (x + width_ <= 0) // don't draw left of workarea
99 if (x >= pi.pain.paperWidth()) // don't draw right of workarea
102 const_iterator it = begin(), et = end();
105 pi.pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
109 for (; it != et; ++it) {
110 MathInset const * p = it->nucleus();
111 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
113 q->draw(p, pi, x, y);
123 // re-break paragraph
125 if (pi.base.restrictwidth) {
130 void MathXArray::metricsT(TextMetricsInfo const & mi) const
139 for (const_iterator it = begin(); it != end(); ++it) {
140 MathInset const * p = it->nucleus();
141 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
145 q->dimensions(ww, aa, dd);
150 ascent_ = max(ascent_, aa);
151 descent_ = max(descent_, dd);
157 void MathXArray::drawT(TextPainter & pain, int x, int y) const
159 //if (drawn_ && x == xo_ && y == yo_)
162 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
168 const_iterator it = begin(), et = end();
170 for (; it != et; ++it) {
171 MathInset const * p = it->nucleus();
172 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
174 q->drawT(p, pain, x, y);
178 p->drawT(pain, x, y);
185 int MathXArray::pos2x(size_type targetpos) const
188 const_iterator target = min(begin() + targetpos, end());
189 for (const_iterator it = begin(); it < target; ++it) {
190 MathInset const * p = it->nucleus();
191 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
196 else // "half" position
197 x += q->dxx(p) + q->nwid(p);
205 MathArray::size_type MathXArray::x2pos(int targetx) const
207 const_iterator it = begin();
210 for (; currx < targetx && it < end(); ++it) {
214 MathInset const * p = it->nucleus();
215 MathScriptInset const * q = 0;
226 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
232 int MathXArray::dist(int x, int y) const
239 else if (x > xo_ + width_)
240 xx = x - xo_ - width_;
242 if (y < yo_ - ascent_)
243 yy = yo_ - ascent_ - y;
244 else if (y > yo_ + descent_)
245 yy = y - yo_ - descent_;
251 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
260 void MathXArray::findPos(MathPosFinder & f) const
264 for (const_iterator it = begin(); it < end(); ++it) {
265 // check this position in the cell first
270 MathInset const * p = it->nucleus();
274 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
286 void MathXArray::center(int & x, int & y) const
288 x = xo_ + width_ / 2;
289 y = yo_ + (descent_ - ascent_) / 2;
293 void MathXArray::towards(int & x, int & y) const
300 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
302 x = cx + int(r * (x - cx));
303 y = cy + int(r * (y - cy));