FifeGUI 0.2.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#include <SDL_ttf.h>
9
10#include <map>
11#include <string>
12
13#include "fifechan/font.hpp"
14#include "fifechan/platform.hpp"
15
16namespace fcn::sdl2
17{
18
29 class FIFEGUI_EXT_API TrueTypeFont : public Font
30 {
31 public:
38 TrueTypeFont(std::string const & filename, int size);
39
40 ~TrueTypeFont() override;
41
42 TrueTypeFont(TrueTypeFont const &) = delete;
43 TrueTypeFont& operator=(TrueTypeFont const &) = delete;
44 TrueTypeFont(TrueTypeFont&&) = delete;
45 TrueTypeFont& operator=(TrueTypeFont&&) = delete;
46
53 virtual void setRowSpacing(int spacing);
54
60 virtual int getRowSpacing();
61
68 virtual void setGlyphSpacing(int spacing);
69
75 virtual int getGlyphSpacing();
76
82 virtual void setAntiAlias(bool antiAlias);
83
89 virtual bool isAntiAlias();
90
91 // Inherited from Font
92
93 int getWidth(std::string const & text) const override;
94
95 int getHeight() const override;
96
97 void drawString(fcn::Graphics* graphics, std::string const & text, int x, int y) override;
98
99 protected:
101 TTF_Font* mFont;
102
104 int mHeight{};
105
108
111
113 std::string mFilename;
114
117 };
118} // namespace fcn::sdl2
119
120#endif // INCLUDE_FIFECHAN_BACKENDS_SDL_SDLTRUETYPEFONT_HPP_
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
TrueTypeFont(std::string const &filename, int size)
Constructor.
int mRowSpacing
Additional spacing between rows in pixels.
void drawString(fcn::Graphics *graphics, std::string const &text, int x, int y) override
Draws a string.
TTF_Font * mFont
Underlying TTF_Font pointer from SDL_ttf.
int mGlyphSpacing
Additional spacing between glyphs 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.
int getWidth(std::string const &text) const override
Gets the width of a string.
virtual void setRowSpacing(int spacing)
Sets the spacing between rows in pixels.
int getHeight() const override
Gets the height of the glyphs in the font.
virtual bool isAntiAlias()
Checks if anti aliasing is used.
virtual int getGlyphSpacing()
Gets the spacing between letters in pixels.
virtual int getRowSpacing()
Gets the spacing between rows in pixels.
bool mAntiAlias
Whether anti-aliasing is enabled for rendering.
int mHeight
Cached font height in pixels.
virtual void setAntiAlias(bool antiAlias)
Enable or disable anti-aliasing for rendered glyphs.
Unified header for the SDL backend.