| 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 "SkAdvancedTypefaceMetrics.h" | 13 #include "SkAdvancedTypefaceMetrics.h" |
| 14 #include "SkFontStyle.h" |
| 14 #include "SkWeakRefCnt.h" | 15 #include "SkWeakRefCnt.h" |
| 15 | 16 |
| 16 class SkDescriptor; | 17 class SkDescriptor; |
| 17 class SkFontDescriptor; | 18 class SkFontDescriptor; |
| 18 class SkScalerContext; | 19 class SkScalerContext; |
| 19 struct SkScalerContextRec; | 20 struct SkScalerContextRec; |
| 20 class SkStream; | 21 class SkStream; |
| 21 class SkAdvancedTypefaceMetrics; | 22 class SkAdvancedTypefaceMetrics; |
| 22 class SkWStream; | 23 class SkWStream; |
| 23 | 24 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 42 */ | 43 */ |
| 43 enum Style { | 44 enum Style { |
| 44 kNormal = 0, | 45 kNormal = 0, |
| 45 kBold = 0x01, | 46 kBold = 0x01, |
| 46 kItalic = 0x02, | 47 kItalic = 0x02, |
| 47 | 48 |
| 48 // helpers | 49 // helpers |
| 49 kBoldItalic = 0x03 | 50 kBoldItalic = 0x03 |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 /** Returns the typeface's intrinsic style attributes | 53 /** Returns the typeface's intrinsic style attributes. */ |
| 53 */ | 54 SkFontStyle fontStyle() const { |
| 54 Style style() const { return fStyle; } | 55 return fStyle; |
| 56 } |
| 55 | 57 |
| 56 /** Returns true if getStyle() has the kBold bit set. | 58 /** Returns the typeface's intrinsic style attributes. |
| 57 */ | 59 * @deprecated use fontStyle() instead. |
| 58 bool isBold() const { return (fStyle & kBold) != 0; } | 60 */ |
| 61 Style style() const { |
| 62 return static_cast<Style>( |
| 63 (fStyle.weight() >= SkFontStyle::kSemiBold_Weight ? kBold : kNormal)
| |
| 64 (fStyle.slant() != SkFontStyle::kUpright_Slant ? kItalic : kNormal)
); |
| 65 } |
| 59 | 66 |
| 60 /** Returns true if getStyle() has the kItalic bit set. | 67 /** Returns true if style() has the kBold bit set. */ |
| 61 */ | 68 bool isBold() const { return fStyle.weight() >= SkFontStyle::kSemiBold_Weigh
t; } |
| 62 bool isItalic() const { return (fStyle & kItalic) != 0; } | 69 |
| 70 /** Returns true if style() has the kItalic bit set. */ |
| 71 bool isItalic() const { return fStyle.slant() != SkFontStyle::kUpright_Slant
; } |
| 63 | 72 |
| 64 /** Returns true if the typeface claims to be fixed-pitch. | 73 /** Returns true if the typeface claims to be fixed-pitch. |
| 65 * This is a style bit, advance widths may vary even if this returns true. | 74 * This is a style bit, advance widths may vary even if this returns true. |
| 66 */ | 75 */ |
| 67 bool isFixedPitch() const { return fIsFixedPitch; } | 76 bool isFixedPitch() const { return fIsFixedPitch; } |
| 68 | 77 |
| 69 /** Return a 32bit value for this typeface, unique for the underlying font | 78 /** Return a 32bit value for this typeface, unique for the underlying font |
| 70 data. Will never return 0. | 79 data. Will never return 0. |
| 71 */ | 80 */ |
| 72 SkFontID uniqueID() const { return fUniqueID; } | 81 SkFontID uniqueID() const { return fUniqueID; } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 this->onFilterRec(rec); | 287 this->onFilterRec(rec); |
| 279 } | 288 } |
| 280 // PRIVATE / EXPERIMENTAL -- do not call | 289 // PRIVATE / EXPERIMENTAL -- do not call |
| 281 void getFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const { | 290 void getFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const { |
| 282 this->onGetFontDescriptor(desc, isLocal); | 291 this->onGetFontDescriptor(desc, isLocal); |
| 283 } | 292 } |
| 284 | 293 |
| 285 protected: | 294 protected: |
| 286 /** uniqueID must be unique and non-zero | 295 /** uniqueID must be unique and non-zero |
| 287 */ | 296 */ |
| 288 SkTypeface(Style style, SkFontID uniqueID, bool isFixedPitch = false); | 297 SkTypeface(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch =
false); |
| 289 virtual ~SkTypeface(); | 298 virtual ~SkTypeface(); |
| 290 | 299 |
| 291 /** Sets the fixedPitch bit. If used, must be called in the constructor. */ | 300 /** Sets the fixedPitch bit. If used, must be called in the constructor. */ |
| 292 void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; } | 301 void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; } |
| 293 | 302 |
| 294 friend class SkScalerContext; | 303 friend class SkScalerContext; |
| 295 static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal); | 304 static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal); |
| 296 | 305 |
| 297 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const =
0; | 306 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const =
0; |
| 298 virtual void onFilterRec(SkScalerContextRec*) const = 0; | 307 virtual void onFilterRec(SkScalerContextRec*) const = 0; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics( | 353 SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics( |
| 345 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, | 354 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, |
| 346 const uint32_t* glyphIDs = NULL, | 355 const uint32_t* glyphIDs = NULL, |
| 347 uint32_t glyphIDsCount = 0) const; | 356 uint32_t glyphIDsCount = 0) const; |
| 348 | 357 |
| 349 private: | 358 private: |
| 350 static SkTypeface* CreateDefault(int style); // SkLazyPtr requires an int,
not a Style. | 359 static SkTypeface* CreateDefault(int style); // SkLazyPtr requires an int,
not a Style. |
| 351 static void DeleteDefault(SkTypeface*); | 360 static void DeleteDefault(SkTypeface*); |
| 352 | 361 |
| 353 SkFontID fUniqueID; | 362 SkFontID fUniqueID; |
| 354 Style fStyle; | 363 SkFontStyle fStyle; |
| 355 bool fIsFixedPitch; | 364 bool fIsFixedPitch; |
| 356 | 365 |
| 357 friend class SkPaint; | 366 friend class SkPaint; |
| 358 friend class SkGlyphCache; // GetDefaultTypeface | 367 friend class SkGlyphCache; // GetDefaultTypeface |
| 359 // just so deprecated fonthost can call protected methods | 368 // just so deprecated fonthost can call protected methods |
| 360 friend class SkFontHost; | 369 friend class SkFontHost; |
| 361 | 370 |
| 362 typedef SkWeakRefCnt INHERITED; | 371 typedef SkWeakRefCnt INHERITED; |
| 363 }; | 372 }; |
| 364 | 373 |
| 365 #endif | 374 #endif |
| OLD | NEW |