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/utility.hpp"
9#include "../macros.hpp"
10#include <span>
11#include <cstddef>
12
13hi_export_module(hikogui.font.otype_loca);
14
15hi_export namespace hi { inline namespace v1 {
16
17[[nodiscard]] inline std::pair<size_t, size_t> otype_loca16_get(std::span<std::byte const> bytes, hi::glyph_id glyph_id)
18{
19 hilet entries = implicit_cast<big_uint16_buf_t>(bytes, bytes.size() / sizeof(big_uint16_buf_t));
20 hilet first = wide_cast<size_t>(*hi_check_at(entries, *glyph_id)) * 2;
21 hilet last = wide_cast<size_t>(*hi_check_at(entries, *glyph_id + 1)) * 2;
22 hi_check(first <= last, "'loca' table has invalid entries.");
23 return {first, last};
24}
25
26[[nodiscard]] inline std::pair<size_t, size_t> otype_loca32_get(std::span<std::byte const> bytes, hi::glyph_id glyph_id)
27{
28 hilet entries = implicit_cast<big_uint32_buf_t>(bytes, bytes.size() / sizeof(big_uint32_buf_t));
29 hilet first = wide_cast<size_t>(*hi_check_at(entries, *glyph_id));
30 hilet last = wide_cast<size_t>(*hi_check_at(entries, *glyph_id + 1));
31 hi_check(first <= last, "'loca' table has invalid entries.");
32 return {first, last};
33}
34
36otype_loca_get(std::span<std::byte const> loca_bytes, hi::glyph_id glyph_id, bool loca_is_offset32)
37{
38 if (loca_is_offset32) {
39 return otype_loca32_get(loca_bytes, glyph_id);
40 } else {
41 return otype_loca16_get(loca_bytes, glyph_id);
42 }
43}
44
45[[nodiscard]] inline std::span<std::byte const> otype_loca_get(
46 std::span<std::byte const> loca_bytes,
47 std::span<std::byte const> glyf_bytes,
48 hi::glyph_id glyph_id,
50{
51 hilet[first, last] = otype_loca_get(loca_bytes, glyph_id, loca_is_offset32);
52 hilet size = last - first;
53 return hi_check_subspan(glyf_bytes, first, size);
54}
55
56}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377