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 Dimension const & MathXArray::metrics(MathMetricsInfo & mi) const
44 mathed_char_dim(mi.base.font, 'I', dim_);
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);
64 //lyxerr << "MathXArray::metrics(): '" << dim_ << "\n";
69 void MathXArray::metricsExternal(MathMetricsInfo & mi,
70 std::vector<Dimension> & v) const
80 mathed_char_dim(mi.base.font, 'I', dim_);
85 for (const_iterator it = begin(); it != end(); ++it) {
86 MathInset const * p = it->nucleus();
87 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
93 v.push_back(Dimension());
101 //for (int i = 0; i < data_.size(); ++i)
102 // lyxerr << "i: " << i << " dim: " << v[i] << endl;
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; r < v.size(); ++r)
153 // lyxerr << "row " << r << " to: " << v[r].end << endl;
154 //lyxerr << " data: " << data_ << endl;
159 for (size_type r = 0; r < v.size(); ++r) {
161 int yy = y + v[r].yo;
162 for (size_type pos = v[r].begin; pos < v[r].end && pos < data_.size(); ++pos) {
163 //lyxerr << "drawing pos " << pos << " of " << data_.size()
164 // << " " << int(data_[pos]->getChar()) << endl;
165 MathInset const * p = data_[pos].nucleus();
168 if (p->getChar() == ' ')
171 MathScriptInset const * q = 0;
172 if (pos + 1 < data_.size())
173 q = asScript(begin() + pos);
175 q->draw(p, pi, xx, yy);
187 Dimension const & MathXArray::metricsT(TextMetricsInfo const & mi) const
192 for (const_iterator it = begin(); it != end(); ++it) {
193 MathInset const * p = it->nucleus();
194 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
198 q->dimensions2(p, d);
210 void MathXArray::drawT(TextPainter & pain, int x, int y) const
212 //if (drawn_ && x == xo_ && y == yo_)
215 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
221 const_iterator it = begin(), et = end();
223 for (; it != et; ++it) {
224 MathInset const * p = it->nucleus();
225 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
227 q->drawT(p, pain, x, y);
231 p->drawT(pain, x, y);
238 int MathXArray::pos2x(size_type pos) const
240 return pos2x(0, pos, 0);
244 int MathXArray::pos2x(size_type pos1, size_type pos2, int glue) const
247 size_type target = min(pos2, data_.size());
248 for (size_type i = pos1; i < target; ++i) {
249 const_iterator it = begin() + i;
250 MathInset const * p = it->nucleus();
251 if (p->getChar() == ' ')
253 MathScriptInset const * q = (i + 1 == data_.size()) ? 0 : asScript(it);
258 else // "half" position
259 x += q->dxx(p) + q->nwid(p);
267 MathArray::size_type MathXArray::x2pos(int targetx) const
269 return x2pos(0, targetx, 0);
273 MathArray::size_type MathXArray::x2pos(size_type startpos, int targetx,
276 const_iterator it = begin() + startpos;
279 for (; currx < targetx && it < end(); ++it) {
280 size_type pos = it - begin();
283 MathInset const * p = it->nucleus();
284 if (p->getChar() == ' ')
286 MathScriptInset const * q = 0;
290 currx += q->width2(p);
296 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin() + startpos)
302 int MathXArray::dist(int x, int y) const
309 else if (x > xo_ + width())
310 xx = x - xo_ - width();
312 if (y < yo_ - ascent())
313 yy = yo_ - ascent() - y;
314 else if (y > yo_ + descent())
315 yy = y - yo_ - descent();
321 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
326 y2 = yo_ + descent();
330 void MathXArray::findPos(MathPosFinder & f) const
334 for (const_iterator it = begin(); it < end(); ++it) {
335 // check this position in the cell first
340 MathInset const * p = it->nucleus();
344 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
356 void MathXArray::center(int & x, int & y) const
358 x = xo_ + width() / 2;
359 y = yo_ + (descent() - ascent()) / 2;
363 void MathXArray::towards(int & x, int & y) const
370 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
372 x = cx + int(r * (x - cx));
373 y = cy + int(r * (y - cy));