From b3fe8d1917ba06ead35671327751ad3b0da6810e Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 18 Sep 2024 12:12:07 +0200 Subject: [PATCH] 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/gfx/fonts/fonts.h | 67 +++++++++++++++++------------------- core/site_scons/ui/common.py | 3 +- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/core/embed/gfx/fonts/fonts.h b/core/embed/gfx/fonts/fonts.h index 84c63dbba8..73863930d9 100644 --- a/core/embed/gfx/fonts/fonts.h +++ b/core/embed/gfx/fonts/fonts.h @@ -36,82 +36,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/ui/common.py b/core/site_scons/ui/common.py index 586d21f7db..9624123978 100644 --- a/core/site_scons/ui/common.py +++ b/core/site_scons/ui/common.py @@ -10,7 +10,8 @@ def add_font( if font is not None: font_filename = font.replace("_upper", "").lower() defines += [ - (f"TREZOR_FONT_{font_name}_ENABLE", font), + f"TREZOR_FONT_{font_name}_ENABLE", + (f"TREZOR_FONT_{font_name}_NAME", font), (f"TREZOR_FONT_{font_name}_INCLUDE", f'"{font_filename}.h"'), ] sourcefile = "embed/gfx/fonts/" + font_filename + ".c"