TGUI  0.9.1
Font.hpp
1 //
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_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 
38 namespace tgui
39 {
40  class BackendFontBase;
41 
42 
46  struct TGUI_API FontGlyph
47  {
48  float advance = 0;
50  };
51 
52 
54 
55  class TGUI_API Font
56  {
57  public:
58 
63  static void setGlobalFont(const Font& font);
64 
65 
70  static Font getGlobalFont();
71 
72 
77  Font(std::nullptr_t = nullptr);
78 
79 
86  Font(const String& id);
87 
88 
95  Font(const char* id);
96 
97 
103  Font(const void* data, std::size_t sizeInBytes);
104 
105 
112  Font(std::shared_ptr<BackendFontBase> backendFont, const String& id);
113 
114 
121  const String& getId() const;
122 
123 
128  operator bool() const;
129 
130 
135  bool operator==(std::nullptr_t) const;
136 
137 
142  bool operator!=(std::nullptr_t) const;
143 
144 
148  bool operator==(const Font& right) const;
149 
150 
154  bool operator!=(const Font& right) const;
155 
156 
170  FontGlyph getGlyph(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const;
171 
172 
186  float getKerning(char32_t first, char32_t second, unsigned int characterSize) const;
187 
188 
198  float getLineSpacing(unsigned int characterSize) const;
199 
200 
205  std::shared_ptr<BackendFontBase> getBackendFont() const;
206 
207 
209  private:
210 
211  std::shared_ptr<BackendFontBase> m_backendFont;
212  String m_id;
213  };
214 
216 }
217 
219 
220 #endif // TGUI_FONT_HPP
Definition: Font.hpp:56
bool operator==(std::nullptr_t) const
Compares the font with a nullptr.
const String & getId() const
Returns the id that was used to load the font.
float getLineSpacing(unsigned int characterSize) const
Returns the line spacing.
bool operator==(const Font &right) const
Compares the font with another one.
static void setGlobalFont(const Font &font)
Changes the global font that is used for all new widgets.
bool operator!=(std::nullptr_t) const
Compares the font with a nullptr.
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) const
Returns the kerning offset of two glyphs.
Font(std::nullptr_t=nullptr)
Default constructor which will set the font to nullptr.
Font(const void *data, std::size_t sizeInBytes)
Constructor to create the font from a byte array.
Font(const char *id)
Constructor to create the font from a string (filename by default)
std::shared_ptr< BackendFontBase > getBackendFont() const
Returns the internal font.
Font(std::shared_ptr< BackendFontBase > backendFont, const String &id)
Constructor to create the font from an internal backend font.
Font(const String &id)
Constructor to create the font from a string (filename by default)
bool operator!=(const Font &right) const
Compares the font with another one.
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:74
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