25#ifndef TGUI_BACKEND_FONT_SDL_TTF_HPP
26#define TGUI_BACKEND_FONT_SDL_TTF_HPP
28#include <TGUI/extlibs/IncludeSDL.hpp>
29#if SDL_MAJOR_VERSION >= 3
30 #include <SDL3_ttf/SDL_ttf.h>
35 #define TTF_GetFontAscent TTF_FontAscent
36 #define TTF_GetFontDescent TTF_FontDescent
37 #define TTF_GetFontHeight TTF_FontHeight
38 #define TTF_GetFontLineSkip TTF_FontLineSkip
41#include <TGUI/Config.hpp>
42#if !TGUI_BUILD_AS_CXX_MODULE
43 #include <TGUI/Backend/Font/BackendFont.hpp>
46#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
47 #include <unordered_map>
52TGUI_MODULE_EXPORT
namespace tgui
74 bool loadFromMemory(std::unique_ptr<std::uint8_t[]> data, std::size_t sizeInBytes)
override;
75 using BackendFont::loadFromMemory;
84 TGUI_NODISCARD
bool hasGlyph(
char32_t codePoint)
const override;
99 TGUI_NODISCARD
FontGlyph getGlyph(
char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness = 0)
override;
115 TGUI_NODISCARD
float getKerning(
char32_t first,
char32_t second,
unsigned int characterSize,
bool bold)
override;
144 TGUI_NODISCARD
float getAscent(
unsigned int characterSize)
override;
153 TGUI_NODISCARD
float getDescent(
unsigned int characterSize)
override;
185 TGUI_NODISCARD std::shared_ptr<BackendTexture>
getTexture(
unsigned int characterSize,
unsigned int& textureVersion)
override;
214 void setFontScale(
float scale)
override;
222 TGUI_NODISCARD TTF_Font* getInternalFont(
unsigned int characterSize);
230 std::pair<int, int> getUnderlineInfo(
unsigned int characterSize);
235 UIntRect findAvailableGlyphRect(
unsigned int width,
unsigned int height);
242 Row(
unsigned int rowTop,
unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
249 std::unique_ptr<std::uint8_t[]> m_fileContents;
250 std::size_t m_fileSize = 0;
253 std::unordered_map<unsigned int, TTF_Font*> m_fonts;
254 std::unordered_map<unsigned int, bool> m_lastBoldFlag;
255 std::unordered_map<unsigned int, int> m_lastOutlineThickness;
257 std::unordered_map<unsigned int, std::pair<int, int>> m_cachedUnderlineInfo;
259 std::unordered_map<std::uint64_t, FontGlyph> m_glyphs;
260 unsigned int m_nextRow = 3;
261 std::vector<Row> m_rows;
263 std::unique_ptr<std::uint8_t[]> m_pixels;
264 std::shared_ptr<BackendTexture> m_texture;
265 unsigned int m_textureSize = 0;
266 unsigned int m_textureVersion = 0;
Font implementations that uses SDL_ttf to load glyphs.
Definition BackendFontSDLttf.hpp:58
float getFontHeight(unsigned int characterSize) override
Returns the height required to render a line of text.
float getUnderlinePosition(unsigned int characterSize) override
Get the position of the underline.
float getLineSpacing(unsigned int characterSize) override
Returns the line spacing.
Vector2u getTextureSize(unsigned int characterSize) override
Returns the size of the texture that is used to store glyphs of the given character size.
bool loadFromMemory(std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes) override
Loads a font from memory.
~BackendFontSDLttf() override
Destructor that cleans up the SDL resources.
float getUnderlineThickness(unsigned int characterSize) override
Get the thickness of the underline.
float getAscent(unsigned int characterSize) override
Returns the maximum height of a glyph above the baseline.
float getDescent(unsigned int characterSize) override
Returns the maximum height of a glyph below the baseline.
void setSmooth(bool smooth) override
Enable or disable the smooth filter.
std::shared_ptr< BackendTexture > getTexture(unsigned int characterSize, unsigned int &textureVersion) override
Returns the texture that is used to store glyphs of the given character size.
FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0) override
Retrieve a glyph of the font.
bool hasGlyph(char32_t codePoint) const override
Returns whether a font contains a certain glyph.
float getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold) override
Returns the kerning offset of two glyphs.
Base class for font implementations that depend on the backend.
Definition BackendFont.hpp:45
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
Information about a glyph in the font.
Definition Font.hpp:48