TGUI
1.6.1
|
Base class for font implementations that depend on the backend. More...
#include <TGUI/Backend/Font/BackendFont.hpp>
Public Member Functions | |
BackendFont () | |
Default constructor. | |
BackendFont (const BackendFont &) | |
Copy constructor. | |
BackendFont (BackendFont &&other) noexcept | |
Move constructor. | |
virtual | ~BackendFont () |
Virtual destructor. | |
BackendFont & | operator= (const BackendFont &other) |
Copy assignment operator. | |
BackendFont & | operator= (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< BackendTexture > | getTexture (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 |
Base class for font implementations that depend on the backend.
|
nodiscardprotected |
Creates a key for each unique character to render.
codePoint | Unicode code of the character |
characterSize | Reference character size |
bold | Whether the character has to be rendered with a bold font |
outlineThickness | Thickness of the outline to draw around the character (0 means no outline) |
Calling this function with the same parameters results in the same id, while other parameters result in another id.
|
nodiscardpure virtual |
Returns the maximum height of a glyph above the baseline.
characterSize | Size of the characters |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscardpure virtual |
Returns the maximum height of a glyph below the baseline.
characterSize | Size of the characters |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscardpure virtual |
Returns the height required to render a line of text.
characterSize | Size of the characters |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
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.
|
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.
codePoint | Unicode code point of the character to get |
characterSize | Reference character size |
bold | Retrieve the bold version or the regular one? |
outlineThickness | Thickness of outline (when != 0 the glyph will not be filled) |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
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.
first | Unicode code point of the first character |
second | Unicode code point of the second character |
characterSize | Size of the characters |
bold | Are the glyphs bold or regular? |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscardpure virtual |
Returns the line spacing.
Line spacing is the vertical offset to apply between two consecutive lines of text.
characterSize | Size of the characters |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscardpure virtual |
Returns the texture that is used to store glyphs of the given character size.
characterSize | Size of the characters that should be part of the texture |
textureVersion | Counter that is incremented each time the texture is changed, returned by this function |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscardpure virtual |
Returns the size of the texture that is used to store glyphs of the given character size.
characterSize | Size of the characters that should be part of the texture |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscardpure virtual |
Get the position of the underline.
Underline position is the vertical offset to apply between the baseline and the underline.
characterSize | Reference character size |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscardpure virtual |
Get the thickness of the underline.
Underline thickness is the vertical size of the underline.
characterSize | Reference character size |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscardpure virtual |
Returns whether a font contains a certain glyph.
codePoint | Character to check |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
nodiscard |
Tell whether the smooth filter is enabled or not.
|
virtual |
Loads a font from a file.
filename | Filename of the font to load |
bool tgui::BackendFont::loadFromMemory | ( | const void * | data, |
std::size_t | sizeInBytes ) |
Loads a font from memory.
data | Pointer to the file data in memory |
sizeInBytes | Size of the data to load, in bytes |
This function makes a copy of the data. Use the overload with a unique_ptr when possible to move instead of copy.
|
pure virtual |
Loads a font from memory.
data | Moved pointer to the file data in memory |
sizeInBytes | Size of the data to load, in bytes |
Implemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.
|
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.
smooth | True to enable smoothing, false to disable it |
Reimplemented in tgui::BackendFontFreetype, tgui::BackendFontRaylib, tgui::BackendFontSDLttf, and tgui::BackendFontSFML.