diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2014-01-21 16:35:51 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-25 03:04:42 +0100 |
commit | 5173589b795560c2042d06d191ac86ad61f24e51 (patch) | |
tree | c1100029b2f3a89b973017a96bc5c74020daa124 | |
parent | a4a174e1a212bb934290853cf900594a18dba6bb (diff) |
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 <simon.hausmann@digia.com>
-rw-r--r-- | src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm | 34 | ||||
-rw-r--r-- | src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h | 12 |
2 files changed, 24 insertions, 22 deletions
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<CGFontRef>::constructFromGet(cgFont)); + m_applicationFonts.append(QVariant::fromValue(QCFType<CGFontRef>::constructFromGet(cgFont))); } else { NSLog(@"Unable to register font: %@", error); CFRelease(error); @@ -509,7 +509,7 @@ QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithAttributes(attributes); font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL); - m_applicationURLFonts.append(QCFType<CFURLRef>::constructFromGet(fontURL)); + m_applicationFonts.append(QVariant::fromValue(QCFType<CFURLRef>::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<int> 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<QCFType<CGFontRef>>())) { + CTFontManagerUnregisterGraphicsFont(font.value<QCFType<CGFontRef>>(), &error); + } else if (font.canConvert(qMetaTypeId<QCFType<CFURLRef>>())) { + CTFontManagerUnregisterFontsForURL(font.value<QCFType<CFURLRef>>(), kCTFontManagerScopeProcess, &error); + } + } else #endif - { - for (int i = 0; i < m_applicationFonts.count(); ++i) - ATSFontDeactivate(m_applicationFonts[i], 0, kATSOptionFlagsDoNotNotify); + if (font.canConvert(qMetaTypeId<ATSFontContainerRef>())) { + ATSFontDeactivate(font.value<ATSFontContainerRef>(), 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 <CoreGraphics/CoreGraphics.h> #endif +#ifdef Q_OS_MACX +Q_DECLARE_METATYPE(QCFType<CGFontRef>); +Q_DECLARE_METATYPE(QCFType<CFURLRef>); +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<QCFType<CGFontRef> > m_applicationGraphicsFonts; - QVector<QCFType<CFURLRef> > m_applicationURLFonts; -#endif - QVector<ATSFontContainerRef> m_applicationFonts; + QVector<QVariant> m_applicationFonts; #endif }; |