comparison Discovery/Src/gfx_engine.c @ 481:89f6857276f8 Improve_Button_Sleep

Bugfix calculation of string center position: Strings shown on the right side at surface mode use special characters ('\016' and '\017') to switch font size. Headline strings like "Desaturation" could also be set to the target font directly, because they do not contain mixed font sizes, but nethertheless they are using the special characters. The function calculating the offset needed to display the strinter with center alignment did not consider the small font size => misalignment during string display. To avoid this an evaluation of the special characters has been added to the helper function.
author ideenmodellierer
date Mon, 18 May 2020 21:51:08 +0200
parents e141b571a03d
children 7a17bfc932b6
comparison
equal deleted inserted replaced
480:3fe9cc747c5c 481:89f6857276f8
3083 uint32_t Xsum; 3083 uint32_t Xsum;
3084 uint32_t i, j; 3084 uint32_t i, j;
3085 uint8_t gfx_selected_language; 3085 uint8_t gfx_selected_language;
3086 uint32_t pText; 3086 uint32_t pText;
3087 uint16_t decodeUTF8; 3087 uint16_t decodeUTF8;
3088 uint8_t tinyState = 0; /* used to identify the usage of tiny font */
3089 tFont* ptargetFont;
3088 3090
3089 #ifndef BOOTLOADER_STANDALONE 3091 #ifndef BOOTLOADER_STANDALONE
3090 SSettings *pSettings; 3092 SSettings *pSettings;
3091 pSettings = settingsGetPointer(); 3093 pSettings = settingsGetPointer();
3092 gfx_selected_language = pSettings->selected_language; 3094 gfx_selected_language = pSettings->selected_language;
3100 pText = (uint32_t)&cText[0]; 3102 pText = (uint32_t)&cText[0];
3101 Xsum = 0; 3103 Xsum = 0;
3102 j = 0; 3104 j = 0;
3103 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size 3105 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size
3104 { 3106 {
3107 if(*(char*)pText == '\016') /* request font change */
3108 {
3109 tinyState++;
3110 }
3111 if(*(char*)pText == '\017') /* request font reset */
3112 {
3113 tinyState = 0;
3114 }
3115 if(tinyState > 1)
3116 {
3117 ptargetFont = (tFont *)cfg->TinyFont;
3118 }
3119 else
3120 {
3121 ptargetFont = (tFont *)cfg->font;
3122 }
3105 if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */ 3123 if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */
3106 { 3124 {
3107 decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */ 3125 decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */
3108 pText++; 3126 pText++;
3109 decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */ 3127 decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */
3111 else 3129 else
3112 { 3130 {
3113 decodeUTF8 = *(char*)pText; /* place ASCII char */ 3131 decodeUTF8 = *(char*)pText; /* place ASCII char */
3114 } 3132 }
3115 3133
3116 for(i=0;i<((tFont *)cfg->font)->length;i++) 3134 for(i=0;i<ptargetFont->length;i++)
3117 { 3135 {
3118 if(((tFont *)cfg->font)->chars[i].code == decodeUTF8) 3136 if(ptargetFont->chars[i].code == decodeUTF8)
3119 { 3137 {
3120 Xsum += ((tFont *)cfg->font)->chars[i].image->width; 3138 Xsum += ptargetFont->chars[i].image->width;
3121 break; 3139 break;
3122 } 3140 }
3123 } 3141 }
3124 pText++; 3142 pText++;
3125 j++; 3143 j++;
3126 if(((tFont *)cfg->font == &FontT144) && (*(char*)pText != 0)) 3144 if((ptargetFont == &FontT144) && (*(char*)pText != 0))
3127 Xsum += 3; 3145 Xsum += 3;
3128 else 3146 else
3129 if(((tFont *)cfg->font == &FontT105) && (*(char*)pText != 0)) 3147 if((ptargetFont == &FontT105) && (*(char*)pText != 0))
3130 Xsum += 2; 3148 Xsum += 2;
3131 } 3149 }
3132 pText -= j; 3150 pText -= j;
3133 3151
3134 if(cfg->doubleSize) 3152 if(cfg->doubleSize)