aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorlolbot-iichan2019-06-30 16:45:46 +0300
committerFilippos Karapetis2019-06-30 16:45:46 +0300
commit747ace78fc1767a549560c46d7689f1f8f1628d9 (patch)
tree036ee7cbf53ae058a273830016d0e5a93a8d9366 /engines
parent1276a4d6d7422ae3c995c800fcde6627f8d78b75 (diff)
downloadscummvm-rg350-747ace78fc1767a549560c46d7689f1f8f1628d9.tar.gz
scummvm-rg350-747ace78fc1767a549560c46d7689f1f8f1628d9.tar.bz2
scummvm-rg350-747ace78fc1767a549560c46d7689f1f8f1628d9.zip
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
Diffstat (limited to 'engines')
-rw-r--r--engines/wintermute/base/font/base_font_truetype.cpp10
-rw-r--r--engines/wintermute/base/font/base_font_truetype.h1
-rw-r--r--engines/wintermute/dcgf.h4
-rw-r--r--engines/wintermute/dctypes.h22
-rw-r--r--engines/wintermute/detection_tables.h48
-rw-r--r--engines/wintermute/utils/string_util.cpp137
-rw-r--r--engines/wintermute/utils/string_util.h6
7 files changed, 159 insertions, 69 deletions
diff --git a/engines/wintermute/base/font/base_font_truetype.cpp b/engines/wintermute/base/font/base_font_truetype.cpp
index 93084ca8a1..03d82cb940 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 c0349eccd4..d74efa067f 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 c919180e45..9ed73614b1 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 571ce21931..9f68eca9a5 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 ec4a7c56d3..0bc2308cd3 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 82d4fe6902..d842b468db 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 431d401d96..4657c66766 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