From d83d7c046863750e82d150b8d3d87e4c2bc23b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 14 Dec 2022 12:33:56 +0100 Subject: [PATCH] vt: improve handling of codepoint 0xfe0f when grapheme-width-method != double-width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Unicode codepoint 0xfe0f (Variation Selector 16) means the preceding emoji should be rendered with its graphical representation, rather than its text representation. This typically means a double-width glyph. Before this patch, we only handled this correctly for grapheme-width-method=double-width. In all other cases, we treated it as any other codepoint. Meaning, for ‘max’, we called wcwidth(0xfe0f), and compared against the last width. For ‘wcswidth’ (the default), we also called wcwidth(0xfe0f) and added this to the existing grapheme width. With this patch, ‘max’ is changed to treat 0xfe0f as if it has width == 2. So if the preceding emoji has width=1 (typically so), then we now assign it width 2. For `wcswidth`, we simply ignore the existing grapheme width and simply set it to two. This will be correct when 0xfe0f is used correctly, but may yield strange results otherwise. --- CHANGELOG.md | 4 ++++ vt.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ead014cf..ae8e0b19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,10 @@ config values (e.g. letter offsets, line height etc). * Selection being stuck visually when `IL` and `DL`.` * URL underlines sometimes still being visible after exiting URL mode. +* Handling of Unicode Variation Selector-16 when + `grapheme-width-method` is set to either `max` or `wcswidth` (the + default). Before this, it was only handled correctly when + `grapheme-width-method=double-width`. [1173]: https://codeberg.org/dnkl/foot/issues/1173 [1190]: https://codeberg.org/dnkl/foot/issues/1190 diff --git a/vt.c b/vt.c index 91f00e6f..d5167622 100644 --- a/vt.c +++ b/vt.c @@ -832,6 +832,8 @@ action_utf8_print(struct terminal *term, char32_t wc) switch (term->conf->tweak.grapheme_width_method) { case GRAPHEME_WIDTH_MAX: + if (unlikely(wc == 0xfe0f)) + width = 2; new_cc->width = max(grapheme_width, width); break; @@ -842,7 +844,10 @@ action_utf8_print(struct terminal *term, char32_t wc) break; case GRAPHEME_WIDTH_WCSWIDTH: - new_cc->width = grapheme_width + width; + if (unlikely(wc == 0xfe0f)) + new_cc->width = 2; + else + new_cc->width = grapheme_width + width; break; }