From f99a0d0b6ec3dfa98704b4fe81a6f76543f9fb96 Mon Sep 17 00:00:00 2001 From: "mozilla%weilbacher.org" Date: Wed, 28 May 2008 12:38:10 +0000 Subject: [PATCH] [OS/2] Bug 432575: add options for font hinting and antialiasing to get approximately equal display than on branch. --- gfx/thebes/public/gfxOS2Fonts.h | 2 ++ gfx/thebes/src/gfxOS2Fonts.cpp | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gfx/thebes/public/gfxOS2Fonts.h b/gfx/thebes/public/gfxOS2Fonts.h index 0d44cf328e5..f358a7d0eba 100644 --- a/gfx/thebes/public/gfxOS2Fonts.h +++ b/gfx/thebes/public/gfxOS2Fonts.h @@ -79,6 +79,8 @@ private: Metrics *mMetrics; gfxFloat mAdjustedSize; PRUint32 mSpaceGlyph; + int mHinting; + PRBool mAntialias; }; diff --git a/gfx/thebes/src/gfxOS2Fonts.cpp b/gfx/thebes/src/gfxOS2Fonts.cpp index 18a95046375..44006dd1e8a 100644 --- a/gfx/thebes/src/gfxOS2Fonts.cpp +++ b/gfx/thebes/src/gfxOS2Fonts.cpp @@ -47,6 +47,8 @@ #include "nsIServiceManager.h" #include "nsIPlatformCharset.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" /********************************************************************** * class gfxOS2Font @@ -55,11 +57,29 @@ gfxOS2Font::gfxOS2Font(const nsAString &aName, const gfxFontStyle *aFontStyle) : gfxFont(aName, aFontStyle), mFontFace(nsnull), mScaledFont(nsnull), - mMetrics(nsnull), mAdjustedSize(0) + mMetrics(nsnull), mAdjustedSize(0), + mHinting(FC_HINT_MEDIUM), mAntialias(FcTrue) { -#ifdef DEBUG_thebes_2 +#if 1 //def DEBUG_thebes_2 printf("gfxOS2Font[%#x]::gfxOS2Font(\"%s\", aFontStyle)\n", (unsigned)this, NS_LossyConvertUTF16toASCII(aName).get()); +#endif + // try to get the preferences for hinting, antialias, and embolden options + nsCOMPtr prefbranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefbranch) { + int value; + nsresult rv = prefbranch->GetIntPref("gfx.os2.font.hinting", &value); + if (NS_SUCCEEDED(rv) && value >= FC_HINT_NONE && value <= FC_HINT_FULL) + mHinting = value; + + PRBool enabled; + rv = prefbranch->GetBoolPref("gfx.os2.font.antialiasing", &enabled); + if (NS_SUCCEEDED(rv)) + mAntialias = enabled; + } +#if 1 //def DEBUG_thebes_2 + printf(" font display options: hinting=%d, antialiasing=%s\n", + mHinting, mAntialias ? "on" : "off"); #endif } @@ -318,13 +338,20 @@ cairo_font_face_t *gfxOS2Font::CairoFontFace() (char *)str2, w2, i2, s2); #endif FcPatternDestroy(fcPattern); + if (mName == NS_LITERAL_STRING("Workplace Sans") && fcW >= FC_WEIGHT_DEMIBOLD) { // if we are dealing with Workplace Sans and want a bold font, we // need to artificially embolden it (no bold counterpart yet) FcPatternAddBool(fcMatch, FC_EMBOLDEN, FcTrue); + } else { + // if we don't embolden, we can possibly switch off antialiasing + FcPatternAddBool(fcMatch, FC_ANTIALIAS, mAntialias); } + FcPatternAddInteger(fcMatch, FC_HINT_STYLE, mHinting); + // and ask cairo to return a font face for this mFontFace = cairo_ft_font_face_create_for_pattern(fcMatch); + FcPatternDestroy(fcMatch); }