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; |
bungeman | 5f213d9 | 2015-01-27 05:39:10 -0800 | [diff] [blame^] | 15 | class SkStreamAsset; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 16 | class SkString; |
reed@google.com | 0b98326 | 2013-04-11 18:27:26 +0000 | [diff] [blame] | 17 | class SkTypeface; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 18 | |
reed@google.com | aae71ba | 2013-04-10 13:10:40 +0000 | [diff] [blame] | 19 | class SK_API SkFontStyleSet : public SkRefCnt { |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 20 | public: |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 21 | SK_DECLARE_INST_COUNT(SkFontStyleSet) |
| 22 | |
reed@google.com | 83787c5 | 2013-03-26 17:19:15 +0000 | [diff] [blame] | 23 | virtual int count() = 0; |
| 24 | virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; |
| 25 | virtual SkTypeface* createTypeface(int index) = 0; |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 26 | virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0; |
| 27 | |
| 28 | static SkFontStyleSet* CreateEmpty(); |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 29 | |
| 30 | private: |
| 31 | typedef SkRefCnt INHERITED; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
reed@google.com | 30ddd61 | 2013-07-30 17:47:39 +0000 | [diff] [blame] | 34 | class SkTypeface; |
| 35 | |
reed@google.com | aae71ba | 2013-04-10 13:10:40 +0000 | [diff] [blame] | 36 | class SK_API SkFontMgr : public SkRefCnt { |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 37 | public: |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 38 | SK_DECLARE_INST_COUNT(SkFontMgr) |
| 39 | |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 40 | int countFamilies() const; |
| 41 | void getFamilyName(int index, SkString* familyName) const; |
| 42 | SkFontStyleSet* createStyleSet(int index) const; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 43 | |
bungeman@google.com | 9fc5c68 | 2013-11-12 15:25:29 +0000 | [diff] [blame] | 44 | /** |
| 45 | * The caller must call unref() on the returned object. |
| 46 | * Never returns NULL; will return an empty set if the name is not found. |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 47 | * |
| 48 | * It is possible that this will return a style set not accessible from |
| 49 | * createStyleSet(int) due to hidden or auto-activated fonts. |
bungeman@google.com | 9fc5c68 | 2013-11-12 15:25:29 +0000 | [diff] [blame] | 50 | */ |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 51 | SkFontStyleSet* matchFamily(const char familyName[]) const; |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 52 | |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 53 | /** |
| 54 | * Find the closest matching typeface to the specified familyName and style |
| 55 | * and return a ref to it. The caller must call unref() on the returned |
| 56 | * object. Will never return NULL, as it will return the default font if |
| 57 | * no matching font is found. |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 58 | * |
| 59 | * It is possible that this will return a style set not accessible from |
| 60 | * createStyleSet(int) or matchFamily(const char[]) due to hidden or |
| 61 | * auto-activated fonts. |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 62 | */ |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 63 | SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 64 | |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 65 | /** |
| 66 | * Use the system fallback to find a typeface for the given character. |
bungeman | c20386e | 2014-10-23 07:08:05 -0700 | [diff] [blame] | 67 | * Note that bcp47 is a combination of ISO 639, 15924, and 3166-1 codes, |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 68 | * so it is fine to just pass a ISO 639 here. |
| 69 | * |
| 70 | * Will return NULL if no family can be found for the character |
| 71 | * in the system fallback. |
bungeman | c20386e | 2014-10-23 07:08:05 -0700 | [diff] [blame] | 72 | * |
| 73 | * bcp47[0] is the least significant fallback, bcp47[bcp47Count-1] is the |
| 74 | * most significant. If no specified bcp47 codes match, any font with the |
| 75 | * requested character will be matched. |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 76 | */ |
| 77 | SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, |
bungeman | c20386e | 2014-10-23 07:08:05 -0700 | [diff] [blame] | 78 | const char* bcp47[], int bcp47Count, |
| 79 | SkUnichar character) const; |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 80 | |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 81 | SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&) const; |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 82 | |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 83 | /** |
| 84 | * Create a typeface for the specified data and TTC index (pass 0 for none) |
| 85 | * or NULL if the data is not recognized. The caller must call unref() on |
| 86 | * the returned object if it is not null. |
| 87 | */ |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 88 | SkTypeface* createFromData(SkData*, int ttcIndex = 0) const; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Create a typeface for the specified stream and TTC index |
| 92 | * (pass 0 for none) or NULL if the stream is not recognized. The caller |
| 93 | * must call unref() on the returned object if it is not null. |
| 94 | */ |
bungeman | 5f213d9 | 2015-01-27 05:39:10 -0800 | [diff] [blame^] | 95 | SkTypeface* createFromStream(SkStreamAsset*, int ttcIndex = 0) const; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Create a typeface for the specified fileName and TTC index |
| 99 | * (pass 0 for none) or NULL if the file is not found, or its contents are |
| 100 | * not recognized. The caller must call unref() on the returned object |
| 101 | * if it is not null. |
| 102 | */ |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 103 | SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 104 | |
reed@google.com | 30ddd61 | 2013-07-30 17:47:39 +0000 | [diff] [blame] | 105 | SkTypeface* legacyCreateTypeface(const char familyName[], |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 106 | unsigned typefaceStyleBits) const; |
reed@google.com | 30ddd61 | 2013-07-30 17:47:39 +0000 | [diff] [blame] | 107 | |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 108 | /** |
| 109 | * Return a ref to the default fontmgr. The caller must call unref() on |
| 110 | * the returned object. |
| 111 | */ |
| 112 | static SkFontMgr* RefDefault(); |
| 113 | |
| 114 | protected: |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 115 | virtual int onCountFamilies() const = 0; |
| 116 | virtual void onGetFamilyName(int index, SkString* familyName) const = 0; |
| 117 | virtual SkFontStyleSet* onCreateStyleSet(int index)const = 0; |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 118 | |
bungeman@google.com | 9fc5c68 | 2013-11-12 15:25:29 +0000 | [diff] [blame] | 119 | /** May return NULL if the name is not found. */ |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 120 | virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0; |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 121 | |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 122 | virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 123 | const SkFontStyle&) const = 0; |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 124 | virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, |
bungeman | c20386e | 2014-10-23 07:08:05 -0700 | [diff] [blame] | 125 | const char* bcp47[], int bcp47Count, |
djsollen | 33068c1 | 2014-11-14 10:52:53 -0800 | [diff] [blame] | 126 | SkUnichar character) const = 0; |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 127 | virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 128 | const SkFontStyle&) const = 0; |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 129 | |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 130 | virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0; |
bungeman | 5f213d9 | 2015-01-27 05:39:10 -0800 | [diff] [blame^] | 131 | virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0; |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 132 | virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0; |
bungeman@google.com | fb1663a | 2013-10-24 22:32:43 +0000 | [diff] [blame] | 133 | |
bungeman@google.com | fb1663a | 2013-10-24 22:32:43 +0000 | [diff] [blame] | 134 | virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
commit-bot@chromium.org | 967dee3 | 2014-02-04 22:35:01 +0000 | [diff] [blame] | 135 | unsigned styleBits) const = 0; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 136 | private: |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 137 | static SkFontMgr* Factory(); // implemented by porting layer |
mtklein | 148ec59 | 2014-10-13 13:17:56 -0700 | [diff] [blame] | 138 | friend SkFontMgr* sk_fontmgr_create_default(); |
skia.committer@gmail.com | e60ed08 | 2013-03-26 07:01:04 +0000 | [diff] [blame] | 139 | |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 140 | typedef SkRefCnt INHERITED; |
| 141 | }; |
| 142 | |
| 143 | #endif |