X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_xdata.C;h=fff922a5720c5b21e01e3ad14f21f2e28f0cf05b;hb=d359dd8fca52c4f0100f7cf4bf636113c5c4e49f;hp=e15e052b09274e036e85bfe12b47e5f9f0515811;hpb=99cb25781ac599f3aeefb5b391b95ed26b74405f;p=lyx.git diff --git a/src/mathed/math_xdata.C b/src/mathed/math_xdata.C index e15e052b09..fff922a572 100644 --- a/src/mathed/math_xdata.C +++ b/src/mathed/math_xdata.C @@ -6,32 +6,32 @@ #include "math_scriptinset.h" #include "math_support.h" -#include "Painter.h" +#include "frontends/Painter.h" #include "textpainter.h" #include "debug.h" using std::max; using std::min; +using std::abs; extern MathScriptInset const * asScript(MathArray::const_iterator it); MathXArray::MathXArray() - : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_(), - clean_(false), drawn_(false) + : xo_(0), yo_(0), clean_(false), drawn_(false) {} void MathXArray::touch() const -{ +{ clean_ = false; drawn_ = false; } -void MathXArray::metrics(MathMetricsInfo const & mi) const +void MathXArray::metrics(MathMetricsInfo & mi) const { //if (clean_) // return; @@ -41,36 +41,70 @@ void MathXArray::metrics(MathMetricsInfo const & mi) const drawn_ = false; if (data_.empty()) { - mathed_char_dim(LM_TC_VAR, mi, 'I', ascent_, descent_, width_); + mathed_char_dim(mi.base.font, 'I', dim_.a, dim_.d, dim_.w); return; } - ascent_ = 0; - descent_ = 0; - width_ = 0; + dim_.clear(); + for (const_iterator it = begin(); it != end(); ++it) { + MathInset const * p = it->nucleus(); + MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it); + int ww, aa, dd; + if (q) { + q->metrics(p, mi); + q->dimensions2(p, ww, aa, dd); + ++it; + } else { + p->metrics(mi); + p->dimensions(ww, aa, dd); + } + dim_ += Dimension(ww, aa, dd); + } + + //lyxerr << "MathXArray::metrics(): '" << dim_ << "\n"; +} + +void MathXArray::metricsExternal(MathMetricsInfo & mi, + std::vector & v) const +{ + //if (clean_) + // return; + + size_ = mi; + clean_ = true; + drawn_ = false; + + if (data_.empty()) { + mathed_char_dim(mi.base.font, 'I', dim_.a, dim_.d, dim_.w); + return; + } + + dim_.clear(); for (const_iterator it = begin(); it != end(); ++it) { MathInset const * p = it->nucleus(); MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it); + int ww, aa, dd; if (q) { q->metrics(p, mi); - ascent_ = max(ascent_, q->ascent2(p)); - descent_ = max(descent_, q->descent2(p)); - width_ += q->width2(p); + q->dimensions2(p, ww, aa, dd); ++it; + v.push_back(Row()); + v.back().dim = Dimension(ww, aa, dd); + v.push_back(Row()); } else { p->metrics(mi); - ascent_ = max(ascent_, p->ascent()); - descent_ = max(descent_, p->descent()); - width_ += p->width(); + p->dimensions(ww, aa, dd); + v.push_back(Row()); + v.back().dim = Dimension(ww, aa, dd); } } - //lyxerr << "MathXArray::metrics(): '" << ascent_ << " " - // << descent_ << " " << width_ << "'\n"; + + //lyxerr << "MathXArray::metrics(): '" << dim_ << "\n"; } -void MathXArray::draw(Painter & pain, int x, int y) const +void MathXArray::draw(MathPainterInfo & pi, int x, int y) const { //if (drawn_ && x == xo_ && y == yo_) // return; @@ -81,19 +115,19 @@ void MathXArray::draw(Painter & pain, int x, int y) const yo_ = y; drawn_ = true; - if (y + descent_ <= 0) // don't draw above the workarea + if (y + descent() <= 0) // don't draw above the workarea return; - if (y - ascent_ >= pain.paperHeight()) // don't draw below the workarea + if (y - ascent() >= pi.pain.paperHeight()) // don't draw below the workarea return; - if (x + width_ <= 0) // don't draw left of workarea + if (x + width() <= 0) // don't draw left of workarea return; - if (x >= pain.paperWidth()) // don't draw right of workarea + if (x >= pi.pain.paperWidth()) // don't draw right of workarea return; const_iterator it = begin(), et = end(); if (it == et) { - pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline); + pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline); return; } @@ -101,46 +135,64 @@ void MathXArray::draw(Painter & pain, int x, int y) const MathInset const * p = it->nucleus(); MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it); if (q) { - q->draw(p, pain, x, y); + q->draw(p, pi, x, y); x += q->width2(p); ++it; } else { - p->draw(pain, x, y); + p->draw(pi, x, y); x += p->width(); } } } -void MathXArray::metrics(TextMetricsInfo const & mi) const +void MathXArray::drawExternal(MathPainterInfo & pi, int x, int y, + std::vector const & v) const { - //if (clean_) - // return; + for (size_type r = 0, pos = 0; r != v.size(); ++r) { + int xx = x; + int yy = y + v[r].yo; + for ( ; pos != v[r].end; ++pos) { + MathInset const * p = data_[pos].nucleus(); + MathScriptInset const * q = 0; + if (pos + 1 != data_.size()) + q = asScript(begin() + pos + 1); + if (q) { + q->draw(p, pi, xx, yy); + xx += q->width2(p); + ++pos; + } else { + p->draw(pi, xx, yy); + xx += p->width(); + } + } + } +} - ascent_ = 0; - descent_ = 0; - width_ = 0; +void MathXArray::metricsT(TextMetricsInfo const & mi) const +{ + //if (clean_) + // return; + dim_.clear(); for (const_iterator it = begin(); it != end(); ++it) { MathInset const * p = it->nucleus(); MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it); + int ww, aa, dd; if (q) { - q->metrics(p, mi); - ascent_ = max(ascent_, q->ascent2(p)); - descent_ = max(descent_, q->descent2(p)); - width_ += q->width2(p); + q->metricsT(p, mi); + q->dimensions2(p, ww, aa, dd); ++it; } else { - p->metrics(mi); - ascent_ = max(ascent_, p->ascent()); - descent_ = max(descent_, p->descent()); - width_ += p->width(); + p->metricsT(mi); + p->dimensions(ww, aa, dd); } + dim_ += Dimension(ww, aa, dd); } } -void MathXArray::draw(TextPainter & pain, int x, int y) const +void MathXArray::drawT(TextPainter & pain, int x, int y) const { //if (drawn_ && x == xo_ && y == yo_) // return; @@ -157,11 +209,11 @@ void MathXArray::draw(TextPainter & pain, int x, int y) const MathInset const * p = it->nucleus(); MathScriptInset const * q = (it + 1 == et) ? 0 : asScript(it); if (q) { - q->draw(p, pain, x, y); + q->drawT(p, pain, x, y); x += q->width2(p); ++it; } else { - p->draw(pain, x, y); + p->drawT(pain, x, y); x += p->width(); } } @@ -222,31 +274,31 @@ int MathXArray::dist(int x, int y) const if (x < xo_) xx = xo_ - x; - else if (x > xo_ + width_) - xx = x - xo_ - width_; + else if (x > xo_ + width()) + xx = x - xo_ - width(); - if (y < yo_ - ascent_) - yy = yo_ - ascent_ - y; - else if (y > yo_ + descent_) - yy = y - yo_ - descent_; + if (y < yo_ - ascent()) + yy = yo_ - ascent() - y; + else if (y > yo_ + descent()) + yy = y - yo_ - descent(); - return xx + yy; + return xx + yy; } void MathXArray::boundingBox(int & x1, int & x2, int & y1, int & y2) { x1 = xo_; - x2 = xo_ + width_; - y1 = yo_ - ascent_; - y2 = yo_ + descent_; + x2 = xo_ + width(); + y1 = yo_ - ascent(); + y2 = yo_ + descent(); } /* void MathXArray::findPos(MathPosFinder & f) const { double x = xo_; - double y = yo_; + double y = yo_; for (const_iterator it = begin(); it < end(); ++it) { // check this position in the cell first f.visit(x, y); @@ -271,8 +323,8 @@ void MathXArray::findPos(MathPosFinder & f) const void MathXArray::center(int & x, int & y) const { - x = xo_ + width_ / 2; - y = yo_ + (descent_ - ascent_) / 2; + x = xo_ + width() / 2; + y = yo_ + (descent() - ascent()) / 2; }