7#include "otype_utilities.hpp"
9#include "../macros.hpp"
11hi_export_module(hikogui.font.otype_cmap);
13hi_export
namespace hi {
inline namespace v1 {
15[[
nodiscard]] hi_inline std::span<std::byte const>
24 big_uint16_buf_t platform_id;
25 big_uint16_buf_t platform_specific_id;
26 big_uint32_buf_t offset;
32 hi_check(*
header.version == 0,
"CMAP version is not 0");
38 return hi_check_subspan(
bytes, *
entry->offset);
47 big_uint16_buf_t format;
48 big_uint16_buf_t length;
49 big_uint16_buf_t language;
58 hi_axiom(*
header.format == 4);
59 auto const length = *
header.length;
65 offset +=
sizeof(uint16_t);
75 auto r = font_char_map{};
82 hi_check(start_code_point <= end_code_point,
"'cmap' subtable 4, start code-point must come before end code-point.");
85 "'cmap' subtable 4, all entries must be non-overlapping and ordered.");
87 if (start_code_point == 0xffff
and end_code_point == 0xffff) {
99 start_glyph_id + (end_code_point - start_code_point) + 1
_uz < 0xffff,
100 "'cmap' subtable 4, glyph_id must be in range 0 to 0xfffe.");
101 r.add(start_code_point, end_code_point, start_glyph_id);
118 hi_check(glyph_id < 0xfffe,
"'cmap' subtable 4, glyph_id must be in range 0 to 0xfffe.");
119 r.add(code_point, code_point, glyph_id);
133 big_uint16_buf_t format;
134 big_uint16_buf_t length;
135 big_uint16_buf_t language;
142 hi_axiom(*
header.format == 6);
148 auto r = font_char_map{};
152 auto const glyph_id = *
entries[i];
153 hi_check(glyph_id < 0xfffe,
"'cmap' subtable 6, glyph_id must be in range 0 to 0xfffe.");
154 r.add(code_point, code_point, glyph_id);
165 big_uint16_buf_t format;
167 big_uint32_buf_t length;
168 big_uint32_buf_t language;
173 big_uint32_buf_t start_char_code;
174 big_uint32_buf_t end_char_code;
175 big_uint32_buf_t start_glyph_id;
180 hi_axiom(*
header.format == 12);
185 auto r = font_char_map{};
186 r.reserve(*
header.num_groups);
190 hi_check(start_code_point <= end_code_point,
"'cmap' subtable 12, has invalid code-point range.");
192 auto const start_glyph_id = *
entry.start_glyph_id;
194 start_glyph_id + (end_code_point - start_code_point) + 1
_uz < 0xffff,
195 "'cmap' subtable 12, glyph_id must be in range 0 to 0xfffe.");
204[[
nodiscard]] hi_inline font_char_map otype_cmap_parse_map(std::span<std::byte const>
bytes)
211 return otype_cmap_parse_map_4(
bytes);
213 return otype_cmap_parse_map_6(
bytes);
215 return otype_cmap_parse_map_12(
bytes);
222[[
nodiscard]] hi_inline font_char_map otype_cmap_parse(std::span<std::byte const>
bytes)
236 if (
auto r = otype_cmap_parse_map(
map_bytes);
not r.empty()) {
242 throw parse_error(
"'cmap' no compatible character map found.");
Defined font_char_map type.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378