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
48 [[nodiscard]] constexpr friend font_metrics operator*(float const &lhs, font_metrics const &rhs) noexcept
49 {
51 r.ascender = lhs * rhs.ascender;
52 r.descender = lhs * rhs.descender;
53 r.line_gap = lhs * rhs.line_gap;
54 r.cap_height = lhs * rhs.cap_height;
55 r.x_height = lhs * rhs.x_height;
56 r.digit_advance = lhs * rhs.digit_advance;
57 return r;
58 }
59
60 [[nodiscard]] constexpr friend font_metrics max(font_metrics const &a, font_metrics const &b) noexcept
61 {
63 r.ascender = std::max(a.ascender, b.ascender);
64 r.descender = std::max(a.descender, b.descender);
65 r.line_gap = std::max(a.line_gap, b.line_gap);
66 r.cap_height = std::max(a.cap_height, b.cap_height);
67 r.x_height = std::max(a.x_height, b.x_height);
68 r.digit_advance = std::max(a.digit_advance, b.digit_advance);
69 return r;
70 }
71
74 [[nodiscard]] float round_scale(float size) const noexcept
75 {
76 return std::round(x_height * size) / x_height;
77 }
78};
79
80} // namespace hi::inline v1
The metrics of a font.
Definition font_metrics.hpp:15
float descender
Distance from baseline of lowest descender.
Definition font_metrics.hpp:24
constexpr friend font_metrics operator*(float const &lhs, font_metrics const &rhs) noexcept
Scale the metrics by a scalar value.
Definition font_metrics.hpp:48
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:74
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)