aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkFontStyle.h29
-rw-r--r--src/core/SkFontStyle.cpp7
2 files changed, 11 insertions, 25 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
diff --git a/src/core/SkFontStyle.cpp b/src/core/SkFontStyle.cpp
index 24ee645a4f..996d383402 100644
--- a/src/core/SkFontStyle.cpp
+++ b/src/core/SkFontStyle.cpp
@@ -9,13 +9,6 @@
#include "SkTypeface.h"
#include "SkTypes.h"
-SkFontStyle::SkFontStyle() {
- fUnion.fU32 = 0;
- fUnion.fR.fWeight = kNormal_Weight;
- fUnion.fR.fWidth = kNormal_Width;
- fUnion.fR.fSlant = kUpright_Slant;
-}
-
/*static*/SkFontStyle SkFontStyle::FromOldStyle(unsigned oldStyle) {
return SkFontStyle((oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weight
: SkFontStyle::kNormal_Weight,