1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-04 21:48:17 +00:00

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]
This commit is contained in:
obrusvit 2024-09-18 12:12:07 +02:00
parent 13df961317
commit b3fe8d1917
2 changed files with 34 additions and 36 deletions

View File

@ -36,82 +36,79 @@
#ifdef TREZOR_FONT_NORMAL_ENABLE #ifdef TREZOR_FONT_NORMAL_ENABLE
#define FONT_NORMAL (-1) #define FONT_NORMAL (-1)
#include TREZOR_FONT_NORMAL_INCLUDE #include TREZOR_FONT_NORMAL_INCLUDE
#define FONT_NORMAL_DATA TREZOR_FONT_NORMAL_ENABLE #define FONT_NORMAL_DATA TREZOR_FONT_NORMAL_NAME
#define FONT_NORMAL_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _HEIGHT) #define FONT_NORMAL_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _HEIGHT)
#define FONT_NORMAL_MAX_HEIGHT \ #define FONT_NORMAL_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _MAX_HEIGHT)
FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _MAX_HEIGHT) #define FONT_NORMAL_BASELINE FONT_DEFINE(TREZOR_FONT_NORMAL_NAME, _BASELINE)
#define FONT_NORMAL_BASELINE FONT_DEFINE(TREZOR_FONT_NORMAL_ENABLE, _BASELINE)
#endif #endif
#ifdef TREZOR_FONT_BIG_ENABLE #ifdef TREZOR_FONT_BIG_ENABLE
#include TREZOR_FONT_BIG_INCLUDE #include TREZOR_FONT_BIG_INCLUDE
#define FONT_BIG (-4) #define FONT_BIG (-4)
#define FONT_BIG_DATA TREZOR_FONT_BIG_ENABLE #define FONT_BIG_DATA TREZOR_FONT_BIG_NAME
#define FONT_BIG_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_ENABLE, _HEIGHT) #define FONT_BIG_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_NAME, _HEIGHT)
#define FONT_BIG_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_ENABLE, _MAX_HEIGHT) #define FONT_BIG_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BIG_NAME, _MAX_HEIGHT)
#define FONT_BIG_BASELINE FONT_DEFINE(TREZOR_FONT_BIG_ENABLE, _BASELINE) #define FONT_BIG_BASELINE FONT_DEFINE(TREZOR_FONT_BIG_NAME, _BASELINE)
#endif #endif
#ifdef TREZOR_FONT_DEMIBOLD_ENABLE #ifdef TREZOR_FONT_DEMIBOLD_ENABLE
#include TREZOR_FONT_DEMIBOLD_INCLUDE #include TREZOR_FONT_DEMIBOLD_INCLUDE
#define FONT_DEMIBOLD (-5) #define FONT_DEMIBOLD (-5)
#define FONT_DEMIBOLD_DATA TREZOR_FONT_DEMIBOLD_ENABLE #define FONT_DEMIBOLD_DATA TREZOR_FONT_DEMIBOLD_NAME
#define FONT_DEMIBOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_DEMIBOLD_ENABLE, _HEIGHT) #define FONT_DEMIBOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _HEIGHT)
#define FONT_DEMIBOLD_MAX_HEIGHT \ #define FONT_DEMIBOLD_MAX_HEIGHT \
FONT_DEFINE(TREZOR_FONT_DEMIBOLD_ENABLE, _MAX_HEIGHT) FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _MAX_HEIGHT)
#define FONT_DEMIBOLD_BASELINE \ #define FONT_DEMIBOLD_BASELINE FONT_DEFINE(TREZOR_FONT_DEMIBOLD_NAME, _BASELINE)
FONT_DEFINE(TREZOR_FONT_DEMIBOLD_ENABLE, _BASELINE)
#endif #endif
#ifdef TREZOR_FONT_SUB_ENABLE #ifdef TREZOR_FONT_SUB_ENABLE
#include TREZOR_FONT_SUB_INCLUDE #include TREZOR_FONT_SUB_INCLUDE
#define FONT_SUB (-8) #define FONT_SUB (-8)
#define FONT_SUB_DATA TREZOR_FONT_SUB_ENABLE #define FONT_SUB_DATA TREZOR_FONT_SUB_NAME
#define FONT_SUB_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_ENABLE, _HEIGHT) #define FONT_SUB_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_NAME, _HEIGHT)
#define FONT_SUB_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_ENABLE, _MAX_HEIGHT) #define FONT_SUB_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_SUB_NAME, _MAX_HEIGHT)
#define FONT_SUB_BASELINE FONT_DEFINE(TREZOR_FONT_SUB_ENABLE, _BASELINE) #define FONT_SUB_BASELINE FONT_DEFINE(TREZOR_FONT_SUB_NAME, _BASELINE)
#endif #endif
#ifdef TREZOR_FONT_MONO_ENABLE #ifdef TREZOR_FONT_MONO_ENABLE
#include TREZOR_FONT_MONO_INCLUDE #include TREZOR_FONT_MONO_INCLUDE
#define FONT_MONO (-3) #define FONT_MONO (-3)
#define FONT_MONO_DATA TREZOR_FONT_MONO_ENABLE #define FONT_MONO_DATA TREZOR_FONT_MONO_NAME
#define FONT_MONO_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _HEIGHT) #define FONT_MONO_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_NAME, _HEIGHT)
#define FONT_MONO_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _MAX_HEIGHT) #define FONT_MONO_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_MONO_NAME, _MAX_HEIGHT)
#define FONT_MONO_BASELINE FONT_DEFINE(TREZOR_FONT_MONO_ENABLE, _BASELINE) #define FONT_MONO_BASELINE FONT_DEFINE(TREZOR_FONT_MONO_NAME, _BASELINE)
#endif #endif
#ifdef TREZOR_FONT_BOLD_ENABLE #ifdef TREZOR_FONT_BOLD_ENABLE
#include TREZOR_FONT_BOLD_INCLUDE #include TREZOR_FONT_BOLD_INCLUDE
#define FONT_BOLD (-2) #define FONT_BOLD (-2)
#define FONT_BOLD_DATA TREZOR_FONT_BOLD_ENABLE #define FONT_BOLD_DATA TREZOR_FONT_BOLD_NAME
#define FONT_BOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _HEIGHT) #define FONT_BOLD_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _HEIGHT)
#define FONT_BOLD_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _MAX_HEIGHT) #define FONT_BOLD_MAX_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _MAX_HEIGHT)
#define FONT_BOLD_BASELINE FONT_DEFINE(TREZOR_FONT_BOLD_ENABLE, _BASELINE) #define FONT_BOLD_BASELINE FONT_DEFINE(TREZOR_FONT_BOLD_NAME, _BASELINE)
#endif #endif
#ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE #ifdef TREZOR_FONT_NORMAL_UPPER_ENABLE
#include TREZOR_FONT_NORMAL_UPPER_INCLUDE #include TREZOR_FONT_NORMAL_UPPER_INCLUDE
#define FONT_NORMAL_UPPER (-6) #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 \ #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 \ #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 \ #define FONT_NORMAL_UPPER_BASELINE \
FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_ENABLE, _BASELINE) FONT_DEFINE(TREZOR_FONT_NORMAL_UPPER_NAME, _BASELINE)
#endif #endif
#ifdef TREZOR_FONT_BOLD_UPPER_ENABLE #ifdef TREZOR_FONT_BOLD_UPPER_ENABLE
#include TREZOR_FONT_BOLD_UPPER_INCLUDE #include TREZOR_FONT_BOLD_UPPER_INCLUDE
#define FONT_BOLD_UPPER (-7) #define FONT_BOLD_UPPER (-7)
#define FONT_BOLD_UPPER_DATA TREZOR_FONT_BOLD_UPPER_ENABLE #define FONT_BOLD_UPPER_DATA TREZOR_FONT_BOLD_UPPER_NAME
#define FONT_BOLD_UPPER_HEIGHT \ #define FONT_BOLD_UPPER_HEIGHT FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_NAME, _HEIGHT)
FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_ENABLE, _HEIGHT)
#define FONT_BOLD_UPPER_MAX_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 \ #define FONT_BOLD_UPPER_BASELINE \
FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_ENABLE, _BASELINE) FONT_DEFINE(TREZOR_FONT_BOLD_UPPER_NAME, _BASELINE)
#endif #endif
#define MAX_FONT_H(A, B) ((A) > (B) ? (A) : (B)) #define MAX_FONT_H(A, B) ((A) > (B) ? (A) : (B))

View File

@ -10,7 +10,8 @@ def add_font(
if font is not None: if font is not None:
font_filename = font.replace("_upper", "").lower() font_filename = font.replace("_upper", "").lower()
defines += [ 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"'), (f"TREZOR_FONT_{font_name}_INCLUDE", f'"{font_filename}.h"'),
] ]
sourcefile = "embed/gfx/fonts/" + font_filename + ".c" sourcefile = "embed/gfx/fonts/" + font_filename + ".c"