26#ifndef TGUI_BACKEND_FONT_SDL_TTF_HPP
27#define TGUI_BACKEND_FONT_SDL_TTF_HPP
29#include <TGUI/extlibs/IncludeSDL.hpp>
30#if SDL_MAJOR_VERSION >= 3
31 #include <SDL3_ttf/SDL_ttf.h>
36#include <TGUI/Config.hpp>
37#if TGUI_BUILD_AS_CXX_MODULE
40 #include <TGUI/Backend/Font/BackendFont.hpp>
43#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
44 #include <unordered_map>
49TGUI_MODULE_EXPORT
namespace tgui
72 bool loadFromMemory(std::unique_ptr<std::uint8_t[]> data, std::size_t sizeInBytes)
override;
83 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;
116 TGUI_NODISCARD
float getKerning(
char32_t first,
char32_t second,
unsigned int characterSize,
bool bold)
override;
148 TGUI_NODISCARD
float getAscent(
unsigned int characterSize)
override;
158 TGUI_NODISCARD
float getDescent(
unsigned int characterSize)
override;
193 TGUI_NODISCARD std::shared_ptr<BackendTexture>
getTexture(
unsigned int characterSize,
unsigned int& textureVersion)
override;
225 void setFontScale(
float scale)
override;
234 TGUI_NODISCARD TTF_Font* getInternalFont(
unsigned int characterSize);
243 std::pair<int, int> getUnderlineInfo(
unsigned int characterSize);
249 UIntRect findAvailableGlyphRect(
unsigned int width,
unsigned int height);
257 Row(
unsigned int rowTop,
unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
264 std::unique_ptr<std::uint8_t[]> m_fileContents;
265 std::size_t m_fileSize = 0;
268 std::unordered_map<unsigned int, TTF_Font*> m_fonts;
269 std::unordered_map<unsigned int, bool> m_lastBoldFlag;
270 std::unordered_map<unsigned int, int> m_lastOutlineThickness;
272 std::unordered_map<unsigned int, std::pair<int, int>> m_cachedUnderlineInfo;
274 std::unordered_map<std::uint64_t, FontGlyph> m_glyphs;
275 unsigned int m_nextRow = 3;
276 std::vector<Row> m_rows;
278 std::unique_ptr<std::uint8_t[]> m_pixels;
279 std::shared_ptr<BackendTexture> m_texture;
280 unsigned int m_textureSize = 0;
281 unsigned int m_textureVersion = 0;
Font implementations that uses SDL_ttf to load glyphs.
Definition BackendFontSDLttf.hpp:55
TGUI_NODISCARD float getUnderlineThickness(unsigned int characterSize) override
Get the thickness of the underline.
TGUI_NODISCARD bool hasGlyph(char32_t codePoint) const override
Returns whether a font contains a certain glyph.
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.
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.
TGUI_NODISCARD float getDescent(unsigned int characterSize) override
Returns the maximum height of a glyph below the baseline.
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 getUnderlinePosition(unsigned int characterSize) override
Get the position of the underline.
TGUI_NODISCARD float getAscent(unsigned int characterSize) override
Returns the maximum height of a glyph above the baseline.
void setSmooth(bool smooth) override
Enable or disable the smooth filter.
TGUI_NODISCARD 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.
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 getFontHeight(unsigned int characterSize) override
Returns the height required to render a line of text.
TGUI_NODISCARD float getLineSpacing(unsigned int characterSize) override
Returns the line spacing.
Base class for font implementations that depend on the backend.
Definition BackendFont.hpp:46
virtual bool loadFromMemory(std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes)=0
Loads a font from memory.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
Information about a glyph in the font.
Definition Font.hpp:50