Permalink
Browse files

COMMON: Fix kerning issue in wordWrapText.

  • Loading branch information...
LubomirR authored and sev- committed Jul 29, 2018
1 parent d796670 commit d9b3853decc2d3ac3b500ef3b76f950bd6a6ef4a
Showing with 11 additions and 1 deletion.
  1. +11 −1 graphics/font.cpp
View
@@ -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);
}

0 comments on commit d9b3853

Please sign in to comment.