unicode-combine: only compose if we don't have any other combining characters

If the client sent the sequence SAB, where SA does NOT have a composed
representation, but SB does, the old code would compose SB and throw
away A.

This patch fixes this by only allowing a compose if there aren't
any pre-existing combining characters.
This commit is contained in:
Daniel Eklöf 2020-05-01 20:17:37 +02:00
parent a6cd151cc7
commit 50543983ad
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

22
vt.c
View file

@ -575,13 +575,22 @@ action_utf8_print(struct terminal *term, uint8_t c)
if (base != 0 && base_width > 0) { if (base != 0 && base_width > 0) {
/* /*
* First, see if there's a pre-composed character of this * If this is the *first* combining characger, see if
* combo, with the same column width as the base * there's a pre-composed character of this combo, with
* character. If there is, replace the base character with * the same column width as the base character.
* the pre-composed character, as that is likely to *
* produce a better looking result. * If there is, replace the base character with the
* pre-composed character, as that is likely to produce a
* better looking result.
*
* TODO: we could perhaps remove this is we improve our
* positioning of the combining characters when rendering
* the glyph.
*/ */
struct combining_chars *comb_chars = &row->comb_chars[base_col];
if (comb_chars->count == 0) {
wchar_t composed[] = {base, wc}; wchar_t composed[] = {base, wc};
ssize_t composed_length = utf8proc_normalize_utf32( ssize_t composed_length = utf8proc_normalize_utf32(
composed, ALEN(composed), UTF8PROC_COMPOSE | UTF8PROC_STABLE); composed, ALEN(composed), UTF8PROC_COMPOSE | UTF8PROC_STABLE);
@ -593,8 +602,7 @@ action_utf8_print(struct terminal *term, uint8_t c)
term_print(term, composed[0], composed_width); term_print(term, composed[0], composed_width);
return; return;
} }
}
struct combining_chars *comb_chars = &row->comb_chars[base_col];
if (comb_chars->count < ALEN(comb_chars->chars)) if (comb_chars->count < ALEN(comb_chars->chars))
comb_chars->chars[comb_chars->count++] = wc; comb_chars->chars[comb_chars->count++] = wc;