TGUI  1.6.1
Loading...
Searching...
No Matches
tgui::BackendFontSDLttf Class Reference

Font implementations that uses SDL_ttf to load glyphs. More...

#include <TGUI/Backend/Font/SDL_ttf/BackendFontSDLttf.hpp>

Inheritance diagram for tgui::BackendFontSDLttf:
tgui::BackendFont

Public Member Functions

 ~BackendFontSDLttf () override
 Destructor that cleans up the SDL resources.
 
bool loadFromMemory (std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes) override
 Loads a font from memory.
 
bool hasGlyph (char32_t codePoint) const override
 Returns whether a font contains a certain glyph.
 
FontGlyph getGlyph (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0) override
 Retrieve a glyph of the font.
 
float getKerning (char32_t first, char32_t second, unsigned int characterSize, bool bold) override
 Returns the kerning offset of two glyphs.
 
float getLineSpacing (unsigned int characterSize) override
 Returns the line spacing.
 
float getFontHeight (unsigned int characterSize) override
 Returns the height required to render a line of text.
 
float getAscent (unsigned int characterSize) override
 Returns the maximum height of a glyph above the baseline.
 
float getDescent (unsigned int characterSize) override
 Returns the maximum height of a glyph below the baseline.
 
float getUnderlinePosition (unsigned int characterSize) override
 Get the position of the underline.
 
float getUnderlineThickness (unsigned int characterSize) override
 Get the thickness of the underline.
 
std::shared_ptr< BackendTexturegetTexture (unsigned int characterSize, unsigned int &textureVersion) override
 Returns the texture that is used to store glyphs of the given character size.
 
Vector2u getTextureSize (unsigned int characterSize) override
 Returns the size of the texture that is used to store glyphs of the given character size.
 
void setSmooth (bool smooth) override
 Enable or disable the smooth filter.
 
void setFontScale (float scale) override
 
TTF_Font * getInternalFont (unsigned int characterSize)
 
bool loadFromMemory (const void *data, std::size_t sizeInBytes)
 Loads a font from memory.
 
- Public Member Functions inherited from tgui::BackendFont
 BackendFont ()
 Default constructor.
 
 BackendFont (const BackendFont &)
 Copy constructor.
 
 BackendFont (BackendFont &&other) noexcept
 Move constructor.
 
virtual ~BackendFont ()
 Virtual destructor.
 
BackendFontoperator= (const BackendFont &other)
 Copy assignment operator.
 
BackendFontoperator= (BackendFont &&other) noexcept
 Move assignment operator.
 
virtual bool loadFromFile (const String &filename)
 Loads a font from a file.
 
bool loadFromMemory (const void *data, std::size_t sizeInBytes)
 Loads a font from memory.
 
bool isSmooth () const
 Tell whether the smooth filter is enabled or not.
 
float getFontScale () const
 Returns the scale at which glyphs are rendered.
 

Additional Inherited Members

- Protected Member Functions inherited from tgui::BackendFont
std::uint64_t constructGlyphKey (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness) const
 Creates a key for each unique character to render.
 
- Protected Attributes inherited from tgui::BackendFont
bool m_isSmooth = true
 
float m_fontScale = 1
 

Detailed Description

Font implementations that uses SDL_ttf to load glyphs.

Member Function Documentation

◆ getAscent()

float tgui::BackendFontSDLttf::getAscent ( unsigned int characterSize)
nodiscardoverridevirtual

Returns the maximum height of a glyph above the baseline.

Parameters
characterSizeSize of the characters
Returns
Ascent of the font

Implements tgui::BackendFont.

◆ getDescent()

float tgui::BackendFontSDLttf::getDescent ( unsigned int characterSize)
nodiscardoverridevirtual

Returns the maximum height of a glyph below the baseline.

Parameters
characterSizeSize of the characters
Returns
Descent of the font

Implements tgui::BackendFont.

◆ getFontHeight()

float tgui::BackendFontSDLttf::getFontHeight ( unsigned int characterSize)
nodiscardoverridevirtual

Returns the height required to render a line of text.

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

Implements tgui::BackendFont.

◆ getGlyph()

FontGlyph tgui::BackendFontSDLttf::getGlyph ( char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness = 0 )
nodiscardoverridevirtual

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

Implements tgui::BackendFont.

◆ getKerning()

float tgui::BackendFontSDLttf::getKerning ( char32_t first,
char32_t second,
unsigned int characterSize,
bool bold )
nodiscardoverridevirtual

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

Implements tgui::BackendFont.

◆ getLineSpacing()

float tgui::BackendFontSDLttf::getLineSpacing ( unsigned int characterSize)
nodiscardoverridevirtual

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

Implements tgui::BackendFont.

◆ getTexture()

std::shared_ptr< BackendTexture > tgui::BackendFontSDLttf::getTexture ( unsigned int characterSize,
unsigned int & textureVersion )
nodiscardoverridevirtual

Returns the texture that is used to store glyphs of the given character size.

Parameters
characterSizeSize of the characters that should be part of the texture
textureVersionCounter that is incremented each time the texture is changed, returned by this function
Returns
Texture to render text glyphs with

Implements tgui::BackendFont.

◆ getTextureSize()

Vector2u tgui::BackendFontSDLttf::getTextureSize ( unsigned int characterSize)
nodiscardoverridevirtual

Returns the size of the texture that is used to store glyphs of the given character size.

Parameters
characterSizeSize of the characters that should be part of the texture
Returns
Size of the texture that holds the glyphs

Implements tgui::BackendFont.

◆ getUnderlinePosition()

float tgui::BackendFontSDLttf::getUnderlinePosition ( unsigned int characterSize)
nodiscardoverridevirtual

Get the position of the underline.

Underline position is the vertical offset to apply between the baseline and the underline.

Parameters
characterSizeReference character size
Returns
Underline position, in pixels

Implements tgui::BackendFont.

◆ getUnderlineThickness()

float tgui::BackendFontSDLttf::getUnderlineThickness ( unsigned int characterSize)
nodiscardoverridevirtual

Get the thickness of the underline.

Underline thickness is the vertical size of the underline.

Parameters
characterSizeReference character size
Returns
Underline thickness, in pixels

Implements tgui::BackendFont.

◆ hasGlyph()

bool tgui::BackendFontSDLttf::hasGlyph ( char32_t codePoint) const
nodiscardoverridevirtual

Returns whether a font contains a certain glyph.

Parameters
codePointCharacter to check
Returns
Does the font contain this character?

Implements tgui::BackendFont.

◆ loadFromMemory() [1/2]

bool tgui::BackendFont::loadFromMemory ( const void * data,
std::size_t sizeInBytes )

Loads a font from memory.

Parameters
dataPointer to the file data in memory
sizeInBytesSize of the data to load, in bytes
Returns
True if the font was loaded successfully, false otherwise

This function makes a copy of the data. Use the overload with a unique_ptr when possible to move instead of copy.

◆ loadFromMemory() [2/2]

bool tgui::BackendFontSDLttf::loadFromMemory ( std::unique_ptr< std::uint8_t[]> data,
std::size_t sizeInBytes )
overridevirtual

Loads a font from memory.

Parameters
dataMoved pointer to the file data in memory
sizeInBytesSize of the data to load, in bytes
Returns
True if the font was loaded successfully, false otherwise

Implements tgui::BackendFont.

◆ setFontScale()

void tgui::BackendFontSDLttf::setFontScale ( float scale)
overridevirtual

Reimplemented from tgui::BackendFont.

◆ setSmooth()

void tgui::BackendFontSDLttf::setSmooth ( bool smooth)
overridevirtual

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

Reimplemented from tgui::BackendFont.


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