From 333040706b4ca0853ea0d56d3ab4ca54b42a15dc Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Wed, 21 Mar 2007 23:13:32 +0000 Subject: [PATCH] Cache char right bearings * src/frontends/qt4/GuiFontMetrics.C (GuiFontMetrics::rbearing): Cache char rbearing. * src/frontends/qt4/GuiFontMetrics.h: Implement rbearing_cache_ as a QHash. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17499 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiFontMetrics.C | 10 +++++++--- src/frontends/qt4/GuiFontMetrics.h | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index 9726bb0a31..0421b5a059 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -59,9 +59,13 @@ int GuiFontMetrics::lbearing(char_type c) const int GuiFontMetrics::rbearing(char_type c) const { - // Qt rbearing is from the right edge of the char's width(). - QChar sc = ucs4_to_qchar(c); - return metrics_.width(sc) - metrics_.rightBearing(sc); + if (!rbearing_cache_.contains(c)) { + // Qt rbearing is from the right edge of the char's width(). + QChar sc = ucs4_to_qchar(c); + int rb = metrics_.width(sc) - metrics_.rightBearing(sc); + rbearing_cache_.insert(c, rb); + } + return rbearing_cache_.value(c); } diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h index 59a03c3a47..fc071f2684 100644 --- a/src/frontends/qt4/GuiFontMetrics.h +++ b/src/frontends/qt4/GuiFontMetrics.h @@ -75,6 +75,9 @@ private: mutable QHash metrics_cache_; /// fill in \c metrics_cache_ at specified value. void fillMetricsCache(char_type) const; + + /// Cache of char right bearings + mutable QHash rbearing_cache_; }; } // namespace frontend