juce::Font::getStringWidthFloat() has one extra kerning

JUCE’s centering algorithm does not use that function, though, so the centering issue demonstrated here is still present.

But @migizo pointed in the right direction (thanks!). The following modification to juce_GlyphArrangment.cpp (line 482) could be a fix for the issue:

if (justification.testFlags (Justification::horizontallyCentred))  
{
    auto font = glyphs.getLast().font;
    auto kerningOfLastGlyph = font.getExtraKerningFactor() * font.getHeight() * font.getHorizontalScale();
    moveRangeOfGlyphs (startIndex, num, deltaX + kerningOfLastGlyph * 0.5f, deltaY);
}
else
{
    moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
}
3 Likes