TGUI  0.10-dev
tgui::BackendFont Class Referenceabstract

Base class for font implementations that depend on the backend. More...

#include <TGUI/Backend/Font/BackendFont.hpp>

Inheritance diagram for tgui::BackendFont:
tgui::BackendFontFreetype tgui::BackendFontSDLttf tgui::BackendFontSFML

Public Member Functions

virtual ~BackendFont ()=default
 Virtual destructor.
 
virtual bool loadFromFile (const String &filename)
 Loads a font from a file. More...
 
virtual bool loadFromMemory (std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes)=0
 Loads a font from memory. More...
 
bool loadFromMemory (const void *data, std::size_t sizeInBytes)
 Loads a font from memory. More...
 
virtual bool hasGlyph (char32_t codePoint) const =0
 Returns whether a font contains a certain glyph. More...
 
virtual FontGlyph getGlyph (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0)=0
 Retrieve a glyph of the font. More...
 
virtual float getKerning (char32_t first, char32_t second, unsigned int characterSize, bool bold)=0
 Returns the kerning offset of two glyphs. More...
 
virtual float getLineSpacing (unsigned int characterSize)=0
 Returns the line spacing. More...
 
virtual float getUnderlinePosition (unsigned int characterSize)=0
 Get the position of the underline. More...
 
virtual float getUnderlineThickness (unsigned int characterSize)=0
 Get the thickness of the underline. More...
 
virtual std::shared_ptr< BackendTexturegetTexture (unsigned int characterSize)=0
 Returns the texture that is used to store glyphs of the given character size. More...
 
virtual void setSmooth (bool smooth)
 Enable or disable the smooth filter. More...
 
bool isSmooth () const
 Tell whether the smooth filter is enabled or not. More...
 

Protected Member Functions

std::uint64_t constructGlyphKey (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness)
 Creates a key for each unique character to render. More...
 

Detailed Description

Base class for font implementations that depend on the backend.

Member Function Documentation

◆ constructGlyphKey()

std::uint64_t tgui::BackendFont::constructGlyphKey ( char32_t  codePoint,
unsigned int  characterSize,
bool  bold,
float  outlineThickness 
)
protected

Creates a key for each unique character to render.

Parameters
codePointUnicode code of the character
characterSizeReference character size
boldWhether the character has to be rendered with a bold font
outlineThicknessThickness of the outline to draw around the character (0 means no outline)
Returns
Id that is specific to the provided parameters

Calling this function with the same parameters results in the same id, while other parameters result in another id.

◆ getGlyph()

virtual FontGlyph tgui::BackendFont::getGlyph ( char32_t  codePoint,
unsigned int  characterSize,
bool  bold,
float  outlineThickness = 0 
)
pure virtual

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

Implemented in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getKerning()

virtual float tgui::BackendFont::getKerning ( char32_t  first,
char32_t  second,
unsigned int  characterSize,
bool  bold 
)
pure virtual

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

Implemented in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getLineSpacing()

virtual float tgui::BackendFont::getLineSpacing ( unsigned int  characterSize)
pure virtual

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

Implemented in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getTexture()

virtual std::shared_ptr< BackendTexture > tgui::BackendFont::getTexture ( unsigned int  characterSize)
pure virtual

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
Returns
Texture to render text glyphs with

Implemented in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getUnderlinePosition()

virtual float tgui::BackendFont::getUnderlinePosition ( unsigned int  characterSize)
pure virtual

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

Implemented in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getUnderlineThickness()

virtual float tgui::BackendFont::getUnderlineThickness ( unsigned int  characterSize)
pure virtual

Get the thickness of the underline.

Underline thickness is the vertical size of the underline.

Parameters
characterSizeReference character size
Returns
Underline thickness, in pixels

Implemented in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ hasGlyph()

virtual bool tgui::BackendFont::hasGlyph ( char32_t  codePoint) const
pure virtual

Returns whether a font contains a certain glyph.

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

Implemented in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ isSmooth()

bool tgui::BackendFont::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

◆ loadFromFile()

virtual bool tgui::BackendFont::loadFromFile ( const String filename)
virtual

Loads a font from a file.

Parameters
filenameFilename of the font to load
Returns
True if the font was loaded successfully, false otherwise

◆ 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]

virtual bool tgui::BackendFont::loadFromMemory ( std::unique_ptr< std::uint8_t[]>  data,
std::size_t  sizeInBytes 
)
pure virtual

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

Implemented in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, tgui::BackendFontSFML, tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ setSmooth()

virtual void tgui::BackendFont::setSmooth ( bool  smooth)
virtual

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 in tgui::BackendFontFreetype, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.


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