TGUI  0.9-dev
BackendFontSFML.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 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 <TGUI/Backend/Font/BackendFont.hpp>
30#include <SFML/Graphics/Font.hpp>
31#include <unordered_set>
32
34
35namespace tgui
36{
40 class TGUI_API BackendFontSFML : public BackendFont
41 {
42 public:
43
52 bool loadFromMemory(std::unique_ptr<std::uint8_t[]> data, std::size_t sizeInBytes) override;
54
55
63 bool hasGlyph(char32_t codePoint) const override;
64
65
79 FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) override;
80
81
96 float getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold) override;
97#ifndef TGUI_REMOVE_DEPRECATED_CODE
98 using BackendFont::getKerning; // Import version without bold parameter
99#endif
100
101
111 float getLineSpacing(unsigned int characterSize) override;
112
113
123 float getUnderlinePosition(unsigned int characterSize) override;
124
125
135 float getUnderlineThickness(unsigned int characterSize) override;
136
137
145 std::shared_ptr<BackendTexture> getTexture(unsigned int characterSize) override;
146
147
157 void setSmooth(bool smooth) override;
158
159
165 sf::Font& getInternalFont();
166
167
169 protected:
170
171 sf::Font m_font;
172 std::unique_ptr<std::uint8_t[]> m_fileContents;
173
174 std::unordered_set<std::uint64_t> m_loadedGlyphKeys;
175
176 // We keep one texture per character size. Other font backends don't do this, but this is to prevent existing code
177 // from breaking since sf::Font does the same.
178 std::map<unsigned int, std::shared_ptr<BackendTexture>> m_textures;
179 };
180}
181
183
184#endif // TGUI_BACKEND_FONT_SFML_HPP
Font implementation that makes use of SFML.
Definition: BackendFontSFML.hpp:41
float getUnderlinePosition(unsigned int characterSize) override
Get the position of the underline.
bool hasGlyph(char32_t codePoint) const override
Returns whether a font contains a certain glyph.
FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0) override
Retrieve a glyph of the font.
std::shared_ptr< BackendTexture > getTexture(unsigned int characterSize) override
Returns the texture that is used to store glyphs of the given character size.
float getUnderlineThickness(unsigned int characterSize) override
Get the thickness of the underline.
bool loadFromMemory(std::unique_ptr< std::uint8_t[]> data, std::size_t sizeInBytes) override
Loads a font from memory.
void setSmooth(bool smooth) override
Enable or disable the smooth filter.
float getLineSpacing(unsigned int characterSize) override
Returns the line spacing.
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:43
virtual bool loadFromMemory(const void *data, std::size_t sizeInBytes)
Loads a font from memory.
virtual float getKerning(char32_t first, char32_t second, unsigned int characterSize)
Returns the kerning offset of two glyphs.
Definition: BackendFont.hpp:129
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Information about a glyph in the font.
Definition: Font.hpp:47