diff options
author | jian liang <jianliang79@gmail.com> | 2012-02-01 23:19:46 +0800 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-02 11:10:04 +0100 |
commit | b852b019586cd53c2b49848ff2ae703fb0815308 (patch) | |
tree | 04e572a3fc0fdd0ce345fe24709b84aafa686a44 | |
parent | 4b1ba7c7928b4b326eb83e6df6f0b8fb93f2edf0 (diff) |
speed up font enumeration in windows platform
Currently, font enumeration is very slow in windows platform, it will take
several seconds to enumerate all fonts for the first time. This patch
cache the font information queried from font registry, it can
significantly speed up font enumeration.
Change-Id: Ic783877b7f3db3facf24965b0c5d669b22d40c61
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
-rw-r--r-- | src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp index b32b8aa59d..e96305e4b7 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp @@ -172,17 +172,40 @@ static bool addFontToDatabase(QString familyName, const QString &scriptName, const QSettings fontRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", QSettings::NativeFormat); + struct FontKey + { + FontKey() {} + FontKey(const QString &k) : key(k) {} + + QString key; + QStringList fonts; + }; + static QVector<FontKey> allFonts; + if (allFonts.isEmpty()) { + const QStringList allKeys = fontRegistry.allKeys(); + allFonts.reserve(allKeys.size()); + const QString trueType = QStringLiteral("(TrueType)"); + foreach (const QString &key, allKeys) { + FontKey fontKey(key); + + QString realKey = key; + realKey = realKey.remove(trueType); + const QStringList fonts = realKey.trimmed().split(QLatin1Char('&')); + foreach (const QString &font, fonts) + fontKey.fonts.push_back(font.trimmed()); + + allFonts.push_back(fontKey); + } + } + QByteArray value; int index = 0; - foreach (const QString &key, fontRegistry.allKeys()) { - QString realKey = key; - realKey = realKey.replace("(TrueType)", ""); - realKey = realKey.trimmed(); - QStringList fonts = realKey.split('&'); - for (int i = 0; i < fonts.length(); ++i) { - const QString font = fonts[i].trimmed(); + for (int k = 0; k < allFonts.size(); ++k) { + const FontKey &fontKey = allFonts.at(k); + for (int i = 0; i < fontKey.fonts.length(); ++i) { + const QString font = fontKey.fonts[i]; if (font == faceName || (faceName != fullName && fullName == font)) { - value = fontRegistry.value(key).toByteArray(); + value = fontRegistry.value(fontKey.key).toByteArray(); index = i; break; } |