7#include "../exception.hpp"
8#include "../strings.hpp"
9#include "../concepts.hpp"
11#include <unordered_map>
17enum class font_weight {
31 {
"thin", font_weight::Thin},
32 {
"hairline", font_weight::Thin},
33 {
"ultra-light", font_weight::ExtraLight},
34 {
"ultra light", font_weight::ExtraLight},
35 {
"extra-light", font_weight::ExtraLight},
36 {
"extra light", font_weight::ExtraLight},
37 {
"light", font_weight::Light},
38 {
"normal", font_weight::Regular},
39 {
"regular", font_weight::Regular},
40 {
"medium", font_weight::Medium},
41 {
"semi-bold", font_weight::SemiBold},
42 {
"semi bold", font_weight::SemiBold},
43 {
"demi-bold", font_weight::SemiBold},
44 {
"demi bold", font_weight::SemiBold},
45 {
"bold", font_weight::Bold},
46 {
"extra-bold", font_weight::ExtraBold},
47 {
"extra bold", font_weight::ExtraBold},
48 {
"ultra-bold", font_weight::ExtraBold},
49 {
"ultra bold", font_weight::ExtraBold},
50 {
"heavy", font_weight::Black},
51 {
"black", font_weight::Black},
52 {
"extra-black", font_weight::ExtraBlack},
53 {
"ultra-black", font_weight::ExtraBlack},
58[[nodiscard]]
constexpr font_weight font_weight_from_int(numeric_integral
auto rhs)
60 if (rhs < 50 || rhs > 1000) {
61 throw parse_error(
"Unknown font-weight {}", rhs);
63 return static_cast<font_weight
>(((rhs + 50) / 100) - 1);
66[[nodiscard]]
inline font_weight font_weight_from_string(std::string_view rhs)
68 ttlet i = font_weight_from_string_table.find(to_lower(rhs));
69 if (i == font_weight_from_string_table.end()) {
70 throw parse_error(
"Unknown font-weight {}", rhs);
75[[nodiscard]]
constexpr char const *to_const_string(font_weight
const &x)
noexcept
78 case font_weight::Thin:
return "Thin";
79 case font_weight::ExtraLight:
return "ExtraLight";
80 case font_weight::Light:
return "Light";
81 case font_weight::Regular:
return "Regular";
82 case font_weight::Medium:
return "Medium";
83 case font_weight::SemiBold:
return "SemiBold";
84 case font_weight::Bold:
return "Bold";
85 case font_weight::ExtraBold:
return "ExtraBold";
86 case font_weight::Black:
return "Black";
87 case font_weight::ExtraBlack:
return "ExtraBlack";
88 default: tt_no_default();
94 return to_const_string(x);
97[[nodiscard]]
inline char to_char(font_weight
const &x)
noexcept
99 ttlet x_ =
static_cast<int>(x);
100 tt_axiom(x_ >= 0 && x_ <= 9);
101 return static_cast<char>(
'0' + x_);
104[[nodiscard]]
constexpr int to_int(font_weight
const &x)
noexcept
106 ttlet x_ = (
static_cast<int>(x) + 1) * 100;
107 return (x_ == 1000) ? 950 : x_;
115inline bool almost_equal(font_weight
const &lhs, font_weight
const &rhs)
noexcept
118 return (lhs > font_weight::Medium) == (rhs > font_weight::Medium);
121[[nodiscard]]
constexpr auto font_weight_alternative_table_generator() noexcept
125 for (
int w = 0; w < 10; ++w) {
131 for (
int i = 0; i < 10; ++i) {
132 r[w * 10 + i] =
static_cast<font_weight
>(new_w);
135 if ((forward && max_w == 9) || (!
forward && min_w == 0)) {
154constexpr auto font_weight_alternative_table = font_weight_alternative_table_generator();
156[[nodiscard]]
constexpr font_weight font_weight_alterative(font_weight weight,
int i)
noexcept
158 tt_axiom(i >= 0 && i < 10);
159 auto w =
static_cast<int>(weight);
160 tt_axiom(w >= 0 && w < 10);
161 return font_weight_alternative_table[(w * 10) + i];
168template<
typename CharT>
169struct std::formatter<tt::font_weight, CharT> : std::formatter<char const *, CharT> {
170 auto format(tt::font_weight
const &t,
auto &fc)
172 return std::formatter<char const *, CharT>::format(tt::to_const_string(t), fc);