blob: a5e3034e1d2d5e4bc1269b7390b8bce13ead293e [file] [log] [blame]
reed@google.comc452d822013-03-25 18:44:17 +00001/*
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
reed@google.com95625db2013-03-25 20:44:02 +00008#ifndef SkFontStyle_DEFINED
9#define SkFontStyle_DEFINED
reed@google.comc452d822013-03-25 18:44:17 +000010
11#include "SkTypes.h"
12
reed@google.comaae71ba2013-04-10 13:10:40 +000013class SK_API SkFontStyle {
reed@google.comc452d822013-03-25 18:44:17 +000014public:
15 enum Weight {
bungeman6e45bda2016-07-25 15:11:49 -070016 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,
bungemand783e082016-08-01 12:37:13 -070026 kExtraBlack_Weight = 1000,
reed@google.comc452d822013-03-25 18:44:17 +000027 };
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,
bungemand783e082016-08-01 12:37:13 -070038 kUltraExpanded_Width = 9,
reed@google.comc452d822013-03-25 18:44:17 +000039 };
40
41 enum Slant {
42 kUpright_Slant,
43 kItalic_Slant,
bungemanb4bb7d82016-04-27 10:21:04 -070044 kOblique_Slant,
reed@google.comc452d822013-03-25 18:44:17 +000045 };
46
Ben Wagner0500eba2017-07-31 15:41:14 -040047 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 ) { }
Ben Wagner71319502017-07-27 10:45:29 -040052
Ben Wagner0500eba2017-07-31 15:41:14 -040053 constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { }
bungeman11a77c62016-04-12 13:45:06 -070054
55 static SkFontStyle FromOldStyle(unsigned oldStyle);
reed@google.comc452d822013-03-25 18:44:17 +000056
57 bool operator==(const SkFontStyle& rhs) const {
Ben Wagner0500eba2017-07-31 15:41:14 -040058 return fValue == rhs.fValue;
reed@google.comc452d822013-03-25 18:44:17 +000059 }
60
Ben Wagner0500eba2017-07-31 15:41:14 -040061 int weight() const { return fValue & 0xFFFF; }
62 int width() const { return (fValue >> 16) & 0xFF; }
63 Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
reed@google.comc452d822013-03-25 18:44:17 +000064
Ben Wagner71319502017-07-27 10:45:29 -040065 static constexpr SkFontStyle Normal() {
66 return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
67 }
68 static constexpr SkFontStyle Bold() {
69 return SkFontStyle(kBold_Weight, kNormal_Width, kUpright_Slant);
70 }
71 static constexpr SkFontStyle Italic() {
72 return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
73 }
74 static constexpr SkFontStyle BoldItalic() {
75 return SkFontStyle(kBold_Weight, kNormal_Width, kItalic_Slant );
76 }
77
reed@google.comc452d822013-03-25 18:44:17 +000078private:
Ben Wagner0500eba2017-07-31 15:41:14 -040079 uint32_t fValue;
reed@google.comc452d822013-03-25 18:44:17 +000080};
81
82#endif