7#include "glyph_metrics.hpp"
8#include "glyph_atlas_info.hpp"
9#include "font_weight.hpp"
10#include "font_variant.hpp"
11#include "font_metrics.hpp"
13#include "../unicode/module.hpp"
14#include "../i18n/module.hpp"
15#include "../graphic_path.hpp"
16#include "../utility/module.hpp"
17#include "../hash_map.hpp"
24namespace hi::inline
v1 {
44 bool monospace =
false;
46 font_style style = font_style::normal;
47 bool condensed =
false;
49 float optical_size = 12.0;
73 virtual ~font() =
default;
75 font& operator=(
font const&) =
delete;
83 [[nodiscard]]
virtual bool loaded() const noexcept = 0;
88 [[nodiscard]]
glyph_id find_glyph(
char32_t c) const noexcept
90 return char_map.find(c);
155 void reserve(
size_t count)
noexcept
160 glyph_positions.
reserve(count);
161 glyph_rectangles.
reserve(count);
173 for (
auto& tmp : advances) {
176 for (
auto& tmp : glyph_positions) {
179 for (
auto& tmp : glyph_rectangles) {
206 if (*glyph >= _glyph_atlas_table.size()) [[unlikely]] {
207 _glyph_atlas_table.resize(*glyph + 1);
211 return _glyph_atlas_table[*glyph];
216 return {weight, style};
222 "{} - {}: style={}{}{}{}{}{}, features={}",
225 rhs.monospace ?
'M' :
'_',
226 rhs.serif ?
'S' :
'_',
228 rhs.condensed ?
'C' :
'_',
240template<
typename CharT>
241struct std::formatter<
hi::font, CharT> : formatter<std::string_view, CharT> {
242 auto format(hi::font
const& t,
auto& fc)
244 return formatter<string_view, CharT>::format(
to_string(t), fc);
Defined font_char_map type.
#define hi_axiom_bounds(x,...)
Specify an axiom that the value is within bounds.
Definition assert.hpp:264
DOXYGEN BUG.
Definition algorithm.hpp:13
font_weight
Definition font_weight.hpp:17
geometry/margins.hpp
Definition cache.hpp:11
font_style
The different styles a font-family comes with.
Definition font_style.hpp:24
@ italic
A font that is italic.
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:66
std::string features
A string representing the features of a font.
Definition font.hpp:60
std::string family_name
The family name as parsed from the font file.
Definition font.hpp:36
std::string sub_family_name
The sub-family name as parsed from the font file.
Definition font.hpp:42
std::vector< hi::font * > fallback_chain
List of fonts to use as a fallback for this font.
Definition font.hpp:70
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:55
std::vector< size_t > glyph_count
The number of glyphs used by each grapheme.
Definition font.hpp:133
std::vector< point2 > glyph_positions
Position of each glyph, relative to the grapheme.
Definition font.hpp:147
std::vector< float > advances
The horizontal advance of each grapheme.
Definition font.hpp:129
std::vector< glyph_id > glyphs
The glyphs representing all the graphemes.
Definition font.hpp:141
void scale_and_offset(float s) noexcept
Scale and position the result of the run.
Definition font.hpp:169
std::vector< aarectangle > glyph_rectangles
The bounding rectangle for each glyph, relative to glyph_position.
Definition font.hpp:153
A font variant is one of 16 different fonts that can be part of a family.
Definition font_variant.hpp:17
Definition glyph_atlas_info.hpp:12
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:17
ISO-639 language code.
Definition iso_639.hpp:23
Definition tagged_id.hpp:17
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:42