Last active
August 17, 2016 19:27
-
-
Save ryanbartley/5f9626d9edb475826486d196d7ca7d0b 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
std::vector<SdfText::InstanceVertex> SdfText::getGlyphVertices( const SdfText::Font::GlyphMeasures &glyphMeasures, const DrawOptions &options, const std::vector<ColorA8u> &colors ) | |
{ | |
const auto& textures = mTextureAtlases->mTextures; | |
const auto& glyphMap = mTextureAtlases->mGlyphInfo; | |
const auto& sdfScale = mTextureAtlases->mSdfScale; | |
const auto& sdfPadding = mTextureAtlases->mSdfPadding; | |
if( textures.empty() ) { | |
return std::vector<SdfText::InstanceVertex>(); | |
} | |
if( ! colors.empty() ) { | |
CI_ASSERT( glyphMeasures.size() == colors.size() ); | |
} | |
const vec2 fontRenderScale = vec2( mFont.getSize() ) / ( 32.0f * mTextureAtlases->mSdfScale ); | |
const vec2 fontOriginScale = vec2( mFont.getSize() ) / 32.0f; | |
vec2 baseline = vec2( 0, 0 ); | |
std::vector<SdfText::InstanceVertex> ret; | |
ret.reserve( glyphMeasures.size() ); | |
const float scale = options.getScale(); | |
for( size_t texIdx = 0; texIdx < textures.size(); ++texIdx ) { | |
const gl::TextureRef &curTex = textures[texIdx]; | |
if( options.getPixelSnap() ) { | |
baseline = vec2( floor( baseline.x ), floor( baseline.y ) ); | |
} | |
for( auto glyphIt = glyphMeasures.begin(); glyphIt != glyphMeasures.end(); ++glyphIt ) { | |
auto glyphInfoIt = glyphMap.find( glyphIt->first ); | |
if( glyphInfoIt == glyphMap.end() ) { | |
CI_LOG_W( "Glyph: " << glyphIt->first << ", not found." ); | |
continue; | |
} | |
const auto &glyphInfo = glyphInfoIt->second; | |
if( glyphInfo.mTextureIndex != texIdx ) | |
continue; | |
const auto &originOffset = glyphInfo.mOriginOffset; | |
Rectf srcTexCoords = curTex->getAreaTexCoords( glyphInfo.mTexCoords ); | |
Rectf destRect = Rectf( glyphInfo.mTexCoords ); | |
destRect.scale( scale ); | |
destRect -= destRect.getUpperLeft(); | |
vec2 offset = vec2( 0, -( destRect.getHeight() ) ); | |
// Reverse the transformation applied during SDF generation | |
float tx = sdfPadding.x; | |
float ty = std::fabs( originOffset.y ) + sdfPadding.y; | |
offset += scale * sdfScale * vec2( -tx, ty ); | |
// Use origin scale for horizontal offset | |
offset += scale * fontOriginScale * vec2( originOffset.x, 0.0f ); | |
destRect += offset; | |
destRect.scale( fontRenderScale ); | |
destRect += glyphIt->second * scale; | |
destRect += baseline; | |
InstanceVertex vert; | |
vert.pos = vec2( destRect.x1, destRect.y1 ); | |
std::cout << destRect << std::endl; | |
vert.size = destRect.getSize(); | |
vert.texCoords = vec4( srcTexCoords.x1, srcTexCoords.y1, srcTexCoords.x2, srcTexCoords.y2 ); | |
ret.emplace_back( std::move( vert ) ); | |
} | |
} | |
return ret; | |
} |
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
auto sdfSize = sdfText->measureString( current->getText() ); | |
auto glyphPlacement = sdfText->getGlyphPlacements( current->getText(), Rectf( 0, 0, sdfSize.x, 21.969 ) ); | |
auto glyphVerts = sdfText->getGlyphVertices( glyphPlacement ); | |
std::transform( glyphVerts.begin(), glyphVerts.end(), std::back_inserter( vert->vertices ), | |
[sdfSize]( const gl::SdfText::InstanceVertex &vert ){ | |
LabelVertices::LabelVertex ret; | |
ret.position = vert.pos; | |
ret.size = vert.size; | |
ret.texCoords = vert.texCoords; | |
return ret; | |
}); |
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
auto sdfSize = sdfText->measureString( current->getText() ); | |
auto glyphPlacement = sdfText->getGlyphPlacements( current->getText(), Rectf( 0, 0, sdfSize.x, sdfSize.y ) ); | |
auto glyphVerts = sdfText->getGlyphVertices( glyphPlacement ); | |
for( auto vert : glyphVerts ) { | |
vert.pos.x -= sdfSize.x / 2.0f; | |
cout << vert.pos << " " << vert.size << " " << vert.texCoords << endl; | |
} | |
/* OUTPUT FROM ABOVE | |
[ -143.330, -19.594] [ 21.969, 21.969] [ 0.297, 1.000, 0.315, 0.982] | |
[ -118.706, -19.371] [ 21.969, 21.969] [ 0.761, 1.000, 0.779, 0.982] | |
[ -96.894, -15.920] [ 21.969, 21.969] [ 0.779, 1.000, 0.797, 0.982] | |
[ -74.360, -19.371] [ 21.969, 21.969] [ 0.872, 1.000, 0.890, 0.982] | |
[ -53.232, -19.594] [ 21.969, 21.969] [ 0.705, 1.000, 0.723, 0.982] | |
[ -44.796, -19.371] [ 21.969, 21.969] [ 0.501, 1.000, 0.519, 0.982] | |
[ -24.390, -19.594] [ 21.969, 21.969] [ 0.816, 1.000, 0.834, 0.982] | |
[ -11.736, -19.594] [ 21.969, 21.969] [ 0.000, 1.000, 0.018, 0.982] | |
[ -1.172, -19.278] [ 21.969, 21.969] [ 0.056, 1.000, 0.074, 0.982] | |
[ 26.264, -19.371] [ 21.969, 21.969] [ 0.872, 1.000, 0.890, 0.982] | |
[ 47.392, -19.594] [ 21.969, 21.969] [ 0.705, 1.000, 0.723, 0.982] | |
[ 55.828, -19.594] [ 21.969, 21.969] [ 0.854, 1.000, 0.872, 0.982] | |
[ 67.798, -19.371] [ 21.969, 21.969] [ 0.872, 1.000, 0.890, 0.982] | |
[ 88.926, -19.594] [ 21.969, 21.969] [ 0.816, 1.000, 0.834, 0.982] | |
[ 101.580, -19.371] [ 21.969, 21.969] [ 0.575, 1.000, 0.593, 0.982] | |
|error | void ocr::StaticResource::processMapLabelLayout(ocr::Content *, ocr::LabelVertex *, const layout::Component &, ocr::layout::GeneratorName)[334] ROMAN | |
[ -144.413, -19.278] [ 21.969, 21.969] [ 0.353, 1.000, 0.371, 0.982] | |
[ -119.789, -15.920] [ 21.969, 21.969] [ 0.779, 1.000, 0.797, 0.982] | |
[ -97.255, -19.371] [ 21.969, 21.969] [ 0.501, 1.000, 0.519, 0.982] | |
[ -76.849, -19.594] [ 21.969, 21.969] [ 0.742, 1.000, 0.760, 0.982] | |
[ -55.721, -19.594] [ 21.969, 21.969] [ 0.649, 1.000, 0.667, 0.982] | |
[ -47.285, -19.371] [ 21.969, 21.969] [ 0.835, 1.000, 0.853, 0.982] | |
[ -28.285, -19.594] [ 21.969, 21.969] [ 0.631, 1.000, 0.649, 0.982] | |
[ -7.157, -19.594] [ 21.969, 21.969] [ 0.000, 1.000, 0.018, 0.982] | |
[ 3.407, -19.594] [ 21.969, 21.969] [ 0.111, 1.000, 0.129, 0.982] | |
[ 25.219, -19.371] [ 21.969, 21.969] [ 0.872, 1.000, 0.890, 0.982] | |
[ 46.347, -19.594] [ 21.969, 21.969] [ 0.854, 1.000, 0.872, 0.982] | |
[ 58.317, -19.371] [ 21.969, 21.969] [ 0.520, 1.000, 0.538, 0.982] | |
[ 80.851, -19.371] [ 21.969, 21.969] [ 0.761, 1.000, 0.779, 0.982] | |
[ 102.663, -19.594] [ 21.969, 21.969] [ 0.705, 1.000, 0.723, 0.982] | |
*/ |
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
[ -143.330, -8.438] [ 21.969, 21.969] [ 0.297, 1.000, 0.315, 0.982] | |
[ -118.706, -8.215] [ 21.969, 21.969] [ 0.761, 1.000, 0.779, 0.982] | |
[ -96.894, -4.764] [ 21.969, 21.969] [ 0.779, 1.000, 0.797, 0.982] | |
[ -74.360, -8.215] [ 21.969, 21.969] [ 0.872, 1.000, 0.890, 0.982] | |
[ -53.232, -8.438] [ 21.969, 21.969] [ 0.705, 1.000, 0.723, 0.982] | |
[ -44.796, -8.215] [ 21.969, 21.969] [ 0.501, 1.000, 0.519, 0.982] | |
[ -24.390, -8.438] [ 21.969, 21.969] [ 0.816, 1.000, 0.834, 0.982] | |
[ -11.736, -8.438] [ 21.969, 21.969] [ 0.000, 1.000, 0.018, 0.982] | |
[ -1.172, -8.122] [ 21.969, 21.969] [ 0.056, 1.000, 0.074, 0.982] | |
[ 26.264, -8.215] [ 21.969, 21.969] [ 0.872, 1.000, 0.890, 0.982] | |
[ 47.392, -8.438] [ 21.969, 21.969] [ 0.705, 1.000, 0.723, 0.982] | |
[ 55.828, -8.438] [ 21.969, 21.969] [ 0.854, 1.000, 0.872, 0.982] | |
[ 67.798, -8.215] [ 21.969, 21.969] [ 0.872, 1.000, 0.890, 0.982] | |
[ 88.926, -8.438] [ 21.969, 21.969] [ 0.816, 1.000, 0.834, 0.982] | |
[ 101.580, -8.215] [ 21.969, 21.969] [ 0.575, 1.000, 0.593, 0.982] |
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
// This comes from getGlyphPlacements | |
[ 0.000, 0.000] | |
[ 12.960, 0.000] | |
[ 24.440, 0.000] | |
[ 36.300, 0.000] | |
[ 47.420, 0.000] | |
[ 51.860, 0.000] | |
[ 62.600, 0.000] | |
[ 69.260, 0.000] | |
[ 74.820, 0.000] | |
[ 89.260, 0.000] | |
[ 100.380, 0.000] | |
[ 104.820, 0.000] | |
[ 111.120, 0.000] | |
[ 122.240, 0.000] | |
[ 128.900, 0.000] | |
// This is the destination rect. | |
(8.75, 89.6875)-(20.3125, 101.25) | |
(21.71, 89.8047)-(33.2725, 101.367) | |
(33.19, 91.6211)-(44.7525, 103.184) | |
(45.05, 89.8047)-(56.6125, 101.367) | |
(56.17, 89.6875)-(67.7325, 101.25) | |
(60.61, 89.8047)-(72.1725, 101.367) | |
(71.35, 89.6875)-(82.9125, 101.25) | |
(78.0099, 89.6875)-(89.5724, 101.25) | |
(83.5699, 89.8535)-(95.1324, 101.416) | |
(98.0099, 89.8047)-(109.572, 101.367) | |
(109.13, 89.6875)-(120.692, 101.25) | |
(113.57, 89.6875)-(125.132, 101.25) | |
(119.87, 89.8047)-(131.432, 101.367) | |
(130.99, 89.6875)-(142.552, 101.25) | |
(137.65, 89.8047)-(149.212, 101.367) |
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
// just a note, BoldFont and Sdf are what is producing the Large labels, and RomanFont and Sdf are | |
// being used to create the texture that seems to be having the opacity problem described in the email. | |
mBoldFont.reset( new gl::SdfText::Font( loadAssetOrResource( "fonts/HelveticaNeueLTPro-75Bold.ttf" ), 28 ) ); | |
auto format = gl::SdfText::Format().textureWidth( 1024 ).textureHeight( 1024 ); | |
mBoldSdf = gl::SdfText::create( *mBoldFont, format, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " ); | |
mRomanFont.reset( new gl::SdfText::Font( loadAssetOrResource( "fonts/HelveticaNeueLTPro55Roman.ttf" ), 20 ) ); | |
mRomanSdf = gl::SdfText::create( *mRomanFont, format, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment