From 5173589b795560c2042d06d191ac86ad61f24e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 21 Jan 2014 16:35:51 +0100 Subject: Use shared list of application fonts in CoreText font database Instead of three separate lists depending on the font type. This makes enables sharing more code between the different implementations. Change-Id: If090d1b4a32f035b6344cbadd4c5ba66e0cb99f7 Reviewed-by: Simon Hausmann --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 34 +++++++++++----------- .../fontdatabases/mac/qcoretextfontdatabase_p.h | 12 ++++---- 2 files changed, 24 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 38c44e3f35..1b468b3eff 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -491,7 +491,7 @@ QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData bool success = CTFontManagerRegisterGraphicsFont(cgFont, &error); if (success) { font = CTFontCreateWithGraphicsFont(cgFont, 0.0, NULL, NULL); - m_applicationGraphicsFonts.append(QCFType::constructFromGet(cgFont)); + m_applicationFonts.append(QVariant::fromValue(QCFType::constructFromGet(cgFont))); } else { NSLog(@"Unable to register font: %@", error); CFRelease(error); @@ -509,7 +509,7 @@ QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); QCFType descriptor = CTFontDescriptorCreateWithAttributes(attributes); font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL); - m_applicationURLFonts.append(QCFType::constructFromGet(fontURL)); + m_applicationFonts.append(QVariant::fromValue(QCFType::constructFromGet(fontURL))); } else { NSLog(@"Unable to register font: %@", error); CFRelease(error); @@ -564,7 +564,7 @@ QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData families.append(QCFString(CTFontCopyFamilyName(font))); } - m_applicationFonts.append(fontContainer); + m_applicationFonts.append(QVariant::fromValue(fontContainer)); return families; } } @@ -597,24 +597,24 @@ QList QCoreTextFontDatabase::standardSizes() const void QCoreTextFontDatabase::removeApplicationFonts() { #ifdef Q_OS_MACX + foreach (const QVariant &font, m_applicationFonts) { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { - CFErrorRef error; - for (int i = 0; i < m_applicationGraphicsFonts.count(); ++i) - CTFontManagerUnregisterGraphicsFont(m_applicationGraphicsFonts[i], &error); - m_applicationGraphicsFonts.clear(); - - for (int i = 0; i < m_applicationURLFonts.count(); ++i) - CTFontManagerUnregisterFontsForURL(m_applicationURLFonts[i], kCTFontManagerScopeProcess, &error); - m_applicationURLFonts.clear(); - } else + if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { + CFErrorRef error; + if (font.canConvert(qMetaTypeId>())) { + CTFontManagerUnregisterGraphicsFont(font.value>(), &error); + } else if (font.canConvert(qMetaTypeId>())) { + CTFontManagerUnregisterFontsForURL(font.value>(), kCTFontManagerScopeProcess, &error); + } + } else #endif - { - for (int i = 0; i < m_applicationFonts.count(); ++i) - ATSFontDeactivate(m_applicationFonts[i], 0, kATSOptionFlagsDoNotNotify); + if (font.canConvert(qMetaTypeId())) { + ATSFontDeactivate(font.value(), 0, kATSOptionFlagsDoNotNotify); + } + } + m_applicationFonts.clear(); ATSFontNotify(kATSFontNotifyActionFontsChanged, 0); - } #endif } diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h index ee1016509b..da0c1d338b 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h @@ -52,6 +52,12 @@ #include #endif +#ifdef Q_OS_MACX +Q_DECLARE_METATYPE(QCFType); +Q_DECLARE_METATYPE(QCFType); +Q_DECLARE_METATYPE(ATSFontContainerRef); +#endif + QT_BEGIN_NAMESPACE class QCoreTextFontDatabase : public QPlatformFontDatabase @@ -79,11 +85,7 @@ private: void removeApplicationFonts(); #ifdef Q_OS_MACX -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 - QVector > m_applicationGraphicsFonts; - QVector > m_applicationURLFonts; -#endif - QVector m_applicationFonts; + QVector m_applicationFonts; #endif }; -- cgit v1.2.3