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<Row> & 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);
104 //lyxerr << "MathXArray::metrics(): '" << dim_ << "\n";
108 void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
110 //if (drawn_ && x == xo_ && y == yo_)
113 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
119 if (y + descent() <= 0) // don't draw above the workarea
121 if (y - ascent() >= pi.pain.paperHeight()) // don't draw below the workarea
123 if (x + width() <= 0) // don't draw left of workarea
125 if (x >= pi.pain.paperWidth()) // don't draw right of workarea
128 const_iterator it = begin(), et = end();
131 pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline);
135 for (; it != et; ++it) {
136 MathInset const * p = it->nucleus();
137 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
139 q->draw(p, pi, x, y);
150 void MathXArray::drawExternal(MathPainterInfo & pi, int x, int y,
151 std::vector<Row> const & v) const
153 for (size_type r = 0, pos = 0; r != v.size(); ++r) {
155 int yy = y + v[r].yo;
156 for ( ; pos != v[r].end; ++pos) {
157 MathInset const * p = data_[pos].nucleus();
158 MathScriptInset const * q = 0;
159 if (pos + 1 != data_.size())
160 q = asScript(begin() + pos + 1);
162 q->draw(p, pi, xx, yy);
174 Dimension const & MathXArray::metricsT(TextMetricsInfo const & mi) const
179 for (const_iterator it = begin(); it != end(); ++it) {
180 MathInset const * p = it->nucleus();
181 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
185 q->dimensions2(p, d);
197 void MathXArray::drawT(TextPainter & pain, int x, int y) const
199 //if (drawn_ && x == xo_ && y == yo_)
202 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
208 const_iterator it = begin(), et = end();
210 for (; it != et; ++it) {
211 MathInset const * p = it->nucleus();
212 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
214 q->drawT(p, pain, x, y);
218 p->drawT(pain, x, y);
225 int MathXArray::pos2x(size_type targetpos) const
228 const_iterator target = min(begin() + targetpos, end());
229 for (const_iterator it = begin(); it < target; ++it) {
230 MathInset const * p = it->nucleus();
231 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
236 else // "half" position
237 x += q->dxx(p) + q->nwid(p);
245 MathArray::size_type MathXArray::x2pos(int targetx) const
247 const_iterator it = begin();
250 for (; currx < targetx && it < end(); ++it) {
254 MathInset const * p = it->nucleus();
255 MathScriptInset const * q = 0;
266 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
272 int MathXArray::dist(int x, int y) const
279 else if (x > xo_ + width())
280 xx = x - xo_ - width();
282 if (y < yo_ - ascent())
283 yy = yo_ - ascent() - y;
284 else if (y > yo_ + descent())
285 yy = y - yo_ - descent();
291 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
296 y2 = yo_ + descent();
300 void MathXArray::findPos(MathPosFinder & f) const
304 for (const_iterator it = begin(); it < end(); ++it) {
305 // check this position in the cell first
310 MathInset const * p = it->nucleus();
314 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
326 void MathXArray::center(int & x, int & y) const
328 x = xo_ + width() / 2;
329 y = yo_ + (descent() - ascent()) / 2;
333 void MathXArray::towards(int & x, int & y) const
340 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
342 x = cx + int(r * (x - cx));
343 y = cy + int(r * (y - cy));