glyph-brush icon indicating copy to clipboard operation
glyph-brush copied to clipboard

Get width of last character

Open MarcAntoine-Arnaud opened this issue 2 years ago • 2 comments

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

MarcAntoine-Arnaud avatar Jul 27 '22 15:07 MarcAntoine-Arnaud

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 avatar Jul 27 '22 18:07 alexheretic

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

alexheretic avatar Sep 01 '22 08:09 alexheretic

Thank you very much, we have implemented and work perfectly

MarcAntoine-Arnaud avatar Sep 16 '22 11:09 MarcAntoine-Arnaud