From e567b489109b91ee2689b32647b44279a00852f4 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 5 Jun 2024 14:44:35 +0100 Subject: [PATCH] PicoVector: render text that doesn't end with a linebreak. --- libraries/pico_vector/alright-fonts.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/pico_vector/alright-fonts.h b/libraries/pico_vector/alright-fonts.h index 655f890a..e598764b 100644 --- a/libraries/pico_vector/alright-fonts.h +++ b/libraries/pico_vector/alright-fonts.h @@ -250,6 +250,7 @@ void af_render_character(af_face_t *face, const char c, af_text_metrics_t *tm) { int get_line_width(af_face_t *face, const char *text, af_text_metrics_t *tm) { int line_width = 0; char *end = strchr(text, '\n'); + if (!end) end = (char *)text + strlen(text); for(char c = *text; text < end; text++, c = *text) { af_glyph_t *glyph = find_glyph(face, c); if(!glyph) { @@ -297,7 +298,9 @@ void af_render(af_face_t *face, const char *text, af_text_metrics_t *tm) { caret.y = 0; char *end = strchr(text, '\n'); - while(end) { + if (!end) end = (char *)text + strlen(text); + + while(true) { int line_width = get_line_width(face, text, tm); for(char c = *text; text < end; text++, c = *text) { @@ -331,7 +334,9 @@ void af_render(af_face_t *face, const char *text, af_text_metrics_t *tm) { } text = end + 1; + if (*text == '\0') break; end = strchr(text, '\n'); + if (!end) end = (char *)text + strlen(text); caret.x = 0; caret.y += line_height;