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

[Freeciv-Dev] Re: (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] Re: (PR#2559) SDL_ttf font problem
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 2 Feb 2003 17:47:47 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Davide Pagnin via RT wrote:
> This should do the trick...

Here's an updated version.  The only change is that I've added new 
functions, get_display_encoding and get_local_encoding, to avoid 
duplicating all the checks.

Remember that charset.m4 is removed and locale.m4 is added.

jason

#serial AM1
dnl From Bruno Haible.

AC_DEFUN([AM_LANGINFO_CODESET],
[
  AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset,
    [AC_TRY_LINK([#include <langinfo.h>],
      [char* cs = nl_langinfo(CODESET);],
      am_cv_langinfo_codeset=yes,
      am_cv_langinfo_codeset=no)
    ])
  if test $am_cv_langinfo_codeset = yes; then
    AC_DEFINE(HAVE_LANGINFO_CODESET, 1,
      [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
  fi
])

AC_DEFUN([AM_LIBCHARSET],
[
  AC_CACHE_CHECK([for libcharset], am_cv_libcharset,
    [lc_save_LIBS="$LIBS"
     LIBS="$LIBS $LIBICONV"
     AC_TRY_LINK([#include <libcharset.h>],
      [locale_charset()],
      am_cv_libcharset=yes,
      am_cv_libcharset=no) 
      LIBS="$lc_save_LIBS" 
    ])
  if test $am_cv_libcharset = yes; then
    AC_DEFINE(HAVE_LIBCHARSET, 1,
      [Define if you have <libcharset.h> and locale_charset().])
  fi
])
Index: Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/Makefile.am,v
retrieving revision 1.29
diff -u -r1.29 Makefile.am
--- Makefile.am 2003/01/16 22:14:13     1.29
+++ Makefile.am 2003/02/03 01:43:02
@@ -65,7 +65,7 @@
                debian/rules                    \
                debian/watch                    \
                m4/ac_path_lib.m4               \
-               m4/codeset.m4                   \
+               m4/locale.m4                    \
                m4/debug.m4                     \
                m4/esd.m4                       \
                m4/gettext.m4                   \
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/02/03 01:43:02
@@ -30,28 +30,65 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <SDL/SDL_byteorder.h>
 #include <SDL/SDL_types.h>
 #include <iconv.h>
 #include <errno.h>
+#ifdef HAVE_LIBCHARSET
+#include <libcharset.h>
+#else
+#ifdef HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
+#endif
 
 #include "gui_mem.h"
 #include "unistring.h"
 #include "gui_iconv.h"
 
 /**************************************************************************
+  Return the display charset encoding (which is always a variant of
+  UTF-16, but must be adjusted for byteorder since SDL_ttf is not
+  byteorder-clean).
+**************************************************************************/
+static const char *get_display_encoding(void)
+{
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+  return "UTF-16LE";
+#else
+  return "UTF-16BE";
+#endif
+}
+
+/**************************************************************************
+  Return the local charset encoding (which will be passed to iconv).
+**************************************************************************/
+static const char *get_local_encoding(void)
+{
+#ifdef HAVE_LIBCHARSET
+  return locale_charset();
+#else
+#  ifdef HAVE_LANGINFO_CODESET
+  return nl_langinfo(CODESET);
+#  else
+  return "";
+#  endif
+#endif
+}
+
+/**************************************************************************
   ...
 **************************************************************************/
 Uint16 *convert_to_utf16(const char *pString)
 {
   /* Start Parametrs */
-  const char *pTocode = "UTF-16";
-  const char *pFromcode = LOCAL_CODE;
+  const char *pTocode = get_display_encoding();
+  const char *pFromcode = get_local_encoding();
   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 +109,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 +146,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 +157,13 @@
 Uint16 *convertcopy_to_utf16(Uint16 * pToString, const char *pFromString)
 {
   /* Start Parametrs */
-  const char *pTocode = "UTF-16";
-  const char *pFromcode = LOCAL_CODE;
+  const char *pTocode = get_display_encoding();
+  const char *pFromcode = get_local_encoding();
   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 +186,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 +221,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 +232,8 @@
 char *convert_to_chars(const Uint16 * pUniString)
 {
   /* Start Parametrs */
-  const char *pTocode = LOCAL_CODE;
-  const char *pFromcode = "UTF-16";
+  const char *pFromcode = get_display_encoding();
+  const char *pTocode = get_local_encoding();
   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/02/03 01:43:02
@@ -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);
Index: m4/codeset.m4
===================================================================
RCS file: /home/freeciv/CVS/freeciv/m4/codeset.m4,v
retrieving revision 1.1
diff -u -r1.1 codeset.m4
--- m4/codeset.m4       2002/08/11 16:07:56     1.1
+++ m4/codeset.m4       2003/02/03 01:43:04
@@ -1,16 +0,0 @@
-#serial AM1
-dnl From Bruno Haible.
-
-AC_DEFUN([AM_LANGINFO_CODESET],
-[
-  AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset,
-    [AC_TRY_LINK([#include <langinfo.h>],
-      [char* cs = nl_langinfo(CODESET);],
-      am_cv_langinfo_codeset=yes,
-      am_cv_langinfo_codeset=no)
-    ])
-  if test $am_cv_langinfo_codeset = yes; then
-    AC_DEFINE(HAVE_LANGINFO_CODESET, 1,
-      [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
-  fi
-])
Index: m4/sdl-client.m4
===================================================================
RCS file: /home/freeciv/CVS/freeciv/m4/sdl-client.m4,v
retrieving revision 1.3
diff -u -r1.3 sdl-client.m4
--- m4/sdl-client.m4    2002/12/14 10:26:43     1.3
+++ m4/sdl-client.m4    2003/02/03 01:43:04
@@ -53,6 +53,8 @@
       dnl Check for libiconv (which is usually included in glibc, but may
       dnl be distributed separately).
       AM_ICONV
+      AM_LIBCHARSET
+      AM_LANGINFO_CODESET
 
       dnl Check for some other libraries - needed under BeOS for instance.
       dnl These should perhaps be checked for in all cases?

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