1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

refactor font handling

This commit is contained in:
Pavol Rusnak 2015-02-13 15:37:23 +01:00
parent ac8d951027
commit 7fd1e894f5
8 changed files with 297 additions and 148 deletions

View File

@ -252,9 +252,9 @@ void layoutAddress(const char *address)
oledDrawString(68, 3 * 9, str[3]);
static const char *btnYes = "Continue";
oledDrawString(OLED_WIDTH - fontCharWidth('}') - 1, OLED_HEIGHT - 8, "}");
oledDrawString(OLED_WIDTH - fontStringWidth(btnYes) - fontCharWidth('}') - 3, OLED_HEIGHT - 8, btnYes);
oledInvert(OLED_WIDTH - fontStringWidth(btnYes) - fontCharWidth('}') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
oledDrawString(OLED_WIDTH - fontCharWidth('\xff') - 1, OLED_HEIGHT - 8, "\xff");
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 3, OLED_HEIGHT - 8, btnYes);
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
oledRefresh();
}

View File

@ -1,122 +1,268 @@
#include "fonts.h"
const uint8_t *font_data[FONT_END - FONT_START + 1] = {
(uint8_t *)"\x01\x00",
(uint8_t *)"\x02\xfa\xfa",
(uint8_t *)"\x03\xc0\x00\xc0",
(uint8_t *)"\x05\x6c\xfe\x6c\xfe\x6c",
(uint8_t *)"\x05\x32\xff\x5a\xff\x4c",
(uint8_t *)"\x06\xc0\xc6\x1c\x70\xc6\x06",
(uint8_t *)"\x06\x5c\xfe\xb2\xfe\x4c\x1e",
(uint8_t *)"\x01\xc0",
(uint8_t *)"\x03\x38\x7c\x82",
(uint8_t *)"\x03\x82\x7c\x38",
(uint8_t *)"\x05\x6c\x38\xfe\x38\x6c",
(uint8_t *)"\x05\x10\x10\x7c\x10\x10",
(uint8_t *)"\x02\x03\x06",
(uint8_t *)"\x04\x10\x10\x10\x10",
(uint8_t *)"\x02\x06\x06",
(uint8_t *)"\x03\x0e\x38\xe0",
(uint8_t *)"\x05\x7c\xfe\x82\xfe\x7c",
(uint8_t *)"\x03\x40\xfe\xfe",
(uint8_t *)"\x05\x8e\x9e\x92\xf2\x62",
(uint8_t *)"\x05\x82\x92\x92\xfe\x6c",
(uint8_t *)"\x05\x18\x28\x48\xfe\xfe",
(uint8_t *)"\x05\xe2\xa2\xa2\xbe\x1c",
(uint8_t *)"\x05\x7c\xfe\xa2\xbe\x1c",
(uint8_t *)"\x05\x80\x8e\xbe\xf0\xc0",
(uint8_t *)"\x05\x6c\xfe\x92\xfe\x6c",
(uint8_t *)"\x05\x70\xfa\x8a\xfe\x7c",
(uint8_t *)"\x02\x36\x36",
(uint8_t *)"\x02\x33\x36",
(uint8_t *)"\x04\x10\x38\x6c\xc6",
(uint8_t *)"\x04\x28\x28\x28\x28",
(uint8_t *)"\x04\xc6\x6c\x38\x10",
(uint8_t *)"\x05\x80\x9a\xba\xe0\x40",
(uint8_t *)"\x06\x7c\xfe\xaa\xba\xfa\x78",
(uint8_t *)"\x05\x7e\xfe\x88\xfe\x7e",
(uint8_t *)"\x05\xfe\xfe\xa2\xfe\x5c",
(uint8_t *)"\x05\x7c\xfe\x82\x82\x82",
(uint8_t *)"\x05\xfe\xfe\x82\xfe\x7c",
(uint8_t *)"\x05\xfe\xfe\xa2\xa2\x82",
(uint8_t *)"\x05\xfe\xfe\xa0\xa0\x80",
(uint8_t *)"\x05\x7c\xfe\x82\x9e\x1e",
(uint8_t *)"\x05\xfe\xfe\x20\xfe\xfe",
(uint8_t *)"\x02\xfe\xfe",
(uint8_t *)"\x04\x02\x02\xfe\xfc",
(uint8_t *)"\x06\xfe\xfe\x38\x6c\xc6\x82",
(uint8_t *)"\x04\xfe\xfe\x02\x02",
(uint8_t *)"\x07\xfe\x7e\x30\x18\x30\x7e\xfe",
(uint8_t *)"\x06\xfe\x7e\x30\x18\xfc\xfe",
(uint8_t *)"\x06\x7c\xfe\x82\x82\xfe\x7c",
(uint8_t *)"\x05\xfe\xfe\x88\xf8\x70",
(uint8_t *)"\x06\x7c\xfe\x82\x86\xff\x7d",
(uint8_t *)"\x05\xfe\xfe\x88\xfe\x72",
(uint8_t *)"\x04\x62\xf2\x9e\x8c",
(uint8_t *)"\x06\x80\x80\xfe\xfe\x80\x80",
(uint8_t *)"\x05\xfc\xfe\x02\xfe\xfc",
(uint8_t *)"\x06\xe0\xf8\x1e\x1e\xf8\xe0",
(uint8_t *)"\x07\xf0\xfe\x1e\x3c\x1e\xfe\xf0",
(uint8_t *)"\x06\xc6\xee\x38\x38\xee\xc6",
(uint8_t *)"\x06\xc0\xe0\x3e\x3e\xe0\xc0",
(uint8_t *)"\x05\x8e\x9e\xba\xf2\xe2",
(uint8_t *)"\x03\xfe\xfe\x82",
(uint8_t *)"\x03\xe0\x38\x0e",
(uint8_t *)"\x03\x82\xfe\xfe",
(uint8_t *)"\x03\x60\xc0\x60",
(uint8_t *)"\x06\x02\x02\x02\x02\x02\x02",
(uint8_t *)"\x02\x80\x40",
(uint8_t *)"\x05\x04\x2e\x2a\x3e\x1e",
(uint8_t *)"\x05\xfe\xfe\x22\x3e\x1c",
(uint8_t *)"\x04\x1c\x3e\x22\x22",
(uint8_t *)"\x05\x1c\x3e\x22\xfe\xfe",
(uint8_t *)"\x05\x1c\x3e\x2a\x3a\x1a",
(uint8_t *)"\x03\x7e\xfe\xa0",
(uint8_t *)"\x05\x18\x3d\x25\x3f\x3e",
(uint8_t *)"\x05\xfe\xfe\x20\x3e\x1e",
(uint8_t *)"\x02\xbe\xbe",
(uint8_t *)"\x03\x01\xbf\xbe",
(uint8_t *)"\x05\xfe\xfe\x1c\x36\x22",
(uint8_t *)"\x02\xfe\xfe",
(uint8_t *)"\x08\x3e\x3e\x20\x3e\x3e\x20\x3e\x1e",
(uint8_t *)"\x05\x3e\x3e\x20\x3e\x1e",
(uint8_t *)"\x05\x1c\x3e\x22\x3e\x1c",
(uint8_t *)"\x05\x3f\x3f\x24\x3c\x18",
(uint8_t *)"\x05\x18\x3c\x24\x3f\x3f",
(uint8_t *)"\x04\x3e\x3e\x10\x30",
(uint8_t *)"\x04\x1a\x3a\x2e\x2c",
(uint8_t *)"\x03\xfc\xfe\x22",
(uint8_t *)"\x05\x3c\x3e\x02\x3e\x3e",
(uint8_t *)"\x05\x30\x3c\x0e\x3c\x30",
(uint8_t *)"\x07\x38\x3e\x06\x1c\x06\x3e\x38",
(uint8_t *)"\x05\x36\x3e\x08\x3e\x36",
(uint8_t *)"\x05\x38\x3d\x05\x3f\x3e",
(uint8_t *)"\x05\x26\x2e\x3a\x32\x22",
(uint8_t *)"\x04\x10\x7c\xee\x82",
(uint8_t *)"\x02\xff\xff",
(uint8_t *)"\x04\x82\xee\x7c\x10",
(uint8_t *)"\x04\x08\x10\x08\x10",
(uint8_t *)"\x02\x00\x00",
(uint8_t *)"\x07\x44\xee\x7c\x38\x7c\xee\x44",
(uint8_t *)"\x07\x18\x1c\x0e\x18\x30\x40\x80",
(uint8_t *)"\x06\x10\x38\x7c\x10\x10\x10",
(uint8_t *)"\x06\x10\x10\x10\x7c\x38\x10",
(uint8_t *)"\x05\x7e\xff\x52\xff\x2c",
const uint8_t *font_data[256] = {
/* 0x00 _ */ (uint8_t *)"\x01\x00",
/* 0x01 _ */ (uint8_t *)"\x01\x00",
/* 0x02 _ */ (uint8_t *)"\x01\x00",
/* 0x03 _ */ (uint8_t *)"\x01\x00",
/* 0x04 _ */ (uint8_t *)"\x01\x00",
/* 0x05 _ */ (uint8_t *)"\x01\x00",
/* 0x06 _ */ (uint8_t *)"\x01\x00",
/* 0x07 _ */ (uint8_t *)"\x01\x00",
/* 0x08 _ */ (uint8_t *)"\x01\x00",
/* 0x09 _ */ (uint8_t *)"\x01\x00",
/* 0x0a _ */ (uint8_t *)"\x01\x00",
/* 0x0b _ */ (uint8_t *)"\x01\x00",
/* 0x0c _ */ (uint8_t *)"\x01\x00",
/* 0x0d _ */ (uint8_t *)"\x01\x00",
/* 0x0e _ */ (uint8_t *)"\x01\x00",
/* 0x0f _ */ (uint8_t *)"\x01\x00",
/* 0x10 _ */ (uint8_t *)"\x01\x00",
/* 0x11 _ */ (uint8_t *)"\x01\x00",
/* 0x12 _ */ (uint8_t *)"\x01\x00",
/* 0x13 _ */ (uint8_t *)"\x01\x00",
/* 0x14 _ */ (uint8_t *)"\x01\x00",
/* 0x15 _ */ (uint8_t *)"\x01\x00",
/* 0x16 _ */ (uint8_t *)"\x01\x00",
/* 0x17 _ */ (uint8_t *)"\x01\x00",
/* 0x18 _ */ (uint8_t *)"\x01\x00",
/* 0x19 _ */ (uint8_t *)"\x01\x00",
/* 0x1a _ */ (uint8_t *)"\x01\x00",
/* 0x1b _ */ (uint8_t *)"\x01\x00",
/* 0x1c _ */ (uint8_t *)"\x01\x00",
/* 0x1d _ */ (uint8_t *)"\x01\x00",
/* 0x1e _ */ (uint8_t *)"\x01\x00",
/* 0x1f _ */ (uint8_t *)"\x01\x00",
/* 0x20 */ (uint8_t *)"\x01\x00",
/* 0x21 ! */ (uint8_t *)"\x02\xfa\xfa",
/* 0x22 " */ (uint8_t *)"\x03\xc0\x00\xc0",
/* 0x23 # */ (uint8_t *)"\x05\x6c\xfe\x6c\xfe\x6c",
/* 0x24 $ */ (uint8_t *)"\x05\x32\xff\x5a\xff\x4c",
/* 0x25 % */ (uint8_t *)"\x06\xc0\xc6\x1c\x70\xc6\x06",
/* 0x26 & */ (uint8_t *)"\x06\x5c\xfe\xb2\xfe\x4c\x1e",
/* 0x27 ' */ (uint8_t *)"\x01\xc0",
/* 0x28 ( */ (uint8_t *)"\x03\x38\x7c\x82",
/* 0x29 ) */ (uint8_t *)"\x03\x82\x7c\x38",
/* 0x2a * */ (uint8_t *)"\x05\x6c\x38\xfe\x38\x6c",
/* 0x2b + */ (uint8_t *)"\x05\x10\x10\x7c\x10\x10",
/* 0x2c , */ (uint8_t *)"\x02\x03\x06",
/* 0x2d - */ (uint8_t *)"\x04\x10\x10\x10\x10",
/* 0x2e . */ (uint8_t *)"\x02\x06\x06",
/* 0x2f / */ (uint8_t *)"\x03\x0e\x38\xe0",
/* 0x30 0 */ (uint8_t *)"\x05\x7c\xfe\x82\xfe\x7c",
/* 0x31 1 */ (uint8_t *)"\x03\x40\xfe\xfe",
/* 0x32 2 */ (uint8_t *)"\x05\x8e\x9e\x92\xf2\x62",
/* 0x33 3 */ (uint8_t *)"\x05\x82\x92\x92\xfe\x6c",
/* 0x34 4 */ (uint8_t *)"\x05\x18\x28\x48\xfe\xfe",
/* 0x35 5 */ (uint8_t *)"\x05\xe2\xa2\xa2\xbe\x1c",
/* 0x36 6 */ (uint8_t *)"\x05\x7c\xfe\xa2\xbe\x1c",
/* 0x37 7 */ (uint8_t *)"\x05\x80\x8e\xbe\xf0\xc0",
/* 0x38 8 */ (uint8_t *)"\x05\x6c\xfe\x92\xfe\x6c",
/* 0x39 9 */ (uint8_t *)"\x05\x70\xfa\x8a\xfe\x7c",
/* 0x3a : */ (uint8_t *)"\x02\x36\x36",
/* 0x3b ; */ (uint8_t *)"\x02\x33\x36",
/* 0x3c < */ (uint8_t *)"\x04\x10\x38\x6c\xc6",
/* 0x3d = */ (uint8_t *)"\x04\x28\x28\x28\x28",
/* 0x3e > */ (uint8_t *)"\x04\xc6\x6c\x38\x10",
/* 0x3f ? */ (uint8_t *)"\x05\x80\x9a\xba\xe0\x40",
/* 0x40 @ */ (uint8_t *)"\x06\x7c\xfe\xaa\xba\xfa\x78",
/* 0x41 A */ (uint8_t *)"\x05\x7e\xfe\x88\xfe\x7e",
/* 0x42 B */ (uint8_t *)"\x05\xfe\xfe\xa2\xfe\x5c",
/* 0x43 C */ (uint8_t *)"\x05\x7c\xfe\x82\x82\x82",
/* 0x44 D */ (uint8_t *)"\x05\xfe\xfe\x82\xfe\x7c",
/* 0x45 E */ (uint8_t *)"\x05\xfe\xfe\xa2\xa2\x82",
/* 0x46 F */ (uint8_t *)"\x05\xfe\xfe\xa0\xa0\x80",
/* 0x47 G */ (uint8_t *)"\x05\x7c\xfe\x82\x9e\x1e",
/* 0x48 H */ (uint8_t *)"\x05\xfe\xfe\x20\xfe\xfe",
/* 0x49 I */ (uint8_t *)"\x02\xfe\xfe",
/* 0x4a J */ (uint8_t *)"\x04\x02\x02\xfe\xfc",
/* 0x4b K */ (uint8_t *)"\x06\xfe\xfe\x38\x6c\xc6\x82",
/* 0x4c L */ (uint8_t *)"\x04\xfe\xfe\x02\x02",
/* 0x4d M */ (uint8_t *)"\x07\xfe\x7e\x30\x18\x30\x7e\xfe",
/* 0x4e N */ (uint8_t *)"\x06\xfe\x7e\x30\x18\xfc\xfe",
/* 0x4f O */ (uint8_t *)"\x06\x7c\xfe\x82\x82\xfe\x7c",
/* 0x50 P */ (uint8_t *)"\x05\xfe\xfe\x88\xf8\x70",
/* 0x51 Q */ (uint8_t *)"\x06\x7c\xfe\x82\x86\xff\x7d",
/* 0x52 R */ (uint8_t *)"\x05\xfe\xfe\x88\xfe\x72",
/* 0x53 S */ (uint8_t *)"\x04\x62\xf2\x9e\x8c",
/* 0x54 T */ (uint8_t *)"\x06\x80\x80\xfe\xfe\x80\x80",
/* 0x55 U */ (uint8_t *)"\x05\xfc\xfe\x02\xfe\xfc",
/* 0x56 V */ (uint8_t *)"\x06\xe0\xf8\x1e\x1e\xf8\xe0",
/* 0x57 W */ (uint8_t *)"\x07\xf0\xfe\x1e\x3c\x1e\xfe\xf0",
/* 0x58 X */ (uint8_t *)"\x06\xc6\xee\x38\x38\xee\xc6",
/* 0x59 Y */ (uint8_t *)"\x06\xc0\xe0\x3e\x3e\xe0\xc0",
/* 0x5a Z */ (uint8_t *)"\x05\x8e\x9e\xba\xf2\xe2",
/* 0x5b [ */ (uint8_t *)"\x03\xfe\xfe\x82",
/* 0x5c \ */ (uint8_t *)"\x03\xe0\x38\x0e",
/* 0x5d ] */ (uint8_t *)"\x03\x82\xfe\xfe",
/* 0x5e ^ */ (uint8_t *)"\x03\x60\xc0\x60",
/* 0x5f _ */ (uint8_t *)"\x06\x02\x02\x02\x02\x02\x02",
/* 0x60 ` */ (uint8_t *)"\x02\x80\x40",
/* 0x61 a */ (uint8_t *)"\x05\x04\x2e\x2a\x3e\x1e",
/* 0x62 b */ (uint8_t *)"\x05\xfe\xfe\x22\x3e\x1c",
/* 0x63 c */ (uint8_t *)"\x04\x1c\x3e\x22\x22",
/* 0x64 d */ (uint8_t *)"\x05\x1c\x3e\x22\xfe\xfe",
/* 0x65 e */ (uint8_t *)"\x05\x1c\x3e\x2a\x3a\x1a",
/* 0x66 f */ (uint8_t *)"\x03\x7e\xfe\xa0",
/* 0x67 g */ (uint8_t *)"\x05\x18\x3d\x25\x3f\x3e",
/* 0x68 h */ (uint8_t *)"\x05\xfe\xfe\x20\x3e\x1e",
/* 0x69 i */ (uint8_t *)"\x02\xbe\xbe",
/* 0x6a j */ (uint8_t *)"\x03\x01\xbf\xbe",
/* 0x6b k */ (uint8_t *)"\x05\xfe\xfe\x1c\x36\x22",
/* 0x6c l */ (uint8_t *)"\x02\xfe\xfe",
/* 0x6d m */ (uint8_t *)"\x08\x3e\x3e\x20\x3e\x3e\x20\x3e\x1e",
/* 0x6e n */ (uint8_t *)"\x05\x3e\x3e\x20\x3e\x1e",
/* 0x6f o */ (uint8_t *)"\x05\x1c\x3e\x22\x3e\x1c",
/* 0x70 p */ (uint8_t *)"\x05\x3f\x3f\x24\x3c\x18",
/* 0x71 q */ (uint8_t *)"\x05\x18\x3c\x24\x3f\x3f",
/* 0x72 r */ (uint8_t *)"\x04\x3e\x3e\x10\x30",
/* 0x73 s */ (uint8_t *)"\x04\x1a\x3a\x2e\x2c",
/* 0x74 t */ (uint8_t *)"\x03\xfc\xfe\x22",
/* 0x75 u */ (uint8_t *)"\x05\x3c\x3e\x02\x3e\x3e",
/* 0x76 v */ (uint8_t *)"\x05\x30\x3c\x0e\x3c\x30",
/* 0x77 w */ (uint8_t *)"\x07\x38\x3e\x06\x1c\x06\x3e\x38",
/* 0x78 x */ (uint8_t *)"\x05\x36\x3e\x08\x3e\x36",
/* 0x79 y */ (uint8_t *)"\x05\x38\x3d\x05\x3f\x3e",
/* 0x7a z */ (uint8_t *)"\x05\x26\x2e\x3a\x32\x22",
/* 0x7b { */ (uint8_t *)"\x04\x10\x7c\xee\x82",
/* 0x7c | */ (uint8_t *)"\x02\xff\xff",
/* 0x7d } */ (uint8_t *)"\x04\x82\xee\x7c\x10",
/* 0x7e ~ */ (uint8_t *)"\x04\x08\x10\x08\x10",
/* 0x7f _ */ (uint8_t *)"\x01\x00",
/* 0x80 _ */ (uint8_t *)"\x01\x00",
/* 0x81 _ */ (uint8_t *)"\x01\x00",
/* 0x82 _ */ (uint8_t *)"\x01\x00",
/* 0x83 _ */ (uint8_t *)"\x01\x00",
/* 0x84 _ */ (uint8_t *)"\x01\x00",
/* 0x85 _ */ (uint8_t *)"\x01\x00",
/* 0x86 _ */ (uint8_t *)"\x01\x00",
/* 0x87 _ */ (uint8_t *)"\x01\x00",
/* 0x88 _ */ (uint8_t *)"\x01\x00",
/* 0x89 _ */ (uint8_t *)"\x01\x00",
/* 0x8a _ */ (uint8_t *)"\x01\x00",
/* 0x8b _ */ (uint8_t *)"\x01\x00",
/* 0x8c _ */ (uint8_t *)"\x01\x00",
/* 0x8d _ */ (uint8_t *)"\x01\x00",
/* 0x8e _ */ (uint8_t *)"\x01\x00",
/* 0x8f _ */ (uint8_t *)"\x01\x00",
/* 0x90 _ */ (uint8_t *)"\x01\x00",
/* 0x91 _ */ (uint8_t *)"\x01\x00",
/* 0x92 _ */ (uint8_t *)"\x01\x00",
/* 0x93 _ */ (uint8_t *)"\x01\x00",
/* 0x94 _ */ (uint8_t *)"\x01\x00",
/* 0x95 _ */ (uint8_t *)"\x01\x00",
/* 0x96 _ */ (uint8_t *)"\x01\x00",
/* 0x97 _ */ (uint8_t *)"\x01\x00",
/* 0x98 _ */ (uint8_t *)"\x01\x00",
/* 0x99 _ */ (uint8_t *)"\x01\x00",
/* 0x9a _ */ (uint8_t *)"\x01\x00",
/* 0x9b _ */ (uint8_t *)"\x01\x00",
/* 0x9c _ */ (uint8_t *)"\x01\x00",
/* 0x9d _ */ (uint8_t *)"\x01\x00",
/* 0x9e _ */ (uint8_t *)"\x01\x00",
/* 0x9f _ */ (uint8_t *)"\x01\x00",
/* 0xa0 _ */ (uint8_t *)"\x01\x00",
/* 0xa1 _ */ (uint8_t *)"\x01\x00",
/* 0xa2 _ */ (uint8_t *)"\x01\x00",
/* 0xa3 _ */ (uint8_t *)"\x01\x00",
/* 0xa4 _ */ (uint8_t *)"\x01\x00",
/* 0xa5 _ */ (uint8_t *)"\x01\x00",
/* 0xa6 _ */ (uint8_t *)"\x01\x00",
/* 0xa7 _ */ (uint8_t *)"\x01\x00",
/* 0xa8 _ */ (uint8_t *)"\x01\x00",
/* 0xa9 _ */ (uint8_t *)"\x01\x00",
/* 0xaa _ */ (uint8_t *)"\x01\x00",
/* 0xab _ */ (uint8_t *)"\x01\x00",
/* 0xac _ */ (uint8_t *)"\x01\x00",
/* 0xad _ */ (uint8_t *)"\x01\x00",
/* 0xae _ */ (uint8_t *)"\x01\x00",
/* 0xaf _ */ (uint8_t *)"\x01\x00",
/* 0xb0 _ */ (uint8_t *)"\x01\x00",
/* 0xb1 _ */ (uint8_t *)"\x01\x00",
/* 0xb2 _ */ (uint8_t *)"\x01\x00",
/* 0xb3 _ */ (uint8_t *)"\x01\x00",
/* 0xb4 _ */ (uint8_t *)"\x01\x00",
/* 0xb5 _ */ (uint8_t *)"\x01\x00",
/* 0xb6 _ */ (uint8_t *)"\x01\x00",
/* 0xb7 _ */ (uint8_t *)"\x01\x00",
/* 0xb8 _ */ (uint8_t *)"\x01\x00",
/* 0xb9 _ */ (uint8_t *)"\x01\x00",
/* 0xba _ */ (uint8_t *)"\x01\x00",
/* 0xbb _ */ (uint8_t *)"\x01\x00",
/* 0xbc _ */ (uint8_t *)"\x01\x00",
/* 0xbd _ */ (uint8_t *)"\x01\x00",
/* 0xbe _ */ (uint8_t *)"\x01\x00",
/* 0xbf _ */ (uint8_t *)"\x01\x00",
/* 0xc0 _ */ (uint8_t *)"\x01\x00",
/* 0xc1 _ */ (uint8_t *)"\x01\x00",
/* 0xc2 _ */ (uint8_t *)"\x01\x00",
/* 0xc3 _ */ (uint8_t *)"\x01\x00",
/* 0xc4 _ */ (uint8_t *)"\x01\x00",
/* 0xc5 _ */ (uint8_t *)"\x01\x00",
/* 0xc6 _ */ (uint8_t *)"\x01\x00",
/* 0xc7 _ */ (uint8_t *)"\x01\x00",
/* 0xc8 _ */ (uint8_t *)"\x01\x00",
/* 0xc9 _ */ (uint8_t *)"\x01\x00",
/* 0xca _ */ (uint8_t *)"\x01\x00",
/* 0xcb _ */ (uint8_t *)"\x01\x00",
/* 0xcc _ */ (uint8_t *)"\x01\x00",
/* 0xcd _ */ (uint8_t *)"\x01\x00",
/* 0xce _ */ (uint8_t *)"\x01\x00",
/* 0xcf _ */ (uint8_t *)"\x01\x00",
/* 0xd0 _ */ (uint8_t *)"\x01\x00",
/* 0xd1 _ */ (uint8_t *)"\x01\x00",
/* 0xd2 _ */ (uint8_t *)"\x01\x00",
/* 0xd3 _ */ (uint8_t *)"\x01\x00",
/* 0xd4 _ */ (uint8_t *)"\x01\x00",
/* 0xd5 _ */ (uint8_t *)"\x01\x00",
/* 0xd6 _ */ (uint8_t *)"\x01\x00",
/* 0xd7 _ */ (uint8_t *)"\x01\x00",
/* 0xd8 _ */ (uint8_t *)"\x01\x00",
/* 0xd9 _ */ (uint8_t *)"\x01\x00",
/* 0xda _ */ (uint8_t *)"\x01\x00",
/* 0xdb _ */ (uint8_t *)"\x01\x00",
/* 0xdc _ */ (uint8_t *)"\x01\x00",
/* 0xdd _ */ (uint8_t *)"\x01\x00",
/* 0xde _ */ (uint8_t *)"\x01\x00",
/* 0xdf _ */ (uint8_t *)"\x01\x00",
/* 0xe0 _ */ (uint8_t *)"\x01\x00",
/* 0xe1 _ */ (uint8_t *)"\x01\x00",
/* 0xe2 _ */ (uint8_t *)"\x01\x00",
/* 0xe3 _ */ (uint8_t *)"\x01\x00",
/* 0xe4 _ */ (uint8_t *)"\x01\x00",
/* 0xe5 _ */ (uint8_t *)"\x01\x00",
/* 0xe6 _ */ (uint8_t *)"\x01\x00",
/* 0xe7 _ */ (uint8_t *)"\x01\x00",
/* 0xe8 _ */ (uint8_t *)"\x01\x00",
/* 0xe9 _ */ (uint8_t *)"\x01\x00",
/* 0xea _ */ (uint8_t *)"\x01\x00",
/* 0xeb _ */ (uint8_t *)"\x01\x00",
/* 0xec _ */ (uint8_t *)"\x01\x00",
/* 0xed _ */ (uint8_t *)"\x01\x00",
/* 0xee _ */ (uint8_t *)"\x01\x00",
/* 0xef _ */ (uint8_t *)"\x01\x00",
/* 0xf0 _ */ (uint8_t *)"\x01\x00",
/* 0xf1 _ */ (uint8_t *)"\x01\x00",
/* 0xf2 _ */ (uint8_t *)"\x01\x00",
/* 0xf3 _ */ (uint8_t *)"\x01\x00",
/* 0xf4 _ */ (uint8_t *)"\x01\x00",
/* 0xf5 _ */ (uint8_t *)"\x01\x00",
/* 0xf6 _ */ (uint8_t *)"\x01\x00",
/* 0xf7 _ */ (uint8_t *)"\x01\x00",
/* 0xf8 _ */ (uint8_t *)"\x01\x00",
/* 0xf9 _ */ (uint8_t *)"\x01\x00",
/* 0xfa _ */ (uint8_t *)"\x01\x00",
/* 0xfb _ */ (uint8_t *)"\x01\x00",
/* 0xfc _ */ (uint8_t *)"\x01\x00",
/* 0xfd _ */ (uint8_t *)"\x01\x00",
/* 0xfe _ */ (uint8_t *)"\x07\x44\xee\x7c\x38\x7c\xee\x44",
/* 0xff _ */ (uint8_t *)"\x07\x18\x1c\x0e\x18\x30\x40\x80",
};
int fontCharWidth(char c) {
if ((c < FONT_START) || (c > FONT_END)) {
c = '?';
}
return font_data[(int)(c - FONT_START)][0];
return font_data[(int)(c)][0];
}
int fontStringWidth(const char *s) {
if (!s) return 0;
int l = 0;
char *c;
for (c = (char *)s; *c; c++) {
l += fontCharWidth(*c) + 1;
}
return l;
const uint8_t *fontCharData(char c) {
return font_data[(int)(c)] + 1;
}

View File

@ -3,13 +3,11 @@
#include <stdint.h>
#define FONT_START 32
#define FONT_END 132
#define FONT_HEIGHT 8
int fontCharWidth(char c);
int fontStringWidth(const char *s);
extern const uint8_t *font_data[256];
extern const uint8_t *font_data[FONT_END - FONT_START + 1];
int fontCharWidth(char c);
const uint8_t *fontCharData(char c);
#endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -20,12 +20,15 @@ class Img(object):
img = Img('font.png')
cur = ''
idx = 0
for i in range(img.w):
if img.pixel(i, 0) == None:
cur = '\\x%02x' % (len(cur) / 4) + cur
print '\t(uint8_t *)"%s",' % cur
ch = chr(idx) if idx >= 32 and idx <= 126 else '_'
print '\t/* 0x%02x %c */ (uint8_t *)"%s",' % (idx, ch , cur)
cur = ''
idx += 1
continue
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' % int(val, 2)

View File

@ -67,14 +67,14 @@ void layoutDialog(LayoutDialogIcon icon, const char *btnNo, const char *btnYes,
}
}
if (btnNo) {
oledDrawString(1, OLED_HEIGHT - 8, "\x80");
oledDrawString(fontCharWidth('\x80') + 3, OLED_HEIGHT - 8, btnNo);
oledInvert(0, OLED_HEIGHT - 9, fontCharWidth('\x80') + fontStringWidth(btnNo) + 2, OLED_HEIGHT - 1);
oledDrawString(1, OLED_HEIGHT - 8, "\xfe");
oledDrawString(fontCharWidth('\xfe') + 3, OLED_HEIGHT - 8, btnNo);
oledInvert(0, OLED_HEIGHT - 9, fontCharWidth('\xfe') + oledStringWidth(btnNo) + 2, OLED_HEIGHT - 1);
}
if (btnYes) {
oledDrawString(OLED_WIDTH - fontCharWidth('\x81') - 1, OLED_HEIGHT - 8, "\x81");
oledDrawString(OLED_WIDTH - fontStringWidth(btnYes) - fontCharWidth('\x81') - 3, OLED_HEIGHT - 8, btnYes);
oledInvert(OLED_WIDTH - fontStringWidth(btnYes) - fontCharWidth('\x81') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
oledDrawString(OLED_WIDTH - fontCharWidth('\xff') - 1, OLED_HEIGHT - 8, "\xff");
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 3, OLED_HEIGHT - 8, btnYes);
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\xff') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
}
oledRefresh();
}

39
oled.c
View File

@ -189,51 +189,52 @@ void oledClearPixel(int x, int y)
void oledDrawChar(int x, int y, char c)
{
uint8_t width, *column;
int char_width;
const uint8_t *char_data;
if ((x >= OLED_WIDTH) || (y >= OLED_HEIGHT)) return;
if (c < FONT_START) {
c = ' ';
}
if (c > FONT_END) {
c = '_';
}
width = font_data[(int)(c - FONT_START)][0];
column = (uint8_t *)(font_data[(int)(c - FONT_START)] + 1);
char_width = fontCharWidth(c);
char_data = fontCharData(c);
int xoffset, yoffset;
for (xoffset = 0; xoffset < width; xoffset++) {
for (xoffset = 0; xoffset < char_width; xoffset++) {
for (yoffset = 0; yoffset < FONT_HEIGHT; yoffset++) {
if (column[xoffset] & (1 << (FONT_HEIGHT - 1 - yoffset))) {
if (char_data[xoffset] & (1 << (FONT_HEIGHT - 1 - yoffset))) {
oledDrawPixel(x + xoffset, y + yoffset);
}
}
}
}
int oledStringWidth(const char *text) {
if (!text) return 0;
int l = 0;
for (; *text; text++) {
l += fontCharWidth(*text) + 1;
}
return l;
}
void oledDrawString(int x, int y, const char* text)
{
if (!text) return;
const char *c;
int l = 0;
for (c = text; *c; c++) {
oledDrawChar(x + l, y, *c);
l += fontCharWidth(*c) + 1;
for (; *text; text++) {
oledDrawChar(x + l, y, *text);
l += fontCharWidth(*text) + 1;
}
}
void oledDrawStringCenter(int y, const char* text)
{
int x = ( OLED_WIDTH - fontStringWidth(text) ) / 2;
int x = ( OLED_WIDTH - oledStringWidth(text) ) / 2;
oledDrawString(x, y, text);
}
void oledDrawStringRight(int x, int y, const char* text)
{
x -= fontStringWidth(text);
x -= oledStringWidth(text);
oledDrawString(x, y, text);
}

1
oled.h
View File

@ -39,6 +39,7 @@ const uint8_t *oledGetBuffer(void);
void oledDrawPixel(int x, int y);
void oledClearPixel(int x, int y);
void oledDrawChar(int x, int y, char c);
int oledStringWidth(const char *text);
void oledDrawString(int x, int y, const char* text);
void oledDrawStringCenter(int y, const char* text);
void oledDrawStringRight(int x, int y, const char* text);