diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2014-12-19 06:59:31 +0400 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2014-12-23 14:57:37 +0100 |
commit | a0742ad6ce8bb85b128246b8c2256e1b24ece4e8 (patch) | |
tree | a4d7c22c3297da97852d85f11fbc7b7be9671876 /src/gui/text/qfontdatabase.cpp | |
parent | a45da5d207431b77a9bfacbc1da1a50712c5d031 (diff) |
Re-use cached font engines when request only differs in script
When looking for engine of non-Common script and lookup in
the font cache failed, first check if we have already loaded that engine
for the same request but different script.
In general, this gives an arbitrary font engine a chance to be re-used
multiple times when request only differs in script, which saves a LOT
of memory (~10MB on my win7, after scrolling the QFontComboBox'es list).
Change-Id: I9c752ce65c27142237a0ed74b33742b6a8d90a24
Reviewed-by: Pierre Rossi <pierre.rossi@theqtcompany.com>
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.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index e40d134a44..42148f95c5 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -816,7 +816,7 @@ static inline void load(const QString & = QString(), int = -1) static QFontEngine *loadSingleEngine(int script, const QFontDef &request, - QtFontFoundry *foundry, + QtFontFamily *family, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size) { Q_UNUSED(foundry); @@ -835,6 +835,24 @@ QFontEngine *loadSingleEngine(int script, QFontCache::Key key(def,script); QFontEngine *engine = QFontCache::instance()->findEngine(key); if (!engine) { + if (script != QChar::Script_Common) { + // fast path: check if engine was loaded for another script + key.script = QChar::Script_Common; + engine = QFontCache::instance()->findEngine(key); + key.script = script; + if (engine) { + Q_ASSERT(engine->type() != QFontEngine::Multi); + // Also check for OpenType tables when using complex scripts + if (Q_UNLIKELY(!engine->supportsScript(QChar::Script(script)))) { + qWarning(" OpenType support missing for script %d", script); + return 0; + } + + QFontCache::instance()->insertEngine(key, engine); + return engine; + } + } + // If the font data's native stretch matches the requested stretch we need to set stretch to 100 // to avoid the fontengine synthesizing stretch. If they didn't match exactly we need to calculate // the new stretch factor. This only done if not matched by styleName. @@ -854,6 +872,13 @@ QFontEngine *loadSingleEngine(int script, } QFontCache::instance()->insertEngine(key, engine); + + if (!engine->symbol && script != QChar::Script_Common && (family->writingSystems[QFontDatabase::Latin] & QtFontFamily::Supported) != 0) { + // cache engine for Common script as well + key.script = QChar::Script_Common; + if (!QFontCache::instance()->findEngine(key)) + QFontCache::instance()->insertEngine(key, engine); + } } } return engine; @@ -864,7 +889,7 @@ QFontEngine *loadEngine(int script, const QFontDef &request, QtFontFamily *family, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size) { - QFontEngine *engine = loadSingleEngine(script, request, foundry, style, size); + QFontEngine *engine = loadSingleEngine(script, request, family, foundry, style, size); Q_ASSERT(!engine || engine->type() != QFontEngine::Multi); if (engine && !(request.styleStrategy & QFont::NoFontMerging) && !engine->symbol) { // make sure that the db has all fallback families |