Chromium Code Reviews| Index: src/ports/SkFontHost_win.cpp |
| diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp |
| index 0874e3b9c376e463274dd7dce7d89deded3728cb..06d56aaa2e053f844563c203bf0ecc6e985e7d36 100755 |
| --- a/src/ports/SkFontHost_win.cpp |
| +++ b/src/ports/SkFontHost_win.cpp |
| @@ -508,6 +508,10 @@ public: |
| SkScalerContext_Windows(SkTypeface*, const SkDescriptor* desc); |
| virtual ~SkScalerContext_Windows(); |
| + // Returns true if the constructor was able to complete all of its |
| + // initializations (which may include calling GDI). |
| + bool isValid() const; |
| + |
| protected: |
| virtual unsigned generateGlyphCount() SK_OVERRIDE; |
| virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; |
| @@ -583,6 +587,10 @@ SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface, |
| LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface); |
| fDDC = ::CreateCompatibleDC(NULL); |
| + if (!fDDC) { |
| + return; |
| + } |
| + |
| SetGraphicsMode(fDDC, GM_ADVANCED); |
| SetBkMode(fDDC, TRANSPARENT); |
| @@ -592,6 +600,9 @@ SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface, |
| lf.lfHeight = -gCanonicalTextSize; |
| lf.lfQuality = compute_quality(fRec); |
| fFont = CreateFontIndirect(&lf); |
| + if (!fFont) { |
| + return; |
| + } |
| // if we're rotated, or want fractional widths, create a hires font |
| fHiResFont = 0; |
| @@ -702,6 +713,10 @@ SkScalerContext_Windows::~SkScalerContext_Windows() { |
| } |
| } |
| +bool SkScalerContext_Windows::isValid() const { |
| + return fDDC && fFont; |
| +} |
| + |
| unsigned SkScalerContext_Windows::generateGlyphCount() { |
| if (fGlyphCount < 0) { |
| if (fType == SkScalerContext_Windows::kBitmap_Type) { |
| @@ -1665,7 +1680,13 @@ SkStream* LogFontTypeface::onOpenStream(int* ttcIndex) const { |
| } |
| SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc) const { |
| - return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(this), desc)); |
| + SkScalerContext_Windows* ctx = SkNEW_ARGS(SkScalerContext_Windows, |
|
bungeman-skia
2013/07/09 22:45:37
It may be easier to understand the intent with som
reed1
2013/07/10 13:59:04
Probably a matter of taste, as I find the current
|
| + (const_cast<LogFontTypeface*>(this), desc)); |
| + if (!ctx->isValid()) { |
| + SkDELETE(ctx); |
| + ctx = NULL; |
| + } |
| + return ctx; |
| } |
| /** Return the closest matching typeface given either an existing family |