From cecd615627d64f6641662fb4ad8c521378d41d96 Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Mon, 22 Sep 2014 16:27:55 +0200 Subject: [PATCH] msgbox: add utf8_to_latin1 encoding inspired from Neutrino/Zapittools ;) - by GetAway -ported fom tuxbox by bazi98 --- gfx.c | 2 +- msgbox.c | 5 +++-- text.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/gfx.c b/gfx.c index f724b0a..d49bb90 100644 --- a/gfx.c +++ b/gfx.c @@ -10,7 +10,7 @@ void RenderBox(int _sx, int _sy, int _ex, int _ey, int rad, int col) if (dxx<0) { - printf("[shellexec] RenderBox called with dx < 0 (%d)\n", dxx); + printf("[msgbox] RenderBox called with dx < 0 (%d)\n", dxx); dxx=0; } diff --git a/msgbox.c b/msgbox.c index 2543b3a..b42a22f 100644 --- a/msgbox.c +++ b/msgbox.c @@ -8,7 +8,7 @@ #include "gfx.h" #include "txtform.h" -#define M_VERSION 1.12 +#define M_VERSION 1.18 #define NCF_FILE "/var/tuxbox/config/neutrino.conf" #define HDF_FILE "/tmp/.msgbox_hidden" @@ -216,7 +216,8 @@ char *pt1=strdup(sptr),*pt2,*pt3; } static int yo=80,dy; -static int psx, psy, pxw, pyw, myo=0, buttx=80, butty=30, buttdx=20, buttdy=10, buttsize=0, buttxstart=0, buttystart=0; +int psx; +static int psy, pxw, pyw, myo=0, buttx=80, butty=30, buttdx=20, buttdy=10, buttsize=0, buttxstart=0, buttystart=0; int show_txt(int buttonly) { diff --git a/text.c b/text.c index 6a64b6f..5d96ae5 100644 --- a/text.c +++ b/text.c @@ -184,7 +184,7 @@ void CatchTabs(char *text) /****************************************************************************** * RenderString ******************************************************************************/ - +extern int psx; int RenderString(char *string, int _sx, int _sy, int maxwidth, int layout, int size, int color) { int stringlen = 0, _ex = 0, charwidth = 0,found = 0; @@ -256,6 +256,7 @@ int RenderString(char *string, int _sx, int _sy, int maxwidth, int layout, int s if(sscanf(rptr+1,"%4d",&i)==1) { rptr+=4; + sx = psx + 10 + i; _sx=i; } break; @@ -264,7 +265,51 @@ int RenderString(char *string, int _sx, int _sy, int maxwidth, int layout, int s } else { - if((charwidth = RenderChar(*rptr, _sx, _sy, _ex, varcolor)) == -1) return _sx; /* string > maxwidth */ + 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; } rptr++; -- 2.39.5