From 57e636dd8e3be0e75492f226e036943989422b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 15 Jun 2021 07:38:27 +0200 Subject: [PATCH] =?UTF-8?q?vt:=20don=E2=80=99t=20call=20wcwidth()=20on=20a?= =?UTF-8?q?ll=20combining=20characters=20every=20time=20we=20add?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We already have all the widths needed to calculate the new one; it’s the base characters width (base_width), or the previous combining chain’s width (composed->width) plus the new characters’s width (width). --- vt.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/vt.c b/vt.c index c343ba14..b99b4fef 100644 --- a/vt.c +++ b/vt.c @@ -700,7 +700,7 @@ action_utf8_print(struct terminal *term, wchar_t wc) if (cc->count != wanted_count) continue; - if (cc->chars[0] != base) + if (cc->chars[0] != base) continue; bool match = true; @@ -732,16 +732,12 @@ action_utf8_print(struct terminal *term, wchar_t wc) new_cc.chars[wanted_count - 1] = wc; if (term->composed_count < CELL_COMB_CHARS_HI) { - int grapheme_width = wcwidth(base); - int min_grapheme_width = 0; - for (size_t i = 0; i < wanted_count; i++) { - wchar_t c = new_cc.chars[i]; - if (c == 0xfe0f) - min_grapheme_width = 2; - grapheme_width += wcwidth(c); - } - - new_cc.width = max(grapheme_width, min_grapheme_width); + int grapheme_width = composed != NULL ? composed->width : base_width; + if (wc == 0xfe0f && grapheme_width < 2) + grapheme_width = 2; + else + grapheme_width += width; + new_cc.width = grapheme_width; term->composed_count++; term->composed = xrealloc(term->composed, term->composed_count * sizeof(term->composed[0]));