7 #include "math_scriptinset.h"
8 #include "math_support.h"
17 extern MathScriptInset const * asScript(MathArray::const_iterator it);
20 MathXArray::MathXArray()
21 : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_(),
22 clean_(false), drawn_(false)
26 void MathXArray::touch() const
33 void MathXArray::metrics(MathMetricsInfo const & mi) const
43 mathed_char_dim(LM_TC_VAR, mi, 'I', ascent_, descent_, width_);
51 for (const_iterator it = begin(); it != end(); ++it) {
52 MathInset const * p = it->nucleus();
53 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
56 ascent_ = max(ascent_, q->ascent2(p));
57 descent_ = max(descent_, q->descent2(p));
58 width_ += q->width2(p);
62 ascent_ = max(ascent_, p->ascent());
63 descent_ = max(descent_, p->descent());
67 //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
68 // << descent_ << " " << width_ << "'\n";
72 void MathXArray::draw(Painter & pain, int x, int y) const
74 //if (drawn_ && x == xo_ && y == yo_)
82 pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
86 for (const_iterator it = begin(); it != end(); ++it) {
87 MathInset const * p = it->nucleus();
88 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
90 q->draw(p, pain, x, y);
101 int MathXArray::pos2x(size_type targetpos) const
104 const_iterator target = min(begin() + targetpos, end());
105 for (const_iterator it = begin(); it < target; ++it) {
106 MathInset const * p = it->nucleus();
107 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
112 else // "half" position
113 x += q->dxx(p) + q->nwid(p);
121 MathArray::size_type MathXArray::x2pos(int targetx) const
123 const_iterator it = begin();
126 for (; currx < targetx && it < end(); ++it) {
130 MathInset const * p = it->nucleus();
131 MathScriptInset const * q = 0;
142 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
148 int MathXArray::dist(int x, int y) const
155 else if (x > xo_ + width_)
156 xx = x - xo_ - width_;
158 if (y < yo_ - ascent_)
159 yy = yo_ - ascent_ - y;
160 else if (y > yo_ + descent_)
161 yy = y - yo_ - descent_;
167 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
176 void MathXArray::findPos(MathPosFinder & f) const
180 for (const_iterator it = begin(); it < end(); ++it) {
181 // check this position in the cell first
186 MathInset const * p = it->nucleus();
190 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
202 void MathXArray::center(int & x, int & y) const
204 x = xo_ + width_ / 2;
205 y = yo_ + (descent_ - ascent_) / 2;
209 void MathXArray::towards(int & x, int & y) const
216 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
218 x = cx + int(r * (x - cx));
219 y = cy + int(r * (y - cy));