7#include "../exception.hpp"
8#include "../strings.hpp"
9#include "../concepts.hpp"
11#include <unordered_map>
15namespace hi::inline
v1 {
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},
60 if (rhs < 50 || rhs > 1000) {
61 throw parse_error(std::format(
"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 hilet i = font_weight_from_string_table.find(to_lower(rhs));
69 if (i == font_weight_from_string_table.end()) {
70 throw parse_error(std::format(
"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";
94 return to_const_string(x);
97[[nodiscard]]
inline char to_char(font_weight
const &x)
noexcept
99 hilet x_ =
static_cast<int>(x);
101 return static_cast<char>(
'0' + x_);
104[[nodiscard]]
constexpr int to_int(font_weight
const &x)
noexcept
106 hilet 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 (
auto w = 0_uz; w < 10_uz; ++w) {
131 for (
auto i = 0_uz; i < 10_uz; ++i) {
132 r[w * 10_uz + i] =
static_cast<font_weight>(new_w);
135 if ((forward and max_w == 9_uz) or (not forward and min_w == 0_uz)) {
139 new_w =
forward ? ++max_w : --min_w;
148constexpr auto font_weight_alternative_table = font_weight_alternative_table_generator();
150[[nodiscard]]
constexpr font_weight font_weight_alterative(font_weight weight,
int i)
noexcept
153 auto w =
static_cast<int>(weight);
155 return font_weight_alternative_table[(w * 10) + i];
160template<
typename CharT>
161struct std::formatter<
hi::font_weight, CharT> : std::formatter<char const *, CharT> {
162 auto format(hi::font_weight
const &t,
auto &fc)
164 return std::formatter<char const *, CharT>::format(hi::to_const_string(t), fc);
#define hi_axiom(expression)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
#define hi_no_default()
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:145
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
constexpr font_weight font_weight_from_int(numeric_integral auto rhs)
Convert a font weight value between 50 and 1000 to a font weight.
Definition font_weight.hpp:58
font_weight
Definition font_weight.hpp:17
@ SemiBold
600: Semi-bold / Demi-bold
@ ExtraBold
800: Extra-bold / Ultra-bold
@ Thin
100: Thin / Hairline
@ Regular
400: Normal / Regular
@ ExtraBlack
950: Extra-black / Ultra-black
@ Black
900: Heavy / Black
@ ExtraLight
200: Ultra-light / Extra-light
The HikoGUI namespace.
Definition ascii.hpp:19
Definition concepts.hpp:24