diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp index b57f514aa6..5f70c8d705 100644 --- a/src/frontends/qt4/GuiFontMetrics.cpp +++ b/src/frontends/qt4/GuiFontMetrics.cpp @@ -148,20 +148,29 @@ int GuiFontMetrics::strikeoutPos() const } -int GuiFontMetrics::lbearing(char_type c) const -{ - if (!is_utf16(c)) - // 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)); +namespace { +int const outOfLimitMetric = -10000; } -namespace { -int const outOfLimitMetric = -10000; +int GuiFontMetrics::lbearing(char_type c) const +{ + 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: + // metrics_.leftBearing(toqstr(docstring(1, c))); + value = 0; + } + + lbearing_cache_.insert(c, value); + + return value; } diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h index 6d50d35425..44897c459e 100644 --- a/src/frontends/qt4/GuiFontMetrics.h +++ b/src/frontends/qt4/GuiFontMetrics.h @@ -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 lbearing_cache_; /// Cache of char right bearings mutable QHash rbearing_cache_;