[Scummvm-git-logs] scummvm master -> 747ace78fc1767a549560c46d7689f1f8f1628d9

bluegr bluegr at gmail.com
Sun Jun 30 15:45:49 CEST 2019


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:
747ace78fc COMMON & WINTERMUTE: Use non-1252 for 125X games (PR 1698)


Commit: 747ace78fc1767a549560c46d7689f1f8f1628d9
    https://github.com/scummvm/scummvm/commit/747ace78fc1767a549560c46d7689f1f8f1628d9
Author: lolbot-iichan (lolbot_iichan at mail.ru)
Date: 2019-06-30T16:45:46+03:00

Commit Message:
COMMON & WINTERMUTE: Use non-1252 for 125X games (PR 1698)

* WINTERMUTE: Add detection for "The Driller Incident"

"The Driller Incident" is a small freeware game for Wintermute,
avaliable in English and Russian: http://questzone.ru/enzi/files/1645

* WINTERMUTE: Add detection table for "One Helluva Day" demo

"One Helluva Day" is a point-and-click adventure demo in English / Czech
/ Russian.
Free download:
https://store.steampowered.com/app/603680/One_helluva_day/

* WINTERMUTE: Support CHARSET property for TT fonts

"// we don't need this anymore" was a mistake =)

Surely, most Wintermute games are either designed for 1252 language
(DE_DEU, EN_ANY, ES_ESP, FR_FRA, IT_ITA, PT_BRA), or don't use TrueType
fonts (5ma, deadcity, grotter1, grotter2, thekite, tib), or use
CHARSET=1 with UTF strings (dirtysplit, reversion1, reversion2, twc),
which meen this conversion is not needed for those games.

However, there are some games that explicitly states CHARSET=10 (driller
(RU_RUS), oknytt (RU_RUS), onehelluvaday (UNK_LANG when playing as
Russian)) and there are some games with CHARSET=1 with non-1252 in mind
(bookofgron (RU_RUS excepts 1251), carolreed4 (RU_RUS excepts 1251),
kulivocko (CZ_CZE excepts 1250)).

This fixes text in some games: bookofgron, carolreed4, driller, kulivocko,
oknytt, onehelluvaday.

* WINTERMUTE: Break savegame compatibility

sizeof(BaseFontTT) was changed, so let's break savegame compatibility

* COMMON: Add conversion tables for win1253 and win1257

* COMMON: Add string conversion from U32String back to Common::String

convertUtf32ToUtf8 code is based on Wintermute::ConvertUTF32toUTF8
convertFromU32String use convertUtf32ToUtf8 for UTF8 or lookup through
conversion table for single-byte encodings

* WINTERMUTE: Use Common::convert functions for non-UTF charsets

* WINTERMUTE: Fix whitespaces at detection tables

* WINTERMUTE: Add TODO comments

Changed paths:
    common/ustr.cpp
    common/ustr.h
    engines/wintermute/base/font/base_font_truetype.cpp
    engines/wintermute/base/font/base_font_truetype.h
    engines/wintermute/dcgf.h
    engines/wintermute/dctypes.h
    engines/wintermute/detection_tables.h
    engines/wintermute/utils/string_util.cpp
    engines/wintermute/utils/string_util.h


diff --git a/common/ustr.cpp b/common/ustr.cpp
index 8e41299..c0a2412 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -428,7 +428,13 @@ void U32String::initWithCStr(const char *str, uint32 len) {
 	_str[len] = 0;
 }
 
-// This is a quick and dirty converter.
+// //TODO: This is a quick and dirty converter. Refactoring needed:
+// 1. This version is unsafe! There are no checks for end of buffer
+//    near i++ operations.
+// 2. Original version has an option for performing strict / nonstrict
+//    conversion for the 0xD800...0xDFFF interval
+// 3. Original version returns a result code. This version does NOT
+//    insert 'FFFD' on errors & does not inform caller on any errors
 //
 // More comprehensive one lives in wintermute/utils/convert_utf.cpp
 U32String convertUtf8ToUtf32(const String &str) {
@@ -461,6 +467,64 @@ U32String convertUtf8ToUtf32(const String &str) {
 	return u32str;
 }
 
+// //TODO: This is a quick and dirty converter. Refactoring needed:
+// 1. Original version is more effective.
+//    This version features buffer = (char)(...) + buffer; pattern that causes
+//    unnecessary copying and reallocations, original code works with raw bytes
+// 2. Original version has an option for performing strict / nonstrict
+//    conversion for the 0xD800...0xDFFF interval
+// 3. Original version returns a result code. This version inserts '0xFFFD' if
+//    character does not fit in 4 bytes & does not inform caller on any errors
+//
+// More comprehensive one lives in wintermute/utils/convert_utf.cpp
+String convertUtf32ToUtf8(const U32String &u32str) {
+	static const uint8 firstByteMark[5] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0 };
+
+	Common::String str;
+	uint i = 0;
+	while (i < u32str.size()) {
+		unsigned short bytesToWrite = 0;
+		const uint32 byteMask = 0xBF;
+		const uint32 byteMark = 0x80;
+
+		uint32 ch = u32str[i++];
+		if (ch < (uint32)0x80) {
+			bytesToWrite = 1;
+		} else if (ch < (uint32)0x800) {
+			bytesToWrite = 2;
+		} else if (ch < (uint32)0x10000) {
+			bytesToWrite = 3;
+		} else if (ch <= 0x0010FFFF) {
+			bytesToWrite = 4;
+		} else {
+			bytesToWrite = 3;
+			ch = 0x0000FFFD;
+		}
+		
+		Common::String buffer;
+
+		switch (bytesToWrite) {
+		case 4:
+			buffer = (char)((ch | byteMark) & byteMask);
+			ch >>= 6;
+			// fallthrough
+		case 3:
+			buffer = (char)((ch | byteMark) & byteMask) + buffer;
+			ch >>= 6;
+			// fallthrough
+		case 2:
+			buffer = (char)((ch | byteMark) & byteMask) + buffer;
+			ch >>= 6;
+			// fallthrough
+		case 1:
+			buffer = (char)(ch | firstByteMark[bytesToWrite]) + buffer;
+		}
+
+		str += buffer;
+	}
+	return str;
+}
+
 static const uint32 g_windows1250ConversionTable[] = {0x20AC, 0x0081, 0x201A, 0x0083, 0x201E, 0x2026, 0x2020, 0x2021,
 										 0x0088, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
 										 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -512,6 +576,23 @@ static const uint32 g_windows1252ConversionTable[] = {0x20AC, 0x0081, 0x201A, 0x
 										 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
 										 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF};
 
+static const uint32 g_windows1253ConversionTable[] = {0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+										 0x0088, 0x2030, 0x008A, 0x2039, 0x008C, 0x008D, 0x008E, 0x008F,
+										 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+										 0x0098, 0x2122, 0x009A, 0x203A, 0x009C, 0x009D, 0x009E, 0x009F,
+										 0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+										 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
+										 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
+										 0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
+										 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
+										 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
+										 0x03A0, 0x03A1, 0x00D2, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
+										 0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
+										 0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
+										 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
+										 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
+										 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x00FF};
+
 static const uint32 g_windows1255ConversionTable[] = {0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
 										 0x02C6, 0x2030, 0x008A, 0x2039, 0x008C, 0x008D, 0x008E, 0x008F,
 										 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@@ -529,6 +610,23 @@ static const uint32 g_windows1255ConversionTable[] = {0x20AC, 0x0081, 0x201A, 0x
 										 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
 										 0x05E8, 0x05E9, 0x05EA, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x00FF};
 
+static const uint32 g_windows1257ConversionTable[] = {0x20AC, 0x0081, 0x201A, 0x0083, 0x201E, 0x2026, 0x2020, 0x2021,
+										 0x0088, 0x2030, 0x008A, 0x2039, 0x008C, 0x00A8, 0x02C7, 0x00B8,
+										 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+										 0x0098, 0x2122, 0x009A, 0x203A, 0x009C, 0x00AF, 0x02DB, 0x009F,
+										 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+										 0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00C6,
+										 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+										 0x00F8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
+										 0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
+										 0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
+										 0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
+										 0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
+										 0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
+										 0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
+										 0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
+										 0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9};
+
 U32String convertToU32String(const char *str, CodePage page) {
 	const String string(str);
 	if (page == kUtf8) {
@@ -554,9 +652,15 @@ U32String convertToU32String(const char *str, CodePage page) {
 		case kWindows1252:
 			unicodeString += g_windows1252ConversionTable[index];
 			break;
+		case kWindows1253:
+			unicodeString += g_windows1253ConversionTable[index];
+			break;
 		case kWindows1255:
 			unicodeString += g_windows1255ConversionTable[index];
 			break;
+		case kWindows1257:
+			unicodeString += g_windows1257ConversionTable[index];
+			break;
 		default:
 			break;
 		}
@@ -564,4 +668,54 @@ U32String convertToU32String(const char *str, CodePage page) {
 	return unicodeString;
 }
 
+String convertFromU32String(const U32String &string, CodePage page) {
+	if (page == kUtf8) {
+		return convertUtf32ToUtf8(string);
+	}
+
+	const uint32 *conversionTable = NULL;
+	switch (page) {
+	case kWindows1250:
+		conversionTable = g_windows1250ConversionTable;
+		break;
+	case kWindows1251:
+		conversionTable = g_windows1251ConversionTable;
+		break;
+	case kWindows1252:
+		conversionTable = g_windows1252ConversionTable;
+		break;
+	case kWindows1253:
+		conversionTable = g_windows1253ConversionTable;
+		break;
+	case kWindows1255:
+		conversionTable = g_windows1255ConversionTable;
+		break;
+	case kWindows1257:
+		conversionTable = g_windows1257ConversionTable;
+		break;
+	default:
+		break;
+	}
+
+	String charsetString;
+	for (uint i = 0; i < string.size(); ++i) {
+		if (string[i] <= 0x7F) {
+			charsetString += string[i];
+			continue;
+		}
+		
+		if (!conversionTable) {
+			continue;
+		}
+
+		for (uint j = 0; j < 128; ++j) {
+			if (conversionTable[j] == string[i]) {
+				charsetString += (char)(j + 0x80);
+				break;
+			}
+		}
+	}	
+	return charsetString;
+}
+
 } // End of namespace Common
diff --git a/common/ustr.h b/common/ustr.h
index 7f20207..17858d4 100644
--- a/common/ustr.h
+++ b/common/ustr.h
@@ -218,16 +218,20 @@ private:
 };
 
 U32String convertUtf8ToUtf32(const String &str);
+String convertUtf32ToUtf8(const U32String &str);
 
 enum CodePage {
 	kUtf8,
 	kWindows1250,
 	kWindows1251,
 	kWindows1252,
-	kWindows1255
+	kWindows1253,
+	kWindows1255,
+	kWindows1257
 };
 
 U32String convertToU32String(const char *str, CodePage page = kUtf8);
+String convertFromU32String(const U32String &str, CodePage page = kUtf8);
 
 } // End of namespace Common
 
diff --git a/engines/wintermute/base/font/base_font_truetype.cpp b/engines/wintermute/base/font/base_font_truetype.cpp
index 93084ca..03d82cb 100644
--- a/engines/wintermute/base/font/base_font_truetype.cpp
+++ b/engines/wintermute/base/font/base_font_truetype.cpp
@@ -48,6 +48,7 @@ IMPLEMENT_PERSISTENT(BaseFontTT, false)
 BaseFontTT::BaseFontTT(BaseGame *inGame) : BaseFont(inGame) {
 	_fontHeight = 12;
 	_isBold = _isItalic = _isUnderline = _isStriked = false;
+	_charset = CHARSET_ANSI;
 
 	_fontFile = nullptr;
 	_font = nullptr;
@@ -116,7 +117,7 @@ int BaseFontTT::getTextWidth(const byte *text, int maxLength) {
 	if (_gameRef->_textEncoding == TEXT_UTF8) {
 		textStr = StringUtil::utf8ToWide((const char *)text);
 	} else {
-		textStr = StringUtil::ansiToWide((const char *)text);
+		textStr = StringUtil::ansiToWide((const char *)text, _charset);
 	}
 
 	if (maxLength >= 0 && textStr.size() > (uint32)maxLength) {
@@ -137,7 +138,7 @@ int BaseFontTT::getTextHeight(const byte *text, int width) {
 	if (_gameRef->_textEncoding == TEXT_UTF8) {
 		textStr = StringUtil::utf8ToWide((const char *)text);
 	} else {
-		textStr = StringUtil::ansiToWide((const char *)text);
+		textStr = StringUtil::ansiToWide((const char *)text, _charset);
 	}
 
 
@@ -162,7 +163,7 @@ void BaseFontTT::drawText(const byte *text, int x, int y, int width, TTextAlign
 	if (_gameRef->_textEncoding == TEXT_UTF8) {
 		textStr = StringUtil::utf8ToWide((const char *)text);
 	} else {
-		textStr = StringUtil::ansiToWide((const char *)text);
+		textStr = StringUtil::ansiToWide((const char *)text, _charset);
 	}
 
 	if (maxLength >= 0 && textStr.size() > (uint32)maxLength) {
@@ -412,7 +413,7 @@ bool BaseFontTT::loadBuffer(char *buffer) {
 			break;
 
 		case TOKEN_CHARSET:
-			// we don't need this anymore
+			parser.scanStr(params, "%d", &_charset);
 			break;
 
 		case TOKEN_COLOR: {
@@ -519,6 +520,7 @@ bool BaseFontTT::persist(BasePersistenceManager *persistMgr) {
 	persistMgr->transferBool(TMEMBER(_isStriked));
 	persistMgr->transferSint32(TMEMBER(_fontHeight));
 	persistMgr->transferCharPtr(TMEMBER(_fontFile));
+	persistMgr->transferSint32(TMEMBER_INT(_charset));
 
 
 	// persist layers
diff --git a/engines/wintermute/base/font/base_font_truetype.h b/engines/wintermute/base/font/base_font_truetype.h
index c0349ec..d74efa0 100644
--- a/engines/wintermute/base/font/base_font_truetype.h
+++ b/engines/wintermute/base/font/base_font_truetype.h
@@ -141,6 +141,7 @@ private:
 	bool _isStriked;
 	int32 _fontHeight;
 	char *_fontFile;
+	TTextCharset _charset;
 
 	BaseArray<BaseTTFontLayer *> _layers;
 	void clearCache();
diff --git a/engines/wintermute/dcgf.h b/engines/wintermute/dcgf.h
index c919180..9ed7361 100644
--- a/engines/wintermute/dcgf.h
+++ b/engines/wintermute/dcgf.h
@@ -32,7 +32,7 @@
 
 //////////////////////////////////////////////////////////////////////////
 #define DCGF_VER_MAJOR 1
-#define DCGF_VER_MINOR 3
+#define DCGF_VER_MINOR 4
 #define DCGF_VER_BUILD 1
 #define DCGF_VER_SUFFIX "ScummVM"
 #define DCGF_VER_BETA true
@@ -42,7 +42,7 @@
 
 // minimal saved game version we support
 #define SAVEGAME_VER_MAJOR 1
-#define SAVEGAME_VER_MINOR 1
+#define SAVEGAME_VER_MINOR 4
 #define SAVEGAME_VER_BUILD 1
 //////////////////////////////////////////////////////////////////////////
 
diff --git a/engines/wintermute/dctypes.h b/engines/wintermute/dctypes.h
index 571ce21..9f68eca 100644
--- a/engines/wintermute/dctypes.h
+++ b/engines/wintermute/dctypes.h
@@ -191,6 +191,28 @@ enum TSpriteCacheType {
 	CACHE_HALF
 };
 
+enum TTextCharset {
+	CHARSET_ANSI = 0,
+	CHARSET_DEFAULT = 1,
+	CHARSET_OEM = 2,
+	CHARSET_BALTIC = 3,
+	CHARSET_CHINESEBIG5 = 4,
+	CHARSET_EASTEUROPE = 5,
+	CHARSET_GB2312 = 6, 
+	CHARSET_GREEK = 7,
+	CHARSET_HANGUL = 8, 
+	CHARSET_MAC = 9,
+	CHARSET_RUSSIAN = 10,
+	CHARSET_SHIFTJIS = 11,
+	CHARSET_SYMBOL = 12,
+	CHARSET_TURKISH = 13,
+	CHARSET_VIETNAMESE = 14,
+	CHARSET_JOHAB = 15,
+	CHARSET_ARABIC = 16,
+	CHARSET_HEBREW = 17,
+	CHARSET_THAI = 18
+};
+
 enum TTextEncoding {
 	TEXT_ANSI = 0,
 	TEXT_UTF8 = 1,
diff --git a/engines/wintermute/detection_tables.h b/engines/wintermute/detection_tables.h
index ec4a7c5..0bc2308 100644
--- a/engines/wintermute/detection_tables.h
+++ b/engines/wintermute/detection_tables.h
@@ -29,9 +29,9 @@ static const PlainGameDescriptor wintermuteGames[] = {
 	{"5ld",             "Five Lethal Demons"},
 	{"5ma",             "Five Magical Amulets"},
 	{"actualdest",      "Actual Destination"},
-	{"agustin",			"Boredom of Agustin Cordes"},
-	{"alimardan1",		"Alimardan's Mischief"},
-	{"alimardan2",		"Alimardan Meets Merlin"},
+	{"agustin",         "Boredom of Agustin Cordes"},
+	{"alimardan1",      "Alimardan's Mischief"},
+	{"alimardan2",      "Alimardan Meets Merlin"},
 	{"basisoctavus",    "Basis Octavus"},
 	{"bickadoodle",     "Bickadoodle"},
 	{"bookofgron",      "Book of Gron Part One"},
@@ -54,6 +54,7 @@ static const PlainGameDescriptor wintermuteGames[] = {
 	{"dfafadventure",   "DFAF Adventure"},
 	{"dreamcat",        "Dreamcat"},
 	{"dreaming",        "Des Reves Elastiques Avec Mille Insectes Nommes Georges"},
+	{"driller",         "The Driller Incident"},
 	{"dirtysplit",      "Dirty Split"},
 	{"dreamscape",      "Dreamscape"},
 	{"escapemansion",   "Escape from the Mansion"},
@@ -71,6 +72,7 @@ static const PlainGameDescriptor wintermuteGames[] = {
 	{"mirage",          "Mirage"},
 	{"nighttrain",      "Night Train"},
 	{"oknytt",          "Oknytt"},
+	{"onehelluvaday",   "One Helluva Day"},
 	{"openquest",       "Open Quest"},
 	{"paintaria",       "Paintaria"},
 	{"pigeons",         "Pigeons in the Park"},
@@ -376,25 +378,33 @@ static const WMEGameDescription gameDescriptions[] = {
 	WME_WINENTRY("dreaming", "",
 		WME_ENTRY1s("data.dcp", "4af26d97ea063fc1277ce30ae431de90", 8804073), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
+	// The Driller Incident (English)
+	WME_WINENTRY("driller", "",
+		WME_ENTRY1s("data.dcp","9cead7a85244263e0a5ff8f69dd7a1fc", 13671792), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+
+	// The Driller Incident (Russian)
+	WME_WINENTRY("driller", "",
+		WME_ENTRY1s("data.dcp","5bec2442339dd1ecf221873fff704617", 13671830), Common::RU_RUS, ADGF_UNSTABLE, LATEST_VERSION),
+
 	// Dreamcat
 	WME_WINENTRY("dreamcat", "",
 		WME_ENTRY1s("data.dcp","189bd4eef29034f4ff4ed30120eaac4e", 7758040), Common::EN_ANY, ADGF_UNSTABLE | GF_LOWSPEC_ASSETS, LATEST_VERSION),
 
 	// Dreamscape
 	WME_WINENTRY("dreamscape", "",
-		WME_ENTRY1s("data.dcp",  "7a5752ed4446c862be9f02d7932acf54", 17034377), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "7a5752ed4446c862be9f02d7932acf54", 17034377), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Escape from the Mansion
 	WME_WINENTRY("escapemansion", "Beta 1",
-		WME_ENTRY1s("data.dcp",  "d8e348b2312cc36a929cad75f12e0b3a", 21452380), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "d8e348b2312cc36a929cad75f12e0b3a", 21452380), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Escape from the Mansion
 	WME_WINENTRY("escapemansion", "Beta 2",
-		WME_ENTRY1s("data.dcp",  "ded5fa6c5f2afdaf2cafb53e52cd3dd8", 21455763), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "ded5fa6c5f2afdaf2cafb53e52cd3dd8", 21455763), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Escape from the Mansion
 	WME_WINENTRY("escapemansion", "1.3",
-		WME_ENTRY1s("data.dcp",  "1e5d231b56c8a228cd15cb690f50253e", 29261972), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "1e5d231b56c8a228cd15cb690f50253e", 29261972), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Four
 	WME_WINENTRY("four", "",
@@ -402,7 +412,7 @@ static const WMEGameDescription gameDescriptions[] = {
 
 	// Framed
 	WME_WINENTRY("framed", "",
-		WME_ENTRY1s("data.dcp",  "e7259fb36f2c6f9f28242291e0c3de98", 34690568), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "e7259fb36f2c6f9f28242291e0c3de98", 34690568), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Ghost in the Sheet
 	WME_WINENTRY("ghostsheet", "",
@@ -498,7 +508,7 @@ static const WMEGameDescription gameDescriptions[] = {
 	// Looky (English)
 	WME_WINENTRY("looky", "",
 		WME_ENTRY2s("english.dcp", "71ed521b7a1d1a23c3805c26f16de2b9", 245968038,
-					"data.dcp",  "d0f2bb73425db45fcff6690637c430dd", 1342439), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+					"data.dcp", "d0f2bb73425db45fcff6690637c430dd", 1342439), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Looky (German)
 	WME_WINENTRY("looky", "",
@@ -548,6 +558,10 @@ static const WMEGameDescription gameDescriptions[] = {
 		WME_ENTRY2s("spanish.dcp", "10c46152cb29581671f3b6b7c229c957", 319406572,
 					"d_sounds.dcp", "7d04dff8ca11174486bd4b7a80fdcabb", 154943401), Common::ES_ESP, ADGF_UNSTABLE, LATEST_VERSION),
 
+	// One Helluva Day (Demo) (multi-language)
+	WME_WINENTRY("onehelluvaday", "",
+		WME_ENTRY1s("data.dcp", "144e23fca7c1c54103dad9c1342de2b6", 229963509), Common::UNK_LANG, ADGF_UNSTABLE | ADGF_DEMO, LATEST_VERSION),
+
 	// Open Quest
 	WME_WINENTRY("openquest", "",
 		WME_ENTRY1s("data.dcp", "16893e3fc15a211a49654ae66f684f28", 82281736), Common::EN_ANY, ADGF_UNSTABLE | GF_LOWSPEC_ASSETS, LATEST_VERSION),
@@ -567,7 +581,7 @@ static const WMEGameDescription gameDescriptions[] = {
 	// Pizza Morgana
 	WME_WINENTRY("pizzamorgana", "",
 		WME_ENTRY2s("english.dcp", "7fa6149bb44574109668ce585d6c41c9", 9282608,
-					"data.dcp",  "a69994c463ff5fcc6fe1800662f5b7d0", 34581370), Common::EN_ANY, ADGF_UNSTABLE | ADGF_DEMO, WME_1_9_0),
+					"data.dcp", "a69994c463ff5fcc6fe1800662f5b7d0", 34581370), Common::EN_ANY, ADGF_UNSTABLE | ADGF_DEMO, WME_1_9_0),
 
 	// Project: Doom
 	WME_WINENTRY("projectdoom", "",
@@ -1736,7 +1750,7 @@ static const WMEGameDescription gameDescriptions[] = {
 
 	// Satan and Son
 	WME_WINENTRY("satanandson", "",
-		WME_ENTRY1s("data.dcp",  "16a6ba8174b697bbba9299619d1e20c4", 67539054), Common::EN_ANY, ADGF_UNSTABLE | ADGF_DEMO, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "16a6ba8174b697bbba9299619d1e20c4", 67539054), Common::EN_ANY, ADGF_UNSTABLE | ADGF_DEMO, LATEST_VERSION),
 
 	// Rosemary
 	WME_WINENTRY("rosemary", "",
@@ -1744,11 +1758,11 @@ static const WMEGameDescription gameDescriptions[] = {
 
 	// Securanote
 	WME_PLATENTRY("securanote", "",
-		WME_ENTRY1s("data.dcp",  "5213d3e59b9e95b7fbd5c56f7de5341a", 2625554), Common::EN_ANY, Common::kPlatformIOS, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "5213d3e59b9e95b7fbd5c56f7de5341a", 2625554), Common::EN_ANY, Common::kPlatformIOS, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Shaban
 	WME_WINENTRY("shaban", "",
-		WME_ENTRY1s("data.dcp",  "35f702ca9baabc5c620e0be230195c8a", 755388466), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "35f702ca9baabc5c620e0be230195c8a", 755388466), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// The Shine of a Star
 	WME_WINENTRY("shinestar", "",
@@ -1764,13 +1778,13 @@ static const WMEGameDescription gameDescriptions[] = {
 
 	// Space Madness
 	WME_WINENTRY("spacemadness", "1.0.2",
-		WME_ENTRY1s("data.dcp",  "b9b83135dc7a9e1b4b5f50195dbeb630", 39546622), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "b9b83135dc7a9e1b4b5f50195dbeb630", 39546622), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Tanya Grotter and the Magical Double Bass
 	WME_WINENTRY("tanya1", "",
 		WME_ENTRY1s("data.dcp", "035bbdaff078cc4053ecf4b518c0d0fd", 1007507786), Common::RU_RUS, ADGF_UNSTABLE, LATEST_VERSION),
 
-  // Tanya Grotter and the Disappearing Floor
+	// Tanya Grotter and the Disappearing Floor
 	WME_WINENTRY("tanya2", "",
 		WME_ENTRY1s("data.dcp", "9c15f14990f630177e063da885d03e6d", 936959767), Common::RU_RUS, ADGF_UNSTABLE, LATEST_VERSION),
 
@@ -1848,11 +1862,11 @@ static const WMEGameDescription gameDescriptions[] = {
 
 	// Zilm: A Game of Reflex 1.0
 	WME_WINENTRY("Zilm", "1.0",
-		WME_ENTRY1s("data.dcp",  "098dffaf03d8adbb4cb5633e4733e63c", 351726), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
+		WME_ENTRY1s("data.dcp", "098dffaf03d8adbb4cb5633e4733e63c", 351726), Common::EN_ANY, ADGF_UNSTABLE, LATEST_VERSION),
 
 	// Zbang! The Game
 	WME_WINENTRY("zbang", "0.89",
-		WME_ENTRY1s("data.dcp",  "db9101f08d12ab95c81042d154bb0ea8", 7210044), Common::EN_ANY, ADGF_UNSTABLE | ADGF_DEMO, WME_1_7_0),
+		WME_ENTRY1s("data.dcp", "db9101f08d12ab95c81042d154bb0ea8", 7210044), Common::EN_ANY, ADGF_UNSTABLE | ADGF_DEMO, WME_1_7_0),
 	{
 		AD_TABLE_END_MARKER,
 		LATEST_VERSION
diff --git a/engines/wintermute/utils/string_util.cpp b/engines/wintermute/utils/string_util.cpp
index 82d4fe6..d842b46 100644
--- a/engines/wintermute/utils/string_util.cpp
+++ b/engines/wintermute/utils/string_util.cpp
@@ -26,7 +26,9 @@
  * Copyright (c) 2011 Jan Nedoma
  */
 
+#include "common/language.h"
 #include "common/tokenizer.h"
+#include "engines/wintermute/base/base_engine.h"
 #include "engines/wintermute/utils/string_util.h"
 #include "engines/wintermute/utils/convert_utf.h"
 
@@ -96,48 +98,103 @@ Utf8String StringUtil::wideToUtf8(const WideString &WideStr) {
 }
 
 //////////////////////////////////////////////////////////////////////////
-WideString StringUtil::ansiToWide(const AnsiString &str) {
-	WideString result;
-	for (AnsiString::const_iterator i = str.begin(), end = str.end(); i != end; ++i) {
-		const byte c = *i;
-		if (c < 0x80 || c >= 0xA0) {
-			result += c;
-		} else {
-			uint32 utf32 = _ansiToUTF32[c - 0x80];
-			if (utf32) {
-				result += utf32;
-			} else {
-				// It's an invalid CP1252 character...
-			}
+Common::CodePage StringUtil::mapCodePage(TTextCharset charset) {
+	switch (charset) {
+	case CHARSET_EASTEUROPE:
+		return Common::kWindows1250;
+
+	case CHARSET_RUSSIAN:
+		return Common::kWindows1251;
+
+	case CHARSET_ANSI:
+		return Common::kWindows1252;
+
+	case CHARSET_GREEK:
+		return Common::kWindows1253;
+
+	case CHARSET_HEBREW:
+		return Common::kWindows1255;
+
+	case CHARSET_BALTIC:
+		return Common::kWindows1257;
+
+	case CHARSET_DEFAULT:
+		switch (BaseEngine::instance().getLanguage()) {
+
+		//cp1250: Central Europe
+		case Common::CZ_CZE:
+		case Common::HR_HRV:
+		case Common::HU_HUN:
+		case Common::PL_POL:
+		case Common::SK_SVK:
+			return Common::kWindows1250;
+
+		//cp1251: Cyrillic
+		case Common::RU_RUS:
+		case Common::UA_UKR:
+			return Common::kWindows1251;
+
+		//cp1252: Western Europe
+		case Common::DA_DAN:
+		case Common::DE_DEU:
+		case Common::EN_ANY:
+		case Common::EN_GRB:
+		case Common::EN_USA:
+		case Common::ES_ESP:
+		case Common::FI_FIN:
+		case Common::FR_FRA:
+		case Common::IT_ITA:
+		case Common::NB_NOR:
+		case Common::NL_NLD:
+		case Common::PT_BRA:
+		case Common::PT_POR:
+		case Common::SE_SWE:
+		case Common::UNK_LANG:
+			return Common::kWindows1252;
+
+		//cp1253: Greek
+		case Common::GR_GRE:
+			return Common::kWindows1253;
+
+		//cp1255: Hebrew
+		case Common::HE_ISR:
+			return Common::kWindows1255;
+
+		//cp1257: Baltic
+		case Common::ET_EST:
+		case Common::LV_LAT:
+			return Common::kWindows1257;
+
+		default:
+			return Common::kWindows1252;
 		}
+
+	case CHARSET_OEM:
+	case CHARSET_CHINESEBIG5:
+	case CHARSET_GB2312:
+	case CHARSET_HANGUL:
+	case CHARSET_MAC:
+	case CHARSET_SHIFTJIS:
+	case CHARSET_SYMBOL:
+	case CHARSET_TURKISH:
+	case CHARSET_VIETNAMESE:
+	case CHARSET_JOHAB:
+	case CHARSET_ARABIC:
+	case CHARSET_THAI:
+	default:
+		warning("Unsupported charset: %d", charset);
+		return Common::kWindows1252;
 	}
-	return result;
 }
 
 //////////////////////////////////////////////////////////////////////////
-AnsiString StringUtil::wideToAnsi(const WideString &wstr) {
-	AnsiString result;
-	for (WideString::const_iterator i = wstr.begin(), end = wstr.end(); i != end; ++i) {
-		const uint32 c = *i;
-		if (c < 0x80 || (c >= 0xA0 && c <= 0xFF)) {
-			result += c;
-		} else {
-			uint32 ansi = 0xFFFFFFFF;
-			for (uint j = 0; j < ARRAYSIZE(_ansiToUTF32); ++j) {
-				if (_ansiToUTF32[j] == c) {
-					ansi = j + 0x80;
-					break;
-				}
-			}
-
-			if (ansi != 0xFFFFFFFF) {
-				result += ansi;
-			} else {
-				// There's no valid CP1252 code for this character...
-			}
-		}
-	}
-	return result;
+WideString StringUtil::ansiToWide(const AnsiString &str, TTextCharset charset) {
+	return Common::convertToU32String(str.c_str(), mapCodePage(charset));
+}
+
+//////////////////////////////////////////////////////////////////////////
+AnsiString StringUtil::wideToAnsi(const WideString &wstr, TTextCharset charset) {
+	return Common::convertFromU32String(wstr, mapCodePage(charset));
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -172,10 +229,4 @@ AnsiString StringUtil::toString(int val) {
 	return Common::String::format("%d", val);
 }
 
-// Mapping of CP1252 characters 0x80...0x9F into UTF-32
-uint32 StringUtil::_ansiToUTF32[32] = {
-	0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000,
-	0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178
-};
-
 } // End of namespace Wintermute
diff --git a/engines/wintermute/utils/string_util.h b/engines/wintermute/utils/string_util.h
index 431d401..4657c66 100644
--- a/engines/wintermute/utils/string_util.h
+++ b/engines/wintermute/utils/string_util.h
@@ -39,8 +39,8 @@ public:
 	//static bool compareNoCase(const WideString &str1, const WideString &str2);
 	static WideString utf8ToWide(const Utf8String &Utf8Str);
 	static Utf8String wideToUtf8(const WideString &WideStr);
-	static WideString ansiToWide(const AnsiString &str);
-	static AnsiString wideToAnsi(const WideString &str);
+	static WideString ansiToWide(const AnsiString &str, TTextCharset charset = CHARSET_ANSI);
+	static AnsiString wideToAnsi(const WideString &str, TTextCharset charset = CHARSET_ANSI);
 
 	static bool isUtf8BOM(const byte *buffer, uint32 bufferSize);
 	static int indexOf(const WideString &str, const WideString &toFind, size_t startFrom);
@@ -51,7 +51,7 @@ public:
 	static AnsiString toString(int val);
 
 private:
-	static uint32 _ansiToUTF32[32];
+	static Common::CodePage mapCodePage(TTextCharset charset);
 };
 
 } // End of namespace Wintermute





More information about the Scummvm-git-logs mailing list