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
This commit is contained in:
Enrico Forestieri 2007-03-21 23:13:32 +00:00
parent a016215367
commit 333040706b
2 changed files with 10 additions and 3 deletions

View 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);
}

View 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