[Scummvm-git-logs] scummvm master -> 711c7f766362db06378d2b538857b82b5a8568eb
athrxx
athrxx at scummvm.org
Mon Jul 12 23:35:04 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
711c7f7663 KYRA: upgrade save descriptions to UTF-8
Commit: 711c7f766362db06378d2b538857b82b5a8568eb
https://github.com/scummvm/scummvm/commit/711c7f766362db06378d2b538857b82b5a8568eb
Author: athrxx (athrxx at scummvm.org)
Date: 2021-07-13T01:34:40+02:00
Commit Message:
KYRA: upgrade save descriptions to UTF-8
Bump save version. New games will be UTF-8, the old ones will still be correctly decoded from kISO8859_1. Tested and adapted all targets (not the fan translations).
Changed paths:
engines/kyra/engine/util.cpp
engines/kyra/engine/util.h
engines/kyra/gui/gui.cpp
engines/kyra/gui/gui_eob.cpp
engines/kyra/gui/gui_eob_segacd.cpp
engines/kyra/gui/gui_lok.cpp
engines/kyra/gui/gui_lol.cpp
engines/kyra/gui/gui_v2.cpp
engines/kyra/gui/saveload.cpp
engines/kyra/kyra_v1.h
engines/kyra/metaengine.cpp
diff --git a/engines/kyra/engine/util.cpp b/engines/kyra/engine/util.cpp
index 425203c8e9..2eb6d9a900 100644
--- a/engines/kyra/engine/util.cpp
+++ b/engines/kyra/engine/util.cpp
@@ -82,45 +82,24 @@ void Util::decodeString2(const char *src, char *dst) {
*dst = 0;
}
-void Util::convertDOSToISO(char *str) {
- uint8 *s = (uint8 *)str;
-
- for (; *s; ++s) {
- if (*s >= 128) {
- uint8 c = _charMapDOSToISO[*s - 128];
-
- if (!c)
- c = 0x20;
-
- *s = c;
- }
- }
+void Util::convertDOSToUTF8(char *str, int bufferSize) {
+ Common::strlcpy(str, Common::U32String(str, Common::kDos850).encode(Common::kUtf8).c_str(), bufferSize);
}
-void Util::convertISOToDOS(char *str) {
- while (*str)
- convertISOToDOS(*str++);
+void Util::convertUTF8ToDOS(char *str, int bufferSize) {
+ Common::strlcpy(str, Common::U32String(str, Common::kUtf8).encode(Common::kDos850).c_str(), bufferSize);
}
-void Util::convertISOToDOS(char &c) {
- uint8 code = (uint8)c;
- if (code >= 128) {
- code = _charMapISOToDOS[code - 128];
- if (!code)
- code = 0x20;
- }
-
- c = code;
+Common::String Util::convertUTF8ToDOS(Common::String &str) {
+ return Common::U32String(str.c_str(), Common::kUtf8).encode(Common::kDos850);
}
-Common::String Util::convertISOToDOS(const Common::String &str) {
- char *tmp = new char[str.size() + 1];
+Common::String Util::convertISOToUTF8(Common::String &str) {
+ return Common::U32String(str.c_str(), Common::kISO8859_1).encode(Common::kUtf8);
+}
- memcpy(tmp, str.c_str(), str.size() + 1);
- convertISOToDOS(tmp);
- Common::String res = tmp;
- delete[] tmp;
- return res;
+void Util::convertISOToDOS(char &c) {
+ c = Common::U32String(Common::String::format("%c", c), Common::kISO8859_1).encode(Common::kDos850).c_str()[0];
}
Common::String Util::decodeString1(const Common::String &src) {
@@ -135,36 +114,4 @@ Common::String Util::decodeString2(const Common::String &src) {
return tmp;
}
-// CP850 to ISO-8859-1 (borrowed from engines/saga/font_map.cpp)
-const uint8 Util::_charMapDOSToISO[128] = {
- 199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232,
- 239, 238, 236, 196, 197, 201, 230, 198, 244, 246, 242,
- 251, 249, 255, 214, 220, 248, 163, 216, 215, 0, 225,
- 237, 243, 250, 241, 209, 170, 186, 191, 174, 172, 189,
- 188, 161, 171, 187, 0, 0, 0, 0, 0, 193, 194,
- 192, 169, 0, 0, 0, 0, 162, 165, 0, 0, 0,
- 0, 0, 0, 0, 227, 195, 0, 0, 0, 0, 0,
- 0, 0, 164, 240, 208, 202, 203, 200, 0, 205, 206,
- 207, 0, 0, 0, 0, 166, 204, 0, 211, 223, 212,
- 210, 245, 213, 181, 254, 222, 218, 219, 217, 253, 221,
- 175, 180, 173, 177, 0, 190, 182, 167, 247, 184, 176,
- 168, 183, 185, 179, 178, 0, 160
-};
-
-// ISO-8859-1 to CP850
-const uint8 Util::_charMapISOToDOS[128] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,
- 173, 189, 156, 207, 190, 221, 245, 249, 184, 166, 174,
- 170, 240, 169, 238, 248, 241, 253, 252, 239, 230, 244,
- 250, 247, 251, 167, 175, 172, 171, 243, 168, 183, 181,
- 182, 199, 142, 143, 146, 128, 212, 144, 210, 211, 222,
- 214, 215, 216, 209, 165, 227, 224, 226, 229, 153, 158,
- 157, 235, 233, 234, 154, 237, 232, 225, 133, 160, 131,
- 198, 132, 134, 145, 135, 138, 130, 136, 137, 141, 161,
- 140, 139, 208, 164, 149, 162, 147, 228, 148, 246, 155,
- 151, 163, 150, 129, 236, 231, 152
-};
-
} // End of namespace Kyra
diff --git a/engines/kyra/engine/util.h b/engines/kyra/engine/util.h
index e14f960d15..fd8e9f90a1 100644
--- a/engines/kyra/engine/util.h
+++ b/engines/kyra/engine/util.h
@@ -35,17 +35,11 @@ public:
static Common::String decodeString1(const Common::String &src);
static Common::String decodeString2(const Common::String &src);
-
- // Since our current GUI font uses ISO-8859-1, this
- // conversion functionallty uses that as a base.
- static void convertDOSToISO(char *str);
- static void convertISOToDOS(char *str);
+ static void convertDOSToUTF8(char *str, int bufferSize);
+ static void convertUTF8ToDOS(char *str, int bufferSize);
+ static Common::String convertUTF8ToDOS(Common::String &str);
+ static Common::String convertISOToUTF8(Common::String &str);
static void convertISOToDOS(char &c);
- static Common::String convertISOToDOS(const Common::String &str);
-
-private:
- static const uint8 _charMapDOSToISO[128];
- static const uint8 _charMapISOToDOS[128];
};
} // End of namespace Kyra
diff --git a/engines/kyra/gui/gui.cpp b/engines/kyra/gui/gui.cpp
index 6ca0819bea..3afa4128ba 100644
--- a/engines/kyra/gui/gui.cpp
+++ b/engines/kyra/gui/gui.cpp
@@ -116,12 +116,13 @@ void GUI::updateSaveSlotsList(Common::String targetName, bool force) {
in = _vm->openSaveForReading(_vm->getSavegameFilename(targetName, _saveSlots[i]).c_str(), header, targetName == _vm->_targetName);
char **listEntry = &_savegameList[allowEmptySlots ? _saveSlots[i] : i];
if (in) {
- *listEntry = new char[header.description.size() + 1];
- Common::strlcpy(*listEntry, header.description.c_str(), header.description.size() + 1);
+ uint buffSize = header.description.size() + 1;
+ *listEntry = new char[buffSize];
+ Common::strlcpy(*listEntry, header.description.c_str(), buffSize);
// Ingame auto-generated Japanese EOB SegaCD savegame descriptions have a special 1-byte encoding that
// does not survive this conversion. And the rest of the characters in these descriptions do not require it.
if (!(_vm->gameFlags().platform == Common::kPlatformSegaCD && _vm->gameFlags().lang == Common::JA_JPN && Common::String(*listEntry).contains('\r')))
- Util::convertISOToDOS(*listEntry);
+ Util::convertUTF8ToDOS(*listEntry, buffSize);
delete in;
} else {
*listEntry = 0;
diff --git a/engines/kyra/gui/gui_eob.cpp b/engines/kyra/gui/gui_eob.cpp
index 7c30d53132..4cc75d9011 100644
--- a/engines/kyra/gui/gui_eob.cpp
+++ b/engines/kyra/gui/gui_eob.cpp
@@ -3192,7 +3192,7 @@ bool GUI_EoB::runSaveMenu(int x, int y) {
// Ingame auto-generated Japanese EOB SegaCD savegame descriptions have a special 1-byte encoding that
// does not survive this conversion. And the rest of the characters in these descriptions do not require it.
if (!(_vm->gameFlags().platform == Common::kPlatformSegaCD && _vm->gameFlags().lang == Common::JA_JPN && Common::String(temp).contains('\r')))
- Util::convertDOSToISO(temp);
+ Util::convertDOSToUTF8(temp, 26);
Common::Error err = _vm->saveGameStateIntern(_savegameOffset + slot, temp, &thumb);
thumb.free();
@@ -4599,12 +4599,16 @@ void GUI_EoB::setupSaveMenuSlots() {
memset(_saveSlotStringsTemp[i], 0, 25);
Common::strlcpy(_saveSlotStringsTemp[i], _savegameList[i + _savegameOffset], 25);
- if (_vm->gameFlags().platform == Common::kPlatformPC98 || _vm->gameFlags().platform == Common::kPlatformFMTowns || (_vm->gameFlags().platform == Common::kPlatformSegaCD && _vm->gameFlags().lang != Common::JA_JPN)) {
- // Clean out special characters from GMM save dialog which might get misinterpreted as SJIS
- for (uint ii = 0; ii < strlen(_saveSlotStringsTemp[i]); ++ii) {
- if (_saveSlotStringsTemp[i][ii] < 32 && _saveSlotStringsTemp[i][ii] != '\r') // due to the signed char type this will also clean up everything >= 0x80
- _saveSlotStringsTemp[i][ii] = ' ';
- }
+ if (!(_vm->gameFlags().lang == Common::JA_JPN && _vm->gameFlags().platform == Common::kPlatformSegaCD &&
+ Common::String(_saveSlotStringsTemp[i]).contains('\r')) && (_vm->gameFlags().lang == Common::JA_JPN || _vm->gameFlags().platform == Common::kPlatformSegaCD)) {
+ // Strip special characters from GMM save dialog which might get misinterpreted as SJIS
+ // Special case for Japanese SegaCD: Only the save descriptions from GMM should be stripped. The auto-generated descriptions from the ingame save dialog
+ // have a special 1-byte encoding that must be kept. It is easy to distinguish between GMM descriptions and ingame descriptions due to the '\r' characters
+ // that the auto-generated strings always and the GMM strings never have.
+ for (uint ii = 0; ii < strlen(_saveSlotStringsTemp[i]); ++ii) {
+ if (_saveSlotStringsTemp[i][ii] < 32 && _saveSlotStringsTemp[i][ii] != '\r') // due to the signed char type this will also clean up everything >= 0x80
+ _saveSlotStringsTemp[i][ii] = ' ';
+ }
}
_saveSlotIdTemp[i] = i + _savegameOffset;
diff --git a/engines/kyra/gui/gui_eob_segacd.cpp b/engines/kyra/gui/gui_eob_segacd.cpp
index eaf6757d57..ad82d198fa 100644
--- a/engines/kyra/gui/gui_eob_segacd.cpp
+++ b/engines/kyra/gui/gui_eob_segacd.cpp
@@ -884,7 +884,7 @@ void GUI_EoB_SegaCD::drawSaveSlotButton(int slot, int redrawBox, bool highlight)
} else {
// Savegame generated via the GMM save dialog. The Japanese font only has upper case ASCII glyphs, so we have to uppercase the string.
s2.toUppercase();
- }
+ }
}
_vm->_txt->printShadedText(s2.c_str(), 0, (slot << 4) + (slot < 5 ? 0 : 2), highlight ? 0x55 : 0xFF, 0xCC, 121, 80, 0, false);
diff --git a/engines/kyra/gui/gui_lok.cpp b/engines/kyra/gui/gui_lok.cpp
index 89c0dbea34..8b81c02109 100644
--- a/engines/kyra/gui/gui_lok.cpp
+++ b/engines/kyra/gui/gui_lok.cpp
@@ -579,9 +579,9 @@ void GUI_LoK::setupSavegames(Menu &menu, int num) {
}
_screen->_charSpacing = 0;
- Util::convertISOToDOS(_savegameNames[i]);
+ Util::convertUTF8ToDOS(_savegameNames[i], 35);
if (_vm->gameFlags().lang == Common::JA_JPN) {
- // Clean out special characters from GMM save dialog which might get misinterpreted as SJIS
+ // Strip special characters from GMM save dialog which might get misinterpreted as SJIS
for (uint ii = 0; ii < strlen(_savegameNames[i]); ++ii) {
if (_savegameNames[i][ii] < 32) // due to the signed char type this will also clean up everything >= 0x80
_savegameNames[i][ii] = ' ';
@@ -778,7 +778,7 @@ int GUI_LoK::saveGame(Button *button) {
if (_savegameOffset == 0 && _vm->_gameToLoad == 0)
_vm->_gameToLoad = getNextSavegameSlot();
if (_vm->_gameToLoad > 0) {
- Util::convertDOSToISO(_savegameName);
+ Util::convertDOSToUTF8(_savegameName, 35);
Graphics::Surface thumb;
createScreenThumbnail(thumb);
diff --git a/engines/kyra/gui/gui_lol.cpp b/engines/kyra/gui/gui_lol.cpp
index efd6894531..9c008a66bd 100644
--- a/engines/kyra/gui/gui_lol.cpp
+++ b/engines/kyra/gui/gui_lol.cpp
@@ -2530,7 +2530,7 @@ void GUI_LoL::setupSaveMenuSlots(Menu &menu, int num) {
}
if (_vm->gameFlags().lang == Common::JA_JPN) {
- // Clean out special characters from GMM save dialog which might get misinterpreted as SJIS
+ // Strip special characters from GMM save dialog which might get misinterpreted as SJIS
for (uint ii = 0; ii < strlen(s); ++ii) {
if (s[ii] < 32) // due to the signed char type this will also clean up everything >= 0x80
s[ii] = ' ';
@@ -2844,7 +2844,7 @@ int GUI_LoL::clickedSavenameMenu(Button *button) {
updateMenuButton(button);
if (button->arg == _savenameMenu.item[0].itemId) {
- Util::convertDOSToISO(_saveDescription);
+ Util::convertDOSToUTF8(_saveDescription, 5120 - (int)((uint8*)_saveDescription - _vm->_tempBuffer5120));
int slot = _menuResult == -2 ? getNextSavegameSlot() : _menuResult - 1;
Graphics::Surface thumb;
diff --git a/engines/kyra/gui/gui_v2.cpp b/engines/kyra/gui/gui_v2.cpp
index 3db76cf7eb..32b6efb41b 100644
--- a/engines/kyra/gui/gui_v2.cpp
+++ b/engines/kyra/gui/gui_v2.cpp
@@ -445,10 +445,10 @@ void GUI_v2::setupSavegameNames(Menu &menu, int num) {
for (int i = startSlot; i < num && uint(_savegameOffset + i) < _saveSlots.size(); ++i) {
if ((in = _vm->openSaveForReading(_vm->getSavegameFilename(_saveSlots[i + _savegameOffset]), header)) != 0) {
Common::String s = header.description;
- s = Util::convertISOToDOS(s);
+ s = Util::convertUTF8ToDOS(s);
if (_vm->gameFlags().lang == Common::JA_JPN || _vm->gameFlags().lang == Common::ZH_CNA || _vm->gameFlags().lang == Common::ZH_TWN) {
- // Clean out special characters from GMM save dialog which might get misinterpreted as SJIS
+ // Strip special characters from GMM save dialog which might get misinterpreted as 2-byte characters
for (Common::String::iterator ii = s.begin(); ii != s.end(); ++ii) {
if (*ii < 32) // due to the signed char type this will also clean up everything >= 0x80
*ii = ' ';
@@ -629,7 +629,7 @@ int GUI_v2::saveMenu(Button *caller) {
Graphics::Surface thumb;
createScreenThumbnail(thumb);
- Util::convertDOSToISO(_saveDescription);
+ Util::convertDOSToUTF8(_saveDescription, 81);
_vm->saveGameStateIntern(_saveSlot, _saveDescription, &thumb);
thumb.free();
diff --git a/engines/kyra/gui/saveload.cpp b/engines/kyra/gui/saveload.cpp
index 743da8c6fc..270f686677 100644
--- a/engines/kyra/gui/saveload.cpp
+++ b/engines/kyra/gui/saveload.cpp
@@ -29,7 +29,7 @@
#include "graphics/thumbnail.h"
#include "graphics/surface.h"
-#define CURRENT_SAVE_VERSION 19
+#define CURRENT_SAVE_VERSION 20
#define GF_FLOPPY (1 << 0)
#define GF_TALKIE (1 << 1)
@@ -66,7 +66,7 @@ WARN_UNUSED_RESULT KyraEngine_v1::ReadSaveHeaderError KyraEngine_v1::readSaveHea
in->read(descriptionBuffer, descriptionSize[i]);
descriptionBuffer[descriptionSize[i]] = 0;
- Util::convertDOSToISO(descriptionBuffer);
+ Util::convertDOSToUTF8(descriptionBuffer, 81);
type = in->readUint32BE();
header.version = in->readUint16LE();
@@ -120,6 +120,9 @@ WARN_UNUSED_RESULT KyraEngine_v1::ReadSaveHeaderError KyraEngine_v1::readSaveHea
header.description += c;
}
+ if (header.version < 20)
+ header.description = Util::convertISOToUTF8(header.description);
+
if (header.version >= 2)
header.flags = in->readUint32BE();
diff --git a/engines/kyra/kyra_v1.h b/engines/kyra/kyra_v1.h
index 0c39e9283b..591126db14 100644
--- a/engines/kyra/kyra_v1.h
+++ b/engines/kyra/kyra_v1.h
@@ -379,7 +379,7 @@ protected:
void loadGameStateCheck(int slot);
Common::Error loadGameState(int slot) override = 0;
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override {
- return saveGameStateIntern(slot, Common::U32String(desc).encode(Common::kISO8859_1).c_str(), 0);
+ return saveGameStateIntern(slot, desc.c_str(), 0);
}
virtual Common::Error saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumbnail) = 0;
diff --git a/engines/kyra/metaengine.cpp b/engines/kyra/metaengine.cpp
index 0f443abdff..f2c1686ac8 100644
--- a/engines/kyra/metaengine.cpp
+++ b/engines/kyra/metaengine.cpp
@@ -162,7 +162,7 @@ SaveStateList KyraMetaEngine::listSaves(const char *target) const {
if (slotNum == 0 && header.gameID == Kyra::GI_KYRA3)
header.description = "New Game";
- saveList.push_back(SaveStateDescriptor(slotNum, header.description.decode(Common::kISO8859_1)));
+ saveList.push_back(SaveStateDescriptor(slotNum, header.description));
}
delete in;
}
More information about the Scummvm-git-logs
mailing list