7#include "glyph_metrics.hpp"
8#include "glyph_atlas_info.hpp"
9#include "glyph_ids.hpp"
10#include "font_weight.hpp"
11#include "font_variant.hpp"
12#include "font_metrics.hpp"
14#include "../unicode/gstring.hpp"
15#include "../i18n/iso_15924.hpp"
16#include "../i18n/iso_639.hpp"
17#include "../graphic_path.hpp"
18#include "../utility/module.hpp"
19#include "../hash_map.hpp"
26namespace hi::inline
v1 {
46 bool monospace =
false;
49 bool condensed =
false;
51 float optical_size = 12.0;
75 virtual ~font() =
default;
77 font& operator=(
font const&) =
delete;
85 [[nodiscard]]
virtual bool loaded() const noexcept = 0;
90 [[nodiscard]]
glyph_id find_glyph(
char32_t c) const noexcept
92 return char_map.find(
c);
158 void reserve(
size_t count)
noexcept
160 grapheme_advances.
reserve(count);
163 glyph_positions.
reserve(count);
164 glyph_bounding_rectangles.
reserve(count);
167 void scale(
float s)
noexcept
170 for (
auto& tmp : grapheme_advances) {
173 for (
auto& tmp : glyph_positions) {
176 for (
auto& tmp : glyph_bounding_rectangles) {
205 if (index >= _single_glyph_atlas_table.size()) [[unlikely]] {
206 _single_glyph_atlas_table.resize(index + 1);
208 return _single_glyph_atlas_table[index];
211 return _multi_glyph_atlas_table[glyphs];
217 return {weight, italic};
223 "{} - {}: style={}{}{}{}{}{}, features={}",
226 rhs.monospace ?
'M' :
'_',
227 rhs.serif ?
'S' :
'_',
228 rhs.italic ?
'I' :
'_',
229 rhs.condensed ?
'C' :
'_',
237 mutable hash_map<glyph_ids, glyph_atlas_info> _multi_glyph_atlas_table;
242template<
typename CharT>
243struct std::formatter<
hi::font, CharT> : formatter<std::string_view, CharT> {
244 auto format(hi::font
const& t,
auto& fc)
246 return formatter<string_view, CharT>::format(
to_string(t), fc);
Defined font_char_map type.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
font_weight
Definition font_weight.hpp:16
geometry/margins.hpp
Definition cache.hpp:11
virtual glyph_metrics get_metrics(hi::glyph_id glyph_id) const =0
Load a glyph into a path.
virtual bool loaded() const noexcept=0
Return if the font is loaded.
virtual shape_run_result_type shape_run(iso_639 language, iso_15924 script, gstring run) const =0
Shape a run of graphemes.
hi::font_metrics metrics
The metrics of a font.
Definition font.hpp:68
std::string features
A string representing the features of a font.
Definition font.hpp:62
std::string family_name
The family name as parsed from the font file.
Definition font.hpp:38
std::string sub_family_name
The sub-family name as parsed from the font file.
Definition font.hpp:44
std::vector< hi::font * > fallback_chain
List of fonts to use as a fallback for this font.
Definition font.hpp:72
virtual graphic_path get_path(hi::glyph_id glyph_id) const =0
Load a glyph into a path.
virtual float get_advance(hi::glyph_id glyph_id) const =0
Get the advance for a glyph.
lean_vector< glyph_id > find_glyph(grapheme g) const
Get the glyphs for a grapheme.
font_char_map char_map
A optimized character map.
Definition font.hpp:57
std::vector< aarectangle > glyph_bounding_rectangles
The bounding rectangle for each glyph.
Definition font.hpp:156
std::vector< float > grapheme_advances
Position of each grapheme.
Definition font.hpp:131
std::vector< size_t > glyph_count
The number of glyphs used by each grapheme.
Definition font.hpp:135
std::vector< point2 > glyph_positions
Position of each glyph.
Definition font.hpp:147
std::vector< glyph_id > glyphs
The glyphs representing all the graphemes.
Definition font.hpp:143
A font variant is one of 16 different fonts that can be part of a family.
Definition font_variant.hpp:16
Definition glyph_atlas_info.hpp:12
A set of glyph-ids of a font which composites into a single glyph.
Definition glyph_ids.hpp:135
constexpr bool has_num_glyphs() const noexcept
Check if this object contains a number of glyphs.
Definition glyph_ids.hpp:255
Definition glyph_metrics.hpp:16
A path is a vector graphics object.
Definition graphic_path.hpp:26
ISO-15924 script code.
Definition iso_15924.hpp:19
ISO-639 language code.
Definition iso_639.hpp:24
Definition language.hpp:17
Definition tagged_id.hpp:17
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:39