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/module.hpp"
9#include <span>
10#include <cstddef>
11
12namespace hi { inline namespace v1 {
13
14[[nodiscard]] inline auto otype_hhea_parse(std::span<std::byte const> bytes, float em_scale)
15{
16 struct header_type {
17 big_int16_buf_t major_version;
18 big_int16_buf_t minor_version;
19 otype_fword_buf_t ascender;
20 otype_fword_buf_t descender;
21 otype_fword_buf_t line_gap;
22 otype_fuword_buf_t advance_width_max;
23 otype_fword_buf_t min_left_side_bearing;
24 otype_fword_buf_t min_right_side_bearing;
25 otype_fword_buf_t x_max_extent;
26 big_int16_buf_t caret_slope_rise;
27 big_int16_buf_t caret_slop_run;
28 big_int16_buf_t caret_offset;
29 big_int16_buf_t reserved_0;
30 big_int16_buf_t reserved_1;
31 big_int16_buf_t reserved_2;
32 big_int16_buf_t reserved_3;
33 big_int16_buf_t metric_data_format;
34 big_uint16_buf_t number_of_h_metrics;
35 };
36
37 struct return_type {
38 float ascender;
39 float descender;
40 float line_gap;
41 uint16_t number_of_h_metrics;
42 };
43
44 hilet& header = implicit_cast<header_type>(bytes);
45 hi_check(*header.major_version == 1 && *header.minor_version == 0, "'hhea' version is not 1.0");
46
47 auto r = return_type{};
48 r.ascender = header.ascender * em_scale;
49 r.descender = header.descender * em_scale;
50 r.line_gap = header.line_gap * em_scale;
51 r.number_of_h_metrics = *header.number_of_h_metrics;
52
53 hi_check(r.ascender > 0.0f, "'hhea' ascender must be larger than 0.0");
54 hi_check(r.descender <= 0.0f, "'hhea' descender must be less than or equal to 0.0");
55 return r;
56}
57
58}} // namespace hi::v1
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:95
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11