glyph pairs for interpolation
This commit is contained in:
parent
cfb5502dd3
commit
5fc06a177b
2 changed files with 95 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "Atlas.h"
|
#include "Atlas.h"
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
|
#include "edge-coloring.h"
|
||||||
#include "import-font.h"
|
#include "import-font.h"
|
||||||
|
|
||||||
namespace ofxMsdfgen {
|
namespace ofxMsdfgen {
|
||||||
|
@ -184,6 +185,16 @@ bool Atlas::generate(){
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vgi = 0;
|
||||||
|
for(const auto & vg : variationGlyphs){
|
||||||
|
const unsigned char cp = vg.getCodepoint();
|
||||||
|
GlyphVariationKey key;
|
||||||
|
key.character = cp;
|
||||||
|
key.variation = variation;
|
||||||
|
glyphGeometryMap[key] = glyphs.size() + vgi;
|
||||||
|
vgi++;
|
||||||
|
}
|
||||||
|
|
||||||
glyphs.insert(glyphs.end(),
|
glyphs.insert(glyphs.end(),
|
||||||
variationGlyphs.begin(),
|
variationGlyphs.begin(),
|
||||||
variationGlyphs.end());
|
variationGlyphs.end());
|
||||||
|
@ -192,10 +203,18 @@ bool Atlas::generate(){
|
||||||
}
|
}
|
||||||
// Apply MSDF edge coloring. See edge-coloring.h for other coloring strategies.
|
// Apply MSDF edge coloring. See edge-coloring.h for other coloring strategies.
|
||||||
for(msdf_atlas::GlyphGeometry & glyph : glyphs){
|
for(msdf_atlas::GlyphGeometry & glyph : glyphs){
|
||||||
//FIXME: we do not need to inverse y axis, something else is wrong
|
// NOTE: const_cast is potentially evil,
|
||||||
|
// but like this we can use clipper for preprocessing shapes
|
||||||
// msdfgen::Shape & shape = const_cast <msdfgen::Shape &>(glyph.getShape());
|
// msdfgen::Shape & shape = const_cast <msdfgen::Shape &>(glyph.getShape());
|
||||||
|
// then convert Shape to ofPolyline and use getResampledBySpacing
|
||||||
|
// to convert it into straight lines
|
||||||
|
// then use clipper2 to union the shapes
|
||||||
|
// convert back into ofPolyline and then Shape
|
||||||
|
// or directly into Shape
|
||||||
|
//
|
||||||
|
// don't do this:
|
||||||
// shape.inverseYAxis = true;
|
// shape.inverseYAxis = true;
|
||||||
glyph.edgeColoring(&msdfgen::edgeColoringInkTrap, // strategy
|
glyph.edgeColoring(&msdfgen::edgeColoringSimple, // strategy
|
||||||
settings.maxCornerAngle, // angleThreshold
|
settings.maxCornerAngle, // angleThreshold
|
||||||
0); // seed
|
0); // seed
|
||||||
}
|
}
|
||||||
|
@ -277,12 +296,76 @@ const GlyphGeometry & Atlas::getGlyphGeometry(unsigned char character){
|
||||||
const GlyphGeometry & Atlas::getGlyphGeometry(unsigned char character,
|
const GlyphGeometry & Atlas::getGlyphGeometry(unsigned char character,
|
||||||
FontVariation variation){
|
FontVariation variation){
|
||||||
// FIXME: error handling?
|
// FIXME: error handling?
|
||||||
//GlyphVariationKey key = {character, variation};
|
float smallestDistance = FLT_MAX;
|
||||||
//int index = glyphGeometryMap[key];
|
int closestIndex = 0;
|
||||||
return glyphGeometries[0];
|
int i = 0;
|
||||||
|
for(const auto & v : variationSteps){
|
||||||
|
float distance = abs(v.value - variation.value);
|
||||||
|
if(distance < smallestDistance){
|
||||||
|
smallestDistance = distance;
|
||||||
|
closestIndex = i;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
const auto & closestVariation = variationSteps[closestIndex];
|
||||||
|
GlyphVariationKey key = {character, closestVariation};
|
||||||
|
int index = glyphGeometryMap[key];
|
||||||
|
return glyphGeometries[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Atlas::getGlyphGeometryPair(const unsigned char character,
|
||||||
|
const FontVariation variation,
|
||||||
|
GlyphGeometry & a,
|
||||||
|
GlyphGeometry & b,
|
||||||
|
float & mix){
|
||||||
|
float smallestDistanceDown = -1 * FLT_MAX;
|
||||||
|
float smallestDistanceUp = FLT_MAX;
|
||||||
|
int closestIndexDown = 0;
|
||||||
|
int closestIndexUp = 0;
|
||||||
|
int i = 0;
|
||||||
|
for(const auto & v : variationSteps){
|
||||||
|
float distance = v.value - variation.value;
|
||||||
|
if(distance <= 0){
|
||||||
|
if(distance > smallestDistanceDown){
|
||||||
|
closestIndexDown = i;
|
||||||
|
smallestDistanceDown = distance;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(distance < smallestDistanceUp){
|
||||||
|
closestIndexUp = i;
|
||||||
|
smallestDistanceUp = distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
float total = abs(smallestDistanceUp) + abs(smallestDistanceDown);
|
||||||
|
//mix = ofMap(abs(smallestDistanceDown), 0, total, 0, 1);
|
||||||
|
mix = total == 0 || smallestDistanceDown == 0 ? 0 : abs(smallestDistanceDown) / total;
|
||||||
|
}
|
||||||
|
if(mix < 0 || mix > 1){
|
||||||
|
ofLogError("Atlas::getGlyphGeometryPair")
|
||||||
|
<< "mix out of range.\n"
|
||||||
|
<< "sorry for the shitty error message, just check the code";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto & closestVariationUp = variationSteps[closestIndexUp];
|
||||||
|
const auto & closestVariationDown = variationSteps[closestIndexDown];
|
||||||
|
GlyphVariationKey glyphKeyUp = {character, closestVariationUp};
|
||||||
|
GlyphVariationKey glyphKeyDown = {character, closestVariationDown};
|
||||||
|
int index_a = glyphGeometryMap[glyphKeyDown];
|
||||||
|
int index_b = glyphGeometryMap[glyphKeyUp];
|
||||||
|
a = glyphGeometries[index_a];
|
||||||
|
b = glyphGeometries[index_b];
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FontGeometry & Atlas::getFontGeometry(){
|
const FontGeometry & Atlas::getFontGeometry(){
|
||||||
return fontGeometry;
|
return fontGeometry;
|
||||||
}
|
}
|
||||||
|
const vector <ofxMsdfgen::FontVariationAxis> & Atlas::getVariationAxesAvailable(){
|
||||||
|
return variationAxesAvailable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,8 +93,15 @@ class Atlas {
|
||||||
const GlyphGeometry & getGlyphGeometry(unsigned char character);
|
const GlyphGeometry & getGlyphGeometry(unsigned char character);
|
||||||
const GlyphGeometry & getGlyphGeometry(unsigned char character,
|
const GlyphGeometry & getGlyphGeometry(unsigned char character,
|
||||||
FontVariation variation);
|
FontVariation variation);
|
||||||
|
bool getGlyphGeometryPair(const unsigned char character,
|
||||||
|
const FontVariation variation,
|
||||||
|
GlyphGeometry & a,
|
||||||
|
GlyphGeometry & b,
|
||||||
|
float & mix);
|
||||||
|
|
||||||
//const GlyphGeometry & getGlyphGeometry(GlyphVariationKey key);
|
//const GlyphGeometry & getGlyphGeometry(GlyphVariationKey key);
|
||||||
const FontGeometry & getFontGeometry();
|
const FontGeometry & getFontGeometry();
|
||||||
|
const vector <FontVariationAxis> & getVariationAxesAvailable();
|
||||||
AtlasSettings settings;
|
AtlasSettings settings;
|
||||||
msdfgen::FontHandle * font;
|
msdfgen::FontHandle * font;
|
||||||
msdfgen::FreetypeHandle * ft;
|
msdfgen::FreetypeHandle * ft;
|
||||||
|
|
Loading…
Reference in a new issue