Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Unified Diff: src/ports/SkFontHost_win.cpp

Issue 18484005: allow createScalerContext to return null, and then have the GDI backend trigger that if we fail to … (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkScalerContext.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_win.cpp
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 0874e3b9c376e463274dd7dce7d89deded3728cb..f05e47dad88fa965be6ccbf4b08006069eceb498 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;
@@ -525,10 +529,10 @@ private:
HDC fDDC;
HFONT fSavefont;
HFONT fFont;
+ HFONT fHiResFont;
SCRIPT_CACHE fSC;
int fGlyphCount;
- HFONT fHiResFont;
MAT2 fMat22Identity;
SkMatrix fHiResMatrix;
enum Type {
@@ -575,14 +579,19 @@ SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface,
const SkDescriptor* desc)
: SkScalerContext(rawTypeface, desc)
, fDDC(0)
- , fFont(0)
, fSavefont(0)
+ , fFont(0)
+ , fHiResFont(0)
, fSC(0)
, fGlyphCount(-1)
{
LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface);
fDDC = ::CreateCompatibleDC(NULL);
+ if (!fDDC) {
+ return;
+ }
+
SetGraphicsMode(fDDC, GM_ADVANCED);
SetBkMode(fDDC, TRANSPARENT);
@@ -592,12 +601,17 @@ 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;
if (needHiResMetrics(fRec.fPost2x2)) {
lf.lfHeight = -HIRES_TEXTSIZE;
fHiResFont = CreateFontIndirect(&lf);
+ if (!fHiResFont) {
+ return;
+ }
fMat22Identity.eM11 = fMat22Identity.eM22 = SkFixedToFIXED(SK_Fixed1);
fMat22Identity.eM12 = fMat22Identity.eM21 = SkFixedToFIXED(0);
@@ -702,6 +716,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 +1683,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,
+ (const_cast<LogFontTypeface*>(this), desc));
+ if (!ctx->isValid()) {
+ SkDELETE(ctx);
+ ctx = NULL;
+ }
+ return ctx;
}
/** Return the closest matching typeface given either an existing family
« no previous file with comments | « src/core/SkScalerContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698