diff --git a/src/Atlas.cpp b/src/Atlas.cpp index 53c67cf..24e6417 100644 --- a/src/Atlas.cpp +++ b/src/Atlas.cpp @@ -9,27 +9,28 @@ #include #include -ofxMsdfgen::Atlas::Atlas(){ +namespace ofxMsdfgen { +Atlas::Atlas(){ } -ofxMsdfgen::Atlas::~Atlas(){ +Atlas::~Atlas(){ } -void ofxMsdfgen::Atlas::setup(string _fontPath){ +void Atlas::setup(string _fontPath){ fontPath = _fontPath; if(generate()){ - ofLogNotice("ofxMsdfgen::Atlas::setup()") << "generated Atlas"; + ofLogNotice("Atlas::setup()") << "generated Atlas"; }else{ - ofLogError("ofxMsdfgen::Atlas::setup()") << "whoops, could not generate Atlas"; + ofLogError("Atlas::setup()") << "whoops, could not generate Atlas"; } } -void ofxMsdfgen::Atlas::setup(string _fontPath, - AtlasSettings _settings){ +void Atlas::setup(string _fontPath, + AtlasSettings _settings){ settings = _settings; setup(_fontPath); } -bool ofxMsdfgen::Atlas::generate(){ +bool Atlas::generate(){ bool success = false; //{ msdfgen::FreetypeHandle * ft = msdfgen::initializeFreetype(); @@ -110,7 +111,8 @@ bool ofxMsdfgen::Atlas::generate(){ // The atlas bitmap can now be retrieved via atlasStorage as a BitmapConstRef. // The glyphs array (or fontGeometry) contains positioning data for typesetting text. msdfgen::Bitmap bitmap(generator.atlasStorage()); - ofxMsdfgen::toOfImage(bitmap, atlasImage); + toOfImage(bitmap, atlasImage); + atlasImage.update(); std::vector layout = generator.getLayout(); int i = 0; @@ -129,10 +131,25 @@ bool ofxMsdfgen::Atlas::generate(){ return success; } -const ofImage & ofxMsdfgen::Atlas::getAtlasImage(){ +const ofImage & Atlas::getAtlasImage(){ return atlasImage; } -const vector & ofxMsdfgen::Atlas::getGlyphGeometries(){ +const vector & Atlas::getGlyphGeometries(){ return glyphGeometries; } + +const GlyphGeometry & Atlas::getGlyphGeometry(unsigned char character){ + for(const GlyphGeometry & gg : glyphGeometries){ + if(gg.getCodepoint() == static_cast (character)){ + return gg; + } + } + // not found! + ofLogError("Atlas::getGlyphGeometry") + << "glyph(" << character << ") not found!" << endl + << "returning first glyph. this is bad." << endl; + // FIXME: proper error handling + return glyphGeometries[0]; +} +} diff --git a/src/Atlas.h b/src/Atlas.h index 528a8bd..fffc437 100644 --- a/src/Atlas.h +++ b/src/Atlas.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "conversion.h" namespace ofxMsdfgen { @@ -30,6 +31,7 @@ class Atlas { bool generate(); const ofImage & getAtlasImage(); const vector & getGlyphGeometries(); + const GlyphGeometry & getGlyphGeometry(unsigned char character); AtlasSettings settings; private: string fontPath;