Skip to content

Commit

Permalink
COMMON: Fix kerning issue in wordWrapText.
Browse files Browse the repository at this point in the history
  • Loading branch information
LubomirR authored and sev- committed Aug 2, 2018
1 parent d796670 commit d9b3853
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion graphics/font.cpp
Expand Up @@ -174,7 +174,8 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
c = '\n'; 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; last = c;
const bool wouldExceedWidth = (lineWidth + tmpWidth + w > maxWidth); const bool wouldExceedWidth = (lineWidth + tmpWidth + w > maxWidth);


Expand Down Expand Up @@ -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. // assure we do not mess something up because of kerning.
tmpWidth = font.getStringWidth(tmpStr); 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 { } else {
wrapper.add(tmpStr, tmpWidth); wrapper.add(tmpStr, tmpWidth);
} }
Expand Down

0 comments on commit d9b3853

Please sign in to comment.