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