TGUI  1.3.0
Loading...
Searching...
No Matches

Wrapper around the backend-specific font. All copies of the font will share the same internal font resource. More...

#include <TGUI/Font.hpp>

Public Member Functions

 Font (std::nullptr_t=nullptr) noexcept
 Default constructor which will set the font to nullptr.
 
 Font (const String &id)
 Constructor to create the font from a string (filename by default)
 
 Font (const char *id)
 Constructor to create the font from a string (filename by default)
 
 Font (const void *data, std::size_t sizeInBytes)
 Constructor to create the font from a byte array.
 
 Font (std::shared_ptr< BackendFont > backendFont, String id)
 Constructor to create the font from an internal backend font.
 
TGUI_NODISCARD const StringgetId () const
 Returns the id that was used to load the font.
 
 operator bool () const
 Converts the font to a boolean to check if it is a nullptr of not.
 
TGUI_NODISCARD bool operator== (std::nullptr_t) const
 Compares the font with a nullptr.
 
TGUI_NODISCARD bool operator!= (std::nullptr_t) const
 Compares the font with a nullptr.
 
TGUI_NODISCARD bool operator== (const Font &right) const
 Compares the font with another one.
 
TGUI_NODISCARD bool operator!= (const Font &right) const
 Compares the font with another one.
 
TGUI_NODISCARD FontGlyph getGlyph (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0) const
 Retrieve a glyph of the font.
 
TGUI_NODISCARD float getKerning (char32_t first, char32_t second, unsigned int characterSize, bool bold=false) const
 Returns the kerning offset of two glyphs.
 
TGUI_NODISCARD float getLineSpacing (unsigned int characterSize) const
 Returns the line spacing.
 
TGUI_NODISCARD float getFontHeight (unsigned int characterSize) const
 Returns the height required to render a line of text.
 
void setSmooth (bool smooth)
 Enable or disable the smooth filter.
 
TGUI_NODISCARD bool isSmooth () const
 Tell whether the smooth filter is enabled or not.
 
TGUI_NODISCARD std::shared_ptr< BackendFontgetBackendFont () const
 Returns the internal font.
 

Static Public Member Functions

static void setGlobalFont (const Font &font)
 Changes the global font that is used for all new widgets.
 
static TGUI_NODISCARD Font getGlobalFont ()
 Returns the global font that is used for all new widgets.
 

Detailed Description

Wrapper around the backend-specific font. All copies of the font will share the same internal font resource.

Constructor & Destructor Documentation

◆ Font() [1/4]

tgui::Font::Font ( const String & id)

Constructor to create the font from a string (filename by default)

Parameters
idString to pass to the Deserializer class to load the font

◆ Font() [2/4]

tgui::Font::Font ( const char * id)

Constructor to create the font from a string (filename by default)

Parameters
idString to pass to the Deserializer class to load the font

◆ Font() [3/4]

tgui::Font::Font ( const void * data,
std::size_t sizeInBytes )

Constructor to create the font from a byte array.

Parameters
dataPointer to the file data in memory
sizeInBytesSize of the data to load, in bytes

◆ Font() [4/4]

tgui::Font::Font ( std::shared_ptr< BackendFont > backendFont,
String id )

Constructor to create the font from an internal backend font.

Parameters
backendFontInternal font to use
idId of the font (usually filename)

Member Function Documentation

◆ getBackendFont()

TGUI_NODISCARD std::shared_ptr< BackendFont > tgui::Font::getBackendFont ( ) const

Returns the internal font.

Returns
Backend font that is used internally

◆ getFontHeight()

TGUI_NODISCARD float tgui::Font::getFontHeight ( unsigned int characterSize) const

Returns the height required to render a line of text.

Parameters
characterSizeSize of the characters
Returns
Sum of font ascent and descent

◆ getGlobalFont()

static TGUI_NODISCARD Font tgui::Font::getGlobalFont ( )
static

Returns the global font that is used for all new widgets.

Returns
Global font

◆ getGlyph()

TGUI_NODISCARD FontGlyph tgui::Font::getGlyph ( char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness = 0 ) const

Retrieve a glyph of the font.

If the font is a bitmap font, not all character sizes might be available. If the glyph is not available at the requested size, an empty glyph is returned.

Parameters
codePointUnicode code point of the character to get
characterSizeReference character size
boldRetrieve the bold version or the regular one?
outlineThicknessThickness of outline (when != 0 the glyph will not be filled)
Returns
The glyph corresponding to codePoint and characterSize

◆ getId()

TGUI_NODISCARD const String & tgui::Font::getId ( ) const

Returns the id that was used to load the font.

Returns
Id of the font or an empty string when no id was passed when this object was created

◆ getKerning()

TGUI_NODISCARD float tgui::Font::getKerning ( char32_t first,
char32_t second,
unsigned int characterSize,
bool bold = false ) const

Returns the kerning offset of two glyphs.

The kerning is an extra offset (negative) to apply between two glyphs when rendering them, to make the pair look more "natural". For example, the pair "AV" have a special kerning to make them closer than other characters. Most of the glyphs pairs have a kerning offset of zero, though.

Parameters
firstUnicode code point of the first character
secondUnicode code point of the second character
characterSizeSize of the characters
boldAre the glyphs bold or regular?
Returns
Kerning value for first and second, in pixels

◆ getLineSpacing()

TGUI_NODISCARD float tgui::Font::getLineSpacing ( unsigned int characterSize) const

Returns the line spacing.

Line spacing is the vertical offset to apply between two consecutive lines of text.

Parameters
characterSizeSize of the characters
Returns
Line spacing, in pixels

◆ isSmooth()

TGUI_NODISCARD bool tgui::Font::isSmooth ( ) const

Tell whether the smooth filter is enabled or not.

Returns
True if smoothing is enabled, false if it is disabled
See also
setSmooth

◆ setGlobalFont()

static void tgui::Font::setGlobalFont ( const Font & font)
static

Changes the global font that is used for all new widgets.

Parameters
fontNew global font

◆ setSmooth()

void tgui::Font::setSmooth ( bool smooth)

Enable or disable the smooth filter.

When the filter is activated, the font appears smoother so that pixels are less noticeable. However if you want the font to look exactly the same as its source file then you should disable it. The smooth filter is enabled by default.

Parameters
smoothTrue to enable smoothing, false to disable it

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