Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit b5c01b54b98b2c2ecb9df21db0e8a2791fc75bd1 1 parent acc42ee
Dan V. authored
4 include/cinder/gl/TextureFont.h
@@ -119,10 +119,8 @@ class TextureFont {
119 119
120 120 //! Returns the size in pixels necessary to render the string \a str with DrawOptions \a options.
121 121 Vec2f measureString( const std::string &str, const DrawOptions &options = DrawOptions() ) const;
122   -#if defined( CINDER_COCOA )
123   - //! 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.
  122 + //! 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.
124 123 Vec2f measureStringWrapped( const std::string &str, const Rectf &fitRect, const DrawOptions &options = DrawOptions() ) const;
125   -#endif
126 124
127 125 //! Returns a vector of glyph/placement pairs representing \a str, suitable for use with drawGlyphs. Useful for caching placement and optimizing batching.
128 126 std::vector<std::pair<uint16_t,Vec2f> > getGlyphPlacements( const std::string &str, const DrawOptions &options ) const;
33 src/cinder/gl/TextureFont.cpp
@@ -328,31 +328,30 @@ Vec2f TextureFont::measureString( const std::string &str, const DrawOptions &opt
328 328 {
329 329 TextBox tbox = TextBox().font( mFont ).text( str ).size( TextBox::GROW, TextBox::GROW ).ligate( options.getLigate() );
330 330
331   -#if defined( CINDER_COCOA ) || defined( CINDER_ANDROID )
332   - return tbox.measure();
333   -#else
334   - vector<pair<uint16_t,Vec2f> > glyphMeasures = tbox.measureGlyphs();
335   -
336   - if( ! glyphMeasures.empty() ) {
337   - Vec2f result = glyphMeasures.back().second;
338   - boost::unordered_map<Font::Glyph, GlyphInfo>::const_iterator glyphInfoIt = mGlyphMap.find( glyphMeasures.back().first );
339   - if( glyphInfoIt != mGlyphMap.end() )
340   - result += glyphInfoIt->second.mOriginOffset + glyphInfoIt->second.mTexCoords.getSize();
341   - return result;
342   - }
343   - else {
344   - return Vec2f::zero();
  331 + TextEngineRef engine = mFont->getTextEngine();
  332 + if ( engine && engine->getEngineType() == TextEngine::GDIPLUS ) {
  333 + vector<pair<uint16_t,Vec2f> > glyphMeasures = tbox.measureGlyphs();
  334 +
  335 + if( ! glyphMeasures.empty() ) {
  336 + Vec2f result = glyphMeasures.back().second;
  337 + boost::unordered_map<Font::Glyph, GlyphInfo>::const_iterator glyphInfoIt = mGlyphMap.find( glyphMeasures.back().first );
  338 + if( glyphInfoIt != mGlyphMap.end() )
  339 + result += glyphInfoIt->second.mOriginOffset + glyphInfoIt->second.mTexCoords.getSize();
  340 + return result;
  341 + }
  342 + else {
  343 + return Vec2f::zero();
  344 + }
345 345 }
346   -#endif
  346 +
  347 + return tbox.measure();
347 348 }
348 349
349   -#if defined( CINDER_COCOA )
350 350 Vec2f TextureFont::measureStringWrapped( const std::string &str, const Rectf &fitRect, const DrawOptions &options ) const
351 351 {
352 352 TextBox tbox = TextBox().font( mFont ).text( str ).size( fitRect.getWidth(), fitRect.getHeight() ).ligate( options.getLigate() );
353 353 return tbox.measure();
354 354 }
355   -#endif
356 355
357 356 vector<pair<uint16_t,Vec2f> > TextureFont::getGlyphPlacements( const std::string &str, const DrawOptions &options ) const
358 357 {

0 comments on commit b5c01b5

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