drawText() returning different width since 2.6.0

Hey,

I noticed some text being slightly misaligned after updating my device past 2.5.0 and after some investigation, it seems to be that the width as returned by graphics.drawText is calculated differently between SDK 2.5.0 and 2.6.0.

EDIT: I just realised that this also occurs when a string ends in a space, i.e. "Hi" and "Hi " now return the same length, whereas in 2.5.0 the latter was longer. That feels a bit unexpected and not very desirable imho.

The other problem only happens when using a font with "negative kerning" on the glyphs, like so:

SDK 2.6.0 returns a width of 2px more than in 2.5.0, so I wonder if it's ignoring the negative advance width from the last character, or calculating the "real" width of the drawn text somehow?

Is this new behaviour correct? Or was this not an intentional change?

2 Likes

One related thing that I just noticed, is that drawText() only returns the width of the text within view? e.g. if a string exceeds the width of the screen the width is reported as 400 max.

The documentation reads:

Returns two numbers indicating the width and height of the drawn text.

Which looks a bit ambiguous to me, as I sort of expected this to work the same as getTextWidth().