[Freeciv-Dev] Re: (PR#2559) SDL_ttf font problem
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Davide Pagnin via RT wrote:
> On Fri, 2003-01-31 at 09:03, Jason Short via RT wrote:
> I can be wrong, but this won't work.
> AFAIK SDL_Byterorder.h do define both SDL_LIL_ENDIAN and SDL_BIG_ENDIAN,
> and afterwords, it define SDL_BYTEODER as equal to one of those two.
>
> This means that you need to check if SDL_LIL_ENDIAN == SDL_BYTEORDER,
> othewise you will always get UTF-16LE.
Oh, duh. New patch attached.
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 17:29:57
@@ -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;
+#if SDL_BYTEORDER == 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;
+#if SDL_BYTEORDER == 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";
+#if SDL_BYTEORDER == 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 17:29:57
@@ -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);
|
|