HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
otype_sfnt.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_sfnt);
14
15hi_export namespace hi {
16inline namespace v1 {
17
18template<fixed_string Name>
19[[nodiscard]] inline std::span<std::byte const> otype_sfnt_search(std::span<std::byte const> bytes)
20{
21 struct header_type {
22 big_uint32_buf_t scaler_type;
23 big_uint16_buf_t num_tables;
24 big_uint16_buf_t search_range;
25 big_uint16_buf_t entry_selector;
26 big_uint16_buf_t range_shift;
27 };
28
29 struct entry_type {
30 big_uint32_buf_t tag;
31 big_uint32_buf_t check_sum;
32 big_uint32_buf_t offset;
33 big_uint32_buf_t length;
34 };
35
36 std::size_t offset = 0;
37 auto const& header = implicit_cast<header_type>(offset, bytes);
38
39 if (not (*header.scaler_type == "true"_fcc or *header.scaler_type == 0x00010000)) {
40 throw parse_error("sfnt.scalerType is not 'true' or 0x00010000");
41 }
42
43 auto const entries = implicit_cast<entry_type>(offset, bytes, *header.num_tables);
44
45 if (auto const entry = fast_binary_search_eq<std::endian::big>(entries, fourcc<Name>())) {
46 return hi_check_subspan(bytes, *entry->offset, *entry->length);
47 } else {
48 return {};
49 }
50}
51
52}}
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20