From 741a4987b8e2a11f515c463152037ae77cd1aea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 15 Mar 2022 17:29:18 +0100 Subject: [PATCH] CoreText: Reuse descriptorForFamily helper function in populateFamily Pick-to: 6.2 6.3 Change-Id: I2c1098309fc994fb7a131564679299a2e850870a Reviewed-by: Timur Pocheptsov --- .../text/coretext/qcoretextfontdatabase.mm | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/gui/text/coretext/qcoretextfontdatabase.mm b/src/gui/text/coretext/qcoretextfontdatabase.mm index e67a01fca9..a49f85e90c 100644 --- a/src/gui/text/coretext/qcoretextfontdatabase.mm +++ b/src/gui/text/coretext/qcoretextfontdatabase.mm @@ -188,14 +188,25 @@ bool QCoreTextFontDatabase::populateFamilyAliases(const QString &missingFamily) #endif } +CTFontDescriptorRef descriptorForFamily(const QString &familyName) +{ + return CTFontDescriptorCreateWithAttributes(CFDictionaryRef(@{ + (id)kCTFontFamilyNameAttribute: familyName.toNSString() + })); +} + +CTFontDescriptorRef descriptorForFamily(const char *familyName) +{ + return descriptorForFamily(QString::fromLatin1(familyName)); +} + void QCoreTextFontDatabase::populateFamily(const QString &familyName) { - QCFType attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, QCFString(familyName)); - QCFType nameOnlyDescriptor = CTFontDescriptorCreateWithAttributes(attributes); - - // A single family might match several different fonts with different styles eg. - QCFType matchingFonts = (CFArrayRef) CTFontDescriptorCreateMatchingFontDescriptors(nameOnlyDescriptor, 0); + // A single family might match several different fonts with different styles. + // We need to add them all so that the font database has the full picture, + // as once a family has been populated we will not populate it again. + QCFType familyDescriptor = descriptorForFamily(familyName); + QCFType matchingFonts = CTFontDescriptorCreateMatchingFontDescriptors(familyDescriptor, nullptr); if (!matchingFonts) { qCWarning(lcQpaFonts) << "QCoreTextFontDatabase: Found no matching fonts for family" << familyName; return; @@ -429,18 +440,6 @@ template class QCoreTextFontDatabaseEngineFactory; template class QCoreTextFontDatabaseEngineFactory; #endif -CTFontDescriptorRef descriptorForFamily(const QString &familyName) -{ - return CTFontDescriptorCreateWithAttributes(CFDictionaryRef(@{ - (id)kCTFontFamilyNameAttribute: familyName.toNSString() - })); -} - -CTFontDescriptorRef descriptorForFamily(const char *familyName) -{ - return descriptorForFamily(QString::fromLatin1(familyName)); -} - CFArrayRef fallbacksForDescriptor(CTFontDescriptorRef descriptor) { QCFType font = CTFontCreateWithFontDescriptor(descriptor, 0.0, nullptr);