]> git.webhop.me Git - input.git/commitdiff
- input: add utf8_to_latin1 encoding
authorbazi98 <bazi98@web.de>
Tue, 7 Oct 2014 09:16:19 +0000 (11:16 +0200)
committersvenhoefer <svenhoefer@svenhoefer.com>
Tue, 7 Oct 2014 09:16:19 +0000 (11:16 +0200)
Original patch from GetAway <get-away@t-online.de> for tuxbox

input.c
text.c

diff --git a/input.c b/input.c
index 54920f1950c9c12852dccb7f3c8c2d8e6877ac12..961fbcc2d23c162840a316f916ca44c0306aae34 100644 (file)
--- 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 92d2473bea137f379e5b436effef63aa5c52dbde..8c9aaf1f74eaf955eb77579ae7ba53e3b87f72d4 100644 (file)
--- 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;
                        }