TGUI  1.3-dev
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 TGUI_NODISCARD bool hasGlyph (char32_t codePoint) const =0
 Returns whether a font contains a certain glyph.
 
virtual TGUI_NODISCARD FontGlyph getGlyph (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0)=0
 Retrieve a glyph of the font.
 
virtual TGUI_NODISCARD float getKerning (char32_t first, char32_t second, unsigned int characterSize, bool bold)=0
 Returns the kerning offset of two glyphs.
 
virtual TGUI_NODISCARD float getLineSpacing (unsigned int characterSize)=0
 Returns the line spacing.
 
virtual TGUI_NODISCARD float getFontHeight (unsigned int characterSize)=0
 Returns the height required to render a line of text.
 
virtual TGUI_NODISCARD float getAscent (unsigned int characterSize)=0
 Returns the maximum height of a glyph above the baseline.
 
virtual TGUI_NODISCARD float getDescent (unsigned int characterSize)=0
 Returns the maximum height of a glyph below the baseline.
 
virtual TGUI_NODISCARD float getUnderlinePosition (unsigned int characterSize)=0
 Get the position of the underline.
 
virtual TGUI_NODISCARD float getUnderlineThickness (unsigned int characterSize)=0
 Get the thickness of the underline.
 
virtual TGUI_NODISCARD 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 TGUI_NODISCARD 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.
 
TGUI_NODISCARD bool isSmooth () const
 Tell whether the smooth filter is enabled or not.
 
virtual void setFontScale (float scale)
 
TGUI_NODISCARD float getFontScale () const
 Returns the scale at which glyphs are rendered.
 

Protected Member Functions

TGUI_NODISCARD 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()

TGUI_NODISCARD std::uint64_t tgui::BackendFont::constructGlyphKey ( char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness ) const
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.

◆ getAscent()

virtual TGUI_NODISCARD float tgui::BackendFont::getAscent ( unsigned int characterSize)
pure 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 TGUI_NODISCARD float tgui::BackendFont::getDescent ( unsigned int characterSize)
pure 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 TGUI_NODISCARD float tgui::BackendFont::getFontHeight ( unsigned int characterSize)
pure 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()

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

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

◆ getKerning()

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

◆ getLineSpacing()

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

◆ getTexture()

virtual TGUI_NODISCARD std::shared_ptr< BackendTexture > tgui::BackendFont::getTexture ( unsigned int characterSize,
unsigned int & textureVersion )
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
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 TGUI_NODISCARD Vector2u tgui::BackendFont::getTextureSize ( unsigned int characterSize)
pure 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 TGUI_NODISCARD 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::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.

◆ getUnderlineThickness()

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

◆ hasGlyph()

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

◆ isSmooth()

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