7#include "otype_utilities.hpp"
8#include "../utility/utility.hpp"
9#include "../i18n/i18n.hpp"
10#include "../macros.hpp"
14hi_export_module(hikogui.font.otype_name);
16hi_export
namespace hi {
inline namespace v1 {
24[[nodiscard]]
inline language_tag otype_name_get_language_tag(
25 std::span<std::byte const> storage_bytes,
26 std::span<otype_name_language_entry_type const> language_tag_table,
29 hi_axiom(language_id >= 0x8000);
30 auto const& entry = hi_check_at(language_tag_table, language_id - 0x8000);
31 auto const tag_bytes = hi_check_subspan(storage_bytes, *entry.offset, *entry.length);
32 return language_tag{std::string_view{
reinterpret_cast<char const *
>(tag_bytes.data()), tag_bytes.size()}};
35[[nodiscard]]
inline language_tag otype_name_get_language_unicode(
36 std::span<std::byte const> storage_bytes,
37 std::span<otype_name_language_entry_type const> language_tag_table,
40 if (language_id == 0 or language_id == 0xffff) {
44 }
else if (language_id >= 0x8000) {
46 return otype_name_get_language_tag(storage_bytes, language_tag_table, language_id);
54[[nodiscard]]
inline language_tag
55otype_name_get_language_quickdraw(std::span<std::byte const> storage_bytes, uint16_t platform_specific_id, uint16_t language_id)
57 if (platform_specific_id == 0 and language_id == 0) {
59 return language_tag{
"en"};
61 return language_tag{};
65[[nodiscard]]
inline language_tag otype_name_get_language_microsoft(
66 std::span<std::byte const> storage_bytes,
67 std::span<otype_name_language_entry_type const> language_tag_table,
70 if (language_id == 0x409) {
71 return language_tag{
"en-US"};
72 }
else if (language_id >= 0x8000) {
73 return otype_name_get_language_tag(storage_bytes, language_tag_table, language_id);
75 return language_tag{};
79[[nodiscard]]
inline language_tag otype_name_get_language(
80 std::span<std::byte const> storage_bytes,
81 std::span<otype_name_language_entry_type const> language_tag_table,
83 uint16_t platform_specific_id,
86 switch (platform_id) {
88 return otype_name_get_language_unicode(storage_bytes, language_tag_table, language_id);
90 return otype_name_get_language_quickdraw(storage_bytes, platform_specific_id, language_id);
92 return otype_name_get_language_microsoft(storage_bytes, language_tag_table, language_id);
107[[nodiscard]]
inline std::optional<std::string>
110 struct header_type_0 {
111 big_uint16_buf_t format;
112 big_uint16_buf_t count;
113 big_uint16_buf_t storage_offset;
116 struct header_type_1 : header_type_0 {
117 big_uint16_buf_t language_tag_count;
121 big_uint16_buf_t platform_id;
122 big_uint16_buf_t platform_specific_id;
123 big_uint16_buf_t language_id;
124 big_uint16_buf_t name_id;
125 big_uint16_buf_t length;
126 big_uint16_buf_t offset;
130 auto const& header = implicit_cast<header_type_0>(offset, bytes);
132 auto const format = *header.format;
133 hi_check(format == 0 or format == 1,
"'name' table must be format 0 or format 1.");
135 auto const storage_bytes = hi_check_subspan(bytes, *header.storage_offset);
137 auto language_tag_count = 0_uz;
140 auto const header1 = implicit_cast<header_type_1>(offset, bytes);
141 language_tag_count = *header1.language_tag_count;
144 auto const language_tag_table = implicit_cast<detail::otype_name_language_entry_type>(offset, bytes, language_tag_count);
146 auto const entries = implicit_cast<entry_type>(offset, bytes, *header.count);
147 for (
auto const& entry : entries) {
148 if (*entry.name_id != name_id) {
152 auto const platform_id = *entry.platform_id;
153 auto const platform_specific_id = *entry.platform_specific_id;
155 auto const name_language = detail::otype_name_get_language(
156 storage_bytes, language_tag_table, platform_id, platform_specific_id, *entry.language_id);
158 if (not
matches(name_language, language)) {
162 auto const name_bytes = hi_check_subspan(storage_bytes, *entry.offset, *entry.length);
164 if (
auto s = otype_get_string(name_bytes, platform_id, platform_specific_id)) {
172[[nodiscard]]
inline auto otype_name_get_family(std::span<std::byte const> bytes)
179 auto r = return_type{};
182 r.family_name =
std::move(*typographic_family_name);
184 r.family_name =
std::move(*common_family_name);
188 r.sub_family_name =
std::move(*typographic_sub_family_name);
190 r.sub_family_name =
std::move(*common_sub_family_name);
The HikoGUI namespace.
Definition array_generic.hpp:20
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:108
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
constexpr bool matches(phrasing_mask const &lhs, phrasing const &rhs) noexcept
Check if the text-phrasing is included in the text-phrasing-mask.
Definition phrasing.hpp:230
Definition otype_name.hpp:19
The IETF BCP 47 language tag.
Definition language_tag_intf.hpp:30