From cb9eb8e8fdc4cf3d47338651b0ff2f3f2b892f38 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 29 Jun 2022 08:39:07 +0200 Subject: [PATCH] Fix QFontDatabase::hasFamily() for ambiguous families MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a font family has several instances from different foundries, we disambiguate this by adding the foundry name in brackets behind the family. But QFontDatabase::hasFamily() would only check for families().contains(familyName). So if the database contains e.g. Foo [Bar] and Foo [Baz] then a check for hasFamily("Foo") would fail. So we need to actually check for the family name instead. In doing this, we also skip the extra step of building the list and then searching it, but just go directly to the source. This removes the BLACKLISTing of Ubuntu and also introduces a QSKIP on Unix-based platforms without fontconfig, since there is no way to know which default fonts are acceptable on those platforms. Fixes: QTBUG-86967 Change-Id: Id8ad80a1671daf1c14fbad8bb8f4c51ee1c59709 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 360f1547f70fd5752a3a44892bfe5009a4357f3c) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/qfontdatabase.cpp | 14 +++++++++++++- tests/auto/gui/text/qfont/BLACKLIST | 4 ---- tests/auto/gui/text/qfont/tst_qfont.cpp | 5 +++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index a4aa8bf3564..5ffda4eb880 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -1892,7 +1892,19 @@ bool QFontDatabase::hasFamily(const QString &family) QString parsedFamily, foundry; parseFontName(family, foundry, parsedFamily); const QString familyAlias = QFontDatabasePrivate::resolveFontFamilyAlias(parsedFamily); - return families().contains(familyAlias, Qt::CaseInsensitive); + + QMutexLocker locker(fontDatabaseMutex()); + QFontDatabasePrivate *d = QFontDatabasePrivate::ensureFontDatabase(); + + for (int i = 0; i < d->count; i++) { + QtFontFamily *f = d->families[i]; + if (f->populated && f->count == 0) + continue; + if (familyAlias.compare(f->name, Qt::CaseInsensitive) == 0) + return true; + } + + return false; } diff --git a/tests/auto/gui/text/qfont/BLACKLIST b/tests/auto/gui/text/qfont/BLACKLIST index e914a7e533c..f85d8ceebb7 100644 --- a/tests/auto/gui/text/qfont/BLACKLIST +++ b/tests/auto/gui/text/qfont/BLACKLIST @@ -1,12 +1,8 @@ [defaultFamily:cursive] -ubuntu-20.04 -ubuntu-22.04 centos b2qt rhel [defaultFamily:fantasy] -ubuntu-20.04 -ubuntu-22.04 centos b2qt rhel diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index a663468d0f1..4b3d4bfddbc 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -589,6 +589,11 @@ void tst_QFont::defaultFamily() break; } } + +#if defined(Q_OS_UNIX) && defined(QT_NO_FONTCONFIG) + QSKIP("This platform does not support checking for default font acceptability"); +#endif + #ifdef Q_PROCESSOR_ARM_32 if (QTestPrivate::isRunningArmOnX86()) QEXPECT_FAIL("", "Fails on ARMv7 QEMU (QTQAINFRA-4127)", Continue);