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 : xo_(0), yo_(0), clean_(false), drawn_(false)
27 void MathXArray::touch() const
34 void MathXArray::metrics(MathMetricsInfo & mi) const
44 mathed_char_dim(mi.base.font, 'I', dim_.a, dim_.d, dim_.w);
49 for (const_iterator it = begin(); it != end(); ++it) {
50 MathInset const * p = it->nucleus();
51 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
55 q->dimensions2(p, ww, aa, dd);
59 p->dimensions(ww, aa, dd);
61 dim_ += Dimension(ww, aa, dd);
64 //lyxerr << "MathXArray::metrics(): '" << dim_ << "\n";
68 void MathXArray::metricsExternal(MathMetricsInfo & mi,
69 std::vector<Row> & v) const
79 mathed_char_dim(mi.base.font, 'I', dim_.a, dim_.d, dim_.w);
84 for (const_iterator it = begin(); it != end(); ++it) {
85 MathInset const * p = it->nucleus();
86 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
90 q->dimensions2(p, ww, aa, dd);
93 v.back().dim = Dimension(ww, aa, dd);
97 p->dimensions(ww, aa, dd);
99 v.back().dim = Dimension(ww, aa, dd);
103 //lyxerr << "MathXArray::metrics(): '" << dim_ << "\n";
107 void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
109 //if (drawn_ && x == xo_ && y == yo_)
112 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
118 if (y + descent() <= 0) // don't draw above the workarea
120 if (y - ascent() >= pi.pain.paperHeight()) // don't draw below the workarea
122 if (x + width() <= 0) // don't draw left of workarea
124 if (x >= pi.pain.paperWidth()) // don't draw right of workarea
127 const_iterator it = begin(), et = end();
130 pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline);
134 for (; it != et; ++it) {
135 MathInset const * p = it->nucleus();
136 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
138 q->draw(p, pi, x, y);
149 void MathXArray::drawExternal(MathPainterInfo & pi, int x, int y,
150 std::vector<Row> const & v) const
152 for (size_type r = 0, pos = 0; r != v.size(); ++r) {
154 int yy = y + v[r].yo;
155 for ( ; pos != v[r].end; ++pos) {
156 MathInset const * p = data_[pos].nucleus();
157 MathScriptInset const * q = 0;
158 if (pos + 1 != data_.size())
159 q = asScript(begin() + pos + 1);
161 q->draw(p, pi, xx, yy);
173 void MathXArray::metricsT(TextMetricsInfo const & mi) const
178 for (const_iterator it = begin(); it != end(); ++it) {
179 MathInset const * p = it->nucleus();
180 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
184 q->dimensions2(p, ww, aa, dd);
188 p->dimensions(ww, aa, dd);
190 dim_ += Dimension(ww, aa, dd);
195 void MathXArray::drawT(TextPainter & pain, int x, int y) const
197 //if (drawn_ && x == xo_ && y == yo_)
200 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
206 const_iterator it = begin(), et = end();
208 for (; it != et; ++it) {
209 MathInset const * p = it->nucleus();
210 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
212 q->drawT(p, pain, x, y);
216 p->drawT(pain, x, y);
223 int MathXArray::pos2x(size_type targetpos) const
226 const_iterator target = min(begin() + targetpos, end());
227 for (const_iterator it = begin(); it < target; ++it) {
228 MathInset const * p = it->nucleus();
229 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
234 else // "half" position
235 x += q->dxx(p) + q->nwid(p);
243 MathArray::size_type MathXArray::x2pos(int targetx) const
245 const_iterator it = begin();
248 for (; currx < targetx && it < end(); ++it) {
252 MathInset const * p = it->nucleus();
253 MathScriptInset const * q = 0;
264 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
270 int MathXArray::dist(int x, int y) const
277 else if (x > xo_ + width())
278 xx = x - xo_ - width();
280 if (y < yo_ - ascent())
281 yy = yo_ - ascent() - y;
282 else if (y > yo_ + descent())
283 yy = y - yo_ - descent();
289 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
294 y2 = yo_ + descent();
298 void MathXArray::findPos(MathPosFinder & f) const
302 for (const_iterator it = begin(); it < end(); ++it) {
303 // check this position in the cell first
308 MathInset const * p = it->nucleus();
312 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
324 void MathXArray::center(int & x, int & y) const
326 x = xo_ + width() / 2;
327 y = yo_ + (descent() - ascent()) / 2;
331 void MathXArray::towards(int & x, int & y) const
338 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
340 x = cx + int(r * (x - cx));
341 y = cy + int(r * (y - cy));