7#include "otype_utilities.hpp"
8#include "../utility/module.hpp"
9#include "../i18n/module.hpp"
13namespace hi {
inline namespace v1 {
17 big_uint16_buf_t length;
18 big_uint16_buf_t offset;
21[[nodiscard]]
inline language_tag otype_name_get_language_tag(
22 std::span<std::byte const> storage_bytes,
23 std::span<otype_name_language_entry_type const> language_tag_table,
29 return language_tag{std::string_view{
reinterpret_cast<char const *
>(tag_bytes.data()), tag_bytes.size()}};
32[[nodiscard]]
inline language_tag otype_name_get_language_unicode(
33 std::span<std::byte const> storage_bytes,
34 std::span<otype_name_language_entry_type const> language_tag_table,
37 if (language_id == 0 or language_id == 0xffff) {
41 }
else if (language_id >= 0x8000) {
43 return otype_name_get_language_tag(storage_bytes, language_tag_table, language_id);
51[[nodiscard]]
inline language_tag
52otype_name_get_language_quickdraw(std::span<std::byte const> storage_bytes, uint16_t platform_specific_id, uint16_t language_id)
54 if (platform_specific_id == 0 and language_id == 0) {
56 return language_tag{
"en"};
58 return language_tag{};
62[[nodiscard]]
inline language_tag otype_name_get_language_microsoft(
63 std::span<std::byte const> storage_bytes,
64 std::span<otype_name_language_entry_type const> language_tag_table,
67 if (language_id == 0x409) {
68 return language_tag{
"en-US"};
69 }
else if (language_id >= 0x8000) {
70 return otype_name_get_language_tag(storage_bytes, language_tag_table, language_id);
72 return language_tag{};
76[[nodiscard]]
inline language_tag otype_name_get_language(
77 std::span<std::byte const> storage_bytes,
78 std::span<otype_name_language_entry_type const> language_tag_table,
80 uint16_t platform_specific_id,
83 switch (platform_id) {
85 return otype_name_get_language_unicode(storage_bytes, language_tag_table, language_id);
87 return otype_name_get_language_quickdraw(storage_bytes, platform_specific_id, language_id);
89 return otype_name_get_language_microsoft(storage_bytes, language_tag_table, language_id);
104[[nodiscard]]
inline std::optional<std::string>
105otype_name_search(std::span<std::byte const> bytes, uint16_t name_id, language_tag language = language_tag{
"en"})
107 struct header_type_0 {
108 big_uint16_buf_t format;
109 big_uint16_buf_t count;
110 big_uint16_buf_t storage_offset;
113 struct header_type_1 : header_type_0 {
114 big_uint16_buf_t language_tag_count;
118 big_uint16_buf_t platform_id;
119 big_uint16_buf_t platform_specific_id;
120 big_uint16_buf_t language_id;
121 big_uint16_buf_t name_id;
122 big_uint16_buf_t length;
123 big_uint16_buf_t offset;
127 hilet& header = implicit_cast<header_type_0>(offset, bytes);
129 hilet format = *header.format;
130 hi_check(format == 0 or format == 1,
"'name' table must be format 0 or format 1.");
134 auto language_tag_count = 0_uz;
137 hilet header1 = implicit_cast<header_type_1>(offset, bytes);
138 language_tag_count = *header1.language_tag_count;
141 hilet language_tag_table = implicit_cast<detail::otype_name_language_entry_type>(offset, bytes, language_tag_count);
143 hilet entries = implicit_cast<entry_type>(offset, bytes, *header.count);
144 for (
hilet& entry : entries) {
145 if (*entry.name_id != name_id) {
149 hilet platform_id = *entry.platform_id;
150 hilet platform_specific_id = *entry.platform_specific_id;
152 hilet name_language = detail::otype_name_get_language(
153 storage_bytes, language_tag_table, platform_id, platform_specific_id, *entry.language_id);
155 if (not match(name_language, language)) {
161 if (
auto s = otype_get_string(name_bytes, platform_id, platform_specific_id)) {
169[[nodiscard]]
inline auto otype_name_get_family(std::span<std::byte const> bytes)
176 auto r = return_type{};
179 r.family_name =
std::move(*typographic_family_name);
181 r.family_name =
std::move(*common_family_name);
185 r.sub_family_name =
std::move(*typographic_sub_family_name);
187 r.sub_family_name =
std::move(*common_sub_family_name);
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:110
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#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
std::optional< std::string > otype_name_search(std::span< std::byte const > bytes, uint16_t name_id, language_tag language=language_tag{"en"})
Get a name from the name table.
Definition otype_name.hpp:105
Definition otype_name.hpp:16