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 : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_(),
24 clean_(false), drawn_(false)
28 void MathXArray::touch() const
35 void MathXArray::metrics(MathMetricsInfo const & mi) const
46 whichFont(font, LM_TC_VAR, mi);
47 mathed_char_dim(font, 'I', ascent_, descent_, width_);
55 for (const_iterator it = begin(); it != end(); ++it) {
56 MathInset const * p = it->nucleus();
57 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
60 ascent_ = max(ascent_, q->ascent2(p));
61 descent_ = max(descent_, q->descent2(p));
62 width_ += q->width2(p);
66 ascent_ = max(ascent_, p->ascent());
67 descent_ = max(descent_, p->descent());
71 //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
72 // << descent_ << " " << width_ << "'\n";
76 void MathXArray::draw(Painter & pain, int x, int y) const
78 //if (drawn_ && x == xo_ && y == yo_)
81 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
87 if (y + descent_ <= 0) // don't draw above the workarea
89 if (y - ascent_ >= pain.paperHeight()) // don't draw below the workarea
91 if (x + width_ <= 0) // don't draw left of workarea
93 if (x >= pain.paperWidth()) // don't draw right of workarea
96 const_iterator it = begin(), et = end();
99 pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
103 for (; it != et; ++it) {
104 MathInset const * p = it->nucleus();
105 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
107 q->draw(p, pain, x, y);
118 void MathXArray::metricsT(TextMetricsInfo const & mi) const
127 for (const_iterator it = begin(); it != end(); ++it) {
128 MathInset const * p = it->nucleus();
129 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
132 ascent_ = max(ascent_, q->ascent2(p));
133 descent_ = max(descent_, q->descent2(p));
134 width_ += q->width2(p);
138 ascent_ = max(ascent_, p->ascent());
139 descent_ = max(descent_, p->descent());
140 width_ += p->width();
146 void MathXArray::drawT(TextPainter & pain, int x, int y) const
148 //if (drawn_ && x == xo_ && y == yo_)
151 //lyxerr << "x: " << x << " y: " << y << " " << pain.workAreaHeight() << endl;
157 const_iterator it = begin(), et = end();
159 for (; it != et; ++it) {
160 MathInset const * p = it->nucleus();
161 MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it);
163 q->drawT(p, pain, x, y);
167 p->drawT(pain, x, y);
174 int MathXArray::pos2x(size_type targetpos) const
177 const_iterator target = min(begin() + targetpos, end());
178 for (const_iterator it = begin(); it < target; ++it) {
179 MathInset const * p = it->nucleus();
180 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
185 else // "half" position
186 x += q->dxx(p) + q->nwid(p);
194 MathArray::size_type MathXArray::x2pos(int targetx) const
196 const_iterator it = begin();
199 for (; currx < targetx && it < end(); ++it) {
203 MathInset const * p = it->nucleus();
204 MathScriptInset const * q = 0;
215 if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
221 int MathXArray::dist(int x, int y) const
228 else if (x > xo_ + width_)
229 xx = x - xo_ - width_;
231 if (y < yo_ - ascent_)
232 yy = yo_ - ascent_ - y;
233 else if (y > yo_ + descent_)
234 yy = y - yo_ - descent_;
240 void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2)
249 void MathXArray::findPos(MathPosFinder & f) const
253 for (const_iterator it = begin(); it < end(); ++it) {
254 // check this position in the cell first
259 MathInset const * p = it->nucleus();
263 MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it);
275 void MathXArray::center(int & x, int & y) const
277 x = xo_ + width_ / 2;
278 y = yo_ + (descent_ - ascent_) / 2;
282 void MathXArray::towards(int & x, int & y) const
289 //int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
291 x = cx + int(r * (x - cx));
292 y = cy + int(r * (y - cy));