diff options
author | bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-13 03:21:53 +0000 |
---|---|---|
committer | bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-13 03:21:53 +0000 |
commit | 62566f361f44bfaefcef69c2a6635aabdc44361b (patch) | |
tree | 4fa8d8349d0d13b5cbcdf6283aff4a59121bac8c /src | |
parent | f57c01bdcfdf1c923b9a473974bfe6f8c66eca3e (diff) |
Change FreeType lcd filter to provide better results.
https://codereview.appspot.com/6652046/
Will require rebaselines on systems using lcd smoothed FreeType.
git-svn-id: http://skia.googlecode.com/svn/trunk@5944 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/ports/SkFontHost_FreeType.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index ce8f409731..dc7666e723 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -86,6 +86,8 @@ static bool gLCDSupportValid; // true iff |gLCDSupport| has been set. static bool gLCDSupport; // true iff LCD is supported by the runtime. static int gLCDExtra; // number of extra pixels for filtering. +///////////////////////////////////////////////////////////////////////// + // FT_Library_SetLcdFilterWeights was introduced in FreeType 2.4.0. // The following platforms provide FreeType of at least 2.4.0. // Ubuntu >= 11.04 (previous deprecated April 2013) @@ -95,8 +97,6 @@ static int gLCDExtra; // number of extra pixels for filtering. // Android >= Gingerbread (good) typedef FT_Error (*FT_Library_SetLcdFilterWeightsProc)(FT_Library, unsigned char*); -///////////////////////////////////////////////////////////////////////// - // Caller must lock gFTMutex before calling this function. static bool InitFreetype() { FT_Error err = FT_Init_FreeType(&gFTLibrary); @@ -106,18 +106,20 @@ static bool InitFreetype() { // Setup LCD filtering. This reduces color fringes for LCD smoothed glyphs. #ifdef FT_LCD_FILTER_H - //Use light as default, as FT_LCD_FILTER_DEFAULT adds up to 0x110. - err = FT_Library_SetLcdFilter(gFTLibrary, FT_LCD_FILTER_LIGHT); + // Use default { 0x10, 0x40, 0x70, 0x40, 0x10 }, as it adds up to 0x110, simulating ink spread. + // SetLcdFilter must be called before SetLcdFilterWeights. + err = FT_Library_SetLcdFilter(gFTLibrary, FT_LCD_FILTER_DEFAULT); if (0 == err) { gLCDSupport = true; gLCDExtra = 2; //Using a filter adds one full pixel to each side. - static unsigned char gaussianLikeWeights[] = { 0x17, 0x40, 0x52, 0x40, 0x17 }; - //static unsigned char triangleLikeWeights[] = { 0x1C, 0x39, 0x56, 0x39, 0x1C }; +#ifdef SK_FONTHOST_FREETYPE_USE_NORMAL_LCD_FILTER + // This also adds to 0x110 simulating ink spread, but provides better results than default. + static unsigned char gGaussianLikeHeavyWeights[] = { 0x1A, 0x43, 0x56, 0x43, 0x1A, }; #if defined(SK_FONTHOST_FREETYPE_RUNTIME_VERSION) && \ SK_FONTHOST_FREETYPE_RUNTIME_VERSION > 0x020400 - err = FT_Library_SetLcdFilterWeights(gFTLibrary, gaussianLikeWeights); + err = FT_Library_SetLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeights); #elif defined(SK_CAN_USE_DLOPEN) && SK_CAN_USE_DLOPEN == 1 //The FreeType library is already loaded, so symbols are available in process. void* self = dlopen(NULL, RTLD_LAZY); @@ -128,10 +130,11 @@ static bool InitFreetype() { dlclose(self); if (NULL != setLcdFilterWeights) { - err = setLcdFilterWeights(gFTLibrary, gaussianLikeWeights); + err = setLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeights); } } #endif +#endif } #else gLCDSupport = false; |