mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
correctly skip utf-8 characters
This commit is contained in:
parent
7fd1e894f5
commit
7d3196a057
@ -252,9 +252,9 @@ void layoutAddress(const char *address)
|
|||||||
oledDrawString(68, 3 * 9, str[3]);
|
oledDrawString(68, 3 * 9, str[3]);
|
||||||
|
|
||||||
static const char *btnYes = "Continue";
|
static const char *btnYes = "Continue";
|
||||||
oledDrawString(OLED_WIDTH - fontCharWidth('\xff') - 1, OLED_HEIGHT - 8, "\xff");
|
oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06");
|
||||||
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 3, OLED_HEIGHT - 8, btnYes);
|
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes);
|
||||||
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
|
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
|
||||||
|
|
||||||
oledRefresh();
|
oledRefresh();
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ const uint8_t *font_data[256] = {
|
|||||||
/* 0x03 _ */ (uint8_t *)"\x01\x00",
|
/* 0x03 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x04 _ */ (uint8_t *)"\x01\x00",
|
/* 0x04 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x05 _ */ (uint8_t *)"\x01\x00",
|
/* 0x05 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x06 _ */ (uint8_t *)"\x01\x00",
|
/* 0x06 _ */ (uint8_t *)"\x07\x18\x1c\x0e\x18\x30\x40\x80",
|
||||||
/* 0x07 _ */ (uint8_t *)"\x01\x00",
|
/* 0x07 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x08 _ */ (uint8_t *)"\x01\x00",
|
/* 0x08 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x09 _ */ (uint8_t *)"\x01\x00",
|
/* 0x09 _ */ (uint8_t *)"\x01\x00",
|
||||||
@ -22,7 +22,7 @@ const uint8_t *font_data[256] = {
|
|||||||
/* 0x12 _ */ (uint8_t *)"\x01\x00",
|
/* 0x12 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x13 _ */ (uint8_t *)"\x01\x00",
|
/* 0x13 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x14 _ */ (uint8_t *)"\x01\x00",
|
/* 0x14 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x15 _ */ (uint8_t *)"\x01\x00",
|
/* 0x15 _ */ (uint8_t *)"\x07\x44\xee\x7c\x38\x7c\xee\x44",
|
||||||
/* 0x16 _ */ (uint8_t *)"\x01\x00",
|
/* 0x16 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x17 _ */ (uint8_t *)"\x01\x00",
|
/* 0x17 _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0x18 _ */ (uint8_t *)"\x01\x00",
|
/* 0x18 _ */ (uint8_t *)"\x01\x00",
|
||||||
@ -255,8 +255,8 @@ const uint8_t *font_data[256] = {
|
|||||||
/* 0xfb _ */ (uint8_t *)"\x01\x00",
|
/* 0xfb _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0xfc _ */ (uint8_t *)"\x01\x00",
|
/* 0xfc _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0xfd _ */ (uint8_t *)"\x01\x00",
|
/* 0xfd _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0xfe _ */ (uint8_t *)"\x07\x44\xee\x7c\x38\x7c\xee\x44",
|
/* 0xfe _ */ (uint8_t *)"\x01\x00",
|
||||||
/* 0xff _ */ (uint8_t *)"\x07\x18\x1c\x0e\x18\x30\x40\x80",
|
/* 0xff _ */ (uint8_t *)"\x01\x00",
|
||||||
};
|
};
|
||||||
|
|
||||||
int fontCharWidth(char c) {
|
int fontCharWidth(char c) {
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.8 KiB |
@ -20,15 +20,15 @@ class Img(object):
|
|||||||
|
|
||||||
img = Img('font.png')
|
img = Img('font.png')
|
||||||
cur = ''
|
cur = ''
|
||||||
idx = 0
|
|
||||||
|
|
||||||
for i in range(img.w):
|
for i in range(256):
|
||||||
if img.pixel(i, 0) == None:
|
x = (i % 16) * 10
|
||||||
cur = '\\x%02x' % (len(cur) / 4) + cur
|
y = (i / 16) * 10
|
||||||
ch = chr(idx) if idx >= 32 and idx <= 126 else '_'
|
cur = ''
|
||||||
print '\t/* 0x%02x %c */ (uint8_t *)"%s",' % (idx, ch , cur)
|
while img.pixel(x, y) != None:
|
||||||
cur = ''
|
val = ''.join(img.pixel(x, y + j) for j in range(8))
|
||||||
idx += 1
|
x += 1
|
||||||
continue
|
cur += '\\x%02x' % int(val, 2)
|
||||||
val = img.pixel(i, 0) + img.pixel(i, 1) + img.pixel(i, 2) + img.pixel(i, 3) + img.pixel(i, 4) + img.pixel(i, 5) + img.pixel(i, 6) + img.pixel(i, 7)
|
cur = '\\x%02x' % (len(cur) / 4) + cur
|
||||||
cur += '\\x%02x' % int(val, 2)
|
ch = chr(i) if i >= 32 and i <= 126 else '_'
|
||||||
|
print '\t/* 0x%02x %c */ (uint8_t *)"%s",' % (i, ch , cur)
|
||||||
|
12
layout.c
12
layout.c
@ -67,14 +67,14 @@ void layoutDialog(LayoutDialogIcon icon, const char *btnNo, const char *btnYes,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (btnNo) {
|
if (btnNo) {
|
||||||
oledDrawString(1, OLED_HEIGHT - 8, "\xfe");
|
oledDrawString(1, OLED_HEIGHT - 8, "\x15");
|
||||||
oledDrawString(fontCharWidth('\xfe') + 3, OLED_HEIGHT - 8, btnNo);
|
oledDrawString(fontCharWidth('\x15') + 3, OLED_HEIGHT - 8, btnNo);
|
||||||
oledInvert(0, OLED_HEIGHT - 9, fontCharWidth('\xfe') + oledStringWidth(btnNo) + 2, OLED_HEIGHT - 1);
|
oledInvert(0, OLED_HEIGHT - 9, fontCharWidth('\x15') + oledStringWidth(btnNo) + 2, OLED_HEIGHT - 1);
|
||||||
}
|
}
|
||||||
if (btnYes) {
|
if (btnYes) {
|
||||||
oledDrawString(OLED_WIDTH - fontCharWidth('\xff') - 1, OLED_HEIGHT - 8, "\xff");
|
oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06");
|
||||||
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 3, OLED_HEIGHT - 8, btnYes);
|
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes);
|
||||||
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
|
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
|
||||||
}
|
}
|
||||||
oledRefresh();
|
oledRefresh();
|
||||||
}
|
}
|
||||||
|
24
oled.c
24
oled.c
@ -207,11 +207,25 @@ void oledDrawChar(int x, int y, char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char oledConvertChar(const char c) {
|
||||||
|
uint8_t a = c;
|
||||||
|
if (a < 0x80) return c;
|
||||||
|
// UTF-8 handling: https://en.wikipedia.org/wiki/UTF-8#Description
|
||||||
|
// bytes 11xxxxxx are first byte of UTF-8 characters
|
||||||
|
// bytes 10xxxxxx are successive UTF-8 characters
|
||||||
|
if (a >= 0xC0) return '_';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int oledStringWidth(const char *text) {
|
int oledStringWidth(const char *text) {
|
||||||
if (!text) return 0;
|
if (!text) return 0;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
|
char c;
|
||||||
for (; *text; text++) {
|
for (; *text; text++) {
|
||||||
l += fontCharWidth(*text) + 1;
|
c = oledConvertChar(*text);
|
||||||
|
if (c) {
|
||||||
|
l += fontCharWidth(c) + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
@ -220,9 +234,13 @@ void oledDrawString(int x, int y, const char* text)
|
|||||||
{
|
{
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
|
char c;
|
||||||
for (; *text; text++) {
|
for (; *text; text++) {
|
||||||
oledDrawChar(x + l, y, *text);
|
c = oledConvertChar(*text);
|
||||||
l += fontCharWidth(*text) + 1;
|
if (c) {
|
||||||
|
oledDrawChar(x + l, y, c);
|
||||||
|
l += fontCharWidth(c) + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user