7#include "../utility/module.hpp"
8#include "../strings.hpp"
10#include <unordered_map>
14namespace hi::inline
v1 {
30 {
"thin", font_weight::Thin},
31 {
"hairline", font_weight::Thin},
32 {
"ultra-light", font_weight::ExtraLight},
33 {
"ultra light", font_weight::ExtraLight},
34 {
"extra-light", font_weight::ExtraLight},
35 {
"extra light", font_weight::ExtraLight},
36 {
"light", font_weight::Light},
37 {
"normal", font_weight::Regular},
38 {
"regular", font_weight::Regular},
39 {
"medium", font_weight::Medium},
40 {
"semi-bold", font_weight::SemiBold},
41 {
"semi bold", font_weight::SemiBold},
42 {
"demi-bold", font_weight::SemiBold},
43 {
"demi bold", font_weight::SemiBold},
44 {
"bold", font_weight::Bold},
45 {
"extra-bold", font_weight::ExtraBold},
46 {
"extra bold", font_weight::ExtraBold},
47 {
"ultra-bold", font_weight::ExtraBold},
48 {
"ultra bold", font_weight::ExtraBold},
49 {
"heavy", font_weight::Black},
50 {
"black", font_weight::Black},
51 {
"extra-black", font_weight::ExtraBlack},
52 {
"ultra-black", font_weight::ExtraBlack},
59 if (rhs < 50 || rhs > 1000) {
60 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
62 return static_cast<font_weight>(((rhs + 50) / 100) - 1);
65[[nodiscard]]
inline font_weight font_weight_from_string(std::string_view rhs)
67 hilet i = font_weight_from_string_table.find(to_lower(rhs));
68 if (i == font_weight_from_string_table.end()) {
69 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
74[[nodiscard]]
constexpr char const *to_const_string(font_weight
const &x)
noexcept
77 case font_weight::Thin:
return "Thin";
78 case font_weight::ExtraLight:
return "ExtraLight";
79 case font_weight::Light:
return "Light";
80 case font_weight::Regular:
return "Regular";
81 case font_weight::Medium:
return "Medium";
82 case font_weight::SemiBold:
return "SemiBold";
83 case font_weight::Bold:
return "Bold";
84 case font_weight::ExtraBold:
return "ExtraBold";
85 case font_weight::Black:
return "Black";
86 case font_weight::ExtraBlack:
return "ExtraBlack";
93 return to_const_string(x);
96[[nodiscard]]
inline char to_char(font_weight
const &x)
noexcept
98 hilet x_ =
static_cast<int>(x);
100 return char_cast<char>(
'0' + x_);
103[[nodiscard]]
constexpr int to_int(font_weight
const &x)
noexcept
105 hilet x_ = (
static_cast<int>(x) + 1) * 100;
106 return (x_ == 1000) ? 950 : x_;
114inline bool almost_equal(font_weight
const &lhs, font_weight
const &rhs)
noexcept
117 return (lhs > font_weight::Medium) == (rhs > font_weight::Medium);
120[[nodiscard]]
constexpr auto font_weight_alternative_table_generator() noexcept
124 for (
auto w = 0_uz; w < 10_uz; ++w) {
130 for (
auto i = 0_uz; i < 10_uz; ++i) {
131 r[w * 10_uz + i] =
static_cast<font_weight>(new_w);
134 if ((forward and max_w == 9_uz) or (not forward and min_w == 0_uz)) {
138 new_w =
forward ? ++max_w : --min_w;
147constexpr auto font_weight_alternative_table = font_weight_alternative_table_generator();
149[[nodiscard]]
constexpr font_weight font_weight_alterative(font_weight weight,
int i)
noexcept
152 auto w =
static_cast<int>(weight);
154 return font_weight_alternative_table[(w * 10) + i];
159template<
typename CharT>
160struct std::formatter<
hi::font_weight, CharT> : std::formatter<char const *, CharT> {
161 auto format(hi::font_weight
const &t,
auto &fc)
163 return std::formatter<char const *, CharT>::format(hi::to_const_string(t), fc);
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:264
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
constexpr std::string to_string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:215
DOXYGEN BUG.
Definition algorithm.hpp:13
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:57
font_weight
Definition font_weight.hpp:16
@ 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
geometry/margins.hpp
Definition cache.hpp:11
Definition concepts.hpp:24