From 3f43fe3cd8391cedfb2b6440ad15b8a250bb4f63 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Mon, 27 Oct 2025 07:31:19 -0400 Subject: [PATCH] checkwps: Validate all fonts in themes Makes sure any fonts specified are either: * Present in the theme itself * One of the fonts in the Rockbox bundle Change-Id: I215132835e2ae7faa06662637bc867df9c5dba92 --- tools/Makefile | 8 -------- tools/checkwps/checkwps.c | 31 +++++++++++++++++++++++++++++++ tools/checkwps/checkwps.make | 7 +++++++ tools/root.make | 2 +- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index 6b990ddce3..525048d39e 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -67,13 +67,6 @@ lngdump: lngdump.c ipod_fw: ipod_fw.c $(SILENT)$(CC) $(CFLAGS) $+ -o $@ -checkwps: checkwps.c ../apps/gui/wps_parser.c ../apps/gui/wps_debug.c \ - ../firmware/common/ctype.c ../apps/misc.c ../apps/recorder/bmp.c - $(SILENT)$(CC) $(CFLAGS) -I ../apps/gui -I../firmware/export \ - -D__PCTOOL__ -DDEBUG -DROCKBOX_HAS_LOGF -DIPOD_COLOR \ - -D ROCKBOX_DIR_LEN -D WPS_DIR=\".\" -I../apps \ - -I../firmware/target/arm/ipod -I../firmware/include $+ -o $@ - convbdf: convbdf.c $(SILENT)$(CC) $(CFLAGS) $+ -o $@ @@ -106,4 +99,3 @@ clean: echo $$f.exe $$f.o $$f.obj ; done) *.ajf *~ $(SILENT)$(MAKE) -C ucl clean $(SILENT)$(MAKE) -C rbspeex clean - diff --git a/tools/checkwps/checkwps.c b/tools/checkwps/checkwps.c index 4d87156122..6c4e404800 100644 --- a/tools/checkwps/checkwps.c +++ b/tools/checkwps/checkwps.c @@ -226,10 +226,41 @@ bool radio_hardware_present(void) } #endif +#include "fontbundle.h" + static int loaded_fonts = 0; static struct font _font; int font_load(const char *path) { + /* First see if it exists in the theme */ + int fd = open(path, O_RDONLY); + if (fd < 0) { + char buf[1024]; + sprintf(buf, ".rockbox/%s", path); + fd = open(buf, O_RDONLY); + if (fd < 0) { + char *first = strrchr(buf, '/'); + char *final = strrchr(buf, '.'); + *final = 0; + int missing = 1; + /* Check if font is included in the bundle */ + for (int i = 0 ; bundledfonts[i] != NULL ; i++) { + if (!strcmp(first+1, bundledfonts[i])) { + missing = 0; + break; + } + } + if (missing) { + //printf("Font missing >%s<\n", first+1); + return -1; + } else { + printf("INFO: Theme requires rockbox font bundle\n"); + } + } + } + if (fd >= 0) + close(fd); + int id = 2 + loaded_fonts; loaded_fonts++; return id; diff --git a/tools/checkwps/checkwps.make b/tools/checkwps/checkwps.make index bec652d292..c103cdcc47 100644 --- a/tools/checkwps/checkwps.make +++ b/tools/checkwps/checkwps.make @@ -40,6 +40,13 @@ $(BUILDDIR)/$(BINARY): $$(CHECKWPS_OBJ) $$(CORE_LIBS) $(SILENT)$(HOSTCC) -o $@ $+ $(INCLUDE) $(GCCOPTS) \ -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) +$(BUILDDIR)/fontbundle.h: $(ROOTDIR)/fonts/*bdf + @echo FONTBUNDLE + $(SILENT)echo "static unsigned char* bundledfonts[] = {" > $@ + $(SILENT)ls $(ROOTDIR)/fonts/*bdf | perl -pne 's|.*/(\d+-.*)\.bdf| "$$1",|;' >> $@ + $(SILENT)echo " NULL, " >> $@ + $(SILENT)echo "};" >> $@ + #### Everything below is hacked in from apps.make and lang.make $(BUILDDIR)/apps/features: $(ROOTDIR)/apps/features.txt diff --git a/tools/root.make b/tools/root.make index 90d82d463c..3e98a78a5d 100644 --- a/tools/root.make +++ b/tools/root.make @@ -226,7 +226,7 @@ clean:: $(LINKRAM) $(LINKROM) rockbox.elf rockbox.map rockbox.bin \ make.dep rombox.elf rombox.map rombox.bin romstart.txt \ $(BINARY) $(FLASHFILE) uisimulator bootloader flash $(BOOTLINK) \ - rockbox.apk lang_enum.h rbversion.h + rockbox.apk lang_enum.h rbversion.h fontbundle.h #### linking the binaries: ####