diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h index 86fcac0451..737b2eb4c4 100644 --- a/include/core/SkFontHost.h +++ b/include/core/SkFontHost.h @@ -167,8 +167,10 @@ public: the same output. A lazy (but valid) fonthost can do nothing in its FilterRec routine. + + The provided typeface corresponds to the fFontID field. */ - static void FilterRec(SkScalerContextRec* rec); + static void FilterRec(SkScalerContextRec* rec, SkTypeface* typeface); /////////////////////////////////////////////////////////////////////////// diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index 78ec9f7cb6..7fb6b810d0 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -189,6 +189,9 @@ protected: SkTypeface(Style style, SkFontID uniqueID, bool isFixedWidth = false); virtual ~SkTypeface(); + friend class SkScalerContext; + static SkTypeface* GetDefaultTypeface(); + private: SkFontID fUniqueID; Style fStyle; diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 58a8c1c407..c517663945 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1505,7 +1505,11 @@ void SkScalerContext::MakeRec(const SkPaint& paint, const SkMatrix* deviceMatrix, Rec* rec) { SkASSERT(deviceMatrix == NULL || !deviceMatrix->hasPerspective()); - rec->fOrigFontID = SkTypeface::UniqueID(paint.getTypeface()); + SkTypeface* typeface = paint.getTypeface(); + if (NULL == typeface) { + typeface = SkTypeface::GetDefaultTypeface(); + } + rec->fOrigFontID = typeface->uniqueID(); rec->fFontID = rec->fOrigFontID; rec->fTextSize = paint.getTextSize(); rec->fPreScaleX = paint.getTextScaleX(); @@ -1622,7 +1626,7 @@ void SkScalerContext::MakeRec(const SkPaint& paint, they can modify our rec up front, so we don't create duplicate cache entries. */ - SkFontHost::FilterRec(rec); + SkFontHost::FilterRec(rec, typeface); // be sure to call PostMakeRec(rec) before you actually use it! } diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 3a40e0130b..94bb237b84 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -36,7 +36,7 @@ SkTypeface::~SkTypeface() { /////////////////////////////////////////////////////////////////////////////// -static SkTypeface* get_default_typeface() { +SkTypeface* SkTypeface::GetDefaultTypeface() { // we keep a reference to this guy for all time, since if we return its // fontID, the font cache may later on ask to resolve that back into a // typeface object. @@ -51,7 +51,7 @@ static SkTypeface* get_default_typeface() { uint32_t SkTypeface::UniqueID(const SkTypeface* face) { if (NULL == face) { - face = get_default_typeface(); + face = GetDefaultTypeface(); } return face->uniqueID(); } diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index 5d351331cf..ce8f409731 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -637,7 +637,7 @@ static bool isAxisAligned(const SkScalerContext::Rec& rec) { bothZero(rec.fPost2x2[0][0], rec.fPost2x2[1][1])); } -void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { +void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) { //BOGUS: http://code.google.com/p/chromium/issues/detail?id=121119 //Cap the requested size as larger sizes give bogus values. //Remove when http://code.google.com/p/skia/issues/detail?id=554 is fixed. diff --git a/src/ports/SkFontHost_mac_atsui.cpp b/src/ports/SkFontHost_mac_atsui.cpp index f8251ab0bb..84f7f0b224 100644 --- a/src/ports/SkFontHost_mac_atsui.cpp +++ b/src/ports/SkFontHost_mac_atsui.cpp @@ -97,7 +97,7 @@ private: static OSStatus Close(void *cb); }; -void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { +void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) { // we only support 2 levels of hinting SkPaint::Hinting h = rec->getHinting(); if (SkPaint::kSlight_Hinting == h) { diff --git a/src/ports/SkFontHost_mac_coretext.cpp b/src/ports/SkFontHost_mac_coretext.cpp index 622b8ede1f..e385337388 100644 --- a/src/ports/SkFontHost_mac_coretext.cpp +++ b/src/ports/SkFontHost_mac_coretext.cpp @@ -1811,7 +1811,7 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) { return nextFontID; } -void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { +void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) { unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | SkScalerContext::kAutohinting_Flag; diff --git a/src/ports/SkFontHost_none.cpp b/src/ports/SkFontHost_none.cpp index a68391915c..21eda8e1b8 100644 --- a/src/ports/SkFontHost_none.cpp +++ b/src/ports/SkFontHost_none.cpp @@ -37,7 +37,7 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics( return NULL; } -void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { +void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) { } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 015df7835b..f2603e99a8 100755 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -210,11 +210,39 @@ static unsigned calculateOutlineGlyphCount(HDC hdc) { class LogFontTypeface : public SkTypeface { public: - LogFontTypeface(SkTypeface::Style style, SkFontID fontID, const LOGFONT& lf) : - SkTypeface(style, fontID, false), fLogFont(lf), fSerializeAsStream(false) {} + LogFontTypeface(SkTypeface::Style style, SkFontID fontID, const LOGFONT& lf, bool serializeAsStream = false) : + SkTypeface(style, fontID, false), fLogFont(lf), fSerializeAsStream(serializeAsStream) { + + // If the font has cubic outlines, it will not be rendered with ClearType. + HFONT font = CreateFontIndirect(&lf); + + HDC deviceContext = ::CreateCompatibleDC(NULL); + HFONT savefont = (HFONT)SelectObject(deviceContext, font); + + TEXTMETRIC textMetric; + if (0 == GetTextMetrics(deviceContext, &textMetric)) { + SkFontHost::EnsureTypefaceAccessible(*this); + if (0 == GetTextMetrics(deviceContext, &textMetric)) { + textMetric.tmPitchAndFamily = TMPF_TRUETYPE; + } + } + if (deviceContext) { + ::SelectObject(deviceContext, savefont); + ::DeleteDC(deviceContext); + } + if (font) { + ::DeleteObject(font); + } + + // Used a logfont on a memory context, should never get a device font. + // Therefore all TMPF_DEVICE will be PostScript (cubic) fonts. + fCanBeLCD = !((textMetric.tmPitchAndFamily & TMPF_VECTOR) && + (textMetric.tmPitchAndFamily & TMPF_DEVICE)); + } LOGFONT fLogFont; bool fSerializeAsStream; + bool fCanBeLCD; static LogFontTypeface* Create(const LOGFONT& lf) { SkTypeface::Style style = get_style(lf); @@ -229,8 +257,7 @@ public: * Takes ownership of fontMemResource. */ FontMemResourceTypeface(SkTypeface::Style style, SkFontID fontID, const LOGFONT& lf, HANDLE fontMemResource) : - LogFontTypeface(style, fontID, lf), fFontMemResource(fontMemResource) { - fSerializeAsStream = true; + LogFontTypeface(style, fontID, lf, true), fFontMemResource(fontMemResource) { } HANDLE fFontMemResource; @@ -1673,7 +1700,7 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { return face; } -void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { +void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface* typeface) { unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | SkScalerContext::kAutohinting_Flag | SkScalerContext::kEmbeddedBitmapText_Flag | @@ -1713,9 +1740,9 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { } #endif -#if 0 - if (SkMask::kLCD16_Format == rec->fMaskFormat) { - rec->fMaskFormat = SkMask::kLCD32_Format; + LogFontTypeface* logfontTypeface = static_cast(typeface); + if (!logfontTypeface->fCanBeLCD && isLCD(*rec)) { + rec->fMaskFormat = SkMask::kA8_Format; + rec->fFlags &= ~SkScalerContext::kGenA8FromLCD_Flag; } -#endif } diff --git a/src/ports/SkFontHost_win_dw.cpp b/src/ports/SkFontHost_win_dw.cpp index d91cfa9b02..82d44eeb33 100644 --- a/src/ports/SkFontHost_win_dw.cpp +++ b/src/ports/SkFontHost_win_dw.cpp @@ -1264,7 +1264,7 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { return NULL; } -void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { +void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) { unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | SkScalerContext::kAutohinting_Flag | SkScalerContext::kEmbeddedBitmapText_Flag | diff --git a/src/utils/ios/SkFontHost_iOS.mm b/src/utils/ios/SkFontHost_iOS.mm index b74b29f1f8..60f111c84e 100755 --- a/src/utils/ios/SkFontHost_iOS.mm +++ b/src/utils/ios/SkFontHost_iOS.mm @@ -253,7 +253,7 @@ SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics( return NULL; } -void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { +void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface*) { } SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) {