bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 SkRemotableFontMgr_DEFINED |
| 9 | #define SkRemotableFontMgr_DEFINED |
| 10 | |
| 11 | #include "SkFontStyle.h" |
| 12 | #include "SkRefCnt.h" |
| 13 | #include "SkTemplates.h" |
| 14 | |
| 15 | class SkDataTable; |
| 16 | class SkStreamAsset; |
| 17 | class SkString; |
| 18 | |
| 19 | struct SK_API SkFontIdentity { |
| 20 | static const uint32_t kInvalidDataId = 0xFFFFFFFF; |
| 21 | |
| 22 | // Note that fDataId is a data identifier, not a font identifier. |
| 23 | // (fDataID, fTtcIndex) can be seen as a font identifier. |
| 24 | uint32_t fDataId; |
| 25 | uint32_t fTtcIndex; |
| 26 | |
| 27 | // On Linux/FontConfig there is also the ability to specify preferences for rendering |
| 28 | // antialias, embedded bitmaps, autohint, hinting, hintstyle, lcd rendering |
| 29 | // may all be set or set to no-preference |
| 30 | // (No-preference is resolved against globals set by the platform) |
| 31 | // Since they may be selected against, these are really 'extensions' to SkFontStyle. |
| 32 | // SkFontStyle should pick these up. |
| 33 | SkFontStyle fFontStyle; |
| 34 | }; |
| 35 | |
| 36 | class SK_API SkRemotableFontIdentitySet : public SkRefCnt { |
| 37 | public: |
| 38 | SK_DECLARE_INST_COUNT(SkRemotableFontIdentitySet) |
| 39 | |
| 40 | SkRemotableFontIdentitySet(int count, SkFontIdentity** data); |
| 41 | |
| 42 | int count() const { return fCount; } |
| 43 | const SkFontIdentity& at(int index) const { return fData[index]; } |
| 44 | |
| 45 | static SkRemotableFontIdentitySet* NewEmpty(); |
| 46 | |
| 47 | private: |
| 48 | SkRemotableFontIdentitySet() : fCount(0), fData() { } |
mtklein | 148ec59 | 2014-10-13 13:17:56 -0700 | [diff] [blame] | 49 | |
| 50 | friend SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new(); |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 51 | |
| 52 | int fCount; |
| 53 | SkAutoTMalloc<SkFontIdentity> fData; |
| 54 | |
| 55 | typedef SkRefCnt INHERITED; |
| 56 | }; |
| 57 | |
| 58 | class SK_API SkRemotableFontMgr : public SkRefCnt { |
| 59 | public: |
| 60 | SK_DECLARE_INST_COUNT(SkRemotableFontMgr) |
| 61 | |
| 62 | /** |
| 63 | * Returns the names of the known fonts on the system. |
| 64 | * Will not return NULL, will return an empty table if no families exist. |
| 65 | * |
| 66 | * The indexes may be used with getIndex(int) and |
| 67 | * matchIndexStyle(int, SkFontStyle). |
| 68 | * |
| 69 | * The caller must unref() the returned object. |
| 70 | */ |
| 71 | virtual SkDataTable* getFamilyNames() const = 0; |
| 72 | |
| 73 | /** |
| 74 | * Returns all of the fonts with the given familyIndex. |
| 75 | * Returns NULL if the index is out of bounds. |
| 76 | * Returns empty if there are no fonts at the given index. |
| 77 | * |
| 78 | * The caller must unref() the returned object. |
| 79 | */ |
| 80 | virtual SkRemotableFontIdentitySet* getIndex(int familyIndex) const = 0; |
| 81 | |
| 82 | /** |
| 83 | * Returns the closest match to the given style in the given index. |
| 84 | * If there are no available fonts at the given index, the return value's |
| 85 | * data id will be kInvalidDataId. |
| 86 | */ |
| 87 | virtual SkFontIdentity matchIndexStyle(int familyIndex, const SkFontStyle&) const = 0; |
| 88 | |
| 89 | /** |
| 90 | * Returns all the fonts on the system with the given name. |
| 91 | * If the given name is NULL, will return the default font family. |
| 92 | * Never returns NULL; will return an empty set if the name is not found. |
| 93 | * |
| 94 | * It is possible that this will return fonts not accessible from |
| 95 | * getIndex(int) or matchIndexStyle(int, SkFontStyle) due to |
| 96 | * hidden or auto-activated fonts. |
| 97 | * |
| 98 | * The matching may be done in a system dependent way. The name may be |
| 99 | * matched case-insensitive, there may be system aliases which resolve, |
| 100 | * and names outside the current locale may be considered. However, this |
| 101 | * should only return fonts which are somehow associated with the requested |
| 102 | * name. |
| 103 | * |
| 104 | * The caller must unref() the returned object. |
| 105 | */ |
| 106 | virtual SkRemotableFontIdentitySet* matchName(const char familyName[]) const = 0; |
| 107 | |
| 108 | /** |
| 109 | * Returns the closest matching font to the specified name and style. |
| 110 | * If there are no available fonts which match the name, the return value's |
| 111 | * data id will be kInvalidDataId. |
| 112 | * If the given name is NULL, the match will be against any default fonts. |
| 113 | * |
| 114 | * It is possible that this will return a font identity not accessible from |
| 115 | * methods returning sets due to hidden or auto-activated fonts. |
| 116 | * |
| 117 | * The matching may be done in a system dependent way. The name may be |
| 118 | * matched case-insensitive, there may be system aliases which resolve, |
| 119 | * and names outside the current locale may be considered. However, this |
| 120 | * should only return a font which is somehow associated with the requested |
| 121 | * name. |
| 122 | * |
| 123 | * The caller must unref() the returned object. |
| 124 | */ |
| 125 | virtual SkFontIdentity matchNameStyle(const char familyName[], const SkFontStyle&) const = 0; |
| 126 | |
| 127 | /** |
| 128 | * Use the system fall-back to find a font for the given character. |
| 129 | * If no font can be found for the character, the return value's data id |
| 130 | * will be kInvalidDataId. |
| 131 | * If the name is NULL, the match will start against any default fonts. |
| 132 | * If the bpc47 is NULL, a default locale will be assumed. |
| 133 | * |
| 134 | * Note that bpc47 is a combination of ISO 639, 15924, and 3166-1 codes, |
| 135 | * so it is fine to just pass a ISO 639 here. |
| 136 | */ |
| 137 | virtual SkFontIdentity matchNameStyleCharacter(const char familyName[], const SkFontStyle&, |
bungeman | c20386e | 2014-10-23 07:08:05 -0700 | [diff] [blame] | 138 | const char* bcp47[], int bcp47Count, |
| 139 | SkUnichar character) const=0; |
bungeman@google.com | 72cf4fc | 2014-03-21 22:48:32 +0000 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * Returns the data for the given data id. |
| 143 | * Will return NULL if the data id is invalid. |
| 144 | * Note that this is a data id, not a font id. |
| 145 | * |
| 146 | * The caller must unref() the returned object. |
| 147 | */ |
| 148 | virtual SkStreamAsset* getData(int dataId) const = 0; |
| 149 | |
| 150 | private: |
| 151 | typedef SkRefCnt INHERITED; |
| 152 | }; |
| 153 | |
| 154 | #endif |