aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/support/font.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic/support/font.cpp')
-rw-r--r--engines/titanic/support/font.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp
index 625d03720b..f81251b10b 100644
--- a/engines/titanic/support/font.cpp
+++ b/engines/titanic/support/font.cpp
@@ -90,7 +90,7 @@ int STFont::getTextBounds(const CString &str, int maxWidth, Point *sizeOut) cons
strP += 4;
} else {
if (*strP == ' ') {
- // Check fo rline wrapping
+ // Check for line wrapping
checkLineWrap(textSize, maxWidth, strP);
}
@@ -152,7 +152,7 @@ int STFont::writeString(CVideoSurface *surface, const Rect &rect1, const Rect &d
setColor(r, g, b);
} else {
if (*srcP == ' ') {
- // Check fo rline wrapping
+ // Check for line wrapping
checkLineWrap(textSize, rect1.width(), srcP);
if (!*srcP)
return endP - str.c_str();
@@ -245,11 +245,8 @@ WriteCharacterResult STFont::writeChar(CVideoSurface *surface, unsigned char c,
if (c == 233)
c = '$';
- Rect tempRect;
- tempRect.left = _chars[c]._offset;
- tempRect.right = _chars[c]._offset + _chars[c]._width;
- tempRect.top = 0;
- tempRect.bottom = _fontHeight;
+ Rect charRect(_chars[c]._offset, 0,
+ _chars[c]._offset + _chars[c]._width, _fontHeight);
Point destPos(pt.x + destRect.left, pt.y + destRect.top);
if (srcRect->isEmpty())
@@ -257,34 +254,34 @@ WriteCharacterResult STFont::writeChar(CVideoSurface *surface, unsigned char c,
if (destPos.y > srcRect->bottom)
return WC_OUTSIDE_BOTTOM;
- if ((destPos.y + tempRect.height()) > srcRect->bottom) {
- tempRect.bottom += tempRect.top - destPos.y;
+ if ((destPos.y + charRect.height()) > srcRect->bottom) {
+ charRect.bottom += srcRect->bottom - (destPos.y + charRect.height());
}
if (destPos.y < srcRect->top) {
- if ((tempRect.height() + destPos.y) < srcRect->top)
+ if ((charRect.height() + destPos.y) < srcRect->top)
return WC_OUTSIDE_TOP;
- tempRect.top += srcRect->top - destPos.y;
+ charRect.top += srcRect->top - destPos.y;
destPos.y = srcRect->top;
}
if (destPos.x < srcRect->left) {
- if ((tempRect.width() + destPos.x) < srcRect->left)
+ if ((charRect.width() + destPos.x) < srcRect->left)
return WC_OUTSIDE_LEFT;
- tempRect.left += srcRect->left - destPos.x;
+ charRect.left += srcRect->left - destPos.x;
destPos.x = srcRect->left;
} else {
- if ((tempRect.width() + destPos.x) > srcRect->right) {
+ if ((charRect.width() + destPos.x) > srcRect->right) {
if (destPos.x > srcRect->right)
return WC_OUTSIDE_RIGHT;
- tempRect.right += srcRect->left - destPos.x;
+ charRect.right += srcRect->left - destPos.x;
}
}
- copyRect(surface, destPos, tempRect);
+ copyRect(surface, destPos, charRect);
return WC_IN_BOUNDS;
}
@@ -318,10 +315,10 @@ void STFont::extendBounds(Point &textSize, byte c, int maxWidth) const {
void STFont::checkLineWrap(Point &textSize, int maxWidth, const char *&str) const {
bool flag = false;
int totalWidth = 0;
- for (const char *srcPtr = str; *srcPtr && *srcPtr != ' '; ++srcPtr) {
- if (*srcPtr == ' ' && flag)
- break;
+ // Loop forward getting the width of the word (including preceding space)
+ // until a space is encountered following at least one character
+ for (const char *srcPtr = str; *srcPtr && (*srcPtr != ' ' || !flag); ++srcPtr) {
if (*srcPtr == TEXTCMD_NPC) {
srcPtr += 3;
} else if (*srcPtr == TEXTCMD_SET_COLOR) {