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";
74 void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
76 //if (drawn_ && x == xo_ && y == yo_)
79 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
85 if (y + descent_ <= 0) // don't draw above the workarea
87 if (y - ascent_ >= pi.pain.paperHeight()) // don't draw below the workarea
89 if (x + width_ <= 0) // don't draw left of workarea
91 if (x >= pi.pain.paperWidth()) // don't draw right of workarea
94 const_iterator it = begin(), et = end();
97 pi.pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
101 for (; it != et; ++it) {
102 MathInset const * p = it->nucleus();
103 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
105 q->draw(p, pi, x, y);
116 void MathXArray::metricsT(TextMetricsInfo const & mi) const
125 for (const_iterator it = begin(); it != end(); ++it) {
126 MathInset const * p = it->nucleus();
127 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
130 ascent_ = max(ascent_, q->ascent2(p));
131 descent_ = max(descent_, q->descent2(p));
132 width_ += q->width2(p);
136 ascent_ = max(ascent_, p->ascent());
137 descent_ = max(descent_, p->descent());
138 width_ += p->width();
144 void MathXArray::drawT(TextPainter & pain, int x, int y) const
146 //if (drawn_ && x == xo_ && y == yo_)
149 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
155 const_iterator it = begin(), et = end();
157 for (; it != et; ++it) {
158 MathInset const * p = it->nucleus();
159 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
161 q->drawT(p, pain, x, y);
165 p->drawT(pain, x, y);
172 int MathXArray::pos2x(size_type targetpos) const
175 const_iterator target = min(begin() + targetpos, end());
176 for (const_iterator it = begin(); it < target; ++it) {
177 MathInset const * p = it->nucleus();
178 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
183 else // "half" position
184 x += q->dxx(p) + q->nwid(p);
192 MathArray::size_type MathXArray::x2pos(int targetx) const
194 const_iterator it = begin();
197 for (; currx < targetx && it < end(); ++it) {
201 MathInset const * p = it->nucleus();
202 MathScriptInset const * q = 0;
213 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
219 int MathXArray::dist(int x, int y) const
226 else if (x > xo_ + width_)
227 xx = x - xo_ - width_;
229 if (y < yo_ - ascent_)
230 yy = yo_ - ascent_ - y;
231 else if (y > yo_ + descent_)
232 yy = y - yo_ - descent_;
238 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
247 void MathXArray::findPos(MathPosFinder & f) const
251 for (const_iterator it = begin(); it < end(); ++it) {
252 // check this position in the cell first
257 MathInset const * p = it->nucleus();
261 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
273 void MathXArray::center(int & x, int & y) const
275 x = xo_ + width_ / 2;
276 y = yo_ + (descent_ - ascent_) / 2;
280 void MathXArray::towards(int & x, int & y) const
287 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
289 x = cx + int(r * (x - cx));
290 y = cy + int(r * (y - cy));