chaoticbob / Cinder-SdfText

libcinder.org
SIL Open Font License 1.1
40 stars 20 forks source link

Added centered and right alignment. #9

Closed paulhoux closed 8 years ago

paulhoux commented 8 years ago

Algorithm calculates offset per line during drawing and then shifts all characters on that line. This is faster than measuring the text twice. For "perfect" alignment, we now also take the exact glyph bounds into account (see: https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html). The bounds are saved to the SDFT file. Note that your old SDFT files will no longer work.

paulhoux commented 8 years ago
const vec2 kOffset = vec2( 0 );
const gl::SdfText::DrawOptions kOptions = gl::SdfText::DrawOptions().alignment( gl::SdfText::CENTER );
mSdfText->drawStringWrapped( mText, mBounds, kOffset, kOptions );
paulhoux commented 8 years ago

Right without and with adjustment: right-without-adjust right-with-adjust

Center without and with adjustment. center-without-adjust center-with-adjust

chaoticbob commented 8 years ago

This is awesome! Thanks so much @paulhoux!

chaoticbob commented 8 years ago

On the right with adjustment - the period renders outside the bounds, is that intentional?