25#ifndef TGUI_BACKEND_FONT_FREETYPE_HPP
26#define TGUI_BACKEND_FONT_FREETYPE_HPP
28#include <TGUI/Config.hpp>
30#include <TGUI/Backend/Font/BackendFont.hpp>
32#include <unordered_map>
36using FT_Library =
struct FT_LibraryRec_*;
37using FT_Face =
struct FT_FaceRec_*;
38using FT_Stroker =
struct FT_StrokerRec_*;
63 [[nodiscard]]
bool loadFromMemory(std::unique_ptr<std::uint8_t[]> data, std::size_t sizeInBytes)
override;
73 [[nodiscard]]
bool hasGlyph(
char32_t codePoint)
const override;
88 [[nodiscard]]
FontGlyph getGlyph(
char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness = 0)
override;
104 [[nodiscard]]
float getKerning(
char32_t first,
char32_t second,
unsigned int characterSize,
bool bold)
override;
133 [[nodiscard]]
float getAscent(
unsigned int characterSize)
override;
142 [[nodiscard]]
float getDescent(
unsigned int characterSize)
override;
174 [[nodiscard]] std::shared_ptr<BackendTexture>
getTexture(
unsigned int characterSize,
unsigned int& textureVersion)
override;
203 void setFontScale(
float scale)
override;
220 [[nodiscard]]
Glyph loadGlyph(
char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness);
225 [[nodiscard]]
Glyph getInternalGlyph(
char32_t codePoint,
unsigned int characterSize,
bool bold,
float outlineThickness);
230 [[nodiscard]] UIntRect findAvailableGlyphRect(
unsigned int width,
unsigned int height);
235 bool setCurrentSize(
unsigned int characterSize);
247 Row(
unsigned int rowTop,
unsigned int rowHeight) :
259 FT_Library m_library =
nullptr;
260 FT_Face m_face =
nullptr;
261 FT_Stroker m_stroker =
nullptr;
263 std::unordered_map<unsigned int, float> m_cachedLineSpacing;
264 std::unordered_map<unsigned int, float> m_cachedFontHeights;
265 std::unordered_map<unsigned int, float> m_cachedAscents;
266 std::unordered_map<unsigned int, float> m_cachedDescents;
268 std::unordered_map<std::uint64_t, Glyph> m_glyphs;
270 std::vector<Row> m_rows;
272 std::unique_ptr<std::uint8_t[]> m_fileContents;
273 std::unique_ptr<std::uint8_t[]> m_pixels;
274 std::shared_ptr<BackendTexture> m_texture;
275 unsigned int m_textureSize = 0;
276 unsigned int m_textureVersion = 0;
279 using BackendFontFreetype TGUI_DEPRECATED(
"Use BackendFontFreeType instead (capital T)") =
BackendFontFreeType;
Font implementations that uses FreeType directly to load glyphs.
Definition BackendFontFreeType.hpp:48
float getDescent(unsigned int characterSize) override
Returns the maximum height of a glyph below the baseline as a negative value.
Vector2u getTextureSize(unsigned int characterSize) override
Returns the size of the texture that is used to store glyphs of the given character size.
float getLineSpacing(unsigned int characterSize) override
Returns the line spacing.
float getUnderlineThickness(unsigned int characterSize) override
Get the thickness of the underline.
~BackendFontFreeType() override
Destructor that cleans up the FreeType resources.
FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0) override
Retrieve a glyph of the font.
float getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold) override
Returns the kerning offset of two glyphs.
float getUnderlinePosition(unsigned int characterSize) override
Get the position of the underline.
unsigned int m_nextRow
Y position of the next new row in the texture (first 2 rows contain pixels for underlining).
Definition BackendFontFreeType.hpp:269
float getAscent(unsigned int characterSize) override
Returns the maximum height of a glyph above the baseline.
float getFontHeight(unsigned int characterSize) override
Returns the height required to render a line of text.
bool loadFromMemory(std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes) override
Loads a font from memory.
bool hasGlyph(char32_t codePoint) const override
Returns whether a font contains a certain glyph.
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.
virtual bool loadFromMemory(std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes)=0
Loads a font from memory.
BackendFont()
Default constructor.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
Definition BackendFontFreeType.hpp:209
float advance
Offset to move horizontally to the next character.
Definition BackendFontFreeType.hpp:210
FloatRect bounds
Bounding rectangle of the glyph, in coordinates relative to the baseline.
Definition BackendFontFreeType.hpp:213
float lsbDelta
Left offset after forced autohint. Internally used by getKerning().
Definition BackendFontFreeType.hpp:211
float rsbDelta
Right offset after forced autohint. Internally used by getKerning().
Definition BackendFontFreeType.hpp:212
UIntRect textureRect
Texture coordinates of the glyph inside the font's texture.
Definition BackendFontFreeType.hpp:214
unsigned int height
Height of the row.
Definition BackendFontFreeType.hpp:256
unsigned int top
Y position of the row into the texture.
Definition BackendFontFreeType.hpp:255
unsigned int width
Current width of the row.
Definition BackendFontFreeType.hpp:254
Information about a glyph in the font.
Definition Font.hpp:44