From 022857a3711cef9b3ae60a88c436c212792918f0 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 2 Nov 2011 22:08:56 +0000 Subject: COMMON: Fix warning --- common/translation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/translation.cpp') diff --git a/common/translation.cpp b/common/translation.cpp index 3570e8c5ae..e0386a29ef 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -390,7 +390,7 @@ bool TranslationManager::checkHeader(File &in) { buf[12] = '\0'; // Check header - if (strcmp(buf, "TRANSLATIONS")) { + if (strcmp(buf, "TRANSLATIONS") != 0) { warning("File '%s' is not a valid translations data file. Skipping this file", in.getName()); return false; } -- cgit v1.2.3 From 3ddea4952d2aec5ef61d0ae8762266edb9ceb02e Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 13 Nov 2011 01:43:41 +0100 Subject: COMMON: Some minor formatting fixes in translation code. Done by running astyle over the files. --- common/translation.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'common/translation.cpp') diff --git a/common/translation.cpp b/common/translation.cpp index e0386a29ef..081bde987d 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -130,14 +130,14 @@ const char *TranslationManager::getTranslation(const char *message, const char * // Get the range of messages with the same ID (but different context) leftIndex = rightIndex = midIndex; while ( - leftIndex > 0 && - _currentTranslationMessages[leftIndex - 1].msgid == m->msgid + leftIndex > 0 && + _currentTranslationMessages[leftIndex - 1].msgid == m->msgid ) { --leftIndex; } while ( - rightIndex < (int)_currentTranslationMessages.size() - 1 && - _currentTranslationMessages[rightIndex + 1].msgid == m->msgid + rightIndex < (int)_currentTranslationMessages.size() - 1 && + _currentTranslationMessages[rightIndex + 1].msgid == m->msgid ) { ++rightIndex; } @@ -222,7 +222,7 @@ String TranslationManager::getLangById(int id) const { return ""; } -bool TranslationManager::openTranslationsFile(File& inFile) { +bool TranslationManager::openTranslationsFile(File &inFile) { // First look in the Themepath if we can find the file. if (ConfMan.hasKey("themepath") && openTranslationsFile(FSNode(ConfMan.get("themepath")), inFile)) return true; @@ -242,7 +242,7 @@ bool TranslationManager::openTranslationsFile(File& inFile) { return false; } -bool TranslationManager::openTranslationsFile(const FSNode &node, File& inFile, int depth) { +bool TranslationManager::openTranslationsFile(const FSNode &node, File &inFile, int depth) { if (!node.exists() || !node.isReadable() || !node.isDirectory()) return false; -- cgit v1.2.3 From f63df3bf7b95ddd9eaa4f55c4f21f53f3bd00f68 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 9 Jan 2012 03:33:59 +0100 Subject: 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. --- common/translation.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'common/translation.cpp') 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) { -- cgit v1.2.3