]> git.lyx.org Git - features.git/commitdiff
Cache char right bearings
authorEnrico Forestieri <forenr@lyx.org>
Wed, 21 Mar 2007 23:13:32 +0000 (23:13 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 21 Mar 2007 23:13:32 +0000 (23:13 +0000)
* 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
src/frontends/qt4/GuiFontMetrics.h

index 9726bb0a31869318fb922224db365bf5f9854819..0421b5a059def8e0a3c06e2cf9e09f84730e9a70 100644 (file)
@@ -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);
 }
 
 
index 59a03c3a471dfb9aec8bf5029e601cd2b12caa9d..fc071f26842ce8506b1a4677c1997ce9401d84e5 100644 (file)
@@ -75,6 +75,9 @@ private:
        mutable QHash<char_type, AscendDescend> metrics_cache_;
        /// fill in \c metrics_cache_ at specified value.
        void fillMetricsCache(char_type) const;
+
+       /// Cache of char right bearings
+       mutable QHash<char_type, int> rbearing_cache_;
 };
 
 } // namespace frontend