Flutter Engine
The Flutter Engine
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
13
14#include <cstdint>
15
17public:
18 enum Weight {
19 kInvisible_Weight = 0,
20 kThin_Weight = 100,
21 kExtraLight_Weight = 200,
22 kLight_Weight = 300,
23 kNormal_Weight = 400,
24 kMedium_Weight = 500,
25 kSemiBold_Weight = 600,
26 kBold_Weight = 700,
27 kExtraBold_Weight = 800,
28 kBlack_Weight = 900,
29 kExtraBlack_Weight = 1000,
30 };
31
32 enum Width {
33 kUltraCondensed_Width = 1,
34 kExtraCondensed_Width = 2,
35 kCondensed_Width = 3,
36 kSemiCondensed_Width = 4,
37 kNormal_Width = 5,
38 kSemiExpanded_Width = 6,
39 kExpanded_Width = 7,
40 kExtraExpanded_Width = 8,
41 kUltraExpanded_Width = 9,
42 };
43
44 enum Slant {
48 };
49
50 constexpr SkFontStyle(int weight, int width, Slant slant) : fValue(
51 (SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)) +
52 (SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width) << 16) +
53 (SkTPin<int>(slant, kUpright_Slant, kOblique_Slant) << 24)
54 ) { }
55
56 constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { }
57
58 bool operator==(const SkFontStyle& rhs) const {
59 return fValue == rhs.fValue;
60 }
61
62 int weight() const { return fValue & 0xFFFF; }
63 int width() const { return (fValue >> 16) & 0xFF; }
64 Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
65
66 static constexpr SkFontStyle Normal() {
67 return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
68 }
69 static constexpr SkFontStyle Bold() {
70 return SkFontStyle(kBold_Weight, kNormal_Width, kUpright_Slant);
71 }
72 static constexpr SkFontStyle Italic() {
73 return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
74 }
75 static constexpr SkFontStyle BoldItalic() {
76 return SkFontStyle(kBold_Weight, kNormal_Width, kItalic_Slant );
77 }
78
79private:
80 friend class SkTypefaceProxyPrototype; // To serialize fValue
81 int32_t fValue;
82};
83
84#endif
#define SK_API
Definition: SkAPI.h:35
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
constexpr SkFontStyle(int weight, int width, Slant slant)
Definition: SkFontStyle.h:50
constexpr SkFontStyle()
Definition: SkFontStyle.h:56
Slant slant() const
Definition: SkFontStyle.h:64
static constexpr SkFontStyle Italic()
Definition: SkFontStyle.h:72
int width() const
Definition: SkFontStyle.h:63
int weight() const
Definition: SkFontStyle.h:62
static constexpr SkFontStyle BoldItalic()
Definition: SkFontStyle.h:75
bool operator==(const SkFontStyle &rhs) const
Definition: SkFontStyle.h:58
static constexpr SkFontStyle Bold()
Definition: SkFontStyle.h:69
static constexpr SkFontStyle Normal()
Definition: SkFontStyle.h:66
int32_t width