diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-07 19:34:16 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-07 19:34:16 +0000 |
commit | c4df655b37aea7097d3007b299de582ba517ef16 (patch) | |
tree | 502b830dfac1a6e4b2f1d2bcba50c6d7a68ffa27 /src/ports | |
parent | 2b4e370a2fe00168838e43f5a78ccc3b371609f5 (diff) |
Factory methods for heap-allocated SkTypeface objects.
This is part of an effort to ensure that all SkPaint effects can only be
allocated on the heap.
This patch makes the constructors of SkTypeface and its subclasses non-public
and instead provides factory methods for creating these objects on the heap.
BUG=skia:2187
R=scroggo@google.com, bungeman@google.com
Author: dominikg@chromium.org
Review URL: https://codereview.chromium.org/227693003
git-svn-id: http://skia.googlecode.com/svn/trunk@14080 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/ports')
-rw-r--r-- | src/ports/SkFontConfigTypeface.h | 34 | ||||
-rw-r--r-- | src/ports/SkFontHost_fontconfig.cpp | 2 |
2 files changed, 23 insertions, 13 deletions
diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h index dc92f1dffb..b6f8797eb7 100644 --- a/src/ports/SkFontConfigTypeface.h +++ b/src/ports/SkFontConfigTypeface.h @@ -18,19 +18,14 @@ class FontConfigTypeface : public SkTypeface_FreeType { SkStream* fLocalStream; public: - FontConfigTypeface(Style style, - const SkFontConfigInterface::FontIdentity& fi, - const SkString& familyName) - : INHERITED(style, SkTypefaceCache::NewFontID(), false) - , fIdentity(fi) - , fFamilyName(familyName) - , fLocalStream(NULL) {} + static FontConfigTypeface* Create(Style style, + const SkFontConfigInterface::FontIdentity& fi, + const SkString& familyName) { + return SkNEW_ARGS(FontConfigTypeface, (style, fi, familyName)); + } - FontConfigTypeface(Style style, bool fixedWidth, SkStream* localStream) - : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) { - // we default to empty fFamilyName and fIdentity - fLocalStream = localStream; - SkSafeRef(localStream); + static FontConfigTypeface* Create(Style style, bool fixedWidth, SkStream* localStream) { + return SkNEW_ARGS(FontConfigTypeface, (style, fixedWidth, localStream)); } virtual ~FontConfigTypeface() { @@ -55,6 +50,21 @@ public: protected: friend class SkFontHost; // hack until we can make public versions + FontConfigTypeface(Style style, + const SkFontConfigInterface::FontIdentity& fi, + const SkString& familyName) + : INHERITED(style, SkTypefaceCache::NewFontID(), false) + , fIdentity(fi) + , fFamilyName(familyName) + , fLocalStream(NULL) {} + + FontConfigTypeface(Style style, bool fixedWidth, SkStream* localStream) + : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) { + // we default to empty fFamilyName and fIdentity + fLocalStream = localStream; + SkSafeRef(localStream); + } + virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE; virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp index 3700ed1e97..07bfbd044c 100644 --- a/src/ports/SkFontHost_fontconfig.cpp +++ b/src/ports/SkFontHost_fontconfig.cpp @@ -118,7 +118,7 @@ SkTypeface* FontConfigTypeface::LegacyCreateTypeface( return face; } - face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName)); + face = FontConfigTypeface::Create(outStyle, indentity, outFamilyName); SkTypefaceCache::Add(face, style); // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str(), face, face->getRefCnt()); return face; |