Skia
2D Graphics Library
SkFontStyle.h
Go to the documentation of this file.
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 
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 {
46  };
47 
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 
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 
60  int weight() const { return fValue & 0xFFFF; }
61  int width() const { return (fValue >> 16) & 0xFF; }
62  Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
63 
64  static constexpr SkFontStyle Normal() {
65  return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
66  }
67  static constexpr SkFontStyle Bold() {
68  return SkFontStyle(kBold_Weight, kNormal_Width, kUpright_Slant);
69  }
70  static constexpr SkFontStyle Italic() {
71  return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
72  }
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
SkFontStyle
Definition: SkFontStyle.h:14
SkFontStyle::Normal
static constexpr SkFontStyle Normal()
Definition: SkFontStyle.h:64
SkFontStyle::Bold
static constexpr SkFontStyle Bold()
Definition: SkFontStyle.h:67
SkFontStyle::SkFontStyle
constexpr SkFontStyle(int weight, int width, Slant slant)
Definition: SkFontStyle.h:48
SkTypes.h
SkFontStyle::Width
Width
Definition: SkFontStyle.h:30
SkFontStyle::Weight
Weight
Definition: SkFontStyle.h:16
SkFontStyle::slant
Slant slant() const
Definition: SkFontStyle.h:62
SkFontStyle::BoldItalic
static constexpr SkFontStyle BoldItalic()
Definition: SkFontStyle.h:73
SkFontStyle::weight
int weight() const
Definition: SkFontStyle.h:60
SkFontStyle::width
int width() const
Definition: SkFontStyle.h:61
SK_API
#define SK_API
Definition: SkTypes.h:181
SkFontStyle::Italic
static constexpr SkFontStyle Italic()
Definition: SkFontStyle.h:70
SkFontStyle::operator==
bool operator==(const SkFontStyle &rhs) const
Definition: SkFontStyle.h:56
SkFontStyle::SkFontStyle
constexpr SkFontStyle()
Definition: SkFontStyle.h:54
SkFontStyle::kOblique_Slant
@ kOblique_Slant
Definition: SkFontStyle.h:45
SkFontStyle::kUpright_Slant
@ kUpright_Slant
Definition: SkFontStyle.h:43
SkFontStyle::Slant
Slant
Definition: SkFontStyle.h:42
SkFontStyle::kItalic_Slant
@ kItalic_Slant
Definition: SkFontStyle.h:44