* 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
This commit is contained in:
Stefan Schimanski 2007-06-07 20:39:14 +00:00
parent 41e194bf88
commit 6daaf5388b
4 changed files with 27 additions and 17 deletions

View File

@ -1695,6 +1695,8 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
Buffer const & buffer = *bv.buffer(); Buffer const & buffer = *bv.buffer();
RowMetrics const m = tm.computeRowMetrics(pit, row); RowMetrics const m = tm.computeRowMetrics(pit, row);
double x = m.x; double x = m.x;
Bidi bidi;
bidi.computeTables(par, buffer, row);
pos_type const row_pos = row.pos(); pos_type const row_pos = row.pos();
pos_type const end = row.endpos(); pos_type const end = row.endpos();

View File

@ -378,8 +378,6 @@ public:
/// ///
int background_color_; int background_color_;
///
mutable Bidi bidi;
/// ///
ParagraphList pars_; ParagraphList pars_;

View File

@ -375,7 +375,6 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
} }
} }
text_->bidi.computeTables(par, buffer, row);
if (is_rtl) { if (is_rtl) {
pos_type body_pos = par.beginOfBody(); pos_type body_pos = par.beginOfBody();
pos_type end = row.endpos(); pos_type end = row.endpos();
@ -812,6 +811,8 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
x -= xo; x -= xo;
RowMetrics const r = computeRowMetrics(pit, row); RowMetrics const r = computeRowMetrics(pit, row);
Paragraph const & par = text_->getPar(pit); Paragraph const & par = text_->getPar(pit);
Bidi bidi;
bidi.computeTables(par, buffer, row);
pos_type vc = row.pos(); pos_type vc = row.pos();
pos_type end = row.endpos(); pos_type end = row.endpos();
@ -839,7 +840,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
= theFontMetrics(text_->getLabelFont(buffer, par)); = theFontMetrics(text_->getLabelFont(buffer, par));
while (vc < end && tmpx <= x) { while (vc < end && tmpx <= x) {
c = text_->bidi.vis2log(vc); c = bidi.vis2log(vc);
last_tmpx = tmpx; last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) { if (body_pos > 0 && c == body_pos - 1) {
// FIXME UNICODE // FIXME UNICODE
@ -885,12 +886,12 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
(!rtl && !left_side && vc == end && x > tmpx + 5))) (!rtl && !left_side && vc == end && x > tmpx + 5)))
c = end; c = end;
else if (vc == row.pos()) { else if (vc == row.pos()) {
c = text_->bidi.vis2log(vc); c = bidi.vis2log(vc);
if (text_->bidi.level(c) % 2 == 1) if (bidi.level(c) % 2 == 1)
++c; ++c;
} else { } else {
c = text_->bidi.vis2log(vc - 1); c = bidi.vis2log(vc - 1);
bool const rtl = (text_->bidi.level(c) % 2 == 1); bool const rtl = (bidi.level(c) % 2 == 1);
if (left_side == rtl) { if (left_side == rtl) {
++c; ++c;
boundary = text_->isRTLBoundary(buffer, par, 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 // specially, so cursor up/down doesn't get stuck in an air gap -- MV
// Newline inset, air gap below: // Newline inset, air gap below:
if (row.pos() < end && c >= end && par.isNewline(end - 1)) { 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); tmpx -= text_->singleWidth(buffer, par, end - 1);
else else
tmpx += text_->singleWidth(buffer, par, end - 1); tmpx += text_->singleWidth(buffer, par, end - 1);

View File

@ -13,6 +13,7 @@
#include "rowpainter.h" #include "rowpainter.h"
#include "Bidi.h"
#include "Buffer.h" #include "Buffer.h"
#include "CoordCache.h" #include "CoordCache.h"
#include "Cursor.h" #include "Cursor.h"
@ -113,6 +114,10 @@ private:
ParagraphMetrics const & pm_; ParagraphMetrics const & pm_;
int max_width_; 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) /// is row erased? (change tracking)
bool erased_; bool erased_;
@ -127,6 +132,9 @@ private:
}; };
Bidi RowPainter::bidi_;
RowPainter::RowPainter(PainterInfo & pi, RowPainter::RowPainter(PainterInfo & pi,
Text const & text, pit_type pit, Row const & row, int x, int y) Text const & text, pit_type pit, Row const & row, int x, int y)
: bv_(*pi.base.bv), pain_(pi.pain), text_(text), : bv_(*pi.base.bv), pain_(pi.pain), text_(text),
@ -139,6 +147,7 @@ RowPainter::RowPainter(PainterInfo & pi,
xo_(x), yo_(y), width_(text_metrics_.width()) xo_(x), yo_(y), width_(text_metrics_.width())
{ {
RowMetrics m = text_metrics_.computeRowMetrics(pit_, row_); RowMetrics m = text_metrics_.computeRowMetrics(pit_, row_);
bidi_.computeTables(par_, *bv_.buffer(), row_);
x_ = m.x + xo_; x_ = m.x + xo_;
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl; //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() ? pi.base.font = inset->noFontChange() ?
bv_.buffer()->params().getFont() : bv_.buffer()->params().getFont() :
font; font;
pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0); pi.ltr_pos = (bidi_.level(pos) % 2 == 0);
pi.erased_ = erased_ || par_.isDeleted(pos); pi.erased_ = erased_ || par_.isDeleted(pos);
#ifdef DEBUG_METRICS #ifdef DEBUG_METRICS
int const x1 = int(x_); 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) void RowPainter::paintHebrewComposeChar(pos_type & vpos, Font const & font)
{ {
pos_type pos = text_.bidi.vis2log(vpos); pos_type pos = bidi_.vis2log(vpos);
docstring str; docstring str;
@ -267,7 +276,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, Font const & font)
void RowPainter::paintArabicComposeChar(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; docstring str;
// first char // first char
@ -299,7 +308,7 @@ void RowPainter::paintChars(pos_type & vpos, Font const & font,
bool hebrew, bool arabic) bool hebrew, bool arabic)
{ {
// This method takes up 70% of time when typing // 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(); pos_type const end = row_.endpos();
FontSpan const font_span = par_.fontSpan(pos); FontSpan const font_span = par_.fontSpan(pos);
Change::Type const prev_change = par_.lookupChange(pos).type; 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 // collect as much similar chars as we can
for (++vpos ; vpos < end ; ++vpos) { for (++vpos ; vpos < end ; ++vpos) {
pos = text_.bidi.vis2log(vpos); pos = bidi_.vis2log(vpos);
if (pos < font_span.first || pos > font_span.last) if (pos < font_span.first || pos > font_span.last)
break; break;
@ -403,7 +412,7 @@ void RowPainter::paintForeignMark(double orig_x, Font const & font, int desc)
void RowPainter::paintFromPos(pos_type & vpos) 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); Font orig_font = text_.getFont(*bv_.buffer(), par_, pos);
double const orig_x = x_; double const orig_x = x_;
@ -747,7 +756,7 @@ void RowPainter::paintText()
if (x_ > bv_.workWidth()) if (x_ > bv_.workWidth())
break; break;
pos_type const pos = text_.bidi.vis2log(vpos); pos_type const pos = bidi_.vis2log(vpos);
if (pos >= par_.size()) { if (pos >= par_.size()) {
++vpos; ++vpos;