|
utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
|
The Font class represents a font resource that can be used to render text. More...
#include <headers/utility/graphic/text/font.hpp>
Classes | |
| struct | FontSizedKey |
| A struct representing a unique key for identifying a specific font face and size combination. More... | |
Public Member Functions | |
| Font (const std::vector< File > &fontAssets) | |
| Constructs a Font object by loading font data from the provided file assets. | |
| ~Font () | |
| Destructs the Font object, releasing any allocated resources. | |
| float | getAscender (uint32_t fontSize) const |
| Retrieves the ascender value for the specified font size. | |
| float | getDescender (uint32_t fontSize) const |
| Retrieves the descender value for the specified font size. | |
| float | getLineHeight (uint32_t fontSize) const |
| Retrieves the line height for the specified font size. | |
| std::vector< Glyph > | processCodePoints (uint32_t fontSize, const codePointString &codePoints) |
| Processes a string of Unicode code points to generate glyphs for rendering text. | |
| math::Vector2F | measureText (uint32_t fontSize, const codePointString &codePoints) const |
| Measure the bounding size of a string of code points without rasterizing or mutating any glyph atlas. | |
| std::vector< std::string > | getFontPaths (void) const |
| Retrieves the paths of the loaded font assets. | |
| bool | isLoaded (void) const |
| Checks if the font has been successfully loaded. | |
| bool | hasGlyph (char32_t codepoint) const |
| Checks if the font contains a glyph for the specified Unicode code point. | |
Public Attributes | |
| std::function< void(std::string, std::shared_ptr< Texture >)> | onNewTextureCreated |
| Member function to set a callback that is called when a new texture atlas is created for a font size. | |
Protected Member Functions | |
| std::string | _getFaceNameForGlyph (uint32_t codePoint) const |
| Retrieves the font face name associated with a specific Unicode code point. | |
Protected Attributes | |
| void * | _ftLibrary |
| FreeType library instance used for managing font resources. | |
| std::map< std::string, void * > | _faces |
| Map of font paths to their corresponding FreeType face objects. | |
| std::map< FontSizedKey, std::shared_ptr< FontSized > > | _sizes |
| Map of font sizes to their corresponding FontSized objects. | |
| std::map< std::string, std::shared_ptr< std::vector< uint8_t > > > | _faceBuffers |
| In-memory buffers backing FreeType faces. | |
The Font class represents a font resource that can be used to render text.
The Font class manages font faces and sizes, allowing you to retrieve glyph information for rendering text. It uses the FreeType library to load and manage font data.
| utility::graphic::Font::Font | ( | const std::vector< File > & | fontAssets | ) |
| utility::graphic::Font::~Font | ( | ) |
|
protected |
Retrieves the font face name associated with a specific Unicode code point.
This method determines which font face contains the glyph for the given Unicode code point and returns the corresponding font path. It is used internally to manage multiple font faces and ensure that the correct glyphs are retrieved for rendering text.
| codePoint | The Unicode code point for which to retrieve the associated font face name. |
Definition at line 210 of file font.cpp.

| float utility::graphic::Font::getAscender | ( | uint32_t | fontSize | ) | const |
Retrieves the ascender value for the specified font size.
The ascender value represents the distance from the baseline to the highest point of the font. It is used in text layout calculations to determine the vertical positioning of text.
| fontSize | The font size for which to retrieve the ascender value. |
| float utility::graphic::Font::getDescender | ( | uint32_t | fontSize | ) | const |
Retrieves the descender value for the specified font size.
The descender value represents the distance from the baseline to the lowest point of the font. It is used in text layout calculations to determine the vertical positioning of text.
| fontSize | The font size for which to retrieve the descender value. |
| std::vector< std::string > utility::graphic::Font::getFontPaths | ( | void | ) | const |
Retrieves the paths of the loaded font assets.
This method returns a vector of strings containing the paths of the font assets that were loaded into this Font object. The paths are extracted from the File objects used to initialize the Font.
| float utility::graphic::Font::getLineHeight | ( | uint32_t | fontSize | ) | const |
Retrieves the line height for the specified font size.
The line height represents the vertical distance between lines of text. It is used in text layout calculations to determine the spacing between lines of text.
| fontSize | The font size for which to retrieve the line height. |
| bool utility::graphic::Font::hasGlyph | ( | char32_t | codepoint | ) | const |
Checks if the font contains a glyph for the specified Unicode code point.
This method checks if the font has a glyph corresponding to the given Unicode code point. It can be used to determine if a particular character can be rendered using this font.
| codepoint | The Unicode code point to check for a corresponding glyph in the font. |
Definition at line 193 of file font.cpp.

| bool utility::graphic::Font::isLoaded | ( | void | ) | const |
Checks if the font has been successfully loaded.
This method checks if the FreeType library was initialized and if at least one font face was loaded. It returns true if the font is ready to be used for rendering, and false otherwise.
Definition at line 181 of file font.cpp.

| math::Vector2F utility::graphic::Font::measureText | ( | uint32_t | fontSize, |
| const codePointString & | codePoints | ||
| ) | const |
Measure the bounding size of a string of code points without rasterizing or mutating any glyph atlas.
This is a side-effect-free measurement based on glyph metrics.
| fontSize | The font size to measure with. |
| codePoints | The code points to measure. |
Definition at line 132 of file font.cpp.

| std::vector< Glyph > utility::graphic::Font::processCodePoints | ( | uint32_t | fontSize, |
| const codePointString & | codePoints | ||
| ) |
Processes a string of Unicode code points to generate glyphs for rendering text.
This method takes a string of Unicode code points and generates the corresponding glyphs for rendering text. It uses the FreeType library to load and render the glyphs, and it returns a vector of Glyph objects containing the necessary information for rendering each character.
| fontSize | The font size to use for generating the glyphs. |
| codePoints | A string of Unicode code points representing the characters for which to generate glyphs. |
Definition at line 89 of file font.cpp.

|
protected |
|
protected |
|
protected |
|
protected |
Map of font sizes to their corresponding FontSized objects.
This map stores FontSized objects for different font sizes, allowing the Font class to manage multiple sizes of the same font. Each entry maps a font size (as a uint32_t) to its corresponding FontSized object.
FontSized objects are created on demand when the getSize method is called, and they are stored in this map for future retrieval. The Font class is responsible for managing the lifetime of these FontSized objects to ensure proper resource management.
| std::function<void(std::string, std::shared_ptr<Texture>)> utility::graphic::Font::onNewTextureCreated |
Member function to set a callback that is called when a new texture atlas is created for a font size.
This callback function is invoked whenever a new texture atlas is generated for a specific font size. It allows the caller to receive the path of the font face associated with the new atlas and a shared pointer to the Texture object representing the atlas. This can be useful for updating rendering resources or performing additional processing when new glyphs are added to the atlas.