Index: src/ports/SkFontHost_fontconfig.cpp |
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp |
index a5aef56f1c9099fe4690acd8e478a3e668ccd3ce..12ff90683fdbf06b0ce624c8170844305b54ebbf 100644 |
--- a/src/ports/SkFontHost_fontconfig.cpp |
+++ b/src/ports/SkFontHost_fontconfig.cpp |
@@ -72,6 +72,12 @@ static bool find_proc(SkTypeface* face, SkTypeface::Style style, void* ctx) { |
return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName); |
} |
+static bool find_proc_by_id(SkTypeface* face, SkTypeface::Style style, void* ctx) { |
+ const uint32_t* fontID = (const uint32_t*)ctx; |
+ uint32_t currFontID = ((FontConfigTypeface*)face)->getIdentity().fID; |
+ return currFontID == *fontID; |
+} |
+ |
SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, |
const char familyName[], |
SkTypeface::Style style) { |
@@ -92,16 +98,21 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, |
return face; |
} |
- SkFontConfigInterface::FontIdentity indentity; |
+ SkFontConfigInterface::FontIdentity identity; |
SkString outFamilyName; |
SkTypeface::Style outStyle; |
if (!fci->matchFamilyName(familyName, style, |
- &indentity, &outFamilyName, &outStyle)) { |
+ &identity, &outFamilyName, &outStyle)) { |
return NULL; |
} |
- face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName)); |
+ face = SkTypefaceCache::FindByProcAndRef(find_proc_by_id, &identity.fID); |
reed1
2013/06/05 13:23:57
this may be correct, but is it strictly needed for
djsollen
2013/06/05 13:51:59
No this is still needed. If an app asks for a font
|
+ if (face) { |
+ return face; |
+ } |
+ |
+ face = SkNEW_ARGS(FontConfigTypeface, (outStyle, identity, outFamilyName)); |
SkTypefaceCache::Add(face, style); |
// SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str(), face, face->getRefCnt()); |
return face; |
@@ -122,7 +133,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; |
} |