// just to create a Letters object for the sole purpose of\r
// getting a text size. It's less efficient but at least it\r
// would be accurate. \r
+ \r
+ // And here I am mucking around in here again...\r
+ //\r
+ // A font character has a few values that are pertinent to the\r
+ // line width:\r
+ // xOffset\r
+ // xAdvance\r
+ // kerningAmount(nextChar)\r
+ //\r
+ // The way BitmapText ultimately works is that the first character\r
+ // starts with xOffset included (ie: it is rendered at -xOffset).\r
+ // Its xAdvance is wider to accomodate that initial offset.\r
+ // The cursor position is advanced by xAdvance each time.\r
+ //\r
+ // So, a width should be calculated in a similar way. Start with\r
+ // -xOffset + xAdvance for the first character and then each subsequent\r
+ // character is just xAdvance more 'width'.\r
+ // \r
+ // The kerning amount from one character to the next affects the\r
+ // cursor position of that next character and thus the ultimate width \r
+ // and so must be factored in also.\r
+ \r
float lineWidth = 0f;\r
float maxLineWidth = 0f;\r
char lastChar = 0;\r
}\r
}\r
if (!firstCharOfLine){\r
- lineWidth += c.getXOffset() * sizeScale;\r
- lineWidth += findKerningAmount(lastChar, theChar) * sizeScale;\r
+ lineWidth += findKerningAmount(lastChar, theChar) * sizeScale; \r
} else {\r
+ // The first character needs to add in its xOffset but it\r
+ // is the only one... and negative offsets = postive width\r
+ // because we're trying to account for the part that hangs\r
+ // over the left. So we subtract. \r
+ lineWidth -= c.getXOffset() * sizeScale; \r
firstCharOfLine = false;\r
}\r
float xAdvance = c.getXAdvance() * sizeScale;\r
\r
// If this is the last character, then we really should have\r
- // only add its width\r
+ // only add its width. The advance may include extra spacing\r
+ // that we don't care about.\r
if (i == text.length() - 1) {\r
lineWidth += c.getWidth() * sizeScale;\r
+ \r
+ // Since theh width includes the xOffset then we need\r
+ // to take it out again by adding it, ie: offset the width\r
+ // we just added by the appropriate amount.\r
+ lineWidth += c.getXOffset() * sizeScale; \r
} else { \r
lineWidth += xAdvance;\r
}\r