DrawString using StringWidth Causes Drawing Issues

Heads up! If you rely on StringWidth for DrawString you will have issues in 2016 R3 and R4.1. Not sure when the bug was introduced but sometime between 2015 R4.1 and 2016 R3.

<https://xojo.com/issue/46037>

From the report:
In 2016 r4, either g.StringWidth isn’t returning the width correctly or g.DrawString isn’t painting it correctly, because anything painted at the width provided by g.StringWidth is truncated. Adding an extra pixel of width is enough to work around the problem, but it will be tedious to add that workaround to all of the places where we paint strings ourselves.

One thing to remember is the DRAWSTRING uses all INTEGER parameters, where STRINGWIDTH returns a DOUBLE since characters are not set on pixel/point boundary. And to make matters worse, if I recall… .OSX uses the ACTUAL character wdiths therefore is fairly accurate, while Windows returns the Integer component (thus making matters worse due to accumulated error) [or at least that is how it used to be], thereby returning a Stringwidth LESS than reality.

And with OSX… you end up using the Floor by default. so it could be off by the one pixel you mentioned

Oh, and I’ve seen THIS behaviour for well before 2015

+1