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
*/
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
*/
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;
};
*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<CGDataProviderRef> pr(SkCreateDataProviderFromData(data));
+ if (NULL == pr) {
+ return NULL;
+ }
+ return create_from_dataProvider(pr);
+ }
+
+ virtual SkTypeface* onCreateFromStream(SkStream* stream,
+ int ttcIndex) SK_OVERRIDE {
+ AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromStream(stream));
+ if (NULL == pr) {
+ return NULL;
+ }
+ return create_from_dataProvider(pr);
+ }
+
+ virtual SkTypeface* onCreateFromFile(const char path[],
+ int ttcIndex) SK_OVERRIDE {
+ AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(path));
+ if (NULL == pr) {
+ return NULL;
+ }
+ return create_from_dataProvider(pr);
+ }
+};
+
+SkFontMgr* SkFontMgr::Factory() {
+ return SkNEW(SkFontMgr_Mac);
+}
+#endif