FifeGUI 0.3.0
A C++ GUI library designed for games.
truetypefont.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_BACKENDS_SDL_SDLTRUETYPEFONT_HPP_
6#define INCLUDE_FIFECHAN_BACKENDS_SDL_SDLTRUETYPEFONT_HPP_
7
8// Standard library includes
9#include <map>
10#include <string>
11
12// Platform config include
13#include "fifechan/platform.hpp"
14
15// Third-party library includes
16#include <SDL3_ttf/SDL_ttf.h>
17
18// Project headers (subdirs before local)
19#include "fifechan/font.hpp"
20
21namespace fcn::sdl3
22{
23
35 class FIFEGUI_EXT_API TrueTypeFont : public Font
36 {
37 public:
44 TrueTypeFont(std::string const & filename, int size);
45
46 ~TrueTypeFont() override;
47
48 TrueTypeFont(TrueTypeFont const &) = delete;
49 TrueTypeFont& operator=(TrueTypeFont const &) = delete;
50 TrueTypeFont(TrueTypeFont&&) = delete;
51 TrueTypeFont& operator=(TrueTypeFont&&) = delete;
52
59 virtual void setRowSpacing(int spacing);
60
66 virtual int getRowSpacing();
67
74 virtual void setGlyphSpacing(int spacing);
75
81 virtual int getGlyphSpacing();
82
88 virtual void setAntiAlias(bool antiAlias);
89
95 virtual bool isAntiAlias();
96
97 // Inherited from Font
98
99 int getWidth(std::string const & text) const override;
100
101 int getHeight() const override;
102
103 void drawString(fcn::Graphics* graphics, std::string const & text, int x, int y) override;
104
105 protected:
107 TTF_Font* mFont;
108
110 int mHeight{};
111
114
117
119 std::string mFilename;
120
123 };
124} // namespace fcn::sdl3
125
126#endif // INCLUDE_FIFECHAN_BACKENDS_SDL_SDLTRUETYPEFONT_HPP_
Font(Font const &)=default
Copy constructor.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
virtual bool isAntiAlias()
Checks if anti aliasing is used.
int mGlyphSpacing
Additional spacing between glyphs in pixels.
int mRowSpacing
Additional spacing between rows in pixels.
int mHeight
Cached font height in pixels.
std::string mFilename
Filename of the font used to create mFont.
virtual void setGlyphSpacing(int spacing)
Sets the spacing between letters in pixels.
TTF_Font * mFont
Underlying TTF_Font pointer from SDL_ttf.
virtual void setAntiAlias(bool antiAlias)
Enable or disable anti-aliasing for rendered glyphs.
int getWidth(std::string const &text) const override
Gets the width of a string.
virtual int getRowSpacing()
Gets the spacing between rows in pixels.
void drawString(fcn::Graphics *graphics, std::string const &text, int x, int y) override
Draws a string.
bool mAntiAlias
Whether anti-aliasing is enabled for rendering.
virtual void setRowSpacing(int spacing)
Sets the spacing between rows in pixels.
TrueTypeFont(std::string const &filename, int size)
Constructor.
virtual int getGlyphSpacing()
Gets the spacing between letters in pixels.
int getHeight() const override
Gets the height of the glyphs in the font.