reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 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 | |
| 14 | class SkData; |
| 15 | class SkStream; |
| 16 | class SkString; |
| 17 | |
| 18 | class SkFontStyleSet : public SkRefCnt { |
| 19 | public: |
reed@google.com | 83787c5 | 2013-03-26 17:19:15 +0000 | [diff] [blame^] | 20 | virtual int count() = 0; |
| 21 | virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; |
| 22 | virtual SkTypeface* createTypeface(int index) = 0; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 23 | }; |
| 24 | |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 25 | class SkFontMgr : public SkRefCnt { |
| 26 | public: |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 27 | int countFamilies(); |
| 28 | void getFamilyName(int index, SkString* familyName); |
| 29 | SkFontStyleSet* createStyleSet(int index); |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Find the closest matching typeface to the specified familyName and style |
| 33 | * and return a ref to it. The caller must call unref() on the returned |
| 34 | * object. Will never return NULL, as it will return the default font if |
| 35 | * no matching font is found. |
| 36 | */ |
| 37 | SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&); |
| 38 | |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 39 | SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&); |
| 40 | |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Create a typeface for the specified data and TTC index (pass 0 for none) |
| 43 | * or NULL if the data is not recognized. The caller must call unref() on |
| 44 | * the returned object if it is not null. |
| 45 | */ |
| 46 | SkTypeface* createFromData(SkData*, int ttcIndex = 0); |
| 47 | |
| 48 | /** |
| 49 | * Create a typeface for the specified stream and TTC index |
| 50 | * (pass 0 for none) or NULL if the stream is not recognized. The caller |
| 51 | * must call unref() on the returned object if it is not null. |
| 52 | */ |
| 53 | SkTypeface* createFromStream(SkStream*, int ttcIndex = 0); |
| 54 | |
| 55 | /** |
| 56 | * Create a typeface for the specified fileName and TTC index |
| 57 | * (pass 0 for none) or NULL if the file is not found, or its contents are |
| 58 | * not recognized. The caller must call unref() on the returned object |
| 59 | * if it is not null. |
| 60 | */ |
| 61 | SkTypeface* createFromFile(const char path[], int ttcIndex = 0); |
| 62 | |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 63 | /** |
| 64 | * Return a ref to the default fontmgr. The caller must call unref() on |
| 65 | * the returned object. |
| 66 | */ |
| 67 | static SkFontMgr* RefDefault(); |
| 68 | |
| 69 | protected: |
| 70 | virtual int onCountFamilies() = 0; |
| 71 | virtual void onGetFamilyName(int index, SkString* familyName) = 0; |
| 72 | virtual SkFontStyleSet* onCreateStyleSet(int index) = 0; |
| 73 | |
| 74 | virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
| 75 | const SkFontStyle&) = 0; |
| 76 | virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, |
| 77 | const SkFontStyle&) = 0; |
| 78 | |
| 79 | virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) = 0; |
| 80 | virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) = 0; |
| 81 | virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) = 0; |
skia.committer@gmail.com | e60ed08 | 2013-03-26 07:01:04 +0000 | [diff] [blame] | 82 | |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 83 | private: |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 84 | static SkFontMgr* Factory(); // implemented by porting layer |
| 85 | static SkMutex* Mutex(); // implemented by porting layer |
skia.committer@gmail.com | e60ed08 | 2013-03-26 07:01:04 +0000 | [diff] [blame] | 86 | |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 87 | typedef SkRefCnt INHERITED; |
| 88 | }; |
| 89 | |
| 90 | #endif |