Mercurial > public > ostc4
diff Discovery/Src/gfx_engine.c @ 58:e97deb6e2705
Added UTF8 decode function
author | Ideenmodellierer |
---|---|
date | Thu, 09 Aug 2018 22:39:15 +0200 |
parents | 5f11787b4f42 |
children | cc8e24374b83 |
line wrap: on
line diff
--- a/Discovery/Src/gfx_engine.c Thu Aug 09 22:38:56 2018 +0200 +++ b/Discovery/Src/gfx_engine.c Thu Aug 09 22:39:15 2018 +0200 @@ -2257,6 +2257,7 @@ uint8_t i, j; uint32_t found; uint32_t pText; + uint16_t decodeUTF8; uint8_t gfx_selected_language; #ifndef BOOTLOADER_STANDALONE SSettings *pSettings; @@ -2265,8 +2266,10 @@ if(gfx_selected_language >= LANGUAGE_END) #endif gfx_selected_language = 0; + + // ----------------------------- - if(textId != (uint8_t)TXT_2BYTE) + if(textId != (uint8_t)TXT_2BYTE) { found = 0; j = 0; @@ -2281,6 +2284,7 @@ } if(!found) return cfg->Xdelta; + // ----------------------------- pText = (uint32_t)text_array[j].text[gfx_selected_language]; if(!pText) @@ -2327,6 +2331,17 @@ if(*(char*)pText == ' ') cfg->Xdelta += ((tFont *)cfg->actualFont)->spacesize; else + if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */ + { + decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */ + pText++; + decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */ + if (decodeUTF8 <= 0xff) /* The following function has a uint8 input parameter ==> no UNICODEs > 0xff supported */ + { + cfg->Xdelta = GFX_write_char(hgfx, cfg, (uint8_t)decodeUTF8, (tFont *)cfg->actualFont); + } + } + else cfg->Xdelta = GFX_write_char(hgfx, cfg, *(uint8_t *)pText, (tFont *)cfg->actualFont); pText++; @@ -3130,6 +3145,7 @@ uint32_t i, j; uint8_t gfx_selected_language; uint32_t pText; + uint16_t decodeUTF8; #ifndef BOOTLOADER_STANDALONE SSettings *pSettings; @@ -3147,9 +3163,20 @@ j = 0; while (*(char*)pText != 0)// und fehlend: Abfrage window / image size { + if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */ + { + decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */ + pText++; + decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */ + } + else + { + decodeUTF8 = *(char*)pText; /* place ASCII char */ + } + for(i=0;i<((tFont *)cfg->font)->length;i++) { - if(((tFont *)cfg->font)->chars[i].code == *(char*)pText) + if(((tFont *)cfg->font)->chars[i].code == decodeUTF8) { Xsum += ((tFont *)cfg->font)->chars[i].image->width; break; @@ -3190,6 +3217,7 @@ uint8_t gfx_selected_language; uint32_t pText; uint8_t setToTinyFont = 0; + uint16_t decodeUTF8; #ifndef BOOTLOADER_STANDALONE SSettings *pSettings; @@ -3236,9 +3264,19 @@ } else { + if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */ + { + decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */ + pText++; + decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */ + } + else + { + decodeUTF8 = *(char*)pText; + } for(i=0;i<font->length;i++) { - if(font->chars[i].code == *(char*)pText) + if(font->chars[i].code == decodeUTF8) { Xsum += font->chars[i].image->width; break;