What changed, and why it matters
This commit is a small internal cleanup of how fonts are selected on the device's screen. It removes an unused second argument from the font-setting function and adds a minor caching shortcut so the same font isn't re-initialized repeatedly. There is no visible security change.
No security action required. Treat as a normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors display_set_font() from taking (uint8_t font, const char* font_file) to taking only (uint8_t font). The font_file parameter was always passed as NULL and never used. The function now uses a local font_data pointer and, after selection, checks if the chosen font is already the current one and cfont.max_x_size is already set; if so, it returns early. Otherwise it populates cfont fields as before. Callers in display.c and gui.c are updated to drop the NULL argument. No bounds checks, memory allocations, or trust boundaries change.
Changed components
main/display.cmain/display.hmain/gui.cInspect captured patch +34 / −30
diff --git a/main/display.c b/main/display.c
index 07682f0..c087533 100644
--- a/main/display.c
+++ b/main/display.c
@@ -279,7 +279,7 @@ void display_init(TaskHandle_t* gui_h)
.x2 = TOUCH_BUTTON_WIDTH + CONFIG_DISPLAY_OFFSET_X,
.y2 = (CONFIG_DISPLAY_HEIGHT + (TOUCH_BUTTON_AREA - TOUCH_BUTTON_MARGIN)) + CONFIG_DISPLAY_OFFSET_Y };
- display_set_font(JADE_SYMBOLS_16x16_FONT, NULL);
+ display_set_font(JADE_SYMBOLS_16x16_FONT);
display_print_in_area("H", CENTER, CENTER, disp_win_virtual_buttons, 0);
disp_win_virtual_buttons.x1 = ((CONFIG_DISPLAY_WIDTH / 2) + CONFIG_DISPLAY_OFFSET_X) - (TOUCH_BUTTON_WIDTH / 2);
disp_win_virtual_buttons.x2 = ((CONFIG_DISPLAY_WIDTH / 2) + CONFIG_DISPLAY_OFFSET_X) + (TOUCH_BUTTON_WIDTH / 2);
@@ -288,7 +288,7 @@ void display_init(TaskHandle_t* gui_h)
= ((CONFIG_DISPLAY_WIDTH - TOUCH_BUTTON_MARGIN) + CONFIG_DISPLAY_OFFSET_X) - TOUCH_BUTTON_WIDTH;
disp_win_virtual_buttons.x2 = (CONFIG_DISPLAY_WIDTH - TOUCH_BUTTON_MARGIN) + CONFIG_DISPLAY_OFFSET_X;
display_print_in_area("I", CENTER, CENTER, disp_win_virtual_buttons, 0);
- display_set_font(DEFAULT_FONT, NULL);
+ display_set_font(DEFAULT_FONT);
vTaskDelay(50 / portTICK_PERIOD_MS);
#endif
@@ -747,56 +747,60 @@ static void get_max_width_height(void)
cfont.size = tempPtr;
}
-void display_set_font(uint8_t font, const char* font_file)
+void display_set_font(const uint8_t font)
{
- cfont.font = NULL;
+ const uint8_t* font_data;
if (font == DEJAVU18_FONT) {
- cfont.font = tft_Dejavu18;
+ font_data = tft_Dejavu18;
} else if (font == DEJAVU24_FONT) {
- cfont.font = tft_Dejavu24;
+ font_data = tft_Dejavu24;
} else if (font == UBUNTU16_FONT) {
- cfont.font = tft_Ubuntu16;
+ font_data = tft_Ubuntu16;
} else if (font == COMIC24_FONT) {
- cfont.font = tft_Comic24;
+ font_data = tft_Comic24;
} else if (font == MINYA24_FONT) {
- cfont.font = tft_minya24;
+ font_data = tft_minya24;
} else if (font == TOONEY32_FONT) {
- cfont.font = tft_tooney32;
+ font_data = tft_tooney32;
} else if (font == SMALL_FONT) {
- cfont.font = tft_SmallFont;
+ font_data = tft_SmallFont;
} else if (font == DEF_SMALL_FONT) {
- cfont.font = tft_def_small;
+ font_data = tft_def_small;
} else if (font == BIG_FONT) {
- cfont.font = tft_BigFont;
+ font_data = tft_BigFont;
} else if (font == SINCLAIR_M) {
- cfont.font = tft_Sinclair_M;
+ font_data = tft_Sinclair_M;
} else if (font == SINCLAIR_S) {
- cfont.font = tft_Sinclair_S;
+ font_data = tft_Sinclair_S;
} else if (font == RETRO_8X16) {
- cfont.font = tft_Retro8x16;
+ font_data = tft_Retro8x16;
} else if (font == VARIOUS_SYMBOLS_FONT) {
- cfont.font = tft_various_symbols;
+ font_data = tft_various_symbols;
} else if (font == VARIOUS_SYMBOLS_32_FONT) {
- cfont.font = tft_Various_Symbols_32x32;
+ font_data = tft_Various_Symbols_32x32;
} else if (font == BATTERY_FONT) {
- cfont.font = tft_Battery_24x48;
+ font_data = tft_Battery_24x48;
} else if (font == JADE_SYMBOLS_16x16_FONT) {
- cfont.font = jade_symbols_16x16;
+ font_data = jade_symbols_16x16;
} else if (font == JADE_SYMBOLS_16x32_FONT) {
- cfont.font = jade_symbols_16x32;
+ font_data = jade_symbols_16x32;
} else if (font == JADE_SYMBOLS_24x24_FONT) {
- cfont.font = jade_symbols_24x24;
+ font_data = jade_symbols_24x24;
} else {
- cfont.font = tft_DefaultFont;
+ font_data = tft_DefaultFont;
}
+ if (font_data == cfont.font && cfont.max_x_size) {
+ return;
+ }
+ cfont.font = font_data;
cfont.bitmap = 1;
- cfont.x_size = cfont.font[0];
- cfont.y_size = cfont.font[1];
+ cfont.x_size = font_data[0];
+ cfont.y_size = font_data[1];
if (cfont.x_size > 0) {
- cfont.offset = cfont.font[2];
- cfont.numchars = cfont.font[3];
+ cfont.offset = font_data[2];
+ cfont.numchars = font_data[3];
cfont.size = cfont.x_size * cfont.y_size * cfont.numchars;
} else {
cfont.offset = 4;
diff --git a/main/display.h b/main/display.h
index ba6350d..a625da4 100644
--- a/main/display.h
+++ b/main/display.h
@@ -98,7 +98,7 @@ void display_fill_rect(int x, int y, int w, int h, color_t color);
void display_icon(const Icon* imgbuf, int x, int y, color_t color, dispWin_t area, const color_t* bg_color);
void display_print_in_area(const char* st, int x, int y, dispWin_t areaWin, bool wrap);
int display_get_string_width(const char* str);
-void display_set_font(uint8_t font, const char* font_file);
+void display_set_font(uint8_t font);
int display_get_font_height(void);
void display_flush(void);
#endif /* DISPLAY_H_ */
diff --git a/main/gui.c b/main/gui.c
index 4fd5582..b44afa5 100644
--- a/main/gui.c
+++ b/main/gui.c
@@ -1482,7 +1482,7 @@ static inline bool can_text_fit(const char* text, uint32_t font, dispWin_t cs)
{
JADE_ASSERT(text);
- display_set_font(font, NULL); // measure relative to this font
+ display_set_font(font); // measure relative to this font
return display_get_string_width(text) <= cs.x2 - cs.x1;
}
@@ -1967,7 +1967,7 @@ static void render_text(gui_view_node_t* node, dispWin_t cs)
JADE_ASSERT(node);
JADE_ASSERT(node->kind == TEXT);
- display_set_font(node->text->font, NULL);
+ display_set_font(node->text->font);
if (node->text->scroll) {
// this text has the scroll enable, so disable wrap
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.