From 7fdcd444a1bd6a2f173c141e09e7ad9c11730ad2 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Tue, 30 Jul 2013 21:25:49 +0000 Subject: [PATCH] support SK_FONTHOST_USES_FONTMGR on mac BUG= Review URL: https://codereview.chromium.org/21142004 git-svn-id: http://skia.googlecode.com/svn/trunk@10445 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/fonts/SkGScalerContext.cpp | 9 +++++ src/fonts/SkGScalerContext.h | 1 + src/ports/SkFontHost_mac.cpp | 68 ++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkGScalerContext.cpp index ab0dce5687..882c70b121 100644 --- a/src/fonts/SkGScalerContext.cpp +++ b/src/fonts/SkGScalerContext.cpp @@ -211,6 +211,15 @@ size_t SkGTypeface::onGetTableData(SkFontTableTag tag, size_t offset, return fProxy->getTableData(tag, offset, length, data); } +SkTypeface* SkGTypeface::onRefMatchingStyle(Style style) const { + if (this->style() == style) { + return const_cast(SkRef(this)); + } + + SkAutoTUnref other(fProxy->refMatchingStyle(style)); + return SkNEW_ARGS(SkGTypeface, (other, fPaint)); +} + /////////////////////////////////////////////////////////////////////////////// #if 0 diff --git a/src/fonts/SkGScalerContext.h b/src/fonts/SkGScalerContext.h index b238b0b0a2..1aa1df369e 100644 --- a/src/fonts/SkGScalerContext.h +++ b/src/fonts/SkGScalerContext.h @@ -35,6 +35,7 @@ protected: virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const SK_OVERRIDE; + virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; private: SkTypeface* fProxy; diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index ef51aef018..52a3fd6930 100755 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -465,6 +465,7 @@ protected: virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], int glyphCount) const SK_OVERRIDE; virtual int onCountGlyphs() const SK_OVERRIDE; + virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; private: @@ -597,27 +598,27 @@ static const char* map_css_names(const char* name) { return name; // no change } -SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, - const char familyName[], - SkTypeface::Style style) { +static SkTypeface* create_typeface(const SkTypeface* familyFace, + const char familyName[], + SkTypeface::Style style) { if (familyName) { familyName = map_css_names(familyName); } - + // Clone an existing typeface // TODO: only clone if style matches the familyFace's style... if (familyName == NULL && familyFace != NULL) { familyFace->ref(); return const_cast(familyFace); } - + if (!familyName || !*familyName) { familyName = FONT_DEFAULT_NAME; } - + NameStyleRec rec = { familyName, style }; SkTypeface* face = SkTypefaceCache::FindByProcAndRef(FindByNameStyle, &rec); - + if (NULL == face) { face = NewFromName(familyName, style); if (face) { @@ -630,6 +631,10 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, return face; } +SkTypeface* SkTypeface_Mac::onRefMatchingStyle(Style styleBits) const { + return create_typeface(this, NULL, styleBits); +} + /////////////////////////////////////////////////////////////////////////////// /** GlyphRect is in FUnits (em space, y up). */ @@ -1437,22 +1442,6 @@ static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { return cg ? SkCreateTypefaceFromCTFont(ct) : NULL; } -SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { - AutoCFRelease provider(SkCreateDataProviderFromStream(stream)); - if (NULL == provider) { - return NULL; - } - return create_from_dataProvider(provider); -} - -SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { - AutoCFRelease provider(CGDataProviderCreateWithFilename(path)); - if (NULL == provider) { - return NULL; - } - return create_from_dataProvider(provider); -} - // Web fonts added to the the CTFont registry do not return their character set. // Iterate through the font in this case. The existing caller caches the result, // so the performance impact isn't too bad. @@ -2258,8 +2247,41 @@ protected: } return create_from_dataProvider(pr); } + + virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], + unsigned styleBits) SK_OVERRIDE { + return create_typeface(NULL, familyName, (SkTypeface::Style)styleBits); + } }; +/////////////////////////////////////////////////////////////////////////////// + +#ifndef SK_FONTHOST_USES_FONTMGR + +SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, + const char familyName[], + SkTypeface::Style style) { + return create_typeface(familyFace, familyName, style); +} + +SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { + AutoCFRelease provider(SkCreateDataProviderFromStream(stream)); + if (NULL == provider) { + return NULL; + } + return create_from_dataProvider(provider); +} + +SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { + AutoCFRelease provider(CGDataProviderCreateWithFilename(path)); + if (NULL == provider) { + return NULL; + } + return create_from_dataProvider(provider); +} + +#endif + SkFontMgr* SkFontMgr::Factory() { return SkNEW(SkFontMgr_Mac); } -- 2.34.1