From 6daaf5388b35e88e85cd4c6d531514e764f1edc4 Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Thu, 7 Jun 2007 20:39:14 +0000 Subject: [PATCH] * local_bidi.patch: The bidi object in the class Text is only used in places now where a ParagraphMetrics::computeRowMetrics call comes before. And this function the Bidi object is updated. So it is a little step now to remove the Text::bidi completely and use local Bidi objects instead without more work to do. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18706 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Text.cpp | 2 ++ src/Text.h | 2 -- src/TextMetrics.cpp | 15 ++++++++------- src/rowpainter.cpp | 25 +++++++++++++++++-------- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/Text.cpp b/src/Text.cpp index 444c46ff98..517f05384a 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -1695,6 +1695,8 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl, Buffer const & buffer = *bv.buffer(); RowMetrics const m = tm.computeRowMetrics(pit, row); double x = m.x; + Bidi bidi; + bidi.computeTables(par, buffer, row); pos_type const row_pos = row.pos(); pos_type const end = row.endpos(); diff --git a/src/Text.h b/src/Text.h index 503bdee356..5ab0864d7f 100644 --- a/src/Text.h +++ b/src/Text.h @@ -378,8 +378,6 @@ public: /// int background_color_; - /// - mutable Bidi bidi; /// ParagraphList pars_; diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 6f3d6a300c..405c6ca88a 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -375,7 +375,6 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit, } } - text_->bidi.computeTables(par, buffer, row); if (is_rtl) { pos_type body_pos = par.beginOfBody(); pos_type end = row.endpos(); @@ -812,6 +811,8 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit, x -= xo; RowMetrics const r = computeRowMetrics(pit, row); Paragraph const & par = text_->getPar(pit); + Bidi bidi; + bidi.computeTables(par, buffer, row); pos_type vc = row.pos(); pos_type end = row.endpos(); @@ -839,7 +840,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit, = theFontMetrics(text_->getLabelFont(buffer, par)); while (vc < end && tmpx <= x) { - c = text_->bidi.vis2log(vc); + c = bidi.vis2log(vc); last_tmpx = tmpx; if (body_pos > 0 && c == body_pos - 1) { // FIXME UNICODE @@ -885,12 +886,12 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit, (!rtl && !left_side && vc == end && x > tmpx + 5))) c = end; else if (vc == row.pos()) { - c = text_->bidi.vis2log(vc); - if (text_->bidi.level(c) % 2 == 1) + c = bidi.vis2log(vc); + if (bidi.level(c) % 2 == 1) ++c; } else { - c = text_->bidi.vis2log(vc - 1); - bool const rtl = (text_->bidi.level(c) % 2 == 1); + c = bidi.vis2log(vc - 1); + bool const rtl = (bidi.level(c) % 2 == 1); if (left_side == rtl) { ++c; boundary = text_->isRTLBoundary(buffer, par, c); @@ -906,7 +907,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit, // specially, so cursor up/down doesn't get stuck in an air gap -- MV // Newline inset, air gap below: if (row.pos() < end && c >= end && par.isNewline(end - 1)) { - if (text_->bidi.level(end -1) % 2 == 0) + if (bidi.level(end -1) % 2 == 0) tmpx -= text_->singleWidth(buffer, par, end - 1); else tmpx += text_->singleWidth(buffer, par, end - 1); diff --git a/src/rowpainter.cpp b/src/rowpainter.cpp index 8f4d19599c..a949f4d4df 100644 --- a/src/rowpainter.cpp +++ b/src/rowpainter.cpp @@ -13,6 +13,7 @@ #include "rowpainter.h" +#include "Bidi.h" #include "Buffer.h" #include "CoordCache.h" #include "Cursor.h" @@ -113,6 +114,10 @@ private: ParagraphMetrics const & pm_; int max_width_; + /// bidi cache, static to speed up rowpaint and reduce size. + /// Only one rowpainter is used at a time anyway + static Bidi bidi_; + /// is row erased? (change tracking) bool erased_; @@ -127,6 +132,9 @@ private: }; +Bidi RowPainter::bidi_; + + RowPainter::RowPainter(PainterInfo & pi, Text const & text, pit_type pit, Row const & row, int x, int y) : bv_(*pi.base.bv), pain_(pi.pain), text_(text), @@ -135,10 +143,11 @@ RowPainter::RowPainter(PainterInfo & pi, row_(row), pit_(pit), par_(text.paragraphs()[pit]), pm_(text_metrics_.parMetrics(pit)), max_width_(bv_.workWidth()), - erased_(pi.erased_), + erased_(pi.erased_), xo_(x), yo_(y), width_(text_metrics_.width()) { RowMetrics m = text_metrics_.computeRowMetrics(pit_, row_); + bidi_.computeTables(par_, *bv_.buffer(), row_); x_ = m.x + xo_; //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl; @@ -180,7 +189,7 @@ void RowPainter::paintInset(pos_type const pos, Font const & font) pi.base.font = inset->noFontChange() ? bv_.buffer()->params().getFont() : font; - pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0); + pi.ltr_pos = (bidi_.level(pos) % 2 == 0); pi.erased_ = erased_ || par_.isDeleted(pos); #ifdef DEBUG_METRICS int const x1 = int(x_); @@ -233,7 +242,7 @@ void RowPainter::paintInset(pos_type const pos, Font const & font) void RowPainter::paintHebrewComposeChar(pos_type & vpos, Font const & font) { - pos_type pos = text_.bidi.vis2log(vpos); + pos_type pos = bidi_.vis2log(vpos); docstring str; @@ -267,7 +276,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, Font const & font) void RowPainter::paintArabicComposeChar(pos_type & vpos, Font const & font) { - pos_type pos = text_.bidi.vis2log(vpos); + pos_type pos = bidi_.vis2log(vpos); docstring str; // first char @@ -299,7 +308,7 @@ void RowPainter::paintChars(pos_type & vpos, Font const & font, bool hebrew, bool arabic) { // This method takes up 70% of time when typing - pos_type pos = text_.bidi.vis2log(vpos); + pos_type pos = bidi_.vis2log(vpos); pos_type const end = row_.endpos(); FontSpan const font_span = par_.fontSpan(pos); Change::Type const prev_change = par_.lookupChange(pos).type; @@ -320,7 +329,7 @@ void RowPainter::paintChars(pos_type & vpos, Font const & font, // collect as much similar chars as we can for (++vpos ; vpos < end ; ++vpos) { - pos = text_.bidi.vis2log(vpos); + pos = bidi_.vis2log(vpos); if (pos < font_span.first || pos > font_span.last) break; @@ -403,7 +412,7 @@ void RowPainter::paintForeignMark(double orig_x, Font const & font, int desc) void RowPainter::paintFromPos(pos_type & vpos) { - pos_type const pos = text_.bidi.vis2log(vpos); + pos_type const pos = bidi_.vis2log(vpos); Font orig_font = text_.getFont(*bv_.buffer(), par_, pos); double const orig_x = x_; @@ -747,7 +756,7 @@ void RowPainter::paintText() if (x_ > bv_.workWidth()) break; - pos_type const pos = text_.bidi.vis2log(vpos); + pos_type const pos = bidi_.vis2log(vpos); if (pos >= par_.size()) { ++vpos; -- 2.39.2