7#include "../utility/module.hpp"
8#include "../strings.hpp"
9#include "../generator.hpp"
11#include <unordered_map>
15namespace hi::inline
v1 {
30constexpr font_weight& operator++(font_weight& rhs)
noexcept
32 hi_axiom(rhs < font_weight::extra_black);
33 return rhs =
static_cast<font_weight
>(to_underlying(rhs) + 1);
36constexpr font_weight& operator--(font_weight& rhs)
noexcept
39 return rhs =
static_cast<font_weight>(to_underlying(rhs) - 1);
43constexpr auto font_weight_metadata = enum_metadata{
44 font_weight::thin,
"thin",
45 font_weight::extra_light,
"extra-light",
46 font_weight::light,
"light",
47 font_weight::regular,
"regular",
48 font_weight::medium,
"medium",
49 font_weight::semi_bold,
"semi-bold",
50 font_weight::bold,
"bold",
51 font_weight::extra_bold,
"extra-bold",
52 font_weight::black,
"black",
53 font_weight::extra_black,
"extra-black",
61 if (rhs < 50 || rhs > 1000) {
62 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
64 return static_cast<font_weight>(((rhs + 50) / 100) - 1);
67[[nodiscard]]
constexpr font_weight font_weight_from_string(std::string_view rhs)
70 return font_weight_metadata.at(rhs);
72 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
76[[nodiscard]]
constexpr std::string_view to_string_view(font_weight
const& x)
noexcept
78 return font_weight_metadata[x];
81[[nodiscard]]
constexpr std::string
to_string(font_weight
const& x)
noexcept
83 return std::string{to_string_view(x)};
86[[nodiscard]]
constexpr char to_char(font_weight
const& x)
noexcept
88 hilet x_ =
static_cast<int>(x);
90 return char_cast<char>(
'0' + x_);
93[[nodiscard]]
constexpr int to_int(font_weight
const& x)
noexcept
95 hilet x_ = (
static_cast<int>(x) + 1) * 100;
96 return (x_ == 1000) ? 950 : x_;
99inline std::ostream& operator<<(std::ostream& lhs, font_weight
const& rhs)
104constexpr bool almost_equal(font_weight
const& lhs, font_weight
const& rhs)
noexcept
107 return (lhs > font_weight::medium) == (rhs > font_weight::medium);
121 auto forward =
false;
125 forward = not forward;
135 forward = not forward;
141template<
typename CharT>
142struct std::formatter<
hi::font_weight, CharT> : std::formatter<std::string_view, CharT> {
143 auto format(hi::font_weight
const& t,
auto& fc)
145 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
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:59
font_weight
Definition font_weight.hpp:17
@ medium
500: Medium
Definition font_weight.hpp:22
@ black
900: Heavy / Black
Definition font_weight.hpp:26
@ light
300: Light
Definition font_weight.hpp:20
@ semi_bold
600: Semi-bold / Demi-bold
Definition font_weight.hpp:23
@ thin
100: Thin / Hairline
Definition font_weight.hpp:18
@ bold
700: Bold
Definition font_weight.hpp:24
@ extra_light
200: Ultra-light / Extra-light
Definition font_weight.hpp:19
@ regular
400: Normal / Regular
Definition font_weight.hpp:21
@ extra_bold
800: Extra-bold / Ultra-bold
Definition font_weight.hpp:25
@ extra_black
950: Extra-black / Ultra-black
Definition font_weight.hpp:27
generator< font_weight > alternatives(font_weight start) noexcept
Generate alternatives for the font_weight.
Definition font_weight.hpp:115
geometry/margins.hpp
Definition cache.hpp:11
A return value for a generator-function.
Definition generator.hpp:29
Definition concepts.hpp:24