diff options
Diffstat (limited to 'firmware/font.c')
-rw-r--r-- | firmware/font.c | 24 |
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 | */ |
1051 | int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) | 1054 | int 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 | */ | ||
1081 | int 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 | */ |