Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 51 additions & 60 deletions radio/src/gui/128x64/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions radio/src/gui/128x64/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* GNU General Public License for more details.
*/

#ifndef _LCD_H_
#define _LCD_H_
#pragma once

#include <inttypes.h>

Expand Down Expand Up @@ -94,7 +93,6 @@ extern coord_t lcdNextPos;
#define IS_IN_DISPLAY(p) ((p) >= displayBuf && (p) < DISPLAY_END)
#define ASSERT_IN_DISPLAY(p) assert((p) >= displayBuf && (p) < DISPLAY_END)


void lcdDrawChar(coord_t x, coord_t y, uint8_t c);
void lcdDrawChar(coord_t x, coord_t y, uint8_t c, LcdFlags flags);
void lcdDrawCenteredText(coord_t y, const char * s, LcdFlags flags = 0);
Expand Down Expand Up @@ -190,5 +188,3 @@ inline pixel_t getPixel(uint8_t x, uint8_t y)
}

uint8_t getTextWidth(const char * s, uint8_t len=0, LcdFlags flags=0);

#endif // _LCD_H_
110 changes: 51 additions & 59 deletions radio/src/gui/212x64/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ void lcdPutPattern(coord_t x, coord_t y, const uint8_t * pattern, uint8_t width,
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;

Expand All @@ -175,62 +178,61 @@ LcdFlags getCharPattern(PatternData * pattern, unsigned char c, LcdFlags flags)
// c has to be remapped. All non existing chars mapped to 0 (space)
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 >= 0x80) {
pattern->data = &font_10x14_extra[((uint16_t) (c - 0x80)) * 20];
}
else {
if (c >= 0x80)
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 < 0x80 ? &font_4x6[(c - 0x20) * 5] : &font_4x6_extra[(c - 0x80) * 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;
}
Expand All @@ -245,14 +247,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)
Expand All @@ -264,11 +261,7 @@ uint8_t getTextWidth(const char * s, uint8_t len, LcdFlags flags)
{
uint8_t width = 0;
for (int i = 0; len == 0 || i < len; ++i) {
#if !defined(BOOT)
unsigned char c = *s;
#else
unsigned char c = *s;
#endif
unsigned char c = map_utf8_char(s, len);
if (!c) {
break;
}
Expand Down Expand Up @@ -309,7 +302,6 @@ void lcdDrawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlag
#if !defined(BOOT)
// UTF8 detection
c = map_utf8_char(s, len);
if (c >= 0x95 && FONTSIZE(flags)) c -=21;
if (!c) break;

if (c == 46 && FONTSIZE(flags) == TINSIZE) { // '.' handling
Expand Down
6 changes: 1 addition & 5 deletions radio/src/gui/212x64/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* GNU General Public License for more details.
*/

#ifndef _LCD_H_
#define _LCD_H_
#pragma once

#include <inttypes.h>

Expand Down Expand Up @@ -255,6 +254,3 @@ class RleBitmap

coord_t pos;
};


#endif // _LCD_H_
Loading