]> git.lyx.org Git - features.git/commitdiff
Cache the value of GuiFontMetrics::lbearing().
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 20 Mar 2019 09:56:16 +0000 (10:56 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:18 +0000 (15:48 +0200)
This seems to be necessary on windows, where math editing can get very
slow. Note that other methods like rbearing already use a cache.

In the future all these caches for single characters shall be unified.

src/frontends/qt4/GuiFontMetrics.cpp
src/frontends/qt4/GuiFontMetrics.h

index b57f514aa6bb7858b5e5b9918c7608ca6b1cc9e7..5f70c8d705f3b4ed25603f6ddad8067d4c0bc430 100644 (file)
@@ -148,20 +148,29 @@ int GuiFontMetrics::strikeoutPos() const
 }
 
 
+namespace {
+int const outOfLimitMetric = -10000;
+}
+
+
 int GuiFontMetrics::lbearing(char_type c) const
 {
-       if (!is_utf16(c))
+       int value = lbearing_cache_.value(c, outOfLimitMetric);
+       if (value != outOfLimitMetric)
+               return value;
+
+       if (is_utf16(c))
+               value = metrics_.leftBearing(ucs4_to_qchar(c));
+       else {
                // FIXME: QFontMetrics::leftBearing does not support the
                //        full unicode range. Once it does, we could use:
-               //return metrics_.leftBearing(toqstr(docstring(1, c)));
-               return 0;
-
-       return metrics_.leftBearing(ucs4_to_qchar(c));
-}
+               // metrics_.leftBearing(toqstr(docstring(1, c)));
+               value = 0;
+       }
 
+       lbearing_cache_.insert(c, value);
 
-namespace {
-int const outOfLimitMetric = -10000;
+       return value;
 }
 
 
index 6d50d35425198ea3d9cf1c073eff22f31b755b9b..44897c459e4b1b042a52440dcbc78a028371cbed 100644 (file)
@@ -103,6 +103,8 @@ private:
        /// fill in \c metrics_cache_ at specified value.
        AscendDescend const fillMetricsCache(char_type) const;
 
+       /// Cache of char leftt bearings
+       mutable QHash<char_type, int> lbearing_cache_;
        /// Cache of char right bearings
        mutable QHash<char_type, int> rbearing_cache_;