7 #include "math_scriptinset.h"
8 #include "math_support.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
44 mathed_char_dim(LM_TC_VAR, mi, '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);
57 ascent_ = max(ascent_, q->ascent2(p));
58 descent_ = max(descent_, q->descent2(p));
59 width_ += q->width2(p);
63 ascent_ = max(ascent_, p->ascent());
64 descent_ = max(descent_, p->descent());
68 //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
69 // << descent_ << " " << width_ << "'\n";
73 void MathXArray::draw(Painter & pain, int x, int y) const
75 //if (drawn_ && x == xo_ && y == yo_)
78 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
84 if (y + descent_ <= 0) // don't draw above the workarea
86 if (y - ascent_ >= pain.paperHeight()) // don't draw below the workarea
88 if (x + width_ <= 0) // don't draw left of workarea
90 if (x >= pain.paperWidth()) // don't draw right of workarea
93 const_iterator it = begin(), et = end();
96 pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
100 for (; it != et; ++it) {
101 MathInset const * p = it->nucleus();
102 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
104 q->draw(p, pain, x, y);
115 void MathXArray::metrics(TextMetricsInfo const & mi) const
124 for (const_iterator it = begin(); it != end(); ++it) {
125 MathInset const * p = it->nucleus();
126 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
129 ascent_ = max(ascent_, q->ascent2(p));
130 descent_ = max(descent_, q->descent2(p));
131 width_ += q->width2(p);
135 ascent_ = max(ascent_, p->ascent());
136 descent_ = max(descent_, p->descent());
137 width_ += p->width();
143 void MathXArray::draw(TextPainter & pain, int x, int y) const
145 //if (drawn_ && x == xo_ && y == yo_)
148 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
154 const_iterator it = begin(), et = end();
156 for (; it != et; ++it) {
157 MathInset const * p = it->nucleus();
158 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
160 q->draw(p, pain, x, y);
171 int MathXArray::pos2x(size_type targetpos) const
174 const_iterator target = min(begin() + targetpos, end());
175 for (const_iterator it = begin(); it < target; ++it) {
176 MathInset const * p = it->nucleus();
177 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
182 else // "half" position
183 x += q->dxx(p) + q->nwid(p);
191 MathArray::size_type MathXArray::x2pos(int targetx) const
193 const_iterator it = begin();
196 for (; currx < targetx && it < end(); ++it) {
200 MathInset const * p = it->nucleus();
201 MathScriptInset const * q = 0;
212 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
218 int MathXArray::dist(int x, int y) const
225 else if (x > xo_ + width_)
226 xx = x - xo_ - width_;
228 if (y < yo_ - ascent_)
229 yy = yo_ - ascent_ - y;
230 else if (y > yo_ + descent_)
231 yy = y - yo_ - descent_;
237 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
246 void MathXArray::findPos(MathPosFinder & f) const
250 for (const_iterator it = begin(); it < end(); ++it) {
251 // check this position in the cell first
256 MathInset const * p = it->nucleus();
260 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
272 void MathXArray::center(int & x, int & y) const
274 x = xo_ + width_ / 2;
275 y = yo_ + (descent_ - ascent_) / 2;
279 void MathXArray::towards(int & x, int & y) const
286 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
288 x = cx + int(r * (x - cx));
289 y = cy + int(r * (y - cy));