Skip to content
Browse files

Runtime check for GDI text handling in TextureFont measureString().

  • Loading branch information...
1 parent acc42ee commit b5c01b54b98b2c2ecb9df21db0e8a2791fc75bd1 @safetydank committed May 7, 2012
Showing with 17 additions and 20 deletions.
  1. +1 −3 include/cinder/gl/TextureFont.h
  2. +16 −17 src/cinder/gl/TextureFont.cpp
View
4 include/cinder/gl/TextureFont.h
@@ -119,10 +119,8 @@ class TextureFont {
//! Returns the size in pixels necessary to render the string \a str with DrawOptions \a options.
Vec2f measureString( const std::string &str, const DrawOptions &options = DrawOptions() ) const;
-#if defined( CINDER_COCOA )
- //! Returns the size in pixels necessary to render the word-wrapped string \a str fit inside \a fitRect with DrawOptions \a options. Mac & iOS only.
+ //! Returns the size in pixels necessary to render the word-wrapped string \a str fit inside \a fitRect with DrawOptions \a options. Mac, iOS and Android only.
Vec2f measureStringWrapped( const std::string &str, const Rectf &fitRect, const DrawOptions &options = DrawOptions() ) const;
-#endif
//! Returns a vector of glyph/placement pairs representing \a str, suitable for use with drawGlyphs. Useful for caching placement and optimizing batching.
std::vector<std::pair<uint16_t,Vec2f> > getGlyphPlacements( const std::string &str, const DrawOptions &options ) const;
View
33 src/cinder/gl/TextureFont.cpp
@@ -328,31 +328,30 @@ Vec2f TextureFont::measureString( const std::string &str, const DrawOptions &opt
{
TextBox tbox = TextBox().font( mFont ).text( str ).size( TextBox::GROW, TextBox::GROW ).ligate( options.getLigate() );
-#if defined( CINDER_COCOA ) || defined( CINDER_ANDROID )
- return tbox.measure();
-#else
- vector<pair<uint16_t,Vec2f> > glyphMeasures = tbox.measureGlyphs();
-
- if( ! glyphMeasures.empty() ) {
- Vec2f result = glyphMeasures.back().second;
- boost::unordered_map<Font::Glyph, GlyphInfo>::const_iterator glyphInfoIt = mGlyphMap.find( glyphMeasures.back().first );
- if( glyphInfoIt != mGlyphMap.end() )
- result += glyphInfoIt->second.mOriginOffset + glyphInfoIt->second.mTexCoords.getSize();
- return result;
- }
- else {
- return Vec2f::zero();
+ TextEngineRef engine = mFont->getTextEngine();
+ if ( engine && engine->getEngineType() == TextEngine::GDIPLUS ) {
+ vector<pair<uint16_t,Vec2f> > glyphMeasures = tbox.measureGlyphs();
+
+ if( ! glyphMeasures.empty() ) {
+ Vec2f result = glyphMeasures.back().second;
+ boost::unordered_map<Font::Glyph, GlyphInfo>::const_iterator glyphInfoIt = mGlyphMap.find( glyphMeasures.back().first );
+ if( glyphInfoIt != mGlyphMap.end() )
+ result += glyphInfoIt->second.mOriginOffset + glyphInfoIt->second.mTexCoords.getSize();
+ return result;
+ }
+ else {
+ return Vec2f::zero();
+ }
}
-#endif
+
+ return tbox.measure();
}
-#if defined( CINDER_COCOA )
Vec2f TextureFont::measureStringWrapped( const std::string &str, const Rectf &fitRect, const DrawOptions &options ) const
{
TextBox tbox = TextBox().font( mFont ).text( str ).size( fitRect.getWidth(), fitRect.getHeight() ).ligate( options.getLigate() );
return tbox.measure();
}
-#endif
vector<pair<uint16_t,Vec2f> > TextureFont::getGlyphPlacements( const std::string &str, const DrawOptions &options ) const
{

0 comments on commit b5c01b5

Please sign in to comment.
Something went wrong with that request. Please try again.