michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkFontMgr_DEFINED michael@0: #define SkFontMgr_DEFINED michael@0: michael@0: #include "SkRefCnt.h" michael@0: #include "SkFontStyle.h" michael@0: michael@0: class SkData; michael@0: class SkStream; michael@0: class SkString; michael@0: class SkTypeface; michael@0: michael@0: class SK_API SkFontStyleSet : public SkRefCnt { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkFontStyleSet) michael@0: michael@0: virtual int count() = 0; michael@0: virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; michael@0: virtual SkTypeface* createTypeface(int index) = 0; michael@0: virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0; michael@0: michael@0: static SkFontStyleSet* CreateEmpty(); michael@0: michael@0: private: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: class SkTypeface; michael@0: michael@0: class SK_API SkFontMgr : public SkRefCnt { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkFontMgr) michael@0: michael@0: int countFamilies() const; michael@0: void getFamilyName(int index, SkString* familyName) const; michael@0: SkFontStyleSet* createStyleSet(int index) const; michael@0: michael@0: /** michael@0: * The caller must call unref() on the returned object. michael@0: * Never returns NULL; will return an empty set if the name is not found. michael@0: */ michael@0: SkFontStyleSet* matchFamily(const char familyName[]) const; michael@0: michael@0: /** michael@0: * Find the closest matching typeface to the specified familyName and style michael@0: * and return a ref to it. The caller must call unref() on the returned michael@0: * object. Will never return NULL, as it will return the default font if michael@0: * no matching font is found. michael@0: */ michael@0: SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const; michael@0: michael@0: SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&) const; michael@0: michael@0: /** michael@0: * Create a typeface for the specified data and TTC index (pass 0 for none) michael@0: * or NULL if the data is not recognized. The caller must call unref() on michael@0: * the returned object if it is not null. michael@0: */ michael@0: SkTypeface* createFromData(SkData*, int ttcIndex = 0) const; michael@0: michael@0: /** michael@0: * Create a typeface for the specified stream and TTC index michael@0: * (pass 0 for none) or NULL if the stream is not recognized. The caller michael@0: * must call unref() on the returned object if it is not null. michael@0: */ michael@0: SkTypeface* createFromStream(SkStream*, int ttcIndex = 0) const; michael@0: michael@0: /** michael@0: * Create a typeface for the specified fileName and TTC index michael@0: * (pass 0 for none) or NULL if the file is not found, or its contents are michael@0: * not recognized. The caller must call unref() on the returned object michael@0: * if it is not null. michael@0: */ michael@0: SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const; michael@0: michael@0: SkTypeface* legacyCreateTypeface(const char familyName[], michael@0: unsigned typefaceStyleBits) const; michael@0: michael@0: /** michael@0: * Return a ref to the default fontmgr. The caller must call unref() on michael@0: * the returned object. michael@0: */ michael@0: static SkFontMgr* RefDefault(); michael@0: michael@0: protected: michael@0: virtual int onCountFamilies() const = 0; michael@0: virtual void onGetFamilyName(int index, SkString* familyName) const = 0; michael@0: virtual SkFontStyleSet* onCreateStyleSet(int index)const = 0; michael@0: michael@0: /** May return NULL if the name is not found. */ michael@0: virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0; michael@0: michael@0: virtual SkTypeface* onMatchFamilyStyle(const char familyName[], michael@0: const SkFontStyle&) const = 0; michael@0: virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, michael@0: const SkFontStyle&) const = 0; michael@0: michael@0: virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0; michael@0: virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) const = 0; michael@0: virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0; michael@0: michael@0: virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], michael@0: unsigned styleBits) const = 0; michael@0: private: michael@0: static SkFontMgr* Factory(); // implemented by porting layer michael@0: friend void set_up_default(SkFontMgr** singleton); michael@0: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: #endif