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 "openmsx.hh"
6 #include <string>
7 #include <utility>
8 
9 namespace openmsx {
10 
11 class TTFFont
12 {
13 public:
14  TTFFont(const TTFFont&) = delete;
15  TTFFont& operator=(const TTFFont&) = delete;
16 
23  TTFFont() = default;
24 
30  TTFFont(const std::string& filename, int ptSize);
31 
33  TTFFont(TTFFont&& other) noexcept
34  : font(other.font)
35  {
36  other.font = nullptr;
37  }
38 
40  TTFFont& operator=(TTFFont&& other) noexcept
41  {
42  std::swap(font, other.font);
43  return *this;
44  }
45 
46  ~TTFFont();
47 
49  bool empty() const { return font == nullptr; }
50 
55  SDLSurfacePtr render(std::string text, byte r, byte g, byte b) const;
56 
60  unsigned getHeight() const;
61 
63  bool isFixedWidth() const;
64 
69  unsigned getWidth() const;
70 
73  void getSize(const std::string& text, unsigned& width, unsigned& height) const;
74 
75 private:
76  void* font = nullptr; // TTF_Font*
77 };
78 
79 } // namespace openmsx
80 
81 #endif
TTFFont()=default
Construct an empty font.
bool empty() const
Is this an empty font? (a default constructed object).
Definition: TTFFont.hh:49
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
TTFFont & operator=(TTFFont &&other) noexcept
Move assignment.
Definition: TTFFont.hh:40
TTFFont(TTFFont &&other) noexcept
Move construct.
Definition: TTFFont.hh:33
SDLSurfacePtr render(std::string text, byte r, byte g, byte b) const
Render the given text to a new SDL_Surface.
Definition: TTFFont.cc:146
unsigned getHeight() const
Return the height of the font.
Definition: TTFFont.cc:218
Wrapper around a SDL_Surface.
constexpr const char *const filename
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
int g
TTFFont & operator=(const TTFFont &)=delete
void getSize(const std::string &text, unsigned &width, unsigned &height) const
Return the size in pixels of the text if it would be rendered.
Definition: TTFFont.cc:241
unsigned getWidth() const
Return the width of the font.
Definition: TTFFont.cc:228
bool isFixedWidth() const
Returns true iff this is a fixed-with (=mono-spaced) font.
Definition: TTFFont.cc:223