getFontGeaometry and destroy fonts on Atlas destructor
This commit is contained in:
parent
3933e7b2ba
commit
f81faaa42a
3 changed files with 17 additions and 4 deletions
|
@ -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 <msdf_atlas::GlyphGeometry> 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 <msdf_atlas::GlyphBox> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "import-font.h"
|
||||
#include "ofMain.h"
|
||||
#include "ofTrueTypeFont.h"
|
||||
#include <freetype2/freetype/freetype.h>
|
||||
|
@ -32,10 +33,14 @@ class Atlas {
|
|||
const ofImage & getAtlasImage();
|
||||
const vector <GlyphGeometry> & getGlyphGeometries();
|
||||
const GlyphGeometry & getGlyphGeometry(unsigned char character);
|
||||
const FontGeometry & getFontGeometry();
|
||||
AtlasSettings settings;
|
||||
private:
|
||||
string fontPath;
|
||||
ofImage atlasImage;
|
||||
vector <GlyphGeometry> glyphGeometries;
|
||||
FontGeometry fontGeometry;
|
||||
msdfgen::FontHandle * font;
|
||||
msdfgen::FreetypeHandle * ft;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 <float, 3> bitmap,
|
||||
ofFloatImage & image);
|
||||
|
|
Loading…
Reference in a new issue