diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/font.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
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); } |