add more scalerrec filtering, in prep for handling unhinted

git-svn-id: http://skia.googlecode.com/svn/trunk@1847 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-07-13 15:25:33 +00:00
Родитель 30b74fc1d3
Коммит e8fab0111d
1 изменённых файлов: 46 добавлений и 52 удалений

Просмотреть файл

@ -15,8 +15,6 @@
*/ */
#include "SkString.h" #include "SkString.h"
//#include "SkStream.h"
#include "SkEndian.h" #include "SkEndian.h"
#include "SkFontHost.h" #include "SkFontHost.h"
#include "SkDescriptor.h" #include "SkDescriptor.h"
@ -134,23 +132,6 @@ public:
static const LOGFONT& get_default_font() { static const LOGFONT& get_default_font() {
static LOGFONT gDefaultFont; 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; return gDefaultFont;
} }
@ -599,45 +580,37 @@ void SkScalerContext_Windows::generateImage(const SkGlyph& glyph) {
uint32_t bytecount = 0; uint32_t bytecount = 0;
uint32_t total_size = GetGlyphOutlineW(fDDC, glyph.fID, GGO_GRAY8_BITMAP | GGO_GLYPH_INDEX, &gm, 0, NULL, &fMat22); 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) { if (GDI_ERROR != total_size && total_size > 0) {
uint8_t *pBuff = new uint8_t[total_size]; SkAutoSMalloc<1024> storage(total_size);
if (NULL != pBuff) { uint8_t *pBuff = (uint8_t*)storage.get();
total_size = GetGlyphOutlineW(fDDC, glyph.fID, GGO_GRAY8_BITMAP | GGO_GLYPH_INDEX, &gm, total_size, pBuff, &fMat22); 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);
SkASSERT(total_size != GDI_ERROR); 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!?
}
SkASSERT(glyph.fWidth == gm.gmBlackBoxX); for (int32_t y = gm.gmBlackBoxY - 1; y >= 0; y--) {
SkASSERT(glyph.fHeight == gm.gmBlackBoxY); const uint8_t* src = pBuff + pitch * y;
uint8_t* dst = (uint8_t*)glyph.fImage; for (uint32_t x = 0; x < gm.gmBlackBoxX; x++) {
uint32_t pitch = (gm.gmBlackBoxX + 3) & ~0x3; if (*src > 63) {
if (pitch != glyph.rowBytes()) { *dst = 0xFF;
SkASSERT(false); // glyph.fImage has different rowsize!? } else {
} *dst = *src << 2; // scale to 0-255
for (int32_t y = gm.gmBlackBoxY - 1; y >= 0; y--) {
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++;
} }
memset(dst, 0, glyph.rowBytes() - glyph.fWidth); dst++;
dst += glyph.rowBytes() - glyph.fWidth; src++;
bytecount++;
} }
memset(dst, 0, glyph.rowBytes() - glyph.fWidth);
delete[] pBuff; dst += glyph.rowBytes() - glyph.fWidth;
} }
} }
SkASSERT(GDI_ERROR != total_size && total_size >= 0); SkASSERT(GDI_ERROR != total_size && total_size >= 0);
} }
void SkScalerContext_Windows::generatePath(const SkGlyph& glyph, SkPath* path) { 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) { void SkFontHost::FilterRec(SkScalerContext::Rec* rec) {
// We don't control the hinting nor ClearType settings here unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag |
rec->setHinting(SkPaint::kNormal_Hinting); 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 #endif // WIN32