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/module.hpp"
9#include <span>
10#include <cstddef>
11
12namespace hi {
13inline namespace v1 {
14
15template<fixed_string Name>
16[[nodiscard]] inline std::span<std::byte const> otype_sfnt_search(std::span<std::byte const> bytes)
17{
18 struct header_type {
19 big_uint32_buf_t scaler_type;
20 big_uint16_buf_t num_tables;
21 big_uint16_buf_t search_range;
22 big_uint16_buf_t entry_selector;
23 big_uint16_buf_t range_shift;
24 };
25
26 struct entry_type {
27 big_uint32_buf_t tag;
28 big_uint32_buf_t check_sum;
29 big_uint32_buf_t offset;
30 big_uint32_buf_t length;
31 };
32
33 std::size_t offset = 0;
34 hilet& header = implicit_cast<header_type>(offset, bytes);
35
36 if (not (*header.scaler_type == "true"_fcc or *header.scaler_type == 0x00010000)) {
37 throw parse_error("sfnt.scalerType is not 'true' or 0x00010000");
38 }
39
40 hilet entries = implicit_cast<entry_type>(offset, bytes, *header.num_tables);
41
42 if (hilet entry = fast_binary_search_eq<std::endian::big>(entries, fourcc<Name>())) {
43 return hi_check_subspan(bytes, *entry->offset, *entry->length);
44 } else {
45 return {};
46 }
47}
48
49}}
#define hi_check_subspan(span, offset,...)
Get a subspan, or throw a parse_error.
Definition assert.hpp:136
#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