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
This commit is contained in:
djsollen@google.com 2013-06-05 14:20:25 +00:00
Родитель 8f6ef4010f
Коммит 4fa748d580
3 изменённых файлов: 18 добавлений и 11 удалений

Просмотреть файл

@ -85,7 +85,7 @@ public:
* Returns a ref() to the default typeface. The caller must call unref() * Returns a ref() to the default typeface. The caller must call unref()
* when they are done referencing the object. Never returns NULL. * 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 /** Return a new reference to the typeface that most closely matches the
requested familyName and style. Pass null as the familyName to return requested familyName and style. Pass null as the familyName to return
@ -222,7 +222,7 @@ protected:
void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; } void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; }
friend class SkScalerContext; friend class SkScalerContext;
static SkTypeface* GetDefaultTypeface(); static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal);
virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0; virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0;
virtual void onFilterRec(SkScalerContextRec*) const = 0; virtual void onFilterRec(SkScalerContextRec*) const = 0;

Просмотреть файл

@ -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 // 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 // fontID, the font cache may later on ask to resolve that back into a
// typeface object. // 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) { // mask off any other bits to avoid a crash in SK_RELEASE
gDefaultTypeface = style = (Style)(style & 0x03);
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() { SkTypeface* SkTypeface::RefDefault(Style style) {
return SkRef(GetDefaultTypeface()); return SkRef(GetDefaultTypeface(style));
} }
uint32_t SkTypeface::UniqueID(const SkTypeface* face) { 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) { SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
if (NULL == name) {
return RefDefault(style);
}
return SkFontHost::CreateTypeface(NULL, name, style); return SkFontHost::CreateTypeface(NULL, name, style);
} }

Просмотреть файл

@ -122,7 +122,6 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
// TODO should the caller give us the style? // TODO should the caller give us the style?
SkTypeface::Style style = SkTypeface::kNormal; SkTypeface::Style style = SkTypeface::kNormal;
SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, stream)); SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, stream));
SkTypefaceCache::Add(face, style);
return face; return face;
} }