[Scummvm-git-logs] scummvm master -> 2186024624393ef243f93facfbc726ae282882a6
sev-
sev at scummvm.org
Thu Mar 25 19:53:18 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:
2186024624 BURIED: Improve text encoding conversion
Commit: 2186024624393ef243f93facfbc726ae282882a6
https://github.com/scummvm/scummvm/commit/2186024624393ef243f93facfbc726ae282882a6
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-03-25T20:53:16+01:00
Commit Message:
BURIED: Improve text encoding conversion
Changed paths:
engines/buried/buried.cpp
engines/buried/graphics.cpp
engines/buried/graphics.h
diff --git a/engines/buried/buried.cpp b/engines/buried/buried.cpp
index d07b1da606..1589079c14 100644
--- a/engines/buried/buried.cpp
+++ b/engines/buried/buried.cpp
@@ -85,12 +85,6 @@ BuriedEngine::~BuriedEngine() {
Common::Error BuriedEngine::run() {
setDebugger(new BuriedConsole(this));
-#ifndef USE_ICONV
- // The Japanese version needs iconv support
- if (getLanguage() == Common::JA_JPN)
- return Common::Error(Common::kUnknownError, "No iconv support available");
-#endif
-
if (isTrueColor()) {
initGraphics(640, 480, 0);
diff --git a/engines/buried/graphics.cpp b/engines/buried/graphics.cpp
index 9e6a404932..857fccece5 100644
--- a/engines/buried/graphics.cpp
+++ b/engines/buried/graphics.cpp
@@ -25,9 +25,6 @@
#include "common/config-manager.h"
#include "common/fs.h"
-#ifdef USE_ICONV
-#include "common/iconv.h"
-#endif
#include "common/str-array.h"
#include "common/system.h"
#include "common/unzip.h"
@@ -75,84 +72,6 @@ GraphicsManager::~GraphicsManager() {
delete[] _palette;
}
-// If we don't have iconv available, have a CP-1252 codepage mapping.
-#ifndef USE_ICONV
-
-#define REQUIRED(x) (((uint32)(x)) | 0x80000000)
-#define NOT_REQUIRED(x) (x)
-
-static const uint32 s_codePage1252[256] = {
- NOT_REQUIRED(0x0000), NOT_REQUIRED(0x0001), NOT_REQUIRED(0x0002), NOT_REQUIRED(0x0003),
- NOT_REQUIRED(0x0004), NOT_REQUIRED(0x0005), NOT_REQUIRED(0x0006), NOT_REQUIRED(0x0007),
- NOT_REQUIRED(0x0008), NOT_REQUIRED(0x0009), NOT_REQUIRED(0x000A), NOT_REQUIRED(0x000B),
- NOT_REQUIRED(0x000C), NOT_REQUIRED(0x000D), NOT_REQUIRED(0x000E), NOT_REQUIRED(0x000F),
- NOT_REQUIRED(0x0010), NOT_REQUIRED(0x0011), NOT_REQUIRED(0x0012), NOT_REQUIRED(0x0013),
- NOT_REQUIRED(0x0014), NOT_REQUIRED(0x0015), NOT_REQUIRED(0x0016), NOT_REQUIRED(0x0017),
- NOT_REQUIRED(0x0018), NOT_REQUIRED(0x0019), NOT_REQUIRED(0x001A), NOT_REQUIRED(0x001B),
- NOT_REQUIRED(0x001C), NOT_REQUIRED(0x001D), NOT_REQUIRED(0x001E), NOT_REQUIRED(0x001F),
- REQUIRED(0x0020), REQUIRED(0x0021), REQUIRED(0x0022), REQUIRED(0x0023),
- REQUIRED(0x0024), REQUIRED(0x0025), REQUIRED(0x0026), REQUIRED(0x0027),
- REQUIRED(0x0028), REQUIRED(0x0029), REQUIRED(0x002A), REQUIRED(0x002B),
- REQUIRED(0x002C), REQUIRED(0x002D), REQUIRED(0x002E), REQUIRED(0x002F),
- REQUIRED(0x0030), REQUIRED(0x0031), REQUIRED(0x0032), REQUIRED(0x0033),
- REQUIRED(0x0034), REQUIRED(0x0035), REQUIRED(0x0036), REQUIRED(0x0037),
- REQUIRED(0x0038), REQUIRED(0x0039), REQUIRED(0x003A), REQUIRED(0x003B),
- REQUIRED(0x003C), REQUIRED(0x003D), REQUIRED(0x003E), REQUIRED(0x003F),
- REQUIRED(0x0040), REQUIRED(0x0041), REQUIRED(0x0042), REQUIRED(0x0043),
- REQUIRED(0x0044), REQUIRED(0x0045), REQUIRED(0x0046), REQUIRED(0x0047),
- REQUIRED(0x0048), REQUIRED(0x0049), REQUIRED(0x004A), REQUIRED(0x004B),
- REQUIRED(0x004C), REQUIRED(0x004D), REQUIRED(0x004E), REQUIRED(0x004F),
- REQUIRED(0x0050), REQUIRED(0x0051), REQUIRED(0x0052), REQUIRED(0x0053),
- REQUIRED(0x0054), REQUIRED(0x0055), REQUIRED(0x0056), REQUIRED(0x0057),
- REQUIRED(0x0058), REQUIRED(0x0059), REQUIRED(0x005A), REQUIRED(0x005B),
- REQUIRED(0x005C), REQUIRED(0x005D), REQUIRED(0x005E), REQUIRED(0x005F),
- REQUIRED(0x0060), REQUIRED(0x0061), REQUIRED(0x0062), REQUIRED(0x0063),
- REQUIRED(0x0064), REQUIRED(0x0065), REQUIRED(0x0066), REQUIRED(0x0067),
- REQUIRED(0x0068), REQUIRED(0x0069), REQUIRED(0x006A), REQUIRED(0x006B),
- REQUIRED(0x006C), REQUIRED(0x006D), REQUIRED(0x006E), REQUIRED(0x006F),
- REQUIRED(0x0070), REQUIRED(0x0071), REQUIRED(0x0072), REQUIRED(0x0073),
- REQUIRED(0x0074), REQUIRED(0x0075), REQUIRED(0x0076), REQUIRED(0x0077),
- REQUIRED(0x0078), REQUIRED(0x0079), REQUIRED(0x007A), REQUIRED(0x007B),
- REQUIRED(0x007C), REQUIRED(0x007D), REQUIRED(0x007E), NOT_REQUIRED(0x007F),
- NOT_REQUIRED(0xFFFE), NOT_REQUIRED(0xFFFE), REQUIRED(0x201A), REQUIRED(0x0192),
- REQUIRED(0x201E), REQUIRED(0x2026), REQUIRED(0x2020), REQUIRED(0x2021),
- REQUIRED(0x02C6), REQUIRED(0x2030), REQUIRED(0x0160), REQUIRED(0x2039),
- REQUIRED(0x0152), NOT_REQUIRED(0xFFFE), NOT_REQUIRED(0xFFFE), NOT_REQUIRED(0xFFFE),
- NOT_REQUIRED(0xFFFE), REQUIRED(0x2018), REQUIRED(0x2019), REQUIRED(0x201C),
- REQUIRED(0x201D), REQUIRED(0x2022), REQUIRED(0x2013), REQUIRED(0x2014),
- REQUIRED(0x02DC), REQUIRED(0x2122), REQUIRED(0x0161), REQUIRED(0x203A),
- REQUIRED(0x0153), NOT_REQUIRED(0xFFFE), NOT_REQUIRED(0xFFFE), REQUIRED(0x0178),
- REQUIRED(0x00A0), REQUIRED(0x00A1), REQUIRED(0x00A2), REQUIRED(0x00A3),
- REQUIRED(0x00A4), REQUIRED(0x00A5), REQUIRED(0x00A6), REQUIRED(0x00A7),
- REQUIRED(0x00A8), REQUIRED(0x00A9), REQUIRED(0x00AA), REQUIRED(0x00AB),
- REQUIRED(0x00AC), REQUIRED(0x00AD), REQUIRED(0x00AE), REQUIRED(0x00AF),
- REQUIRED(0x00B0), REQUIRED(0x00B1), REQUIRED(0x00B2), REQUIRED(0x00B3),
- REQUIRED(0x00B4), REQUIRED(0x00B5), REQUIRED(0x00B6), REQUIRED(0x00B7),
- REQUIRED(0x00B8), REQUIRED(0x00B9), REQUIRED(0x00BA), REQUIRED(0x00BB),
- REQUIRED(0x00BC), REQUIRED(0x00BD), REQUIRED(0x00BE), REQUIRED(0x00BF),
- REQUIRED(0x00C0), REQUIRED(0x00C1), REQUIRED(0x00C2), REQUIRED(0x00C3),
- REQUIRED(0x00C4), REQUIRED(0x00C5), REQUIRED(0x00C6), REQUIRED(0x00C7),
- REQUIRED(0x00C8), REQUIRED(0x00C9), REQUIRED(0x00CA), REQUIRED(0x00CB),
- REQUIRED(0x00CC), REQUIRED(0x00CD), REQUIRED(0x00CE), REQUIRED(0x00CF),
- REQUIRED(0x00D0), REQUIRED(0x00D1), REQUIRED(0x00D2), REQUIRED(0x00D3),
- REQUIRED(0x00D4), REQUIRED(0x00D5), REQUIRED(0x00D6), REQUIRED(0x00D7),
- REQUIRED(0x00D8), REQUIRED(0x00D9), REQUIRED(0x00DA), REQUIRED(0x00DB),
- REQUIRED(0x00DC), REQUIRED(0x00DD), REQUIRED(0x00DE), REQUIRED(0x00DF),
- REQUIRED(0x00E0), REQUIRED(0x00E1), REQUIRED(0x00E2), REQUIRED(0x00E3),
- REQUIRED(0x00E4), REQUIRED(0x00E5), REQUIRED(0x00E6), REQUIRED(0x00E7),
- REQUIRED(0x00E8), REQUIRED(0x00E9), REQUIRED(0x00EA), REQUIRED(0x00EB),
- REQUIRED(0x00EC), REQUIRED(0x00ED), REQUIRED(0x00EE), REQUIRED(0x00EF),
- REQUIRED(0x00F0), REQUIRED(0x00F1), REQUIRED(0x00F2), REQUIRED(0x00F3),
- REQUIRED(0x00F4), REQUIRED(0x00F5), REQUIRED(0x00F6), REQUIRED(0x00F7),
- REQUIRED(0x00F8), REQUIRED(0x00F9), REQUIRED(0x00FA), REQUIRED(0x00FB),
- REQUIRED(0x00FC), REQUIRED(0x00FD), REQUIRED(0x00FE), REQUIRED(0x00FF)
-};
-
-#undef REQUIRED
-#undef NOT_REQUIRED
-
-#endif // USE_ICONV
-
Graphics::Font *GraphicsManager::createFont(int size, bool bold) const {
// MS Gothic for the Japanese version
// Arial or Arial Bold for everything else
@@ -192,18 +111,10 @@ Graphics::Font *GraphicsManager::createArialFont(int size, bool bold) const {
// with the TrueType font on Win7/Win8 (at least)
// FIXME: The font is slightly off from the original... need to check. Sizes are right though!
- // Enable code page mapping only if we don't have iconv. Otherwise, we'll
- // let that handle mapping for us.
-#ifdef USE_ICONV
- static const uint32 *codePageMapping = nullptr;
-#else
- static const uint32 *codePageMapping = s_codePage1252;
-#endif
-
Graphics::Font *font;
if (stream) {
- font = Graphics::loadTTFFont(*stream, size, Graphics::kTTFSizeModeCharacter, 96, _vm->isTrueColor() ? Graphics::kTTFRenderModeLight : Graphics::kTTFRenderModeMonochrome, codePageMapping);
+ font = Graphics::loadTTFFont(*stream, size, Graphics::kTTFSizeModeCharacter, 96, _vm->isTrueColor() ? Graphics::kTTFRenderModeLight : Graphics::kTTFRenderModeMonochrome);
delete stream;
} else {
@@ -213,7 +124,7 @@ Graphics::Font *GraphicsManager::createArialFont(int size, bool bold) const {
else
fname = "LiberationSans-Regular.ttf";
- font = Graphics::loadTTFFontFromArchive(fname, size, Graphics::kTTFSizeModeCharacter, 96, _vm->isTrueColor() ? Graphics::kTTFRenderModeLight : Graphics::kTTFRenderModeMonochrome, codePageMapping);
+ font = Graphics::loadTTFFontFromArchive(fname, size, Graphics::kTTFSizeModeCharacter, 96, _vm->isTrueColor() ? Graphics::kTTFRenderModeLight : Graphics::kTTFRenderModeMonochrome);
}
if (!font)
@@ -681,17 +592,19 @@ void GraphicsManager::renderText(Graphics::Surface *dst, Graphics::Font *font, c
if (text.empty())
return;
-#ifdef USE_ICONV
// Convert to UTF-32 for drawing. Choose the codepage based on the language.
- const char *srcFormat = (_vm->getLanguage() == Common::JA_JPN) ? "CP932" : "CP1252";
- Common::U32String convString = Common::convertToU32String(srcFormat, text);
- Common::Array<Common::U32String> lines;
- font->wordWrapText(convString, w, lines);
-#else
- // Assume we loaded the font with the correct mapping and draw it directly.
- Common::StringArray lines;
+ Common::CodePage srcFormat = (_vm->getLanguage() == Common::JA_JPN) ? Common::kWindows932 : Common::kWindows1252;
+ Common::U32String convString = text.decode(srcFormat);
+
+ renderText(dst, font, convString, x, y, w, h, color, lineHeight, textAlign, centerVertically);
+}
+
+void GraphicsManager::renderText(Graphics::Surface *dst, Graphics::Font *font, const Common::U32String &text, int x, int y, int w, int h, uint32 color, int lineHeight, TextAlign textAlign, bool centerVertically) {
+ if (text.empty())
+ return;
+
+ Common::U32StringArray lines;
font->wordWrapText(text, w, lines);
-#endif
Graphics::TextAlign align = Graphics::kTextAlignLeft;
switch (textAlign) {
diff --git a/engines/buried/graphics.h b/engines/buried/graphics.h
index b1305a11ee..a14b537531 100644
--- a/engines/buried/graphics.h
+++ b/engines/buried/graphics.h
@@ -102,6 +102,7 @@ public:
bool checkPointAgainstMaskedBitmap(const Graphics::Surface *bitmap, int x, int y, const Common::Point &point, byte rTrans, byte gTrans, byte bTrans);
void crossBlit(Graphics::Surface *dst, int xDst, int yDst, uint w, uint h, const Graphics::Surface *src, int xSrc, int ySrc);
void renderText(Graphics::Surface *dst, Graphics::Font *font, const Common::String &text, int x, int y, int w, int h, uint32 color, int lineHeight, TextAlign textAlign = kTextAlignLeft, bool centerVertically = false);
+ void renderText(Graphics::Surface *dst, Graphics::Font *font, const Common::U32String &text, int x, int y, int w, int h, uint32 color, int lineHeight, TextAlign textAlign = kTextAlignLeft, bool centerVertically = false);
void drawEllipse(const Common::Rect &rect, uint32 color);
Graphics::Surface *remapPalettedFrame(const Graphics::Surface *frame, const byte *palette);
More information about the Scummvm-git-logs
mailing list