diff options
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkFontStyle.h | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/include/core/SkFontStyle.h b/include/core/SkFontStyle.h index 306895d78f..a5e3034e1d 100644 --- a/include/core/SkFontStyle.h +++ b/include/core/SkFontStyle.h @@ -44,23 +44,23 @@ public: kOblique_Slant, }; - SkFontStyle(); + constexpr SkFontStyle(int weight, int width, Slant slant) : fValue( + (SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)) + + (SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width) << 16) + + (SkTPin<int>(slant, kUpright_Slant, kOblique_Slant) << 24) + ) { } - constexpr SkFontStyle(int weight, int width, Slant slant) : fUnion {{ - static_cast<uint16_t>(SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)), - static_cast<uint8_t >(SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width)), - static_cast<uint8_t >(SkTPin<int>(slant, kUpright_Slant, kOblique_Slant)) - }} { } + constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { } static SkFontStyle FromOldStyle(unsigned oldStyle); bool operator==(const SkFontStyle& rhs) const { - return fUnion.fU32 == rhs.fUnion.fU32; + return fValue == rhs.fValue; } - int weight() const { return fUnion.fR.fWeight; } - int width() const { return fUnion.fR.fWidth; } - Slant slant() const { return (Slant)fUnion.fR.fSlant; } + int weight() const { return fValue & 0xFFFF; } + int width() const { return (fValue >> 16) & 0xFF; } + Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); } static constexpr SkFontStyle Normal() { return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant); @@ -76,14 +76,7 @@ public: } private: - union { - struct { - uint16_t fWeight; // 100 .. 900 - uint8_t fWidth; // 1 .. 9 - uint8_t fSlant; // 0 .. 2 - } fR; - uint32_t fU32; - } fUnion; + uint32_t fValue; }; #endif |