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/base/SkTPin.h" 13 14 #include <cstdint> 15 16 class SK_API SkFontStyle { 17 public: 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 { 45 kUpright_Slant, 46 kItalic_Slant, 47 kOblique_Slant, 48 }; 49 SkFontStyle(int weight,int width,Slant slant)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 SkFontStyle()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 weight()62 int weight() const { return fValue & 0xFFFF; } width()63 int width() const { return (fValue >> 16) & 0xFF; } slant()64 Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); } 65 Normal()66 static constexpr SkFontStyle Normal() { 67 return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant); 68 } Bold()69 static constexpr SkFontStyle Bold() { 70 return SkFontStyle(kBold_Weight, kNormal_Width, kUpright_Slant); 71 } Italic()72 static constexpr SkFontStyle Italic() { 73 return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant ); 74 } BoldItalic()75 static constexpr SkFontStyle BoldItalic() { 76 return SkFontStyle(kBold_Weight, kNormal_Width, kItalic_Slant ); 77 } 78 79 private: 80 int32_t fValue; 81 }; 82 83 #endif 84