7#include "../exception.hpp"
9#include <unordered_map>
14enum class font_weight {
28 {
"thin", font_weight::Thin},
29 {
"hairline", font_weight::Thin},
30 {
"ultra-light", font_weight::ExtraLight},
31 {
"ultra light", font_weight::ExtraLight},
32 {
"extra-light", font_weight::ExtraLight},
33 {
"extra light", font_weight::ExtraLight},
34 {
"light", font_weight::Light},
35 {
"normal", font_weight::Regular},
36 {
"regular", font_weight::Regular},
37 {
"medium", font_weight::Medium},
38 {
"semi-bold", font_weight::SemiBold},
39 {
"semi bold", font_weight::SemiBold},
40 {
"demi-bold", font_weight::SemiBold},
41 {
"demi bold", font_weight::SemiBold},
42 {
"bold", font_weight::Bold},
43 {
"extra-bold", font_weight::ExtraBold},
44 {
"extra bold", font_weight::ExtraBold},
45 {
"ultra-bold", font_weight::ExtraBold},
46 {
"ultra bold", font_weight::ExtraBold},
47 {
"heavy", font_weight::Black},
48 {
"black", font_weight::Black},
49 {
"extra-black", font_weight::ExtraBlack},
50 {
"ultra-black", font_weight::ExtraBlack},
55[[nodiscard]]
constexpr font_weight font_weight_from_int(
int rhs) {
56 if (rhs < 50 || rhs > 1000) {
57 throw parse_error(
"Unknown font-weight {}", rhs);
59 return static_cast<font_weight
>(((rhs + 50) / 100) - 1);
62[[nodiscard]]
inline font_weight font_weight_from_string(std::string_view rhs) {
63 ttlet i = font_weight_from_string_table.find(to_lower(rhs));
64 if (i == font_weight_from_string_table.end()) {
65 throw parse_error(
"Unknown font-weight {}", rhs);
70[[nodiscard]]
constexpr char const *to_const_string(font_weight
const &x)
noexcept {
72 case font_weight::Thin:
return "Thin";
73 case font_weight::ExtraLight:
return "ExtraLight";
74 case font_weight::Light:
return "Light";
75 case font_weight::Regular:
return "Regular";
76 case font_weight::Medium:
return "Medium";
77 case font_weight::SemiBold:
return "SemiBold";
78 case font_weight::Bold:
return "Bold";
79 case font_weight::ExtraBold:
return "ExtraBold";
80 case font_weight::Black:
return "Black";
81 case font_weight::ExtraBlack:
return "ExtraBlack";
82 default: tt_no_default();
87 return to_const_string(x);
90[[nodiscard]]
inline char to_char(font_weight
const &x)
noexcept {
91 ttlet x_ =
static_cast<int>(x);
92 tt_axiom(x_ >= 0 && x_ <= 9);
93 return static_cast<char>(
'0' + x_);
96[[nodiscard]]
constexpr int to_int(font_weight
const &x)
noexcept {
97 ttlet x_ = (
static_cast<int>(x) + 1) * 100;
98 return (x_ == 1000) ? 950 : x_;
105inline bool almost_equal(font_weight
const &lhs, font_weight
const &rhs)
noexcept {
107 return (lhs > font_weight::Medium) == (rhs > font_weight::Medium);
110[[nodiscard]]
constexpr auto font_weight_alternative_table_generator() noexcept
114 for (
int w = 0; w < 10; ++w) {
120 for (
int i = 0; i < 10; ++i) {
121 r[w * 10 + i] =
static_cast<font_weight
>(new_w);
124 if ((forward && max_w == 9) || (!
forward && min_w == 0)) {
143constexpr auto font_weight_alternative_table = font_weight_alternative_table_generator();
145[[nodiscard]]
constexpr font_weight font_weight_alterative(font_weight weight,
int i)
noexcept {
146 tt_axiom(i >= 0 && i < 10);
147 auto w =
static_cast<int>(weight);
148 tt_axiom(w >= 0 && w < 10);
149 return font_weight_alternative_table[(w * 10) + i];