HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Static Public Member Functions
v1::font_book Class Reference

#include <hikogui/font/font_book.hpp>

Data Structures

struct  font_glyph_type
 
struct  font_glyphs_type
 

Public Member Functions

 font_book (font_book const &)=delete
 
 font_book (font_book &&)=delete
 
font_bookoperator= (font_book const &)=delete
 
font_bookoperator= (font_book &&)=delete
 
fontregister_font_file (std::filesystem::path const &path, bool post_process=true)
 Register a font.
 
void register_font_directory (std::filesystem::path const &path, bool post_process=true)
 Register all fonts found in a directory.
 
void post_process () noexcept
 Post process font_book Should be called after a set of register_font() calls This calculates font fallbacks.
 
font_family_id find_family (std::string const &family_name) const noexcept
 Find font family id.
 
font_family_id register_family (std::string_view family_name) noexcept
 Register font family id.
 
font const & find_font (font_family_id family_id, font_variant variant) const noexcept
 Find a font closest to the variant.
 
font const * find_font (std::string const &family_name, font_variant variant) const noexcept
 Find a font closest to the variant.
 
font_glyphs_type find_glyph (font const &font, hi::grapheme grapheme) const noexcept
 Find a glyph using the given code-point.
 
font_glyph_type find_glyph (font const &font, char32_t code_point) const noexcept
 Find a glyph using the given code-point.
 

Static Public Member Functions

static font_bookglobal () noexcept
 

Detailed Description

font_book keeps track of multiple fonts.

The font_book is instantiated during application startup and is available through Foundation_globals->font_book.

Member Function Documentation

◆ find_family()

font_family_id v1::font_book::find_family ( std::string const & family_name) const
inlinenoexcept

Find font family id.

This function will always return a valid font_family_id by walking the fallback-chain.

◆ find_font() [1/2]

font const & v1::font_book::find_font ( font_family_id family_id,
font_variant variant ) const
inlinenoexcept

Find a font closest to the variant.

This function will always return a valid font_id.

Parameters
family_ida valid family id.
variantThe variant of the font to select.
Returns
a valid font id.

◆ find_font() [2/2]

font const * v1::font_book::find_font ( std::string const & family_name,
font_variant variant ) const
inlinenoexcept

Find a font closest to the variant.

This function will always return a valid font_id.

Parameters
family_nameA name of a font family, which may be invalid.
weightThe weight of the font to select.
styleIf the font to select should be italic or not.
Returns
A pointer to a font, or nullptr when the family was not found.

◆ find_glyph() [1/2]

font_glyph_type v1::font_book::find_glyph ( font const & font,
char32_t code_point ) const
inlinenoexcept

Find a glyph using the given code-point.

This function will find a glyph matching the grapheme in the selected font, or find the glyph in the fallback font.

Parameters
fontThe font to use to find the grapheme in.
graphemeThe Unicode grapheme to find in the font.
Returns
A list of glyphs which matched the grapheme.

◆ find_glyph() [2/2]

font_glyphs_type v1::font_book::find_glyph ( font const & font,
hi::grapheme grapheme ) const
inlinenoexcept

Find a glyph using the given code-point.

This function will find a glyph matching the grapheme in the selected font, or find the glyph in the fallback font.

Parameters
fontThe font to use to find the grapheme in.
graphemeThe Unicode grapheme to find in the font.
Returns
A list of glyphs which matched the grapheme.

◆ post_process()

void v1::font_book::post_process ( )
inlinenoexcept

Post process font_book Should be called after a set of register_font() calls This calculates font fallbacks.

◆ register_family()

font_family_id v1::font_book::register_family ( std::string_view family_name)
inlinenoexcept

Register font family id.

If the family already exists the existing family_id is returned.

◆ register_font_directory()

void v1::font_book::register_font_directory ( std::filesystem::path const & path,
bool post_process = true )
inline

Register all fonts found in a directory.

See also
register_font()

◆ register_font_file()

font & v1::font_book::register_font_file ( std::filesystem::path const & path,
bool post_process = true )
inline

Register a font.

Duplicate registrations will be ignored.

When a font file is registered the file will be temporarily opened to read and cache a set of properties:

  • The English font Family from the 'name' table.
  • The weight, width, slant & design-size from the 'fdsc' table.
  • The character map 'cmap' table.
Parameters
pathLocation of font.
post_processCalculate font fallback

The documentation for this class was generated from the following file: