diff --git a/src/Atlas.cpp b/src/Atlas.cpp index 24e6417..26bad30 100644 --- a/src/Atlas.cpp +++ b/src/Atlas.cpp @@ -13,6 +13,8 @@ namespace ofxMsdfgen { Atlas::Atlas(){ } Atlas::~Atlas(){ + msdfgen::destroyFont(font); + msdfgen::deinitializeFreetype(ft); } void Atlas::setup(string _fontPath){ @@ -42,7 +44,8 @@ bool Atlas::generate(){ std::vector glyphs; // FontGeometry is a helper class that loads a set of glyphs from a single font. // It can also be used to get additional font metrics, kerning information, etc. - msdf_atlas::FontGeometry fontGeometry(&glyphs); + msdf_atlas::FontGeometry _fontGeometry(&glyphs); + fontGeometry = _fontGeometry; // Load a set of character glyphs: // The second argument can be ignored unless you mix different font sizes in one atlas. // In the last argument, you can specify a charset other than ASCII. @@ -117,16 +120,16 @@ bool Atlas::generate(){ std::vector layout = generator.getLayout(); int i = 0; for(const msdf_atlas::GlyphBox & gb : layout){ - msdf_atlas::GlyphGeometry gg = glyphs.data()[i]; + msdf_atlas::GlyphGeometry gg = glyphs[i]; i++; glyphGeometries.push_back(gg); } // Cleanup - msdfgen::destroyFont(font); + //msdfgen::destroyFont(font); success = true; // FIXME: always turns true, why do we have this } - msdfgen::deinitializeFreetype(ft); + //msdfgen::deinitializeFreetype(ft); } return success; } @@ -152,4 +155,8 @@ const GlyphGeometry & Atlas::getGlyphGeometry(unsigned char character){ // FIXME: proper error handling return glyphGeometries[0]; } + +const FontGeometry & Atlas::getFontGeometry(){ + return fontGeometry; +} } diff --git a/src/Atlas.h b/src/Atlas.h index fffc437..a339b89 100644 --- a/src/Atlas.h +++ b/src/Atlas.h @@ -1,5 +1,6 @@ #pragma once +#include "import-font.h" #include "ofMain.h" #include "ofTrueTypeFont.h" #include @@ -32,10 +33,14 @@ class Atlas { const ofImage & getAtlasImage(); const vector & getGlyphGeometries(); const GlyphGeometry & getGlyphGeometry(unsigned char character); + const FontGeometry & getFontGeometry(); AtlasSettings settings; private: string fontPath; ofImage atlasImage; vector glyphGeometries; + FontGeometry fontGeometry; + msdfgen::FontHandle * font; + msdfgen::FreetypeHandle * ft; }; } diff --git a/src/conversion.h b/src/conversion.h index 28da6a7..2d7ca8a 100644 --- a/src/conversion.h +++ b/src/conversion.h @@ -10,6 +10,7 @@ namespace ofxMsdfgen { using GlyphBox = msdf_atlas::GlyphBox; using GlyphGeometry = msdf_atlas::GlyphGeometry; +using FontGeometry = msdf_atlas::FontGeometry; void toOfImage(const msdfgen::Bitmap bitmap, ofFloatImage & image);