Commit 155ba886 authored by jdaggett@mozilla.com's avatar jdaggett@mozilla.com
Browse files

Bug 418479. Allow antialiased text rendering to be disabled for small text...

Bug 418479. Allow antialiased text rendering to be disabled for small text sizes via a pref. r+sr=vlad, a=damons
parent a8cda160
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -80,14 +80,21 @@ public:
    // Ex: Mac OS X 10.4.x ==> 0x104x 
    PRInt32 OSXVersion();

    // lower threshold on font anti-aliasing
    PRUint32 GetAntiAliasingThreshold() { return mFontAntiAliasingThreshold; }
    
private:
    void gfxPlatformMac::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, 
                                            eFontPrefLang aCharLang, eFontPrefLang aPageLang);
                                               
    virtual cmsHPROFILE GetPlatformCMSOutputProfile();
    
    // read in the pref value for the lower threshold on font anti-aliasing
    static PRUint32 ReadAntiAliasingThreshold();    
    
    nsTArray<PRUint32> mCJKPrefLangs;
    PRInt32 mOSXVersion;
    PRUint32 mFontAntiAliasingThreshold;
};

#endif /* GFX_PLATFORM_MAC_H */
+7 −0
Original line number Diff line number Diff line
@@ -140,6 +140,13 @@ gfxAtsuiFont::gfxAtsuiFont(MacOSFontEntry *aFontEntry,
    }

    cairo_font_options_t *fontOptions = cairo_font_options_create();
    
    // turn off font anti-aliasing based on user pref setting
    if (mAdjustedSize <= (float) gfxPlatformMac::GetPlatform()->GetAntiAliasingThreshold()) {
        cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_NONE); 
        //printf("font: %s, size: %f, disabling anti-aliasing\n", NS_ConvertUTF16toUTF8(mName).get(), mAdjustedSize);
    }
    
    mScaledFont = cairo_scaled_font_create(mFontFace, &sizeMatrix, &ctm, fontOptions);
    cairo_font_options_destroy(fontOptions);
    NS_ASSERTION(cairo_scaled_font_status(mScaledFont) == CAIRO_STATUS_SUCCESS,
+34 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ gfxPlatformMac::gfxPlatformMac()
        glitz_agl_init();
#endif
    mOSXVersion = 0;
    mFontAntiAliasingThreshold = ReadAntiAliasingThreshold();
}

already_AddRefed<gfxASurface>
@@ -336,6 +337,39 @@ gfxPlatformMac::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, e
        
}

PRUint32
gfxPlatformMac::ReadAntiAliasingThreshold()
{
    PRUint32 threshold = 0;  // default == no threshold
    
    // first read prefs flag to determine whether to use the setting or not
    PRBool useAntiAliasingThreshold = PR_FALSE;
    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
    if (prefs) {
        PRBool enabled;
        nsresult rv =
            prefs->GetBoolPref("gfx.use_text_smoothing_setting", &enabled);
        if (NS_SUCCEEDED(rv)) {
            useAntiAliasingThreshold = enabled;
        }
    }
    
    // if the pref setting is disabled, return 0 which effectively disables this feature
    if (!useAntiAliasingThreshold)
        return threshold;
        
    // value set via Appearance pref panel, "Turn off text smoothing for font sizes xxx and smaller"
    CFNumberRef prefValue = (CFNumberRef)CFPreferencesCopyAppValue(CFSTR("AppleAntiAliasingThreshold"), kCFPreferencesCurrentApplication);

    if (prefValue) {
        if (!CFNumberGetValue(prefValue, kCFNumberIntType, &threshold)) {
            threshold = 0;
        }
        CFRelease(prefValue);
    }

    return threshold;
}

cmsHPROFILE
gfxPlatformMac::GetPlatformCMSOutputProfile()
+3 −0
Original line number Diff line number Diff line
@@ -172,6 +172,9 @@ pref("accessibility.typeaheadfind.soundURL", "beep");
pref("accessibility.typeaheadfind.enablesound", true);
pref("accessibility.typeaheadfind.prefillwithselection", true);

// use Mac OS X Appearance panel text smoothing setting when rendering text, disabled by default
pref("gfx.use_text_smoothing_setting", false);

pref("browser.history_expire_days", 9);

// loading and rendering of framesets and iframes