2013-03-25 18:44:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2013-03-25 20:44:02 +00:00
|
|
|
#ifndef SkFontStyle_DEFINED
|
|
|
|
#define SkFontStyle_DEFINED
|
2013-03-25 18:44:17 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2013-03-25 18:44:17 +00:00
|
|
|
|
2013-04-10 13:10:40 +00:00
|
|
|
class SK_API SkFontStyle {
|
2013-03-25 18:44:17 +00:00
|
|
|
public:
|
|
|
|
enum Weight {
|
2016-07-25 22:11:49 +00:00
|
|
|
kInvisible_Weight = 0,
|
|
|
|
kThin_Weight = 100,
|
|
|
|
kExtraLight_Weight = 200,
|
|
|
|
kLight_Weight = 300,
|
|
|
|
kNormal_Weight = 400,
|
|
|
|
kMedium_Weight = 500,
|
|
|
|
kSemiBold_Weight = 600,
|
|
|
|
kBold_Weight = 700,
|
|
|
|
kExtraBold_Weight = 800,
|
|
|
|
kBlack_Weight = 900,
|
2016-08-01 19:37:13 +00:00
|
|
|
kExtraBlack_Weight = 1000,
|
2013-03-25 18:44:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Width {
|
|
|
|
kUltraCondensed_Width = 1,
|
|
|
|
kExtraCondensed_Width = 2,
|
|
|
|
kCondensed_Width = 3,
|
|
|
|
kSemiCondensed_Width = 4,
|
|
|
|
kNormal_Width = 5,
|
|
|
|
kSemiExpanded_Width = 6,
|
|
|
|
kExpanded_Width = 7,
|
|
|
|
kExtraExpanded_Width = 8,
|
2016-08-01 19:37:13 +00:00
|
|
|
kUltraExpanded_Width = 9,
|
2013-03-25 18:44:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Slant {
|
|
|
|
kUpright_Slant,
|
|
|
|
kItalic_Slant,
|
2016-04-27 17:21:04 +00:00
|
|
|
kOblique_Slant,
|
2013-03-25 18:44:17 +00:00
|
|
|
};
|
|
|
|
|
2017-07-31 19:41:14 +00:00
|
|
|
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)
|
|
|
|
) { }
|
2017-07-27 14:45:29 +00:00
|
|
|
|
2017-07-31 19:41:14 +00:00
|
|
|
constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { }
|
2016-04-12 20:45:06 +00:00
|
|
|
|
2013-03-25 18:44:17 +00:00
|
|
|
bool operator==(const SkFontStyle& rhs) const {
|
2017-07-31 19:41:14 +00:00
|
|
|
return fValue == rhs.fValue;
|
2013-03-25 18:44:17 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 19:41:14 +00:00
|
|
|
int weight() const { return fValue & 0xFFFF; }
|
|
|
|
int width() const { return (fValue >> 16) & 0xFF; }
|
|
|
|
Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
|
2013-03-25 18:44:17 +00:00
|
|
|
|
2017-07-27 14:45:29 +00:00
|
|
|
static constexpr SkFontStyle Normal() {
|
|
|
|
return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
|
|
|
|
}
|
|
|
|
static constexpr SkFontStyle Bold() {
|
|
|
|
return SkFontStyle(kBold_Weight, kNormal_Width, kUpright_Slant);
|
|
|
|
}
|
|
|
|
static constexpr SkFontStyle Italic() {
|
|
|
|
return SkFontStyle(kNormal_Weight, kNormal_Width, kItalic_Slant );
|
|
|
|
}
|
|
|
|
static constexpr SkFontStyle BoldItalic() {
|
|
|
|
return SkFontStyle(kBold_Weight, kNormal_Width, kItalic_Slant );
|
|
|
|
}
|
|
|
|
|
2013-03-25 18:44:17 +00:00
|
|
|
private:
|
2017-07-31 19:41:14 +00:00
|
|
|
uint32_t fValue;
|
2013-03-25 18:44:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|