From 41e005dd21aea91209f61a560bf5956d23f56601 Mon Sep 17 00:00:00 2001 From: bazi98 Date: Tue, 7 Oct 2014 11:16:19 +0200 Subject: [PATCH] - input: add utf8_to_latin1 encoding Original patch from GetAway for tuxbox --- input.c | 2 +- text.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/input.c b/input.c index 54920f1..961fbcc 100644 --- a/input.c +++ b/input.c @@ -10,7 +10,7 @@ #define NCF_FILE "/var/tuxbox/config/neutrino.conf" #define BUFSIZE 1024 -#define I_VERSION 1.08 +#define I_VERSION 1.09 //#define FONT "/usr/share/fonts/md_khmurabi_10.ttf" #define FONT2 "/share/fonts/pakenham.ttf" diff --git a/text.c b/text.c index 92d2473..8c9aaf1 100644 --- a/text.c +++ b/text.c @@ -154,8 +154,8 @@ void CatchTabs(char *text) int RenderString(char *string, int sx, int sy, int maxwidth, int layout, int size, int color) { - int stringlen, ex, charwidth,i,found; - char rstr[BUFSIZE], *rptr=rstr, rc; + int stringlen = 0, ex = 0, charwidth = 0, i = 0, found = 0; + char rstr[BUFSIZE]={0}, *rptr=rstr, rc=' '; int varcolor=color; //set size @@ -237,6 +237,50 @@ int RenderString(char *string, int sx, int sy, int maxwidth, int layout, int siz } else { + int uml = 0; + switch(*rptr) /* skip Umlauts */ + { + case '\xc4': + case '\xd6': + case '\xdc': + case '\xe4': + case '\xf6': + case '\xfc': + case '\xdf': uml=1; break; + } + if (uml == 0) + { + // UTF8_to_Latin1 encoding + if (((*rptr) & 0xf0) == 0xf0) /* skip (can't be encoded in Latin1) */ + { + rptr++; + if ((*rptr) == 0) + *rptr='\x3f'; // ? question mark + rptr++; + if ((*rptr) == 0) + *rptr='\x3f'; + rptr++; + if ((*rptr) == 0) + *rptr='\x3f'; + } + else if (((*rptr) & 0xe0) == 0xe0) /* skip (can't be encoded in Latin1) */ + { + rptr++; + if ((*rptr) == 0) + *rptr='\x3f'; + rptr++; + if ((*rptr) == 0) + *rptr='\x3f'; + } + else if (((*rptr) & 0xc0) == 0xc0) + { + char c = (((*rptr) & 3) << 6); + rptr++; + if ((*rptr) == 0) + *rptr='\x3f'; + *rptr = (c | ((*rptr) & 0x3f)); + } + } if((charwidth = RenderChar(*rptr, sx, sy, ex, varcolor)) == -1) return sx; /* string > maxwidth */ sx += charwidth; } -- 2.39.5