diff --git a/graf2d/graf/inc/TTF.h b/graf2d/graf/inc/TTF.h index 773459a9502d2..60dc87c37d279 100644 --- a/graf2d/graf/inc/TTF.h +++ b/graf2d/graf/inc/TTF.h @@ -68,6 +68,7 @@ class TTF { FT_Vector fPos; ///< position of glyph origin FT_Glyph fImage{nullptr}; ///< glyph image TTGlyph(UInt_t indx = 0) : fIndex(indx) {} + ~TTGlyph(); }; TTF() {} diff --git a/graf2d/graf/src/TTF.cxx b/graf2d/graf/src/TTF.cxx index 5621cfa749433..c026beb98de4f 100644 --- a/graf2d/graf/src/TTF.cxx +++ b/graf2d/graf/src/TTF.cxx @@ -35,6 +35,11 @@ const Float_t kScale = 0.93376068; Bool_t TTFhandle::fgHinting = kFALSE; Bool_t TTFhandle::fgSmoothing = kTRUE; +/// Free all resources of this glyph. +TTF::TTGlyph::~TTGlyph() +{ + FT_Done_Glyph(fImage); +} struct TTFontHandle { std::string name; @@ -67,8 +72,6 @@ struct TTFhandle::FT_Library_Wrapper { return _library; } - bool InitCompleted() const { return _library != nullptr; } - ~FT_Library_Wrapper() { if (_library) @@ -80,7 +83,11 @@ thread_local TTFhandle::FT_Library_Wrapper TTFhandle::fFT_Library; //////////////////////////////////////////////////////////////////////////////// -TTFhandle::TTFhandle() = default; +TTFhandle::TTFhandle() +{ + // Ensure that there's a freetype library in our thread + fFT_Library.Get(); +} //////////////////////////////////////////////////////////////////////////////// @@ -278,15 +285,6 @@ FT_BitmapGlyph TTFhandle::GetGlyphBitmap(UInt_t n, Bool_t smooth) void TTFhandle::CleanupGlyphs() { - bool is_lib = fFT_Library.InitCompleted(); - - for(auto &glyph : fGlyphs) { - // clear existing image if there is one - if (glyph.fImage && is_lib) { - FT_Done_Glyph(glyph.fImage); - glyph.fImage = nullptr; - } - } fGlyphs.clear(); }