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_()
25 void MathXArray::metrics(MathMetricsInfo const & mi) const
30 mathed_char_dim(LM_TC_VAR, mi, 'I', ascent_, descent_, width_);
38 for (const_iterator it = begin(); it != end(); ++it) {
39 MathInset const * p = it->nucleus();
40 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
43 ascent_ = max(ascent_, q->ascent2(p));
44 descent_ = max(descent_, q->descent2(p));
45 width_ += q->width2(p);
49 ascent_ = max(ascent_, p->ascent());
50 descent_ = max(descent_, p->descent());
54 //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
55 // << descent_ << " " << width_ << "'\n";
59 void MathXArray::draw(Painter & pain, int x, int y) const
65 pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
69 for (const_iterator it = begin(); it != end(); ++it) {
70 MathInset const * p = it->nucleus();
71 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
73 q->draw(p, pain, x, y);
84 int MathXArray::pos2x(size_type targetpos) const
87 const_iterator target = min(begin() + targetpos, end());
88 for (const_iterator it = begin(); it < target; ++it) {
89 MathInset const * p = it->nucleus();
90 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
95 else // "half" position
96 x += q->dxx(p) + q->nwid(p);
104 MathArray::size_type MathXArray::x2pos(int targetx) const
106 const_iterator it = begin();
109 for (; currx < targetx && it < end(); ++it) {
113 MathInset const * p = it->nucleus();
114 MathScriptInset const * q = 0;
125 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
131 int MathXArray::dist(int x, int y) const
138 else if (x > xo_ + width_)
139 xx = x - xo_ - width_;
141 if (y < yo_ - ascent_)
142 yy = yo_ - ascent_ - y;
143 else if (y > yo_ + descent_)
144 yy = y - yo_ - descent_;
150 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
159 void MathXArray::findPos(MathPosFinder & f) const
163 for (const_iterator it = begin(); it < end(); ++it) {
164 // check this position in the cell first
169 MathInset const * p = it->nucleus();
173 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
185 void MathXArray::center(int & x, int & y) const
187 x = xo_ + width_ / 2;
188 y = yo_ + (descent_ - ascent_) / 2;
192 void MathXArray::towards(int & x, int & y) const
199 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
201 x = cx + int(r * (x - cx));
202 y = cy + int(r * (y - cy));