SkFontMgr.h revision 114cfbd10ec2d91aa60fcc60a795c45d5b8345ae
1/* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef SkFontMgr_DEFINED 9#define SkFontMgr_DEFINED 10 11#include "SkRefCnt.h" 12#include "SkFontStyle.h" 13 14class SkData; 15class SkStream; 16class SkString; 17class SkTypeface; 18 19class SK_API SkFontStyleSet : public SkRefCnt { 20public: 21 SK_DECLARE_INST_COUNT(SkFontStyleSet) 22 23 virtual int count() = 0; 24 virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; 25 virtual SkTypeface* createTypeface(int index) = 0; 26 virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0; 27 28 static SkFontStyleSet* CreateEmpty(); 29 30private: 31 typedef SkRefCnt INHERITED; 32}; 33 34class SK_API SkFontMgr : public SkRefCnt { 35public: 36 SK_DECLARE_INST_COUNT(SkFontMgr) 37 38 int countFamilies(); 39 void getFamilyName(int index, SkString* familyName); 40 SkFontStyleSet* createStyleSet(int index); 41 42 SkFontStyleSet* matchFamily(const char familyName[]); 43 44 /** 45 * Find the closest matching typeface to the specified familyName and style 46 * and return a ref to it. The caller must call unref() on the returned 47 * object. Will never return NULL, as it will return the default font if 48 * no matching font is found. 49 */ 50 SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&); 51 52 SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&); 53 54 /** 55 * Create a typeface for the specified data and TTC index (pass 0 for none) 56 * or NULL if the data is not recognized. The caller must call unref() on 57 * the returned object if it is not null. 58 */ 59 SkTypeface* createFromData(SkData*, int ttcIndex = 0); 60 61 /** 62 * Create a typeface for the specified stream and TTC index 63 * (pass 0 for none) or NULL if the stream is not recognized. The caller 64 * must call unref() on the returned object if it is not null. 65 */ 66 SkTypeface* createFromStream(SkStream*, int ttcIndex = 0); 67 68 /** 69 * Create a typeface for the specified fileName and TTC index 70 * (pass 0 for none) or NULL if the file is not found, or its contents are 71 * not recognized. The caller must call unref() on the returned object 72 * if it is not null. 73 */ 74 SkTypeface* createFromFile(const char path[], int ttcIndex = 0); 75 76 /** 77 * Return a ref to the default fontmgr. The caller must call unref() on 78 * the returned object. 79 */ 80 static SkFontMgr* RefDefault(); 81 82protected: 83 virtual int onCountFamilies() = 0; 84 virtual void onGetFamilyName(int index, SkString* familyName) = 0; 85 virtual SkFontStyleSet* onCreateStyleSet(int index) = 0; 86 87 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) = 0; 88 89 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], 90 const SkFontStyle&) = 0; 91 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, 92 const SkFontStyle&) = 0; 93 94 virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) = 0; 95 virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) = 0; 96 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) = 0; 97 98private: 99 static SkFontMgr* Factory(); // implemented by porting layer 100 101 typedef SkRefCnt INHERITED; 102}; 103 104#endif 105