TextLayout single character bug and fix


I finally looked into a problem I was having with TextLayout whenever there is only a single character in it. The issue was that the text would be displayed slightly to the right.

The issue turned out to be that TextLayout’s width gets recalculated as 0.0 in TextLayout::recalculateWidth because the for loop at line 104 in juce_TextLayout.cpp in TextLayout::Line::getLineBoundsX isn’t including the first character in the run’s range.

[code]float minX = run.glyphs.getReference(0).anchor.x;
float maxX = minX// + run.glyphs.getReference(0).width; *********** I’ve added this as a fix

for (int j = run.glyphs.size(); --j >/=/ 0;) //*********** This also fixes it
const Glyph& glyph = run.glyphs.getReference (j);
const float x = glyph.anchor.x;
minX = jmin (minX, x);
maxX = jmax (maxX, x + glyph.width);


Well spotted, thanks! I’ll get that sorted out…