diff --git a/minuitwrp/truetype.cpp b/minuitwrp/truetype.cpp index de927156..86954325 100755 --- a/minuitwrp/truetype.cpp +++ b/minuitwrp/truetype.cpp @@ -77,13 +77,14 @@ void* twrpTruetype::gr_ttf_loadFont(const char *filename, int size, int dpi) { int error; TrueTypeFont* res = nullptr; TrueTypeFontKey* key; + std::string fontFileName(filename); pthread_mutex_lock(&font_data.mutex); TrueTypeFontKey k = { .size = size, .dpi = dpi, - .path = (char*)filename + .path = fontFileName }; TrueTypeFontMap::iterator ttfIter = font_data.fonts.find(k); @@ -154,7 +155,7 @@ void* twrpTruetype::gr_ttf_scaleFont(void *font, int max_width, int measured_wid int new_size = ((int)((float)f->size * scale_value)) - 1; if (new_size < 1) new_size = 1; - const char* file = f->key->path; + const char* file = f->key->path.c_str(); int dpi = f->dpi; return gr_ttf_loadFont(file, new_size, dpi); } @@ -182,7 +183,6 @@ void twrpTruetype::gr_ttf_freeFont(void *font) { TrueTypeFont *d = (TrueTypeFont *)font; if(--d->refcount == 0) { - delete d->key->path; delete d->key; FT_Done_Face(d->face); diff --git a/minuitwrp/truetype.hpp b/minuitwrp/truetype.hpp index 3ae20905..72b7620a 100755 --- a/minuitwrp/truetype.hpp +++ b/minuitwrp/truetype.hpp @@ -29,11 +29,11 @@ typedef struct TrueTypeFontKey { int size; int dpi; - char *path; + std::string path; } TrueTypeFontKey; inline bool operator<(const TrueTypeFontKey &ttfkLeft, const TrueTypeFontKey &ttfkRight) { - return std::tie(ttfkLeft.size, ttfkLeft.dpi, *ttfkLeft.path) < std::tie(ttfkRight.size, ttfkRight.dpi, *ttfkRight.path); + return std::tie(ttfkLeft.size, ttfkLeft.dpi, ttfkLeft.path) < std::tie(ttfkRight.size, ttfkRight.dpi, ttfkRight.path); } typedef struct {