TGUI  1.0-beta
Loading...
Searching...
No Matches
Font.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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#include <cstdint>
32#include <string>
33#include <cstddef>
34#include <memory>
35
37
38namespace tgui
39{
40 class BackendFont;
41
42
46 struct TGUI_API FontGlyph
47 {
48 float advance = 0;
51 };
52
53
55
56 class TGUI_API Font
57 {
58 public:
59
64 static void setGlobalFont(const Font& font);
65
66
72
73
78 Font(std::nullptr_t = nullptr) noexcept;
79
80
87 Font(const String& id);
88
89
96 Font(const char* id);
97
98
104 Font(const void* data, std::size_t sizeInBytes);
105
106
113 Font(std::shared_ptr<BackendFont> backendFont, String id);
114
115
122 const String& getId() const;
123
124
129 operator bool() const;
130
131
136 bool operator==(std::nullptr_t) const;
137
138
143 bool operator!=(std::nullptr_t) const;
144
145
149 bool operator==(const Font& right) const;
150
151
155 bool operator!=(const Font& right) const;
156
157
171 FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const;
172
173
188 float getKerning(char32_t first, char32_t second, unsigned int characterSize, bool bold = false) const;
189
190
200 float getLineSpacing(unsigned int characterSize) const;
201
202
210 float getFontHeight(unsigned int characterSize) const;
211
212
222 void setSmooth(bool smooth);
223
224
232 bool isSmooth() const;
233
234
239 std::shared_ptr<BackendFont> getBackendFont() const;
240
241
243 private:
244
245 std::shared_ptr<BackendFont> m_backendFont;
246 String m_id;
247 };
248
250}
251
253
254#endif // TGUI_FONT_HPP
Base class for font implementations that depend on the backend.
Definition: BackendFont.hpp:43
Definition: Font.hpp:57
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 Font getGlobalFont()
Returns the global font that is used for all new widgets.
Wrapper class to store strings.
Definition: String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Information about a glyph in the font.
Definition: Font.hpp:47
FloatRect bounds
Bounding rectangle of the glyph, in coordinates relative to the baseline.
Definition: Font.hpp:49
UIntRect textureRect
Texture coordinates of the glyph inside the font's texture.
Definition: Font.hpp:50