SkFontStyle.h 2.3 KB

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