aboutsummaryrefslogtreecommitdiff
path: root/vt.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-06-26 16:38:47 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-06-26 16:38:47 +0000
commitcbe399ecd9978b9c8a83aefa89e1b97ef4465fee (patch)
tree0ef1ea631de8ae3d6f6fe46ebe382791d70159ef /vt.c
parentdoc: foot.ini: fix typos (diff)
parentscripts: generate-emoji-variation-sequences: don't assume single codepoint sequences (diff)
Merge branch 'vs15-16'
Closes #1742
Diffstat (limited to 'vt.c')
-rw-r--r--vt.c63
1 files changed, 56 insertions, 7 deletions
diff --git a/vt.c b/vt.c
index a8a0f0fb..ba78540f 100644
--- a/vt.c
+++ b/vt.c
@@ -16,6 +16,7 @@
#include "csi.h"
#include "dcs.h"
#include "debug.h"
+#include "emoji-variation-sequences.h"
#include "grid.h"
#include "osc.h"
#include "sixel.h"
@@ -655,6 +656,38 @@ chain_key(uint32_t old_key, uint32_t new_wc)
return new_key;
}
+#if defined(FOOT_GRAPHEME_CLUSTERING)
+static int
+emoji_vs_compare(const void *_key, const void *_entry)
+{
+ const struct emoji_vs *key = _key;
+ const struct emoji_vs *entry = _entry;
+
+ uint32_t cp = key->start;
+
+ if (cp < entry->start)
+ return -1;
+ else if (cp > entry->end)
+ return 1;
+ else
+ return 0;
+}
+
+UNITTEST
+{
+ /* Verify the emoji_vs list is sorted */
+ int64_t last_end = -1;
+
+ for (size_t i = 0; i < sizeof(emoji_vs) / sizeof(emoji_vs[0]); i++) {
+ const struct emoji_vs *vs = &emoji_vs[i];
+ xassert(vs->start <= vs->end);
+ xassert(vs->start > last_end);
+ xassert(vs->vs15 || vs->vs16);
+ last_end = vs->end;
+ }
+}
+#endif
+
static void
action_utf8_print(struct terminal *term, char32_t wc)
{
@@ -852,21 +885,37 @@ action_utf8_print(struct terminal *term, char32_t wc)
break;
case GRAPHEME_WIDTH_DOUBLE:
+ new_cc->width = min(grapheme_width + width, 2);
+
#if defined(FOOT_GRAPHEME_CLUSTERING)
+ /* Handle VS-15 and VS-16 variation selectors */
if (unlikely(grapheme_clustering &&
- wc == 0xfe0f &&
+ (wc == 0xfe0e || wc == 0xfe0f) &&
new_cc->count == 2))
{
- /* Only emojis should be affected by VS16 */
- const utf8proc_property_t *props =
- utf8proc_get_property(new_cc->chars[0]);
+ const struct emoji_vs *vs =
+ bsearch(
+ &(struct emoji_vs){.start = new_cc->chars[0]},
+ emoji_vs, sizeof(emoji_vs) / sizeof(emoji_vs[0]),
+ sizeof(struct emoji_vs),
+ &emoji_vs_compare);
+
+ if (vs != NULL) {
+ xassert(new_cc->chars[0] >= vs->start &&
+ new_cc->chars[0] <= vs->end);
- if (props->boundclass == UTF8PROC_BOUNDCLASS_EXTENDED_PICTOGRAPHIC)
- width = 2;
+ /* Force a grapheme width of 1 for VS-15, and 2 for VS-16 */
+ if (wc == 0xfe0e) {
+ if (vs->vs15)
+ new_cc->width = 1;
+ } else if (wc == 0xfe0f) {
+ if (vs->vs16)
+ new_cc->width = 2;
+ }
+ }
}
#endif
- new_cc->width = min(grapheme_width + width, 2);
break;
case GRAPHEME_WIDTH_WCSWIDTH: