Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions graf2d/graf/inc/TTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
22 changes: 10 additions & 12 deletions graf2d/graf/src/TTF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,8 +72,6 @@ struct TTFhandle::FT_Library_Wrapper {
return _library;
}

bool InitCompleted() const { return _library != nullptr; }

~FT_Library_Wrapper()
{
if (_library)
Expand All @@ -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();
}

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -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();
}

Expand Down
Loading