Skip to content

Commit

Permalink
rdpq_paragraph: fix word wrap algorithm in pathological cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Sep 11, 2024
1 parent 00e51ea commit dbcbb36
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/rdpq/rdpq_paragraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,22 @@ void rdpq_paragraph_builder_span(const char *utf8_text, int nbytes)
wrapch -= 1;
}

// We have now found the character at which we want to wrap.
// We want to insert the ellipsis in place of this character,
// but using the font/style of the *previous* character (if it exists).
builder.layout->nchars = wrapchar;
uint8_t wrap_font_id, wrap_style_id;
if (wrapchar > 0) {
wrap_font_id = wrapch[-1].font_id; wrap_style_id = wrapch[-1].style_id;
} else {
wrap_font_id = wrapch[0].font_id; wrap_style_id = wrapch[0].style_id;
}
wfnt = rdpq_text_get_font(wrap_font_id);

uint8_t ellipsis_atlas_id;
__rdpq_font_glyph_metrics(wfnt, wfnt->ellipsis_glyph, NULL, NULL, NULL, NULL, &ellipsis_atlas_id);

builder.layout->nchars = wrapchar;
uint8_t wrap_font_id = wrapch[-1].font_id, wrap_style_id = wrapch[-1].style_id;
assert(wrap_font_id > 0);
for (int i=0; i<wfnt->ellipsis_reps; i++) {
if (UNLIKELY(builder.layout->nchars >= builder.layout->capacity)) paragraph_extend();
builder.layout->chars[builder.layout->nchars++] = (rdpq_paragraph_char_t) {
Expand Down

0 comments on commit dbcbb36

Please sign in to comment.