TGUI  1.3-dev
Loading...
Searching...
No Matches
Font.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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_FONT_HPP
27#define TGUI_FONT_HPP
28
29#include <TGUI/String.hpp>
30#include <TGUI/Rect.hpp>
31
32#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
33 #include <cstdint>
34 #include <string>
35 #include <cstddef>
36 #include <memory>
37#endif
38
40
41TGUI_MODULE_EXPORT namespace tgui
42{
43 class BackendFont;
44
45
49 struct TGUI_API FontGlyph
50 {
51 float advance = 0;
54 };
55
56
60 class TGUI_API Font
61 {
62 public:
63
68 static void setGlobalFont(const Font& font);
69
70
75 TGUI_NODISCARD static Font getGlobalFont();
76
77
82 Font(std::nullptr_t = nullptr) noexcept;
83
84
91 Font(const String& id);
92
93
100 Font(const char* id);
101
102
108 Font(const void* data, std::size_t sizeInBytes);
109
110
117 Font(std::shared_ptr<BackendFont> backendFont, String id);
118
119
126 TGUI_NODISCARD const String& getId() const;
127
128
133 operator bool() const;
134
135
140 TGUI_NODISCARD bool operator==(std::nullptr_t) const;
141
142
147 TGUI_NODISCARD bool operator!=(std::nullptr_t) const;
148
149
153 TGUI_NODISCARD bool operator==(const Font& right) const;
154
155
159 TGUI_NODISCARD bool operator!=(const Font& right) const;
160
161
175 TGUI_NODISCARD FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const;
176
177
192 TGUI_NODISCARD float getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold = false) const;
193
194
204 TGUI_NODISCARD float getLineSpacing(unsigned int characterSize) const;
205
206
214 TGUI_NODISCARD float getFontHeight(unsigned int characterSize) const;
215
216
226 void setSmooth(bool smooth);
227
228
236 TGUI_NODISCARD bool isSmooth() const;
237
238
243 TGUI_NODISCARD std::shared_ptr<BackendFont> getBackendFont() const;
244
245
247 private:
248
249 std::shared_ptr<BackendFont> m_backendFont;
250 String m_id;
251 };
252
254}
255
257
258#endif // TGUI_FONT_HPP
Base class for font implementations that depend on the backend.
Definition BackendFont.hpp:46
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:61
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.
static TGUI_NODISCARD Font getGlobalFont()
Returns the global font that is used for all new widgets.
Wrapper class to store strings.
Definition String.hpp:101
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
Information about a glyph in the font.
Definition Font.hpp:50
FloatRect bounds
Bounding rectangle of the glyph, in coordinates relative to the baseline.
Definition Font.hpp:52
UIntRect textureRect
Texture coordinates of the glyph inside the font's texture.
Definition Font.hpp:53