Index: src/core/SkTypeface.cpp |
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp |
index cc60ca1809189b95667ee843b7b8f1dcebad6998..ba58c4c4244741495124374398ac0a4ad69847cf 100644 |
--- a/src/core/SkTypeface.cpp |
+++ b/src/core/SkTypeface.cpp |
@@ -37,21 +37,26 @@ SkTypeface::~SkTypeface() { |
/////////////////////////////////////////////////////////////////////////////// |
-SkTypeface* SkTypeface::GetDefaultTypeface() { |
+SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { |
// we keep a reference to this guy for all time, since if we return its |
// fontID, the font cache may later on ask to resolve that back into a |
// typeface object. |
- static SkTypeface* gDefaultTypeface; |
+ static const uint32_t FONT_STYLE_COUNT = 4; |
+ static SkTypeface* gDefaultTypefaces[FONT_STYLE_COUNT]; |
+ SkASSERT((unsigned)style < FONT_STYLE_COUNT); |
- if (NULL == gDefaultTypeface) { |
- gDefaultTypeface = |
- SkFontHost::CreateTypeface(NULL, NULL, SkTypeface::kNormal); |
+ // mask off any other bits to avoid a crash in SK_RELEASE |
+ style = (Style)(style & 0x03); |
+ |
+ if (NULL == gDefaultTypefaces[style]) { |
+ gDefaultTypefaces[style] = |
+ SkFontHost::CreateTypeface(NULL, NULL, style); |
} |
- return gDefaultTypeface; |
+ return gDefaultTypefaces[style]; |
} |
-SkTypeface* SkTypeface::RefDefault() { |
- return SkRef(GetDefaultTypeface()); |
+SkTypeface* SkTypeface::RefDefault(Style style) { |
+ return SkRef(GetDefaultTypeface(style)); |
} |
uint32_t SkTypeface::UniqueID(const SkTypeface* face) { |
@@ -68,6 +73,9 @@ bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { |
/////////////////////////////////////////////////////////////////////////////// |
SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { |
+ if (NULL == name) { |
+ return RefDefault(style); |
+ } |
return SkFontHost::CreateTypeface(NULL, name, style); |
} |