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