I have some word-wrapping code that is working under the simulator for all devices except the Forerunner 920xt.
I traced the issue back to a core problem that affects the Forerunner only:
The sum of the width of each character in a string is not equal to the width of the whole string.
Here's a bit of test code and the results across devices:
var testString = "When in the course of h";
System.println("width of whole string=" + dc.getTextWidthInPixels(testString, Gfx.FONT_MEDIUM));
var sumOfCharWidths = 0;
var curChar, curCharWidth;
for (var i=0; i < testString.length(); i++) {
curChar = testString.substring(i, i + 1);
curCharWidth = dc.getTextWidthInPixels(curChar, Gfx.FONT_MEDIUM);
sumOfCharWidths += curCharWidth;
}
System.println("width of sum of chars=" + sumOfCharWidths);
FONT_MEDIUM
- fr920xt
width of whole string=199
width of sum of chars=177
- epix
width of whole string=205
width of sum of chars=205
- vivoactive
width of whole string=205
width of sum of chars=205
- fenix3
width of whole string=221
width of sum of chars=221
I'm curious if this is just a simulator bug or whether this affects the device as well.
Thanks!