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