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>bb10
parent
4b1ba7c792
commit
b852b01958
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue