22 true_type_font(std::filesystem::path
const& path) : _path(path), _view(file_view{path})
24 ++global_counter<
"ttf:map">;
26 _bytes = as_span<std::byte const>(_view);
27 parse_font_directory(_bytes);
32 ++global_counter<
"ttf:unmap">;
35 throw parse_error(std::format(
"{}: Could not parse font directory.\n{}", path.string(), e.
what()));
46 [[nodiscard]]
bool loaded() const noexcept
override
48 return to_bool(_view);
54 [[nodiscard]] hi::glyph_id
find_glyph(
char32_t c)
const override;
76 [[nodiscard]]
vector2 get_kerning(hi::glyph_id current_glyph, hi::glyph_id next_glyph)
const override
79 return otype_kern_find(_kern_table_bytes, current_glyph, next_glyph, _em_scale);
90 std::filesystem::path _path;
96 mutable file_view _view;
98 float OS2_x_height = 0;
99 float OS2_cap_height = 0;
103 uint16_t numberOfHMetrics;
106 mutable std::span<std::byte const> _bytes;
107 mutable std::span<std::byte const> _loca_table_bytes;
108 mutable std::span<std::byte const> _glyf_table_bytes;
109 mutable std::span<std::byte const> _hmtx_table_bytes;
110 mutable std::span<std::byte const> _kern_table_bytes;
111 mutable std::span<std::byte const> _GSUB_table_bytes;
112 bool _loca_is_offset32;
113 font_char_map _char_map;
115 void cache_tables(std::span<std::byte const> bytes)
const
117 _loca_table_bytes = otype_sfnt_search<
"loca">(bytes);
118 _glyf_table_bytes = otype_sfnt_search<
"glyf">(bytes);
119 _hmtx_table_bytes = otype_sfnt_search<
"hmtx">(bytes);
122 _kern_table_bytes = otype_sfnt_search<
"kern">(bytes);
123 _GSUB_table_bytes = otype_sfnt_search<
"GSUB">(bytes);
126 void load_view() const noexcept
132 _view = file_view{_path};
133 _bytes = as_span<std::byte const>(_view);
134 ++global_counter<
"ttf:map">;
135 cache_tables(_bytes);
143 void parse_font_directory(std::span<std::byte const> bytes);
147 [[nodiscard]] hi::unicode_mask parse_cmap_table_mask()
const;
152 bool update_glyph_metrics(
153 hi::glyph_id glyph_id,
154 glyph_metrics &metrics,
155 hi::glyph_id kern_glyph1_id = hi::glyph_id{},
156 hi::glyph_id kern_glyph2_id = hi::glyph_id{})
const;
158 bool load_simple_glyph(std::span<std::byte const> bytes, graphic_path &glyph)
const;
169 load_compound_glyph(std::span<std::byte const> bytes, graphic_path &glyph, hi::glyph_id &metrics_glyph_id)
const;
178 bool load_compound_glyph_metrics(std::span<std::byte const> bytes, hi::glyph_id &metrics_glyph_id)
const;
186 [[nodiscard]]
std::ptrdiff_t get_coverage_index(std::span<std::byte const> bytes, hi::glyph_id glyph);
void substitution_and_kerning(iso_639 language, iso_15924 script, std::vector< substitution_and_kerning_type > &word) const override
Substitute and kern a run of glyphs.
Definition true_type_font.hpp:82
vector2 get_kerning(hi::glyph_id current_glyph, hi::glyph_id next_glyph) const override
Get the kerning between two glyphs.
Definition true_type_font.hpp:76
bool load_glyph_metrics(hi::glyph_id glyph_id, glyph_metrics &metrics, hi::glyph_id lookahead_glyph_id=hi::glyph_id{}) const override
Load a glyphMetrics into a path.