From 23ecaf897fad6e786d8e833695baecae148c739c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 9 Aug 2022 13:11:28 +0200 Subject: [PATCH] Don't assume that QtFontFamily::ensurePopulated() will populate The WASM platform populates a family asynchronously, so we can't assume that a family will be populated straight after calling ensurePopulated(). By adding a bool return to the function we can teach all the call sites to behave as if the font family does not exist yet if the font was not populated. The WASM platform will then invalidate the font database when the populated font's data comes in asynchronously, and then be ready for another call to ensurePopulated, which this time will succeed to populate the family. Change-Id: I4e0e6211c10e5c1123beebd77aca28ac82ba7186 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Aleksandr Reviakin --- src/gui/text/qfontdatabase.cpp | 29 +++++++++++++++++------------ src/gui/text/qfontdatabase_p.h | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 5ffda4eb880..f2d2a2401dc 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -254,13 +254,13 @@ bool QtFontFamily::matchesFamilyName(const QString &familyName) const return equalsCaseInsensitive(name, familyName) || aliases.contains(familyName, Qt::CaseInsensitive); } -void QtFontFamily::ensurePopulated() +bool QtFontFamily::ensurePopulated() { if (populated) - return; + return true; QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFamily(name); - Q_ASSERT_X(populated, Q_FUNC_INFO, qPrintable(name)); + return populated; } void QFontDatabasePrivate::clearFamilies() @@ -329,8 +329,10 @@ QtFontFamily *QFontDatabasePrivate::family(const QString &f, FamilyRequestFlags fam = families[pos]; } - if (fam && (flags & EnsurePopulated)) - fam->ensurePopulated(); + if (fam && (flags & EnsurePopulated)) { + if (!fam->ensurePopulated()) + return nullptr; + } return fam; } @@ -1047,7 +1049,8 @@ int QFontDatabasePrivate::match(int script, const QFontDef &request, const QStri if (!matchFamilyName(family_name, test.family)) continue; - test.family->ensurePopulated(); + if (!test.family->ensurePopulated()) + continue; // Check if family is supported in the script we want if (writingSystem != QFontDatabase::Any && !familySupportsWritingSystem(test.family, writingSystem)) @@ -1351,7 +1354,8 @@ QList QFontDatabase::writingSystems() for (int i = 0; i < d->count; ++i) { QtFontFamily *family = d->families[i]; - family->ensurePopulated(); + if (!family->ensurePopulated()) + continue; if (family->count == 0) continue; @@ -1423,7 +1427,8 @@ QStringList QFontDatabase::families(WritingSystem writingSystem) if (f->populated && f->count == 0) continue; if (writingSystem != Any) { - f->ensurePopulated(); + if (!f->ensurePopulated()) + continue; if (f->writingSystems[writingSystem] != QtFontFamily::Supported) continue; } @@ -1571,8 +1576,8 @@ bool QFontDatabase::isSmoothlyScalable(const QString &family, const QString &sty for (int i = 0; i < d->count; i++) { if (d->families[i]->matchesFamilyName(familyName)) { f = d->families[i]; - f->ensurePopulated(); - break; + if (f->ensurePopulated()) + break; } } } @@ -2592,8 +2597,8 @@ Q_GUI_EXPORT QStringList qt_sort_families_by_writing_system(QChar::Script script for (int x = 0; x < db->count; ++x) { if (Q_UNLIKELY(matchFamilyName(family, db->families[x]))) { testFamily = db->families[x]; - testFamily->ensurePopulated(); - break; + if (testFamily->ensurePopulated()) + break; } } diff --git a/src/gui/text/qfontdatabase_p.h b/src/gui/text/qfontdatabase_p.h index 5428e18071f..a0796d25c0a 100644 --- a/src/gui/text/qfontdatabase_p.h +++ b/src/gui/text/qfontdatabase_p.h @@ -174,7 +174,7 @@ struct Q_GUI_EXPORT QtFontFamily bool matchesFamilyName(const QString &familyName) const; QtFontFoundry *foundry(const QString &f, bool = false); - void ensurePopulated(); + bool ensurePopulated(); }; class Q_GUI_EXPORT QFontDatabasePrivate