11 using FontFaceDisposingFunction = void(*)(
void*);
17 FontFaceDisposingFunction dispose_fn;
19 FontFace(
void *buf,
const size_t buf_size, FontFaceDisposingFunction disp_fn,
const u32 font_sz,
void *font_class_ptr) : font(
nullptr), ptr(buf), ptr_sz(buf_size), dispose_fn(disp_fn) {
20 this->font =
TTF_OpenFontRW(SDL_RWFromMem(this->ptr, this->ptr_sz), 1, font_sz);
21 if(this->font !=
nullptr) {
28 inline bool IsSourceValid() {
30 return (this->ptr !=
nullptr) && (this->ptr_sz > 0);
34 if(this->font !=
nullptr) {
42 if(this->IsSourceValid()) {
43 (this->dispose_fn)(this->ptr);
51 std::vector<std::pair<i32, std::unique_ptr<FontFace>>> font_faces;
55 if(!this->font_faces.empty()) {
56 return this->font_faces.begin()->second->font;
71 Font(
const u32 font_sz) : font_size(font_sz) {}
79 return this->font_size;
Definition: ttf_Font.hpp:9
void Unload(const i32 font_idx)
static void EmptyFontFaceDisposingFunction(void *)
Definition: ttf_Font.hpp:65
i32 LoadFromMemory(void *ptr, const size_t size, FontFaceDisposingFunction disp_fn)
sdl2::Texture RenderText(const std::string &str, const ui::Color clr)
u32 GetFontSize()
Definition: ttf_Font.hpp:78
static constexpr i32 InvalidFontFaceIndex
Definition: ttf_Font.hpp:62
sdl2::Font FindValidFontFor(const char ch)
static constexpr bool IsValidFontFaceIndex(const i32 index)
Definition: ttf_Font.hpp:67
Font(const u32 font_sz)
Definition: ttf_Font.hpp:71
static constexpr u32 DefaultFontSize
Definition: ttf_Font.hpp:63
i32 LoadFromFile(const std::string &path)
std::pair< u32, u32 > GetTextDimensions(const std::string &str)
SDL_Texture * Texture
Definition: sdl2_Types.hpp:11
TTF_Font * Font
Definition: sdl2_Types.hpp:14
Definition: ttf_Font.hpp:7
s32 i32
Definition: pu_Include.hpp:28
DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font)
DECLSPEC TTF_Font *SDLCALL TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize)
void TTF_CppWrap_SetCppPtrRef(TTF_Font *font, void *cpp_ptr_ref)
Definition: ui_Types.hpp:44