From 0e7ccb896dafb69664fb313c63bdb8fbe0ea82d1 Mon Sep 17 00:00:00 2001
From: Eugene Sandulenko
Date: Mon, 28 Jun 2010 15:17:10 +0000
Subject: i18n: Add support for locale-dependent fonts
Currently it ws not decided where to put fonts, but if you put BDF files into
themepath, they will get picked up.
The font name has to contain same codepage specification as in the .po file,
i.e. fixed5x8-iso-8859-5.bdf for Cyrillic codepage. In case the font does not
exist, default will be used.
All built in fonts get proper names.
TODO: Currently there is a bug with our font cacher. Font clR6x12-iso-8859-5
is empty after loading from FCC file. Reason is unknown.
svn-id: r50448
---
common/translation.cpp | 4 +
common/translation.h | 5 +
graphics/fontman.cpp | 28 +-
gui/ThemeEngine.cpp | 39 +-
gui/ThemeEngine.h | 1 +
gui/themes/default.inc | 2108 ++++++++++++++--------------
gui/themes/scummclassic.zip | Bin 56607 -> 57409 bytes
gui/themes/scummclassic/classic_gfx.stx | 20 +-
gui/themes/scummmodern.zip | Bin 163899 -> 158996 bytes
gui/themes/scummmodern/scummmodern_gfx.stx | 20 +-
10 files changed, 1158 insertions(+), 1067 deletions(-)
diff --git a/common/translation.cpp b/common/translation.cpp
index 3c5ff4d3c7..093f26510f 100644
--- a/common/translation.cpp
+++ b/common/translation.cpp
@@ -130,6 +130,10 @@ const char *TranslationManager::getTranslation(const char *message) {
return po2c_gettext(message);
}
+const char *TranslationManager::getCurrentCharset() {
+ return po2c_getcharset();
+}
+
String TranslationManager::getTranslation(const String &message) {
return po2c_gettext(message.c_str());
}
diff --git a/common/translation.h b/common/translation.h
index 0722ae44ae..277ac6f5c4 100644
--- a/common/translation.h
+++ b/common/translation.h
@@ -121,6 +121,11 @@ public:
*/
const TLangArray getSupportedLanguages() const;
+ /**
+ * Returns charset specified by selected translation language
+ */
+ const char *getCurrentCharset();
+
private:
Common::String _syslang;
};
diff --git a/graphics/fontman.cpp b/graphics/fontman.cpp
index 808dbafa1a..c6972cfaab 100644
--- a/graphics/fontman.cpp
+++ b/graphics/fontman.cpp
@@ -57,18 +57,28 @@ FontManager::~FontManager() {
g_consolefont = 0;
}
-const char *builtinFontNames[] = {
- "builtinOSD",
- "builtinConsole",
- "builtinGUI",
- "builtinBigGUI",
- 0
+const struct {
+ const char *name;
+ FontManager::FontUsage id;
+} builtinFontNames[] = {
+ { "builtinOSD", FontManager::kOSDFont },
+ { "builtinConsole", FontManager::kConsoleFont },
+ { "fixed5x8.bdf", FontManager::kConsoleFont },
+ { "fixed5x8-iso-8859-1.bdf", FontManager::kConsoleFont },
+ { "fixed5x8-ascii.bdf", FontManager::kConsoleFont },
+ { "clR6x12.bdf", FontManager::kGUIFont },
+ { "clR6x12-iso-8859-1.bdf", FontManager::kGUIFont },
+ { "clR6x12-ascii.bdf", FontManager::kGUIFont },
+ { "helvB12.bdf", FontManager::kBigGUIFont },
+ { "helvB12-iso-8859-1.bdf", FontManager::kBigGUIFont },
+ { "helvB12-ascii.bdf", FontManager::kBigGUIFont },
+ { 0, FontManager::kOSDFont }
};
const Font *FontManager::getFontByName(const Common::String &name) const {
- for (int i = 0; builtinFontNames[i]; i++)
- if (!strcmp(name.c_str(), builtinFontNames[i]))
- return getFontByUsage((FontUsage)i);
+ for (int i = 0; builtinFontNames[i].name; i++)
+ if (!scumm_stricmp(name.c_str(), builtinFontNames[i].name))
+ return getFontByUsage(builtinFontNames[i].id);
if (!_fontMap.contains(name))
return 0;
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index 8f4f767a94..0691f8351d 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -568,10 +568,17 @@ bool ThemeEngine::addFont(TextData textId, const Common::String &file) {
if (file == "default") {
_texts[textId]->_fontPtr = _font;
} else {
- _texts[textId]->_fontPtr = FontMan.getFontByName(file);
+ Common::String localized = genLocalizedFontFilename(file.c_str());
+ // Try built-in fonts
+ _texts[textId]->_fontPtr = FontMan.getFontByName(localized);
if (!_texts[textId]->_fontPtr) {
- _texts[textId]->_fontPtr = loadFont(file);
+ // First try to load localized font
+ _texts[textId]->_fontPtr = loadFont(localized);
+
+ // Fallback to non-localized font
+ if (!_texts[textId]->_fontPtr)
+ _texts[textId]->_fontPtr = loadFont(file);
if (!_texts[textId]->_fontPtr)
error("Couldn't load font '%s'", file.c_str());
@@ -1495,6 +1502,34 @@ Common::String ThemeEngine::genCacheFilename(const char *filename) {
return Common::String();
}
+Common::String ThemeEngine::genLocalizedFontFilename(const char *filename) {
+#ifndef USE_TRANSLATION
+ return Common::String(filename);
+#else
+
+ Common::String result;
+ bool pointPassed = false;
+
+ for (const char *p = filename; *p != 0; p++) {
+ if (!pointPassed) {
+ if (*p != '.') {
+ result += *p;
+ } else {
+ result += "-";
+ result += TransMan.getCurrentCharset();
+ result += *p;
+
+ pointPassed = true;
+ }
+ } else {
+ result += *p;
+ }
+ }
+
+ return result;
+#endif
+}
+
/**********************************************************
* Static Theme XML functions
diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h
index 5f474f1a88..f0d4e2585d 100644
--- a/gui/ThemeEngine.h
+++ b/gui/ThemeEngine.h
@@ -539,6 +539,7 @@ protected:
const Graphics::Font *loadFont(const Common::String &filename);
const Graphics::Font *loadFontFromArchive(const Common::String &filename);
Common::String genCacheFilename(const char *filename);
+ Common::String genLocalizedFontFilename(const char *filename);
/**
* Actual Dirty Screen handling function.
diff --git a/gui/themes/default.inc b/gui/themes/default.inc
index 9554bdf799..086fecc123 100644
--- a/gui/themes/default.inc
+++ b/gui/themes/default.inc
@@ -1,573 +1,442 @@
""
-" "
-" "
-" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
+" "
-" "
-" "
-" "
+" "
+" "
-" "
-" "
-" "
+" "
-" "
-" "
-" "
-" "
+" "
+" "
+" "
-" "
-" "
+" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
+" "
-" "
-" "
-" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
+" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
-" "
-" "
-" "
+" "
-" "
-" "
-" "
+" "
+" "
+" "
+" "
-" "
-" "
-" "
-" "
+" "
+" "
+" "
+" "
+" "
+" "
" "
-" "
-" "
-" "
-" "
+" "
+" "
+" "
+" "
" "
" "
" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
-" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
" "
" "
+" "
+" "
+" "
" "
" "
" "
" "
" "
" "
" "
" "
" "
" "
" "
-" "
+" "
" "
-" "
+" "
" "
@@ -1282,38 +1299,39 @@
" "
" "
" "
-" "
+" "
" "
" "
" "
" "
" "
-" "
+" "
+" "
" "
" "
" "
" "
" "
" "
" "
-" "
-" "
+" "
+" "
" "
@@ -1321,7 +1339,7 @@
"height='Globals.Line.Height' "
"/> "
" "
-" "
+" "
" "
@@ -1335,10 +1353,10 @@
" "
" "
" "
-" "
+" "
" "
" "
-" "
+" "
" "
" "
" "
" "
-" "
+" "
" "
@@ -1359,7 +1377,7 @@
"type='PopUp' "
"/> "
" "
-" "
+" "
" "
@@ -1377,7 +1395,7 @@
" "
" "
" "
-" "
+" "
" "
@@ -1385,7 +1403,7 @@
"type='PopUp' "
"/> "
" "
-" "
+" "
" "
@@ -1393,7 +1411,7 @@
"type='PopUp' "
"/> "
" "
-" "
+" "
" "
@@ -1401,7 +1419,7 @@
"type='PopUp' "
"/> "
" "
-" "
+" "
" "
@@ -1409,7 +1427,7 @@
"type='PopUp' "
"/> "
" "
-" "
+" "
" "
@@ -1417,7 +1435,7 @@
"type='PopUp' "
"/> "
" "
-" "
+" "
" "
@@ -1431,7 +1449,7 @@
"type='Radiobutton' "
"/> "
" "
-" "
+" "
" "
@@ -1445,8 +1463,9 @@
" "
" "
" "
-" "
-" "
+" "
+" "
+" "
" "
@@ -1457,7 +1476,7 @@
"type='SmallLabel' "
"/> "
" "
-" "
+" "
" "
@@ -1468,7 +1487,7 @@
"type='SmallLabel' "
"/> "
" "
-" "
+" "
" "
@@ -1479,8 +1498,8 @@
"type='SmallLabel' "
"/> "
" "
-" "
-" "
+" "
+" "
" "
@@ -1489,7 +1508,7 @@
" "
" "
" "
-" "
+" "
" "
@@ -1510,7 +1529,7 @@
" "
-" "
+" "
" "
@@ -1526,7 +1545,7 @@
" "
" "
" "
-" "
+" "
" "
@@ -1534,7 +1553,7 @@
"height='Globals.Line.Height' "
"/> "
" "
-" "
+" "
" "
@@ -1542,7 +1561,7 @@
"height='Globals.Line.Height' "
"/> "
" "
-" "
+" "
" "
@@ -1562,7 +1581,7 @@
" "
" "
" "
-" "
+" "
" "
@@ -1570,31 +1589,25 @@
"height='Globals.Line.Height' "
"/> "
" "
-" "
+" "
" "
" "
" "
-" "
+" "
" "
" "
" "
-" "
+" "
" "
" "
" "
" "
-" "
+" "
" "
" "
-" "
+" "
" "
" "
" "
" "
-" "
+" "
" "
@@ -1652,7 +1665,7 @@
" "
" "
" "
-" "
+" "
" "
@@ -1660,7 +1673,7 @@
" "
" "
" "
-" "
+" "
" "
@@ -1668,7 +1681,7 @@
" "
" "
" "
-" "
+" "
" "
@@ -1676,43 +1689,34 @@
" "
" "
" "
-" "
-" "
+" "
+" "
" "
" "
" "
-" "
+" "
" "
" "
" "
-" "
-" "
+" "
" "
" "
" "
-" "
+" "
" "
" "
" "
" "
-" "
-" "
+" "
+" "
" "
@@ -1730,7 +1734,7 @@
"height='Globals.Line.Height' "
"/> "
" "
-" "
+" "
" "
@@ -1738,7 +1742,7 @@
"height='Globals.Line.Height' "
"/> "
" "
-" "
+" "
" "
@@ -1749,55 +1753,57 @@
" "
" "
" "
-" "
+" "
" "
" "
-" "
+" "
+" "
" "
" "
-" "
+" "
" "
" "
" "
-" "
-" "
+" "
" "
" "
" "
" "
" "
" "
-" "
+" "
+" "
+" "
" "
@@ -1808,7 +1814,7 @@
"type='SmallLabel' "
"/> "
" "
-" "
+" "
" "
@@ -1819,7 +1825,7 @@
"type='SmallLabel' "
"/> "
" "
-" "
+" "
" "
@@ -1830,35 +1836,33 @@
"type='SmallLabel' "
"/> "
" "
-" "
-" "
+" "
+" "
" "
" "
-" "
-" "
+" "
+" "
+" "
" "
-" "
" "
" "
" "
" "
-" "
-" "
-" "
+" "
" "
@@ -1869,8 +1873,8 @@
"type='SmallLabel' "
"/> "
" "
-" "
-" "
+" "
+" "
" "
@@ -1885,15 +1889,23 @@
" "
" "
" "
-" "
-" "
+" "
+" "
+" "
" "
-" "
+" "
+" "
+" "
" "
" "
-" "
+" "
" "
@@ -1903,16 +1915,16 @@
" "
" "
" "
-" "
-" "
+" "
+" "
" "
" "
-" "
+" "
" "
@@ -1927,20 +1939,20 @@
" "
" "
" "
-" "
+" "
" "
" "
" "
-" "
+" "
" "
@@ -1951,20 +1963,20 @@
" "
" "
" "
-" "
+" "
" "
" "
" "
" "
" "
"
+
+
+
+
+
+