[Scummvm-git-logs] scummvm master -> 5dfe57d2305bcafd7dfbf21bc69d96e26bccda7c
athrxx
athrxx at scummvm.org
Mon Aug 16 15:46:13 UTC 2021
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
4f98ab5789 SCUMM: COMI: Fix getStringWidth behavior
5dfe57d230 SCUMM: COMI: Attempt at a proper fix to getStringWidth
Commit: 4f98ab5789bc0c10ba1fe5265fcbd181946dc162
https://github.com/scummvm/scummvm/commit/4f98ab5789bc0c10ba1fe5265fcbd181946dc162
Author: Andrea Boscarino (andywinxp at gmail.com)
Date: 2021-08-16T17:46:09+02:00
Commit Message:
SCUMM: COMI: Fix getStringWidth behavior
Changed paths:
engines/scumm/script_v8.cpp
diff --git a/engines/scumm/script_v8.cpp b/engines/scumm/script_v8.cpp
index a9ac86193f..2e317258ff 100644
--- a/engines/scumm/script_v8.cpp
+++ b/engines/scumm/script_v8.cpp
@@ -1337,13 +1337,13 @@ void ScummEngine_v8::o8_getStringWidth() {
// Skip to the next instruction
_scriptPointer += resStrLen(_scriptPointer) + 1;
- translateText(msg, transBuf);
+ convertMessageToString(msg, transBuf, 256);
msg = transBuf;
// Temporary set the specified charset id
_charset->setCurID(charset);
// Determine the strings width
- width = _charset->getStringWidth(0, msg);
+ width = _charset->getStringWidth(0, msg) - 1;
// Revert to old font
_charset->setCurID(oldID);
Commit: 5dfe57d2305bcafd7dfbf21bc69d96e26bccda7c
https://github.com/scummvm/scummvm/commit/5dfe57d2305bcafd7dfbf21bc69d96e26bccda7c
Author: Andrea Boscarino (andywinxp at gmail.com)
Date: 2021-08-16T17:46:09+02:00
Commit Message:
SCUMM: COMI: Attempt at a proper fix to getStringWidth
Changed paths:
engines/scumm/charset.cpp
engines/scumm/script_v8.cpp
diff --git a/engines/scumm/charset.cpp b/engines/scumm/charset.cpp
index bd7a4f9671..f0c6cf87d9 100644
--- a/engines/scumm/charset.cpp
+++ b/engines/scumm/charset.cpp
@@ -456,6 +456,56 @@ int CharsetRendererClassic::getCharWidth(uint16 chr) {
}
int CharsetRenderer::getStringWidth(int arg, const byte *text) {
+ if (_vm->_game.id == GID_CMI) {
+ int numBytesMax = 100000; // Also hardcoded in the exe
+ int maxWidth = 0;
+ int width = 0;
+
+ while (*text && numBytesMax) {
+ // Some localizations may override colors
+ // See credits in Chinese COMI
+ if (_vm->_language == Common::ZH_TWN &&
+ text[0] == '^') {
+ if (text[1] == 'c') {
+ text += 4;
+ }
+ }
+
+ while (text[0] == '^') {
+ switch (text[1]) {
+ case 'f':
+ // We should change the font on the fly at this point
+ // which would result in a different width result.
+ // This has never been observed in the game though, and
+ // as such, we don't handle it.
+ text += 4;
+ break;
+ case 'c':
+ text += 5;
+ break;
+ default:
+ error("CharsetRenderer::getStringWidth(): Invalid escape code in text string");
+ }
+ }
+
+ if (is2ByteCharacter(_vm->_language, *text)) {
+ width += _vm->_2byteWidth + (_vm->_language != Common::JA_JPN ? 1 : 0);
+ ++text;
+ --numBytesMax;
+ } else if (*text == '\n') {
+ maxWidth = MAX<int>(width, maxWidth);
+ width = 0;
+ } else if (*text != '\r' && *text != _vm->_newLineCharacter) {
+ width += getCharWidth(*text);
+ }
+
+ ++text;
+ --numBytesMax;
+ }
+
+ return MAX<int>(width, maxWidth);
+ }
+
int pos = 0;
int width = 1;
int chr;
@@ -508,16 +558,6 @@ int CharsetRenderer::getStringWidth(int arg, const byte *text) {
continue;
}
}
-
- // Some localizations may override colors
- // See credits in Chinese COMI
- if (_vm->_game.id == GID_CMI && _vm->_language == Common::ZH_TWN &&
- chr == '^' && pos == 1) {
- if (text[pos] == 'c') {
- pos += 4;
- chr = text[pos++];
- }
- }
}
if (_vm->_useCJKMode) {
diff --git a/engines/scumm/script_v8.cpp b/engines/scumm/script_v8.cpp
index 2e317258ff..b91c4a7f87 100644
--- a/engines/scumm/script_v8.cpp
+++ b/engines/scumm/script_v8.cpp
@@ -1337,13 +1337,13 @@ void ScummEngine_v8::o8_getStringWidth() {
// Skip to the next instruction
_scriptPointer += resStrLen(_scriptPointer) + 1;
- convertMessageToString(msg, transBuf, 256);
+ convertMessageToString(msg, transBuf, 512);
msg = transBuf;
// Temporary set the specified charset id
_charset->setCurID(charset);
// Determine the strings width
- width = _charset->getStringWidth(0, msg) - 1;
+ width = _charset->getStringWidth(0, msg);
// Revert to old font
_charset->setCurID(oldID);
More information about the Scummvm-git-logs
mailing list