pygfx.utils.text.FontManager

class pygfx.utils.text.FontManager

Bases: object

Storage and discovery of text glyphs.

The main purpose of the font manager is font selection, i.e. selecting a font based on the text to be rendered and a font_props object.

This manager uses a default font set based on the Noto fonts, allowing a very complete Unicode coverage, including rare and ancient scripts. Users probably don’t have the full set of Noto fonts installed. When a font is missing that the manager knows would support the text, a useful error message is produced, that includes a link to where the font can be installed from.

There is a singleton instance of this class at pygfx.utils.text.font_manager.

property default_font_props

The default font properties.

add_font_file(font_file)

Add the given font_file to the collection of fonts. The font_file can be a filename or a FontFile object. Returns the FontFile object for the font.

get_fonts()

Get a list of all registered FontFile objects. E.g. to show a list of all available fonts: for ff in font_manager.get_fonts(): print(ff.family, "-", ff.variant)

select_font(text, font_props)

Select the (best) fonts for the given text. Returns a list of (text, font_file) tuples, because different characters in the text may require different fonts.