Skip to content

Commit 5fbced1

Browse files
authored
Merge pull request #1124 from jef41/patch/pico-vector-measure-text
correct measurement of utf-8 characters in pico_vector
2 parents f32f26c + 99c2c7e commit 5fbced1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libraries/pico_vector/alright-fonts.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,12 @@ pp_rect_t af_measure(af_face_t *face, const char *text, size_t tlen, float max_l
460460
int line_width = get_line_width(face, line, &line_len, max_line_width, tm);
461461
char *end = line + line_len;
462462

463-
for(char c = *line; line < end; line++, c = *line) {
463+
while(line < end) {
464+
uint16_t c = get_utf8_char(line, end);
465+
line++;
466+
if(c > 0x7F) line++;
467+
if(c > 0x7FF) line++;
468+
464469
af_glyph_t *glyph = find_glyph(face, c);
465470
if(!glyph) {
466471
continue;
@@ -489,7 +494,7 @@ pp_rect_t af_measure(af_face_t *face, const char *text, size_t tlen, float max_l
489494
result = pp_rect_merge(&result, &r);
490495
}
491496

492-
if(c == L' ') {
497+
if(c == ' ') {
493498
caret.x += (glyph->advance * tm->word_spacing) / 100.0f;
494499
} else {
495500
caret.x += (glyph->advance * tm->letter_spacing) / 100.0f;

0 commit comments

Comments
 (0)