aboutsummaryrefslogtreecommitdiff
path: root/graphics/font.cpp
diff options
context:
space:
mode:
authorĽubomír Remák2018-07-29 11:56:21 +0200
committerEugene Sandulenko2018-08-02 18:54:13 +0200
commitd9b3853decc2d3ac3b500ef3b76f950bd6a6ef4a (patch)
tree7d6775df873f1f70ff6e6988182ea5f8e6ee4492 /graphics/font.cpp
parentd79667015a3986038999e7a9528f5e4f24348a33 (diff)
downloadscummvm-rg350-d9b3853decc2d3ac3b500ef3b76f950bd6a6ef4a.tar.gz
scummvm-rg350-d9b3853decc2d3ac3b500ef3b76f950bd6a6ef4a.tar.bz2
scummvm-rg350-d9b3853decc2d3ac3b500ef3b76f950bd6a6ef4a.zip
COMMON: Fix kerning issue in wordWrapText.
Diffstat (limited to 'graphics/font.cpp')
-rw-r--r--graphics/font.cpp12
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);
}