aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-05 14:20:25 +0000
committerGravatar djsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-05 14:20:25 +0000
commit4fa748d5801df66e46e6f4e98e07523d44d261a2 (patch)
treea4de9f397c7526b6e964de5ee195c24f23d47552
parent8f6ef4010f6835c5ce9ede180e50a6a58512a81e (diff)
Fix issues related to resolving fonts based on name.
1) non-system font files are not added to the cache. 2) We cache the default fonts for quick lookup. Review URL: https://codereview.chromium.org/16439004 git-svn-id: http://skia.googlecode.com/svn/trunk@9441 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkTypeface.h4
-rw-r--r--src/core/SkTypeface.cpp24
-rw-r--r--src/ports/SkFontHost_fontconfig.cpp1
3 files changed, 18 insertions, 11 deletions
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index a314e0fffb..d34854d329 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -85,7 +85,7 @@ public:
* Returns a ref() to the default typeface. The caller must call unref()
* when they are done referencing the object. Never returns NULL.
*/
- static SkTypeface* RefDefault();
+ static SkTypeface* RefDefault(Style style = SkTypeface::kNormal);
/** Return a new reference to the typeface that most closely matches the
requested familyName and style. Pass null as the familyName to return
@@ -222,7 +222,7 @@ protected:
void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; }
friend class SkScalerContext;
- static SkTypeface* GetDefaultTypeface();
+ static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal);
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0;
virtual void onFilterRec(SkScalerContextRec*) const = 0;
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index cc60ca1809..ba58c4c424 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);
}
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp
index a5aef56f1c..1cd2dd9035 100644
--- a/src/ports/SkFontHost_fontconfig.cpp
+++ b/src/ports/SkFontHost_fontconfig.cpp
@@ -122,7 +122,6 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
// TODO should the caller give us the style?
SkTypeface::Style style = SkTypeface::kNormal;
SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, stream));
- SkTypefaceCache::Add(face, style);
return face;
}