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/unicode.hpp"
14#include "../i18n/i18n.hpp"
15#include "../graphic_path/graphic_path.hpp"
16#include "../utility/utility.hpp"
17#include "../container/container.hpp"
23hi_export_module(hikogui.font.font);
25hi_export
namespace hi::inline
v1 {
45 bool monospace =
false;
47 font_style style = font_style::normal;
48 bool condensed =
false;
50 float optical_size = 12.0;
72 virtual ~font() =
default;
74 font& operator=(
font const&) =
delete;
82 [[nodiscard]]
virtual bool loaded() const noexcept = 0;
87 [[nodiscard]]
glyph_id find_glyph(
char32_t c) const noexcept
89 return char_map.find(c);
98 auto r = lean_vector<glyph_id>{};
182 void reserve(
size_t count)
noexcept
187 glyph_positions.
reserve(count);
188 glyph_rectangles.
reserve(count);
200 for (
auto& tmp : advances) {
203 for (
auto& tmp : glyph_positions) {
206 for (
auto& tmp : glyph_rectangles) {
233 if (*glyph >= _glyph_atlas_table.size()) [[unlikely]] {
234 _glyph_atlas_table.resize(*glyph + 1);
237 hi_axiom_bounds(*glyph, _glyph_atlas_table);
238 return _glyph_atlas_table[*glyph];
243 return {weight, style};
249 "{} - {}: style={}{}{}{}{}{}, features={}",
252 rhs.monospace ?
'M' :
'_',
253 rhs.serif ?
'S' :
'_',
255 rhs.condensed ?
'C' :
'_',
269struct std::formatter<
hi::font, char> : formatter<std::string_view, char> {
270 auto format(hi::font
const& t,
auto& fc)
const
272 return formatter<string_view, char>::format(
to_string(t), fc);
Defined font_char_map type.
The HikoGUI namespace.
Definition array_generic.hpp:20
font_style
The different styles a font-family comes with.
Definition font_style.hpp:27
@ italic
A font that is italic.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
font_weight
Definition font_weight.hpp:21
hi_export auto find_glyph(font const &font, grapheme grapheme) noexcept
Find a glyph using the given code-point.
Definition font_book.hpp:440
Definition font_font.hpp:31
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.
font_metrics_em metrics
The metrics of a font.
Definition font_font.hpp:65
std::string features
A string representing the features of a font.
Definition font_font.hpp:61
std::string family_name
The family name as parsed from the font file.
Definition font_font.hpp:37
std::string sub_family_name
The sub-family name as parsed from the font file.
Definition font_font.hpp:43
std::vector< hi::font * > fallback_chain
List of fonts to use as a fallback for this font.
Definition font_font.hpp:69
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.
Definition font_font.hpp:95
font_char_map char_map
A optimized character map.
Definition font_font.hpp:56
Definition font_font.hpp:153
std::vector< size_t > glyph_count
The number of glyphs used by each grapheme.
Definition font_font.hpp:160
std::vector< point2 > glyph_positions
Position of each glyph, relative to the grapheme.
Definition font_font.hpp:174
std::vector< float > advances
The horizontal advance of each grapheme.
Definition font_font.hpp:156
std::vector< glyph_id > glyphs
The glyphs representing all the graphemes.
Definition font_font.hpp:168
void scale_and_offset(float s) noexcept
Scale and position the result of the run.
Definition font_font.hpp:196
std::vector< aarectangle > glyph_rectangles
The bounding rectangle for each glyph, relative to glyph_position.
Definition font_font.hpp:180
A font variant is one of 16 different fonts that can be part of a family.
Definition font_variant.hpp:27
Definition glyph_atlas_info.hpp:16
Definition glyph_metrics.hpp:20
ISO-639 language code.
Definition iso_639.hpp:29
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:167
constexpr std::u32string decomposed(unicode_normalize_config config=unicode_normalize_config::NFD()) const noexcept
Get a list of code-point normalized to NFD.
Definition grapheme.hpp:455
constexpr std::u32string composed() const noexcept
Get a list of code-point normalized to NFC.
Definition grapheme.hpp:443
Definition tagged_id.hpp:26