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

Unified Diff: src/core/SkTypeface.cpp

Issue 16439004: Fix issues related to resolving fonts based on name. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: defer cache change to another CLwq Created 7 years, 6 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 | « include/core/SkTypeface.h ('k') | src/ports/SkFontHost_fontconfig.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « include/core/SkTypeface.h ('k') | src/ports/SkFontHost_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698