From 59f4dc31cb92d82f23b680e13c729b18dafdcea4 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/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 2e4405e90..5172346d9 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 315ca5cef..579ada8c0 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"