SHERLOCK: Handle scalpel big5 wrapping

This commit is contained in:
Vladimir Serbinenko 2023-02-04 15:37:17 +01:00 committed by Eugene Sandulenko
parent d2b37c9dde
commit d5480c37c3

View File

@ -232,11 +232,14 @@ void ScalpelTalk::talkInterface(const byte *&str) {
} }
// Find amount of text that will fit on the line // Find amount of text that will fit on the line
int width = 0, idx = 0; int width = 0, idx = 0, last_space = 0, last_valid = 0;
do { do {
width += screen.charWidth(str[idx]); int old_idx = idx;
++idx; if (str[idx] == ' ')
++_charCount; last_space = idx;
last_valid = idx;
width += screen.charWidth((const char *) str, idx);
_charCount += idx - old_idx;
} while (width < 298 && str[idx] && str[idx] != '{' && (!isOpcode(str[idx]))); } while (width < 298 && str[idx] && str[idx] != '{' && (!isOpcode(str[idx])));
if (str[idx] || width >= 298) { if (str[idx] || width >= 298) {
@ -250,9 +253,12 @@ void ScalpelTalk::talkInterface(const byte *&str) {
// If word wrap is needed, find the start of the current word // If word wrap is needed, find the start of the current word
if (width >= 298) { if (width >= 298) {
while (str[idx] != ' ') { if (last_space > 0) {
--idx; _charCount -= idx - last_space;
--_charCount; idx = last_space;
} else {
_charCount -= idx - last_valid;
idx = last_valid;
} }
} }
@ -279,8 +285,8 @@ void ScalpelTalk::talkInterface(const byte *&str) {
// Move to end of displayed line // Move to end of displayed line
str += idx; str += idx;
// If line wrap occurred, then move to after the separating space between the words // If line wrap with space occurred, then move to after the separating space between the words
if (str[0] && (!isOpcode(str[0])) && str[0] != '{') if (str[0] == ' ')
++str; ++str;
_yp += 9; _yp += 9;
@ -823,19 +829,27 @@ int ScalpelTalk::talkLine(int lineNum, int stateNum, byte color, int lineY, bool
for (;;) { for (;;) {
// Get as much of the statement as possible will fit on the // Get as much of the statement as possible will fit on the
Common::String sLine; Common::String sLine;
const char *lineEndP = lineStartP;
int width = 0; int width = 0;
int lastSpace = 0;
int lastValid = 0;
int linePtr = 0;
int nextLine = -1;
do { do {
width += screen.charWidth(*lineEndP); lastValid = linePtr;
} while (*++lineEndP && width < maxWidth); if (lineStartP[linePtr] == ' ')
lastSpace = linePtr;
width += screen.charWidth(lineStartP, linePtr);
} while (lineStartP[linePtr] && width < maxWidth);
// Check if we need to wrap the line // Check if we need to wrap the line
if (width >= maxWidth) { if (width >= maxWidth) {
// Work backwards to the prior word's end if (lastSpace > 0) {
while (*--lineEndP != ' ') sLine = Common::String(lineStartP, lastSpace);
; nextLine = lastSpace + 1;
} else {
sLine = Common::String(lineStartP, lineEndP++); sLine = Common::String(lineStartP, lastValid);
nextLine = lastValid;
}
} else { } else {
// Can display remainder of the statement on the current line // Can display remainder of the statement on the current line
sLine = Common::String(lineStartP); sLine = Common::String(lineStartP);
@ -872,10 +886,9 @@ int ScalpelTalk::talkLine(int lineNum, int stateNum, byte color, int lineY, bool
// Move to next line, if any // Move to next line, if any
lineY += 9; lineY += 9;
lineStartP = lineEndP; if (nextLine < 0)
if (!*lineEndP)
break; break;
lineStartP += nextLine;
} else { } else {
// We're close to the bottom of the screen, so stop display // We're close to the bottom of the screen, so stop display
lineY = -1; lineY = -1;