From b80255700ee01bd4bcb93006281c610f3e5c719d Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Fri, 24 Jun 2011 18:24:59 +0000 Subject: [PATCH] fix null fFontRef in GetDefaultFont() http://codereview.appspot.com/4662041/ git-svn-id: http://skia.googlecode.com/svn/trunk@1709 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/ports/SkFontHost_mac_coretext.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ports/SkFontHost_mac_coretext.cpp b/src/ports/SkFontHost_mac_coretext.cpp index fd8e2845a9..a48c3650b3 100644 --- a/src/ports/SkFontHost_mac_coretext.cpp +++ b/src/ports/SkFontHost_mac_coretext.cpp @@ -75,8 +75,13 @@ static SkTypeface::Style computeStyleBits(CTFontRef font, bool* isMonospace) { class SkTypeface_Mac : public SkTypeface { public: - SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isMonospace) - : SkTypeface(style, fontID, isMonospace), fFontRef(0) {} + SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isMonospace, + CTFontRef fontRef, const char name[]) + : SkTypeface(style, fontID, isMonospace) { + SkASSERT(fontRef); + fFontRef = fontRef; // we take over ownership + fName.set(name); + } virtual ~SkTypeface_Mac() { CFRelease(fFontRef); } @@ -85,14 +90,11 @@ public: }; static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { + SkASSERT(fontRef); bool isMonospace; SkTypeface::Style style = computeStyleBits(fontRef, &isMonospace); - SkTypeface_Mac* face = new SkTypeface_Mac(style, - SkTypefaceCache::NewFontID(), - isMonospace); - face->fFontRef = fontRef; // we take over ownership of fontRef - face->fName.set(name); - return face; + return new SkTypeface_Mac(style, SkTypefaceCache::NewFontID(), + isMonospace, fontRef, name); } static SkTypeface* NewFromName(const char familyName[], @@ -156,8 +158,7 @@ static SkTypeface* GetDefaultFace() { static SkTypeface* gDefaultFace; if (NULL == gDefaultFace) { - gDefaultFace = new SkTypeface_Mac(SkTypeface::kNormal, - SkTypefaceCache::NewFontID(), false); + gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkTypeface::kNormal); } return gDefaultFace; }