Friday, November 20, 2009

fixed and smoothed my fonts in Firefox on Windows XP

I use Windows Vista at work, and although I'm about to upgrade to Windows 7 (yay!!!) I wasn't sure how to smooth the fonts in Firefox given screenshots of a website in Firefox 3.5.5 and IE 8. The client pointed out that the fonts looked better in IE than in Firefox. What?! This never happens! So with a little searching, I discovered that Firefox displays fonts based on the user's operating system settings. There's a display setting called ClearType that you can get to from desktop Properties -> Appearance -> Effects. In Windows XP, the default is Standard, not ClearType. In Windows Vista (and I assume Windows 7) the default is ClearType.

How to make font render smoothly in firefox just like safari and IE7

How to evaluate and change Windows font smoothing or ClearType

(although I'm sure this is condemned as browser hijack)

[DllImport("user32.dll", SetLastError = true)]
static extern bool
SystemParametersInfo(uint uiAction, uint uiParam,
ref int pvParam, uint fWinIni);

/* Constants used for User32 calls. */
const uint SPI_GETFONTSMOOTHING = 74;
const uint SPI_SETFONTSMOOTHING = 75;
const unit SPI_UPDATEINI = 0x1;

private Boolean GetFontSmoothing()
{
bool iResult;
int pv = 0;
/* Call to systemparametersinfo
to get the font smoothing value. */
iResult =
SystemParametersInfo(SPI_GETFONTSMOOTHING, 0,
ref pv, 0);
if (pv > 0)
{
//pv > 0 means font smoothing is on.
return true;
}
else
{
//pv == 0 means font smoothing is off.
return false;
}
}

private void DisableFontSmoothing()
{
bool iResult;
int pv = 0;
/* Call to systemparametersinfo
to set the font smoothing value. */
iResult =
SystemParametersInfo(SPI_SETFONTSMOOTHING, 0,
ref pv, SPIF_UPDATEINIFILE);
}

private void EnableFontSmoothing()
{
bool iResult;
int pv = 0;
/* Call to systemparametersinfo
to set the font smoothing value. */
iResult =
SystemParametersInfo(SPI_SETFONTSMOOTHING, 1,
ref pv, SPIF_UPDATEINIFILE);
}


More on ClearType:
Microsoft Typography
Microsoft ClearType FAQ
Technical Overview of ClearType Filtering