From d9b3853decc2d3ac3b500ef3b76f950bd6a6ef4a Mon Sep 17 00:00:00 2001 From: Ľubomír Remák Date: Sun, 29 Jul 2018 11:56:21 +0200 Subject: COMMON: Fix kerning issue in wordWrapText. --- graphics/font.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'graphics') diff --git a/graphics/font.cpp b/graphics/font.cpp index 3446619299..b84d6907c6 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -174,7 +174,8 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm c = '\n'; } - const int w = font.getCharWidth(c) + font.getKerningOffset(last, c); + const int currentCharWidth = font.getCharWidth(c); + const int w = currentCharWidth + font.getKerningOffset(last, c); last = c; const bool wouldExceedWidth = (lineWidth + tmpWidth + w > maxWidth); @@ -212,6 +213,15 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm // assure we do not mess something up because of kerning. tmpWidth = font.getStringWidth(tmpStr); } + + if (tmpStr.empty()) { + // If tmpStr is empty, we might have removed the space before 'c'. + // That means we have to recompute the kerning. + + tmpWidth += currentCharWidth + font.getKerningOffset(0, c); + tmpStr += c; + continue; + } } else { wrapper.add(tmpStr, tmpWidth); } -- cgit v1.2.3