Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] (PR#2559) SDL_ttf font problem
Home

[Freeciv-Dev] (PR#2559) SDL_ttf font problem

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: bernd.korz@xxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#2559) SDL_ttf font problem
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Fri, 31 Jan 2003 00:03:38 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Here is a patch that aims to fix the problem.

I believe this will work for Davide's system.  However I seem to recall
already testing this solution on Bernd's system and it didn't work.  In
that case there's probably a different SDL_ttf bug at work.

Note that this code will still fail if you are using UTF-8.  The code
assumes a 1-1 correspondence between 2-byte UTF-16 and 1-byte
local-encoding blocks.  In utf-8 this isn't the case.

Nonetheless it is still a big step forward.

Davide pointed out that SDL_BIG_ENDIAN and SDL_LIL_ENDIAN are not
defined very well: SDL_Byteorder just has a bunch of #ifdefs checking
for specific systems.  It is easy to add a configure check to do this
(properly) ourselves.  If someone wants to do this, you're welcome to it...

jason

Index: client/gui-sdl/gui_iconv.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/gui_iconv.c,v
retrieving revision 1.3
diff -u -r1.3 gui_iconv.c
--- client/gui-sdl/gui_iconv.c  2003/01/24 21:21:42     1.3
+++ client/gui-sdl/gui_iconv.c  2003/01/31 07:59:04
@@ -30,9 +30,13 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <SDL/SDL_byteorder.h>
 #include <SDL/SDL_types.h>
 #include <iconv.h>
 #include <errno.h>
+#ifdef HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
 
 #include "gui_mem.h"
 #include "unistring.h"
@@ -44,14 +48,21 @@
 Uint16 *convert_to_utf16(const char *pString)
 {
   /* Start Parametrs */
-  const char *pTocode = "UTF-16";
-  const char *pFromcode = LOCAL_CODE;
+#ifdef SDL_LIL_ENDIAN
+  const char *pTocode = "UTF-16LE";
+#else
+  const char *pTocode = "UTF-16BE";
+#endif
+#ifdef HAVE_LANGINFO_CODESET
+  const char *pFromcode = nl_langinfo(CODESET);
+#else
+  const char *pFromcode = "";
+#endif
   const char *pStart = pString;
   const char *pEnd = pString + strlen(pString);
   /* ===== */
 
   char *pResult = NULL;
-  int iIter;
 
   /* From 8 bit code to UTF-16 (16 bit code)
      size_t length = 2*(strlen(pString)+1); */
@@ -72,7 +83,7 @@
   /* Do the conversion for real. */
   {
     const char *pInptr = pStart;
-    size_t Insize = pEnd - pStart;
+    size_t Insize = pEnd - pStart + 1;
 
     char *pOutptr = pResult;
     size_t Outsize = length;
@@ -109,13 +120,6 @@
     }
   }
 
-  /* Bug Corection */
-  for (iIter = 0; iIter < length - 2; iIter++) {
-    pResult[iIter] = pResult[iIter + 2];
-  }
-  pResult[length - 2] = 0;
-  pResult[length - 1] = 0;
-
   iconv_close(cd);
 
   return (Uint16 *) pResult;
@@ -127,14 +131,21 @@
 Uint16 *convertcopy_to_utf16(Uint16 * pToString, const char *pFromString)
 {
   /* Start Parametrs */
-  const char *pTocode = "UTF-16";
-  const char *pFromcode = LOCAL_CODE;
+#ifdef SDL_LIL_ENDIAN
+  const char *pTocode = "UTF-16LE";
+#else
+  const char *pTocode = "UTF-16BE";
+#endif
+#ifdef HAVE_LANGINFO_CODESET
+  const char *pFromcode = nl_langinfo(CODESET);
+#else
+  const char *pFromcode = "";
+#endif
   const char *pStart = pFromString;
   const char *pEnd = pFromString + strlen(pFromString);
   /* ===== */
 
   char *pResult = (char *) pToString;
-  int iIter;
 
   /* From 8 bit code to UTF-16 (16 bit code)
      size_t length = 2*(strlen(pString)+1); */
@@ -157,7 +168,7 @@
   /* Do the conversion for real. */
   {
     const char *pInptr = pStart;
-    size_t Insize = pEnd - pStart;
+    size_t Insize = pEnd - pStart + 1;
 
     char *pOutptr = pResult;
     size_t Outsize = length;
@@ -192,13 +203,6 @@
     }
   }
 
-  /* Bug Corection */
-  for (iIter = 0; iIter < length - 2; iIter++) {
-    pResult[iIter] = pResult[iIter + 2];
-  }
-  pResult[length - 2] = 0;
-  pResult[length - 1] = 0;
-
   iconv_close(cd);
 
   return (Uint16 *) pResult;
@@ -210,8 +214,16 @@
 char *convert_to_chars(const Uint16 * pUniString)
 {
   /* Start Parametrs */
-  const char *pTocode = LOCAL_CODE;
-  const char *pFromcode = "UTF-16";
+#ifdef SDL_LIL_ENDIAN
+  const char *pTocode = "UTF-16LE";
+#else
+  const char *pTocode = "UTF-16BE";
+#endif
+#ifdef HAVE_LANGINFO_CODESET
+  const char *pFromcode = nl_langinfo(CODESET);
+#else
+  const char *pFromcode = "";
+#endif
   const char *pStart = (char *) pUniString;
   const char *pEnd =
       (char *) pUniString + (unistrlen(pUniString) << 1) + 2;
Index: client/gui-sdl/gui_iconv.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/gui_iconv.h,v
retrieving revision 1.1
diff -u -r1.1 gui_iconv.h
--- client/gui-sdl/gui_iconv.h  2002/12/02 08:47:02     1.1
+++ client/gui-sdl/gui_iconv.h  2003/01/31 07:59:04
@@ -26,8 +26,6 @@
 #ifndef FC__GUI_ICONV_H
 #define FC__GUI_ICONV_H
 
-#define LOCAL_CODE "ISO-8859-2"
-
 Uint16 *convert_to_utf16(const char *pString);
 Uint16 *convertcopy_to_utf16(Uint16 *pToString, const char *pFromString);
 char *convert_to_chars(const Uint16 *pUniString);

[Prev in Thread] Current Thread [Next in Thread]