TGUI  1.6.1
Loading...
Searching...
No Matches

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::BackendFontRaylib tgui::BackendFontSDLttf tgui::BackendFontSFML

Public Member Functions

 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.
 
virtual bool loadFromMemory (std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes)=0
 Loads a font from memory.
 
bool loadFromMemory (const void *data, std::size_t sizeInBytes)
 Loads a font from memory.
 
virtual bool hasGlyph (char32_t codePoint) const =0
 Returns whether a font contains a certain glyph.
 
virtual FontGlyph getGlyph (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0)=0
 Retrieve a glyph of the font.
 
virtual float getKerning (char32_t first, char32_t second, unsigned int characterSize, bool bold)=0
 Returns the kerning offset of two glyphs.
 
virtual float getLineSpacing (unsigned int characterSize)=0
 Returns the line spacing.
 
virtual float getFontHeight (unsigned int characterSize)=0
 Returns the height required to render a line of text.
 
virtual float getAscent (unsigned int characterSize)=0
 Returns the maximum height of a glyph above the baseline.
 
virtual float getDescent (unsigned int characterSize)=0
 Returns the maximum height of a glyph below the baseline.
 
virtual float getUnderlinePosition (unsigned int characterSize)=0
 Get the position of the underline.
 
virtual float getUnderlineThickness (unsigned int characterSize)=0
 Get the thickness of the underline.
 
virtual std::shared_ptr< BackendTexturegetTexture (unsigned int characterSize, unsigned int &textureVersion)=0
 Returns the texture that is used to store glyphs of the given character size.
 
virtual Vector2u getTextureSize (unsigned int characterSize)=0
 Returns the size of the texture that is used to store glyphs of the given character size.
 
virtual void setSmooth (bool smooth)
 Enable or disable the smooth filter.
 
bool isSmooth () const
 Tell whether the smooth filter is enabled or not.
 
virtual void setFontScale (float scale)
 
float getFontScale () const
 Returns the scale at which glyphs are rendered.
 

Protected Member Functions

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

bool m_isSmooth = true
 
float m_fontScale = 1
 

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 ) const
nodiscardprotected

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.

◆ getAscent()

virtual float tgui::BackendFont::getAscent ( unsigned int characterSize)
nodiscardpure virtual

Returns the maximum height of a glyph above the baseline.

Parameters
characterSizeSize of the characters
Returns
Ascent of the font

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

◆ getDescent()

virtual float tgui::BackendFont::getDescent ( unsigned int characterSize)
nodiscardpure virtual

Returns the maximum height of a glyph below the baseline.

Parameters
characterSizeSize of the characters
Returns
Descent of the font

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

◆ getFontHeight()

virtual float tgui::BackendFont::getFontHeight ( unsigned int characterSize)
nodiscardpure virtual

Returns the height required to render a line of text.

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

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

◆ getFontScale()

float tgui::BackendFont::getFontScale ( ) const
nodiscard

Returns the scale at which glyphs are rendered.

Text may be rendered blurry if the font scale doesn't match the ratio between the window size and gui view. Default scaling is 1. If the scale is set to 1.5 then a font with text size 20 would be internally rendered at 30px.

◆ getGlyph()

virtual FontGlyph tgui::BackendFont::getGlyph ( char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness = 0 )
nodiscardpure 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::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getKerning()

virtual float tgui::BackendFont::getKerning ( char32_t first,
char32_t second,
unsigned int characterSize,
bool bold )
nodiscardpure 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::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getLineSpacing()

virtual float tgui::BackendFont::getLineSpacing ( unsigned int characterSize)
nodiscardpure 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::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getTexture()

virtual std::shared_ptr< BackendTexture > tgui::BackendFont::getTexture ( unsigned int characterSize,
unsigned int & textureVersion )
nodiscardpure 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
textureVersionCounter that is incremented each time the texture is changed, returned by this function
Returns
Texture to render text glyphs with

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

◆ getTextureSize()

virtual Vector2u tgui::BackendFont::getTextureSize ( unsigned int characterSize)
nodiscardpure virtual

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

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

◆ getUnderlinePosition()

virtual float tgui::BackendFont::getUnderlinePosition ( unsigned int characterSize)
nodiscardpure 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::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getUnderlineThickness()

virtual float tgui::BackendFont::getUnderlineThickness ( unsigned int characterSize)
nodiscardpure 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::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ hasGlyph()

virtual bool tgui::BackendFont::hasGlyph ( char32_t codePoint) const
nodiscardpure 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::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ isSmooth()

bool tgui::BackendFont::isSmooth ( ) const
nodiscard

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


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