summaryrefslogtreecommitdiff
path: root/firmware/font.c
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-11-10 09:38:50 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2022-11-12 06:22:16 -0500
commitc756a8a89d6970090b060a179dcabb93a67d8f21 (patch)
tree868fa2b1393c512ecfa445688635ada71086dea7 /firmware/font.c
parentdd1fbd51fc7bb3fa7237b3bc34335e99bef29e35 (diff)
downloadrockbox-c756a8a89d6970090b060a179dcabb93a67d8f21.tar.gz
rockbox-c756a8a89d6970090b060a179dcabb93a67d8f21.zip
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
Diffstat (limited to 'firmware/font.c')
-rw-r--r--firmware/font.c24
1 files changed, 18 insertions, 6 deletions
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)
1046#endif /* BOOTLOADER */ 1046#endif /* BOOTLOADER */
1047 1047
1048/* 1048/*
1049 * Returns the stringsize of a given string. 1049 * Returns the stringsize of a given NULL terminated string
1050 * stops after maxbytes or NULL (\0) whichever occurs first.
1051 * maxbytes = -1 ignores maxbytes and relies on NULL terminator (\0)
1052 * to terminate the string
1050 */ 1053 */
1051int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) 1054int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *h, int fontnum)
1052{ 1055{
1053 struct font* pf = font_get(fontnumber); 1056 struct font* pf = font_get(fontnum);
1057 font_lock( fontnum, true );
1054 unsigned short ch; 1058 unsigned short ch;
1055 int width = 0; 1059 int width = 0;
1060 size_t b = maxbytes - 1;
1056 1061
1057 font_lock( fontnumber, true ); 1062 for (str = utf8decode(str, &ch); ch != 0 && b < maxbytes; str = utf8decode(str, &ch), b--)
1058 for (str = utf8decode(str, &ch); ch != 0 ; str = utf8decode(str, &ch))
1059 { 1063 {
1060 if (is_diacritic(ch, NULL)) 1064 if (is_diacritic(ch, NULL))
1061 continue; 1065 continue;
@@ -1067,10 +1071,18 @@ int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber)
1067 *w = width; 1071 *w = width;
1068 if ( h ) 1072 if ( h )
1069 *h = pf->height; 1073 *h = pf->height;
1070 font_lock( fontnumber, false ); 1074 font_lock( fontnum, false );
1071 return width; 1075 return width;
1072} 1076}
1073 1077
1078/*
1079 * Returns the stringsize of a given NULL terminated string.
1080 */
1081int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber)
1082{
1083 return font_getstringnsize(str, -1, w, h, fontnumber);
1084}
1085
1074/* ----------------------------------------------------------------- 1086/* -----------------------------------------------------------------
1075 * vim: et sw=4 ts=8 sts=4 tw=78 1087 * vim: et sw=4 ts=8 sts=4 tw=78
1076 */ 1088 */