TGUI  1.0.0
Loading...
Searching...
No Matches
BackendFontSFML.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2023 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_BACKEND_FONT_SFML_HPP
27#define TGUI_BACKEND_FONT_SFML_HPP
28
29#include <SFML/Graphics/Font.hpp>
30
31#include <TGUI/Config.hpp>
32#if TGUI_BUILD_AS_CXX_MODULE
33 import tgui;
34#else
35 #include <TGUI/Backend/Font/BackendFont.hpp>
36#endif
37
38#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
39 #include <unordered_set>
40 #include <memory>
41 #include <map>
42#endif
43
45
46TGUI_MODULE_EXPORT namespace tgui
47{
51 class TGUI_API BackendFontSFML : public BackendFont
52 {
53 public:
54
63 bool loadFromMemory(std::unique_ptr<std::uint8_t[]> data, std::size_t sizeInBytes) override;
64 using BackendFont::loadFromMemory;
65
66
74 TGUI_NODISCARD bool hasGlyph(char32_t codePoint) const override;
75
76
90 TGUI_NODISCARD FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) override;
91
92
107 TGUI_NODISCARD float getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold) override;
108
109
119 TGUI_NODISCARD float getLineSpacing(unsigned int characterSize) override;
120
121
129 TGUI_NODISCARD float getFontHeight(unsigned int characterSize) override;
130
131
139 TGUI_NODISCARD float getAscent(unsigned int characterSize) override;
140
141
149 TGUI_NODISCARD float getDescent(unsigned int characterSize) override;
150
151
161 TGUI_NODISCARD float getUnderlinePosition(unsigned int characterSize) override;
162
163
173 TGUI_NODISCARD float getUnderlineThickness(unsigned int characterSize) override;
174
175
184 TGUI_NODISCARD std::shared_ptr<BackendTexture> getTexture(unsigned int characterSize, unsigned int& textureVersion) override;
185
186
194 TGUI_NODISCARD Vector2u getTextureSize(unsigned int characterSize) override;
195
196
206 void setSmooth(bool smooth) override;
207
208
216 void setFontScale(float scale) override;
217
218
224 TGUI_NODISCARD sf::Font& getInternalFont();
225
226
228 protected:
229
230 sf::Font m_font;
231 std::unique_ptr<std::uint8_t[]> m_fileContents;
232
233 std::unordered_set<std::uint64_t> m_loadedGlyphKeys;
234
235 // We keep one texture per character size. Other font backends don't do this, but this is to prevent existing code
236 // from breaking since sf::Font does the same.
237 std::map<unsigned int, std::shared_ptr<BackendTexture>> m_textures;
238 std::map<unsigned int, unsigned int> m_textureVersions;
239 };
240}
241
243
244#endif // TGUI_BACKEND_FONT_SFML_HPP
Font implementation that makes use of SFML.
Definition BackendFontSFML.hpp:52
TGUI_NODISCARD float getAscent(unsigned int characterSize) override
Returns the maximum height of a glyph above the baseline.
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 getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold) override
Returns the kerning offset of two glyphs.
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.
TGUI_NODISCARD float getUnderlinePosition(unsigned int characterSize) override
Get the position of the underline.
TGUI_NODISCARD float getLineSpacing(unsigned int characterSize) override
Returns the line spacing.
bool loadFromMemory(std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes) override
Loads a font from memory.
TGUI_NODISCARD 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.
TGUI_NODISCARD float getUnderlineThickness(unsigned int characterSize) override
Get the thickness of the underline.
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 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:46
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
Information about a glyph in the font.
Definition Font.hpp:50