From a127d540d3dfc4382f602092274a34bfbd13064d Mon Sep 17 00:00:00 2001 From: Asger Ottar Alstrup Date: Sun, 22 Oct 2006 18:49:18 +0000 Subject: [PATCH] - LyX is dead slow, so the least we can do is use anti-alised text - Various micro-optimisations - Revert Abdel's repaint instead of update for QPainter - Get rid of unused methods in GuiWorkArea git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15491 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/changes.C | 3 +++ src/frontends/qt4/GuiFontMetrics.C | 7 +++--- src/frontends/qt4/GuiWorkArea.C | 20 +-------------- src/frontends/qt4/GuiWorkArea.h | 6 ----- src/frontends/qt4/QLPainter.C | 5 +++- src/rowpainter.C | 40 +++++++++++------------------- 6 files changed, 27 insertions(+), 54 deletions(-) diff --git a/src/changes.C b/src/changes.C index 1a7f2cffb7..0a708c64bb 100644 --- a/src/changes.C +++ b/src/changes.C @@ -210,6 +210,9 @@ void Changes::insert(Change const & change, lyx::pos_type pos) Change const Changes::lookup(pos_type const pos) const { + if (table_.empty()) { + return Change(Change::UNCHANGED); + } ChangeTable::const_iterator it = table_.begin(); ChangeTable::const_iterator const end = table_.end(); diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index f2aca33e49..544ee5348f 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -115,15 +115,16 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const int GuiFontMetrics::width(char_type const * s, size_t ls) const { + if (ls == 1 && !smallcaps_shape_) { + QChar c = ucs4_to_qchar(s[0]); + return width(c.unicode()); + } QString ucs2; ucs4_to_qstring(s, ls, ucs2); if (smallcaps_shape_) return smallcapsWidth(ucs2); - if (ls == 1) - return width(ucs2[0].unicode()); - int w = 0; for (unsigned int i = 0; i < ls; ++i) w += width(ucs2[i].unicode()); diff --git a/src/frontends/qt4/GuiWorkArea.C b/src/frontends/qt4/GuiWorkArea.C index dfb154f61b..2f04f8a6f9 100644 --- a/src/frontends/qt4/GuiWorkArea.C +++ b/src/frontends/qt4/GuiWorkArea.C @@ -420,7 +420,7 @@ void GuiWorkArea::resizeEvent(QResizeEvent *) void GuiWorkArea::update(int x, int y, int w, int h) { - viewport()->repaint(x, y, w, h); + viewport()->update(x, y, w, h); } @@ -458,24 +458,6 @@ void GuiWorkArea::paintEvent(QPaintEvent * e) } -QPixmap GuiWorkArea::copyScreen(int x, int y, int w, int h) const -{ - lyxerr << "copyScreen begin: x: " << x << " y: " << y << endl; - return paint_device_.copy(x, y, w, h); - lyxerr << "copyScreen end " << endl; -} - - -void GuiWorkArea::drawScreen(int x, int y, const QPixmap & pixmap) -{ - lyxerr << "drawScreen begin: x: " << x << " y: " << y << endl; - QPainter q(&paint_device_); - q.drawPixmap(x, y, pixmap); - update(x, y, pixmap.width(), pixmap.height()); - lyxerr << "drawScreen end" << endl; -} - - void GuiWorkArea::expose(int x, int y, int w, int h) { update(x, y, w, h); diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index 84aa093224..c8aaac8b8e 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -119,12 +119,6 @@ public: /// update the passed area. void update(int x, int y, int w, int h); - /// return a screen copy of the defined area. - QPixmap copyScreen(int x, int y, int w, int h) const; - - /// Draw a pixmap onto the backing pixmap. - void drawScreen(int x, int y, const QPixmap & pixmap); - /// copies specified area of pixmap to screen virtual void expose(int x, int y, int exp_width, int exp_height); diff --git a/src/frontends/qt4/QLPainter.C b/src/frontends/qt4/QLPainter.C index 1742085d23..db3f13bd4f 100644 --- a/src/frontends/qt4/QLPainter.C +++ b/src/frontends/qt4/QLPainter.C @@ -57,6 +57,7 @@ void QLPainter::start() { lyxerr << "QLPainter::start()" << endl; qp_.reset(new QPainter(qwa_->paintDevice())); + qp_->setRenderHint(QPainter::TextAntialiasing); // new QPainter has default QPen: current_color_ = LColor::black; current_ls_ = line_solid; @@ -248,7 +249,9 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls, if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { setQPainterPen(f.realColor()); - qp_->setFont(fi.font); + if (qp_->font() != fi.font) { + qp_->setFont(fi.font); + } // We need to draw the text as LTR as we use our own bidi code. qp_->setLayoutDirection(Qt::LeftToRight); qp_->drawText(x, y, str); diff --git a/src/rowpainter.C b/src/rowpainter.C index 7be384bfdf..40144cc407 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -79,7 +79,7 @@ private: void paintForeignMark(double orig_x, LyXFont const & font, int desc = 0); void paintHebrewComposeChar(pos_type & vpos, LyXFont const & font); void paintArabicComposeChar(pos_type & vpos, LyXFont const & font); - void paintChars(pos_type & vpos, LyXFont font, + void paintChars(pos_type & vpos, LyXFont const & font, bool hebrew, bool arabic); int paintAppendixStart(int y); void paintFromPos(pos_type & vpos); @@ -252,24 +252,20 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font) pain_.text(int(x_) + dx, yo_, str, font); } - -void RowPainter::paintChars(pos_type & vpos, LyXFont font, +void RowPainter::paintChars(pos_type & vpos, LyXFont const & font, bool hebrew, bool arabic) { + // This method takes up 70% of time when typing pos_type pos = text_.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; // first character -#if 0 - string str; - str += par_.getChar(pos); -#else std::vector str; str.reserve(100); str.push_back(par_.getChar(pos)); -#endif + if (arabic) { char_type c = str[0]; str[0] = par_.transformChar(c, pos); @@ -298,26 +294,20 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font, if (arabic) c = par_.transformChar(c, pos); -#if 0 - str += c; -#else str.push_back(c); -#endif } - if (prev_change == Change::DELETED) - font.setColor(LColor::strikeout); - else if (prev_change == Change::INSERTED) - font.setColor(LColor::newtext); - - // Draw text and set the new x position - //lyxerr << "paint row: yo_ " << yo_ << "\n"; -#if 0 - int width = pain_.text(int(x_), yo_, str, font); -#else - int width = pain_.text(int(x_), yo_, &str[0], str.size(), font); -#endif - x_ += width; + if (prev_change != Change::UNCHANGED) { + LyXFont copy(font); + if (prev_change == Change::DELETED) { + copy.setColor(LColor::strikeout); + } else if (prev_change == Change::INSERTED) { + copy.setColor(LColor::newtext); + } + x_ += pain_.text(int(x_), yo_, &str[0], str.size(), copy); + } else { + x_ += pain_.text(int(x_), yo_, &str[0], str.size(), font); + } } -- 2.39.2