TGUI  1.2.0
Loading...
Searching...
No Matches

Font implementations that uses FreeType directly to load glyphs. More...

#include <TGUI/Backend/Font/FreeType/BackendFontFreeType.hpp>

Inheritance diagram for tgui::BackendFontFreetype:
tgui::BackendFont

Classes

struct  Glyph
 
struct  Row
 

Public Member Functions

 ~BackendFontFreetype () override
 Destructor that cleans up the FreeType resources.
 
bool loadFromMemory (std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes) override
 Loads a font from memory.
 
TGUI_NODISCARD bool hasGlyph (char32_t codePoint) const override
 Returns whether a font contains a certain glyph.
 
TGUI_NODISCARD FontGlyph getGlyph (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0) override
 Retrieve a glyph of the font.
 
TGUI_NODISCARD float getKerning (char32_t first, char32_t second, unsigned int characterSize, bool bold) override
 Returns the kerning offset of two glyphs.
 
TGUI_NODISCARD float getLineSpacing (unsigned int characterSize) override
 Returns the line spacing.
 
TGUI_NODISCARD float getFontHeight (unsigned int characterSize) override
 Returns the height required to render a line of text.
 
TGUI_NODISCARD float getAscent (unsigned int characterSize) override
 Returns the maximum height of a glyph above the baseline.
 
TGUI_NODISCARD float getDescent (unsigned int characterSize) override
 Returns the maximum height of a glyph below the baseline.
 
TGUI_NODISCARD float getUnderlinePosition (unsigned int characterSize) override
 Get the position of the underline.
 
TGUI_NODISCARD float getUnderlineThickness (unsigned int characterSize) override
 Get the thickness of the underline.
 
TGUI_NODISCARD 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.
 
TGUI_NODISCARD 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
 
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.
 
- 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.
 
TGUI_NODISCARD bool isSmooth () const
 Tell whether the smooth filter is enabled or not.
 
TGUI_NODISCARD float getFontScale () const
 Returns the scale at which glyphs are rendered.
 

Protected Member Functions

TGUI_NODISCARD Glyph loadGlyph (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness)
 
TGUI_NODISCARD Glyph getInternalGlyph (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness)
 
TGUI_NODISCARD UIntRect findAvailableGlyphRect (unsigned int width, unsigned int height)
 
bool setCurrentSize (unsigned int characterSize)
 
void cleanup ()
 
- Protected Member Functions inherited from tgui::BackendFont
TGUI_NODISCARD std::uint64_t constructGlyphKey (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness)
 Creates a key for each unique character to render.
 

Protected Attributes

FT_Library m_library = nullptr
 
FT_Face m_face = nullptr
 
FT_Stroker m_stroker = nullptr
 
std::unordered_map< unsigned int, float > m_cachedLineSpacing
 
std::unordered_map< unsigned int, float > m_cachedFontHeights
 
std::unordered_map< unsigned int, float > m_cachedAscents
 
std::unordered_map< unsigned int, float > m_cachedDescents
 
std::unordered_map< std::uint64_t, Glyphm_glyphs
 
unsigned int m_nextRow = 3
 Y position of the next new row in the texture (first 2 rows contain pixels for underlining)
 
std::vector< Rowm_rows
 
std::unique_ptr< std::uint8_t[]> m_fileContents
 
std::unique_ptr< std::uint8_t[]> m_pixels
 
std::shared_ptr< BackendTexturem_texture
 
unsigned int m_textureSize = 0
 
unsigned int m_textureVersion = 0
 
- Protected Attributes inherited from tgui::BackendFont
bool m_isSmooth = true
 
float m_fontScale = 1
 

Detailed Description

Font implementations that uses FreeType directly to load glyphs.

Member Function Documentation

◆ getAscent()

TGUI_NODISCARD float tgui::BackendFontFreetype::getAscent ( unsigned int characterSize)
overridevirtual

Returns the maximum height of a glyph above the baseline.

Parameters
characterSizeSize of the characters
Returns
Ascent of the font

Implements tgui::BackendFont.

◆ getDescent()

TGUI_NODISCARD float tgui::BackendFontFreetype::getDescent ( unsigned int characterSize)
overridevirtual

Returns the maximum height of a glyph below the baseline.

Parameters
characterSizeSize of the characters
Returns
Descent of the font

Implements tgui::BackendFont.

◆ getFontHeight()

TGUI_NODISCARD float tgui::BackendFontFreetype::getFontHeight ( unsigned int characterSize)
overridevirtual

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

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

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

TGUI_NODISCARD float tgui::BackendFontFreetype::getKerning ( char32_t first,
char32_t second,
unsigned int characterSize,
bool bold )
overridevirtual

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

TGUI_NODISCARD float tgui::BackendFontFreetype::getLineSpacing ( unsigned int characterSize)
overridevirtual

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

TGUI_NODISCARD std::shared_ptr< BackendTexture > tgui::BackendFontFreetype::getTexture ( unsigned int characterSize,
unsigned int & textureVersion )
overridevirtual

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

TGUI_NODISCARD Vector2u tgui::BackendFontFreetype::getTextureSize ( unsigned int characterSize)
overridevirtual

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

TGUI_NODISCARD float tgui::BackendFontFreetype::getUnderlinePosition ( unsigned int characterSize)
overridevirtual

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

TGUI_NODISCARD float tgui::BackendFontFreetype::getUnderlineThickness ( unsigned int characterSize)
overridevirtual

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

TGUI_NODISCARD bool tgui::BackendFontFreetype::hasGlyph ( char32_t codePoint) const
overridevirtual

Returns whether a font contains a certain glyph.

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

Implements tgui::BackendFont.

◆ loadFromMemory() [1/3]

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/3]

bool tgui::BackendFontFreetype::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.

◆ loadFromMemory() [3/3]

virtual bool tgui::BackendFont::loadFromMemory ( std::unique_ptr< std::uint8_t[]> data,
std::size_t sizeInBytes )
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

Implements tgui::BackendFont.

◆ setFontScale()

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

Reimplemented from tgui::BackendFont.

◆ setSmooth()

void tgui::BackendFontFreetype::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: