From 95625dbcb6b2960732bc27ad0dd0fc4adbb4f7c0 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Mon, 25 Mar 2013 20:44:02 +0000 Subject: [PATCH] check-point (early) for fontmgr stuff, not called. git-svn-id: http://skia.googlecode.com/svn/trunk@8377 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/ports/SkFontMgr.h | 41 +++++++++++++++-------- include/ports/SkFontStyle.h | 4 +-- src/ports/SkFontHost_mac.cpp | 64 ++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 15 deletions(-) diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h index b3d38138b8..8f1c4a6eeb 100644 --- a/include/ports/SkFontMgr.h +++ b/include/ports/SkFontMgr.h @@ -22,21 +22,11 @@ public: SkTypeface* createTypeface(int index) const; }; -class SkFontFamilySet : public SkRefCnt { -public: - int count() const; - void getName(int index, SkString* familyName) const; - SkFontStyleSet* refStyleSet(int index) const; -}; - class SkFontMgr : public SkRefCnt { public: - /** - * Return a fontfamily set, which can iterate all of the font families - * available to this fontmgr. The caller is responsible for calling unref() - * on the returned object. Will never return NULL. - */ - SkFontFamilySet* createFamilySet(); + int countFamilies(); + void getFamilyName(int index, SkString* familyName); + SkFontStyleSet* createStyleSet(int index); /** * Find the closest matching typeface to the specified familyName and style @@ -46,6 +36,8 @@ public: */ SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&); + SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&); + /** * Create a typeface for the specified data and TTC index (pass 0 for none) * or NULL if the data is not recognized. The caller must call unref() on @@ -68,7 +60,30 @@ public: */ SkTypeface* createFromFile(const char path[], int ttcIndex = 0); + /** + * Return a ref to the default fontmgr. The caller must call unref() on + * the returned object. + */ + static SkFontMgr* RefDefault(); + +protected: + virtual int onCountFamilies() = 0; + virtual void onGetFamilyName(int index, SkString* familyName) = 0; + virtual SkFontStyleSet* onCreateStyleSet(int index) = 0; + + virtual SkTypeface* onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) = 0; + virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, + const SkFontStyle&) = 0; + + virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) = 0; + virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) = 0; + virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) = 0; + private: + static SkFontMgr* Factory(); // implemented by porting layer + static SkMutex* Mutex(); // implemented by porting layer + typedef SkRefCnt INHERITED; }; diff --git a/include/ports/SkFontStyle.h b/include/ports/SkFontStyle.h index f145a6ee74..1279024b2e 100644 --- a/include/ports/SkFontStyle.h +++ b/include/ports/SkFontStyle.h @@ -5,8 +5,8 @@ * found in the LICENSE file. */ -#ifndef SkFontMgr_DEFINED -#define SkFontMgr_DEFINED +#ifndef SkFontStyle_DEFINED +#define SkFontStyle_DEFINED #include "SkTypes.h" diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 1f13748231..8999e8c972 100755 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -1832,3 +1832,67 @@ void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, *isLocalStream = false; } +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +#if 1 +#include "SkFontMgr.h" + +class SkFontMgr_Mac : public SkFontMgr { +public: + SkFontMgr_Mac() {} + +protected: + virtual int onCountFamilies() SK_OVERRIDE { + return 0; + } + + virtual void onGetFamilyName(int index, SkString* familyName) SK_OVERRIDE { + } + + virtual SkFontStyleSet* onCreateStyleSet(int index) SK_OVERRIDE { + return NULL; + } + + virtual SkTypeface* onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) SK_OVERRIDE { + return NULL; + } + + virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, + const SkFontStyle&) SK_OVERRIDE { + return NULL; + } + + virtual SkTypeface* onCreateFromData(SkData* data, + int ttcIndex) SK_OVERRIDE { + AutoCFRelease pr(SkCreateDataProviderFromData(data)); + if (NULL == pr) { + return NULL; + } + return create_from_dataProvider(pr); + } + + virtual SkTypeface* onCreateFromStream(SkStream* stream, + int ttcIndex) SK_OVERRIDE { + AutoCFRelease pr(SkCreateDataProviderFromStream(stream)); + if (NULL == pr) { + return NULL; + } + return create_from_dataProvider(pr); + } + + virtual SkTypeface* onCreateFromFile(const char path[], + int ttcIndex) SK_OVERRIDE { + AutoCFRelease pr(CGDataProviderCreateWithFilename(path)); + if (NULL == pr) { + return NULL; + } + return create_from_dataProvider(pr); + } +}; + +SkFontMgr* SkFontMgr::Factory() { + return SkNEW(SkFontMgr_Mac); +} +#endif