utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::graphic::FontSized Class Reference

The FontSized class represents a specific size of a font face, managing the glyphs and texture atlas for that size. More...

#include <headers/utility/graphic/text/font_sized.hpp>

Public Member Functions

 FontSized (uint32_t fontSize, void *face)
 Constructs a FontSized object for a specific font size and corresponding FreeType face.
 
 ~FontSized ()=default
 Destructs the FontSized object, releasing any allocated resources.
 
std::shared_ptr< TexturegetAtlas (bool shouldRegenerate=false)
 Retrieves the texture atlas containing the rendered glyphs for this font size.
 
bool hasGlyph (uint32_t codePoint) const
 Checks whether a glyph has already been generated for this font size.
 
Glyph generateGlyph (uint32_t codePoint)
 Generates a glyph for a specific Unicode code point and adds it to the texture atlas.
 
std::vector< GlyphgenerateGlyphs (const codePointString &codePoints)
 Generates glyphs for a string of Unicode code points and adds them to the texture atlas.
 
Glyph measureGlyph (uint32_t codePoint) const
 Compute glyph metrics for a code point without rasterizing or mutating the texture atlas.
 

Public Attributes

float _ascender
 The ascender value for the font size, representing the height of the tallest glyph above the baseline.
 
float _descender
 The descender value for the font size, representing the depth of the lowest glyph below the baseline.
 
float _lineHeight
 The line height value for the font size, representing the vertical distance between lines of text.
 

Protected Member Functions

void generateAtlas ()
 Generates the texture atlas based on the currently generated glyphs for this font size.
 
void resizeAtlas (int newHeight)
 Grow the atlas to the given new height, preserving existing glyphs.
 

Protected Attributes

std::shared_ptr< Texture_generatedAtlas
 The font size in points for this FontSized object.
 
uint32_t _fontSize
 The font size in points for this FontSized object.
 
void * _correspondingFace
 The corresponding FreeType face associated with this FontSized object.
 
std::map< uint32_t, Glyph_generatedGlyphs
 A map storing the generated glyphs for this font size.
 
int _atlasWidth
 The width of the texture atlas.
 
int _atlasHeight
 The height of the texture atlas.
 
int _penX
 The x-coordinate of the pen for glyph placement.
 
int _penY
 The y-coordinate of the pen for glyph placement.
 
int _rowHeight
 The height of each row in the texture atlas.
 

Detailed Description

The FontSized class represents a specific size of a font face, managing the glyphs and texture atlas for that size.

The FontSized class is responsible for generating glyphs for a specific font size and managing the texture atlas that contains the rendered glyphs. It uses the FreeType library to load and render the glyphs, and it provides functionality to retrieve the generated texture atlas and glyph information for rendering text.

Definition at line 31 of file font_sized.hpp.

Constructor & Destructor Documentation

◆ FontSized()

utility::graphic::FontSized::FontSized ( uint32_t  fontSize,
void *  face 
)

Constructs a FontSized object for a specific font size and corresponding FreeType face.

This constructor initializes the FontSized object with the specified font size and the corresponding FreeType face. It sets up the necessary data structures for managing glyphs and the texture atlas for rendering text at the specified size.

Parameters
fontSizeThe font size in points for this FontSized object.
faceThe corresponding FreeType face associated with this FontSized object (opaque handle).

Definition at line 28 of file font_sized.cpp.

Member Function Documentation

◆ generateAtlas()

void utility::graphic::FontSized::generateAtlas ( )
protected

Generates the texture atlas based on the currently generated glyphs for this font size.

This method creates a texture atlas by arranging the generated glyphs in a grid and rendering them into a single Texture object. It updates the texture coordinates for each glyph based on their position in the atlas, allowing for efficient rendering of text using the associated shader.

Definition at line 212 of file font_sized.cpp.

Here is the caller graph for this function:

◆ generateGlyph()

Glyph utility::graphic::FontSized::generateGlyph ( uint32_t  codePoint)

Generates a glyph for a specific Unicode code point and adds it to the texture atlas.

This method generates a glyph for the specified Unicode code point using the FreeType library. It renders the glyph and adds it to the texture atlas managed by this FontSized object. The generated glyph information is stored in a map for later retrieval when rendering text.

Parameters
codePointThe Unicode code point for which to generate the glyph.
Returns
A Glyph object containing the information about the generated glyph, including its size, bearing, advance, and texture coordinates in the atlas.

Definition at line 58 of file font_sized.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateGlyphs()

std::vector< Glyph > utility::graphic::FontSized::generateGlyphs ( const codePointString codePoints)

Generates glyphs for a string of Unicode code points and adds them to the texture atlas.

This method takes a string of Unicode code points and generates the corresponding glyphs for each code point using the FreeType library. It renders each glyph and adds them to the texture atlas managed by this FontSized object. The generated glyph information is stored in a map for later retrieval when rendering text.

Parameters
codePointsA string of Unicode code points representing the characters for which to generate glyphs.
Returns
A vector of Glyph objects containing the information about the generated glyphs for each code point, including their size, bearing, advance, and texture coordinates in the atlas.

Definition at line 149 of file font_sized.cpp.

Here is the call graph for this function:

◆ getAtlas()

std::shared_ptr< Texture > utility::graphic::FontSized::getAtlas ( bool  shouldRegenerate = false)

Retrieves the texture atlas containing the rendered glyphs for this font size.

This method returns a shared pointer to the Texture object that contains the rendered glyphs for this font size. The texture atlas is generated based on the glyphs that have been created for this font size, and it can be used for rendering text with the associated shader.

Parameters
shouldRegenerateA boolean flag indicating whether to regenerate the texture atlas. If true, the atlas will be regenerated based on the current glyphs; if false, the existing atlas will be returned.
Returns
A shared pointer to the Texture object containing the rendered glyphs for this font size.

Definition at line 191 of file font_sized.cpp.

Here is the call graph for this function:

◆ hasGlyph()

bool utility::graphic::FontSized::hasGlyph ( uint32_t  codePoint) const

Checks whether a glyph has already been generated for this font size.

Parameters
codePointThe Unicode code point to look up.
Returns
true if the glyph exists in the atlas cache, false otherwise.

Definition at line 207 of file font_sized.cpp.

◆ measureGlyph()

Glyph utility::graphic::FontSized::measureGlyph ( uint32_t  codePoint) const

Compute glyph metrics for a code point without rasterizing or mutating the texture atlas.

Parameters
codePointThe Unicode code point to measure.
Returns
A Glyph whose size, bearing, and advance are populated; uv coordinates are zero-initialized.

Definition at line 161 of file font_sized.cpp.

Here is the caller graph for this function:

◆ resizeAtlas()

void utility::graphic::FontSized::resizeAtlas ( int  newHeight)
protected

Grow the atlas to the given new height, preserving existing glyphs.

Parameters
newHeightThe new atlas height in pixels.

Definition at line 227 of file font_sized.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ _ascender

float utility::graphic::FontSized::_ascender

The ascender value for the font size, representing the height of the tallest glyph above the baseline.

Definition at line 135 of file font_sized.hpp.

◆ _atlasHeight

int utility::graphic::FontSized::_atlasHeight
protected

The height of the texture atlas.

Definition at line 201 of file font_sized.hpp.

◆ _atlasWidth

int utility::graphic::FontSized::_atlasWidth
protected

The width of the texture atlas.

Definition at line 196 of file font_sized.hpp.

◆ _correspondingFace

void* utility::graphic::FontSized::_correspondingFace
protected

The corresponding FreeType face associated with this FontSized object.

Stored as an opaque handle to keep FreeType types out of the public API.

Definition at line 186 of file font_sized.hpp.

◆ _descender

float utility::graphic::FontSized::_descender

The descender value for the font size, representing the depth of the lowest glyph below the baseline.

Definition at line 141 of file font_sized.hpp.

◆ _fontSize

uint32_t utility::graphic::FontSized::_fontSize
protected

The font size in points for this FontSized object.

Definition at line 177 of file font_sized.hpp.

◆ _generatedAtlas

std::shared_ptr<Texture> utility::graphic::FontSized::_generatedAtlas
protected

The font size in points for this FontSized object.

Definition at line 172 of file font_sized.hpp.

◆ _generatedGlyphs

std::map<uint32_t, Glyph> utility::graphic::FontSized::_generatedGlyphs
protected

A map storing the generated glyphs for this font size.

Definition at line 191 of file font_sized.hpp.

◆ _lineHeight

float utility::graphic::FontSized::_lineHeight

The line height value for the font size, representing the vertical distance between lines of text.

Definition at line 147 of file font_sized.hpp.

◆ _penX

int utility::graphic::FontSized::_penX
protected

The x-coordinate of the pen for glyph placement.

Definition at line 206 of file font_sized.hpp.

◆ _penY

int utility::graphic::FontSized::_penY
protected

The y-coordinate of the pen for glyph placement.

Definition at line 211 of file font_sized.hpp.

◆ _rowHeight

int utility::graphic::FontSized::_rowHeight
protected

The height of each row in the texture atlas.

Definition at line 216 of file font_sized.hpp.


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