25#ifndef TGUI_BACKEND_FONT_FREETYPE_HPP
26#define TGUI_BACKEND_FONT_FREETYPE_HPP
28#include <TGUI/Config.hpp>
29#if !TGUI_BUILD_AS_CXX_MODULE
30 #include <TGUI/Backend/Font/BackendFont.hpp>
33#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
34 #include <unordered_map>
39#if !TGUI_BUILD_AS_CXX_MODULE
40 using FT_Library =
struct FT_LibraryRec_*;
41 using FT_Face =
struct FT_FaceRec_*;
42 using FT_Stroker =
struct FT_StrokerRec_*;
47TGUI_MODULE_EXPORT
namespace tgui
69 bool loadFromMemory(std::unique_ptr<std::uint8_t[]> data, std::size_t sizeInBytes)
override;
70 using BackendFont::loadFromMemory;
79 TGUI_NODISCARD
bool hasGlyph(
char32_t codePoint)
const override;
94 TGUI_NODISCARD
FontGlyph getGlyph(
char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness = 0)
override;
110 TGUI_NODISCARD
float getKerning(
char32_t first,
char32_t second,
unsigned int characterSize,
bool bold)
override;
139 TGUI_NODISCARD
float getAscent(
unsigned int characterSize)
override;
148 TGUI_NODISCARD
float getDescent(
unsigned int characterSize)
override;
180 TGUI_NODISCARD std::shared_ptr<BackendTexture>
getTexture(
unsigned int characterSize,
unsigned int& textureVersion)
override;
209 void setFontScale(
float scale)
override;
226 TGUI_NODISCARD
Glyph loadGlyph(
char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness);
231 TGUI_NODISCARD
Glyph getInternalGlyph(
char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness);
236 TGUI_NODISCARD
UIntRect findAvailableGlyphRect(
unsigned int width,
unsigned int height);
241 bool setCurrentSize(
unsigned int characterSize);
253 Row(
unsigned int rowTop,
unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
260 FT_Library m_library =
nullptr;
261 FT_Face m_face =
nullptr;
262 FT_Stroker m_stroker =
nullptr;
264 std::unordered_map<unsigned int, float> m_cachedLineSpacing;
265 std::unordered_map<unsigned int, float> m_cachedFontHeights;
266 std::unordered_map<unsigned int, float> m_cachedAscents;
267 std::unordered_map<unsigned int, float> m_cachedDescents;
269 std::unordered_map<std::uint64_t, Glyph> m_glyphs;
270 unsigned int m_nextRow = 3;
271 std::vector<Row> m_rows;
273 std::unique_ptr<std::uint8_t[]> m_fileContents;
274 std::unique_ptr<std::uint8_t[]> m_pixels;
275 std::shared_ptr<BackendTexture> m_texture;
276 unsigned int m_textureSize = 0;
277 unsigned int m_textureVersion = 0;
Font implementations that uses FreeType directly to load glyphs.
Definition BackendFontFreeType.hpp:53
TGUI_NODISCARD float getLineSpacing(unsigned int characterSize) override
Returns the line spacing.
TGUI_NODISCARD bool hasGlyph(char32_t codePoint) const override
Returns whether a font contains a certain glyph.
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.
~BackendFontFreetype() override
Destructor that cleans up the FreeType resources.
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 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 float getUnderlineThickness(unsigned int characterSize) override
Get the thickness of the underline.
TGUI_NODISCARD float getDescent(unsigned int characterSize) override
Returns the maximum height of a glyph below the baseline.
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.
TGUI_NODISCARD float getUnderlinePosition(unsigned int characterSize) override
Get the position of the underline.
TGUI_NODISCARD float getFontHeight(unsigned int characterSize) override
Returns the height required to render a line of text.
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
Definition BackendFontFreeType.hpp:215
UIntRect textureRect
Texture coordinates of the glyph inside the font's texture.
Definition BackendFontFreeType.hpp:220
FloatRect bounds
Bounding rectangle of the glyph, in coordinates relative to the baseline.
Definition BackendFontFreeType.hpp:219
Definition BackendFontFreeType.hpp:252
unsigned int height
Height of the row.
Definition BackendFontFreeType.hpp:257
unsigned int width
Current width of the row.
Definition BackendFontFreeType.hpp:255
unsigned int top
Y position of the row into the texture.
Definition BackendFontFreeType.hpp:256
Information about a glyph in the font.
Definition Font.hpp:48