From 59f4dc31cb92d82f23b680e13c729b18dafdcea4 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 18 Sep 2024 12:12:07 +0200 Subject: [PATCH 1/5] refactor(core): separate concerns of FONT macros Introduce a new flag `_NAME` for each font and reduce the usage of `_ENABLE` flag to purely compilation guard. [no changelog] --- core/embed/lib/fonts/fonts.h | 67 +++++++++++++++++------------------- core/site_scons/tools.py | 3 +- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/core/embed/lib/fonts/fonts.h b/core/embed/lib/fonts/fonts.h index 2e4405e9035..5172346d97f 100644 --- a/core/embed/lib/fonts/fonts.h +++ b/core/embed/lib/fonts/fonts.h @@ -37,82 +37,79 @@ #ifdef TREZOR_FONT_NORMAL_ENABLE #define FONT_NORMAL (-1) #include TREZOR_FONT_NORMAL_INCLUDE -#define FONT_NORMAL_DATA TREZOR_FONT_NORMAL_ENABLE -#define FONT_NORMAL_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _HEIGHT) -#define FONT_NORMAL_MAX_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _MAX_HEIGHT) -#define FONT_NORMAL_BASELINE FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _BASELINE) +#define FONT_NORMAL_DATA TREZOR_FONT_NORMAL_NAME +#define FONT_NORMAL_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _HEIGHT) +#define FONT_NORMAL_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _MAX_HEIGHT) +#define FONT_NORMAL_BASELINE FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _BASELINE) #endif #ifdef TREZOR_FONT_BIG_ENABLE #include TREZOR_FONT_BIG_INCLUDE #define FONT_BIG (-4) -#define FONT_BIG_DATA TREZOR_FONT_BIG_ENABLE -#define FONT_BIG_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_ENABLE, _HEIGHT) -#define FONT_BIG_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_ENABLE, _MAX_HEIGHT) -#define FONT_BIG_BASELINE FONT_DEFINE(TREZOR_FONT_BIG_ENABLE, _BASELINE) +#define FONT_BIG_DATA TREZOR_FONT_BIG_NAME +#define FONT_BIG_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_NAME, _HEIGHT) +#define FONT_BIG_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_NAME, _MAX_HEIGHT) +#define FONT_BIG_BASELINE FONT_DEFINE(TREZOR_FONT_BIG_NAME, _BASELINE) #endif #ifdef TREZOR_FONT_DEMIBOLD_ENABLE #include TREZOR_FONT_DEMIBOLD_INCLUDE #define FONT_DEMIBOLD (-5) -#define FONT_DEMIBOLD_DATA TREZOR_FONT_DEMIBOLD_ENABLE -#define FONT_DEMIBOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_DEMIBOLD_ENABLE, _HEIGHT) +#define FONT_DEMIBOLD_DATA TREZOR_FONT_DEMIBOLD_NAME +#define FONT_DEMIBOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _HEIGHT) #define FONT_DEMIBOLD_MAX_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_DEMIBOLD_ENABLE, _MAX_HEIGHT) -#define FONT_DEMIBOLD_BASELINE \ - FONT_DEFINE(TREZOR_FONT_DEMIBOLD_ENABLE, _BASELINE) + FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _MAX_HEIGHT) +#define FONT_DEMIBOLD_BASELINE FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _BASELINE) #endif #ifdef TREZOR_FONT_SUB_ENABLE #include TREZOR_FONT_SUB_INCLUDE #define FONT_SUB (-8) -#define FONT_SUB_DATA TREZOR_FONT_SUB_ENABLE -#define FONT_SUB_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_ENABLE, _HEIGHT) -#define FONT_SUB_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_ENABLE, _MAX_HEIGHT) -#define FONT_SUB_BASELINE FONT_DEFINE(TREZOR_FONT_SUB_ENABLE, _BASELINE) +#define FONT_SUB_DATA TREZOR_FONT_SUB_NAME +#define FONT_SUB_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_NAME, _HEIGHT) +#define FONT_SUB_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_NAME, _MAX_HEIGHT) +#define FONT_SUB_BASELINE FONT_DEFINE(TREZOR_FONT_SUB_NAME, _BASELINE) #endif #ifdef TREZOR_FONT_MONO_ENABLE #include TREZOR_FONT_MONO_INCLUDE #define FONT_MONO (-3) -#define FONT_MONO_DATA TREZOR_FONT_MONO_ENABLE -#define FONT_MONO_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _HEIGHT) -#define FONT_MONO_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _MAX_HEIGHT) -#define FONT_MONO_BASELINE FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _BASELINE) +#define FONT_MONO_DATA TREZOR_FONT_MONO_NAME +#define FONT_MONO_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_NAME, _HEIGHT) +#define FONT_MONO_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_NAME, _MAX_HEIGHT) +#define FONT_MONO_BASELINE FONT_DEFINE(TREZOR_FONT_MONO_NAME, _BASELINE) #endif #ifdef TREZOR_FONT_BOLD_ENABLE #include TREZOR_FONT_BOLD_INCLUDE #define FONT_BOLD (-2) -#define FONT_BOLD_DATA TREZOR_FONT_BOLD_ENABLE -#define FONT_BOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _HEIGHT) -#define FONT_BOLD_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _MAX_HEIGHT) -#define FONT_BOLD_BASELINE FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _BASELINE) +#define FONT_BOLD_DATA TREZOR_FONT_BOLD_NAME +#define FONT_BOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _HEIGHT) +#define FONT_BOLD_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _MAX_HEIGHT) +#define FONT_BOLD_BASELINE FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _BASELINE) #endif #ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE #include TREZOR_FONT_NORMAL_UPPER_INCLUDE #define FONT_NORMAL_UPPER (-6) -#define FONT_NORMAL_UPPER_DATA TREZOR_FONT_NORMAL_UPPER_ENABLE +#define FONT_NORMAL_UPPER_DATA TREZOR_FONT_NORMAL_UPPER_NAME #define FONT_NORMAL_UPPER_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_ENABLE, _HEIGHT) + FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_NAME, _HEIGHT) #define FONT_NORMAL_UPPER_MAX_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_ENABLE, _MAX_HEIGHT) + FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_NAME, _MAX_HEIGHT) #define FONT_NORMAL_UPPER_BASELINE \ - FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_ENABLE, _BASELINE) + FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_NAME, _BASELINE) #endif #ifdef TREZOR_FONT_BOLD_UPPER_ENABLE #include TREZOR_FONT_BOLD_UPPER_INCLUDE #define FONT_BOLD_UPPER (-7) -#define FONT_BOLD_UPPER_DATA TREZOR_FONT_BOLD_UPPER_ENABLE -#define FONT_BOLD_UPPER_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_ENABLE, _HEIGHT) +#define FONT_BOLD_UPPER_DATA TREZOR_FONT_BOLD_UPPER_NAME +#define FONT_BOLD_UPPER_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_NAME, _HEIGHT) #define FONT_BOLD_UPPER_MAX_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_ENABLE, _MAX_HEIGHT) + FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_NAME, _MAX_HEIGHT) #define FONT_BOLD_UPPER_BASELINE \ - FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_ENABLE, _BASELINE) + FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_NAME, _BASELINE) #endif #define MAX_FONT_H(A, B) ((A) > (B) ? (A) : (B)) diff --git a/core/site_scons/tools.py b/core/site_scons/tools.py index 315ca5cef76..579ada8c090 100644 --- a/core/site_scons/tools.py +++ b/core/site_scons/tools.py @@ -16,7 +16,8 @@ def add_font( if font is not None: font_filename = font.replace("_upper", "").lower() defines += [ - "TREZOR_FONT_" + font_name + "_ENABLE=" + font, + "TREZOR_FONT_" + font_name + "_ENABLE", + "TREZOR_FONT_" + font_name + "_NAME=" + font, "TREZOR_FONT_" + font_name + '_INCLUDE=\\"' + font_filename + '.h\\"', ] sourcefile = "embed/lib/fonts/" + font_filename + ".c" From 9b718122f98335fe839a9135e870499c3276a774 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 18 Sep 2024 13:36:18 +0200 Subject: [PATCH 2/5] chore(core): remove unused constants [no changelog] --- core/embed/lib/buffers.c | 3 --- core/embed/lib/buffers.h | 3 --- 2 files changed, 6 deletions(-) diff --git a/core/embed/lib/buffers.c b/core/embed/lib/buffers.c index cbf53a322af..ee9ab114e56 100644 --- a/core/embed/lib/buffers.c +++ b/core/embed/lib/buffers.c @@ -22,9 +22,6 @@ #include "fonts/fonts.h" #include "memzero.h" -const int32_t text_buffer_height = FONT_MAX_HEIGHT; -const int32_t buffer_width = DISPLAY_RESX; - #define CONCAT_(a, b) a##b #define CONCAT(a, b) CONCAT_(a, b) diff --git a/core/embed/lib/buffers.h b/core/embed/lib/buffers.h index 03d00a79e57..37f5fa270a5 100644 --- a/core/embed/lib/buffers.h +++ b/core/embed/lib/buffers.h @@ -85,9 +85,6 @@ typedef __attribute__((aligned(4))) struct { uint16_t buffer[3][BUFFER_PIXELS]; } buffer_blurring_totals_t; -extern const int32_t text_buffer_height; -extern const int32_t buffer_width; - buffer_line_16bpp_t* buffers_get_line_16bpp(bool clear); void buffers_free_line_16bpp(buffer_line_16bpp_t* buffer); From 25cabd515d7e33f58b4b90d6d3700ac382ac3ab0 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 18 Sep 2024 15:02:20 +0200 Subject: [PATCH 3/5] refactor(core): simplify font handling This commit removes the usage of macros for font data definitions. Instead, it includes data as const structs of newly introduced font_info_t type. [no changelog] --- core/embed/lib/fonts/fonts.c | 245 ++++++++----------------- core/embed/lib/fonts/fonts.h | 160 +++------------- core/embed/lib/fonts/fonts_types.h | 35 ++++ core/embed/rust/src/ui/display/font.rs | 4 +- 4 files changed, 132 insertions(+), 312 deletions(-) create mode 100644 core/embed/lib/fonts/fonts_types.h diff --git a/core/embed/lib/fonts/fonts.c b/core/embed/lib/fonts/fonts.c index d2e6a739621..a1da435c3c7 100644 --- a/core/embed/lib/fonts/fonts.c +++ b/core/embed/lib/fonts/fonts.c @@ -22,124 +22,123 @@ #include #include #include +#include "fonts_types.h" #ifdef TRANSLATIONS #include "librust_fonts.h" #endif -#define UNICODE_BADCHAR 0xFFFD - -int font_height(int font) { - switch (font) { +// include selectively based on the SCons variables #ifdef TREZOR_FONT_NORMAL_ENABLE - case FONT_NORMAL: - return FONT_NORMAL_HEIGHT; +#include TREZOR_FONT_NORMAL_INCLUDE #endif #ifdef TREZOR_FONT_DEMIBOLD_ENABLE - case FONT_DEMIBOLD: - return FONT_DEMIBOLD_HEIGHT; +#include TREZOR_FONT_DEMIBOLD_INCLUDE #endif #ifdef TREZOR_FONT_BOLD_ENABLE - case FONT_BOLD: - return FONT_BOLD_HEIGHT; +#include TREZOR_FONT_BOLD_INCLUDE #endif #ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE - case FONT_NORMAL_UPPER: - return FONT_NORMAL_UPPER_HEIGHT; +#include TREZOR_FONT_NORMAL_UPPER_INCLUDE #endif #ifdef TREZOR_FONT_BOLD_UPPER_ENABLE - case FONT_BOLD_UPPER: - return FONT_BOLD_UPPER_HEIGHT; +#include TREZOR_FONT_BOLD_UPPER_INCLUDE #endif #ifdef TREZOR_FONT_MONO_ENABLE - case FONT_MONO: - return FONT_MONO_HEIGHT; +#include TREZOR_FONT_MONO_INCLUDE #endif #ifdef TREZOR_FONT_BIG_ENABLE - case FONT_BIG: - return FONT_BIG_HEIGHT; +#include TREZOR_FONT_BIG_INCLUDE #endif #ifdef TREZOR_FONT_SUB_ENABLE - case FONT_SUB: - return FONT_SUB_HEIGHT; +#include TREZOR_FONT_SUB_INCLUDE #endif - } - return 0; -} -int font_max_height(int font) { - switch (font) { +#define PASTER(font_name) font_name##_info +#define FONT_INFO(font_name) PASTER(font_name) + + +static const font_info_t *get_font_info(font_id_t font_id) { + switch (font_id) { #ifdef TREZOR_FONT_NORMAL_ENABLE case FONT_NORMAL: - return FONT_NORMAL_MAX_HEIGHT; -#endif -#ifdef TREZOR_FONT_DEMIBOLD_ENABLE - case FONT_DEMIBOLD: - return FONT_DEMIBOLD_MAX_HEIGHT; + return &FONT_INFO(TREZOR_FONT_NORMAL_NAME); #endif #ifdef TREZOR_FONT_BOLD_ENABLE case FONT_BOLD: - return FONT_BOLD_MAX_HEIGHT; -#endif -#ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE - case FONT_NORMAL_UPPER: - return FONT_NORMAL_UPPER_MAX_HEIGHT; + return &FONT_INFO(TREZOR_FONT_BOLD_NAME); #endif -#ifdef TREZOR_FONT_BOLD_UPPER_ENABLE - case FONT_BOLD_UPPER: - return FONT_BOLD_UPPER_MAX_HEIGHT; +#ifdef TREZOR_FONT_DEMIBOLD_ENABLE + case FONT_DEMIBOLD: + return &FONT_INFO(TREZOR_FONT_DEMIBOLD_NAME); #endif #ifdef TREZOR_FONT_MONO_ENABLE case FONT_MONO: - return FONT_MONO_MAX_HEIGHT; + return &FONT_INFO(TREZOR_FONT_MONO_NAME); #endif #ifdef TREZOR_FONT_BIG_ENABLE case FONT_BIG: - return FONT_BIG_MAX_HEIGHT; -#endif -#ifdef TREZOR_FONT_SUB_ENABLE - case FONT_SUB: - return FONT_SUB_MAX_HEIGHT; -#endif - } - return 0; -} - -int font_baseline(int font) { - switch (font) { -#ifdef TREZOR_FONT_NORMAL_ENABLE - case FONT_NORMAL: - return FONT_NORMAL_BASELINE; -#endif -#ifdef TREZOR_FONT_DEMIBOLD_ENABLE - case FONT_DEMIBOLD: - return FONT_DEMIBOLD_BASELINE; -#endif -#ifdef TREZOR_FONT_BOLD_ENABLE - case FONT_BOLD: - return FONT_BOLD_BASELINE; + return &FONT_INFO(TREZOR_FONT_BIG_NAME); #endif #ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE case FONT_NORMAL_UPPER: - return FONT_NORMAL_UPPER_BASELINE; + return &FONT_INFO(TREZOR_FONT_NORMAL_UPPER_NAME); #endif #ifdef TREZOR_FONT_BOLD_UPPER_ENABLE case FONT_BOLD_UPPER: - return FONT_BOLD_UPPER_BASELINE; -#endif -#ifdef TREZOR_FONT_MONO_ENABLE - case FONT_MONO: - return FONT_MONO_BASELINE; -#endif -#ifdef TREZOR_FONT_BIG_ENABLE - case FONT_BIG: - return FONT_BIG_BASELINE; + return &FONT_INFO(TREZOR_FONT_BOLD_UPPER_NAME); #endif #ifdef TREZOR_FONT_SUB_ENABLE case FONT_SUB: - return FONT_SUB_BASELINE; + return &FONT_INFO(TREZOR_FONT_SUB_NAME); #endif + default: + return NULL; } - return 0; +} + +int font_height(int font_id) { + const font_info_t *font_info = get_font_info(font_id); + return font_info ? font_info->height : 0; +} + +int font_max_height(int font) { + const font_info_t *font_info = get_font_info(font); + return font_info ? font_info->max_height : 0; +} + +int font_baseline(int font) { + const font_info_t *font_info = get_font_info(font); + return font_info ? font_info->baseline : 0; +} + +const uint8_t *font_get_glyph(int font, uint16_t c) { +#ifdef TRANSLATIONS + // found UTF8 character + // it is not hardcoded in firmware fonts, it must be extracted from the + // embedded blob + if (c >= 0x7F) { + const uint8_t *g = get_utf8_glyph(c, font); + if (g != NULL) { + return g; + } + } +#endif + + // printable ASCII character + if (c >= ' ' && c < 0x7F) { + const font_info_t *font_info = get_font_info(font); + if (font_info == NULL) { + return NULL; + } + return font_info->glyph_data[c - ' ']; + } + + return font_nonprintable_glyph(font); +} + +const uint8_t *font_nonprintable_glyph(int font) { + const font_info_t *font_info = get_font_info(font); + return font_info ? font_info->glyph_nonprintable : NULL; } font_glyph_iter_t font_glyph_iter_init(const int font, const uint8_t *text, @@ -151,6 +150,7 @@ font_glyph_iter_t font_glyph_iter_init(const int font, const uint8_t *text, }; } +#define UNICODE_BADCHAR 0xFFFD #define IS_UTF8_CONTINUE(c) (((c) & 0b11000000) == 0b10000000) static uint16_t next_utf8_codepoint(font_glyph_iter_t *iter) { @@ -211,103 +211,6 @@ bool font_next_glyph(font_glyph_iter_t *iter, const uint8_t **out) { } } -const uint8_t *font_nonprintable_glyph(int font) { -#define PASTER(s) s##_glyph_nonprintable -#define NONPRINTABLE_GLYPH(s) PASTER(s) - - switch (font) { -#ifdef TREZOR_FONT_NORMAL_ENABLE - case FONT_NORMAL: - return NONPRINTABLE_GLYPH(FONT_NORMAL_DATA); -#endif -#ifdef TREZOR_FONT_DEMIBOLD_ENABLE - case FONT_DEMIBOLD: - return NONPRINTABLE_GLYPH(FONT_DEMIBOLD_DATA); -#endif -#ifdef TREZOR_FONT_BOLD_ENABLE - case FONT_BOLD: - return NONPRINTABLE_GLYPH(FONT_BOLD_DATA); -#endif -#ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE - case FONT_NORMAL_UPPER: - return NONPRINTABLE_GLYPH(FONT_NORMAL_UPPER_DATA); -#endif -#ifdef TREZOR_FONT_BOLD_UPPER_ENABLE - case FONT_BOLD_UPPER: - return NONPRINTABLE_GLYPH(FONT_BOLD_UPPER_DATA); -#endif -#ifdef TREZOR_FONT_MONO_ENABLE - case FONT_MONO: - return NONPRINTABLE_GLYPH(FONT_MONO_DATA); -#endif -#ifdef TREZOR_FONT_BIG_ENABLE - case FONT_BIG: - return NONPRINTABLE_GLYPH(FONT_BIG_DATA); -#endif -#ifdef TREZOR_FONT_SUB_ENABLE - case FONT_SUB: - return NONPRINTABLE_GLYPH(FONT_SUB_DATA); -#endif - default: - return NULL; - } -} - -const uint8_t *font_get_glyph(int font, uint16_t c) { -#ifdef TRANSLATIONS - // found UTF8 character - // it is not hardcoded in firmware fonts, it must be extracted from the - // embedded blob - if (c >= 0x7F) { - const uint8_t *g = get_utf8_glyph(c, font); - if (g != NULL) { - return g; - } - } -#endif - - // printable ASCII character - if (c >= ' ' && c < 0x7F) { - switch (font) { -#ifdef TREZOR_FONT_NORMAL_ENABLE - case FONT_NORMAL: - return FONT_NORMAL_DATA[c - ' ']; -#endif -#ifdef TREZOR_FONT_DEMIBOLD_ENABLE - case FONT_DEMIBOLD: - return FONT_DEMIBOLD_DATA[c - ' ']; -#endif -#ifdef TREZOR_FONT_BOLD_ENABLE - case FONT_BOLD: - return FONT_BOLD_DATA[c - ' ']; -#endif -#ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE - case FONT_NORMAL_UPPER: - return FONT_NORMAL_UPPER_DATA[c - ' ']; -#endif -#ifdef TREZOR_FONT_BOLD_UPPER_ENABLE - case FONT_BOLD_UPPER: - return FONT_BOLD_UPPER_DATA[c - ' ']; -#endif -#ifdef TREZOR_FONT_MONO_ENABLE - case FONT_MONO: - return FONT_MONO_DATA[c - ' ']; -#endif -#ifdef TREZOR_FONT_BIG_ENABLE - case FONT_BIG: - return FONT_BIG_DATA[c - ' ']; -#endif -#ifdef TREZOR_FONT_SUB_ENABLE - case FONT_SUB: - return FONT_SUB_DATA[c - ' ']; -#endif - } - return 0; - } - - return font_nonprintable_glyph(font); -} - // compute the width of the text (in pixels) int font_text_width(int font, const char *text, int textlen) { int width = 0; diff --git a/core/embed/lib/fonts/fonts.h b/core/embed/lib/fonts/fonts.h index 5172346d97f..f8f5b14e9cb 100644 --- a/core/embed/lib/fonts/fonts.h +++ b/core/embed/lib/fonts/fonts.h @@ -23,6 +23,7 @@ #include #include "fonts/font_bitmap.h" +#include "fonts_types.h" #include TREZOR_BOARD #ifdef USE_RGB_COLORS @@ -31,140 +32,27 @@ #define TREZOR_FONT_BPP 1 #endif -#define COMPOSE(font_name, suffix) font_name##suffix -#define FONT_DEFINE(s, suffix) COMPOSE(s, suffix) - -#ifdef TREZOR_FONT_NORMAL_ENABLE -#define FONT_NORMAL (-1) -#include TREZOR_FONT_NORMAL_INCLUDE -#define FONT_NORMAL_DATA TREZOR_FONT_NORMAL_NAME -#define FONT_NORMAL_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _HEIGHT) -#define FONT_NORMAL_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _MAX_HEIGHT) -#define FONT_NORMAL_BASELINE FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _BASELINE) -#endif - -#ifdef TREZOR_FONT_BIG_ENABLE -#include TREZOR_FONT_BIG_INCLUDE -#define FONT_BIG (-4) -#define FONT_BIG_DATA TREZOR_FONT_BIG_NAME -#define FONT_BIG_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_NAME, _HEIGHT) -#define FONT_BIG_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_NAME, _MAX_HEIGHT) -#define FONT_BIG_BASELINE FONT_DEFINE(TREZOR_FONT_BIG_NAME, _BASELINE) -#endif - -#ifdef TREZOR_FONT_DEMIBOLD_ENABLE -#include TREZOR_FONT_DEMIBOLD_INCLUDE -#define FONT_DEMIBOLD (-5) -#define FONT_DEMIBOLD_DATA TREZOR_FONT_DEMIBOLD_NAME -#define FONT_DEMIBOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _HEIGHT) -#define FONT_DEMIBOLD_MAX_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _MAX_HEIGHT) -#define FONT_DEMIBOLD_BASELINE FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _BASELINE) -#endif - -#ifdef TREZOR_FONT_SUB_ENABLE -#include TREZOR_FONT_SUB_INCLUDE -#define FONT_SUB (-8) -#define FONT_SUB_DATA TREZOR_FONT_SUB_NAME -#define FONT_SUB_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_NAME, _HEIGHT) -#define FONT_SUB_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_NAME, _MAX_HEIGHT) -#define FONT_SUB_BASELINE FONT_DEFINE(TREZOR_FONT_SUB_NAME, _BASELINE) -#endif - -#ifdef TREZOR_FONT_MONO_ENABLE -#include TREZOR_FONT_MONO_INCLUDE -#define FONT_MONO (-3) -#define FONT_MONO_DATA TREZOR_FONT_MONO_NAME -#define FONT_MONO_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_NAME, _HEIGHT) -#define FONT_MONO_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_NAME, _MAX_HEIGHT) -#define FONT_MONO_BASELINE FONT_DEFINE(TREZOR_FONT_MONO_NAME, _BASELINE) -#endif - -#ifdef TREZOR_FONT_BOLD_ENABLE -#include TREZOR_FONT_BOLD_INCLUDE -#define FONT_BOLD (-2) -#define FONT_BOLD_DATA TREZOR_FONT_BOLD_NAME -#define FONT_BOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _HEIGHT) -#define FONT_BOLD_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _MAX_HEIGHT) -#define FONT_BOLD_BASELINE FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _BASELINE) -#endif - -#ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE -#include TREZOR_FONT_NORMAL_UPPER_INCLUDE -#define FONT_NORMAL_UPPER (-6) -#define FONT_NORMAL_UPPER_DATA TREZOR_FONT_NORMAL_UPPER_NAME -#define FONT_NORMAL_UPPER_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_NAME, _HEIGHT) -#define FONT_NORMAL_UPPER_MAX_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_NAME, _MAX_HEIGHT) -#define FONT_NORMAL_UPPER_BASELINE \ - FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_NAME, _BASELINE) -#endif - -#ifdef TREZOR_FONT_BOLD_UPPER_ENABLE -#include TREZOR_FONT_BOLD_UPPER_INCLUDE -#define FONT_BOLD_UPPER (-7) -#define FONT_BOLD_UPPER_DATA TREZOR_FONT_BOLD_UPPER_NAME -#define FONT_BOLD_UPPER_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_NAME, _HEIGHT) -#define FONT_BOLD_UPPER_MAX_HEIGHT \ - FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_NAME, _MAX_HEIGHT) -#define FONT_BOLD_UPPER_BASELINE \ - FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_NAME, _BASELINE) -#endif - +// Calculate the maximum height across all enabled fonts at compile time #define MAX_FONT_H(A, B) ((A) > (B) ? (A) : (B)) - -#define FONT_MAX_HEIGHT_1 0 -#ifdef TREZOR_FONT_NORMAL_ENABLE -#define FONT_MAX_HEIGHT_2 MAX_FONT_H(FONT_NORMAL_MAX_HEIGHT, FONT_MAX_HEIGHT_1) -#else -#define FONT_MAX_HEIGHT_2 FONT_MAX_HEIGHT_1 -#endif - -#ifdef TREZOR_FONT_BOLD_ENABLE -#define FONT_MAX_HEIGHT_3 MAX_FONT_H(FONT_BOLD_MAX_HEIGHT, FONT_MAX_HEIGHT_2) -#else -#define FONT_MAX_HEIGHT_3 FONT_MAX_HEIGHT_2 -#endif - -#ifdef TREZOR_FONT_BIG_ENABLE -#define FONT_MAX_HEIGHT_4 MAX_FONT_H(FONT_BIG_MAX_HEIGHT, FONT_MAX_HEIGHT_3) -#else -#define FONT_MAX_HEIGHT_4 FONT_MAX_HEIGHT_3 -#endif - -#ifdef TREZOR_FONT_DEMIBOLD_ENABLE -#define FONT_MAX_HEIGHT_5 \ - MAX_FONT_H(FONT_DEMIBOLD_MAX_HEIGHT, FONT_MAX_HEIGHT_4) -#else -#define FONT_MAX_HEIGHT_5 FONT_MAX_HEIGHT_4 -#endif - -#ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE -#define FONT_MAX_HEIGHT_6 \ - MAX_FONT_H(FONT_NORMAL_UPPER_MAX_HEIGHT, FONT_MAX_HEIGHT_5) -#else -#define FONT_MAX_HEIGHT_6 FONT_MAX_HEIGHT_5 -#endif - -#ifdef TREZOR_FONT_BOLD_UPPER_ENABLE -#define FONT_MAX_HEIGHT_7 \ - MAX_FONT_H(FONT_BOLD_UPPER_MAX_HEIGHT, FONT_MAX_HEIGHT_6) -#else -#define FONT_MAX_HEIGHT_7 FONT_MAX_HEIGHT_6 -#endif - -#ifdef TREZOR_FONT_SUB_ENABLE -#define FONT_MAX_HEIGHT_8 MAX_FONT_H(FONT_SUB_MAX_HEIGHT, FONT_MAX_HEIGHT_7) -#else -#define FONT_MAX_HEIGHT_8 FONT_MAX_HEIGHT_7 -#endif - -#ifdef TREZOR_FONT_MONO_ENABLE -#define FONT_MAX_HEIGHT MAX_FONT_H(FONT_MONO_MAX_HEIGHT, FONT_MAX_HEIGHT_8) -#else -#define FONT_MAX_HEIGHT FONT_MAX_HEIGHT_8 -#endif +// clang-format off +#define FONT_MAX_HEIGHT \ + MAX_FONT_H( \ + MAX_FONT_H( \ + MAX_FONT_H( \ + MAX_FONT_H( \ + MAX_FONT_H( \ + MAX_FONT_H( \ + MAX_FONT_H( \ + MAX_FONT_H(0, \ + TREZOR_FONT_NORMAL_ENABLE ? FONT_NORMAL_MAX_HEIGHT : 0), \ + TREZOR_FONT_BOLD_ENABLE ? FONT_BOLD_MAX_HEIGHT : 0), \ + TREZOR_FONT_BIG_ENABLE ? FONT_BIG_MAX_HEIGHT : 0), \ + TREZOR_FONT_DEMIBOLD_ENABLE ? FONT_DEMIBOLD_MAX_HEIGHT : 0), \ + TREZOR_FONT_NORMAL_UPPER_ENABLE ? FONT_NORMAL_UPPER_MAX_HEIGHT : 0), \ + TREZOR_FONT_BOLD_UPPER_ENABLE ? FONT_BOLD_UPPER_MAX_HEIGHT : 0), \ + TREZOR_FONT_SUB_ENABLE ? FONT_SUB_MAX_HEIGHT : 0), \ + TREZOR_FONT_MONO_ENABLE ? FONT_MONO_MAX_HEIGHT : 0) +// clang-format on int font_height(int font); int font_max_height(int font); @@ -172,12 +60,6 @@ int font_baseline(int font); const uint8_t *font_get_glyph(int font, uint16_t c); const uint8_t *font_nonprintable_glyph(int font); -typedef struct { - const int font; - const uint8_t *text; - int remaining; -} font_glyph_iter_t; - font_glyph_iter_t font_glyph_iter_init(const int font, const uint8_t *text, const int len); bool font_next_glyph(font_glyph_iter_t *iter, const uint8_t **out); diff --git a/core/embed/lib/fonts/fonts_types.h b/core/embed/lib/fonts/fonts_types.h new file mode 100644 index 00000000000..7b5ec3866d0 --- /dev/null +++ b/core/embed/lib/fonts/fonts_types.h @@ -0,0 +1,35 @@ +#ifndef _FONTS_TYPES_H +#define _FONTS_TYPES_H + +#include + +/// Font information structure containing metadata and pointers to font data +typedef struct { + const char* name; + int height; + int max_height; + int baseline; + const uint8_t* const* glyph_data; + const uint8_t* glyph_nonprintable; +} font_info_t; + +/// Font identifiers +typedef enum { + FONT_NORMAL = -1, + FONT_BOLD = -2, + FONT_MONO = -3, + FONT_BIG = -4, + FONT_DEMIBOLD = -5, + FONT_NORMAL_UPPER = -6, + FONT_BOLD_UPPER = -7, + FONT_SUB = -8, +} font_id_t; + +/// Font glyph iterator structure +typedef struct { + const int font; + const uint8_t* text; + int remaining; +} font_glyph_iter_t; + +#endif // _FONTS_TYPES_H diff --git a/core/embed/rust/src/ui/display/font.rs b/core/embed/rust/src/ui/display/font.rs index fd410a43bff..96a6341f30d 100644 --- a/core/embed/rust/src/ui/display/font.rs +++ b/core/embed/rust/src/ui/display/font.rs @@ -142,8 +142,8 @@ impl Glyph { } } -/// Font constants. Keep in sync with FONT_ definitions in -/// `core/embed/lib/fonts/fonts.h`. +/// Font constants. Keep in sync with `font_id_t` definition in +/// `core/embed/lib/fonts/fonts_types.h`. #[derive(Copy, Clone, PartialEq, Eq, FromPrimitive)] #[repr(u8)] #[allow(non_camel_case_types)] From 6e50231a648bef9ad0d5dae3d031812995f0d5bf Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 18 Sep 2024 16:21:57 +0200 Subject: [PATCH 4/5] refactor(core): change gen_font.py and regen fonts Change to the new structures and preserve manual changes. This commit also removes duplicated definition of nonprintable glyph for _UPPER fonts. [no changelog] --- .../lib/fonts/font_pixeloperator_bold_8.c | 25 ++++-- .../lib/fonts/font_pixeloperator_bold_8.h | 12 +-- .../lib/fonts/font_pixeloperator_regular_8.c | 25 ++++-- .../lib/fonts/font_pixeloperator_regular_8.h | 12 +-- .../fonts/font_pixeloperatormono_regular_8.c | 14 +++- .../fonts/font_pixeloperatormono_regular_8.h | 7 +- core/embed/lib/fonts/font_roboto_bold_20.c | 13 ++- core/embed/lib/fonts/font_roboto_bold_20.h | 7 +- core/embed/lib/fonts/font_roboto_regular_20.c | 13 ++- core/embed/lib/fonts/font_roboto_regular_20.h | 7 +- .../lib/fonts/font_robotomono_medium_20.c | 13 ++- .../lib/fonts/font_robotomono_medium_20.h | 7 +- .../lib/fonts/font_robotomono_medium_21.c | 13 ++- .../lib/fonts/font_robotomono_medium_21.h | 7 +- core/embed/lib/fonts/font_tthoves_bold_17.c | 13 ++- core/embed/lib/fonts/font_tthoves_bold_17.h | 7 +- .../lib/fonts/font_tthoves_demibold_21.c | 13 ++- .../lib/fonts/font_tthoves_demibold_21.h | 7 +- .../embed/lib/fonts/font_tthoves_regular_21.c | 13 ++- .../embed/lib/fonts/font_tthoves_regular_21.h | 7 +- .../lib/fonts/font_ttsatoshi_demibold_18.c | 14 +++- .../lib/fonts/font_ttsatoshi_demibold_18.h | 7 +- .../lib/fonts/font_ttsatoshi_demibold_21.c | 13 ++- .../lib/fonts/font_ttsatoshi_demibold_21.h | 7 +- .../lib/fonts/font_ttsatoshi_demibold_42.c | 15 +++- .../lib/fonts/font_ttsatoshi_demibold_42.h | 7 +- core/embed/lib/fonts/font_unifont_bold_16.c | 13 ++- core/embed/lib/fonts/font_unifont_bold_16.h | 7 +- .../embed/lib/fonts/font_unifont_regular_16.c | 13 ++- .../embed/lib/fonts/font_unifont_regular_16.h | 7 +- core/embed/lib/fonts/fonts_types.h | 1 - core/tools/codegen/gen_font.py | 82 +++++++++---------- 32 files changed, 271 insertions(+), 150 deletions(-) diff --git a/core/embed/lib/fonts/font_pixeloperator_bold_8.c b/core/embed/lib/fonts/font_pixeloperator_bold_8.c index 76c6ce16b91..25bdbab6ff6 100644 --- a/core/embed/lib/fonts/font_pixeloperator_bold_8.c +++ b/core/embed/lib/fonts/font_pixeloperator_bold_8.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -106,11 +107,9 @@ /* } */ static const uint8_t Font_PixelOperator_Bold_8_glyph_125[] = { 5, 7, 6, 0, 7, 225, 140, 51, 27, 128 }; /* ~ */ static const uint8_t Font_PixelOperator_Bold_8_glyph_126[] = { 7, 2, 8, 0, 7, 119, 184 }; -/* ? */ const uint8_t Font_PixelOperator_Bold_8_glyph_nonprintable[] = { 6, 7, 7, 0, 7, 132, 207, 57, 207, 252, 255 }; +/* ? */ static const uint8_t Font_PixelOperator_Bold_8_glyph_nonprintable[] = { 6, 7, 7, 0, 7, 132, 207, 57, 207, 252, 255 }; -/* ? */ const uint8_t Font_PixelOperator_Bold_8_upper_glyph_nonprintable[] = { 6, 7, 7, 0, 7, 132, 207, 57, 207, 252, 255 }; - -const uint8_t * const Font_PixelOperator_Bold_8[126 + 1 - 32] = { +static const uint8_t * const Font_PixelOperator_Bold_8[126 + 1 - 32] = { Font_PixelOperator_Bold_8_glyph_32, Font_PixelOperator_Bold_8_glyph_33, Font_PixelOperator_Bold_8_glyph_34, @@ -208,7 +207,7 @@ const uint8_t * const Font_PixelOperator_Bold_8[126 + 1 - 32] = { Font_PixelOperator_Bold_8_glyph_126, }; -const uint8_t * const Font_PixelOperator_Bold_8_upper[126 + 1 - 32] = { +static const uint8_t * const Font_PixelOperator_Bold_8_upper[126 + 1 - 32] = { Font_PixelOperator_Bold_8_glyph_32, Font_PixelOperator_Bold_8_glyph_33, Font_PixelOperator_Bold_8_glyph_34, @@ -305,3 +304,19 @@ const uint8_t * const Font_PixelOperator_Bold_8_upper[126 + 1 - 32] = { Font_PixelOperator_Bold_8_glyph_125, Font_PixelOperator_Bold_8_glyph_126, }; + +const font_info_t Font_PixelOperator_Bold_8_info = { + .height = 8, + .max_height = 8, + .baseline = 1, + .glyph_data = Font_PixelOperator_Bold_8, + .glyph_nonprintable = Font_PixelOperator_Bold_8_glyph_nonprintable, +}; + +const font_info_t Font_PixelOperator_Bold_8_upper_info = { + .height = 8, + .max_height = 8, + .baseline = 1, + .glyph_data = Font_PixelOperator_Bold_8_upper, + .glyph_nonprintable = Font_PixelOperator_Bold_8_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_pixeloperator_bold_8.h b/core/embed/lib/fonts/font_pixeloperator_bold_8.h index d3b0f11a575..dd34b599feb 100644 --- a/core/embed/lib/fonts/font_pixeloperator_bold_8.h +++ b/core/embed/lib/fonts/font_pixeloperator_bold_8.h @@ -1,17 +1,13 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 1 #error Wrong TREZOR_FONT_BPP (expected 1) #endif -#define Font_PixelOperator_Bold_8_HEIGHT 8 + #define Font_PixelOperator_Bold_8_MAX_HEIGHT 8 -#define Font_PixelOperator_Bold_8_BASELINE 1 -extern const uint8_t* const Font_PixelOperator_Bold_8[126 + 1 - 32]; -extern const uint8_t Font_PixelOperator_Bold_8_glyph_nonprintable[]; -#define Font_PixelOperator_Bold_8_upper_HEIGHT 8 +extern const font_info_t Font_PixelOperator_Bold_8_info; #define Font_PixelOperator_Bold_8_upper_MAX_HEIGHT 8 -#define Font_PixelOperator_Bold_8_upper_BASELINE 1 -extern const uint8_t* const Font_PixelOperator_Bold_8_upper[126 + 1 - 32]; -extern const uint8_t Font_PixelOperator_Bold_8_upper_glyph_nonprintable[]; +extern const font_info_t Font_PixelOperator_Bold_8_upper_info; diff --git a/core/embed/lib/fonts/font_pixeloperator_regular_8.c b/core/embed/lib/fonts/font_pixeloperator_regular_8.c index 5f618133070..9bfb22b3f76 100644 --- a/core/embed/lib/fonts/font_pixeloperator_regular_8.c +++ b/core/embed/lib/fonts/font_pixeloperator_regular_8.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -106,11 +107,9 @@ /* } */ static const uint8_t Font_PixelOperator_Regular_8_glyph_125[] = { 4, 7, 6, 0, 7, 194, 33, 34, 192 }; /* ~ */ static const uint8_t Font_PixelOperator_Regular_8_glyph_126[] = { 6, 2, 7, 0, 7, 102, 96 }; -/* ? */ const uint8_t Font_PixelOperator_Regular_8_glyph_nonprintable[] = { 5, 7, 6, 0, 7, 139, 189, 221, 255, 127 }; +/* ? */ static const uint8_t Font_PixelOperator_Regular_8_glyph_nonprintable[] = { 5, 7, 6, 0, 7, 139, 189, 221, 255, 127 }; -/* ? */ const uint8_t Font_PixelOperator_Regular_8_upper_glyph_nonprintable[] = { 5, 7, 6, 0, 7, 139, 189, 221, 255, 127 }; - -const uint8_t * const Font_PixelOperator_Regular_8[126 + 1 - 32] = { +static const uint8_t * const Font_PixelOperator_Regular_8[126 + 1 - 32] = { Font_PixelOperator_Regular_8_glyph_32, Font_PixelOperator_Regular_8_glyph_33, Font_PixelOperator_Regular_8_glyph_34, @@ -208,7 +207,7 @@ const uint8_t * const Font_PixelOperator_Regular_8[126 + 1 - 32] = { Font_PixelOperator_Regular_8_glyph_126, }; -const uint8_t * const Font_PixelOperator_Regular_8_upper[126 + 1 - 32] = { +static const uint8_t * const Font_PixelOperator_Regular_8_upper[126 + 1 - 32] = { Font_PixelOperator_Regular_8_glyph_32, Font_PixelOperator_Regular_8_glyph_33, Font_PixelOperator_Regular_8_glyph_34, @@ -305,3 +304,19 @@ const uint8_t * const Font_PixelOperator_Regular_8_upper[126 + 1 - 32] = { Font_PixelOperator_Regular_8_glyph_125, Font_PixelOperator_Regular_8_glyph_126, }; + +const font_info_t Font_PixelOperator_Regular_8_info = { + .height = 8, + .max_height = 8, + .baseline = 1, + .glyph_data = Font_PixelOperator_Regular_8, + .glyph_nonprintable = Font_PixelOperator_Regular_8_glyph_nonprintable, +}; + +const font_info_t Font_PixelOperator_Regular_8_upper_info = { + .height = 8, + .max_height = 8, + .baseline = 1, + .glyph_data = Font_PixelOperator_Regular_8_upper, + .glyph_nonprintable = Font_PixelOperator_Regular_8_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_pixeloperator_regular_8.h b/core/embed/lib/fonts/font_pixeloperator_regular_8.h index 2565d879053..27212ca2052 100644 --- a/core/embed/lib/fonts/font_pixeloperator_regular_8.h +++ b/core/embed/lib/fonts/font_pixeloperator_regular_8.h @@ -1,17 +1,13 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 1 #error Wrong TREZOR_FONT_BPP (expected 1) #endif -#define Font_PixelOperator_Regular_8_HEIGHT 8 + #define Font_PixelOperator_Regular_8_MAX_HEIGHT 8 -#define Font_PixelOperator_Regular_8_BASELINE 1 -extern const uint8_t* const Font_PixelOperator_Regular_8[126 + 1 - 32]; -extern const uint8_t Font_PixelOperator_Regular_8_glyph_nonprintable[]; -#define Font_PixelOperator_Regular_8_upper_HEIGHT 8 +extern const font_info_t Font_PixelOperator_Regular_8_info; #define Font_PixelOperator_Regular_8_upper_MAX_HEIGHT 8 -#define Font_PixelOperator_Regular_8_upper_BASELINE 1 -extern const uint8_t* const Font_PixelOperator_Regular_8_upper[126 + 1 - 32]; -extern const uint8_t Font_PixelOperator_Regular_8_upper_glyph_nonprintable[]; +extern const font_info_t Font_PixelOperator_Regular_8_upper_info; diff --git a/core/embed/lib/fonts/font_pixeloperatormono_regular_8.c b/core/embed/lib/fonts/font_pixeloperatormono_regular_8.c index 0f8ea4e9cde..6676241ed56 100644 --- a/core/embed/lib/fonts/font_pixeloperatormono_regular_8.c +++ b/core/embed/lib/fonts/font_pixeloperatormono_regular_8.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -10,7 +11,6 @@ // NOTE: hand-changed all the advances with 8 to 7 // NOTE: hand-changed the visuals of "m", "w", "M" and "W" to make it narrower - /* */ static const uint8_t Font_PixelOperatorMono_Regular_8_glyph_32[] = { 0, 0, 7, 0, 0 }; // width hand-changed from 8 to 7 to have 9px space between words /* ! */ static const uint8_t Font_PixelOperatorMono_Regular_8_glyph_33[] = { 1, 7, 7, 2, 7, 250 }; /* " */ static const uint8_t Font_PixelOperatorMono_Regular_8_glyph_34[] = { 3, 3, 7, 1, 7, 182, 128 }; @@ -107,9 +107,9 @@ /* } */ static const uint8_t Font_PixelOperatorMono_Regular_8_glyph_125[] = { 4, 7, 7, 0, 7, 194, 33, 34, 192 }; /* ~ */ static const uint8_t Font_PixelOperatorMono_Regular_8_glyph_126[] = { 6, 2, 7, 0, 7, 102, 96 }; -/* ? */ const uint8_t Font_PixelOperatorMono_Regular_8_glyph_nonprintable[] = { 5, 7, 7, 0, 7, 139, 189, 221, 255, 127 }; +/* ? */ static const uint8_t Font_PixelOperatorMono_Regular_8_glyph_nonprintable[] = { 5, 7, 7, 0, 7, 139, 189, 221, 255, 127 }; -const uint8_t * const Font_PixelOperatorMono_Regular_8[126 + 1 - 32] = { +static const uint8_t * const Font_PixelOperatorMono_Regular_8[126 + 1 - 32] = { Font_PixelOperatorMono_Regular_8_glyph_32, Font_PixelOperatorMono_Regular_8_glyph_33, Font_PixelOperatorMono_Regular_8_glyph_34, @@ -206,3 +206,11 @@ const uint8_t * const Font_PixelOperatorMono_Regular_8[126 + 1 - 32] = { Font_PixelOperatorMono_Regular_8_glyph_125, Font_PixelOperatorMono_Regular_8_glyph_126, }; + +const font_info_t Font_PixelOperatorMono_Regular_8_info = { + .height = 8, + .max_height = 8, + .baseline = 1, + .glyph_data = Font_PixelOperatorMono_Regular_8, + .glyph_nonprintable = Font_PixelOperatorMono_Regular_8_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_pixeloperatormono_regular_8.h b/core/embed/lib/fonts/font_pixeloperatormono_regular_8.h index ce157770fd8..617064d32ef 100644 --- a/core/embed/lib/fonts/font_pixeloperatormono_regular_8.h +++ b/core/embed/lib/fonts/font_pixeloperatormono_regular_8.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 1 #error Wrong TREZOR_FONT_BPP (expected 1) #endif -#define Font_PixelOperatorMono_Regular_8_HEIGHT 8 + #define Font_PixelOperatorMono_Regular_8_MAX_HEIGHT 8 -#define Font_PixelOperatorMono_Regular_8_BASELINE 1 -extern const uint8_t* const Font_PixelOperatorMono_Regular_8[126 + 1 - 32]; -extern const uint8_t Font_PixelOperatorMono_Regular_8_glyph_nonprintable[]; +extern const font_info_t Font_PixelOperatorMono_Regular_8_info; diff --git a/core/embed/lib/fonts/font_roboto_bold_20.c b/core/embed/lib/fonts/font_roboto_bold_20.c index da87d94e854..6c94426447c 100644 --- a/core/embed/lib/fonts/font_roboto_bold_20.c +++ b/core/embed/lib/fonts/font_roboto_bold_20.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -104,9 +105,9 @@ /* } */ static const uint8_t Font_Roboto_Bold_20_glyph_125[] = { 7, 20, 7, 0, 16, 180, 3, 0, 0, 248, 79, 0, 0, 176, 239, 0, 0, 64, 255, 3, 0, 32, 255, 5, 0, 32, 255, 6, 0, 32, 255, 6, 0, 16, 255, 7, 0, 0, 252, 45, 0, 0, 210, 255, 2, 0, 210, 255, 2, 0, 252, 45, 0, 16, 255, 7, 0, 32, 255, 6, 0, 32, 255, 6, 0, 32, 255, 5, 0, 64, 255, 3, 0, 176, 239, 0, 0, 248, 79, 0, 0, 180, 3, 0, 0 }; /* ~ */ static const uint8_t Font_Roboto_Bold_20_glyph_126[] = { 11, 5, 13, 1, 8, 96, 254, 60, 0, 162, 9, 245, 255, 255, 6, 249, 12, 252, 108, 252, 255, 255, 6, 237, 3, 128, 255, 175, 0, 0, 0, 0, 65, 2, 0 }; -/* ? */ const uint8_t Font_Roboto_Bold_20_glyph_nonprintable[] = { 10, 14, 10, 0, 14, 255, 40, 16, 163, 255, 79, 0, 0, 0, 247, 11, 16, 137, 0, 240, 8, 160, 255, 5, 192, 255, 255, 255, 4, 208, 255, 255, 175, 0, 243, 255, 255, 10, 16, 253, 255, 239, 0, 209, 255, 255, 143, 0, 251, 255, 255, 111, 16, 255, 255, 255, 255, 255, 255, 255, 255, 159, 65, 255, 255, 255, 47, 0, 252, 255, 255, 143, 64, 255, 255 }; +/* ? */ static const uint8_t Font_Roboto_Bold_20_glyph_nonprintable[] = { 10, 14, 10, 0, 14, 255, 40, 16, 163, 255, 79, 0, 0, 0, 247, 11, 16, 137, 0, 240, 8, 160, 255, 5, 192, 255, 255, 255, 4, 208, 255, 255, 175, 0, 243, 255, 255, 10, 16, 253, 255, 239, 0, 209, 255, 255, 143, 0, 251, 255, 255, 111, 16, 255, 255, 255, 255, 255, 255, 255, 255, 159, 65, 255, 255, 255, 47, 0, 252, 255, 255, 143, 64, 255, 255 }; -const uint8_t * const Font_Roboto_Bold_20[126 + 1 - 32] = { +static const uint8_t * const Font_Roboto_Bold_20[126 + 1 - 32] = { Font_Roboto_Bold_20_glyph_32, Font_Roboto_Bold_20_glyph_33, Font_Roboto_Bold_20_glyph_34, @@ -203,3 +204,11 @@ const uint8_t * const Font_Roboto_Bold_20[126 + 1 - 32] = { Font_Roboto_Bold_20_glyph_125, Font_Roboto_Bold_20_glyph_126, }; + +const font_info_t Font_Roboto_Bold_20_info = { + .height = 20, + .max_height = 21, + .baseline = 4, + .glyph_data = Font_Roboto_Bold_20, + .glyph_nonprintable = Font_Roboto_Bold_20_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_roboto_bold_20.h b/core/embed/lib/fonts/font_roboto_bold_20.h index f922ba66008..a0016eb25a4 100644 --- a/core/embed/lib/fonts/font_roboto_bold_20.h +++ b/core/embed/lib/fonts/font_roboto_bold_20.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_Roboto_Bold_20_HEIGHT 20 + #define Font_Roboto_Bold_20_MAX_HEIGHT 21 -#define Font_Roboto_Bold_20_BASELINE 4 -extern const uint8_t* const Font_Roboto_Bold_20[126 + 1 - 32]; -extern const uint8_t Font_Roboto_Bold_20_glyph_nonprintable[]; +extern const font_info_t Font_Roboto_Bold_20_info; diff --git a/core/embed/lib/fonts/font_roboto_regular_20.c b/core/embed/lib/fonts/font_roboto_regular_20.c index f4370a6e6de..cc70bfe5aed 100644 --- a/core/embed/lib/fonts/font_roboto_regular_20.c +++ b/core/embed/lib/fonts/font_roboto_regular_20.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -104,9 +105,9 @@ /* } */ static const uint8_t Font_Roboto_Regular_20_glyph_125[] = { 7, 20, 7, 0, 16, 152, 1, 0, 0, 228, 29, 0, 0, 48, 159, 0, 0, 0, 238, 0, 0, 0, 252, 0, 0, 0, 252, 0, 0, 0, 252, 0, 0, 0, 250, 2, 0, 0, 244, 27, 0, 0, 112, 255, 1, 0, 209, 143, 0, 0, 248, 5, 0, 0, 251, 1, 0, 0, 252, 0, 0, 0, 252, 0, 0, 0, 252, 0, 0, 0, 222, 0, 0, 80, 143, 0, 0, 229, 29, 0, 0, 152, 1, 0, 0 }; /* ~ */ static const uint8_t Font_Roboto_Regular_20_glyph_126[] = { 12, 4, 14, 1, 8, 64, 253, 109, 0, 32, 59, 243, 173, 254, 43, 161, 31, 249, 1, 144, 255, 255, 7, 50, 0, 0, 115, 56, 0 }; -/* ? */ const uint8_t Font_Roboto_Regular_20_glyph_nonprintable[] = { 9, 14, 9, 0, 14, 255, 57, 16, 213, 255, 111, 16, 69, 16, 254, 14, 242, 255, 8, 247, 125, 250, 255, 12, 245, 255, 255, 255, 10, 248, 255, 255, 239, 1, 254, 255, 255, 46, 160, 255, 255, 255, 3, 250, 255, 255, 191, 96, 255, 255, 255, 143, 160, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 159, 160, 255, 255, 255, 159, 160, 255, 255 }; +/* ? */ static const uint8_t Font_Roboto_Regular_20_glyph_nonprintable[] = { 9, 14, 9, 0, 14, 255, 57, 16, 213, 255, 111, 16, 69, 16, 254, 14, 242, 255, 8, 247, 125, 250, 255, 12, 245, 255, 255, 255, 10, 248, 255, 255, 239, 1, 254, 255, 255, 46, 160, 255, 255, 255, 3, 250, 255, 255, 191, 96, 255, 255, 255, 143, 160, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 159, 160, 255, 255, 255, 159, 160, 255, 255 }; -const uint8_t * const Font_Roboto_Regular_20[126 + 1 - 32] = { +static const uint8_t * const Font_Roboto_Regular_20[126 + 1 - 32] = { Font_Roboto_Regular_20_glyph_32, Font_Roboto_Regular_20_glyph_33, Font_Roboto_Regular_20_glyph_34, @@ -203,3 +204,11 @@ const uint8_t * const Font_Roboto_Regular_20[126 + 1 - 32] = { Font_Roboto_Regular_20_glyph_125, Font_Roboto_Regular_20_glyph_126, }; + +const font_info_t Font_Roboto_Regular_20_info = { + .height = 20, + .max_height = 22, + .baseline = 5, + .glyph_data = Font_Roboto_Regular_20, + .glyph_nonprintable = Font_Roboto_Regular_20_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_roboto_regular_20.h b/core/embed/lib/fonts/font_roboto_regular_20.h index 8eeb5098378..706c0897788 100644 --- a/core/embed/lib/fonts/font_roboto_regular_20.h +++ b/core/embed/lib/fonts/font_roboto_regular_20.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_Roboto_Regular_20_HEIGHT 20 + #define Font_Roboto_Regular_20_MAX_HEIGHT 22 -#define Font_Roboto_Regular_20_BASELINE 5 -extern const uint8_t* const Font_Roboto_Regular_20[126 + 1 - 32]; -extern const uint8_t Font_Roboto_Regular_20_glyph_nonprintable[]; +extern const font_info_t Font_Roboto_Regular_20_info; diff --git a/core/embed/lib/fonts/font_robotomono_medium_20.c b/core/embed/lib/fonts/font_robotomono_medium_20.c index c08fc3fb0a4..58c0d363706 100644 --- a/core/embed/lib/fonts/font_robotomono_medium_20.c +++ b/core/embed/lib/fonts/font_robotomono_medium_20.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -104,9 +105,9 @@ /* } */ static const uint8_t Font_RobotoMono_Medium_20_glyph_125[] = { 7, 20, 12, 3, 16, 117, 1, 0, 0, 249, 30, 0, 0, 112, 175, 0, 0, 16, 255, 0, 0, 0, 255, 2, 0, 0, 255, 3, 0, 0, 255, 3, 0, 0, 254, 4, 0, 0, 248, 28, 0, 0, 144, 255, 11, 0, 144, 255, 10, 0, 248, 28, 0, 0, 254, 4, 0, 0, 255, 3, 0, 0, 255, 3, 0, 0, 255, 2, 0, 32, 255, 0, 0, 144, 159, 0, 0, 250, 29, 0, 0, 100, 0, 0, 0 }; /* ~ */ static const uint8_t Font_RobotoMono_Medium_20_glyph_126[] = { 12, 5, 12, 0, 8, 64, 237, 76, 0, 32, 22, 242, 255, 255, 8, 144, 63, 248, 6, 229, 239, 253, 14, 149, 0, 32, 251, 239, 3, 0, 0, 0, 16, 2, 0 }; -/* ? */ const uint8_t Font_RobotoMono_Medium_20_glyph_nonprintable[] = { 10, 16, 12, 1, 15, 255, 207, 153, 251, 255, 239, 3, 0, 16, 250, 47, 0, 102, 2, 208, 12, 176, 255, 14, 128, 174, 250, 255, 47, 112, 255, 255, 255, 13, 160, 255, 255, 255, 3, 242, 255, 255, 79, 16, 253, 255, 255, 5, 209, 255, 255, 255, 0, 251, 255, 255, 255, 34, 254, 255, 255, 255, 255, 255, 255, 255, 255, 153, 255, 255, 255, 175, 0, 250, 255, 255, 207, 0, 253, 255, 255, 255, 255, 255, 255 }; +/* ? */ static const uint8_t Font_RobotoMono_Medium_20_glyph_nonprintable[] = { 10, 16, 12, 1, 15, 255, 207, 153, 251, 255, 239, 3, 0, 16, 250, 47, 0, 102, 2, 208, 12, 176, 255, 14, 128, 174, 250, 255, 47, 112, 255, 255, 255, 13, 160, 255, 255, 255, 3, 242, 255, 255, 79, 16, 253, 255, 255, 5, 209, 255, 255, 255, 0, 251, 255, 255, 255, 34, 254, 255, 255, 255, 255, 255, 255, 255, 255, 153, 255, 255, 255, 175, 0, 250, 255, 255, 207, 0, 253, 255, 255, 255, 255, 255, 255 }; -const uint8_t * const Font_RobotoMono_Medium_20[126 + 1 - 32] = { +static const uint8_t * const Font_RobotoMono_Medium_20[126 + 1 - 32] = { Font_RobotoMono_Medium_20_glyph_32, Font_RobotoMono_Medium_20_glyph_33, Font_RobotoMono_Medium_20_glyph_34, @@ -203,3 +204,11 @@ const uint8_t * const Font_RobotoMono_Medium_20[126 + 1 - 32] = { Font_RobotoMono_Medium_20_glyph_125, Font_RobotoMono_Medium_20_glyph_126, }; + +const font_info_t Font_RobotoMono_Medium_20_info = { + .height = 20, + .max_height = 22, + .baseline = 5, + .glyph_data = Font_RobotoMono_Medium_20, + .glyph_nonprintable = Font_RobotoMono_Medium_20_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_robotomono_medium_20.h b/core/embed/lib/fonts/font_robotomono_medium_20.h index 7b43d298fcb..8ea21088ff1 100644 --- a/core/embed/lib/fonts/font_robotomono_medium_20.h +++ b/core/embed/lib/fonts/font_robotomono_medium_20.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_RobotoMono_Medium_20_HEIGHT 20 + #define Font_RobotoMono_Medium_20_MAX_HEIGHT 22 -#define Font_RobotoMono_Medium_20_BASELINE 5 -extern const uint8_t* const Font_RobotoMono_Medium_20[126 + 1 - 32]; -extern const uint8_t Font_RobotoMono_Medium_20_glyph_nonprintable[]; +extern const font_info_t Font_RobotoMono_Medium_20_info; diff --git a/core/embed/lib/fonts/font_robotomono_medium_21.c b/core/embed/lib/fonts/font_robotomono_medium_21.c index 50077e6ebd3..13b2bd9dc0c 100644 --- a/core/embed/lib/fonts/font_robotomono_medium_21.c +++ b/core/embed/lib/fonts/font_robotomono_medium_21.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -104,9 +105,9 @@ /* } */ static const uint8_t Font_RobotoMono_Medium_21_glyph_125[] = { 8, 21, 13, 3, 17, 66, 0, 0, 0, 248, 45, 0, 0, 128, 223, 0, 0, 0, 254, 4, 0, 0, 252, 7, 0, 0, 252, 8, 0, 0, 252, 8, 0, 0, 251, 9, 0, 0, 248, 12, 0, 0, 225, 175, 4, 0, 16, 253, 63, 0, 160, 239, 42, 0, 245, 30, 0, 0, 250, 9, 0, 0, 252, 8, 0, 0, 252, 8, 0, 0, 252, 8, 0, 0, 254, 5, 0, 80, 239, 0, 0, 246, 95, 0, 0, 148, 3, 0, 0 }; /* ~ */ static const uint8_t Font_RobotoMono_Medium_21_glyph_126[] = { 12, 6, 13, 0, 9, 0, 82, 3, 0, 0, 0, 128, 255, 207, 2, 0, 155, 244, 191, 254, 111, 97, 191, 248, 5, 144, 255, 255, 79, 98, 0, 0, 197, 239, 6, 0, 0, 0, 0, 0, 0 }; -/* ? */ const uint8_t Font_RobotoMono_Medium_21_glyph_nonprintable[] = { 11, 17, 13, 1, 16, 255, 255, 222, 254, 255, 255, 255, 42, 0, 32, 250, 255, 143, 0, 0, 0, 144, 255, 15, 48, 254, 46, 16, 255, 61, 195, 255, 143, 0, 255, 255, 255, 255, 143, 0, 255, 255, 255, 255, 30, 80, 255, 255, 255, 255, 3, 225, 255, 255, 255, 62, 16, 252, 255, 255, 255, 7, 208, 255, 255, 255, 255, 3, 246, 255, 255, 255, 255, 104, 251, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 105, 253, 255, 255, 255, 239, 0, 244, 255, 255, 255, 255, 2, 248, 255, 255, 255, 255, 239, 255, 255, 255 }; +/* ? */ static const uint8_t Font_RobotoMono_Medium_21_glyph_nonprintable[] = { 11, 17, 13, 1, 16, 255, 255, 222, 254, 255, 255, 255, 42, 0, 32, 250, 255, 143, 0, 0, 0, 144, 255, 15, 48, 254, 46, 16, 255, 61, 195, 255, 143, 0, 255, 255, 255, 255, 143, 0, 255, 255, 255, 255, 30, 80, 255, 255, 255, 255, 3, 225, 255, 255, 255, 62, 16, 252, 255, 255, 255, 7, 208, 255, 255, 255, 255, 3, 246, 255, 255, 255, 255, 104, 251, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 105, 253, 255, 255, 255, 239, 0, 244, 255, 255, 255, 255, 2, 248, 255, 255, 255, 255, 239, 255, 255, 255 }; -const uint8_t * const Font_RobotoMono_Medium_21[126 + 1 - 32] = { +static const uint8_t * const Font_RobotoMono_Medium_21[126 + 1 - 32] = { Font_RobotoMono_Medium_21_glyph_32, Font_RobotoMono_Medium_21_glyph_33, Font_RobotoMono_Medium_21_glyph_34, @@ -203,3 +204,11 @@ const uint8_t * const Font_RobotoMono_Medium_21[126 + 1 - 32] = { Font_RobotoMono_Medium_21_glyph_125, Font_RobotoMono_Medium_21_glyph_126, }; + +const font_info_t Font_RobotoMono_Medium_21_info = { + .height = 21, + .max_height = 23, + .baseline = 5, + .glyph_data = Font_RobotoMono_Medium_21, + .glyph_nonprintable = Font_RobotoMono_Medium_21_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_robotomono_medium_21.h b/core/embed/lib/fonts/font_robotomono_medium_21.h index 224fb3762a5..4323e09817c 100644 --- a/core/embed/lib/fonts/font_robotomono_medium_21.h +++ b/core/embed/lib/fonts/font_robotomono_medium_21.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_RobotoMono_Medium_21_HEIGHT 21 + #define Font_RobotoMono_Medium_21_MAX_HEIGHT 23 -#define Font_RobotoMono_Medium_21_BASELINE 5 -extern const uint8_t* const Font_RobotoMono_Medium_21[126 + 1 - 32]; -extern const uint8_t Font_RobotoMono_Medium_21_glyph_nonprintable[]; +extern const font_info_t Font_RobotoMono_Medium_21_info; diff --git a/core/embed/lib/fonts/font_tthoves_bold_17.c b/core/embed/lib/fonts/font_tthoves_bold_17.c index d8b3138e3ca..9f04a77653d 100644 --- a/core/embed/lib/fonts/font_tthoves_bold_17.c +++ b/core/embed/lib/fonts/font_tthoves_bold_17.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -78,9 +79,9 @@ /* } */ static const uint8_t Font_TTHoves_Bold_17_glyph_125[] = { 7, 17, 7, 0, 13, 65, 3, 0, 0, 246, 223, 1, 0, 246, 255, 10, 0, 16, 254, 13, 0, 0, 251, 13, 0, 0, 251, 13, 0, 0, 251, 14, 0, 0, 248, 207, 0, 0, 128, 255, 0, 0, 210, 255, 0, 0, 249, 127, 0, 0, 251, 14, 0, 0, 251, 13, 0, 0, 251, 13, 0, 81, 255, 12, 0, 246, 255, 8, 0, 246, 158, 0, 0 }; /* ~ */ static const uint8_t Font_TTHoves_Bold_17_glyph_126[] = { 10, 4, 10, 0, 7, 0, 98, 2, 0, 0, 128, 255, 159, 246, 143, 242, 255, 255, 255, 79, 245, 63, 180, 239, 7 }; -/* ? */ const uint8_t Font_TTHoves_Bold_17_upper_glyph_nonprintable[] = { 9, 12, 9, 0, 12, 255, 40, 32, 230, 255, 63, 0, 0, 16, 254, 10, 32, 39, 0, 248, 90, 213, 207, 0, 246, 255, 255, 95, 0, 249, 255, 223, 2, 96, 255, 255, 95, 0, 250, 255, 255, 47, 64, 255, 255, 255, 239, 238, 255, 255, 255, 63, 99, 255, 255, 255, 15, 48, 255, 255, 255, 15, 48, 255, 255 }; +/* ? */ static const uint8_t Font_TTHoves_Bold_17_glyph_nonprintable[] = { 9, 12, 9, 0, 12, 255, 40, 32, 230, 255, 63, 0, 0, 16, 254, 10, 32, 39, 0, 248, 90, 213, 207, 0, 246, 255, 255, 95, 0, 249, 255, 223, 2, 96, 255, 255, 95, 0, 250, 255, 255, 47, 64, 255, 255, 255, 239, 238, 255, 255, 255, 63, 99, 255, 255, 255, 15, 48, 255, 255, 255, 15, 48, 255, 255 }; -const uint8_t * const Font_TTHoves_Bold_17_upper[126 + 1 - 32] = { +static const uint8_t * const Font_TTHoves_Bold_17_upper[126 + 1 - 32] = { Font_TTHoves_Bold_17_glyph_32, Font_TTHoves_Bold_17_glyph_33, Font_TTHoves_Bold_17_glyph_34, @@ -177,3 +178,11 @@ const uint8_t * const Font_TTHoves_Bold_17_upper[126 + 1 - 32] = { Font_TTHoves_Bold_17_glyph_125, Font_TTHoves_Bold_17_glyph_126, }; + +const font_info_t Font_TTHoves_Bold_17_upper_info = { + .height = 17, + .max_height = 18, + .baseline = 4, + .glyph_data = Font_TTHoves_Bold_17_upper, + .glyph_nonprintable = Font_TTHoves_Bold_17_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_tthoves_bold_17.h b/core/embed/lib/fonts/font_tthoves_bold_17.h index 94ecd370d76..e90cf1c6a30 100644 --- a/core/embed/lib/fonts/font_tthoves_bold_17.h +++ b/core/embed/lib/fonts/font_tthoves_bold_17.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_TTHoves_Bold_17_upper_HEIGHT 17 + #define Font_TTHoves_Bold_17_upper_MAX_HEIGHT 18 -#define Font_TTHoves_Bold_17_upper_BASELINE 4 -extern const uint8_t* const Font_TTHoves_Bold_17_upper[126 + 1 - 32]; -extern const uint8_t Font_TTHoves_Bold_17_upper_glyph_nonprintable[]; +extern const font_info_t Font_TTHoves_Bold_17_upper_info; diff --git a/core/embed/lib/fonts/font_tthoves_demibold_21.c b/core/embed/lib/fonts/font_tthoves_demibold_21.c index de02f2ba80f..a72098be4e0 100644 --- a/core/embed/lib/fonts/font_tthoves_demibold_21.c +++ b/core/embed/lib/fonts/font_tthoves_demibold_21.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -104,9 +105,9 @@ /* } */ static const uint8_t Font_TTHoves_DemiBold_21_glyph_125[] = { 7, 20, 8, 0, 16, 97, 37, 0, 0, 244, 255, 8, 0, 244, 255, 47, 0, 0, 248, 79, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 242, 175, 1, 0, 160, 255, 12, 0, 0, 249, 12, 0, 208, 255, 10, 0, 243, 143, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 245, 95, 0, 97, 252, 79, 0, 244, 255, 14, 0, 244, 207, 3, 0 }; /* ~ */ static const uint8_t Font_TTHoves_DemiBold_21_glyph_126[] = { 12, 5, 12, 0, 8, 0, 215, 158, 1, 144, 73, 112, 255, 255, 61, 245, 111, 224, 255, 254, 255, 255, 47, 241, 143, 64, 254, 255, 9, 64, 37, 0, 113, 72, 0 }; -/* ? */ const uint8_t Font_TTHoves_DemiBold_21_glyph_nonprintable[] = { 11, 15, 11, 0, 15, 255, 93, 2, 98, 254, 255, 175, 0, 0, 0, 192, 255, 30, 0, 100, 2, 16, 255, 11, 80, 255, 63, 0, 252, 157, 217, 255, 127, 0, 250, 255, 255, 255, 30, 0, 253, 255, 255, 159, 0, 80, 255, 255, 255, 9, 0, 248, 255, 255, 255, 2, 176, 255, 255, 255, 255, 0, 244, 255, 255, 255, 255, 85, 249, 255, 255, 255, 255, 255, 255, 255, 255, 255, 239, 17, 245, 255, 255, 255, 239, 0, 244, 255, 255, 255, 239, 0, 244, 255, 255 }; +/* ? */ static const uint8_t Font_TTHoves_DemiBold_21_glyph_nonprintable[] = { 11, 15, 11, 0, 15, 255, 93, 2, 98, 254, 255, 175, 0, 0, 0, 192, 255, 30, 0, 100, 2, 16, 255, 11, 80, 255, 63, 0, 252, 157, 217, 255, 127, 0, 250, 255, 255, 255, 30, 0, 253, 255, 255, 159, 0, 80, 255, 255, 255, 9, 0, 248, 255, 255, 255, 2, 176, 255, 255, 255, 255, 0, 244, 255, 255, 255, 255, 85, 249, 255, 255, 255, 255, 255, 255, 255, 255, 255, 239, 17, 245, 255, 255, 255, 239, 0, 244, 255, 255, 255, 239, 0, 244, 255, 255 }; -const uint8_t * const Font_TTHoves_DemiBold_21[126 + 1 - 32] = { +static const uint8_t * const Font_TTHoves_DemiBold_21[126 + 1 - 32] = { Font_TTHoves_DemiBold_21_glyph_32, Font_TTHoves_DemiBold_21_glyph_33, Font_TTHoves_DemiBold_21_glyph_34, @@ -203,3 +204,11 @@ const uint8_t * const Font_TTHoves_DemiBold_21[126 + 1 - 32] = { Font_TTHoves_DemiBold_21_glyph_125, Font_TTHoves_DemiBold_21_glyph_126, }; + +const font_info_t Font_TTHoves_DemiBold_21_info = { + .height = 21, + .max_height = 21, + .baseline = 4, + .glyph_data = Font_TTHoves_DemiBold_21, + .glyph_nonprintable = Font_TTHoves_DemiBold_21_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_tthoves_demibold_21.h b/core/embed/lib/fonts/font_tthoves_demibold_21.h index bcaf664609d..faa91547140 100644 --- a/core/embed/lib/fonts/font_tthoves_demibold_21.h +++ b/core/embed/lib/fonts/font_tthoves_demibold_21.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_TTHoves_DemiBold_21_HEIGHT 21 + #define Font_TTHoves_DemiBold_21_MAX_HEIGHT 21 -#define Font_TTHoves_DemiBold_21_BASELINE 4 -extern const uint8_t* const Font_TTHoves_DemiBold_21[126 + 1 - 32]; -extern const uint8_t Font_TTHoves_DemiBold_21_glyph_nonprintable[]; +extern const font_info_t Font_TTHoves_DemiBold_21_info; diff --git a/core/embed/lib/fonts/font_tthoves_regular_21.c b/core/embed/lib/fonts/font_tthoves_regular_21.c index 2db8aae33cc..22ece349e97 100644 --- a/core/embed/lib/fonts/font_tthoves_regular_21.c +++ b/core/embed/lib/fonts/font_tthoves_regular_21.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -104,9 +105,9 @@ /* } */ static const uint8_t Font_TTHoves_Regular_21_glyph_125[] = { 6, 20, 7, 0, 16, 81, 3, 0, 244, 143, 0, 0, 250, 0, 0, 247, 1, 0, 247, 1, 0, 247, 1, 0, 247, 1, 0, 247, 1, 0, 246, 3, 0, 209, 77, 0, 48, 126, 0, 243, 25, 0, 247, 1, 0, 247, 1, 0, 247, 1, 0, 247, 1, 0, 247, 1, 0, 247, 1, 97, 237, 0, 244, 77, 0 }; /* ~ */ static const uint8_t Font_TTHoves_Regular_21_glyph_126[] = { 11, 4, 12, 0, 8, 0, 97, 21, 0, 48, 5, 64, 255, 239, 3, 208, 12, 192, 61, 211, 159, 251, 7, 224, 8, 0, 233, 142, 0 }; -/* ? */ const uint8_t Font_TTHoves_Regular_21_glyph_nonprintable[] = { 10, 15, 11, 0, 15, 255, 76, 17, 163, 255, 159, 0, 84, 1, 246, 14, 226, 255, 79, 176, 10, 250, 255, 239, 96, 239, 255, 255, 255, 64, 255, 255, 255, 207, 96, 255, 255, 255, 46, 192, 255, 255, 175, 1, 251, 255, 255, 10, 211, 255, 255, 255, 4, 254, 255, 255, 255, 19, 255, 255, 255, 255, 119, 255, 255, 255, 255, 255, 255, 255, 255, 255, 35, 255, 255, 255, 255, 1, 255, 255 }; +/* ? */ static const uint8_t Font_TTHoves_Regular_21_glyph_nonprintable[] = { 10, 15, 11, 0, 15, 255, 76, 17, 163, 255, 159, 0, 84, 1, 246, 14, 226, 255, 79, 176, 10, 250, 255, 239, 96, 239, 255, 255, 255, 64, 255, 255, 255, 207, 96, 255, 255, 255, 46, 192, 255, 255, 175, 1, 251, 255, 255, 10, 211, 255, 255, 255, 4, 254, 255, 255, 255, 19, 255, 255, 255, 255, 119, 255, 255, 255, 255, 255, 255, 255, 255, 255, 35, 255, 255, 255, 255, 1, 255, 255 }; -const uint8_t * const Font_TTHoves_Regular_21[126 + 1 - 32] = { +static const uint8_t * const Font_TTHoves_Regular_21[126 + 1 - 32] = { Font_TTHoves_Regular_21_glyph_32, Font_TTHoves_Regular_21_glyph_33, Font_TTHoves_Regular_21_glyph_34, @@ -203,3 +204,11 @@ const uint8_t * const Font_TTHoves_Regular_21[126 + 1 - 32] = { Font_TTHoves_Regular_21_glyph_125, Font_TTHoves_Regular_21_glyph_126, }; + +const font_info_t Font_TTHoves_Regular_21_info = { + .height = 21, + .max_height = 21, + .baseline = 4, + .glyph_data = Font_TTHoves_Regular_21, + .glyph_nonprintable = Font_TTHoves_Regular_21_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_tthoves_regular_21.h b/core/embed/lib/fonts/font_tthoves_regular_21.h index 82e48105fe9..c9cb109e5f9 100644 --- a/core/embed/lib/fonts/font_tthoves_regular_21.h +++ b/core/embed/lib/fonts/font_tthoves_regular_21.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_TTHoves_Regular_21_HEIGHT 21 + #define Font_TTHoves_Regular_21_MAX_HEIGHT 21 -#define Font_TTHoves_Regular_21_BASELINE 4 -extern const uint8_t* const Font_TTHoves_Regular_21[126 + 1 - 32]; -extern const uint8_t Font_TTHoves_Regular_21_glyph_nonprintable[]; +extern const font_info_t Font_TTHoves_Regular_21_info; diff --git a/core/embed/lib/fonts/font_ttsatoshi_demibold_18.c b/core/embed/lib/fonts/font_ttsatoshi_demibold_18.c index f46c501dab3..248df600fe5 100644 --- a/core/embed/lib/fonts/font_ttsatoshi_demibold_18.c +++ b/core/embed/lib/fonts/font_ttsatoshi_demibold_18.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -9,7 +10,6 @@ // - the rest is packed 4-bit glyph data // NOTE: numeral chars ('0','1',..,'9') mapped to alternative style glyphs contained in the font (glyph indices: 1298-1307) - /* */ static const uint8_t Font_TTSatoshi_DemiBold_18_glyph_32[] = { 0, 0, 5, 0, 0 }; /* ! */ static const uint8_t Font_TTSatoshi_DemiBold_18_glyph_33[] = { 3, 13, 5, 1, 13, 248, 12, 248, 12, 248, 12, 248, 12, 248, 12, 248, 11, 247, 10, 245, 8, 244, 7, 64, 1, 132, 6, 248, 12, 248, 12 }; /* " */ static const uint8_t Font_TTSatoshi_DemiBold_18_glyph_34[] = { 6, 5, 8, 1, 13, 254, 146, 127, 254, 146, 127, 254, 146, 127, 254, 146, 127, 34, 16, 18 }; @@ -106,9 +106,9 @@ /* } */ static const uint8_t Font_TTSatoshi_DemiBold_18_glyph_125[] = { 6, 18, 7, 0, 14, 0, 0, 0, 245, 159, 0, 245, 255, 5, 0, 252, 8, 0, 250, 9, 0, 250, 9, 0, 250, 9, 0, 249, 28, 0, 210, 223, 0, 128, 223, 0, 247, 110, 0, 250, 9, 0, 250, 9, 0, 250, 9, 0, 250, 9, 16, 253, 8, 245, 255, 5, 245, 142, 0 }; /* ~ */ static const uint8_t Font_TTSatoshi_DemiBold_18_glyph_126[] = { 10, 4, 11, 0, 7, 32, 251, 44, 48, 137, 192, 255, 239, 182, 191, 242, 127, 250, 255, 111, 146, 9, 112, 238, 8 }; -/* ? */ const uint8_t Font_TTSatoshi_DemiBold_18_glyph_nonprintable[] = { 9, 13, 10, 0, 13, 255, 56, 32, 229, 255, 79, 0, 0, 0, 253, 11, 80, 139, 0, 245, 41, 243, 255, 6, 242, 255, 255, 255, 3, 243, 255, 255, 61, 0, 249, 255, 239, 1, 160, 255, 255, 143, 0, 253, 255, 255, 111, 64, 255, 255, 255, 223, 219, 255, 255, 255, 175, 151, 255, 255, 255, 95, 64, 255, 255, 255, 95, 64, 255, 255 }; +/* ? */ static const uint8_t Font_TTSatoshi_DemiBold_18_glyph_nonprintable[] = { 9, 13, 10, 0, 13, 255, 56, 32, 229, 255, 79, 0, 0, 0, 253, 11, 80, 139, 0, 245, 41, 243, 255, 6, 242, 255, 255, 255, 3, 243, 255, 255, 61, 0, 249, 255, 239, 1, 160, 255, 255, 143, 0, 253, 255, 255, 111, 64, 255, 255, 255, 223, 219, 255, 255, 255, 175, 151, 255, 255, 255, 95, 64, 255, 255, 255, 95, 64, 255, 255 }; -const uint8_t * const Font_TTSatoshi_DemiBold_18[126 + 1 - 32] = { +static const uint8_t * const Font_TTSatoshi_DemiBold_18[126 + 1 - 32] = { Font_TTSatoshi_DemiBold_18_glyph_32, Font_TTSatoshi_DemiBold_18_glyph_33, Font_TTSatoshi_DemiBold_18_glyph_34, @@ -205,3 +205,11 @@ const uint8_t * const Font_TTSatoshi_DemiBold_18[126 + 1 - 32] = { Font_TTSatoshi_DemiBold_18_glyph_125, Font_TTSatoshi_DemiBold_18_glyph_126, }; + +const font_info_t Font_TTSatoshi_DemiBold_18_info = { + .height = 18, + .max_height = 19, + .baseline = 4, + .glyph_data = Font_TTSatoshi_DemiBold_18, + .glyph_nonprintable = Font_TTSatoshi_DemiBold_18_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_ttsatoshi_demibold_18.h b/core/embed/lib/fonts/font_ttsatoshi_demibold_18.h index 0508e3a324d..4a1af8ff94e 100644 --- a/core/embed/lib/fonts/font_ttsatoshi_demibold_18.h +++ b/core/embed/lib/fonts/font_ttsatoshi_demibold_18.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_TTSatoshi_DemiBold_18_HEIGHT 18 + #define Font_TTSatoshi_DemiBold_18_MAX_HEIGHT 19 -#define Font_TTSatoshi_DemiBold_18_BASELINE 4 -extern const uint8_t* const Font_TTSatoshi_DemiBold_18[126 + 1 - 32]; -extern const uint8_t Font_TTSatoshi_DemiBold_18_glyph_nonprintable[]; +extern const font_info_t Font_TTSatoshi_DemiBold_18_info; diff --git a/core/embed/lib/fonts/font_ttsatoshi_demibold_21.c b/core/embed/lib/fonts/font_ttsatoshi_demibold_21.c index edd6f21f3e9..91095e352a9 100644 --- a/core/embed/lib/fonts/font_ttsatoshi_demibold_21.c +++ b/core/embed/lib/fonts/font_ttsatoshi_demibold_21.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -106,9 +107,9 @@ /* } */ static const uint8_t Font_TTSatoshi_DemiBold_21_glyph_125[] = { 7, 20, 8, 0, 16, 97, 37, 0, 0, 244, 255, 7, 0, 244, 255, 47, 0, 0, 248, 79, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 242, 175, 1, 0, 160, 255, 12, 0, 0, 250, 12, 0, 208, 255, 10, 0, 243, 143, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 244, 95, 0, 0, 244, 95, 0, 97, 252, 79, 0, 244, 255, 14, 0, 244, 191, 3, 0 }; /* ~ */ static const uint8_t Font_TTSatoshi_DemiBold_21_glyph_126[] = { 12, 5, 12, 0, 8, 0, 215, 158, 1, 144, 73, 112, 255, 255, 61, 246, 111, 224, 255, 251, 255, 255, 47, 241, 127, 64, 254, 255, 9, 48, 19, 0, 113, 72, 0 }; -/* ? */ const uint8_t Font_TTSatoshi_DemiBold_21_glyph_nonprintable[] = { 11, 15, 11, 0, 15, 255, 93, 2, 98, 254, 255, 175, 0, 0, 0, 176, 255, 30, 0, 100, 2, 16, 255, 11, 80, 255, 63, 0, 252, 156, 217, 255, 127, 0, 250, 255, 255, 255, 46, 0, 252, 255, 255, 159, 0, 80, 255, 255, 255, 9, 0, 248, 255, 255, 255, 2, 176, 255, 255, 255, 255, 0, 244, 255, 255, 255, 255, 85, 249, 255, 255, 255, 255, 255, 255, 255, 255, 255, 239, 17, 245, 255, 255, 255, 239, 0, 244, 255, 255, 255, 239, 0, 244, 255, 255 }; +/* ? */ static const uint8_t Font_TTSatoshi_DemiBold_21_glyph_nonprintable[] = { 11, 15, 11, 0, 15, 255, 93, 2, 98, 254, 255, 175, 0, 0, 0, 176, 255, 30, 0, 100, 2, 16, 255, 11, 80, 255, 63, 0, 252, 156, 217, 255, 127, 0, 250, 255, 255, 255, 46, 0, 252, 255, 255, 159, 0, 80, 255, 255, 255, 9, 0, 248, 255, 255, 255, 2, 176, 255, 255, 255, 255, 0, 244, 255, 255, 255, 255, 85, 249, 255, 255, 255, 255, 255, 255, 255, 255, 255, 239, 17, 245, 255, 255, 255, 239, 0, 244, 255, 255, 255, 239, 0, 244, 255, 255 }; -const uint8_t * const Font_TTSatoshi_DemiBold_21[126 + 1 - 32] = { +static const uint8_t * const Font_TTSatoshi_DemiBold_21[126 + 1 - 32] = { Font_TTSatoshi_DemiBold_21_glyph_32, Font_TTSatoshi_DemiBold_21_glyph_33, Font_TTSatoshi_DemiBold_21_glyph_34, @@ -205,3 +206,11 @@ const uint8_t * const Font_TTSatoshi_DemiBold_21[126 + 1 - 32] = { Font_TTSatoshi_DemiBold_21_glyph_125, Font_TTSatoshi_DemiBold_21_glyph_126, }; + +const font_info_t Font_TTSatoshi_DemiBold_21_info = { + .height = 21, + .max_height = 21, + .baseline = 4, + .glyph_data = Font_TTSatoshi_DemiBold_21, + .glyph_nonprintable = Font_TTSatoshi_DemiBold_21_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_ttsatoshi_demibold_21.h b/core/embed/lib/fonts/font_ttsatoshi_demibold_21.h index 79c7b42403c..95dbe9c77e6 100644 --- a/core/embed/lib/fonts/font_ttsatoshi_demibold_21.h +++ b/core/embed/lib/fonts/font_ttsatoshi_demibold_21.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_TTSatoshi_DemiBold_21_HEIGHT 21 + #define Font_TTSatoshi_DemiBold_21_MAX_HEIGHT 21 -#define Font_TTSatoshi_DemiBold_21_BASELINE 4 -extern const uint8_t* const Font_TTSatoshi_DemiBold_21[126 + 1 - 32]; -extern const uint8_t Font_TTSatoshi_DemiBold_21_glyph_nonprintable[]; +extern const font_info_t Font_TTSatoshi_DemiBold_21_info; diff --git a/core/embed/lib/fonts/font_ttsatoshi_demibold_42.c b/core/embed/lib/fonts/font_ttsatoshi_demibold_42.c index 20bc5b8f8f9..2ff80209b94 100644 --- a/core/embed/lib/fonts/font_ttsatoshi_demibold_42.c +++ b/core/embed/lib/fonts/font_ttsatoshi_demibold_42.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -8,6 +9,8 @@ // - the third, fourth and fifth bytes are advance, bearingX and bearingY of the horizontal metrics of the glyph // - the rest is packed 4-bit glyph data +// NOTE: glyphs of uppercase and special characters removed to save space as they are not used + /* */ static const uint8_t Font_TTSatoshi_DemiBold_42_glyph_32[] = { 0, 0, 11, 0, 0 }; /* a */ static const uint8_t Font_TTSatoshi_DemiBold_42_glyph_97[] = { 20, 23, 23, 1, 22, 0, 0, 0, 147, 237, 239, 140, 3, 0, 0, 0, 0, 161, 255, 255, 255, 255, 191, 2, 0, 0, 48, 255, 255, 255, 255, 255, 255, 62, 0, 0, 225, 255, 255, 255, 255, 255, 255, 239, 1, 0, 250, 255, 255, 108, 100, 252, 255, 255, 9, 0, 255, 255, 159, 0, 0, 176, 255, 255, 15, 64, 255, 255, 15, 0, 0, 32, 255, 255, 95, 16, 34, 34, 2, 0, 0, 0, 253, 255, 127, 0, 0, 0, 0, 0, 0, 0, 251, 255, 159, 0, 0, 96, 218, 254, 255, 255, 255, 255, 159, 0, 96, 255, 255, 255, 255, 255, 255, 255, 159, 0, 249, 255, 255, 255, 255, 255, 255, 255, 159, 80, 255, 255, 255, 255, 255, 255, 255, 255, 159, 208, 255, 255, 143, 2, 0, 0, 250, 255, 159, 242, 255, 255, 5, 0, 0, 0, 252, 255, 159, 244, 255, 255, 0, 0, 0, 0, 255, 255, 159, 244, 255, 255, 0, 0, 0, 112, 255, 255, 159, 242, 255, 255, 6, 0, 0, 244, 255, 255, 159, 224, 255, 255, 159, 52, 166, 255, 255, 255, 159, 80, 255, 255, 255, 255, 255, 255, 255, 255, 159, 0, 250, 255, 255, 255, 255, 255, 251, 255, 159, 0, 112, 255, 255, 255, 255, 111, 240, 255, 159, 0, 0, 129, 236, 223, 123, 0, 0, 0, 0 }; /* b */ static const uint8_t Font_TTSatoshi_DemiBold_42_glyph_98[] = { 23, 30, 26, 2, 29, 240, 255, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 255, 2, 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 255, 2, 96, 218, 239, 124, 1, 0, 0, 0, 240, 255, 255, 82, 254, 255, 255, 255, 143, 0, 0, 0, 240, 255, 255, 249, 255, 255, 255, 255, 255, 11, 0, 0, 240, 255, 255, 255, 255, 255, 255, 255, 255, 207, 0, 0, 240, 255, 255, 255, 255, 239, 255, 255, 255, 255, 7, 0, 240, 255, 255, 255, 94, 1, 48, 252, 255, 255, 31, 0, 240, 255, 255, 223, 1, 0, 0, 144, 255, 255, 127, 0, 240, 255, 255, 63, 0, 0, 0, 0, 254, 255, 207, 0, 240, 255, 255, 11, 0, 0, 0, 0, 246, 255, 255, 0, 240, 255, 255, 7, 0, 0, 0, 0, 242, 255, 255, 3, 240, 255, 255, 5, 0, 0, 0, 0, 240, 255, 255, 4, 240, 255, 255, 3, 0, 0, 0, 0, 224, 255, 255, 5, 240, 255, 255, 5, 0, 0, 0, 0, 240, 255, 255, 4, 240, 255, 255, 7, 0, 0, 0, 0, 242, 255, 255, 3, 240, 255, 255, 11, 0, 0, 0, 0, 246, 255, 255, 0, 240, 255, 255, 63, 0, 0, 0, 0, 254, 255, 207, 0, 240, 255, 255, 207, 1, 0, 0, 144, 255, 255, 127, 0, 240, 255, 255, 255, 94, 1, 48, 252, 255, 255, 31, 0, 240, 255, 255, 255, 255, 239, 255, 255, 255, 255, 7, 0, 240, 255, 255, 255, 255, 255, 255, 255, 255, 207, 0, 0, 240, 255, 239, 250, 255, 255, 255, 255, 255, 28, 0, 0, 240, 255, 175, 112, 255, 255, 255, 255, 143, 0, 0, 0, 0, 0, 0, 0, 113, 219, 239, 124, 1, 0, 0, 0 }; @@ -36,9 +39,9 @@ /* y */ static const uint8_t Font_TTSatoshi_DemiBold_42_glyph_121[] = { 23, 29, 22, 0, 21, 252, 255, 175, 0, 0, 0, 0, 0, 246, 255, 255, 1, 246, 255, 255, 1, 0, 0, 0, 0, 251, 255, 191, 0, 240, 255, 255, 6, 0, 0, 0, 16, 255, 255, 95, 0, 160, 255, 255, 13, 0, 0, 0, 112, 255, 255, 15, 0, 48, 255, 255, 63, 0, 0, 0, 208, 255, 255, 9, 0, 0, 253, 255, 159, 0, 0, 0, 242, 255, 255, 3, 0, 0, 247, 255, 255, 0, 0, 0, 248, 255, 239, 0, 0, 0, 241, 255, 255, 6, 0, 0, 254, 255, 143, 0, 0, 0, 160, 255, 255, 12, 0, 64, 255, 255, 47, 0, 0, 0, 64, 255, 255, 47, 0, 144, 255, 255, 12, 0, 0, 0, 0, 253, 255, 143, 0, 240, 255, 255, 6, 0, 0, 0, 0, 247, 255, 239, 0, 245, 255, 255, 1, 0, 0, 0, 0, 241, 255, 255, 5, 251, 255, 191, 0, 0, 0, 0, 0, 176, 255, 255, 27, 255, 255, 95, 0, 0, 0, 0, 0, 64, 255, 255, 255, 255, 255, 15, 0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 9, 0, 0, 0, 0, 0, 0, 248, 255, 255, 255, 255, 3, 0, 0, 0, 0, 0, 0, 242, 255, 255, 255, 223, 0, 0, 0, 0, 0, 0, 0, 176, 255, 255, 255, 143, 0, 0, 0, 0, 0, 0, 0, 80, 255, 255, 255, 47, 0, 0, 0, 0, 0, 0, 0, 0, 254, 255, 255, 12, 0, 0, 0, 0, 0, 0, 0, 0, 249, 255, 255, 6, 0, 0, 0, 0, 0, 0, 0, 0, 247, 255, 255, 1, 0, 0, 0, 0, 0, 0, 0, 16, 253, 255, 191, 0, 0, 0, 0, 0, 0, 214, 221, 253, 255, 255, 95, 0, 0, 0, 0, 0, 0, 247, 255, 255, 255, 255, 14, 0, 0, 0, 0, 0, 0, 247, 255, 255, 255, 255, 6, 0, 0, 0, 0, 0, 0, 247, 255, 255, 255, 175, 0, 0, 0, 0, 0, 0, 0, 247, 255, 255, 189, 4, 0, 0, 0, 0, 0, 0 }; /* z */ static const uint8_t Font_TTSatoshi_DemiBold_42_glyph_122[] = { 18, 21, 20, 1, 21, 248, 255, 255, 255, 255, 255, 255, 255, 127, 248, 255, 255, 255, 255, 255, 255, 255, 127, 248, 255, 255, 255, 255, 255, 255, 255, 127, 248, 255, 255, 255, 255, 255, 255, 255, 127, 215, 221, 221, 221, 221, 254, 255, 255, 111, 0, 0, 0, 0, 0, 252, 255, 255, 10, 0, 0, 0, 0, 176, 255, 255, 191, 0, 0, 0, 0, 0, 250, 255, 255, 12, 0, 0, 0, 0, 144, 255, 255, 223, 1, 0, 0, 0, 0, 247, 255, 255, 46, 0, 0, 0, 0, 96, 255, 255, 255, 2, 0, 0, 0, 0, 245, 255, 255, 63, 0, 0, 0, 0, 48, 255, 255, 255, 5, 0, 0, 0, 0, 242, 255, 255, 111, 0, 0, 0, 0, 32, 254, 255, 255, 7, 0, 0, 0, 0, 209, 255, 255, 159, 0, 0, 0, 0, 0, 250, 255, 255, 223, 221, 221, 221, 221, 157, 251, 255, 255, 255, 255, 255, 255, 255, 175, 251, 255, 255, 255, 255, 255, 255, 255, 175, 251, 255, 255, 255, 255, 255, 255, 255, 175, 251, 255, 255, 255, 255, 255, 255, 255, 175 }; -/* ? */ const uint8_t Font_TTSatoshi_DemiBold_42_glyph_nonprintable[] = { 20, 30, 22, 1, 30, 255, 255, 223, 55, 1, 32, 132, 253, 255, 255, 255, 223, 4, 0, 0, 0, 0, 80, 254, 255, 255, 11, 0, 0, 0, 0, 0, 0, 193, 255, 207, 0, 0, 0, 0, 0, 0, 0, 16, 253, 63, 0, 0, 0, 0, 0, 0, 0, 0, 244, 11, 0, 0, 80, 235, 157, 1, 0, 0, 192, 6, 0, 0, 247, 255, 255, 63, 0, 0, 112, 2, 0, 0, 255, 255, 255, 207, 0, 0, 80, 35, 34, 82, 255, 255, 255, 255, 0, 0, 48, 255, 255, 255, 255, 255, 255, 255, 0, 0, 80, 255, 255, 255, 255, 255, 255, 175, 0, 0, 112, 255, 255, 255, 255, 255, 255, 10, 0, 0, 192, 255, 255, 255, 255, 255, 77, 0, 0, 0, 243, 255, 255, 255, 255, 143, 0, 0, 0, 16, 253, 255, 255, 255, 255, 9, 0, 0, 0, 211, 255, 255, 255, 255, 223, 0, 0, 0, 161, 255, 255, 255, 255, 255, 127, 0, 0, 48, 254, 255, 255, 255, 255, 255, 47, 0, 0, 241, 255, 255, 255, 255, 255, 255, 31, 0, 0, 248, 255, 255, 255, 255, 255, 255, 15, 0, 0, 251, 255, 255, 255, 255, 255, 255, 15, 0, 0, 252, 255, 255, 255, 255, 255, 255, 175, 170, 170, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 44, 34, 34, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255 }; +/* ? */ static const uint8_t Font_TTSatoshi_DemiBold_42_glyph_nonprintable[] = { 20, 30, 22, 1, 30, 255, 255, 223, 55, 1, 32, 132, 253, 255, 255, 255, 223, 4, 0, 0, 0, 0, 80, 254, 255, 255, 11, 0, 0, 0, 0, 0, 0, 193, 255, 207, 0, 0, 0, 0, 0, 0, 0, 16, 253, 63, 0, 0, 0, 0, 0, 0, 0, 0, 244, 11, 0, 0, 80, 235, 157, 1, 0, 0, 192, 6, 0, 0, 247, 255, 255, 63, 0, 0, 112, 2, 0, 0, 255, 255, 255, 207, 0, 0, 80, 35, 34, 82, 255, 255, 255, 255, 0, 0, 48, 255, 255, 255, 255, 255, 255, 255, 0, 0, 80, 255, 255, 255, 255, 255, 255, 175, 0, 0, 112, 255, 255, 255, 255, 255, 255, 10, 0, 0, 192, 255, 255, 255, 255, 255, 77, 0, 0, 0, 243, 255, 255, 255, 255, 143, 0, 0, 0, 16, 253, 255, 255, 255, 255, 9, 0, 0, 0, 211, 255, 255, 255, 255, 223, 0, 0, 0, 161, 255, 255, 255, 255, 255, 127, 0, 0, 48, 254, 255, 255, 255, 255, 255, 47, 0, 0, 241, 255, 255, 255, 255, 255, 255, 31, 0, 0, 248, 255, 255, 255, 255, 255, 255, 15, 0, 0, 251, 255, 255, 255, 255, 255, 255, 15, 0, 0, 252, 255, 255, 255, 255, 255, 255, 175, 170, 170, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 44, 34, 34, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255, 255, 255, 255, 12, 0, 0, 249, 255, 255, 255 }; -const uint8_t * const Font_TTSatoshi_DemiBold_42[126 + 1 - 32] = { +static const uint8_t * const Font_TTSatoshi_DemiBold_42[126 + 1 - 32] = { Font_TTSatoshi_DemiBold_42_glyph_32, Font_TTSatoshi_DemiBold_42_glyph_nonprintable, Font_TTSatoshi_DemiBold_42_glyph_nonprintable, @@ -135,3 +138,11 @@ const uint8_t * const Font_TTSatoshi_DemiBold_42[126 + 1 - 32] = { Font_TTSatoshi_DemiBold_42_glyph_nonprintable, Font_TTSatoshi_DemiBold_42_glyph_nonprintable, }; + +const font_info_t Font_TTSatoshi_DemiBold_42_info = { + .height = 42, + .max_height = 44, + .baseline = 9, + .glyph_data = Font_TTSatoshi_DemiBold_42, + .glyph_nonprintable = Font_TTSatoshi_DemiBold_42_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_ttsatoshi_demibold_42.h b/core/embed/lib/fonts/font_ttsatoshi_demibold_42.h index 6b737171e2d..c0583a490f9 100644 --- a/core/embed/lib/fonts/font_ttsatoshi_demibold_42.h +++ b/core/embed/lib/fonts/font_ttsatoshi_demibold_42.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 4 #error Wrong TREZOR_FONT_BPP (expected 4) #endif -#define Font_TTSatoshi_DemiBold_42_HEIGHT 42 + #define Font_TTSatoshi_DemiBold_42_MAX_HEIGHT 44 -#define Font_TTSatoshi_DemiBold_42_BASELINE 9 -extern const uint8_t* const Font_TTSatoshi_DemiBold_42[126 + 1 - 32]; -extern const uint8_t Font_TTSatoshi_DemiBold_42_glyph_nonprintable[]; +extern const font_info_t Font_TTSatoshi_DemiBold_42_info; diff --git a/core/embed/lib/fonts/font_unifont_bold_16.c b/core/embed/lib/fonts/font_unifont_bold_16.c index 666d0049dde..30e2aa35dcd 100644 --- a/core/embed/lib/fonts/font_unifont_bold_16.c +++ b/core/embed/lib/fonts/font_unifont_bold_16.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -104,9 +105,9 @@ /* } */ static const uint8_t Font_Unifont_Bold_16_glyph_125[] = { 5, 13, 7, 0, 11, 225, 140, 198, 24, 102, 99, 12, 110, 0 }; /* ~ */ static const uint8_t Font_Unifont_Bold_16_glyph_126[] = { 7, 3, 8, 0, 11, 99, 118, 48 }; -/* ? */ const uint8_t Font_Unifont_Bold_16_glyph_nonprintable[] = { 6, 10, 7, 0, 10, 5, 199, 60, 231, 60, 255, 207, 63 }; +/* ? */ static const uint8_t Font_Unifont_Bold_16_glyph_nonprintable[] = { 6, 10, 7, 0, 10, 5, 199, 60, 231, 60, 255, 207, 63 }; -const uint8_t * const Font_Unifont_Bold_16[126 + 1 - 32] = { +static const uint8_t * const Font_Unifont_Bold_16[126 + 1 - 32] = { Font_Unifont_Bold_16_glyph_32, Font_Unifont_Bold_16_glyph_33, Font_Unifont_Bold_16_glyph_34, @@ -203,3 +204,11 @@ const uint8_t * const Font_Unifont_Bold_16[126 + 1 - 32] = { Font_Unifont_Bold_16_glyph_125, Font_Unifont_Bold_16_glyph_126, }; + +const font_info_t Font_Unifont_Bold_16_info = { + .height = 16, + .max_height = 15, + .baseline = 2, + .glyph_data = Font_Unifont_Bold_16, + .glyph_nonprintable = Font_Unifont_Bold_16_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_unifont_bold_16.h b/core/embed/lib/fonts/font_unifont_bold_16.h index 976e13c18d9..afd21f6befa 100644 --- a/core/embed/lib/fonts/font_unifont_bold_16.h +++ b/core/embed/lib/fonts/font_unifont_bold_16.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 1 #error Wrong TREZOR_FONT_BPP (expected 1) #endif -#define Font_Unifont_Bold_16_HEIGHT 16 + #define Font_Unifont_Bold_16_MAX_HEIGHT 15 -#define Font_Unifont_Bold_16_BASELINE 2 -extern const uint8_t* const Font_Unifont_Bold_16[126 + 1 - 32]; -extern const uint8_t Font_Unifont_Bold_16_glyph_nonprintable[]; +extern const font_info_t Font_Unifont_Bold_16_info; diff --git a/core/embed/lib/fonts/font_unifont_regular_16.c b/core/embed/lib/fonts/font_unifont_regular_16.c index ecb75394577..47bd89fc423 100644 --- a/core/embed/lib/fonts/font_unifont_regular_16.c +++ b/core/embed/lib/fonts/font_unifont_regular_16.c @@ -1,6 +1,7 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" // clang-format off @@ -108,9 +109,9 @@ /* } */ static const uint8_t Font_Unifont_Regular_16_glyph_125[] = { 4, 13, 7, 1, 11, 194, 36, 66, 18, 68, 34, 192 }; /* ~ */ static const uint8_t Font_Unifont_Regular_16_glyph_126[] = { 7, 3, 8, 0, 11, 99, 38, 48 }; // < --- advanced changed from 7 to 8 -/* ? */ const uint8_t Font_Unifont_Regular_16_glyph_nonprintable[] = { 6, 10, 7, 0, 10, 133, 231, 190, 247, 190, 255, 239, 191 }; +/* ? */ static const uint8_t Font_Unifont_Regular_16_glyph_nonprintable[] = { 6, 10, 7, 0, 10, 133, 231, 190, 247, 190, 255, 239, 191 }; -const uint8_t * const Font_Unifont_Regular_16[126 + 1 - 32] = { +static const uint8_t * const Font_Unifont_Regular_16[126 + 1 - 32] = { Font_Unifont_Regular_16_glyph_32, Font_Unifont_Regular_16_glyph_33, Font_Unifont_Regular_16_glyph_34, @@ -207,3 +208,11 @@ const uint8_t * const Font_Unifont_Regular_16[126 + 1 - 32] = { Font_Unifont_Regular_16_glyph_125, Font_Unifont_Regular_16_glyph_126, }; + +const font_info_t Font_Unifont_Regular_16_info = { + .height = 16, + .max_height = 15, + .baseline = 2, + .glyph_data = Font_Unifont_Regular_16, + .glyph_nonprintable = Font_Unifont_Regular_16_glyph_nonprintable, +}; diff --git a/core/embed/lib/fonts/font_unifont_regular_16.h b/core/embed/lib/fonts/font_unifont_regular_16.h index 108b384d9a5..20153f17462 100644 --- a/core/embed/lib/fonts/font_unifont_regular_16.h +++ b/core/embed/lib/fonts/font_unifont_regular_16.h @@ -1,12 +1,11 @@ // This file is generated by core/tools/codegen/gen_font.py #include +#include "fonts_types.h" #if TREZOR_FONT_BPP != 1 #error Wrong TREZOR_FONT_BPP (expected 1) #endif -#define Font_Unifont_Regular_16_HEIGHT 16 + #define Font_Unifont_Regular_16_MAX_HEIGHT 15 -#define Font_Unifont_Regular_16_BASELINE 2 -extern const uint8_t* const Font_Unifont_Regular_16[126 + 1 - 32]; -extern const uint8_t Font_Unifont_Regular_16_glyph_nonprintable[]; +extern const font_info_t Font_Unifont_Regular_16_info; diff --git a/core/embed/lib/fonts/fonts_types.h b/core/embed/lib/fonts/fonts_types.h index 7b5ec3866d0..3871137cc5f 100644 --- a/core/embed/lib/fonts/fonts_types.h +++ b/core/embed/lib/fonts/fonts_types.h @@ -5,7 +5,6 @@ /// Font information structure containing metadata and pointers to font data typedef struct { - const char* name; int height; int max_height; int baseline; diff --git a/core/tools/codegen/gen_font.py b/core/tools/codegen/gen_font.py index bd86912d83b..11fd05fe4ff 100755 --- a/core/tools/codegen/gen_font.py +++ b/core/tools/codegen/gen_font.py @@ -24,7 +24,7 @@ def _normalize(s: str) -> str: HERE = Path(__file__).parent CORE_ROOT = HERE.parent.parent FONTS_DIR = HERE / "fonts" -OUT_DIR = HERE / ".." / ".." / "embed" / "lib" / "fonts" +OUT_DIR = CORE_ROOT / "embed" / "lib" / "fonts" C_FONTS_DEST = CORE_ROOT / "embed" / "lib" / "fonts" JSON_FONTS_DEST = CORE_ROOT / "translations" / "fonts" @@ -362,20 +362,15 @@ def _write_c_file_content(self, f: TextIO) -> None: self._write_char_definition(f, chr(i), i) # Write nonprintable glyph - if self.gen_normal: - f.write("\n") - nonprintable = self._get_nonprintable_definition_line() - f.write(nonprintable) - if self.gen_upper: - f.write("\n") - nonprintable = self._get_nonprintable_definition_line(upper=True) - f.write(nonprintable) + f.write("\n") + nonprintable = self._get_nonprintable_definition_line() + f.write(nonprintable) # Write array of all glyphs if self.gen_normal: f.write("\n") f.write( - f"const uint8_t * const Font_{self._name_style_size}[{MAX_GLYPH} + 1 - {MIN_GLYPH}] = {{\n" + f"static const uint8_t * const Font_{self._name_style_size}[{MAX_GLYPH} + 1 - {MIN_GLYPH}] = {{\n" ) for i in range(MIN_GLYPH, MAX_GLYPH + 1): f.write(f" Font_{self._name_style_size}_glyph_{i},\n") @@ -385,7 +380,7 @@ def _write_c_file_content(self, f: TextIO) -> None: if self.gen_upper: f.write("\n") f.write( - f"const uint8_t * const Font_{self._name_style_size}_upper[{MAX_GLYPH} + 1 - {MIN_GLYPH}] = {{\n" + f"static const uint8_t * const Font_{self._name_style_size}_upper[{MAX_GLYPH} + 1 - {MIN_GLYPH}] = {{\n" ) for i in range(MIN_GLYPH, MAX_GLYPH + 1): comment = "" @@ -397,6 +392,12 @@ def _write_c_file_content(self, f: TextIO) -> None: f.write(f" Font_{self._name_style_size}_glyph_{i},{comment}\n") f.write("};\n") + # Write font info structure + if self.gen_normal: + self._write_font_info_structure(f) + if self.gen_upper: + self._write_font_info_structure(f, is_upper=True) + def _write_char_definition(self, f: TextIO, c: str, i: int) -> None: self._load_char(c) glyph = Glyph.from_face(self.face, c, self.shaveX) @@ -412,7 +413,8 @@ def _write_char_definition(self, f: TextIO, c: str, i: int) -> None: def _write_c_file_header(self, f: TextIO) -> None: f.write("// This file is generated by core/tools/codegen/gen_font.py\n\n") - f.write("#include \n\n") + f.write("#include \n") + f.write('#include "fonts_types.h"\n\n') f.write("// clang-format off\n\n") f.write("// - the first two bytes are width and height of the glyph\n") f.write( @@ -420,18 +422,27 @@ def _write_c_file_header(self, f: TextIO) -> None: ) f.write(f"// - the rest is packed {self.bpp}-bit glyph data\n\n") - def _get_nonprintable_definition_line(self, upper: bool = False) -> str: + # Write font info structure to instantiate font_info_t defined in fonts_types.h + def _write_font_info_structure(self, f: TextIO, is_upper: bool = False): + suffix = "_upper" if is_upper else "" + f.write("\n") + f.write(f"const font_info_t Font_{self._name_style_size}{suffix}_info = {{\n") + f.write(f" .height = {self.size},\n") + f.write(f" .max_height = {self.font_ymax - self.font_ymin},\n") + f.write(f" .baseline = {-self.font_ymin},\n") + f.write(f" .glyph_data = Font_{self._name_style_size}{suffix},\n") + f.write( + f" .glyph_nonprintable = Font_{self._name_style_size}_glyph_nonprintable,\n" + ) + f.write("};\n") + + def _get_nonprintable_definition_line(self) -> str: c = "?" self._load_char(c) glyph = Glyph.from_face(self.face, c, self.shaveX, inverse_colors=True) - if upper: - return glyph.get_definition_line( - f"{self._name_style_size}_upper", self.bpp, "nonprintable", static=False - ) - else: - return glyph.get_definition_line( - self._name_style_size, self.bpp, "nonprintable", static=False - ) + return glyph.get_definition_line( + self._name_style_size, self.bpp, "nonprintable", static=True + ) def _load_char(self, c: str) -> None: self.face.load_char(c, freetype.FT_LOAD_RENDER | freetype.FT_LOAD_TARGET_NORMAL) # type: ignore @@ -439,39 +450,24 @@ def _load_char(self, c: str) -> None: def _write_h_file(self) -> None: with open(OUT_DIR / self._h_file_name, "wt") as f: f.write("// This file is generated by core/tools/codegen/gen_font.py\n\n") - f.write("#include \n\n") + f.write("#include \n") + f.write('#include "fonts_types.h"\n\n') f.write(f"#if TREZOR_FONT_BPP != {self.bpp}\n") f.write(f"#error Wrong TREZOR_FONT_BPP (expected {self.bpp})\n") - f.write("#endif\n") + f.write("#endif\n\n") if self.gen_normal: - f.write(f"#define Font_{self._name_style_size}_HEIGHT {self.size}\n") f.write( f"#define Font_{self._name_style_size}_MAX_HEIGHT {self.font_ymax - self.font_ymin}\n" ) f.write( - f"#define Font_{self._name_style_size}_BASELINE {-self.font_ymin}\n" - ) - f.write( - f"extern const uint8_t* const Font_{self._name_style_size}[{MAX_GLYPH} + 1 - {MIN_GLYPH}];\n" - ) - f.write( - f"extern const uint8_t Font_{self._name_style_size}_glyph_nonprintable[];\n" + f"extern const font_info_t Font_{self._name_style_size}_info;\n" ) if self.gen_upper: - f.write( - f"#define Font_{self._name_style_size}_upper_HEIGHT {self.size}\n" - ) f.write( f"#define Font_{self._name_style_size}_upper_MAX_HEIGHT {self.font_ymax - self.font_ymin}\n" ) f.write( - f"#define Font_{self._name_style_size}_upper_BASELINE {-self.font_ymin}\n" - ) - f.write( - f"extern const uint8_t* const Font_{self._name_style_size}_upper[{MAX_GLYPH} + 1 - {MIN_GLYPH}];\n" - ) - f.write( - f"extern const uint8_t Font_{self._name_style_size}_upper_glyph_nonprintable[];\n" + f"extern const font_info_t Font_{self._name_style_size}_upper_info;\n" ) @@ -489,6 +485,7 @@ def _write_h_file(self) -> None: ).write_files() FaceProcessor("RobotoMono", "Medium", 20).write_files() + # model R FaceProcessor( "PixelOperator", "Regular", @@ -508,12 +505,11 @@ def _write_h_file(self) -> None: gen_upper=True, ).write_files() FaceProcessor("PixelOperatorMono", "Regular", 8, bpp=1, shaveX=1).write_files() - - # For model R FaceProcessor("Unifont", "Regular", 16, bpp=1, shaveX=1, ext="otf").write_files() # NOTE: Unifont Bold does not seem to have czech characters FaceProcessor("Unifont", "Bold", 16, bpp=1, shaveX=1, ext="otf").write_files() + # model mercury FaceProcessor("TTSatoshi", "DemiBold", 42, ext="otf").write_files() FaceProcessor("TTSatoshi", "DemiBold", 21, ext="otf").write_files() FaceProcessor("TTSatoshi", "DemiBold", 18, ext="otf").write_files() From 94db1ee198fb845efb588788dfe5df3d8282dfa6 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 18 Sep 2024 23:54:22 +0200 Subject: [PATCH 5/5] refactor(core): use font_id_t instead of plain int [no changelog] --- core/embed/lib/display_draw.c | 18 ++++++++++-------- core/embed/lib/display_draw.h | 12 ++++++------ core/embed/lib/fonts/fonts.c | 14 +++++++------- core/embed/lib/fonts/fonts.h | 14 +++++++------- core/embed/lib/fonts/fonts_types.h | 2 +- core/embed/lib/gfx_draw.c | 6 +++--- core/embed/rust/librust_fonts.h | 4 +++- core/embed/trezorhal/xdisplay_legacy.h | 5 +++-- 8 files changed, 40 insertions(+), 35 deletions(-) diff --git a/core/embed/lib/display_draw.c b/core/embed/lib/display_draw.c index 289b2ce16c1..71def0f775a 100644 --- a/core/embed/lib/display_draw.c +++ b/core/embed/lib/display_draw.c @@ -89,7 +89,7 @@ void display_bar(int x, int y, int w, int h, uint16_t c) { display_pixeldata_dirty(); } -void display_text_render_buffer(const char *text, int textlen, int font, +void display_text_render_buffer(const char *text, int textlen, font_id_t font, buffer_text_t *buffer, int text_offset) { // determine text length if not provided if (textlen < 0) { @@ -159,7 +159,8 @@ void display_text_render_buffer(const char *text, int textlen, int font, #ifdef FRAMEBUFFER static void display_text_render(int x, int y, const char *text, int textlen, - int font, uint16_t fgcolor, uint16_t bgcolor) { + font_id_t font, uint16_t fgcolor, + uint16_t bgcolor) { // determine text length if not provided if (textlen < 0) { textlen = strlen(text); @@ -226,7 +227,8 @@ static void display_text_render(int x, int y, const char *text, int textlen, #else static void display_text_render(int x, int y, const char *text, int textlen, - int font, uint16_t fgcolor, uint16_t bgcolor) { + font_id_t font, uint16_t fgcolor, + uint16_t bgcolor) { // determine text length if not provided if (textlen < 0) { textlen = strlen(text); @@ -282,23 +284,23 @@ static void display_text_render(int x, int y, const char *text, int textlen, } #endif -void display_text(int x, int y, const char *text, int textlen, int font, +void display_text(int x, int y, const char *text, int textlen, font_id_t font, uint16_t fgcolor, uint16_t bgcolor) { x += DISPLAY_OFFSET.x; y += DISPLAY_OFFSET.y; display_text_render(x, y, text, textlen, font, fgcolor, bgcolor); } -void display_text_center(int x, int y, const char *text, int textlen, int font, - uint16_t fgcolor, uint16_t bgcolor) { +void display_text_center(int x, int y, const char *text, int textlen, + font_id_t font, uint16_t fgcolor, uint16_t bgcolor) { x += DISPLAY_OFFSET.x; y += DISPLAY_OFFSET.y; int w = font_text_width(font, text, textlen); display_text_render(x - w / 2, y, text, textlen, font, fgcolor, bgcolor); } -void display_text_right(int x, int y, const char *text, int textlen, int font, - uint16_t fgcolor, uint16_t bgcolor) { +void display_text_right(int x, int y, const char *text, int textlen, + font_id_t font, uint16_t fgcolor, uint16_t bgcolor) { x += DISPLAY_OFFSET.x; y += DISPLAY_OFFSET.y; int w = font_text_width(font, text, textlen); diff --git a/core/embed/lib/display_draw.h b/core/embed/lib/display_draw.h index dcd046681d4..df69212e135 100644 --- a/core/embed/lib/display_draw.h +++ b/core/embed/lib/display_draw.h @@ -35,13 +35,13 @@ void display_clear(void); void display_bar(int x, int y, int w, int h, uint16_t c); -void display_text(int x, int y, const char *text, int textlen, int font, +void display_text(int x, int y, const char *text, int textlen, font_id_t font, uint16_t fgcolor, uint16_t bgcolor); -void display_text_center(int x, int y, const char *text, int textlen, int font, - uint16_t fgcolor, uint16_t bgcolor); -void display_text_right(int x, int y, const char *text, int textlen, int font, - uint16_t fgcolor, uint16_t bgcolor); -void display_text_render_buffer(const char *text, int textlen, int font, +void display_text_center(int x, int y, const char *text, int textlen, + font_id_t font, uint16_t fgcolor, uint16_t bgcolor); +void display_text_right(int x, int y, const char *text, int textlen, + font_id_t font, uint16_t fgcolor, uint16_t bgcolor); +void display_text_render_buffer(const char *text, int textlen, font_id_t font, buffer_text_t *buffer, int text_offset); void display_qrcode(int x, int y, const char *data, uint8_t scale); diff --git a/core/embed/lib/fonts/fonts.c b/core/embed/lib/fonts/fonts.c index a1da435c3c7..b5a3bc8f1b2 100644 --- a/core/embed/lib/fonts/fonts.c +++ b/core/embed/lib/fonts/fonts.c @@ -96,22 +96,22 @@ static const font_info_t *get_font_info(font_id_t font_id) { } } -int font_height(int font_id) { +int font_height(font_id_t font_id) { const font_info_t *font_info = get_font_info(font_id); return font_info ? font_info->height : 0; } -int font_max_height(int font) { +int font_max_height(font_id_t font) { const font_info_t *font_info = get_font_info(font); return font_info ? font_info->max_height : 0; } -int font_baseline(int font) { +int font_baseline(font_id_t font) { const font_info_t *font_info = get_font_info(font); return font_info ? font_info->baseline : 0; } -const uint8_t *font_get_glyph(int font, uint16_t c) { +const uint8_t *font_get_glyph(font_id_t font, uint16_t c) { #ifdef TRANSLATIONS // found UTF8 character // it is not hardcoded in firmware fonts, it must be extracted from the @@ -136,12 +136,12 @@ const uint8_t *font_get_glyph(int font, uint16_t c) { return font_nonprintable_glyph(font); } -const uint8_t *font_nonprintable_glyph(int font) { +const uint8_t *font_nonprintable_glyph(font_id_t font) { const font_info_t *font_info = get_font_info(font); return font_info ? font_info->glyph_nonprintable : NULL; } -font_glyph_iter_t font_glyph_iter_init(const int font, const uint8_t *text, +font_glyph_iter_t font_glyph_iter_init(font_id_t font, const uint8_t *text, const int len) { return (font_glyph_iter_t){ .font = font, @@ -212,7 +212,7 @@ bool font_next_glyph(font_glyph_iter_t *iter, const uint8_t **out) { } // compute the width of the text (in pixels) -int font_text_width(int font, const char *text, int textlen) { +int font_text_width(font_id_t font, const char *text, int textlen) { int width = 0; // determine text length if not provided if (textlen < 0) { diff --git a/core/embed/lib/fonts/fonts.h b/core/embed/lib/fonts/fonts.h index f8f5b14e9cb..9cc85b82ea5 100644 --- a/core/embed/lib/fonts/fonts.h +++ b/core/embed/lib/fonts/fonts.h @@ -54,15 +54,15 @@ TREZOR_FONT_MONO_ENABLE ? FONT_MONO_MAX_HEIGHT : 0) // clang-format on -int font_height(int font); -int font_max_height(int font); -int font_baseline(int font); -const uint8_t *font_get_glyph(int font, uint16_t c); -const uint8_t *font_nonprintable_glyph(int font); +int font_height(font_id_t font); +int font_max_height(font_id_t font); +int font_baseline(font_id_t font); +const uint8_t *font_get_glyph(font_id_t font, const uint16_t c); +const uint8_t *font_nonprintable_glyph(font_id_t font); -font_glyph_iter_t font_glyph_iter_init(const int font, const uint8_t *text, +font_glyph_iter_t font_glyph_iter_init(font_id_t font, const uint8_t *text, const int len); bool font_next_glyph(font_glyph_iter_t *iter, const uint8_t **out); -int font_text_width(int font, const char *text, int textlen); +int font_text_width(font_id_t font, const char *text, int textlen); #endif //_FONTS_H diff --git a/core/embed/lib/fonts/fonts_types.h b/core/embed/lib/fonts/fonts_types.h index 3871137cc5f..17fe834c52a 100644 --- a/core/embed/lib/fonts/fonts_types.h +++ b/core/embed/lib/fonts/fonts_types.h @@ -26,7 +26,7 @@ typedef enum { /// Font glyph iterator structure typedef struct { - const int font; + const font_id_t font; const uint8_t* text; int remaining; } font_glyph_iter_t; diff --git a/core/embed/lib/gfx_draw.c b/core/embed/lib/gfx_draw.c index 192bfef361d..95d584eb657 100644 --- a/core/embed/lib/gfx_draw.c +++ b/core/embed/lib/gfx_draw.c @@ -297,7 +297,7 @@ void display_bar(int x, int y, int w, int h, uint16_t c) { gfx_draw_bar(gfx_rect_wh(x, y, w, h), c); } -void display_text(int x, int y, const char* text, int textlen, int font, +void display_text(int x, int y, const char* text, int textlen, font_id_t font, uint16_t fg_color, uint16_t bg_color) { gfx_text_attr_t attr = { .font = font, @@ -309,8 +309,8 @@ void display_text(int x, int y, const char* text, int textlen, int font, gfx_draw_text(gfx_offset(x, y), text, maxlen, &attr); } -void display_text_center(int x, int y, const char* text, int textlen, int font, - uint16_t fg_color, uint16_t bg_color) { +void display_text_center(int x, int y, const char* text, int textlen, + font_id_t font, uint16_t fg_color, uint16_t bg_color) { gfx_text_attr_t attr = { .font = font, .fg_color = fg_color, diff --git a/core/embed/rust/librust_fonts.h b/core/embed/rust/librust_fonts.h index 17249c4b1b7..ca82cb1b011 100644 --- a/core/embed/rust/librust_fonts.h +++ b/core/embed/rust/librust_fonts.h @@ -1 +1,3 @@ -const uint8_t *get_utf8_glyph(uint16_t char_code, int font); +#include "fonts/fonts_types.h" + +const uint8_t *get_utf8_glyph(uint16_t char_code, font_id_t font); diff --git a/core/embed/trezorhal/xdisplay_legacy.h b/core/embed/trezorhal/xdisplay_legacy.h index 0fc4d75cc60..4274a92f479 100644 --- a/core/embed/trezorhal/xdisplay_legacy.h +++ b/core/embed/trezorhal/xdisplay_legacy.h @@ -20,8 +20,9 @@ #ifndef TREZORHAL_DISPLAY_LEGACY_H #define TREZORHAL_DISPLAY_LEGACY_H -#include #include +#include "buffers.h" +#include "fonts/fonts_types.h" // These declarationscode emulates will be removed after the // final cleanup of display drivers. They are here just to simplify @@ -48,7 +49,7 @@ void display_pixeldata(uint16_t c); uint32_t* display_get_fb_addr(void); void display_clear(void); -void display_text_render_buffer(const char* text, int textlen, int font, +void display_text_render_buffer(const char* text, int textlen, font_id_t font, buffer_text_t* buffer, int text_offset); #define PIXELDATA(c) display_pixeldata(c)