comparison 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
comparison
equal deleted inserted replaced
57:e941c9e49f73 58:e97deb6e2705
2255 static uint32_t GFX_write_substring(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, uint8_t textId, int8_t nextCharFor2Byte) 2255 static uint32_t GFX_write_substring(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, uint8_t textId, int8_t nextCharFor2Byte)
2256 { 2256 {
2257 uint8_t i, j; 2257 uint8_t i, j;
2258 uint32_t found; 2258 uint32_t found;
2259 uint32_t pText; 2259 uint32_t pText;
2260 uint16_t decodeUTF8;
2260 uint8_t gfx_selected_language; 2261 uint8_t gfx_selected_language;
2261 #ifndef BOOTLOADER_STANDALONE 2262 #ifndef BOOTLOADER_STANDALONE
2262 SSettings *pSettings; 2263 SSettings *pSettings;
2263 pSettings = settingsGetPointer(); 2264 pSettings = settingsGetPointer();
2264 gfx_selected_language = pSettings->selected_language; 2265 gfx_selected_language = pSettings->selected_language;
2265 if(gfx_selected_language >= LANGUAGE_END) 2266 if(gfx_selected_language >= LANGUAGE_END)
2266 #endif 2267 #endif
2267 gfx_selected_language = 0; 2268 gfx_selected_language = 0;
2269
2270
2268 // ----------------------------- 2271 // -----------------------------
2269 if(textId != (uint8_t)TXT_2BYTE) 2272 if(textId != (uint8_t)TXT_2BYTE)
2270 { 2273 {
2271 found = 0; 2274 found = 0;
2272 j = 0; 2275 j = 0;
2273 for(i=(uint8_t)TXT_Language;i<(uint8_t)TXT_END;i++) 2276 for(i=(uint8_t)TXT_Language;i<(uint8_t)TXT_END;i++)
2274 { 2277 {
2279 } 2282 }
2280 j++; 2283 j++;
2281 } 2284 }
2282 if(!found) 2285 if(!found)
2283 return cfg->Xdelta; 2286 return cfg->Xdelta;
2287
2284 // ----------------------------- 2288 // -----------------------------
2285 pText = (uint32_t)text_array[j].text[gfx_selected_language]; 2289 pText = (uint32_t)text_array[j].text[gfx_selected_language];
2286 if(!pText) 2290 if(!pText)
2287 pText = (uint32_t)text_array[j].text[0]; 2291 pText = (uint32_t)text_array[j].text[0];
2288 else 2292 else
2324 if(*(char*)pText == '\t') 2328 if(*(char*)pText == '\t')
2325 cfg->Xdelta = hgfx->WindowTab - hgfx->WindowX0; 2329 cfg->Xdelta = hgfx->WindowTab - hgfx->WindowX0;
2326 else 2330 else
2327 if(*(char*)pText == ' ') 2331 if(*(char*)pText == ' ')
2328 cfg->Xdelta += ((tFont *)cfg->actualFont)->spacesize; 2332 cfg->Xdelta += ((tFont *)cfg->actualFont)->spacesize;
2333 else
2334 if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */
2335 {
2336 decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */
2337 pText++;
2338 decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */
2339 if (decodeUTF8 <= 0xff) /* The following function has a uint8 input parameter ==> no UNICODEs > 0xff supported */
2340 {
2341 cfg->Xdelta = GFX_write_char(hgfx, cfg, (uint8_t)decodeUTF8, (tFont *)cfg->actualFont);
2342 }
2343 }
2329 else 2344 else
2330 cfg->Xdelta = GFX_write_char(hgfx, cfg, *(uint8_t *)pText, (tFont *)cfg->actualFont); 2345 cfg->Xdelta = GFX_write_char(hgfx, cfg, *(uint8_t *)pText, (tFont *)cfg->actualFont);
2331 2346
2332 pText++; 2347 pText++;
2333 } 2348 }
3128 uint32_t result; 3143 uint32_t result;
3129 uint32_t Xsum; 3144 uint32_t Xsum;
3130 uint32_t i, j; 3145 uint32_t i, j;
3131 uint8_t gfx_selected_language; 3146 uint8_t gfx_selected_language;
3132 uint32_t pText; 3147 uint32_t pText;
3148 uint16_t decodeUTF8;
3133 3149
3134 #ifndef BOOTLOADER_STANDALONE 3150 #ifndef BOOTLOADER_STANDALONE
3135 SSettings *pSettings; 3151 SSettings *pSettings;
3136 pSettings = settingsGetPointer(); 3152 pSettings = settingsGetPointer();
3137 gfx_selected_language = pSettings->selected_language; 3153 gfx_selected_language = pSettings->selected_language;
3145 pText = (uint32_t)&cText[0]; 3161 pText = (uint32_t)&cText[0];
3146 Xsum = 0; 3162 Xsum = 0;
3147 j = 0; 3163 j = 0;
3148 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size 3164 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size
3149 { 3165 {
3166 if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */
3167 {
3168 decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */
3169 pText++;
3170 decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */
3171 }
3172 else
3173 {
3174 decodeUTF8 = *(char*)pText; /* place ASCII char */
3175 }
3176
3150 for(i=0;i<((tFont *)cfg->font)->length;i++) 3177 for(i=0;i<((tFont *)cfg->font)->length;i++)
3151 { 3178 {
3152 if(((tFont *)cfg->font)->chars[i].code == *(char*)pText) 3179 if(((tFont *)cfg->font)->chars[i].code == decodeUTF8)
3153 { 3180 {
3154 Xsum += ((tFont *)cfg->font)->chars[i].image->width; 3181 Xsum += ((tFont *)cfg->font)->chars[i].image->width;
3155 break; 3182 break;
3156 } 3183 }
3157 } 3184 }
3188 uint32_t i, j; 3215 uint32_t i, j;
3189 tFont *font; 3216 tFont *font;
3190 uint8_t gfx_selected_language; 3217 uint8_t gfx_selected_language;
3191 uint32_t pText; 3218 uint32_t pText;
3192 uint8_t setToTinyFont = 0; 3219 uint8_t setToTinyFont = 0;
3220 uint16_t decodeUTF8;
3193 3221
3194 #ifndef BOOTLOADER_STANDALONE 3222 #ifndef BOOTLOADER_STANDALONE
3195 SSettings *pSettings; 3223 SSettings *pSettings;
3196 pSettings = settingsGetPointer(); 3224 pSettings = settingsGetPointer();
3197 gfx_selected_language = pSettings->selected_language; 3225 gfx_selected_language = pSettings->selected_language;
3234 { 3262 {
3235 Xsum += font->spacesize; 3263 Xsum += font->spacesize;
3236 } 3264 }
3237 else 3265 else
3238 { 3266 {
3267 if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */
3268 {
3269 decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */
3270 pText++;
3271 decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */
3272 }
3273 else
3274 {
3275 decodeUTF8 = *(char*)pText;
3276 }
3239 for(i=0;i<font->length;i++) 3277 for(i=0;i<font->length;i++)
3240 { 3278 {
3241 if(font->chars[i].code == *(char*)pText) 3279 if(font->chars[i].code == decodeUTF8)
3242 { 3280 {
3243 Xsum += font->chars[i].image->width; 3281 Xsum += font->chars[i].image->width;
3244 break; 3282 break;
3245 } 3283 }
3246 } 3284 }