fix(bw): language special characters not working for 10x14 font size (#4816)

Also cleans up the font handling to make the different font sizes more consistent.
It will now allow more than 64 special characters for language translation (if it is ever required).
This commit is contained in:
philmoz
2024-03-30 10:57:30 +10:00
committed by GitHub
parent 2d4c1acbfb
commit d73d88a10b
7 changed files with 178 additions and 180 deletions
+51 -60
View File
@@ -162,70 +162,72 @@ uint8_t getPatternWidth(const PatternData * pattern)
LcdFlags getCharPattern(PatternData * pattern, unsigned char c, LcdFlags flags)
{
#if !defined(BOOT)
static const uint8_t fontWidth[] = { 5, 3, 5, 8, 10, 22, 5 };
static const uint8_t fontHeight[] = { 7, 5, 6, 12, 16, 38, 7 };
uint32_t fontsize = FONTSIZE(flags);
unsigned char c_remapped = 0;
if (fontsize == DBLSIZE || (flags & BOLD)) {
// To save space only some DBLSIZE and BOLD chars are available
// c has to be remapped. All non existing chars mapped to 0 (space)
if (c>=',' && c<=':')
if (c >= ',' && c <= ':')
c_remapped = c - ',' + 1;
else if (c>='A' && c<='Z')
else if (c >= 'A' && c <= 'Z')
c_remapped = c - 'A' + 16;
else if (c>='a' && c<='z')
else if (c >= 'a' && c <= 'z')
c_remapped = c - 'a' + 42;
else if (c=='_')
else if (c == '_')
c_remapped = 4;
else if (c!=' ')
flags &= ~BOLD;
else if (c != ' ')
flags &= ~BOLD; // For BOLD use Standard font if character is not in BOLD
}
if (fontsize == DBLSIZE) {
pattern->width = 10;
pattern->height = 16;
if (c >= 0xC0) {
pattern->data = &font_10x14_extra[((uint16_t)(c-0xC0))*20];
}
else {
if (c >= 128)
c_remapped = c - 81;
pattern->data = &font_10x14[((uint16_t)c_remapped)*20];
}
}
else if (fontsize == XXLSIZE) {
pattern->width = 22;
pattern->height = 38;
pattern->data = &font_22x38_num[((uint16_t)c-'0'+5)*110];
}
else if (fontsize == MIDSIZE) {
pattern->width = 8;
pattern->height = 12;
pattern->data = &font_8x10[((uint16_t)c-0x20)*16];
}
else if (fontsize == SMLSIZE) {
pattern->width = 5;
pattern->height = 6;
pattern->data = (c < 0xc0 ? &font_4x6[(c-0x20)*5] : &font_4x6_extra[(c-0xc0)*5]);
}
else if (fontsize == TINSIZE) {
pattern->width = 3;
pattern->height = 5;
pattern->data = &font_3x5[((uint16_t)c-0x20)*3];
}
else if (flags & BOLD) {
pattern->width = 5;
pattern->height = 7;
pattern->data = &font_5x7_B[c_remapped*5];
}
else {
pattern->width = 5;
pattern->height = 7;
pattern->data = &font_5x7[(c - 0x20) * 5];
}
uint8_t fontIdx = fontsize >> 8;
if (fontIdx == 0 && flags & BOLD) fontIdx = 6;
pattern->width = fontWidth[fontIdx];
pattern->height = fontHeight[fontIdx];
int charSize = (pattern->height + 7) / 8 * pattern->width;
switch (fontIdx) {
case 0: // Standard
pattern->data = &font_5x7[(c - FONT_BASE_START) * charSize];
break;
case 1: // TINSIZE
pattern->data = &font_3x5[(c - FONT_BASE_START) * charSize];
break;
case 2: // SMLSIZE
// Adjust language special characters offset
if (c >= FONT_LANG_START)
c = c - (FONT_SYMS_CNT - FONT_SYMS_CNT_4x6);
pattern->data = &font_4x6[(c - FONT_BASE_START) * charSize];
break;
case 3: // MDLSIZE
// Adjust language special characters offset
if (c >= FONT_LANG_START)
c = c - FONT_SYMS_CNT;
pattern->data = &font_8x10[(c - FONT_BASE_START) * charSize];
break;
case 4: // DBLSIZE
// Adjust language special characters offset and symbols offset
if (c >= FONT_LANG_START)
c_remapped = c - (FONT_BASE_CNT - FONT_BASE_CNT_10x14) - (FONT_SYMS_CNT - FONT_SYMS_CNT_10x14) - FONT_BASE_START;
else if (c >= FONT_SYMS_START)
c_remapped = c - (FONT_BASE_CNT - FONT_BASE_CNT_10x14) - FONT_BASE_START;
pattern->data = &font_10x14[(c_remapped) * charSize];
break;
case 5: // XXLSIZE
pattern->data = &font_22x38_num[(c - '0' + 5) * charSize];
break;
case 6: // BOLD
pattern->data = &font_5x7_B[c_remapped * charSize];
break;
};
#else
pattern->width = 5;
pattern->height = 7;
pattern->data = &font_5x7[(c-0x20)*5];
pattern->data = &font_5x7[(c - FONT_BASE_START) * 5];
#endif
return flags;
}
@@ -240,14 +242,9 @@ uint8_t getCharWidth(char c, LcdFlags flags)
void lcdDrawChar(coord_t x, coord_t y, uint8_t c, LcdFlags flags)
{
lcdNextPos = x - 1;
#if defined(BOOT)
const uint8_t * data = &font_5x7[(c-0x20)*5];
lcdPutPattern(x, y, data, 5, 7, flags);
#else
PatternData pattern;
flags = getCharPattern(&pattern, c, flags);
lcdPutPattern(x, y, pattern.data, pattern.width, pattern.height, flags);
#endif
}
void lcdDrawChar(coord_t x, coord_t y, uint8_t c)
@@ -260,12 +257,7 @@ uint8_t getTextWidth(const char * s, uint8_t len, LcdFlags flags)
uint8_t width = 0;
if (len == 0) len = strlen(s);
while (len--) {
#if !defined(BOOT)
unsigned char c = map_utf8_char(s, len);
if (c >= 0x95 && FONTSIZE(flags)) c -=21;
#else
unsigned char c = *s;
#endif
if (!c) {
break;
}
@@ -306,7 +298,6 @@ void lcdDrawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlag
else if (c >= 0x20) {
// UTF8 detection
c = map_utf8_char(s, len);
if (c >= 0x95 && fontsize) c -=21;
if (!c) break;
lcdDrawChar(x, y, c, flags);