From e4b78f4f621a7d73c08099c3b7674f3966cf8da4 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Tue, 2 Apr 2019 20:23:13 +0100 Subject: WIN32: Ensure the translated dialog strings are using the correct encoding --- backends/platform/sdl/win32/win32_wrapper.cpp | 28 +++++++++++++++++++++------ backends/platform/sdl/win32/win32_wrapper.h | 6 ++++-- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'backends/platform/sdl/win32') diff --git a/backends/platform/sdl/win32/win32_wrapper.cpp b/backends/platform/sdl/win32/win32_wrapper.cpp index aa3a05fa48..7efcb00aa1 100644 --- a/backends/platform/sdl/win32/win32_wrapper.cpp +++ b/backends/platform/sdl/win32/win32_wrapper.cpp @@ -29,6 +29,7 @@ #include #include "common/scummsys.h" +#include "common/translation.h" #include "backends/platform/sdl/win32/win32_wrapper.h" // VerSetConditionMask, VerifyVersionInfo and SHGetFolderPath didn't appear until Windows 2000, @@ -80,28 +81,43 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion) { return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask); } -wchar_t *ansiToUnicode(const char *s) { - DWORD size = MultiByteToWideChar(0, 0, s, -1, NULL, 0); +wchar_t *ansiToUnicode(const char *s, uint codePage) { + DWORD size = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0); if (size > 0) { LPWSTR result = new WCHAR[size]; - if (MultiByteToWideChar(0, 0, s, -1, result, size) != 0) + if (MultiByteToWideChar(codePage, 0, s, -1, result, size) != 0) return result; } return NULL; } -char *unicodeToAnsi(const wchar_t *s) { - DWORD size = WideCharToMultiByte(0, 0, s, -1, NULL, 0, 0, 0); +char *unicodeToAnsi(const wchar_t *s, uint codePage) { + DWORD size = WideCharToMultiByte(codePage, 0, s, -1, NULL, 0, 0, 0); if (size > 0) { char *result = new char[size]; - if (WideCharToMultiByte(0, 0, s, -1, result, size, 0, 0) != 0) + if (WideCharToMultiByte(codePage, 0, s, -1, result, size, 0, 0) != 0) return result; } return NULL; } +uint getCurrentCharset() { +#ifdef USE_TRANSLATION + Common::String charset = TransMan.getCurrentCharset(); + if (charset == "iso-8859-2") + return 28592; + if (charset == "iso-8859-5") + return 28595; + if (charset == "iso-8859-7") + return 28597; + if (charset == "iso-8859-8") + return 28598; +#endif + return 28591; +} + } diff --git a/backends/platform/sdl/win32/win32_wrapper.h b/backends/platform/sdl/win32/win32_wrapper.h index d42838d1e1..8bd60239df 100644 --- a/backends/platform/sdl/win32/win32_wrapper.h +++ b/backends/platform/sdl/win32/win32_wrapper.h @@ -45,7 +45,7 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion); * * @note Return value must be freed by the caller. */ -wchar_t *ansiToUnicode(const char *s); +wchar_t *ansiToUnicode(const char *s, uint codePage = CP_ACP); /** * Converts a Windows wide-character string into a C string. * Used to interact with Win32 Unicode APIs with no ANSI fallback. @@ -55,7 +55,9 @@ wchar_t *ansiToUnicode(const char *s); * * @note Return value must be freed by the caller. */ -char *unicodeToAnsi(const wchar_t *s); +char *unicodeToAnsi(const wchar_t *s, uint codePage = CP_ACP); + +uint getCurrentCharset(); } -- cgit v1.2.3