From 94db1ee198fb845efb588788dfe5df3d8282dfa6 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 18 Sep 2024 23:54:22 +0200 Subject: [PATCH] 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)