From 9a2ab9c8d717eb4b98ac1a70a28f381ef2eaad00 Mon Sep 17 00:00:00 2001 From: "jdaggett@mozilla.com" Date: Thu, 1 May 2008 02:07:17 -0700 Subject: [PATCH] Bug 418479. Allow antialiased text rendering to be disabled for small text sizes via a pref. r+sr=vlad, a=damons --- gfx/thebes/public/gfxPlatformMac.h | 7 ++++++ gfx/thebes/src/gfxAtsuiFonts.cpp | 7 ++++++ gfx/thebes/src/gfxPlatformMac.cpp | 34 ++++++++++++++++++++++++++++++ modules/libpref/src/init/all.js | 3 +++ 4 files changed, 51 insertions(+) diff --git a/gfx/thebes/public/gfxPlatformMac.h b/gfx/thebes/public/gfxPlatformMac.h index 10c091b9d21..6fd61dd7af9 100644 --- a/gfx/thebes/public/gfxPlatformMac.h +++ b/gfx/thebes/public/gfxPlatformMac.h @@ -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 mCJKPrefLangs; PRInt32 mOSXVersion; + PRUint32 mFontAntiAliasingThreshold; }; #endif /* GFX_PLATFORM_MAC_H */ diff --git a/gfx/thebes/src/gfxAtsuiFonts.cpp b/gfx/thebes/src/gfxAtsuiFonts.cpp index 8c359b884b5..5241195ce04 100644 --- a/gfx/thebes/src/gfxAtsuiFonts.cpp +++ b/gfx/thebes/src/gfxAtsuiFonts.cpp @@ -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, diff --git a/gfx/thebes/src/gfxPlatformMac.cpp b/gfx/thebes/src/gfxPlatformMac.cpp index 1f7095a5e9b..ad4ed122ea7 100644 --- a/gfx/thebes/src/gfxPlatformMac.cpp +++ b/gfx/thebes/src/gfxPlatformMac.cpp @@ -65,6 +65,7 @@ gfxPlatformMac::gfxPlatformMac() glitz_agl_init(); #endif mOSXVersion = 0; + mFontAntiAliasingThreshold = ReadAntiAliasingThreshold(); } already_AddRefed @@ -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 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() diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 6e4b919351b..664f854e816 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -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