19 constexpr static int max() {
return 20; }
20 constexpr static int half() {
return max() / 2; }
22 constexpr FontVariant(FontWeight weight,
bool italic) noexcept : value(
static_cast<uint8_t
>(
static_cast<int>(weight) + (italic ? half() : 0))) {}
27 constexpr FontWeight weight()
const noexcept {
28 tt_assume(value < max());
29 return static_cast<FontWeight
>(value % half());
32 [[nodiscard]]
constexpr bool italic()
const noexcept {
33 tt_assume(value < max());
34 return value >= half();
37 constexpr FontVariant &set_weight(FontWeight rhs)
noexcept {
38 value =
static_cast<uint8_t
>(
static_cast<int>(rhs) + (italic() ? half() : 0));
39 tt_assume(value < max());
43 constexpr FontVariant &set_italic(
bool rhs)
noexcept {
44 value =
static_cast<uint8_t
>(
static_cast<int>(weight()) + (rhs ? half() : 0));
45 tt_assume(value < max());
49 constexpr operator int ()
const noexcept {
50 tt_assume(value < max());
58 tt_assume(i >= 0 && i < max());
59 ttlet w = FontWeight_alterative(weight(), i % half());
60 ttlet it = italic() == (i < half());
65 return fmt::format(
"{}", rhs.weight(), rhs.italic() ?
"/italic" :
"");
69 return lhs << to_string(rhs);