summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontdatabase.cpp
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2016-01-27 04:35:05 +0400
committerKonstantin Ritt <ritt.ks@gmail.com>2016-01-29 11:24:49 +0000
commit3e5719ae7b8f4ff2b1aff6d9134386bcc64e5b4b (patch)
tree94b0f9ef7407ce5f17bbdc7f8b6a23b2d7e4a4c3 /src/gui/text/qfontdatabase.cpp
parent270cc073b7e0fbc34d635aa70788e70d66433334 (diff)
QFont: Fix possible cache misses due to misprepared cache key
Parse the requested family before we're looking/saving into the cache, thus hitting the cached EngineData for: * quoted family names (eg. QFont("'Arial'")) * non-simplified family names (eg. QFont(" Arial ")) * substituted family names (\sa QFont::insertSubstitution()) * explicit fallback list, where possible (eg. QFont("Tahoma, Arial")) This also improves the cache hitting for the font engines in some cases. Change-Id: I18cdc3e8d669cccec961f84e9b27329402e2b7ed Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/gui/text/qfontdatabase.cpp')
-rw-r--r--src/gui/text/qfontdatabase.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 333f1d2bb0..d606681e52 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -2732,9 +2732,16 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
if (req.stretch == 0)
req.stretch = 100;
+ // respect the fallback families that might be passed through the request
+ const QStringList fallBackFamilies = familyList(req);
+
if (!d->engineData) {
QFontCache *fontCache = QFontCache::instance();
// look for the requested font in the engine data cache
+ // note: fallBackFamilies are not respected in the EngineData cache key;
+ // join them with the primary selection family to avoid cache misses
+ req.family = fallBackFamilies.join(QLatin1Char(','));
+
d->engineData = fontCache->findEngineData(req);
if (!d->engineData) {
// create a new one
@@ -2748,25 +2755,18 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
if (d->engineData->engines[script])
return;
- // Until we specifically asked not to, try looking for Multi font engine
- // first, the last '1' indicates that we want Multi font engine instead
- // of single ones
- bool multi = !(req.styleStrategy & QFont::NoFontMerging);
- QFontCache::Key key(req, script, multi ? 1 : 0);
+ QFontEngine *fe = Q_NULLPTR;
- QFontEngine *fe = QFontCache::instance()->findEngine(key);
+ req.fallBackFamilies = fallBackFamilies;
+ if (!req.fallBackFamilies.isEmpty())
+ req.family = req.fallBackFamilies.takeFirst();
// list of families to try
QStringList family_list;
if (!req.family.isEmpty()) {
- QStringList familiesForRequest = familyList(req);
-
// Add primary selection
- family_list << familiesForRequest.takeFirst();
-
- // Fallbacks requested in font request
- req.fallBackFamilies = familiesForRequest;
+ family_list << req.family;
// add the default family
QString defaultFamily = QGuiApplication::font().family();