aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJohannes Schickel2012-01-09 03:33:59 +0100
committerWillem Jan Palenstijn2012-01-29 16:26:20 +0100
commitf63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68 (patch)
treeb7ec71daf5c1d957c818e62ec87cd079fa7f2dbc /common
parent9f3fbe1bd773664b1e86241e71875cd97230d791 (diff)
downloadscummvm-rg350-f63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68.tar.gz
scummvm-rg350-f63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68.tar.bz2
scummvm-rg350-f63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68.zip
GRAPHICS/GUI: Implement charset mapping for TTF fonts.
The charsets used by the translations now need to have a "$(name).cp" file, which contains an charset index => unicode mapping. Otherwise create_translations will fail.
Diffstat (limited to 'common')
-rw-r--r--common/translation.cpp56
-rw-r--r--common/translation.h19
2 files changed, 69 insertions, 6 deletions
diff --git a/common/translation.cpp b/common/translation.cpp
index 081bde987d..219fce8794 100644
--- a/common/translation.cpp
+++ b/common/translation.cpp
@@ -26,7 +26,7 @@
#undef ARRAYSIZE
#endif
-#define TRANSLATIONS_DAT_VER 2
+#define TRANSLATIONS_DAT_VER 3
#include "common/translation.h"
#include "common/config-manager.h"
@@ -45,7 +45,7 @@ bool operator<(const TLanguage &l, const TLanguage &r) {
return strcmp(l.name, r.name) < 0;
}
-TranslationManager::TranslationManager() : _currentLang(-1) {
+TranslationManager::TranslationManager() : _currentLang(-1), _charmap(0) {
loadTranslationsInfoDat();
// Set the default language
@@ -53,6 +53,7 @@ TranslationManager::TranslationManager() : _currentLang(-1) {
}
TranslationManager::~TranslationManager() {
+ delete[] _charmap;
}
int32 TranslationManager::findMatchingLanguage(const String &lang) {
@@ -289,9 +290,14 @@ void TranslationManager::loadTranslationsInfoDat() {
// Get number of translations
int nbTranslations = in.readUint16BE();
- // Skip all the block sizes
- for (int i = 0; i < nbTranslations + 2; ++i)
- in.readUint16BE();
+ // Get number of codepages
+ int nbCodepages = in.readUint16BE();
+
+ // Determine where the codepages start
+ _charmapStart = 0;
+ for (int i = 0; i < nbTranslations + 3; ++i)
+ _charmapStart += in.readUint16BE();
+ _charmapStart += in.pos();
// Read list of languages
_langs.resize(nbTranslations);
@@ -305,6 +311,14 @@ void TranslationManager::loadTranslationsInfoDat() {
_langNames[i] = String(buf, len - 1);
}
+ // Read list of codepages
+ _charmaps.resize(nbCodepages);
+ for (int i = 0; i < nbCodepages; ++i) {
+ len = in.readUint16BE();
+ in.read(buf, len);
+ _charmaps[i] = String(buf, len - 1);
+ }
+
// Read messages
int numMessages = in.readUint16BE();
_messageIds.resize(numMessages);
@@ -344,9 +358,16 @@ void TranslationManager::loadLanguageDat(int index) {
return;
}
+ // Get the number of codepages
+ int nbCodepages = in.readUint16BE();
+ if (nbCodepages != (int)_charmaps.size()) {
+ warning("The 'translations.dat' file has changed since starting ScummVM. GUI translation will not be available");
+ return;
+ }
+
// Get size of blocks to skip.
int skipSize = 0;
- for (int i = 0; i < index + 2; ++i)
+ for (int i = 0; i < index + 3; ++i)
skipSize += in.readUint16BE();
// We also need to skip the remaining block sizes
skipSize += 2 * (nbTranslations - index);
@@ -380,6 +401,29 @@ void TranslationManager::loadLanguageDat(int index) {
_currentTranslationMessages[i].msgctxt = String(buf, len - 1);
}
}
+
+ // Find the charset
+ int charmapNum = -1;
+ for (uint i = 0; i < _charmaps.size(); ++i) {
+ if (_charmaps[i].equalsIgnoreCase(_currentCharset)) {
+ charmapNum = i;
+ break;
+ }
+ }
+
+ // Setup the new charset mapping
+ if (charmapNum == -1) {
+ delete[] _charmap;
+ _charmap = 0;
+ } else {
+ if (!_charmap)
+ _charmap = new uint32[256];
+
+ in.seek(_charmapStart + charmapNum * 256 * 4, SEEK_SET);
+ for (int i = 0; i < 256; ++i)
+ _charmap[i] = in.readUint32BE();
+ }
+
}
bool TranslationManager::checkHeader(File &in) {
diff --git a/common/translation.h b/common/translation.h
index 71cf2b0981..77e2fdfc07 100644
--- a/common/translation.h
+++ b/common/translation.h
@@ -154,6 +154,21 @@ public:
String getCurrentCharset() const;
/**
+ * Returns a pointer to the current charset mapping. This mapping is a
+ * codepage encoding -> unicode mapping and always 256 entries long.
+ *
+ * The MSB of the individual mapped (i.e. unicode) character states
+ * whether the character is required for this charset. If it is set, the
+ * character needs to be present in order to have the text displayed.
+ * This is used in the font loading code to detect whether the font is
+ * able of supporting this language.
+ *
+ * The return value might be 0 in case it's a default ASCII/ISO-8859-1
+ * map.
+ */
+ const uint32 *getCharsetMapping() const { return _charmap; }
+
+ /**
* Returns currently selected translation language
*/
String getCurrentLanguage() const;
@@ -200,11 +215,15 @@ private:
StringArray _langs;
StringArray _langNames;
+ StringArray _charmaps;
StringArray _messageIds;
Array<PoMessageEntry> _currentTranslationMessages;
String _currentCharset;
int _currentLang;
+
+ uint32 _charmapStart;
+ uint32 *_charmap;
};
} // End of namespace Common