Aether
SDL2 based UI Framework for NX
Public Member Functions | List of all members
Aether::FontCache Class Reference

Caches SDL_ttf font objects + surfaces to reduce rendering. This class is not thread-safe, all operations should be protected from the outside by a mutex. More...

#include <FontCache.hpp>

Public Member Functions

 FontCache (Renderer *renderer)
 Pointer to main renderer in order to manipulate surfaces. More...
 
void empty ()
 Remove all cached data.
 
void setCustomFont (const std::string &path)
 Set a custom font to use before checking built-in fonts. Pass an empty string to remove. More...
 
SDL_Surface * getGlyph (const uint16_t ch, const unsigned int fontSize)
 Render the requested character. Searches a custom font first before in-built fonts. More...
 
GlyphMetrics getMetrics (const uint16_t ch, const unsigned int fontSize)
 Get the GlyphMetrics for the character at the passed font size. More...
 
 ~FontCache ()
 Cleans up all allocated resources.
 

Detailed Description

Caches SDL_ttf font objects + surfaces to reduce rendering. This class is not thread-safe, all operations should be protected from the outside by a mutex.

Note
Only one of these should be instantiated at one time.

Constructor & Destructor Documentation

◆ FontCache()

Aether::FontCache::FontCache ( Renderer renderer)

Pointer to main renderer in order to manipulate surfaces.

Initialize the font cache object + rendering backend.

Parameters
rendererPointer to main renderer

Member Function Documentation

◆ getGlyph()

SDL_Surface* Aether::FontCache::getGlyph ( const uint16_t  ch,
const unsigned int  fontSize 
)

Render the requested character. Searches a custom font first before in-built fonts.

Note
The returned surface could be removed at anytime subsequent calls, so a copy should be made unless it's immediately used.
Parameters
chUTF-8 character code
fontSizeFont size to render character with
Returns
Surface containing the rendered character.

◆ getMetrics()

GlyphMetrics Aether::FontCache::getMetrics ( const uint16_t  ch,
const unsigned int  fontSize 
)

Get the GlyphMetrics for the character at the passed font size.

Parameters
chUTf-8 character code
fontSizeFont size to get metrics for
Returns
GlyphMetrics containing metrics of glyph

◆ setCustomFont()

void Aether::FontCache::setCustomFont ( const std::string &  path)

Set a custom font to use before checking built-in fonts. Pass an empty string to remove.

Note
An invalid path will not make any changes.
Parameters
pathPath to TTF file.

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