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:
parent
8f6ef4010f
commit
4fa748d580
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user