diff --git a/sfw/render_core/font.cpp b/sfw/render_core/font.cpp index be13887..fb47086 100644 --- a/sfw/render_core/font.cpp +++ b/sfw/render_core/font.cpp @@ -63,12 +63,12 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font return; } + unload(); + if (!(flags & FONT_ASCII)) { flags |= FONT_ASCII; // ensure this minimal range [0020-00FF] is almost always in } - _initialized = 1; - // load .ttf into a bitmap using stb_truetype.h int dim = flags & FONT_4096 ? 4096 : flags & FONT_2048 ? 2048 : flags & FONT_1024 ? 1024 @@ -304,6 +304,9 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font memdelete_arr(cdata); _initialized = true; + +#undef MERGE_TABLE +#undef MERGE_PACKED_TABLE } void Font::font_face(const char *filename_ttf, float font_size, unsigned flags) { @@ -442,6 +445,55 @@ Ref Font::get_texture() { return _texture; } -Font::Font() { +void Font::unload() { + if (!_initialized) { + return; + } + + _num_glyphs = 0; + _cp2iter = NULL; + _iter2cp = NULL; + _begin = 0; + _initialized = false; + + _height = 0; + _width = 0; + _font_size = 0; + _factor = 0; + _scale = 0; + + _ascent = 0; + _descent = 0; + _linegap = 0; + _linedist = 0; + + _image.unref(); + _texture.unref(); + + _texture_offsets.clear(); +} + +Font::Font() { + _num_glyphs = 0; + _cp2iter = NULL; + _iter2cp = NULL; + _begin = 0; + + _initialized = false; + + _height = 0; + _width = 0; + _font_size = 0; + _factor = 0; + _scale = 0; + + _ascent = 0; + _descent = 0; + _linegap = 0; + _linedist = 0; +} + +Font::~Font() { + unload(); } diff --git a/sfw/render_core/font.h b/sfw/render_core/font.h index 306a47f..37f5d52 100644 --- a/sfw/render_core/font.h +++ b/sfw/render_core/font.h @@ -79,15 +79,18 @@ public: Ref get_image(); Ref get_texture(); + void unload(); + Font(); + ~Font(); protected: // character info // filled up by stb_truetype.h - unsigned _num_glyphs; - unsigned *_cp2iter; - unsigned *_iter2cp; - unsigned _begin; // first glyph. used in cp2iter table to clamp into a lesser range + uint32_t _num_glyphs; + uint32_t *_cp2iter; + uint32_t *_iter2cp; + uint32_t _begin; // first glyph. used in cp2iter table to clamp into a lesser range // font info and data bool _initialized;