1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-26 18:02:35 +00:00

legacy: fix types for characted data

This commit is contained in:
Pavol Rusnak 2019-10-10 17:43:55 +00:00
parent b07b9b1d09
commit 145b098f0e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 11 additions and 9 deletions

View File

@ -9,8 +9,8 @@ const uint8_t *const font_data[2][128] = {
}, },
}; };
int fontCharWidth(int font, char c) { return font_data[font][c & 0x7f][0]; } int fontCharWidth(int font, uint8_t c) { return font_data[font][c & 0x7f][0]; }
const uint8_t *fontCharData(int font, char c) { const uint8_t *fontCharData(int font, uint8_t c) {
return font_data[font][c & 0x7f] + 1; return font_data[font][c & 0x7f] + 1;
} }

View File

@ -10,7 +10,7 @@
extern const uint8_t *const font_data[2][128]; extern const uint8_t *const font_data[2][128];
int fontCharWidth(int font, char c); int fontCharWidth(int font, uint8_t c);
const uint8_t *fontCharData(int font, char c); const uint8_t *fontCharData(int font, uint8_t c);
#endif #endif

View File

@ -247,8 +247,8 @@ void oledDrawChar(int x, int y, char c, int font) {
} }
int zoom = (font & FONT_DOUBLE) ? 2 : 1; int zoom = (font & FONT_DOUBLE) ? 2 : 1;
int char_width = fontCharWidth(font & 0x7f, c); int char_width = fontCharWidth(font & 0x7f, (uint8_t)c);
const uint8_t *char_data = fontCharData(font & 0x7f, c); const uint8_t *char_data = fontCharData(font & 0x7f, (uint8_t)c);
if (x <= -char_width) { if (x <= -char_width) {
return; return;
@ -268,9 +268,11 @@ void oledDrawChar(int x, int y, char c, int font) {
} }
} }
char oledConvertChar(const char c) { static uint8_t convert_char(const char a) {
static char last_was_utf8 = 0; static char last_was_utf8 = 0;
uint8_t c = a;
// non-printable ASCII character // non-printable ASCII character
if (c < ' ') { if (c < ' ') {
last_was_utf8 = 0; last_was_utf8 = 0;
@ -307,7 +309,7 @@ int oledStringWidth(const char *text, int font) {
int space = (font & FONT_DOUBLE) ? 2 : 1; int space = (font & FONT_DOUBLE) ? 2 : 1;
int l = 0; int l = 0;
for (; *text; text++) { for (; *text; text++) {
char c = oledConvertChar(*text); uint8_t c = convert_char(*text);
if (c) { if (c) {
l += fontCharWidth(font & 0x7f, c) + space; l += fontCharWidth(font & 0x7f, c) + space;
} }
@ -320,7 +322,7 @@ void oledDrawString(int x, int y, const char *text, int font) {
int l = 0; int l = 0;
int space = (font & FONT_DOUBLE) ? 2 : 1; int space = (font & FONT_DOUBLE) ? 2 : 1;
for (; *text; text++) { for (; *text; text++) {
char c = oledConvertChar(*text); uint8_t c = convert_char(*text);
if (c) { if (c) {
oledDrawChar(x + l, y, c, font); oledDrawChar(x + l, y, c, font);
l += fontCharWidth(font & 0x7f, c) + space; l += fontCharWidth(font & 0x7f, c) + space;