mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 504698. Enable Cleartype content rendering by default on Win XP. r=jkew
This commit is contained in:
parent
21ded9fe47
commit
c6e609d0b2
@ -64,6 +64,7 @@ class gfxPlatformFontList;
|
||||
class gfxTextRun;
|
||||
class nsIURI;
|
||||
class nsIAtom;
|
||||
class nsIPrefBranch;
|
||||
|
||||
// pref lang id's for font prefs
|
||||
// !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
|
||||
@ -120,6 +121,8 @@ enum eCMSMode {
|
||||
// when searching through pref langs, max number of pref langs
|
||||
const PRUint32 kMaxLenPrefLangList = 32;
|
||||
|
||||
#define UNINITIALIZED_VALUE (-1)
|
||||
|
||||
class THEBES_API gfxPlatform {
|
||||
public:
|
||||
/**
|
||||
@ -329,10 +332,14 @@ public:
|
||||
return sDPI;
|
||||
}
|
||||
|
||||
virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
|
||||
|
||||
protected:
|
||||
gfxPlatform() { }
|
||||
gfxPlatform();
|
||||
virtual ~gfxPlatform();
|
||||
|
||||
static PRBool GetBoolPref(const char *aPref, PRBool aDefault);
|
||||
|
||||
void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen,
|
||||
eFontPrefLang aCharLang, eFontPrefLang aPageLang);
|
||||
|
||||
@ -342,6 +349,8 @@ protected:
|
||||
virtual void InitDisplayCaps();
|
||||
static PRInt32 sDPI;
|
||||
|
||||
PRBool mAllowDownloadableFonts;
|
||||
|
||||
private:
|
||||
virtual qcms_profile* GetPlatformCMSOutputProfile();
|
||||
|
||||
|
@ -191,6 +191,26 @@ public:
|
||||
|
||||
void ClearPrefFonts() { mPrefFonts.Clear(); }
|
||||
|
||||
// ClearType is not always enabled even when available (e.g. Windows XP)
|
||||
// if either of these prefs are enabled and apply, use ClearType rendering
|
||||
PRBool UseClearTypeForDownloadableFonts();
|
||||
PRBool UseClearTypeAlways();
|
||||
|
||||
// OS version in 16.16 major/minor form
|
||||
// based on http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx
|
||||
enum {
|
||||
kWindowsUnknown = 0,
|
||||
kWindows2000 = 0x50000,
|
||||
kWindowsXP = 0x50001,
|
||||
kWindowsServer2003 = 0x50002,
|
||||
kWindowsVista = 0x60000,
|
||||
kWindows7 = 0x60001
|
||||
};
|
||||
|
||||
static PRInt32 WindowsOSVersion();
|
||||
|
||||
virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
|
||||
|
||||
#ifdef CAIRO_HAS_DWRITE_FONT
|
||||
IDWriteFactory *GetDWriteFactory() { return mDWriteFactory; }
|
||||
#endif
|
||||
@ -204,6 +224,9 @@ protected:
|
||||
|
||||
RenderMode mRenderMode;
|
||||
|
||||
PRBool mUseClearTypeForDownloadableFonts;
|
||||
PRBool mUseClearTypeAlways;
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
|
@ -360,6 +360,7 @@ gfxGDIFont::FillLogFont(LOGFONTW& aLogFont, gfxFloat aSize)
|
||||
}
|
||||
}
|
||||
|
||||
fe->FillLogFont(&aLogFont, italic, weight, aSize);
|
||||
fe->FillLogFont(&aLogFont, italic, weight, aSize,
|
||||
(mAntialiasOption == kAntialiasSubpixel) ? PR_TRUE : PR_FALSE);
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,11 @@
|
||||
|
||||
#define ROUND(x) floor((x) + 0.5)
|
||||
|
||||
|
||||
#ifndef CLEARTYPE_QUALITY
|
||||
#define CLEARTYPE_QUALITY 5
|
||||
#endif
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
static PRLogModuleInfo *gFontInfoLog = PR_NewLogModule("fontInfoLog");
|
||||
#endif /* PR_LOGGING */
|
||||
@ -193,7 +198,16 @@ GDIFontEntry::GDIFontEntry(const nsAString& aFaceName, gfxWindowsFontType aFontT
|
||||
if (IsType1())
|
||||
mForceGDI = PR_TRUE;
|
||||
mIsUserFont = aUserFontData != nsnull;
|
||||
InitLogFont(aFaceName, aFontType);
|
||||
|
||||
PRBool isXP = (gfxWindowsPlatform::WindowsOSVersion()
|
||||
< gfxWindowsPlatform::kWindowsVista);
|
||||
|
||||
PRBool useClearType = isXP &&
|
||||
(gfxWindowsPlatform::GetPlatform()->UseClearTypeAlways() ||
|
||||
(mIsUserFont &&
|
||||
gfxWindowsPlatform::GetPlatform()->UseClearTypeForDownloadableFonts()));
|
||||
|
||||
InitLogFont(aFaceName, aFontType, useClearType);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -224,7 +238,17 @@ GDIFontEntry::ReadCMAP()
|
||||
gfxFont *
|
||||
GDIFontEntry::CreateFontInstance(const gfxFontStyle* aFontStyle, PRBool aNeedsBold)
|
||||
{
|
||||
return new gfxGDIFont(this, aFontStyle, aNeedsBold);
|
||||
PRBool isXP = (gfxWindowsPlatform::WindowsOSVersion()
|
||||
< gfxWindowsPlatform::kWindowsVista);
|
||||
|
||||
PRBool useClearType = isXP &&
|
||||
(gfxWindowsPlatform::GetPlatform()->UseClearTypeAlways() ||
|
||||
(mIsUserFont &&
|
||||
gfxWindowsPlatform::GetPlatform()->UseClearTypeForDownloadableFonts()));
|
||||
|
||||
return new gfxGDIFont(this, aFontStyle, aNeedsBold,
|
||||
(useClearType ? gfxFont::kAntialiasSubpixel
|
||||
: gfxFont::kAntialiasDefault));
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -247,7 +271,8 @@ GDIFontEntry::GetFontTable(PRUint32 aTableTag, nsTArray<PRUint8>& aBuffer)
|
||||
|
||||
void
|
||||
GDIFontEntry::FillLogFont(LOGFONTW *aLogFont, PRBool aItalic,
|
||||
PRUint16 aWeight, gfxFloat aSize)
|
||||
PRUint16 aWeight, gfxFloat aSize,
|
||||
PRBool aUseCleartype)
|
||||
{
|
||||
memcpy(aLogFont, &mLogFont, sizeof(LOGFONTW));
|
||||
|
||||
@ -331,7 +356,8 @@ GDIFontEntry::TestCharacterMap(PRUint32 aCh)
|
||||
|
||||
void
|
||||
GDIFontEntry::InitLogFont(const nsAString& aName,
|
||||
gfxWindowsFontType aFontType)
|
||||
gfxWindowsFontType aFontType,
|
||||
PRBool aUseCleartype)
|
||||
{
|
||||
#define CLIP_TURNOFF_FONTASSOCIATION 0x40
|
||||
|
||||
@ -346,7 +372,7 @@ GDIFontEntry::InitLogFont(const nsAString& aName,
|
||||
mLogFont.lfCharSet = DEFAULT_CHARSET;
|
||||
mLogFont.lfOutPrecision = FontTypeToOutPrecision(aFontType);
|
||||
mLogFont.lfClipPrecision = CLIP_TURNOFF_FONTASSOCIATION;
|
||||
mLogFont.lfQuality = DEFAULT_QUALITY;
|
||||
mLogFont.lfQuality = (aUseCleartype ? CLEARTYPE_QUALITY : DEFAULT_QUALITY);
|
||||
mLogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
|
||||
// always force lfItalic if we want it. Font selection code will
|
||||
// do its best to give us an italic font entry, but if no face exists
|
||||
|
@ -145,7 +145,7 @@ public:
|
||||
nsresult ReadCMAP();
|
||||
|
||||
void FillLogFont(LOGFONTW *aLogFont, PRBool aItalic,
|
||||
PRUint16 aWeight, gfxFloat aSize);
|
||||
PRUint16 aWeight, gfxFloat aSize, PRBool aUseCleartype);
|
||||
|
||||
static gfxWindowsFontType DetermineFontType(const NEWTEXTMETRICW& metrics,
|
||||
DWORD fontType)
|
||||
@ -300,7 +300,8 @@ protected:
|
||||
GDIFontEntry(const nsAString& aFaceName, gfxWindowsFontType aFontType,
|
||||
PRBool aItalic, PRUint16 aWeight, gfxUserFontData *aUserFontData);
|
||||
|
||||
void InitLogFont(const nsAString& aName, gfxWindowsFontType aFontType);
|
||||
void InitLogFont(const nsAString& aName, gfxWindowsFontType aFontType,
|
||||
PRBool aUseCleartype);
|
||||
|
||||
virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle, PRBool aNeedsBold);
|
||||
|
||||
|
@ -131,6 +131,35 @@ SRGBOverrideObserver::Observe(nsISupports *aSubject,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#define GFX_DOWNLOADABLE_FONTS_ENABLED "gfx.downloadable_fonts.enabled"
|
||||
|
||||
class FontPrefsObserver : public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(FontPrefsObserver, nsIObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
FontPrefsObserver::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const PRUnichar *someData)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(aSubject);
|
||||
if (!branch || someData == nsnull) {
|
||||
NS_ERROR("font pref observer code broken");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
gfxPlatform::GetPlatform()->FontsPrefsChanged(branch,
|
||||
NS_ConvertUTF16toUTF8(someData).get());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// this needs to match the list of pref font.default.xx entries listed in all.js!
|
||||
// the order *must* match the order in eFontPrefLang
|
||||
@ -169,6 +198,10 @@ static const char *gPrefLangNames[] = {
|
||||
"x-user-def"
|
||||
};
|
||||
|
||||
gfxPlatform::gfxPlatform()
|
||||
{
|
||||
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
|
||||
}
|
||||
|
||||
gfxPlatform*
|
||||
gfxPlatform::GetPlatform()
|
||||
@ -238,9 +271,14 @@ gfxPlatform::Init()
|
||||
|
||||
/* Create and register our CMS Override observer. */
|
||||
gPlatform->overrideObserver = new SRGBOverrideObserver();
|
||||
FontPrefsObserver *fontPrefObserver = new FontPrefsObserver();
|
||||
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs)
|
||||
if (prefs) {
|
||||
prefs->AddObserver(CMForceSRGBPrefName, gPlatform->overrideObserver, PR_TRUE);
|
||||
prefs->AddObserver(GFX_DOWNLOADABLE_FONTS_ENABLED, fontPrefObserver, PR_FALSE);
|
||||
prefs->AddObserver("gfx.font_rendering.", fontPrefObserver, PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -331,26 +369,28 @@ gfxPlatform::UpdateFontList()
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#define GFX_DOWNLOADABLE_FONTS_ENABLED "gfx.downloadable_fonts.enabled"
|
||||
PRBool
|
||||
gfxPlatform::GetBoolPref(const char *aPref, PRBool aDefault)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
PRBool allow;
|
||||
nsresult rv = prefs->GetBoolPref(aPref, &allow);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return allow;
|
||||
}
|
||||
|
||||
return aDefault;
|
||||
}
|
||||
|
||||
PRBool
|
||||
gfxPlatform::DownloadableFontsEnabled()
|
||||
{
|
||||
static PRBool initialized = PR_FALSE;
|
||||
static PRBool allowDownloadableFonts = PR_FALSE;
|
||||
|
||||
if (initialized == PR_FALSE) {
|
||||
initialized = PR_TRUE;
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
PRBool allow;
|
||||
nsresult rv = prefs->GetBoolPref(GFX_DOWNLOADABLE_FONTS_ENABLED, &allow);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
allowDownloadableFonts = allow;
|
||||
}
|
||||
if (mAllowDownloadableFonts == UNINITIALIZED_VALUE) {
|
||||
mAllowDownloadableFonts = GetBoolPref(GFX_DOWNLOADABLE_FONTS_ENABLED, PR_FALSE);
|
||||
}
|
||||
|
||||
return allowDownloadableFonts;
|
||||
return mAllowDownloadableFonts;
|
||||
}
|
||||
|
||||
gfxFontEntry*
|
||||
@ -1058,3 +1098,15 @@ gfxPlatform::SetupClusterBoundaries(gfxTextRun *aTextRun, const PRUnichar *aStri
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gfxPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref)
|
||||
{
|
||||
NS_ASSERTION(aPref != nsnull, "null pref branch");
|
||||
if (!strcmp(GFX_DOWNLOADABLE_FONTS_ENABLED, aPref)) {
|
||||
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -88,6 +88,9 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#define GFX_USE_CLEARTYPE_ALWAYS "gfx.font_rendering.cleartype.always_use_for_content"
|
||||
#define GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE "gfx.font_rendering.cleartype.use_for_downloadable_fonts"
|
||||
|
||||
#ifdef MOZ_FT2_FONTS
|
||||
static FT_Library gPlatformFTLibrary = NULL;
|
||||
#endif
|
||||
@ -114,6 +117,9 @@ gfxWindowsPlatform::gfxWindowsPlatform()
|
||||
{
|
||||
mPrefFonts.Init(50);
|
||||
|
||||
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
|
||||
mUseClearTypeAlways = UNINITIALIZED_VALUE;
|
||||
|
||||
#ifdef MOZ_FT2_FONTS
|
||||
FT_Init_FreeType(&gPlatformFTLibrary);
|
||||
#endif
|
||||
@ -435,6 +441,44 @@ gfxWindowsPlatform::GetFTLibrary()
|
||||
}
|
||||
#endif
|
||||
|
||||
PRBool
|
||||
gfxWindowsPlatform::UseClearTypeForDownloadableFonts()
|
||||
{
|
||||
if (mUseClearTypeForDownloadableFonts == UNINITIALIZED_VALUE) {
|
||||
mUseClearTypeForDownloadableFonts = GetBoolPref(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, PR_TRUE);
|
||||
}
|
||||
|
||||
return mUseClearTypeForDownloadableFonts;
|
||||
}
|
||||
|
||||
PRBool
|
||||
gfxWindowsPlatform::UseClearTypeAlways()
|
||||
{
|
||||
if (mUseClearTypeAlways == UNINITIALIZED_VALUE) {
|
||||
mUseClearTypeAlways = GetBoolPref(GFX_USE_CLEARTYPE_ALWAYS, PR_FALSE);
|
||||
}
|
||||
|
||||
return mUseClearTypeAlways;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
gfxWindowsPlatform::WindowsOSVersion()
|
||||
{
|
||||
static PRInt32 winVersion = UNINITIALIZED_VALUE;
|
||||
|
||||
OSVERSIONINFO vinfo;
|
||||
|
||||
if (winVersion == UNINITIALIZED_VALUE) {
|
||||
vinfo.dwOSVersionInfoSize = sizeof (vinfo);
|
||||
if (!GetVersionEx(&vinfo)) {
|
||||
winVersion = kWindowsUnknown;
|
||||
} else {
|
||||
winVersion = PRInt32(vinfo.dwMajorVersion << 16) + vinfo.dwMinorVersion;
|
||||
}
|
||||
}
|
||||
return winVersion;
|
||||
}
|
||||
|
||||
void
|
||||
gfxWindowsPlatform::InitDisplayCaps()
|
||||
{
|
||||
@ -444,3 +488,28 @@ gfxWindowsPlatform::InitDisplayCaps()
|
||||
|
||||
ReleaseDC((HWND)nsnull, dc);
|
||||
}
|
||||
|
||||
void
|
||||
gfxWindowsPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref)
|
||||
{
|
||||
PRBool clearFontCache = PR_TRUE;
|
||||
|
||||
gfxPlatform::FontsPrefsChanged(aPrefBranch, aPref);
|
||||
|
||||
if (!aPref) {
|
||||
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
|
||||
mUseClearTypeAlways = UNINITIALIZED_VALUE;
|
||||
} else if (!strcmp(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, aPref)) {
|
||||
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
|
||||
} else if (!strcmp(GFX_USE_CLEARTYPE_ALWAYS, aPref)) {
|
||||
mUseClearTypeAlways = UNINITIALIZED_VALUE;
|
||||
} else {
|
||||
clearFontCache = PR_FALSE;
|
||||
}
|
||||
|
||||
if (clearFontCache) {
|
||||
gfxFontCache *fc = gfxFontCache::GetCache();
|
||||
if (fc)
|
||||
fc->AgeAllGenerations();
|
||||
}
|
||||
}
|
@ -1608,6 +1608,14 @@ pref("font.size.fixed.zh-HK", 16);
|
||||
// We have special support for Monotype Symbol on Windows.
|
||||
pref("font.mathfont-family", "STIXNonUnicode, STIXSize1, STIXGeneral, Symbol, DejaVu Sans, Cambria Math");
|
||||
|
||||
// cleartype settings - false implies default system settings
|
||||
|
||||
// use cleartype rendering for downloadable fonts (win xp only)
|
||||
pref("gfx.font_rendering.cleartype.use_for_downloadable_fonts", true);
|
||||
|
||||
// use cleartype rendering for all fonts always (win xp only)
|
||||
pref("gfx.font_rendering.cleartype.always_use_for_content", true);
|
||||
|
||||
pref("ui.key.menuAccessKeyFocuses", true);
|
||||
|
||||
// override double-click word selection behavior.
|
||||
|
Loading…
Reference in New Issue
Block a user