aboutsummaryrefslogtreecommitdiff
path: root/engines/lab/dispman.cpp
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2015-12-24 15:23:20 +0100
committerWillem Jan Palenstijn2015-12-24 15:27:48 +0100
commita08dd694e56ee53f99faeb18e1ca7b442b8875ce (patch)
treebbbbbcc0c7d949fc03f1072a7a1b64b95664df17 /engines/lab/dispman.cpp
parent6ad66320709973afd870cad10b0ef7f4155afa3a (diff)
downloadscummvm-rg350-a08dd694e56ee53f99faeb18e1ca7b442b8875ce.tar.gz
scummvm-rg350-a08dd694e56ee53f99faeb18e1ca7b442b8875ce.tar.bz2
scummvm-rg350-a08dd694e56ee53f99faeb18e1ca7b442b8875ce.zip
LAB: Improve whitespace handling in flowText
flowText was handling presence/absence of whitespace after lines inconsistently. This caused end-of-string to be missed, which broke last-page detection in the journal. It also introduced extra spaces at the beginning of pages.
Diffstat (limited to 'engines/lab/dispman.cpp')
-rw-r--r--engines/lab/dispman.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/engines/lab/dispman.cpp b/engines/lab/dispman.cpp
index 376c8ad6d9..d8504eb613 100644
--- a/engines/lab/dispman.cpp
+++ b/engines/lab/dispman.cpp
@@ -120,26 +120,29 @@ Common::String DisplayMan::getWord(const char *mainBuffer) {
Common::String DisplayMan::getLine(TextFont *tf, const char **mainBuffer, uint16 lineWidth) {
uint16 curWidth = 0;
Common::String result;
- bool doit = true;
- lineWidth += textLength(tf, " ");
-
- while ((*mainBuffer)[0] && doit) {
- Common::String wordBuffer = getWord(*mainBuffer) + " ";
+ while ((*mainBuffer)[0]) {
+ Common::String wordBuffer = getWord(*mainBuffer);
if ((curWidth + textLength(tf, wordBuffer)) <= lineWidth) {
result += wordBuffer;
- (*mainBuffer) += wordBuffer.size() - 1;
+ (*mainBuffer) += wordBuffer.size();
- if ((*mainBuffer)[0] == '\n')
- doit = false;
+ // end of line
+ if ((*mainBuffer)[0] == '\n') {
+ (*mainBuffer)++;
+ break;
+ }
- if ((*mainBuffer)[0])
+ // append any space after the word
+ if ((*mainBuffer)[0]) {
+ result += (*mainBuffer)[0];
(*mainBuffer)++;
+ }
curWidth = textLength(tf, result);
} else
- doit = false;
+ break;
}
return result;
@@ -161,19 +164,20 @@ int DisplayMan::flowText(TextFont *font, int16 spacing, byte penColor, byte back
if (!str)
return 0;
+ const char *orig = str;
+
TextFont *msgFont = font;
uint16 fontHeight = textHeight(msgFont) + spacing;
uint16 numLines = (textRect.height() + 1) / fontHeight;
uint16 width = textRect.width() + 1;
uint16 y = textRect.top;
- Common::String lineBuffer;
if (centerv && output) {
const char *temp = str;
uint16 actlines = 0;
while (temp[0]) {
- lineBuffer = getLine(msgFont, &temp, width);
+ getLine(msgFont, &temp, width);
actlines++;
}
@@ -183,6 +187,7 @@ int DisplayMan::flowText(TextFont *font, int16 spacing, byte penColor, byte back
int len = 0;
while (numLines && str[0]) {
+ Common::String lineBuffer;
lineBuffer = getLine(msgFont, &str, width);
uint16 x = textRect.left;
@@ -198,11 +203,9 @@ int DisplayMan::flowText(TextFont *font, int16 spacing, byte penColor, byte back
y += fontHeight;
}
- len--;
-
_currentDisplayBuffer = saveDisplayBuffer;
- return len;
+ return (str - orig);
}
void DisplayMan::createBox(uint16 y2) {