From 95ea1b1aa8d71889bce87c76bb1a996c0f2b58f4 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Fri, 22 Apr 2016 17:22:53 -0700 Subject: Remove all code paths related to unsupported Apple platforms. Now that the minimum deployment target (and thus SDK) is 10.9 for OS X and 7.0 for iOS, all code paths affecting platform versions lower than the aforementioned are removed. Change-Id: Id985c7259c4ac069319d88f2c29c9559ae9e8641 Reviewed-by: Jake Petroules --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 249 +++++++-------------- 1 file changed, 79 insertions(+), 170 deletions(-) (limited to 'src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm') diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 493ffc7a46..d81a68d6e5 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -517,46 +517,37 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo static QHash fallbackLists; if (!family.isEmpty()) { -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_8, __IPHONE_6_0) - // CTFontCopyDefaultCascadeListForLanguages is available in the SDK - #if QT_MAC_DEPLOYMENT_TARGET_BELOW(__MAC_10_8, __IPHONE_6_0) - // But we have to feature check at runtime - if (&CTFontCopyDefaultCascadeListForLanguages) - #endif - { - QCFType attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, QCFString(family)); - if (QCFType fontDescriptor = CTFontDescriptorCreateWithAttributes(attributes)) { - if (QCFType font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0)) { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"]; - - QCFType cascadeList = (CFArrayRef) CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef) languages); - if (cascadeList) { - QStringList fallbackList; - const int numCascades = CFArrayGetCount(cascadeList); - for (int i = 0; i < numCascades; ++i) { - CTFontDescriptorRef fontFallback = (CTFontDescriptorRef) CFArrayGetValueAtIndex(cascadeList, i); - QCFString fallbackFamilyName = (CFStringRef) CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute); - fallbackList.append(QCFString::toQString(fallbackFamilyName)); - } + QCFType attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, QCFString(family)); + if (QCFType fontDescriptor = CTFontDescriptorCreateWithAttributes(attributes)) { + if (QCFType font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0)) { + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"]; + + QCFType cascadeList = (CFArrayRef) CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef) languages); + if (cascadeList) { + QStringList fallbackList; + const int numCascades = CFArrayGetCount(cascadeList); + for (int i = 0; i < numCascades; ++i) { + CTFontDescriptorRef fontFallback = (CTFontDescriptorRef) CFArrayGetValueAtIndex(cascadeList, i); + QCFString fallbackFamilyName = (CFStringRef) CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute); + fallbackList.append(QCFString::toQString(fallbackFamilyName)); + } #if defined(Q_OS_OSX) - // Since we are only returning a list of default fonts for the current language, we do not - // cover all unicode completely. This was especially an issue for some of the common script - // symbols such as mathematical symbols, currency or geometric shapes. To minimize the risk - // of missing glyphs, we add Arial Unicode MS as a final fail safe, since this covers most - // of Unicode 2.1. - if (!fallbackList.contains(QStringLiteral("Arial Unicode MS"))) - fallbackList.append(QStringLiteral("Arial Unicode MS")); + // Since we are only returning a list of default fonts for the current language, we do not + // cover all unicode completely. This was especially an issue for some of the common script + // symbols such as mathematical symbols, currency or geometric shapes. To minimize the risk + // of missing glyphs, we add Arial Unicode MS as a final fail safe, since this covers most + // of Unicode 2.1. + if (!fallbackList.contains(QStringLiteral("Arial Unicode MS"))) + fallbackList.append(QStringLiteral("Arial Unicode MS")); #endif - return fallbackList; - } + return fallbackList; } } } -#endif } // We were not able to find a fallback for the specific family, @@ -620,7 +611,6 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo return fallbackLists[styleLookupKey.arg(styleHint)]; } -#if HAVE_CORETEXT static CFArrayRef createDescriptorArrayForFont(CTFontRef font, const QString &fileName = QString()) { CFMutableArrayRef array = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); @@ -653,104 +643,41 @@ static CFArrayRef createDescriptorArrayForFont(CTFontRef font, const QString &fi CFArrayAppendValue(array, descriptor); return array; } -#endif QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) { QCFType fonts; QStringList families; -#if HAVE_CORETEXT - if (&CTFontManagerRegisterGraphicsFont) { - CFErrorRef error = 0; - if (!fontData.isEmpty()) { - QByteArray* fontDataCopy = new QByteArray(fontData); - QCFType dataProvider = CGDataProviderCreateWithData(fontDataCopy, - fontDataCopy->constData(), fontDataCopy->size(), releaseFontData); - QCFType cgFont = CGFontCreateWithDataProvider(dataProvider); - if (cgFont) { - if (CTFontManagerRegisterGraphicsFont(cgFont, &error)) { - QCFType font = CTFontCreateWithGraphicsFont(cgFont, 0.0, NULL, NULL); - fonts = createDescriptorArrayForFont(font + CFErrorRef error = 0; + if (!fontData.isEmpty()) { + QByteArray* fontDataCopy = new QByteArray(fontData); + QCFType dataProvider = CGDataProviderCreateWithData(fontDataCopy, + fontDataCopy->constData(), fontDataCopy->size(), releaseFontData); + QCFType cgFont = CGFontCreateWithDataProvider(dataProvider); + if (cgFont) { + if (CTFontManagerRegisterGraphicsFont(cgFont, &error)) { + QCFType font = CTFontCreateWithGraphicsFont(cgFont, 0.0, NULL, NULL); + fonts = createDescriptorArrayForFont(font #ifndef QT_NO_FREETYPE - , m_useFreeType ? fileName : QString() + , m_useFreeType ? fileName : QString() #endif - ); - m_applicationFonts.append(QVariant::fromValue(QCFType::constructFromGet(cgFont))); - } - } - } else { - QCFType fontURL = CFURLCreateWithFileSystemPath(NULL, QCFString(fileName), kCFURLPOSIXPathStyle, false); - if (CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error)) { -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_6, __IPHONE_7_0) - if (&CTFontManagerCreateFontDescriptorsFromURL) - fonts = CTFontManagerCreateFontDescriptorsFromURL(fontURL); - else -#endif - { - // We're limited to a single font per file, unless we dive into the font tables - QCFType attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, - &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - CFDictionaryAddValue(attributes, kCTFontURLAttribute, fontURL); - QCFType descriptor = CTFontDescriptorCreateWithAttributes(attributes); - QCFType font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL); - fonts = createDescriptorArrayForFont(font); - } - - m_applicationFonts.append(QVariant::fromValue(QCFType::constructFromGet(fontURL))); + ); + m_applicationFonts.append(QVariant::fromValue(QCFType::constructFromGet(cgFont))); } } - - if (error) { - NSLog(@"Unable to register font: %@", error); - CFRelease(error); + } else { + QCFType fontURL = CFURLCreateWithFileSystemPath(NULL, QCFString(fileName), kCFURLPOSIXPathStyle, false); + if (CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error)) { + fonts = CTFontManagerCreateFontDescriptorsFromURL(fontURL); + m_applicationFonts.append(QVariant::fromValue(QCFType::constructFromGet(fontURL))); } } -#endif -#if HAVE_CORETEXT && HAVE_ATS - else -#endif -#if HAVE_ATS - { - ATSFontContainerRef fontContainer; - OSStatus e; - - if (!fontData.isEmpty()) { - e = ATSFontActivateFromMemory((void *) fontData.constData(), fontData.size(), - kATSFontContextLocal, kATSFontFormatUnspecified, NULL, - kATSOptionFlagsDefault, &fontContainer); - } else { - FSRef ref; - if (FSPathMakeRef(reinterpret_cast(fileName.toUtf8().constData()), - &ref, 0) != noErr) - return QStringList(); - e = ATSFontActivateFromFileReference(&ref, kATSFontContextLocal, kATSFontFormatUnspecified, 0, - kATSOptionFlagsDefault, &fontContainer); - } - - if (e == noErr) { - ItemCount fontCount = 0; - e = ATSFontFindFromContainer(fontContainer, kATSOptionFlagsDefault, 0, 0, &fontCount); - if (e != noErr) - return QStringList(); - - QVarLengthArray containedFonts(fontCount); - e = ATSFontFindFromContainer(fontContainer, kATSOptionFlagsDefault, fontCount, containedFonts.data(), &fontCount); - if (e != noErr) - return QStringList(); - - CFMutableArrayRef fontsArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); - for (int i = 0; i < containedFonts.size(); ++i) { - QCFType font = CTFontCreateWithPlatformFont(containedFonts[i], 12.0, NULL, NULL); - CFArrayAppendValue(fontsArray, QCFType(CTFontCopyFontDescriptor(font))); - } - - fonts = fontsArray; - m_applicationFonts.append(QVariant::fromValue(fontContainer)); - } + if (error) { + NSLog(@"Unable to register font: %@", error); + CFRelease(error); } -#endif if (fonts) { const int numFonts = CFArrayGetCount(fonts); @@ -848,38 +775,36 @@ static CTFontUIFontType fontTypeFromTheme(QPlatformTheme::Font f) static CTFontDescriptorRef fontDescriptorFromTheme(QPlatformTheme::Font f) { #if defined(QT_PLATFORM_UIKIT) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_7_0) { - // Use Dynamic Type to resolve theme fonts if possible, to get - // correct font sizes and style based on user configuration. - NSString *textStyle = 0; - switch (f) { - case QPlatformTheme::TitleBarFont: - case QPlatformTheme::HeaderViewFont: - textStyle = UIFontTextStyleHeadline; - break; - case QPlatformTheme::MdiSubWindowTitleFont: - textStyle = UIFontTextStyleSubheadline; - break; - case QPlatformTheme::TipLabelFont: - case QPlatformTheme::SmallFont: - textStyle = UIFontTextStyleFootnote; - break; - case QPlatformTheme::MiniFont: - textStyle = UIFontTextStyleCaption2; - break; - case QPlatformTheme::FixedFont: - // Fall back to regular code path, as iOS doesn't provide - // an appropriate text style for this theme font. - break; - default: - textStyle = UIFontTextStyleBody; - break; - } + // Use Dynamic Type to resolve theme fonts if possible, to get + // correct font sizes and style based on user configuration. + NSString *textStyle = 0; + switch (f) { + case QPlatformTheme::TitleBarFont: + case QPlatformTheme::HeaderViewFont: + textStyle = UIFontTextStyleHeadline; + break; + case QPlatformTheme::MdiSubWindowTitleFont: + textStyle = UIFontTextStyleSubheadline; + break; + case QPlatformTheme::TipLabelFont: + case QPlatformTheme::SmallFont: + textStyle = UIFontTextStyleFootnote; + break; + case QPlatformTheme::MiniFont: + textStyle = UIFontTextStyleCaption2; + break; + case QPlatformTheme::FixedFont: + // Fall back to regular code path, as iOS doesn't provide + // an appropriate text style for this theme font. + break; + default: + textStyle = UIFontTextStyleBody; + break; + } - if (textStyle) { - UIFontDescriptor *desc = [UIFontDescriptor preferredFontDescriptorWithTextStyle:textStyle]; - return static_cast(CFBridgingRetain(desc)); - } + if (textStyle) { + UIFontDescriptor *desc = [UIFontDescriptor preferredFontDescriptorWithTextStyle:textStyle]; + return static_cast(CFBridgingRetain(desc)); } #endif // Q_OS_IOS, Q_OS_TVOS @@ -948,31 +873,15 @@ void QCoreTextFontDatabase::removeApplicationFonts() return; foreach (const QVariant &font, m_applicationFonts) { -#if HAVE_CORETEXT - if (&CTFontManagerUnregisterGraphicsFont && &CTFontManagerUnregisterFontsForURL) { - CFErrorRef error; - if (font.canConvert(qMetaTypeId >())) { - CTFontManagerUnregisterGraphicsFont(font.value >(), &error); - } else if (font.canConvert(qMetaTypeId >())) { - CTFontManagerUnregisterFontsForURL(font.value >(), kCTFontManagerScopeProcess, &error); - } - } -#endif -#if HAVE_CORETEXT && HAVE_ATS - else -#endif -#if HAVE_ATS - if (font.canConvert(qMetaTypeId())) { - ATSFontDeactivate(font.value(), 0, kATSOptionFlagsDoNotNotify); + CFErrorRef error; + if (font.canConvert(qMetaTypeId >())) { + CTFontManagerUnregisterGraphicsFont(font.value >(), &error); + } else if (font.canConvert(qMetaTypeId >())) { + CTFontManagerUnregisterFontsForURL(font.value >(), kCTFontManagerScopeProcess, &error); } -#endif } m_applicationFonts.clear(); - -#if HAVE_ATS - ATSFontNotify(kATSFontNotifyActionFontsChanged, 0); -#endif } #ifndef QT_NO_FREETYPE -- cgit v1.2.3