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>
This commit is contained in:
parent
a4a174e1a2
commit
5173589b79
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user