From d1ebeafde802291529452faf34ede7fd3e89e86e Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 16 Jul 2009 11:00:38 +0100 Subject: [PATCH] bug 502795 - avoid using CTFontCreateCopyWithAttributes to disable ligatures because it fails with privately-activated download fonts, r=roc --- gfx/thebes/public/gfxCoreTextFonts.h | 2 +- gfx/thebes/src/gfxCoreTextFonts.cpp | 49 +++++++++++++++++++--------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/gfx/thebes/public/gfxCoreTextFonts.h b/gfx/thebes/public/gfxCoreTextFonts.h index da8dde8b482b..30a9f43be391 100644 --- a/gfx/thebes/public/gfxCoreTextFonts.h +++ b/gfx/thebes/public/gfxCoreTextFonts.h @@ -109,7 +109,7 @@ public: // clean up static objects that may have been cached static void Shutdown(); - static CTFontRef CreateCopyWithDisabledLigatures(CTFontRef aFont); + static CTFontRef CreateCTFontWithDisabledLigatures(ATSFontRef aFont, CGFloat aSize); protected: const gfxFontStyle *mFontStyle; diff --git a/gfx/thebes/src/gfxCoreTextFonts.cpp b/gfx/thebes/src/gfxCoreTextFonts.cpp index 98c293e97c59..5d31b8ea4f7d 100644 --- a/gfx/thebes/src/gfxCoreTextFonts.cpp +++ b/gfx/thebes/src/gfxCoreTextFonts.cpp @@ -77,6 +77,26 @@ static PRLogModuleInfo *gCoreTextTextRunLog = PR_NewLogModule("coreTextTextRun") CTFontDescriptorRef gfxCoreTextFont::sDefaultFeaturesDescriptor = NULL; CTFontDescriptorRef gfxCoreTextFont::sDisableLigaturesDescriptor = NULL; +#ifdef DEBUG_jonathan +static void dumpFontDescCallback(const void *key, const void *value, void *context) +{ + CFStringRef attribute = (CFStringRef)key; + CFTypeRef setting = (CFTypeRef)value; + fprintf(stderr, "attr: "); CFShow(attribute); + fprintf(stderr, " = "); CFShow(setting); + fprintf(stderr, "\n"); +} + +static void +dumpFontDescriptor(CTFontRef font) +{ + CTFontDescriptorRef desc = CTFontCopyFontDescriptor(font); + CFDictionaryRef dict = CTFontDescriptorCopyAttributes(desc); + CFRelease(desc); + CFDictionaryApplyFunction(dict, &dumpFontDescCallback, 0); + CFRelease(dict); +} +#endif gfxCoreTextFont::gfxCoreTextFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyle, @@ -451,9 +471,9 @@ gfxCoreTextFont::CreateDefaultFeaturesDescriptor() CFRelease(attributesDict); } -// Create a copy of a CTFontRef, with the Common Ligatures feature disabled [static] +// Create a CTFontRef for an ATS font ref, with the Common Ligatures feature disabled [static] CTFontRef -gfxCoreTextFont::CreateCopyWithDisabledLigatures(CTFontRef aFontRef) +gfxCoreTextFont::CreateCTFontWithDisabledLigatures(ATSFontRef aFontRef, CGFloat aSize) { if (sDisableLigaturesDescriptor == NULL) { // initialize cached descriptor to turn off the Common Ligatures feature @@ -499,16 +519,11 @@ gfxCoreTextFont::CreateCopyWithDisabledLigatures(CTFontRef aFontRef) CFRelease(featuresArray); sDisableLigaturesDescriptor = - CTFontDescriptorCreateWithAttributes(attributesDict); + CTFontDescriptorCreateCopyWithAttributes(GetDefaultFeaturesDescriptor(), attributesDict); CFRelease(attributesDict); } - - aFontRef = - CTFontCreateCopyWithAttributes(aFontRef, - 0.0, - NULL, - sDisableLigaturesDescriptor); - return aFontRef; + + return CTFontCreateWithPlatformFont(aFontRef, aSize, NULL, sDisableLigaturesDescriptor); } void @@ -759,19 +774,20 @@ gfxCoreTextFontGroup::InitTextRun(gfxTextRun *aTextRun, if (disableLigatures) { // For letterspacing (or maybe other situations) we need to make a copy of the CTFont // with the ligature feature disabled - CTFontRef mainCTFont = mainFont->GetCTFont(); - mainCTFont = gfxCoreTextFont::CreateCopyWithDisabledLigatures(mainCTFont); + CTFontRef ctFont = + gfxCoreTextFont::CreateCTFontWithDisabledLigatures(mainFont->GetATSFont(), + CTFontGetSize(mainFont->GetCTFont())); // Set up the initial font, for the (common) case of a monostyled textRun attrObj = CFDictionaryCreate(kCFAllocatorDefault, (const void**) &kCTFontAttributeName, - (const void**) &mainCTFont, + (const void**) &ctFont, 1, // count of attributes &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - // Having created the dict, we're finished with our modified copy of the CTFont - CFRelease(mainCTFont); + // Having created the dict, we're finished with our ligature-disabled CTFontRef + CFRelease(ctFont); } else { attrObj = mainFont->GetAttributesDictionary(); CFRetain(attrObj); @@ -813,7 +829,8 @@ gfxCoreTextFontGroup::InitTextRun(gfxTextRun *aTextRun, if (matchedFont != mainFont) { CTFontRef matchedCTFont = matchedFont->GetCTFont(); if (disableLigatures) - matchedCTFont = gfxCoreTextFont::CreateCopyWithDisabledLigatures(matchedCTFont); + matchedCTFont = gfxCoreTextFont::CreateCTFontWithDisabledLigatures(matchedFont->GetATSFont(), + CTFontGetSize(matchedCTFont)); // if necessary, make a mutable copy of the string if (!mutableStringObj) { mutableStringObj =