From c756a8a89d6970090b060a179dcabb93a67d8f21 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 10 Nov 2022 09:38:50 -0500 Subject: make splash split on control characters splits on spaces also considers \r\n\f\v\t as mandatory breaks I'm still working on the strptokspn function my goal is to use it directly rather than storing the matched char and modifying the source string with \0 in order to tokenize the output --Done Change-Id: I7f378b5b9c4df8f10899b9a55a98950afb3931dc --- firmware/font.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'firmware/font.c') diff --git a/firmware/font.c b/firmware/font.c index 7ce64ed47d..97a15221fc 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -1046,16 +1046,20 @@ const unsigned char* font_get_bits(struct font* pf, unsigned short char_code) #endif /* BOOTLOADER */ /* - * Returns the stringsize of a given string. + * Returns the stringsize of a given NULL terminated string + * stops after maxbytes or NULL (\0) whichever occurs first. + * maxbytes = -1 ignores maxbytes and relies on NULL terminator (\0) + * to terminate the string */ -int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) +int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *h, int fontnum) { - struct font* pf = font_get(fontnumber); + struct font* pf = font_get(fontnum); + font_lock( fontnum, true ); unsigned short ch; int width = 0; + size_t b = maxbytes - 1; - font_lock( fontnumber, true ); - for (str = utf8decode(str, &ch); ch != 0 ; str = utf8decode(str, &ch)) + for (str = utf8decode(str, &ch); ch != 0 && b < maxbytes; str = utf8decode(str, &ch), b--) { if (is_diacritic(ch, NULL)) continue; @@ -1067,10 +1071,18 @@ int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) *w = width; if ( h ) *h = pf->height; - font_lock( fontnumber, false ); + font_lock( fontnum, false ); return width; } +/* + * Returns the stringsize of a given NULL terminated string. + */ +int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) +{ + return font_getstringnsize(str, -1, w, h, fontnumber); +} + /* ----------------------------------------------------------------- * vim: et sw=4 ts=8 sts=4 tw=78 */ -- cgit v1.2.3