get individual glyphgeometry ... and namespace
This commit is contained in:
parent
c3c58b422b
commit
b2b0fafe76
2 changed files with 30 additions and 11 deletions
|
@ -9,27 +9,28 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
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;
|
fontPath = _fontPath;
|
||||||
if(generate()){
|
if(generate()){
|
||||||
ofLogNotice("ofxMsdfgen::Atlas::setup()") << "generated Atlas";
|
ofLogNotice("Atlas::setup()") << "generated Atlas";
|
||||||
}else{
|
}else{
|
||||||
ofLogError("ofxMsdfgen::Atlas::setup()") << "whoops, could not generate Atlas";
|
ofLogError("Atlas::setup()") << "whoops, could not generate Atlas";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ofxMsdfgen::Atlas::setup(string _fontPath,
|
void Atlas::setup(string _fontPath,
|
||||||
AtlasSettings _settings){
|
AtlasSettings _settings){
|
||||||
settings = _settings;
|
settings = _settings;
|
||||||
setup(_fontPath);
|
setup(_fontPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ofxMsdfgen::Atlas::generate(){
|
bool Atlas::generate(){
|
||||||
bool success = false;
|
bool success = false;
|
||||||
//{
|
//{
|
||||||
msdfgen::FreetypeHandle * ft = msdfgen::initializeFreetype();
|
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 atlas bitmap can now be retrieved via atlasStorage as a BitmapConstRef.
|
||||||
// The glyphs array (or fontGeometry) contains positioning data for typesetting text.
|
// The glyphs array (or fontGeometry) contains positioning data for typesetting text.
|
||||||
msdfgen::Bitmap <float, 3> bitmap(generator.atlasStorage());
|
msdfgen::Bitmap <float, 3> bitmap(generator.atlasStorage());
|
||||||
ofxMsdfgen::toOfImage(bitmap, atlasImage);
|
toOfImage(bitmap, atlasImage);
|
||||||
|
atlasImage.update();
|
||||||
|
|
||||||
std::vector <msdf_atlas::GlyphBox> layout = generator.getLayout();
|
std::vector <msdf_atlas::GlyphBox> layout = generator.getLayout();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -129,10 +131,25 @@ bool ofxMsdfgen::Atlas::generate(){
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ofImage & ofxMsdfgen::Atlas::getAtlasImage(){
|
const ofImage & Atlas::getAtlasImage(){
|
||||||
return atlasImage;
|
return atlasImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vector <ofxMsdfgen::GlyphGeometry> & ofxMsdfgen::Atlas::getGlyphGeometries(){
|
const vector <GlyphGeometry> & Atlas::getGlyphGeometries(){
|
||||||
return glyphGeometries;
|
return glyphGeometries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GlyphGeometry & Atlas::getGlyphGeometry(unsigned char character){
|
||||||
|
for(const GlyphGeometry & gg : glyphGeometries){
|
||||||
|
if(gg.getCodepoint() == static_cast <msdf_atlas::unicode_t>(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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <freetype2/freetype/freetype.h>
|
#include <freetype2/freetype/freetype.h>
|
||||||
#include <msdf-atlas-gen/msdf-atlas-gen.h>
|
#include <msdf-atlas-gen/msdf-atlas-gen.h>
|
||||||
#include <msdf-atlas-gen/types.h>
|
#include <msdf-atlas-gen/types.h>
|
||||||
|
#include <unordered_map>
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
|
|
||||||
namespace ofxMsdfgen {
|
namespace ofxMsdfgen {
|
||||||
|
@ -30,6 +31,7 @@ class Atlas {
|
||||||
bool generate();
|
bool generate();
|
||||||
const ofImage & getAtlasImage();
|
const ofImage & getAtlasImage();
|
||||||
const vector <GlyphGeometry> & getGlyphGeometries();
|
const vector <GlyphGeometry> & getGlyphGeometries();
|
||||||
|
const GlyphGeometry & getGlyphGeometry(unsigned char character);
|
||||||
AtlasSettings settings;
|
AtlasSettings settings;
|
||||||
private:
|
private:
|
||||||
string fontPath;
|
string fontPath;
|
||||||
|
|
Loading…
Reference in a new issue