Fix QFontDatabase::hasFamily() for ambiguous families

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ø <tor.arne.vestbo@qt.io>
(cherry picked from commit 360f1547f70fd5752a3a44892bfe5009a4357f3c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2022-06-29 08:39:07 +02:00 committed by Qt Cherry-pick Bot
parent 4f4dbbac78
commit cb9eb8e8fd
3 changed files with 18 additions and 5 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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);