OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkTypeface_DEFINED | 10 #ifndef SkTypeface_DEFINED |
11 #define SkTypeface_DEFINED | 11 #define SkTypeface_DEFINED |
12 | 12 |
13 #include "SkFontStyle.h" | 13 #include "SkFontStyle.h" |
14 #include "SkLazyPtr.h" | 14 #include "SkLazyPtr.h" |
15 #include "SkRect.h" | 15 #include "SkRect.h" |
16 #include "SkString.h" | 16 #include "SkString.h" |
17 #include "SkWeakRefCnt.h" | 17 #include "SkWeakRefCnt.h" |
18 | 18 |
19 class SkDescriptor; | 19 class SkDescriptor; |
| 20 class SkFontData; |
20 class SkFontDescriptor; | 21 class SkFontDescriptor; |
21 class SkScalerContext; | 22 class SkScalerContext; |
22 struct SkScalerContextRec; | 23 struct SkScalerContextRec; |
23 class SkStream; | 24 class SkStream; |
24 class SkStreamAsset; | 25 class SkStreamAsset; |
25 class SkAdvancedTypefaceMetrics; | 26 class SkAdvancedTypefaceMetrics; |
26 class SkWStream; | 27 class SkWStream; |
27 | 28 |
28 typedef uint32_t SkFontID; | 29 typedef uint32_t SkFontID; |
29 /** Machine endian. */ | 30 /** Machine endian. */ |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 not a valid font file, returns null. | 128 not a valid font file, returns null. |
128 */ | 129 */ |
129 static SkTypeface* CreateFromFile(const char path[], int index = 0); | 130 static SkTypeface* CreateFromFile(const char path[], int index = 0); |
130 | 131 |
131 /** Return a new typeface given a stream. If the stream is | 132 /** Return a new typeface given a stream. If the stream is |
132 not a valid font file, returns null. Ownership of the stream is | 133 not a valid font file, returns null. Ownership of the stream is |
133 transferred, so the caller must not reference it again. | 134 transferred, so the caller must not reference it again. |
134 */ | 135 */ |
135 static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0); | 136 static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0); |
136 | 137 |
| 138 /** Return a new typeface given font data and configuration. If the data |
| 139 is not valid font data, returns null. Ownership of the font data is |
| 140 transferred, so the caller must not reference it again. |
| 141 */ |
| 142 static SkTypeface* CreateFromFontData(SkFontData*); |
| 143 |
137 /** Write a unique signature to a stream, sufficient to reconstruct a | 144 /** Write a unique signature to a stream, sufficient to reconstruct a |
138 typeface referencing the same font when Deserialize is called. | 145 typeface referencing the same font when Deserialize is called. |
139 */ | 146 */ |
140 void serialize(SkWStream*) const; | 147 void serialize(SkWStream*) const; |
141 | 148 |
142 /** Like serialize, but write the whole font (not just a signature) if possi
ble. | 149 /** Like serialize, but write the whole font (not just a signature) if possi
ble. |
143 */ | 150 */ |
144 void serializeForcingEmbedding(SkWStream*) const; | 151 void serializeForcingEmbedding(SkWStream*) const; |
145 | 152 |
146 /** Given the data previously written by serialize(), return a new instance | 153 /** Given the data previously written by serialize(), return a new instance |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 /** | 284 /** |
278 * Return a stream for the contents of the font data, or NULL on failure. | 285 * Return a stream for the contents of the font data, or NULL on failure. |
279 * If ttcIndex is not null, it is set to the TrueTypeCollection index | 286 * If ttcIndex is not null, it is set to the TrueTypeCollection index |
280 * of this typeface within the stream, or 0 if the stream is not a | 287 * of this typeface within the stream, or 0 if the stream is not a |
281 * collection. | 288 * collection. |
282 * The caller is responsible for deleting the stream. | 289 * The caller is responsible for deleting the stream. |
283 */ | 290 */ |
284 SkStreamAsset* openStream(int* ttcIndex) const; | 291 SkStreamAsset* openStream(int* ttcIndex) const; |
285 | 292 |
286 /** | 293 /** |
| 294 * Return the font data, or NULL on failure. |
| 295 * The caller is responsible for deleting the font data. |
| 296 */ |
| 297 SkFontData* createFontData() const; |
| 298 |
| 299 /** |
287 * Return a scalercontext for the given descriptor. If this fails, then | 300 * Return a scalercontext for the given descriptor. If this fails, then |
288 * if allowFailure is true, this returns NULL, else it returns a | 301 * if allowFailure is true, this returns NULL, else it returns a |
289 * dummy scalercontext that will not crash, but will draw nothing. | 302 * dummy scalercontext that will not crash, but will draw nothing. |
290 */ | 303 */ |
291 SkScalerContext* createScalerContext(const SkDescriptor*, | 304 SkScalerContext* createScalerContext(const SkDescriptor*, |
292 bool allowFailure = false) const; | 305 bool allowFailure = false) const; |
293 | 306 |
294 /** | 307 /** |
295 * Return a rectangle (scaled to 1-pt) that represents the union of the bou
nds of all | 308 * Return a rectangle (scaled to 1-pt) that represents the union of the bou
nds of all |
296 * of the glyphs, but each one positioned at (0,). This may be conservative
ly large, and | 309 * of the glyphs, but each one positioned at (0,). This may be conservative
ly large, and |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal); | 343 static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal); |
331 | 344 |
332 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const =
0; | 345 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const =
0; |
333 virtual void onFilterRec(SkScalerContextRec*) const = 0; | 346 virtual void onFilterRec(SkScalerContextRec*) const = 0; |
334 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 347 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
335 PerGlyphInfo, | 348 PerGlyphInfo, |
336 const uint32_t* glyphIDs, | 349 const uint32_t* glyphIDs, |
337 uint32_t glyphIDsCount) const = 0; | 350 uint32_t glyphIDsCount) const = 0; |
338 | 351 |
339 virtual SkStreamAsset* onOpenStream(int* ttcIndex) const = 0; | 352 virtual SkStreamAsset* onOpenStream(int* ttcIndex) const = 0; |
| 353 // TODO: make pure virtual. |
| 354 virtual SkFontData* onCreateFontData() const; |
| 355 |
340 virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0
; | 356 virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0
; |
341 | 357 |
342 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], | 358 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
343 int glyphCount) const = 0; | 359 int glyphCount) const = 0; |
344 virtual int onCountGlyphs() const = 0; | 360 virtual int onCountGlyphs() const = 0; |
345 | 361 |
346 virtual int onGetUPEM() const = 0; | 362 virtual int onGetUPEM() const = 0; |
347 virtual bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count, | 363 virtual bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count, |
348 int32_t adjustments[]) const; | 364 int32_t adjustments[]) const; |
349 | 365 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 SkFontStyle fStyle; | 411 SkFontStyle fStyle; |
396 bool fIsFixedPitch; | 412 bool fIsFixedPitch; |
397 | 413 |
398 friend class SkPaint; | 414 friend class SkPaint; |
399 friend class SkGlyphCache; // GetDefaultTypeface | 415 friend class SkGlyphCache; // GetDefaultTypeface |
400 | 416 |
401 typedef SkWeakRefCnt INHERITED; | 417 typedef SkWeakRefCnt INHERITED; |
402 }; | 418 }; |
403 | 419 |
404 #endif | 420 #endif |
OLD | NEW |