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

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: 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
Index: src/core/SkTypeface.cpp
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index cc60ca1809189b95667ee843b7b8f1dcebad6998..361f5a99436677ebe57e4ae7d5819a21ea87df9c 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -37,21 +37,23 @@ 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 int FONT_STYLE_COUNT = 4;
+ static SkTypeface* gDefaultTypefaces[FONT_STYLE_COUNT] = {0};
reed1 2013/06/05 13:23:57 nit: don't need {0} as it will automatically be ze
djsollen 2013/06/05 13:51:59 Done.
+ SkASSERT(FONT_STYLE_COUNT > style);
reed1 2013/06/05 13:23:57 nit: I think I always see this compare the other w
djsollen 2013/06/05 13:51:59 Done.
- if (NULL == gDefaultTypeface) {
- gDefaultTypeface =
- SkFontHost::CreateTypeface(NULL, NULL, SkTypeface::kNormal);
+ 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 +70,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);
}

Powered by Google App Engine
This is Rietveld 408576698