From db8f89cdb4fcb0d8436db80d50221308900dca01 Mon Sep 17 00:00:00 2001 From: Morten Sorvig Date: Wed, 16 Sep 2009 07:53:15 +0200 Subject: 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 --- src/gui/text/qfontdatabase_mac.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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 = CTFontCreateWithName(familyName, 12, NULL); + QCFType 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 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; } -- cgit v0.12