static bool find_by_FontIdentity(SkTypeface* cachedTypeface, const SkFontStyle&, void* ctx) { typedef SkFontConfigInterface::FontIdentity FontIdentity; FontConfigTypeface* cachedFCTypeface = static_cast<FontConfigTypeface*>(cachedTypeface); FontIdentity* indentity = static_cast<FontIdentity*>(ctx); return cachedFCTypeface->getIdentity() == *indentity; }
SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char familyName[], SkTypeface::Style style) { SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); if (NULL == fci.get()) { return NULL; } if (familyFace) { FontConfigTypeface* fct = (FontConfigTypeface*)familyFace; familyName = fct->getFamilyName(); } FindRec rec(familyName, style); SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); if (face) { // SkDebugf("found cached face <%s> <%s> %p [%d]\n", familyName, ((FontConfigTypeface*)face)->getFamilyName(), face, face->getRefCnt()); return face; } SkFontConfigInterface::FontIdentity indentity; SkString outFamilyName; SkTypeface::Style outStyle; if (!fci->matchFamilyName(familyName, style, &indentity, &outFamilyName, &outStyle)) { return NULL; } face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName)); SkTypefaceCache::Add(face, style); // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str(), face, face->getRefCnt()); return face; }
static bool find_by_NameStyle(SkTypeface* cachedTypeface, const SkFontStyle& cachedStyle, void* ctx) { FontConfigTypeface* cachedFCTypeface = static_cast<FontConfigTypeface*>(cachedTypeface); const NameStyle* nameStyle = static_cast<const NameStyle*>(ctx); return nameStyle->fStyle == cachedStyle && cachedFCTypeface->isFamilyName(nameStyle->fFamilyName); }
SkTypeface* FontConfigTypeface::LegacyCreateTypeface( const SkTypeface* familyFace, const char familyName[], SkTypeface::Style style) { SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); if (NULL == fci.get()) { return NULL; } if (familyFace) { FontConfigTypeface* fct = (FontConfigTypeface*)familyFace; familyName = fct->getFamilyName(); } FindRec rec(familyName, style); SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); if (face) { // SkDebugf("found cached face <%s> <%s> %p [%d]\n", familyName, ((FontConfigTypeface*)face)->getFamilyName(), face, face->getRefCnt()); return face; } SkFontConfigInterface::FontIdentity indentity; SkString outFamilyName; SkTypeface::Style outStyle; if (!fci->matchFamilyName(familyName, style, &indentity, &outFamilyName, &outStyle)) { return NULL; } // check if we, in fact, already have this. perhaps fontconfig aliased the // requested name to some other name we actually have... rec.fFamilyName = outFamilyName.c_str(); rec.fStyle = outStyle; face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); if (face) { return face; } face = FontConfigTypeface::Create(outStyle, indentity, outFamilyName); SkTypefaceCache::Add(face, style); // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str(), face, face->getRefCnt()); return face; }
static bool find_proc(SkTypeface* face, SkTypeface::Style style, void* ctx) { FontConfigTypeface* fci = (FontConfigTypeface*)face; const FindRec* rec = (const FindRec*)ctx; return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName); }