[Scummvm-cvs-logs] SF.net SVN: scummvm:[41720] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sun Jun 21 03:15:24 CEST 2009


Revision: 41720
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41720&view=rev
Author:   lordhoto
Date:     2009-06-21 01:15:24 +0000 (Sun, 21 Jun 2009)

Log Message:
-----------
Moved CP850<->ISO-8859-1 conversion to Util.

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/gui_lol.cpp
    scummvm/trunk/engines/kyra/lol.h
    scummvm/trunk/engines/kyra/staticres.cpp
    scummvm/trunk/engines/kyra/util.cpp
    scummvm/trunk/engines/kyra/util.h

Modified: scummvm/trunk/engines/kyra/gui_lol.cpp
===================================================================
--- scummvm/trunk/engines/kyra/gui_lol.cpp	2009-06-21 01:15:09 UTC (rev 41719)
+++ scummvm/trunk/engines/kyra/gui_lol.cpp	2009-06-21 01:15:24 UTC (rev 41720)
@@ -29,6 +29,7 @@
 #include "kyra/screen_lol.h"
 #include "kyra/gui_lol.h"
 #include "kyra/resource.h"
+#include "kyra/util.h"
 
 #include "common/savefile.h"
 #include "graphics/scaler.h"
@@ -2408,14 +2409,7 @@
 			strncpy(s, header.description.c_str(), 80);
 			s[79] = 0;
 
-			for (uint32 ii = 0; ii < strlen(s); ii++) {
-				for (int iii = 0; iii < _vm->_fontConversionTableSize; iii += 2) {
-					if ((uint8)s[ii] == _vm->_fontConversionTable[iii]) {
-						s[ii] = (uint8)_vm->_fontConversionTable[iii + 1];
-						break;
-					}
-				}
-			}
+			Util::convertISOToDOS(s);
 
 			menu.item[i].itemString = s;
 			s += (strlen(s) + 1);
@@ -2468,16 +2462,12 @@
 	int inputFlag = _vm->checkInput(_menuButtonList);
 
 	if (_currentMenu == &_savenameMenu && _keyPressed.ascii){
-		for (int i = 0; i < _vm->_fontConversionTableSize; i += 2) {
-			if (_keyPressed.ascii == _vm->_fontConversionTable[i]) {
-				_keyPressed.ascii = _vm->_fontConversionTable[i + 1];
-				break;
-			}
-		}
+		char inputKey = _keyPressed.ascii;
+		Util::convertISOToDOS(inputKey);
 
-		if (_keyPressed.ascii > 31 && _keyPressed.ascii < 226) {
+		if ((uint8)inputKey > 31 && (uint8)inputKey < 226) {
 			_saveDescription[strlen(_saveDescription) + 1] = 0;
-			_saveDescription[strlen(_saveDescription)] = _keyPressed.ascii;
+			_saveDescription[strlen(_saveDescription)] = inputKey;
 			inputFlag |= 0x8000;
 		} else if (_keyPressed.keycode == Common::KEYCODE_BACKSPACE && strlen(_saveDescription)) {
 			_saveDescription[strlen(_saveDescription) - 1] = 0;
@@ -2631,15 +2621,8 @@
 int GUI_LoL::clickedSavenameMenu(Button *button) {
 	updateMenuButton(button);
 	if (button->arg == _savenameMenu.item[0].itemId) {
-		for (uint32 i = 0; i < strlen(_saveDescription); i++) {
-			for (int ii = 0; ii < _vm->_fontConversionTableSize; ii += 2) {
-				if ((uint8)_saveDescription[i] == _vm->_fontConversionTable[ii + 1]) {
-					_saveDescription[i] = (char)_vm->_fontConversionTable[ii];
-					break;
-				}
-			}
-		}
-		
+		Util::convertDOSToISO(_saveDescription);
+
 		int slot = _menuResult == -2 ? getNextSavegameSlot() : _menuResult;
 		Graphics::Surface thumb;
 		createScreenThumbnail(thumb);

Modified: scummvm/trunk/engines/kyra/lol.h
===================================================================
--- scummvm/trunk/engines/kyra/lol.h	2009-06-21 01:15:09 UTC (rev 41719)
+++ scummvm/trunk/engines/kyra/lol.h	2009-06-21 01:15:24 UTC (rev 41720)
@@ -853,11 +853,6 @@
 
 	static const char * const _languageExt[];
 
-	// TODO: Rethink of a proper way for conversion, currently our GUI charset isn't defined
-	// properly, thus this might not work on every system.
-	static const uint8 _fontConversionTable[];
-	static const int _fontConversionTableSize;
-
 	// graphics
 	void setupScreenDims();
 	void initSceneWindowDialogue(int controlMode);

Modified: scummvm/trunk/engines/kyra/staticres.cpp
===================================================================
--- scummvm/trunk/engines/kyra/staticres.cpp	2009-06-21 01:15:09 UTC (rev 41719)
+++ scummvm/trunk/engines/kyra/staticres.cpp	2009-06-21 01:15:24 UTC (rev 41720)
@@ -3323,21 +3323,6 @@
 	0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100, 0x100
 };
 
-const uint8 LoLEngine::_fontConversionTable[] = {
-	(const uint8)'\xC4', 0x8e, (const uint8)'\xE4', 0x84, (const uint8)'\xD6', 0x99,
-	(const uint8)'\xF6', 0x94, (const uint8)'\xDC', 0x9a, (const uint8)'\xFC', 0x81,
-	(const uint8)'\xDF', 0xe1, (const uint8)'\xC9', 0x90, (const uint8)'\xE9', 0x82,
-	(const uint8)'\xE8', 0x8a, (const uint8)'\xEA', 0x88, (const uint8)'\xE0', 0x85,
-	(const uint8)'\xE2', 0x83, (const uint8)'\xF4', 0x93,	(const uint8)'\xC7', 0x80,
-	(const uint8)'\xE7', 0x87, (const uint8)'\xEB', 0x89, (const uint8)'\xE5', 0x86,
-	(const uint8)'\xEF', 0x8b, (const uint8)'\xEE', 0x8c, (const uint8)'\xEC', 0x8d,
-	(const uint8)'\xC5', 0x8f, (const uint8)'\xE6', 0x91, (const uint8)'\xC6', 0x92,
-	(const uint8)'\xF2', 0x95, (const uint8)'\xFB', 0x96, (const uint8)'\xF9', 0x97,
-	(const uint8)'\xE1', 0xa0
-};
-
-const int LoLEngine::_fontConversionTableSize = ARRAYSIZE(LoLEngine::_fontConversionTable);
-
 #endif // ENABLE_LOL
 
 } // End of namespace Kyra

Modified: scummvm/trunk/engines/kyra/util.cpp
===================================================================
--- scummvm/trunk/engines/kyra/util.cpp	2009-06-21 01:15:09 UTC (rev 41719)
+++ scummvm/trunk/engines/kyra/util.cpp	2009-06-21 01:15:24 UTC (rev 41720)
@@ -85,5 +85,68 @@
 	*dst = 0;
 }
 
+void Util::convertDOSToISO(char *str) {
+	uint8 *s = (uint8 *)str;
+
+	for (; *s; ++s) {
+		if (*s >= 128) {
+			uint8 c = _charMapDOSToISO[*s - 128];
+
+			if (!c)
+				c = 0x20;
+
+			*s = c;
+		}
+	}
+}
+
+void Util::convertISOToDOS(char *str) {
+	while (*str)
+		convertISOToDOS(*str++);
+}
+
+void Util::convertISOToDOS(char &c) {
+	uint8 code = (uint8)c;
+	if (code >= 128) {
+		code = _charMapISOToDOS[code - 128];
+		if (!code)
+			code = 0x20;
+	}
+
+	c = code;
+}
+
+// CP850 to ISO-8859-1 (borrowed from engines/saga/font_map.cpp)
+const uint8 Util::_charMapDOSToISO[128] = {
+	199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232,
+	239, 238, 236, 196, 197, 201, 230, 198, 244, 246, 242,
+	251, 249, 255, 214, 220, 248, 163, 216, 215,   0, 225,
+	237, 243, 250, 241, 209, 170, 186, 191, 174, 172, 189,
+	188, 161, 171, 187,   0,   0,   0,   0,   0, 193, 194,
+	192, 169,   0,   0,   0,   0, 162, 165,   0,   0,   0,
+	  0,   0,   0,   0, 227, 195,   0,   0,   0,   0,   0,
+	  0,   0, 164, 240, 208, 202, 203, 200,   0, 205, 206,
+	207,   0,   0,   0,   0, 166, 204,   0, 211, 223, 212,
+	210, 245, 213, 181, 254, 222, 218, 219, 217, 253, 221,
+	175, 180, 173, 177,   0, 190, 182, 167, 247, 184, 176,
+	168, 183, 185, 179, 178,   0, 160
+};
+
+// ISO-8859-1 to CP850
+const uint8 Util::_charMapISOToDOS[128] = {
+	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 255,
+	173, 189, 156, 207, 190, 221, 245, 249, 184, 166, 174,
+	170, 240, 169, 238, 248, 241, 253, 252, 239, 230, 244,
+	250, 247, 251, 167, 175, 172, 171, 243, 168, 183, 181,
+	182, 199, 142, 143, 146, 128, 212, 144, 210, 211, 222,
+	214, 215, 216, 209, 165, 227, 224, 226, 229, 153, 158,
+	157, 235, 233, 234, 154, 237, 232, 225, 133, 160, 131,
+	198, 132, 134, 145, 135, 138, 130, 136, 137, 141, 161,
+	140, 139, 208, 164, 149, 162, 147, 228, 148, 246, 155,
+	151, 163, 150, 129, 236, 231, 152
+};
+
 } // end of namespace Kyra
 

Modified: scummvm/trunk/engines/kyra/util.h
===================================================================
--- scummvm/trunk/engines/kyra/util.h	2009-06-21 01:15:09 UTC (rev 41719)
+++ scummvm/trunk/engines/kyra/util.h	2009-06-21 01:15:24 UTC (rev 41720)
@@ -34,6 +34,16 @@
 public:
 	static int decodeString1(const char *src, char *dst);
 	static void decodeString2(const char *src, char *dst);
+
+	// Since our current GUI font uses ISO-8859-1, this
+	// conversion functionallty uses that as a base.
+	static void convertDOSToISO(char *str);
+	static void convertISOToDOS(char *str);
+	static void convertISOToDOS(char &c);
+
+private:
+	static const uint8 _charMapDOSToISO[128];
+	static const uint8 _charMapISOToDOS[128];
 };
 
 } // end of namespace Kyra


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list