OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkFontMgr_DEFINED | 8 #ifndef SkFontMgr_DEFINED |
9 #define SkFontMgr_DEFINED | 9 #define SkFontMgr_DEFINED |
10 | 10 |
| 11 #include "SkFontStyle.h" |
11 #include "SkRefCnt.h" | 12 #include "SkRefCnt.h" |
12 #include "SkFontStyle.h" | 13 #include "SkScalar.h" |
| 14 #include "SkTypes.h" |
13 | 15 |
14 class SkData; | 16 class SkData; |
15 class SkFontData; | 17 class SkFontData; |
16 class SkStreamAsset; | 18 class SkStreamAsset; |
17 class SkString; | 19 class SkString; |
18 class SkTypeface; | 20 class SkTypeface; |
19 | 21 |
20 class SK_API SkFontStyleSet : public SkRefCnt { | 22 class SK_API SkFontStyleSet : public SkRefCnt { |
21 public: | 23 public: |
22 virtual int count() = 0; | 24 virtual int count() = 0; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 */ | 95 */ |
94 SkTypeface* createFromData(SkData*, int ttcIndex = 0) const; | 96 SkTypeface* createFromData(SkData*, int ttcIndex = 0) const; |
95 | 97 |
96 /** | 98 /** |
97 * Create a typeface for the specified stream and TTC index | 99 * Create a typeface for the specified stream and TTC index |
98 * (pass 0 for none) or NULL if the stream is not recognized. The caller | 100 * (pass 0 for none) or NULL if the stream is not recognized. The caller |
99 * must call unref() on the returned object if it is not null. | 101 * must call unref() on the returned object if it is not null. |
100 */ | 102 */ |
101 SkTypeface* createFromStream(SkStreamAsset*, int ttcIndex = 0) const; | 103 SkTypeface* createFromStream(SkStreamAsset*, int ttcIndex = 0) const; |
102 | 104 |
| 105 struct FontParameters { |
| 106 struct Axis { |
| 107 SkFourByteTag fTag; |
| 108 SkScalar fStyleValue; |
| 109 }; |
| 110 |
| 111 FontParameters() : fCollectionIndex(0), fAxisCount(0), fAxes(nullptr) {} |
| 112 |
| 113 /** Specify the index of the desired font. |
| 114 * |
| 115 * Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may ac
tually be indexed |
| 116 * collections of fonts. |
| 117 */ |
| 118 FontParameters& setCollectionIndex(int collectionIndex) { |
| 119 fCollectionIndex = collectionIndex; |
| 120 return *this; |
| 121 } |
| 122 |
| 123 /** Specify the GX variation axis values. |
| 124 * |
| 125 * Any axes not specified will use the default value. Specified axes no
t present in the |
| 126 * font will be ignored. |
| 127 * |
| 128 * @param axes not copied. This pointer must remain valid for life of F
ontParameters. |
| 129 */ |
| 130 FontParameters& setAxes(const Axis* axes, int axisCount) { |
| 131 fAxisCount = axisCount; |
| 132 fAxes = axes; |
| 133 return *this; |
| 134 } |
| 135 |
| 136 int getCollectionIndex() const { |
| 137 return fCollectionIndex; |
| 138 } |
| 139 const Axis* getAxes(int* axisCount) const { |
| 140 *axisCount = fAxisCount; |
| 141 return fAxes; |
| 142 } |
| 143 private: |
| 144 int fCollectionIndex; |
| 145 int fAxisCount; |
| 146 const Axis* fAxes; |
| 147 }; |
| 148 /* Experimental, API subject to change. */ |
| 149 SkTypeface* createFromStream(SkStreamAsset*, const FontParameters&) const; |
| 150 |
103 /** | 151 /** |
104 * Create a typeface from the specified font data. | 152 * Create a typeface from the specified font data. |
105 * Takes ownership of the font data, so the caller should not reference it
again. | 153 * Takes ownership of the font data, so the caller should not reference it
again. |
106 * Will return NULL if the typeface could not be created. | 154 * Will return NULL if the typeface could not be created. |
107 * The caller must call unref() on the returned object if it is not null. | 155 * The caller must call unref() on the returned object if it is not null. |
108 */ | 156 */ |
109 SkTypeface* createFromFontData(SkFontData*) const; | 157 SkTypeface* createFromFontData(SkFontData*) const; |
110 | 158 |
111 /** | 159 /** |
112 * Create a typeface for the specified fileName and TTC index | 160 * Create a typeface for the specified fileName and TTC index |
(...skipping 24 matching lines...) Expand all Loading... |
137 const SkFontStyle&) const = 0; | 185 const SkFontStyle&) const = 0; |
138 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, | 186 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, |
139 const char* bcp47[], int bcp
47Count, | 187 const char* bcp47[], int bcp
47Count, |
140 SkUnichar character) const =
0; | 188 SkUnichar character) const =
0; |
141 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, | 189 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, |
142 const SkFontStyle&) const = 0; | 190 const SkFontStyle&) const = 0; |
143 | 191 |
144 virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0; | 192 virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0; |
145 virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const =
0; | 193 virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const =
0; |
146 // TODO: make pure virtual. | 194 // TODO: make pure virtual. |
| 195 virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const FontParameters&
) const; |
147 virtual SkTypeface* onCreateFromFontData(SkFontData*) const; | 196 virtual SkTypeface* onCreateFromFontData(SkFontData*) const; |
148 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
= 0; | 197 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
= 0; |
149 | 198 |
150 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 199 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
151 unsigned styleBits) const = 0; | 200 unsigned styleBits) const = 0; |
152 private: | 201 private: |
153 static SkFontMgr* Factory(); // implemented by porting layer | 202 static SkFontMgr* Factory(); // implemented by porting layer |
154 friend SkFontMgr* sk_fontmgr_create_default(); | 203 friend SkFontMgr* sk_fontmgr_create_default(); |
155 | 204 |
156 typedef SkRefCnt INHERITED; | 205 typedef SkRefCnt INHERITED; |
157 }; | 206 }; |
158 | 207 |
159 #endif | 208 #endif |
OLD | NEW |