lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::ui::Font Class Reference

Font class for loading and rendering text. More...

#include <font.hpp>

Public Member Functions

 Font (const std::string &filepath, unsigned int font_size=48)
 Load a font from file.
 ~Font ()=default
 Destructor.
const Glyphget_glyph (char c) const
 Get glyph metadata for a character.
std::shared_ptr< renderer::Textureget_atlas () const
 Get the texture atlas containing all glyphs.
unsigned int get_font_size () const
 Get the font size in pixels.
float get_line_height () const
 Get the line height for this font.
float measure_text (const std::string &text) const
 Calculate the width of a text string in pixels.

Detailed Description

Font class for loading and rendering text.

The Font class uses FreeType to load TrueType fonts, generates a texture atlas containing all ASCII glyphs, and provides metrics for text rendering.

Constructor & Destructor Documentation

◆ Font()

lmgl::ui::Font::Font ( const std::string & filepath,
unsigned int font_size = 48 )

Load a font from file.

Parameters
filepathPath to the TTF/OTF font file.
font_sizeSize of the font in pixels.

Member Function Documentation

◆ get_atlas()

std::shared_ptr< renderer::Texture > lmgl::ui::Font::get_atlas ( ) const
inline

Get the texture atlas containing all glyphs.

Returns
Shared pointer to the texture atlas.

◆ get_font_size()

unsigned int lmgl::ui::Font::get_font_size ( ) const
inline

Get the font size in pixels.

Returns
Font size.

◆ get_glyph()

const Glyph & lmgl::ui::Font::get_glyph ( char c) const

Get glyph metadata for a character.

Parameters
cCharacter to get glyph for.
Returns
Const reference to the glyph data.

◆ get_line_height()

float lmgl::ui::Font::get_line_height ( ) const
inline

Get the line height for this font.

Returns
Line height in pixels.

◆ measure_text()

float lmgl::ui::Font::measure_text ( const std::string & text) const

Calculate the width of a text string in pixels.

Parameters
textText string to measure.
Returns
Width in pixels.

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