[Scummvm-cvs-logs] SF.net SVN: scummvm:[48682] tools/branches/branch-1-1-0

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sat Apr 17 04:54:14 CEST 2010


Revision: 48682
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48682&view=rev
Author:   lordhoto
Date:     2010-04-17 02:54:14 +0000 (Sat, 17 Apr 2010)

Log Message:
-----------
Backport endian fix(es) r48680+r48681 for create_sjisfnt.

Modified Paths:
--------------
    tools/branches/branch-1-1-0/NEWS
    tools/branches/branch-1-1-0/create_sjisfnt.cpp

Modified: tools/branches/branch-1-1-0/NEWS
===================================================================
--- tools/branches/branch-1-1-0/NEWS	2010-04-17 02:50:35 UTC (rev 48681)
+++ tools/branches/branch-1-1-0/NEWS	2010-04-17 02:54:14 UTC (rev 48682)
@@ -7,4 +7,5 @@
  - Fix bug #2905473: "GUI Tools: cannot use lame with compress_scumm_sou"
  - Patch #2982306: "set MP3 ABR bit rate in GUI Tools"
  - Patch #2982090: "Tools: include unistd.h for unlink"
- - Patch #2982091: "Tools: use $(INSTALL) instead of install".
\ No newline at end of file
+ - Patch #2982091: "Tools: use $(INSTALL) instead of install".
+ - Fix endian problem in create_sjisfnt

Modified: tools/branches/branch-1-1-0/create_sjisfnt.cpp
===================================================================
--- tools/branches/branch-1-1-0/create_sjisfnt.cpp	2010-04-17 02:50:35 UTC (rev 48681)
+++ tools/branches/branch-1-1-0/create_sjisfnt.cpp	2010-04-17 02:54:14 UTC (rev 48682)
@@ -28,6 +28,7 @@
 #include <iconv.h>
 #include <list>
 #include <assert.h>
+#include <errno.h>
 
 #include "common/endian.h"
 #include "common/file.h"
@@ -300,9 +301,9 @@
 iconv_t confSetup = (iconv_t)-1;
 
 bool initSJIStoUTF32Conversion() {
-	// We initialize a SJIS to native endian UTF-32 conversion
+	// We initialize a SJIS to little endian UTF-32 conversion
 	// over here.
-	confSetup = iconv_open("UTF-32", "SJIS");
+	confSetup = iconv_open("UTF-32LE", "SJIS");
 	return (confSetup != (iconv_t)-1);
 }
 
@@ -333,7 +334,7 @@
 	char outBuf[3 * sizeof(uint32)];
 	memset(outBuf, 0, sizeof(outBuf));
 
-	size_t inBufSize = sizeof(inBuf);
+	size_t inBufSize = ((fB >= 0x81 && fB <= 0x9F) || (fB >= 0xE0 && fB <= 0xEF)) ? 3 : 2;
 	size_t outBufSize = sizeof(outBuf);
 #ifdef ICONV_USES_CONST
 	const char *inBufWrap = inBuf;
@@ -345,14 +346,16 @@
 	if (iconv(confSetup, &inBufWrap, &inBufSize, &outBufWrap, &outBufSize) == (size_t)-1)
 		return (uint32)-1;
 
-	uint32 ret = *(uint32 *)outBuf;
+	const uint32 ret = READ_LE_UINT32(outBuf);
 
-	// It might happen that iconv will add a "ZERO WIDTH NO-BREAK SPACE"
-	// before a character, we filter that out over here.
+	// According to http://www.unicode.org/reports/tr19/tr19-9.html it is possible
+	// that a "zero width no-break space" is added as first character (probably
+	// to be consistent with the "byte order mark"). In case any iconv implementation
+	// does that, we just skip over that bit.
 	if (ret == 0x0000FEFF)
-		ret = *(uint32 *)(outBuf + 4);
-
-	return ret;
+		return READ_LE_UINT32(outBuf + 4);
+	else
+		return ret;
 }
 
 FT_Library ft = NULL;
@@ -414,7 +417,8 @@
 		// It might be useful to enable that warning again to detect problems with
 		// iconv though. An example for such an iconv problem is the
 		// "FULLWIDTH APOSTROPHE", which iconv refuses to convert to UTF-32.
-		//warning("Conversion error on: %.2X %.02X", fB, sB);
+		if (errno == E2BIG || errno == EINVAL)
+			warning("Conversion error on: %.2X %.02X", fB, sB);
 		return false;
 	}
 


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