aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-07 19:34:16 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-07 19:34:16 +0000
commitc4df655b37aea7097d3007b299de582ba517ef16 (patch)
tree502b830dfac1a6e4b2f1d2bcba50c6d7a68ffa27 /src
parent2b4e370a2fe00168838e43f5a78ccc3b371609f5 (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')
-rw-r--r--src/core/SkTypeface.cpp9
-rw-r--r--src/fonts/SkFontMgr_fontconfig.cpp2
-rw-r--r--src/ports/SkFontConfigTypeface.h34
-rw-r--r--src/ports/SkFontHost_fontconfig.cpp2
4 files changed, 31 insertions, 16 deletions
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index d15caeb86f..cd3953ba98 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -37,8 +37,12 @@ SkTypeface::~SkTypeface() {
class SkEmptyTypeface : public SkTypeface {
public:
- SkEmptyTypeface() : SkTypeface(SkTypeface::kNormal, 0, true) { }
+ static SkEmptyTypeface* Create() {
+ return SkNEW(SkEmptyTypeface);
+ }
protected:
+ SkEmptyTypeface() : SkTypeface(SkTypeface::kNormal, 0, true) { }
+
virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { return NULL; }
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE {
return NULL;
@@ -85,7 +89,8 @@ void SkTypeface::create_default_typeface(Style style) {
gDefaultTypefaces[style] = SkFontHost::CreateTypeface(NULL, NULL, style);
}
if (NULL == gDefaultTypefaces[style]) {
- gDefaultTypefaces[style] = SkNEW(SkEmptyTypeface);
+ // FIXME: Use a singleton for SkEmptyTypeface.
+ gDefaultTypefaces[style] = SkEmptyTypeface::Create();
}
}
diff --git a/src/fonts/SkFontMgr_fontconfig.cpp b/src/fonts/SkFontMgr_fontconfig.cpp
index 1d17111b79..226da963d7 100644
--- a/src/fonts/SkFontMgr_fontconfig.cpp
+++ b/src/fonts/SkFontMgr_fontconfig.cpp
@@ -311,7 +311,7 @@ protected:
return NULL;
}
- SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, isFixedWidth, stream));
+ SkTypeface* face = FontConfigTypeface::Create(style, isFixedWidth, stream);
return face;
}
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;