Index: src/ports/SkFontHost_win.cpp |
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp |
index 0874e3b9c376e463274dd7dce7d89deded3728cb..eb55748069145b6ab3df9f627a4794399789ba53 100755 |
--- a/src/ports/SkFontHost_win.cpp |
+++ b/src/ports/SkFontHost_win.cpp |
@@ -505,7 +505,8 @@ const void* HDCOffscreen::draw(const SkGlyph& glyph, bool isBW, |
class SkScalerContext_Windows : public SkScalerContext { |
public: |
- SkScalerContext_Windows(SkTypeface*, const SkDescriptor* desc); |
+ // we take ownership of the HDC |
+ SkScalerContext_Windows(SkTypeface*, const SkDescriptor* desc, HDC); |
virtual ~SkScalerContext_Windows(); |
protected: |
@@ -572,17 +573,18 @@ static BYTE compute_quality(const SkScalerContext::Rec& rec) { |
} |
SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface, |
- const SkDescriptor* desc) |
+ const SkDescriptor* desc, |
+ HDC ddc) |
: SkScalerContext(rawTypeface, desc) |
- , fDDC(0) |
+ , fDDC(ddc) |
, fFont(0) |
, fSavefont(0) |
, fSC(0) |
, fGlyphCount(-1) |
{ |
+ SkASSERT(fDDC); |
LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface); |
- fDDC = ::CreateCompatibleDC(NULL); |
SetGraphicsMode(fDDC, GM_ADVANCED); |
SetBkMode(fDDC, TRANSPARENT); |
@@ -687,10 +689,9 @@ SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface, |
} |
SkScalerContext_Windows::~SkScalerContext_Windows() { |
- if (fDDC) { |
- ::SelectObject(fDDC, fSavefont); |
- ::DeleteDC(fDDC); |
- } |
+ ::SelectObject(fDDC, fSavefont); |
+ ::DeleteDC(fDDC); |
+ |
if (fFont) { |
::DeleteObject(fFont); |
} |
@@ -1665,7 +1666,11 @@ SkStream* LogFontTypeface::onOpenStream(int* ttcIndex) const { |
} |
SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc) const { |
- return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(this), desc)); |
+ HDC hdc = ::CreateCompatibleDC(NULL); |
+ if (!hdc) { |
+ return NULL; |
+ } |
+ return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(this), desc, hdc)); |
} |
/** Return the closest matching typeface given either an existing family |