HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
otype_coverage.hpp
1// Copyright Take Vos 2022.
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#include "true_type_font.hpp"
6#include "../geometry/module.hpp"
7#include "../telemetry/telemetry.hpp"
8#include "../utility/utility.hpp"
9#include "../parser/parser.hpp"
10#include <cstddef>
11#include <span>
12
13hi_export_module(hikogui.font.otype_coverage);
14
15hi_export namespace hi::inline v1 {
16
18 big_int16_buf_t coverage_format;
19 big_int16_buf_t glyph_count;
20};
21
23 big_int16_buf_t coverage_format;
24 big_int16_buf_t range_count;
25};
26
28 big_int16_buf_t start_glyph_id;
29 big_int16_buf_t end_glyph_id;
30 big_int16_buf_t start_coverage_index;
31};
32
33[[nodiscard]] std::ptrdiff_t true_type_font::get_coverage_index(std::span<std::byte const> bytes, hi::glyph_id glyph_id)
34{
35 std::size_t offset = 0;
36
37 hi_assert_or_return(*glyph_id >= 0 && *glyph_id < num_glyphs, -2);
38
40 if (*header1->coverage_format == 1) {
41 hilet table = make_placement_array<big_uint16_buf_t>(bytes, offset, *header1->glyph_count);
42
43 hilet it = std::lower_bound(table.begin(), table.end(), glyph_id, [](hilet &item, hilet &value) {
44 return *item < *value;
45 });
46
47 if (it != table.end() and **it == *glyph_id) {
48 return std::distance(table.begin(), it);
49 } else {
50 return -1;
51 }
52
53 } else if (*header1->coverage_format == 2) {
54 offset = 0;
56
58
59 hilet it = std::lower_bound(table.begin(), table.end(), glyph_id, [](hilet &item, hilet &value) {
60 return *item.end_glyph_id < *value;
61 });
62
63 if (it != table.end() and *it->start_glyph_id <= *glyph_id and *glyph_id <= *it->end_glyph_id) {
64 return *it->start_coverage_index + *glyph_id - *it->start_glyph_id;
65 } else {
66 return -1;
67 }
68
69 } else {
70 return -2;
71 }
72}
73
74} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Definition otype_coverage.hpp:17
Definition otype_coverage.hpp:22
Definition otype_coverage.hpp:27
Definition tagged_id.hpp:20
T distance(T... args)
T lower_bound(T... args)