TGUI 1.13
Loading...
Searching...
No Matches
Font.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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#ifndef TGUI_FONT_HPP
26#define TGUI_FONT_HPP
27
28#include <TGUI/Rect.hpp>
29#include <TGUI/String.hpp>
30
31#include <cstddef>
32#include <memory>
33
35
36namespace tgui
37{
38 class BackendFont;
39
43 struct TGUI_API FontGlyph
44 {
45 float advance = 0;
46 FloatRect bounds;
47 UIntRect textureRect;
48 };
49
53 class TGUI_API Font
54 {
55 public:
60 static void setGlobalFont(const Font& font);
61
66 [[nodiscard]] static Font getGlobalFont();
67
71 Font(std::nullptr_t = nullptr) noexcept;
72
78 Font(const String& id);
79
85 Font(const char* id);
86
92 Font(const void* data, std::size_t sizeInBytes);
93
100 Font(std::shared_ptr<BackendFont> backendFont, String id);
101
107 [[nodiscard]] const String& getId() const;
108
112 operator bool() const;
113
117 [[nodiscard]] bool operator==(std::nullptr_t) const;
118
122 [[nodiscard]] bool operator!=(std::nullptr_t) const;
123
127 [[nodiscard]] bool operator==(const Font& right) const;
128
132 [[nodiscard]] bool operator!=(const Font& right) const;
133
147 [[nodiscard]] FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const;
148
163 [[nodiscard]] float getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold = false) const;
164
174 [[nodiscard]] float getLineSpacing(unsigned int characterSize) const;
175
183 [[nodiscard]] float getFontHeight(unsigned int characterSize) const;
184
194 void setSmooth(bool smooth);
195
203 [[nodiscard]] bool isSmooth() const;
204
209 [[nodiscard]] std::shared_ptr<BackendFont> getBackendFont() const;
210
212
213 private:
214 std::shared_ptr<BackendFont> m_backendFont;
215 String m_id;
216 };
217} // namespace tgui
218
219#endif // TGUI_FONT_HPP
Base class for font implementations that depend on the backend.
Definition BackendFont.hpp:45
float getFontHeight(unsigned int characterSize) const
Returns the height required to render a line of text.
float getLineSpacing(unsigned int characterSize) const
Returns the line spacing.
Font(std::nullptr_t=nullptr) noexcept
Default constructor which will set the font to nullptr.
static void setGlobalFont(const Font &font)
Changes the global font that is used for all new widgets.
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
static Font getGlobalFont()
Returns the global font that is used for all new widgets.
float getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold=false) const
Returns the kerning offset of two glyphs.
std::shared_ptr< BackendFont > getBackendFont() const
Returns the internal font.
const String & getId() const
Returns the id that was used to load the font.
void setSmooth(bool smooth)
Enable or disable the smooth filter.
FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness=0) const
Retrieve a glyph of the font.
Wrapper class to store strings.
Definition String.hpp:94
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
Information about a glyph in the font.
Definition Font.hpp:44
FloatRect bounds
Bounding rectangle of the glyph, in coordinates relative to the baseline.
Definition Font.hpp:46
UIntRect textureRect
Texture coordinates of the glyph inside the font's texture.
Definition Font.hpp:47
float advance
Offset to move horizontally to the next character.
Definition Font.hpp:45