Created
August 19, 2016 16:31
-
-
Save ryanbartley/cdf2fd9d33acca372717c40777f58cd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ci::gl::SdfTextRef sdfText; | |
std::array<gl::SdfText::Font::Glyph, 5> *descentGlyphs; | |
uint32_t texture; | |
float furtherOffset; | |
if( genName == GeneratorName::GEO_LABEL_COUNTRY || genName == GeneratorName::CLUSTER_LABEL_CONTINENT ) { | |
sdfText = mBoldSdf; | |
descentGlyphs = &mBoldDescentGlyphs; | |
furtherOffset = 1.51; | |
texture = 0; | |
} | |
else if( genName == GeneratorName::GEO_LABEL_CITY || genName == GeneratorName::CLUSTER_LABEL ) { | |
sdfText = mRomanSdf; | |
descentGlyphs = &mRomanDescentGlyphs; | |
furtherOffset = 1.51; | |
texture = 1; | |
} | |
auto height = sdfText->getHeight(); | |
auto ascent = sdfText->getAscent(); | |
auto descent = sdfText->getDescent(); | |
auto glyphPlacement = sdfText->getGlyphPlacements( current->getText(), Rectf( 0, 0, 200, 21.969 ) ); | |
Rectf bounding; | |
auto glyphVerts = sdfText->getGlyphVertices( glyphPlacement, &bounding ); | |
auto numGlyphs = glyphVerts.size(); | |
auto widthOffset = lmap( float(numGlyphs), 0.0f, 26.0f, 1.0f, -0.5f ); | |
std::transform( glyphVerts.begin(), glyphVerts.end(), std::back_inserter( vert->vertices ), | |
[bounding, descentGlyphs, height, numGlyphs, widthOffset, | |
descent, ascent, furtherOffset]( const gl::SdfText::InstanceVertex &vert ){ | |
LabelVertices::LabelVertex ret; | |
auto searchGlyph = vert.glyph; | |
auto endIt = end( *descentGlyphs ); | |
auto foundIt = std::find_if( begin( *descentGlyphs ), endIt, | |
[searchGlyph]( const gl::SdfText::Font::Glyph &glyph ){ | |
return glyph == searchGlyph; | |
}); | |
float yOffset = 0; | |
if( foundIt != endIt ) { | |
yOffset = -ascent + descent + furtherOffset; | |
} | |
ret.position = vert.pos; | |
ret.position.x -= (bounding.getWidth() / (2.5f + widthOffset)); | |
ret.position.y += yOffset + (ascent * 1.4f); //+ (bounding.getHeight() / 2.0f); | |
ret.size = vert.size; | |
ret.texCoords = vert.texCoords; | |
return ret; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment