HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
otype_hhea.hpp
1// Copyright Take Vos 2023.
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
7#include "otype_utilities.hpp"
8#include "../utility/utility.hpp"
9#include "../macros.hpp"
10#include <span>
11#include <cstddef>
12
13hi_export_module(hikogui.font.otype_hhea);
14
15hi_export namespace hi { inline namespace v1 {
16
17[[nodiscard]] inline auto otype_hhea_parse(std::span<std::byte const> bytes, float em_scale)
18{
19 struct header_type {
20 big_int16_buf_t major_version;
21 big_int16_buf_t minor_version;
22 otype_fword_buf_t ascender;
23 otype_fword_buf_t descender;
24 otype_fword_buf_t line_gap;
25 otype_fuword_buf_t advance_width_max;
26 otype_fword_buf_t min_left_side_bearing;
27 otype_fword_buf_t min_right_side_bearing;
28 otype_fword_buf_t x_max_extent;
29 big_int16_buf_t caret_slope_rise;
30 big_int16_buf_t caret_slop_run;
31 big_int16_buf_t caret_offset;
32 big_int16_buf_t reserved_0;
33 big_int16_buf_t reserved_1;
34 big_int16_buf_t reserved_2;
35 big_int16_buf_t reserved_3;
36 big_int16_buf_t metric_data_format;
37 big_uint16_buf_t number_of_h_metrics;
38 };
39
40 struct return_type {
41 float ascender;
42 float descender;
43 float line_gap;
44 uint16_t number_of_h_metrics;
45 };
46
47 auto const& header = implicit_cast<header_type>(bytes);
48 hi_check(*header.major_version == 1 && *header.minor_version == 0, "'hhea' version is not 1.0");
49
50 auto r = return_type{};
51 r.ascender = header.ascender * em_scale;
52 r.descender = header.descender * em_scale;
53 r.line_gap = header.line_gap * em_scale;
54 r.number_of_h_metrics = *header.number_of_h_metrics;
55
56 hi_check(r.ascender > 0.0f, "'hhea' ascender must be larger than 0.0");
57 hi_check(r.descender <= 0.0f, "'hhea' descender must be less than or equal to 0.0");
58 return r;
59}
60
61}} // namespace hi::v1
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20