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_)
77 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
83 if (y + descent_ <= 0) // don't draw above the workarea
85 if (y - ascent_ >= pain.paperHeight()) // don't draw below the workarea
87 if (x + width_ <= 0) // don't draw left of workarea
89 if (x >= pain.paperWidth()) // don't draw right of workarea
92 const_iterator it = begin(), et = end();
95 pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
99 for (; it != et; ++it) {
100 MathInset const * p = it->nucleus();
101 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
103 q->draw(p, pain, x, y);
114 int MathXArray::pos2x(size_type targetpos) const
117 const_iterator target = min(begin() + targetpos, end());
118 for (const_iterator it = begin(); it < target; ++it) {
119 MathInset const * p = it->nucleus();
120 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
125 else // "half" position
126 x += q->dxx(p) + q->nwid(p);
134 MathArray::size_type MathXArray::x2pos(int targetx) const
136 const_iterator it = begin();
139 for (; currx < targetx && it < end(); ++it) {
143 MathInset const * p = it->nucleus();
144 MathScriptInset const * q = 0;
155 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
161 int MathXArray::dist(int x, int y) const
168 else if (x > xo_ + width_)
169 xx = x - xo_ - width_;
171 if (y < yo_ - ascent_)
172 yy = yo_ - ascent_ - y;
173 else if (y > yo_ + descent_)
174 yy = y - yo_ - descent_;
180 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
189 void MathXArray::findPos(MathPosFinder & f) const
193 for (const_iterator it = begin(); it < end(); ++it) {
194 // check this position in the cell first
199 MathInset const * p = it->nucleus();
203 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
215 void MathXArray::center(int & x, int & y) const
217 x = xo_ + width_ / 2;
218 y = yo_ + (descent_ - ascent_) / 2;
222 void MathXArray::towards(int & x, int & y) const
229 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
231 x = cx + int(r * (x - cx));
232 y = cy + int(r * (y - cy));