Base class for font implementations that depend on the backend.
More...
#include <TGUI/Backend/Font/BackendFont.hpp>
|
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< BackendTexture > | getTexture (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...
|
|
|
std::uint64_t | constructGlyphKey (char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness) |
| Creates a key for each unique character to render. More...
|
|
Base class for font implementations that depend on the backend.
◆ 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
-
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) |
- 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
-
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) |
- 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
-
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? |
- 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 |
◆ getTexture()
virtual std::shared_ptr< BackendTexture > tgui::BackendFont::getTexture |
( |
unsigned int |
characterSize | ) |
|
|
pure virtual |
◆ getUnderlinePosition()
virtual float tgui::BackendFont::getUnderlinePosition |
( |
unsigned int |
characterSize | ) |
|
|
pure virtual |
◆ getUnderlineThickness()
virtual float tgui::BackendFont::getUnderlineThickness |
( |
unsigned int |
characterSize | ) |
|
|
pure virtual |
◆ hasGlyph()
virtual bool tgui::BackendFont::hasGlyph |
( |
char32_t |
codePoint | ) |
const |
|
pure virtual |
◆ 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
-
filename | Filename 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
-
data | Pointer to the file data in memory |
sizeInBytes | Size 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 |
◆ 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
-
smooth | True 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: