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), size_(),
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);
58 ascent_ = max(ascent_, q->ascent2(p));
59 descent_ = max(descent_, q->descent2(p));
60 width_ += q->width2(p);
64 ascent_ = max(ascent_, p->ascent());
65 descent_ = max(descent_, p->descent());
69 //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
70 // << descent_ << " " << width_ << "'\n";
76 if (mi.base.restrictwidth) {
77 width_ = mi.base.textwidth;
78 lyxerr << "restricting width to " << width_ << " pixel\n";
83 void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
85 //if (drawn_ && x == xo_ && y == yo_)
88 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
94 if (y + descent_ <= 0) // don't draw above the workarea
96 if (y - ascent_ >= pi.pain.paperHeight()) // don't draw below the workarea
98 if (x + width_ <= 0) // don't draw left of workarea
100 if (x >= pi.pain.paperWidth()) // don't draw right of workarea
103 const_iterator it = begin(), et = end();
106 pi.pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
110 for (; it != et; ++it) {
111 MathInset const * p = it->nucleus();
112 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
114 q->draw(p, pi, x, y);
124 // re-break paragraph
126 if (pi.base.restrictwidth) {
131 void MathXArray::metricsT(TextMetricsInfo const & mi) const
140 for (const_iterator it = begin(); it != end(); ++it) {
141 MathInset const * p = it->nucleus();
142 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
145 ascent_ = max(ascent_, q->ascent2(p));
146 descent_ = max(descent_, q->descent2(p));
147 width_ += q->width2(p);
151 ascent_ = max(ascent_, p->ascent());
152 descent_ = max(descent_, p->descent());
153 width_ += p->width();
159 void MathXArray::drawT(TextPainter & pain, int x, int y) const
161 //if (drawn_ && x == xo_ && y == yo_)
164 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
170 const_iterator it = begin(), et = end();
172 for (; it != et; ++it) {
173 MathInset const * p = it->nucleus();
174 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
176 q->drawT(p, pain, x, y);
180 p->drawT(pain, x, y);
187 int MathXArray::pos2x(size_type targetpos) const
190 const_iterator target = min(begin() + targetpos, end());
191 for (const_iterator it = begin(); it < target; ++it) {
192 MathInset const * p = it->nucleus();
193 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
198 else // "half" position
199 x += q->dxx(p) + q->nwid(p);
207 MathArray::size_type MathXArray::x2pos(int targetx) const
209 const_iterator it = begin();
212 for (; currx < targetx && it < end(); ++it) {
216 MathInset const * p = it->nucleus();
217 MathScriptInset const * q = 0;
228 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
234 int MathXArray::dist(int x, int y) const
241 else if (x > xo_ + width_)
242 xx = x - xo_ - width_;
244 if (y < yo_ - ascent_)
245 yy = yo_ - ascent_ - y;
246 else if (y > yo_ + descent_)
247 yy = y - yo_ - descent_;
253 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
262 void MathXArray::findPos(MathPosFinder & f) const
266 for (const_iterator it = begin(); it < end(); ++it) {
267 // check this position in the cell first
272 MathInset const * p = it->nucleus();
276 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
288 void MathXArray::center(int & x, int & y) const
290 x = xo_ + width_ / 2;
291 y = yo_ + (descent_ - ascent_) / 2;
295 void MathXArray::towards(int & x, int & y) const
302 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
304 x = cx + int(r * (x - cx));
305 y = cy + int(r * (y - cy));