reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 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 | |
reed@google.com | 95625db | 2013-03-25 20:44:02 +0000 | [diff] [blame] | 8 | #ifndef SkFontStyle_DEFINED |
| 9 | #define SkFontStyle_DEFINED |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 10 | |
| 11 | #include "SkTypes.h" |
| 12 | |
reed@google.com | aae71ba | 2013-04-10 13:10:40 +0000 | [diff] [blame] | 13 | class SK_API SkFontStyle { |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 14 | public: |
| 15 | enum Weight { |
bungeman | 6e45bda | 2016-07-25 15:11:49 -0700 | [diff] [blame] | 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, |
bungeman | d783e08 | 2016-08-01 12:37:13 -0700 | [diff] [blame] | 26 | kExtraBlack_Weight = 1000, |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 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, |
bungeman | d783e08 | 2016-08-01 12:37:13 -0700 | [diff] [blame] | 38 | kUltraExpanded_Width = 9, |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | enum Slant { |
| 42 | kUpright_Slant, |
| 43 | kItalic_Slant, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 44 | kOblique_Slant, |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Ben Wagner | 0500eba | 2017-07-31 15:41:14 -0400 | [diff] [blame^] | 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 | ) { } |
Ben Wagner | 7131950 | 2017-07-27 10:45:29 -0400 | [diff] [blame] | 52 | |
Ben Wagner | 0500eba | 2017-07-31 15:41:14 -0400 | [diff] [blame^] | 53 | constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { } |
bungeman | 11a77c6 | 2016-04-12 13:45:06 -0700 | [diff] [blame] | 54 | |
| 55 | static SkFontStyle FromOldStyle(unsigned oldStyle); |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 56 | |
| 57 | bool operator==(const SkFontStyle& rhs) const { |
Ben Wagner | 0500eba | 2017-07-31 15:41:14 -0400 | [diff] [blame^] | 58 | return fValue == rhs.fValue; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Ben Wagner | 0500eba | 2017-07-31 15:41:14 -0400 | [diff] [blame^] | 61 | 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.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 64 | |
Ben Wagner | 7131950 | 2017-07-27 10:45:29 -0400 | [diff] [blame] | 65 | 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.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 78 | private: |
Ben Wagner | 0500eba | 2017-07-31 15:41:14 -0400 | [diff] [blame^] | 79 | uint32_t fValue; |
reed@google.com | c452d82 | 2013-03-25 18:44:17 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | #endif |