From e8fab0111d11316a027bc6ae60c62cc6575cdc05 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 13 Jul 2011 15:25:33 +0000 Subject: [PATCH] add more scalerrec filtering, in prep for handling unhinted git-svn-id: http://skia.googlecode.com/svn/trunk@1847 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/ports/SkFontHost_win.cpp | 100 ++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 53 deletions(-) diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 5971dee..0610085 100755 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -15,8 +15,6 @@ */ #include "SkString.h" -//#include "SkStream.h" - #include "SkEndian.h" #include "SkFontHost.h" #include "SkDescriptor.h" @@ -134,23 +132,6 @@ public: static const LOGFONT& get_default_font() { static LOGFONT gDefaultFont; - // don't hardcode on Windows, Win2000, XP, Vista, and international all have different default - // and the user could change too - - -// lfMessageFont is garbage on my XP, so skip for now -#if 0 - if (gDefaultFont.lfFaceName[0] != 0) { - return gDefaultFont; - } - - NONCLIENTMETRICS ncm; - ncm.cbSize = sizeof(NONCLIENTMETRICS); - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0); - - //memcpy(&gDefaultFont, &(ncm.lfMessageFont), sizeof(LOGFONT)); -#endif - return gDefaultFont; } @@ -599,45 +580,37 @@ void SkScalerContext_Windows::generateImage(const SkGlyph& glyph) { uint32_t bytecount = 0; uint32_t total_size = GetGlyphOutlineW(fDDC, glyph.fID, GGO_GRAY8_BITMAP | GGO_GLYPH_INDEX, &gm, 0, NULL, &fMat22); if (GDI_ERROR != total_size && total_size > 0) { - uint8_t *pBuff = new uint8_t[total_size]; - if (NULL != pBuff) { - total_size = GetGlyphOutlineW(fDDC, glyph.fID, GGO_GRAY8_BITMAP | GGO_GLYPH_INDEX, &gm, total_size, pBuff, &fMat22); - - SkASSERT(total_size != GDI_ERROR); - - SkASSERT(glyph.fWidth == gm.gmBlackBoxX); - SkASSERT(glyph.fHeight == gm.gmBlackBoxY); - - uint8_t* dst = (uint8_t*)glyph.fImage; - uint32_t pitch = (gm.gmBlackBoxX + 3) & ~0x3; - if (pitch != glyph.rowBytes()) { - SkASSERT(false); // glyph.fImage has different rowsize!? - } + SkAutoSMalloc<1024> storage(total_size); + uint8_t *pBuff = (uint8_t*)storage.get(); + total_size = GetGlyphOutlineW(fDDC, glyph.fID, GGO_GRAY8_BITMAP | GGO_GLYPH_INDEX, &gm, total_size, pBuff, &fMat22); + SkASSERT(total_size != GDI_ERROR); + SkASSERT(glyph.fWidth == gm.gmBlackBoxX); + SkASSERT(glyph.fHeight == gm.gmBlackBoxY); + + uint8_t* dst = (uint8_t*)glyph.fImage; + uint32_t pitch = (gm.gmBlackBoxX + 3) & ~0x3; + if (pitch != glyph.rowBytes()) { + SkASSERT(false); // glyph.fImage has different rowsize!? + } - for (int32_t y = gm.gmBlackBoxY - 1; y >= 0; y--) { - uint8_t* src = pBuff + pitch * y; + for (int32_t y = gm.gmBlackBoxY - 1; y >= 0; y--) { + const uint8_t* src = pBuff + pitch * y; - for (uint32_t x = 0; x < gm.gmBlackBoxX; x++) { - if (*src > 63) { - *dst = 0xFF; - } - else { - *dst = *src << 2; // scale to 0-255 - } - dst++; - src++; - bytecount++; + for (uint32_t x = 0; x < gm.gmBlackBoxX; x++) { + if (*src > 63) { + *dst = 0xFF; + } else { + *dst = *src << 2; // scale to 0-255 } - memset(dst, 0, glyph.rowBytes() - glyph.fWidth); - dst += glyph.rowBytes() - glyph.fWidth; + dst++; + src++; + bytecount++; } - - delete[] pBuff; + memset(dst, 0, glyph.rowBytes() - glyph.fWidth); + dst += glyph.rowBytes() - glyph.fWidth; } } - SkASSERT(GDI_ERROR != total_size && total_size >= 0); - } void SkScalerContext_Windows::generatePath(const SkGlyph& glyph, SkPath* path) { @@ -967,8 +940,29 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { } void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { - // We don't control the hinting nor ClearType settings here - rec->setHinting(SkPaint::kNormal_Hinting); + unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | + SkScalerContext::kAutohinting_Flag | + SkScalerContext::kEmbeddedBitmapText_Flag | + SkScalerContext::kEmbolden_Flag | + SkScalerContext::kLCD_BGROrder_Flag | + SkScalerContext::kLCD_Vertical_Flag; + rec->fFlags &= ~flagsWeDontSupport; + + // we only support binary hinting: normal or none + SkPaint::Hinting h = rec->getHinting(); + switch (h) { + case SkPaint::kNo_Hinting: + case SkPaint::kSlight_Hinting: + h = SkPaint::kNo_Hinting; + break; + case SkPaint::kNormal_Hinting: + case SkPaint::kFull_Hinting: + h = SkPaint::kNormal_Hinting; + break; + default: + SkASSERT(!"unknown hinting"); + } + rec->setHinting(h); } #endif // WIN32 -- 2.7.4