diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-08-09 13:11:28 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-08-19 14:04:28 +0200 |
commit | 23ecaf897fad6e786d8e833695baecae148c739c (patch) | |
tree | b63afc97574c73ec0e581af9d82ea44fbefe465a | |
parent | a8b49216d0a397e19cbc3095525f4bac69b7fe9e (diff) |
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 <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 29 | ||||
-rw-r--r-- | 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 5ffda4eb88..f2d2a2401d 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::WritingSystem> 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 5428e18071..a0796d25c0 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 |