7#include "../utility/module.hpp"
8#include "../strings.hpp"
10#include <unordered_map>
14namespace hi::inline
v1 {
30constexpr auto font_weight_metadata = enum_metadata{
31 font_weight::thin,
"thin",
32 font_weight::extra_light,
"extra-light",
33 font_weight::light,
"light",
34 font_weight::regular,
"regular",
35 font_weight::medium,
"medium",
36 font_weight::semi_bold,
"semi-bold",
37 font_weight::bold,
"bold",
38 font_weight::extra_bold,
"extra-bold",
39 font_weight::black,
"black",
40 font_weight::extra_black,
"extra-black",
48 if (rhs < 50 || rhs > 1000) {
49 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
51 return static_cast<font_weight>(((rhs + 50) / 100) - 1);
54[[nodiscard]]
constexpr font_weight font_weight_from_string(std::string_view rhs)
57 return font_weight_metadata.at(rhs);
59 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
63[[nodiscard]]
constexpr std::string_view to_string_view(font_weight
const& x)
noexcept
65 return font_weight_metadata[x];
73[[nodiscard]]
constexpr char to_char(font_weight
const &x)
noexcept
75 hilet x_ =
static_cast<int>(x);
77 return char_cast<char>(
'0' + x_);
80[[nodiscard]]
constexpr int to_int(font_weight
const &x)
noexcept
82 hilet x_ = (
static_cast<int>(x) + 1) * 100;
83 return (x_ == 1000) ? 950 : x_;
91constexpr bool almost_equal(font_weight
const &lhs, font_weight
const &rhs)
noexcept
94 return (lhs > font_weight::medium) == (rhs > font_weight::medium);
97[[nodiscard]]
constexpr auto font_weight_alternative_table_generator() noexcept
101 for (
auto w = 0_uz; w < 10_uz; ++w) {
107 for (
auto i = 0_uz; i < 10_uz; ++i) {
108 r[w * 10_uz + i] =
static_cast<font_weight>(new_w);
111 if ((forward and max_w == 9_uz) or (not forward and min_w == 0_uz)) {
115 new_w =
forward ? ++max_w : --min_w;
124constexpr auto font_weight_alternative_table = font_weight_alternative_table_generator();
126[[nodiscard]]
constexpr font_weight font_weight_alterative(font_weight weight,
int i)
noexcept
129 auto w =
static_cast<int>(weight);
131 return font_weight_alternative_table[(w * 10) + i];
136template<
typename CharT>
137struct std::formatter<
hi::font_weight, CharT> : std::formatter<std::string_view, CharT> {
138 auto format(hi::font_weight
const &t,
auto &fc)
140 return std::formatter<std::string_view, CharT>::format(hi::to_string_view(t), fc);
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#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:46
font_weight
Definition font_weight.hpp:16
@ black
900: Heavy / Black
@ semi_bold
600: Semi-bold / Demi-bold
@ thin
100: Thin / Hairline
@ extra_light
200: Ultra-light / Extra-light
@ regular
400: Normal / Regular
@ extra_bold
800: Extra-bold / Ultra-bold
@ extra_black
950: Extra-black / Ultra-black
geometry/margins.hpp
Definition cache.hpp:11
Definition concepts.hpp:24