@@ -1070,6 +1070,9 @@ void nbgl_textWrapOnNbLines(nbgl_font_id_e fontId, char *text, uint16_t maxWidth
1070
1070
char * lastDelimiter = NULL ;
1071
1071
uint32_t lenAtLastDelimiter = 0 ;
1072
1072
char * prevText = NULL ;
1073
+ char * prevPrevText = NULL ;
1074
+ uint16_t prevWidth = 0 ;
1075
+
1073
1076
#ifdef HAVE_UNICODE_SUPPORT
1074
1077
nbgl_unicode_ctx_t * unicode_ctx = NULL ;
1075
1078
#endif // HAVE_UNICODE_SUPPORT
@@ -1078,12 +1081,13 @@ void nbgl_textWrapOnNbLines(nbgl_font_id_e fontId, char *text, uint16_t maxWidth
1078
1081
uint8_t char_width ;
1079
1082
uint32_t unicode ;
1080
1083
bool is_unicode ;
1081
- char * prevPrevText ;
1084
+ char * prevPrevPrevText ;
1082
1085
1083
- // memorize the two last chars
1084
- prevPrevText = prevText ;
1085
- prevText = text ;
1086
- unicode = nbgl_popUnicodeChar ((const uint8_t * * ) & text , & textLen , & is_unicode );
1086
+ // memorize the three last chars
1087
+ prevPrevPrevText = prevPrevText ;
1088
+ prevPrevText = prevText ;
1089
+ prevText = text ;
1090
+ unicode = nbgl_popUnicodeChar ((const uint8_t * * ) & text , & textLen , & is_unicode );
1087
1091
// if \n, reset width
1088
1092
if (unicode == '\n' ) {
1089
1093
width = 0 ;
@@ -1117,26 +1121,38 @@ void nbgl_textWrapOnNbLines(nbgl_font_id_e fontId, char *text, uint16_t maxWidth
1117
1121
* lastDelimiter ++ = '\n' ;
1118
1122
text = lastDelimiter ;
1119
1123
lastDelimiter = NULL ;
1120
- textLen = lenAtLastDelimiter ;
1124
+ textLen = lenAtLastDelimiter - 1 ;
1121
1125
}
1122
1126
else {
1123
1127
textLen += text - prevText ;
1124
1128
text = prevText ;
1125
1129
}
1126
1130
// reset width for next line
1127
1131
width = 0 ;
1132
+ continue ;
1128
1133
}
1129
1134
else {
1130
- // replace the 2 last chars by '...' (should be same width)
1135
+ // replace the 2 or 3 last chars by '...'
1136
+ // try at first with 2, if it fits
1131
1137
if (prevPrevText != NULL ) {
1132
- * prevPrevText ++ = '.' ;
1133
- * prevPrevText ++ = '.' ;
1134
- * prevPrevText ++ = '.' ;
1135
- * prevPrevText = '\0' ;
1138
+ if ((prevWidth + (3 * getCharWidth (font , '.' , false))) <= maxWidth ) {
1139
+ * prevPrevText ++ = '.' ;
1140
+ * prevPrevText ++ = '.' ;
1141
+ * prevPrevText ++ = '.' ;
1142
+ * prevPrevText = '\0' ;
1143
+ }
1144
+ else if (prevPrevPrevText != NULL ) {
1145
+ * prevPrevPrevText ++ = '.' ;
1146
+ * prevPrevPrevText ++ = '.' ;
1147
+ * prevPrevPrevText ++ = '.' ;
1148
+ * prevPrevPrevText = '\0' ;
1149
+ }
1136
1150
}
1137
1151
return ;
1138
1152
}
1139
1153
}
1154
+ // memorize the last width
1155
+ prevWidth = width ;
1140
1156
width += char_width ;
1141
1157
}
1142
1158
}
0 commit comments