Luanti 5.16.0-dev
Loading...
Searching...
No Matches
FontEngine Class Reference

#include <fontengine.h>

Collaboration diagram for FontEngine:

Public Member Functions

 FontEngine (gui::IGUIEnvironment *env)
 ~FontEngine ()
gui::IGUIFont * getFont (FontSpec spec)
gui::IGUIFont * getFont (unsigned int font_size=FONT_SIZE_UNSPECIFIED, FontMode mode=FM_Unspecified)
unsigned int getTextHeight (const FontSpec &spec)
 get text height for a specific font
unsigned int getTextHeight (unsigned int font_size=FONT_SIZE_UNSPECIFIED, FontMode mode=FM_Unspecified)
 get text width of a text for a specific font
unsigned int getTextWidth (const std::wstring &text, const FontSpec &spec)
unsigned int getTextWidth (const std::wstring &text, unsigned int font_size=FONT_SIZE_UNSPECIFIED, FontMode mode=FM_Unspecified)
 get text width of a text for a specific font
unsigned int getTextWidth (const std::string &text, const FontSpec &spec)
unsigned int getTextWidth (const std::string &text, unsigned int font_size=FONT_SIZE_UNSPECIFIED, FontMode mode=FM_Unspecified)
unsigned int getLineHeight (const FontSpec &spec)
 get line height for a specific font (including empty room between lines)
unsigned int getLineHeight (unsigned int font_size=FONT_SIZE_UNSPECIFIED, FontMode mode=FM_Unspecified)
unsigned int getDefaultFontSize ()
 get default font size
unsigned int getFontSize (FontMode mode)
 get font size for a specific mode
void readSettings ()
 update internal parameters from settings
void handleReload ()
 reload fonts if settings were changed
void setMediaFont (const std::string &name, const std::string &data)
void clearMediaFonts ()

Private Member Functions

gui::IGUIFont * getFont (FontSpec spec, bool may_fail)
void updateCache ()
 update content of font cache in case of a setting change made it invalid
gui::IGUIFont * initFont (FontSpec spec)
 initialize a new TTF font
void updateSkin ()
 update current minetest skin with font changes
void clearCache ()
void refresh ()
 refresh after fonts have been changed
gui::SGUITTFacegetOrLoadFace (const std::string &filename)
 DISABLE_CLASS_COPY (FontEngine)

Static Private Member Functions

static void fontSettingChanged (const std::string &name, void *userdata)
 callback to be used on change of font size setting

Private Attributes

gui::IGUIEnvironment * m_env = nullptr
 pointer to irrlicht gui environment
std::recursive_mutex m_font_mutex
 mutex used to protect font init and cache
std::map< unsigned int, gui::IGUIFont * > m_font_cache [FontSpec::MAX_VARIANTS]
 internal storage for caching fonts of different size
std::unordered_map< std::string, irr_ptr< gui::SGUITTFace > > m_local_faces
 local faces, indexed by file path
std::unordered_map< std::string, irr_ptr< gui::SGUITTFace > > m_media_faces
 media-provided faces, indexed by filename (without extension)
unsigned int m_default_size [FM_MaxMode]
 default font size to use
bool m_default_bold = false
 default bold and italic
bool m_default_italic = false
bool m_needs_reload = false

Static Private Attributes

static const FontMode s_default_font_mode = FM_Standard
 default font engine mode (fixed)

Constructor & Destructor Documentation

◆ FontEngine()

FontEngine::FontEngine ( gui::IGUIEnvironment * env)

References FONT_SIZE_UNSPECIFIED, fontSettingChanged(), g_settings, m_default_size, m_env, readSettings(), and settings.

Referenced by DISABLE_CLASS_COPY(), and fontSettingChanged().

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

◆ ~FontEngine()

FontEngine::~FontEngine ( )

References clearCache(), and g_settings.

Here is the call graph for this function:

Member Function Documentation

◆ clearCache()

void FontEngine::clearCache ( )
private

References m_font_cache, and m_font_mutex.

Referenced by ~FontEngine(), and refresh().

Here is the caller graph for this function:

◆ clearMediaFonts()

void FontEngine::clearMediaFonts ( )

References m_font_mutex, m_media_faces, and refresh().

Here is the call graph for this function:

◆ DISABLE_CLASS_COPY()

FontEngine::DISABLE_CLASS_COPY ( FontEngine )
private

References FontEngine().

Here is the call graph for this function:

◆ fontSettingChanged()

void FontEngine::fontSettingChanged ( const std::string & name,
void * userdata )
staticprivate

callback to be used on change of font size setting

References FontEngine().

Referenced by FontEngine().

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

◆ getDefaultFontSize()

unsigned int FontEngine::getDefaultFontSize ( )

get default font size

References m_default_size, and s_default_font_mode.

◆ getFont() [1/3]

gui::IGUIFont * FontEngine::getFont ( FontSpec spec)

References getFont().

Referenced by getFont(), getFont(), getLineHeight(), getTextHeight(), getTextWidth(), initFont(), updateCache(), and updateSkin().

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

◆ getFont() [2/3]

gui::IGUIFont * FontEngine::getFont ( FontSpec spec,
bool may_fail )
private

References _FM_Fallback, FontSpec::bold, FM_Unspecified, FONT_SIZE_UNSPECIFIED, FontSpec::getHash(), initFont(), FontSpec::italic, m_default_size, m_font_cache, m_font_mutex, FontSpec::mode, s_default_font_mode, and FontSpec::size.

Here is the call graph for this function:

◆ getFont() [3/3]

gui::IGUIFont * FontEngine::getFont ( unsigned int font_size = FONT_SIZE_UNSPECIFIED,
FontMode mode = FM_Unspecified )
inline

References FM_Unspecified, FONT_SIZE_UNSPECIFIED, getFont(), m_default_bold, and m_default_italic.

Here is the call graph for this function:

◆ getFontSize()

unsigned int FontEngine::getFontSize ( FontMode mode)

get font size for a specific mode

References FM_Standard, FM_Unspecified, and m_default_size.

◆ getLineHeight() [1/2]

unsigned int FontEngine::getLineHeight ( const FontSpec & spec)

get line height for a specific font (including empty room between lines)

References getFont().

Referenced by getLineHeight().

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

◆ getLineHeight() [2/2]

unsigned int FontEngine::getLineHeight ( unsigned int font_size = FONT_SIZE_UNSPECIFIED,
FontMode mode = FM_Unspecified )
inline

References FM_Unspecified, FONT_SIZE_UNSPECIFIED, getLineHeight(), m_default_bold, and m_default_italic.

Here is the call graph for this function:

◆ getOrLoadFace()

gui::SGUITTFace * FontEngine::getOrLoadFace ( const std::string & filename)
private

References gui::SGUITTFace::loadFace(), and m_local_faces.

Referenced by initFont().

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

◆ getTextHeight() [1/2]

unsigned int FontEngine::getTextHeight ( const FontSpec & spec)

get text height for a specific font

References getFont().

Referenced by getTextHeight().

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

◆ getTextHeight() [2/2]

unsigned int FontEngine::getTextHeight ( unsigned int font_size = FONT_SIZE_UNSPECIFIED,
FontMode mode = FM_Unspecified )
inline

get text width of a text for a specific font

References FM_Unspecified, FONT_SIZE_UNSPECIFIED, getTextHeight(), m_default_bold, and m_default_italic.

Here is the call graph for this function:

◆ getTextWidth() [1/4]

unsigned int FontEngine::getTextWidth ( const std::string & text,
const FontSpec & spec )
inline

References getTextWidth(), and utf8_to_wide().

Here is the call graph for this function:

◆ getTextWidth() [2/4]

unsigned int FontEngine::getTextWidth ( const std::string & text,
unsigned int font_size = FONT_SIZE_UNSPECIFIED,
FontMode mode = FM_Unspecified )
inline

References FM_Unspecified, FONT_SIZE_UNSPECIFIED, getTextWidth(), m_default_bold, m_default_italic, and utf8_to_wide().

Here is the call graph for this function:

◆ getTextWidth() [3/4]

unsigned int FontEngine::getTextWidth ( const std::wstring & text,
const FontSpec & spec )

References getFont().

Referenced by getTextWidth(), getTextWidth(), and getTextWidth().

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

◆ getTextWidth() [4/4]

unsigned int FontEngine::getTextWidth ( const std::wstring & text,
unsigned int font_size = FONT_SIZE_UNSPECIFIED,
FontMode mode = FM_Unspecified )
inline

get text width of a text for a specific font

References FM_Unspecified, FONT_SIZE_UNSPECIFIED, getTextWidth(), m_default_bold, and m_default_italic.

Here is the call graph for this function:

◆ handleReload()

void FontEngine::handleReload ( )

reload fonts if settings were changed

References m_needs_reload, and readSettings().

Here is the call graph for this function:

◆ initFont()

gui::IGUIFont * FontEngine::initFont ( FontSpec spec)
private

initialize a new TTF font

References _FM_Fallback, FontSpec::allow_server_media, FontSpec::bold, gui::CGUITTFont::createTTFont(), errorstream, FM_Mono, FM_Unspecified, FONT_SIZE_UNSPECIFIED, g_settings, RenderingEngine::getDisplayDensity(), getFont(), Settings::getLayer(), getOrLoadFace(), infostream, FontSpec::italic, m_env, m_media_faces, FontSpec::mode, rangelim(), sanity_check, FontSpec::size, and SL_DEFAULTS.

Referenced by getFont().

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

◆ readSettings()

void FontEngine::readSettings ( )

update internal parameters from settings

References _FM_Fallback, FM_Mono, FM_Standard, g_settings, m_default_bold, m_default_italic, m_default_size, rangelim(), and refresh().

Referenced by FontEngine(), and handleReload().

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

◆ refresh()

void FontEngine::refresh ( )
private

refresh after fonts have been changed

References clearCache(), updateCache(), and updateSkin().

Referenced by clearMediaFonts(), readSettings(), and setMediaFont().

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

◆ setMediaFont()

void FontEngine::setMediaFont ( const std::string & name,
const std::string & data )

References gui::SGUITTFace::createFace(), m_media_faces, refresh(), and warningstream.

Here is the call graph for this function:

◆ updateCache()

void FontEngine::updateCache ( )
private

update content of font cache in case of a setting change made it invalid

References FM_Unspecified, FONT_SIZE_UNSPECIFIED, and getFont().

Referenced by refresh().

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

◆ updateSkin()

void FontEngine::updateSkin ( )
private

update current minetest skin with font changes

References getFont(), and m_env.

Referenced by refresh().

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

Member Data Documentation

◆ m_default_bold

bool FontEngine::m_default_bold = false
private

default bold and italic

Referenced by getFont(), getLineHeight(), getTextHeight(), getTextWidth(), getTextWidth(), and readSettings().

◆ m_default_italic

bool FontEngine::m_default_italic = false
private

◆ m_default_size

unsigned int FontEngine::m_default_size[FM_MaxMode]
private

default font size to use

Referenced by FontEngine(), getDefaultFontSize(), getFont(), getFontSize(), and readSettings().

◆ m_env

gui::IGUIEnvironment* FontEngine::m_env = nullptr
private

pointer to irrlicht gui environment

Referenced by FontEngine(), initFont(), and updateSkin().

◆ m_font_cache

std::map<unsigned int, gui::IGUIFont*> FontEngine::m_font_cache[FontSpec::MAX_VARIANTS]
private

internal storage for caching fonts of different size

Referenced by clearCache(), and getFont().

◆ m_font_mutex

std::recursive_mutex FontEngine::m_font_mutex
private

mutex used to protect font init and cache

Referenced by clearCache(), clearMediaFonts(), and getFont().

◆ m_local_faces

std::unordered_map<std::string, irr_ptr<gui::SGUITTFace> > FontEngine::m_local_faces
private

local faces, indexed by file path

Referenced by getOrLoadFace().

◆ m_media_faces

std::unordered_map<std::string, irr_ptr<gui::SGUITTFace> > FontEngine::m_media_faces
private

media-provided faces, indexed by filename (without extension)

Referenced by clearMediaFonts(), initFont(), and setMediaFont().

◆ m_needs_reload

bool FontEngine::m_needs_reload = false
private

Referenced by handleReload().

◆ s_default_font_mode

const FontMode FontEngine::s_default_font_mode = FM_Standard
staticprivate

default font engine mode (fixed)

Referenced by getDefaultFontSize(), and getFont().


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