|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
RAII wrapper around a TTF_Font handle. More...
#include <font.hpp>
Public Member Functions | |
| Font ()=default | |
| Default constructor — font is not loaded. | |
| Font (const std::string &tf) | |
| Load a font without specifying a size (size determined later). | |
| Font (const std::string &tf, int size) | |
| Load a font at the given point size. | |
| Font (TTF_Font *tf) | |
| Wrap an already-open TTF_Font pointer (takes ownership). | |
| Font (const Font &f)=delete | |
| Font (Font &&f) | |
| Move constructor — transfers ownership of the TTF handle. | |
| ~Font () | |
| Destructor — closes the TTF_Font if loaded. | |
| Font & | operator= (const Font &f)=delete |
| Font & | operator= (Font &&f) |
| Move-assign — transfers ownership of the TTF handle. | |
| bool | tryLoadFont (const std::string &fname, int size) |
| Attempt to load a font, returning false on failure. | |
| void | loadFont (const std::string &fname, int size) |
| Load a font, throwing mx::Exception on failure. | |
| std::optional< TTF_Font * > | handle () const |
| Return the underlying TTF_Font as an optional. | |
| TTF_Font * | unwrap () const |
| Unwrap the TTF_Font pointer, throwing on null. | |
| Wrapper< TTF_Font * > | wrapper () const |
| Return a Wrapper around the TTF_Font handle. | |
Private Attributes | |
| TTF_Font * | the_font = nullptr |
| Underlying SDL_ttf font handle. | |
RAII wrapper around a TTF_Font handle.
Loads a TrueType font from disk and manages its lifetime. The underlying TTF_Font pointer is accessible via handle(), unwrap(), or wrapper() for safe optional-style access.
|
default |
Default constructor — font is not loaded.
Referenced by Font(), Font(), operator=(), and operator=().
| mx::Font::Font | ( | const std::string & | tf | ) |
Load a font without specifying a size (size determined later).
| tf | Path to the TTF/OTF file. |
Definition at line 9 of file font.cpp.
References loadFont().
| mx::Font::Font | ( | const std::string & | tf, |
| int | size ) |
Load a font at the given point size.
| tf | Path to the TTF/OTF file. |
| size | Point size to load. |
Definition at line 20 of file font.cpp.
References loadFont(), and the_font.
| mx::Font::Font | ( | TTF_Font * | tf | ) |
|
delete |
References Font().
| mx::Font::Font | ( | Font && | f | ) |
| mx::Font::~Font | ( | ) |
|
inline |
| void mx::Font::loadFont | ( | const std::string & | fname, |
| int | size ) |
Load a font, throwing mx::Exception on failure.
| fname | Path to the font file. |
| size | Desired point size. |
Definition at line 66 of file font.cpp.
References tryLoadFont().
| bool mx::Font::tryLoadFont | ( | const std::string & | fname, |
| int | size ) |
Attempt to load a font, returning false on failure.
| fname | Path to the font file. |
| size | Desired point size. |
true if loaded successfully, false otherwise. Definition at line 45 of file font.cpp.
References mx::system_err, and the_font.
Referenced by loadFont().
|
inline |
Unwrap the TTF_Font pointer, throwing on null.
| mx::Exception | if the font is not loaded. |
Definition at line 88 of file font.hpp.
References the_font.
|
inline |
Return a Wrapper around the TTF_Font handle.
Definition at line 100 of file font.hpp.
References the_font.
Referenced by gl::GLText::printText_Blended(), mx::Text::printText_Blended(), gl::GLText::printText_Solid(), and mx::Text::printText_Solid().
|
private |