• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkFontStyle_DEFINED
9 #define SkFontStyle_DEFINED
10 
11 #include "include/core/SkTypes.h"
12 #include "include/private/SkTPin.h"
13 
14 class SK_API SkFontStyle {
15 public:
16     enum Weight {
17         kInvisible_Weight   =    0,
18         kThin_Weight        =  100,
19         kExtraLight_Weight  =  200,
20         kLight_Weight       =  300,
21         kNormal_Weight      =  400,
22         kMedium_Weight      =  500,
23         kSemiBold_Weight    =  600,
24         kBold_Weight        =  700,
25         kExtraBold_Weight   =  800,
26         kBlack_Weight       =  900,
27         kExtraBlack_Weight  = 1000,
28     };
29 
30     enum Width {
31         kUltraCondensed_Width   = 1,
32         kExtraCondensed_Width   = 2,
33         kCondensed_Width        = 3,
34         kSemiCondensed_Width    = 4,
35         kNormal_Width           = 5,
36         kSemiExpanded_Width     = 6,
37         kExpanded_Width         = 7,
38         kExtraExpanded_Width    = 8,
39         kUltraExpanded_Width    = 9,
40     };
41 
42     enum Slant {
43         kUpright_Slant,
44         kItalic_Slant,
45         kOblique_Slant,
46     };
47 
SkFontStyle(int weight,int width,Slant slant)48     constexpr SkFontStyle(int weight, int width, Slant slant) : fValue(
49         (SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)) +
50         (SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width) << 16) +
51         (SkTPin<int>(slant, kUpright_Slant, kOblique_Slant) << 24)
52      ) { }
53 
SkFontStyle()54     constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { }
55 
56     bool operator==(const SkFontStyle& rhs) const {
57         return fValue == rhs.fValue;
58     }
59 
weight()60     int weight() const { return fValue & 0xFFFF; }
width()61     int width() const { return (fValue >> 16) & 0xFF; }
slant()62     Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
63 
Normal()64     static constexpr SkFontStyle Normal() {
65         return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
66     }
Bold()67     static constexpr SkFontStyle Bold() {
68         return SkFontStyle(kBold_Weight,   kNormal_Width, kUpright_Slant);
69     }
Italic()70     static constexpr SkFontStyle Italic() {
71         return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
72     }
BoldItalic()73     static constexpr SkFontStyle BoldItalic() {
74         return SkFontStyle(kBold_Weight,   kNormal_Width, kItalic_Slant );
75     }
76 
77 private:
78     int32_t fValue;
79 };
80 
81 #endif
82