HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
font_metrics.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7namespace hi::inline v1 {
8
18 float ascender = 0.0f;
19
24 float descender = 0.0f;
25
30 float line_gap = 0.0f;
31
34 float cap_height = 0.0f;
35
38 float x_height = 0.0f;
39
44 float digit_advance = 0.0f;
45
49 float line_spacing = 1.0f;
50
54 float paragraph_spacing = 1.5f;
55
56 ~font_metrics() = default;
57 constexpr font_metrics() noexcept = default;
58 constexpr font_metrics(font_metrics const&) noexcept = default;
59 constexpr font_metrics(font_metrics&&) noexcept = default;
60 constexpr font_metrics& operator=(font_metrics const&) noexcept = default;
61 constexpr font_metrics& operator=(font_metrics&&) noexcept = default;
62 [[nodiscard]] constexpr friend bool operator==(font_metrics const&, font_metrics const&) noexcept = default;
63
66 [[nodiscard]] constexpr friend font_metrics operator*(float const& lhs, font_metrics const& rhs) noexcept
67 {
69 r.ascender = lhs * rhs.ascender;
70 r.descender = lhs * rhs.descender;
71 r.line_gap = lhs * rhs.line_gap;
72 r.cap_height = lhs * rhs.cap_height;
73 r.x_height = lhs * rhs.x_height;
74 r.digit_advance = lhs * rhs.digit_advance;
75 return r;
76 }
77
78 [[nodiscard]] constexpr friend font_metrics max(font_metrics const& a, font_metrics const& b) noexcept
79 {
81 r.ascender = std::max(a.ascender, b.ascender);
82 r.descender = std::max(a.descender, b.descender);
83 r.line_gap = std::max(a.line_gap, b.line_gap);
84 r.cap_height = std::max(a.cap_height, b.cap_height);
85 r.x_height = std::max(a.x_height, b.x_height);
86 r.digit_advance = std::max(a.digit_advance, b.digit_advance);
87 return r;
88 }
89
92 [[nodiscard]] float round_scale(float size) const noexcept
93 {
94 return std::round(x_height * size) / x_height;
95 }
96};
97
98} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:13
The metrics of a font.
Definition font_metrics.hpp:15
float descender
Distance from baseline of lowest descender.
Definition font_metrics.hpp:24
float line_gap
Distance between lines.
Definition font_metrics.hpp:30
float ascender
Distance from baseline of highest ascender.
Definition font_metrics.hpp:18
float round_scale(float size) const noexcept
Round a scale so that the scaled x-height is an integral.
Definition font_metrics.hpp:92
float x_height
Height of lower case characters without ascenders or descenders, or the small letter 'x'.
Definition font_metrics.hpp:38
float cap_height
Height of capital letter, or height of the letter 'H'.
Definition font_metrics.hpp:34
float digit_advance
The advance for digits, specifically the digit '8'.
Definition font_metrics.hpp:44
T max(T... args)
T round(T... args)