summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontdatabase_mac.cpp
diff options
context:
space:
mode:
authorMorten Sorvig <msorvig@trolltech.com>2009-09-16 05:53:15 (GMT)
committerMorten Sorvig <msorvig@trolltech.com>2009-09-16 05:53:15 (GMT)
commitdb8f89cdb4fcb0d8436db80d50221308900dca01 (patch)
tree5c9333d24f328224084ef30e6e9da2d2e7b706cd /src/gui/text/qfontdatabase_mac.cpp
parent10e1d939d6bf08249304cb2c555be2f74c3a0f02 (diff)
downloadQt-db8f89cdb4fcb0d8436db80d50221308900dca01.zip
Qt-db8f89cdb4fcb0d8436db80d50221308900dca01.tar.gz
Qt-db8f89cdb4fcb0d8436db80d50221308900dca01.tar.bz2
Improve font handling on Mac/Cocoa.
The Mac/Cocoa font database currently relies on two APIs, ATSUI (old) and CoreText (new). These are interchangable and work on the same font database. Some differences do exist, in particular ATSFontFamilyGetName seems to return the same as ATSFontGetName for some fonts - the font name, not the family name. In any case, the old ATS code path is initializing QFontDatabase::familes() with the font name. This causes a naming mismatch with code that uses CoreText and gets the proper family name, in this case in initializeDb(). The fix is to make sure the correct family name is used by using the CoreText API to access it. RevBy: TrustMe
Diffstat (limited to 'src/gui/text/qfontdatabase_mac.cpp')
-rw-r--r--src/gui/text/qfontdatabase_mac.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/gui/text/qfontdatabase_mac.cpp b/src/gui/text/qfontdatabase_mac.cpp
index d65910c..2584003 100644
--- a/src/gui/text/qfontdatabase_mac.cpp
+++ b/src/gui/text/qfontdatabase_mac.cpp
@@ -308,6 +308,21 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
if (familyRef) {
fontRef = ATSFontFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault);
goto FamilyFound;
+ } else {
+#if defined(QT_MAC_USE_COCOA)
+ // ATS and CT disagrees on what the family name should be,
+ // use CT to look up the font if ATS fails.
+ QCFString familyName = QString::fromAscii(family_name);
+ QCFType<CTFontRef> CTfontRef = CTFontCreateWithName(familyName, 12, NULL);
+ QCFType<CTFontDescriptorRef> fontDescriptor = CTFontCopyFontDescriptor(CTfontRef);
+ QCFString displayName = (CFStringRef)CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontDisplayNameAttribute);
+
+ familyRef = ATSFontFamilyFindFromName(displayName, kATSOptionFlagsDefault);
+ if (familyRef) {
+ fontRef = ATSFontFindFromName(displayName, kATSOptionFlagsDefault);
+ goto FamilyFound;
+ }
+#endif
}
}
}
@@ -456,11 +471,27 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
return;
fnt->families.clear();
+#if defined(QT_MAC_USE_COCOA)
+ // Make sure that the family name set on the font matches what
+ // kCTFontFamilyNameAttribute returns in initializeDb().
+ // So far the best solution seems find the installed font
+ // using CoreText and get the family name from it.
+ // (ATSFontFamilyGetName appears to be the correct API, but also
+ // returns the font display name.)
+ for(int i = 0; i < containedFonts.size(); ++i) {
+ QCFString fontPostScriptName;
+ ATSFontGetPostScriptName(containedFonts[i], kATSOptionFlagsDefault, &fontPostScriptName);
+ QCFType<CTFontDescriptorRef> font = CTFontDescriptorCreateWithNameAndSize(fontPostScriptName, 14);
+ QCFString familyName = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute);
+ fnt->families.append(familyName);
+ }
+#else
for(int i = 0; i < containedFonts.size(); ++i) {
QCFString family;
ATSFontGetName(containedFonts[i], kATSOptionFlagsDefault, &family);
fnt->families.append(family);
}
+#endif
fnt->handle = handle;
}