HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
otype_loca.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 std::pair<size_t, size_t> otype_loca16_get(std::span<std::byte const> bytes, hi::glyph_id glyph_id)
15{
16 hilet entries = implicit_cast<big_uint16_buf_t>(bytes, bytes.size() / sizeof(big_uint16_buf_t));
17 hilet first = wide_cast<size_t>(*hi_check_at(entries, *glyph_id)) * 2;
18 hilet last = wide_cast<size_t>(*hi_check_at(entries, *glyph_id + 1)) * 2;
19 hi_check(first <= last, "'loca' table has invalid entries.");
20 return {first, last};
21}
22
23[[nodiscard]] inline std::pair<size_t, size_t> otype_loca32_get(std::span<std::byte const> bytes, hi::glyph_id glyph_id)
24{
25 hilet entries = implicit_cast<big_uint32_buf_t>(bytes, bytes.size() / sizeof(big_uint32_buf_t));
26 hilet first = wide_cast<size_t>(*hi_check_at(entries, *glyph_id));
27 hilet last = wide_cast<size_t>(*hi_check_at(entries, *glyph_id + 1));
28 hi_check(first <= last, "'loca' table has invalid entries.");
29 return {first, last};
30}
31
32[[nodiscard]] inline std::pair<size_t, size_t>
33otype_loca_get(std::span<std::byte const> loca_bytes, hi::glyph_id glyph_id, bool loca_is_offset32)
34{
35 if (loca_is_offset32) {
36 return otype_loca32_get(loca_bytes, glyph_id);
37 } else {
38 return otype_loca16_get(loca_bytes, glyph_id);
39 }
40}
41
42[[nodiscard]] inline std::span<std::byte const> otype_loca_get(
43 std::span<std::byte const> loca_bytes,
44 std::span<std::byte const> glyf_bytes,
45 hi::glyph_id glyph_id,
46 bool loca_is_offset32)
47{
48 hilet[first, last] = otype_loca_get(loca_bytes, glyph_id, loca_is_offset32);
49 hilet size = last - first;
50 return hi_check_subspan(glyf_bytes, first, size);
51}
52
53}} // namespace hi::v1
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:110
#define hi_check_at(span, index)
Get an element from a span, or throw a parse_error.
Definition assert.hpp:176
#define hi_check_subspan(span, offset,...)
Get a subspan, or throw a parse_error.
Definition assert.hpp:151
#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