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_)
81 const_iterator it = begin(), et = end();
84 pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
88 for (; it != et; ++it) {
89 MathInset const * p = it->nucleus();
90 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
92 q->draw(p, pain, x, y);
103 int MathXArray::pos2x(size_type targetpos) const
106 const_iterator target = min(begin() + targetpos, end());
107 for (const_iterator it = begin(); it < target; ++it) {
108 MathInset const * p = it->nucleus();
109 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
114 else // "half" position
115 x += q->dxx(p) + q->nwid(p);
123 MathArray::size_type MathXArray::x2pos(int targetx) const
125 const_iterator it = begin();
128 for (; currx < targetx && it < end(); ++it) {
132 MathInset const * p = it->nucleus();
133 MathScriptInset const * q = 0;
144 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
150 int MathXArray::dist(int x, int y) const
157 else if (x > xo_ + width_)
158 xx = x - xo_ - width_;
160 if (y < yo_ - ascent_)
161 yy = yo_ - ascent_ - y;
162 else if (y > yo_ + descent_)
163 yy = y - yo_ - descent_;
169 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
178 void MathXArray::findPos(MathPosFinder & f) const
182 for (const_iterator it = begin(); it < end(); ++it) {
183 // check this position in the cell first
188 MathInset const * p = it->nucleus();
192 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
204 void MathXArray::center(int & x, int & y) const
206 x = xo_ + width_ / 2;
207 y = yo_ + (descent_ - ascent_) / 2;
211 void MathXArray::towards(int & x, int & y) const
218 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
220 x = cx + int(r * (x - cx));
221 y = cy + int(r * (y - cy));