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(){
|
||||||
}
|
}
|
||||||
Atlas::~Atlas(){
|
Atlas::~Atlas(){
|
||||||
|
msdfgen::destroyFont(font);
|
||||||
|
msdfgen::deinitializeFreetype(ft);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Atlas::setup(string _fontPath){
|
void Atlas::setup(string _fontPath){
|
||||||
|
@ -42,7 +44,8 @@ bool Atlas::generate(){
|
||||||
std::vector <msdf_atlas::GlyphGeometry> glyphs;
|
std::vector <msdf_atlas::GlyphGeometry> glyphs;
|
||||||
// FontGeometry is a helper class that loads a set of glyphs from a single font.
|
// 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.
|
// 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:
|
// Load a set of character glyphs:
|
||||||
// The second argument can be ignored unless you mix different font sizes in one atlas.
|
// 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.
|
// 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();
|
std::vector <msdf_atlas::GlyphBox> layout = generator.getLayout();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(const msdf_atlas::GlyphBox & gb : layout){
|
for(const msdf_atlas::GlyphBox & gb : layout){
|
||||||
msdf_atlas::GlyphGeometry gg = glyphs.data()[i];
|
msdf_atlas::GlyphGeometry gg = glyphs[i];
|
||||||
i++;
|
i++;
|
||||||
glyphGeometries.push_back(gg);
|
glyphGeometries.push_back(gg);
|
||||||
}
|
}
|
||||||
// Cleanup
|
// Cleanup
|
||||||
msdfgen::destroyFont(font);
|
//msdfgen::destroyFont(font);
|
||||||
|
|
||||||
success = true; // FIXME: always turns true, why do we have this
|
success = true; // FIXME: always turns true, why do we have this
|
||||||
}
|
}
|
||||||
msdfgen::deinitializeFreetype(ft);
|
//msdfgen::deinitializeFreetype(ft);
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -152,4 +155,8 @@ const GlyphGeometry & Atlas::getGlyphGeometry(unsigned char character){
|
||||||
// FIXME: proper error handling
|
// FIXME: proper error handling
|
||||||
return glyphGeometries[0];
|
return glyphGeometries[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FontGeometry & Atlas::getFontGeometry(){
|
||||||
|
return fontGeometry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "import-font.h"
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
#include "ofTrueTypeFont.h"
|
#include "ofTrueTypeFont.h"
|
||||||
#include <freetype2/freetype/freetype.h>
|
#include <freetype2/freetype/freetype.h>
|
||||||
|
@ -32,10 +33,14 @@ class Atlas {
|
||||||
const ofImage & getAtlasImage();
|
const ofImage & getAtlasImage();
|
||||||
const vector <GlyphGeometry> & getGlyphGeometries();
|
const vector <GlyphGeometry> & getGlyphGeometries();
|
||||||
const GlyphGeometry & getGlyphGeometry(unsigned char character);
|
const GlyphGeometry & getGlyphGeometry(unsigned char character);
|
||||||
|
const FontGeometry & getFontGeometry();
|
||||||
AtlasSettings settings;
|
AtlasSettings settings;
|
||||||
private:
|
private:
|
||||||
string fontPath;
|
string fontPath;
|
||||||
ofImage atlasImage;
|
ofImage atlasImage;
|
||||||
vector <GlyphGeometry> glyphGeometries;
|
vector <GlyphGeometry> glyphGeometries;
|
||||||
|
FontGeometry fontGeometry;
|
||||||
|
msdfgen::FontHandle * font;
|
||||||
|
msdfgen::FreetypeHandle * ft;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
namespace ofxMsdfgen {
|
namespace ofxMsdfgen {
|
||||||
using GlyphBox = msdf_atlas::GlyphBox;
|
using GlyphBox = msdf_atlas::GlyphBox;
|
||||||
using GlyphGeometry = msdf_atlas::GlyphGeometry;
|
using GlyphGeometry = msdf_atlas::GlyphGeometry;
|
||||||
|
using FontGeometry = msdf_atlas::FontGeometry;
|
||||||
|
|
||||||
void toOfImage(const msdfgen::Bitmap <float, 3> bitmap,
|
void toOfImage(const msdfgen::Bitmap <float, 3> bitmap,
|
||||||
ofFloatImage & image);
|
ofFloatImage & image);
|
||||||
|
|
Loading…
Reference in a new issue