M5GFX icon indicating copy to clipboard operation
M5GFX copied to clipboard

Use actual glyph width, not the guessed spaceWidth, to determine the width of the space character in VLW fonts

Open kirberich opened this issue 2 months ago • 1 comments

I was hitting an issue where textWidth would give me results that were slightly off from the actual width of a string drawn to the display when using a VLW font today. After a bunch of digging, it seems that the problem is that drawChar uses a special case for the space character where it uses this->spaceWidth (which according to the comment in the code is just a guess), instead of the width of the space glyph, but textWidth doesn't use this special case.

I'm not sure why this special case was there, and I'm not sure if this would break for some other fonts, but for my case at least the rendering looks correct, and textWidth and drawChar now agree.

Note: the test was done with a custom font, Bookerly 24pt, created using the M5 font converter Also note: I pointed this at develop as that's what i'm using, let me know if that's wrong

kirberich avatar Oct 26 '25 14:10 kirberich

Hello, @kirberich First and foremost, it's important to note that the width of drawChar and the width of textWidth are not necessarily the same. drawChar renders a single character, but it can vary depending on negative offsets and various other conditions.

We need to investigate how this pull request affects other existing fonts, but this will take time, so it's difficult to merge it immediately.

lovyan03 avatar Oct 29 '25 12:10 lovyan03