Micro optimization to Basic/Android FDB::populateFontDatabase()
Re-use QDir to check if dir exists (QDir::exists() also returns false if path specifies a file), and use somewhat faster QDir::entryInfoList() to iterate the font files. Change-Id: Iea3a6e5548928a01db71037425adf170cb722151 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>bb10
parent
5e3e34731b
commit
839af2268e
|
|
@ -55,23 +55,24 @@ QT_BEGIN_NAMESPACE
|
|||
void QBasicFontDatabase::populateFontDatabase()
|
||||
{
|
||||
QString fontpath = fontDir();
|
||||
QDir dir(fontpath);
|
||||
|
||||
if(!QFile::exists(fontpath)) {
|
||||
if (!dir.exists()) {
|
||||
qWarning("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?",
|
||||
qPrintable(fontpath));
|
||||
return;
|
||||
}
|
||||
|
||||
QDir dir(fontpath);
|
||||
dir.setNameFilters(QStringList() << QLatin1String("*.ttf")
|
||||
<< QLatin1String("*.ttc") << QLatin1String("*.pfa")
|
||||
<< QLatin1String("*.pfb")
|
||||
<< QLatin1String("*.otf"));
|
||||
dir.refresh();
|
||||
for (int i = 0; i < int(dir.count()); ++i) {
|
||||
const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i]));
|
||||
// qDebug() << "looking at" << file;
|
||||
addTTFile(QByteArray(), file);
|
||||
QStringList nameFilters;
|
||||
nameFilters << QLatin1String("*.ttf")
|
||||
<< QLatin1String("*.ttc")
|
||||
<< QLatin1String("*.pfa")
|
||||
<< QLatin1String("*.pfb")
|
||||
<< QLatin1String("*.otf");
|
||||
|
||||
foreach (const QFileInfo &fi, dir.entryInfoList(nameFilters, QDir::Files)) {
|
||||
const QByteArray file = QFile::encodeName(fi.absoluteFilePath());
|
||||
QBasicFontDatabase::addTTFile(QByteArray(), file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,16 +45,19 @@ QString QAndroidPlatformFontDatabase::fontDir() const
|
|||
void QAndroidPlatformFontDatabase::populateFontDatabase()
|
||||
{
|
||||
QString fontpath = fontDir();
|
||||
QDir dir(fontpath);
|
||||
|
||||
if (!QFile::exists(fontpath)) {
|
||||
if (!dir.exists()) {
|
||||
qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?",
|
||||
qPrintable(fontpath));
|
||||
}
|
||||
|
||||
QDir dir(fontpath);
|
||||
QList<QFileInfo> entries = dir.entryInfoList(QStringList() << QStringLiteral("*.ttf") << QStringLiteral("*.otf"), QDir::Files);
|
||||
for (int i = 0; i < int(entries.count()); ++i) {
|
||||
const QByteArray file = QFile::encodeName(entries.at(i).absoluteFilePath());
|
||||
QStringList nameFilters;
|
||||
nameFilters << QLatin1String("*.ttf")
|
||||
<< QLatin1String("*.otf");
|
||||
|
||||
foreach (const QFileInfo &fi, dir.entryInfoList(nameFilters, QDir::Files)) {
|
||||
const QByteArray file = QFile::encodeName(fi.absoluteFilePath());
|
||||
QBasicFontDatabase::addTTFile(QByteArray(), file);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue