mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +00:00
modtrezorui: add display_btext
This commit is contained in:
parent
3d89dc8085
commit
1d5a6dd1b4
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "inflate.h"
|
||||
#include "font_bitmap.h"
|
||||
#include "font_robotomono_regular_20.h"
|
||||
#include "font_roboto_regular_20.h"
|
||||
#include "font_roboto_bold_20.h"
|
||||
@ -238,6 +239,33 @@ static const uint8_t *get_glyph(uint8_t font, uint8_t c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// display text using bitmap font
|
||||
void display_btext(int x, int y, const char *text, int textlen, uint16_t color)
|
||||
{
|
||||
// determine text length if not provided
|
||||
if (textlen < 0) {
|
||||
textlen = strlen(text);
|
||||
}
|
||||
|
||||
for (int i = 0; i < textlen; i++) {
|
||||
char c = text[i];
|
||||
if (c < ' ' || c >= 0x80) c = ' ';
|
||||
const uint8_t *g = Font_Bitmap + (5 * (c - ' '));
|
||||
display_set_window(x + i * 6, y, x + i * 6 + 4, y + 7);
|
||||
for (int j = 0; j < 8; j++) {
|
||||
for (int k = 0; k < 5; k++) {
|
||||
if (g[k] & (1 << j)) {
|
||||
DATA(color >> 8);
|
||||
DATA(color & 0xFF);
|
||||
} else {
|
||||
DATA(0x00);
|
||||
DATA(0x00);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// first two bytes are width and height of the glyph
|
||||
// third, fourth and fifth bytes are advance, bearingX and bearingY of the horizontal metrics of the glyph
|
||||
// rest is packed 4-bit glyph data
|
||||
|
@ -35,6 +35,7 @@ void display_image(int x, int y, int w, int h, const void *data, int datalen);
|
||||
void display_icon(int x, int y, int w, int h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale);
|
||||
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);
|
||||
void display_btext(int x, int y, const char *text, int textlen, uint16_t color);
|
||||
void display_text(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_text_center(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_text_right(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
|
||||
|
99
micropython/extmod/modtrezorui/font_bitmap.c
Normal file
99
micropython/extmod/modtrezorui/font_bitmap.c
Normal file
@ -0,0 +1,99 @@
|
||||
#include "font_bitmap.h"
|
||||
|
||||
const uint8_t *Font_Bitmap = (const uint8_t *)
|
||||
"\x00\x00\x00\x00\x00"
|
||||
"\x00\x00\x5f\x00\x00"
|
||||
"\x00\x07\x00\x07\x00"
|
||||
"\x14\x7f\x14\x7f\x14"
|
||||
"\x24\x2a\x7f\x2a\x12"
|
||||
"\x23\x13\x08\x64\x62"
|
||||
"\x36\x49\x56\x20\x50"
|
||||
"\x00\x08\x07\x03\x00"
|
||||
"\x00\x1c\x22\x41\x00"
|
||||
"\x00\x41\x22\x1c\x00"
|
||||
"\x2a\x1c\x7f\x1c\x2a"
|
||||
"\x08\x08\x3e\x08\x08"
|
||||
"\x00\x80\x70\x30\x00"
|
||||
"\x08\x08\x08\x08\x08"
|
||||
"\x00\x00\x60\x60\x00"
|
||||
"\x20\x10\x08\x04\x02"
|
||||
"\x3e\x51\x49\x45\x3e"
|
||||
"\x00\x42\x7f\x40\x00"
|
||||
"\x72\x49\x49\x49\x46"
|
||||
"\x21\x41\x49\x4d\x33"
|
||||
"\x18\x14\x12\x7f\x10"
|
||||
"\x27\x45\x45\x45\x39"
|
||||
"\x3c\x4a\x49\x49\x31"
|
||||
"\x41\x21\x11\x09\x07"
|
||||
"\x36\x49\x49\x49\x36"
|
||||
"\x46\x49\x49\x29\x1e"
|
||||
"\x00\x00\x14\x00\x00"
|
||||
"\x00\x40\x34\x00\x00"
|
||||
"\x00\x08\x14\x22\x41"
|
||||
"\x14\x14\x14\x14\x14"
|
||||
"\x00\x41\x22\x14\x08"
|
||||
"\x02\x01\x59\x09\x06"
|
||||
"\x3e\x41\x5d\x59\x4e"
|
||||
"\x7c\x12\x11\x12\x7c"
|
||||
"\x7f\x49\x49\x49\x36"
|
||||
"\x3e\x41\x41\x41\x22"
|
||||
"\x7f\x41\x41\x41\x3e"
|
||||
"\x7f\x49\x49\x49\x41"
|
||||
"\x7f\x09\x09\x09\x01"
|
||||
"\x3e\x41\x41\x51\x73"
|
||||
"\x7f\x08\x08\x08\x7f"
|
||||
"\x00\x41\x7f\x41\x00"
|
||||
"\x20\x40\x41\x3f\x01"
|
||||
"\x7f\x08\x14\x22\x41"
|
||||
"\x7f\x40\x40\x40\x40"
|
||||
"\x7f\x02\x1c\x02\x7f"
|
||||
"\x7f\x04\x08\x10\x7f"
|
||||
"\x3e\x41\x41\x41\x3e"
|
||||
"\x7f\x09\x09\x09\x06"
|
||||
"\x3e\x41\x51\x21\x5e"
|
||||
"\x7f\x09\x19\x29\x46"
|
||||
"\x26\x49\x49\x49\x32"
|
||||
"\x03\x01\x7f\x01\x03"
|
||||
"\x3f\x40\x40\x40\x3f"
|
||||
"\x1f\x20\x40\x20\x1f"
|
||||
"\x3f\x40\x38\x40\x3f"
|
||||
"\x63\x14\x08\x14\x63"
|
||||
"\x03\x04\x78\x04\x03"
|
||||
"\x61\x59\x49\x4d\x43"
|
||||
"\x00\x7f\x41\x41\x41"
|
||||
"\x02\x04\x08\x10\x20"
|
||||
"\x00\x41\x41\x41\x7f"
|
||||
"\x04\x02\x01\x02\x04"
|
||||
"\x40\x40\x40\x40\x40"
|
||||
"\x00\x03\x07\x08\x00"
|
||||
"\x20\x54\x54\x78\x40"
|
||||
"\x7f\x28\x44\x44\x38"
|
||||
"\x38\x44\x44\x44\x28"
|
||||
"\x38\x44\x44\x28\x7f"
|
||||
"\x38\x54\x54\x54\x18"
|
||||
"\x00\x08\x7e\x09\x02"
|
||||
"\x18\xa4\xa4\x9c\x78"
|
||||
"\x7f\x08\x04\x04\x78"
|
||||
"\x00\x44\x7d\x40\x00"
|
||||
"\x20\x40\x40\x3d\x00"
|
||||
"\x7f\x10\x28\x44\x00"
|
||||
"\x00\x41\x7f\x40\x00"
|
||||
"\x7c\x04\x78\x04\x78"
|
||||
"\x7c\x08\x04\x04\x78"
|
||||
"\x38\x44\x44\x44\x38"
|
||||
"\xfc\x18\x24\x24\x18"
|
||||
"\x18\x24\x24\x18\xfc"
|
||||
"\x7c\x08\x04\x04\x08"
|
||||
"\x48\x54\x54\x54\x24"
|
||||
"\x04\x04\x3f\x44\x24"
|
||||
"\x3c\x40\x40\x20\x7c"
|
||||
"\x1c\x20\x40\x20\x1c"
|
||||
"\x3c\x40\x30\x40\x3c"
|
||||
"\x44\x28\x10\x28\x44"
|
||||
"\x4c\x90\x90\x90\x7c"
|
||||
"\x44\x64\x54\x4c\x44"
|
||||
"\x00\x08\x36\x41\x00"
|
||||
"\x00\x00\x77\x00\x00"
|
||||
"\x00\x41\x36\x08\x00"
|
||||
"\x02\x01\x02\x04\x02"
|
||||
"\x3c\x26\x23\x26\x3c";
|
3
micropython/extmod/modtrezorui/font_bitmap.h
Normal file
3
micropython/extmod/modtrezorui/font_bitmap.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include <stdint.h>
|
||||
|
||||
const uint8_t *Font_Bitmap;
|
@ -126,6 +126,23 @@ STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_icon_obj, 6, 6, mod_TrezorUi_Display_icon);
|
||||
|
||||
/// def trezor.ui.display.btext(x: int, y: int, text: bytes, color: int) -> None:
|
||||
/// '''
|
||||
/// Renders text using 5x8 bitmap font at position (x,y) using color
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_btext(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t text;
|
||||
mp_get_buffer_raise(args[3], &text, MP_BUFFER_READ);
|
||||
mp_int_t color = mp_obj_get_int(args[4]);
|
||||
if (text.len > 0) {
|
||||
display_btext(x, y, text.buf, text.len, color);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_btext_obj, 5, 5, mod_TrezorUi_Display_btext);
|
||||
|
||||
/// def trezor.ui.display.text(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None:
|
||||
/// '''
|
||||
/// Renders left-aligned text at position (x,y) where x is left position and y is baseline.
|
||||
@ -376,6 +393,7 @@ STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_bar_radius), MP_ROM_PTR(&mod_TrezorUi_Display_bar_radius_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_image), MP_ROM_PTR(&mod_TrezorUi_Display_image_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_icon), MP_ROM_PTR(&mod_TrezorUi_Display_icon_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_btext), MP_ROM_PTR(&mod_TrezorUi_Display_btext_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_TrezorUi_Display_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text_center), MP_ROM_PTR(&mod_TrezorUi_Display_text_center_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text_right), MP_ROM_PTR(&mod_TrezorUi_Display_text_right_obj) },
|
||||
|
2
vendor/micropython
vendored
2
vendor/micropython
vendored
@ -1 +1 @@
|
||||
Subproject commit d9efa985b2fa14f9794ad2f2d574950df5649899
|
||||
Subproject commit a47b3052f851cc70d5d7f181064ea43ea1ccc91f
|
Loading…
Reference in New Issue
Block a user