openMSX
TTFFont.hh
Go to the documentation of this file.
1#ifndef TTFFONT_HH
2#define TTFFONT_HH
3
4#include "SDLSurfacePtr.hh"
5#include "gl_vec.hh"
6#include "zstring_view.hh"
7#include <cstdint>
8#include <string>
9#include <utility>
10
11namespace openmsx {
12
14{
15public:
16 TTFFont(const TTFFont&) = delete;
17 TTFFont& operator=(const TTFFont&) = delete;
18
25 TTFFont() = default;
26
32 TTFFont(const std::string& filename, int ptSize);
33
35 TTFFont(TTFFont&& other) noexcept
36 : font(other.font)
37 {
38 other.font = nullptr;
39 }
40
42 TTFFont& operator=(TTFFont&& other) noexcept
43 {
44 std::swap(font, other.font);
45 return *this;
46 }
47
48 ~TTFFont();
49
51 [[nodiscard]] bool empty() const { return font == nullptr; }
52
57 [[nodiscard]] SDLSurfacePtr render(std::string text, uint8_t r, uint8_t g, uint8_t b) const;
58
62 [[nodiscard]] int getHeight() const;
63
65 [[nodiscard]] bool isFixedWidth() const;
66
71 [[nodiscard]] int getWidth() const;
72
75 [[nodiscard]] gl::ivec2 getSize(zstring_view text) const;
76
77private:
78 void* font = nullptr; // TTF_Font*
79};
80
81} // namespace openmsx
82
83#endif
int g
Wrapper around a SDL_Surface.
int getHeight() const
Return the height of the font.
Definition TTFFont.cc:233
bool empty() const
Is this an empty font? (a default constructed object).
Definition TTFFont.hh:51
SDLSurfacePtr render(std::string text, uint8_t r, uint8_t g, uint8_t b) const
Render the given text to a new SDL_Surface.
Definition TTFFont.cc:149
TTFFont & operator=(const TTFFont &)=delete
TTFFont(TTFFont &&other) noexcept
Move construct.
Definition TTFFont.hh:35
int getWidth() const
Return the width of the font.
Definition TTFFont.cc:243
bool isFixedWidth() const
Returns true iff this is a fixed-with (=mono-spaced) font.
Definition TTFFont.cc:238
TTFFont & operator=(TTFFont &&other) noexcept
Move assignment.
Definition TTFFont.hh:42
gl::ivec2 getSize(zstring_view text) const
Return the size in pixels of the text if it would be rendered.
Definition TTFFont.cc:256
TTFFont()=default
Construct an empty font.
TTFFont(const TTFFont &)=delete
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
This file implemented 3 utility functions:
Definition Autofire.cc:11