From ebac219ba3c77c77d3cc8e8ee9358a36026f7ca3 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 9 Jun 2018 08:49:27 +0200 Subject: [PATCH] lv_txt_get_width: trim letter space of trailing non-printoble characters --- lv_misc/lv_txt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lv_misc/lv_txt.c b/lv_misc/lv_txt.c index d19c6365d..7e2c567a2 100644 --- a/lv_misc/lv_txt.c +++ b/lv_misc/lv_txt.c @@ -199,9 +199,12 @@ lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, width += letter_space; } + + width -= letter_space; /*Trim the last letter space. Important if the text is center aligned */ + /*Trim closing spaces. Important when the text is aligned to the middle */ for(i = length - 1; i > 0; i--) { - if(txt[i] == ' ') { + if(txt[i] == ' ' || txt[i] == '\n' || txt[i] == '\r') { width -= lv_font_get_width(font, txt[i]); width -= letter_space; } else {