alexheretic / glyph-brush

Fast GPU cached text rendering
Apache License 2.0
673 stars 52 forks source link

Get width of last character #154

Closed MarcAntoine-Arnaud closed 1 year ago

MarcAntoine-Arnaud commented 1 year ago

Hello (again ;-) ),

We are face to an issue to draw our underline text.

Based on GlyphCruncher it's possible to retrieve character position.

But in case of:

       some
    awesome
text longer here

drawn in one section, we cannot retrieve coordinates of awesome word as Glyph::position returns le left point of the character. And GlyphCruncher::glyph_bounds cannot be used as last line is longer ...

As all letters does not have the same width, do you have a way to find the width of one character ?

Thank you for your advices. Marc-Antoine

alexheretic commented 1 year ago

The right of a glyph is its position + the ScaleFont::h_advance for that glyph. So your horizontal positions to underline "awesome" would start at something like a.position.x until e.position.x + font.h_advance(e.id)

If the final glyph has another glyph after it (so not the word case) you may also want to apply kerning.

alexheretic commented 1 year ago

Actually I didn't mention Font::glyph_bounds which seems a better answer to your question.

MarcAntoine-Arnaud commented 1 year ago

Thank you very much, we have implemented and work perfectly