This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit ad70396173c3959f40e160a3886ef3ca0e25836f
Author: Boris Faure <[email protected]>
AuthorDate: Mon Nov 16 22:11:56 2026 +0000
termptydbl: give combining marks and format characters no width
Only U+0300..U+036F, U+200B..U+200F and the variation selectors were
skipped; every other combining mark took a cell. Programs give them no
width, as wcwidth() does, so a line of Hebrew points, Arabic marks or
combining marks for symbols ended up wider on screen than they
expected. Once such a line reached the right edge it wrapped and pushed
the rows below it, and the extra cells were never erased: scrolling a
file of such characters in an editor overwrote its status line and left
stray glyphs behind.
Generate a zero-width table from the UCD, following wcwidth() in
glibc: non-spacing and enclosing marks, format characters but the soft
hyphen and the prepended concatenation marks, and the Hangul medial
vowels and final consonants. Spacing marks keep their cell.
The table is a two-level bitmap rather than a switch, which cost 5% on
the unicode corpus of tybench. Over ten interleaved runs of 20
iterations, unicode goes from 112.7 to 111.8 MB/s (-0.7%), and the
other corpora stay within noise.
---
src/bin/termptydbl.c | 116 +++++++++++++++++++++++++++++++++++++++++++++
src/bin/termptydbl.h | 17 +++++++
src/bin/termptyops.c | 7 +--
tests/tests.results | 1 +
tests/zero-width.sh | 32 +++++++++++++
tools/unicode_dbl_width.py | 104 +++++++++++++++++++++++++++++++++++++---
6 files changed, 265 insertions(+), 12 deletions(-)
diff --git a/src/bin/termptydbl.c b/src/bin/termptydbl.c
index 22ebed2d..ab39f8f2 100644
--- a/src/bin/termptydbl.c
+++ b/src/bin/termptydbl.c
@@ -713,3 +713,119 @@ _termpty_is_wide(Eina_Unicode g, Eina_Bool emoji_dbl_width)
}
return EINA_FALSE;
}
+
+/* 256-bit block of each 256 code points below the table end */
+const unsigned char _termpty_zero_width_block[] = {
+ 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 0, 16, 0, 0, 0, 17, 18, 19, 20, 21, 22, 23, 0, 0,
+ 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 26, 0, 0,
+ 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 28, 0, 29, 30, 31, 32, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 35, 36,
+ 0, 37, 38, 39, 0, 0, 0, 0, 0, 0, 40, 0, 0, 41, 42, 43,
+ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 61, 0, 0, 0, 0, 0, 0, 0, 0, 62, 63, 0, 0, 0, 64,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66,
+ 0, 67, 68, 0, 0, 0, 0, 0, 0, 0, 69, 0, 0, 0, 0, 0,
+ 70, 63, 71, 0, 72, 73, 74, 0, 75, 76, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+
+const unsigned int _termpty_zero_width_bits[][8] = {
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000FFFF, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000003F8, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xFFFE0000, 0xBFFFFFFF, 0x000003B6, 0x00000000 },
+ { 0x17FF0000, 0x00000000, 0xFFFFF800, 0x00010000, 0x00000000, 0x00000000, 0x9FC00000, 0x00003D9F },
+ { 0x00020000, 0xFFFF0000, 0x000007FF, 0x00000000, 0x00000000, 0x0001FFC0, 0x00000000, 0x200FF800 },
+ { 0xFBC00000, 0x00003EEF, 0x0E000000, 0x00000000, 0xFF800000, 0x00000000, 0xFFFFFC00, 0xFFFFFFFB },
+ { 0x00000007, 0x14000000, 0x00FE21FE, 0x0000000C, 0x00000002, 0x10000000, 0x0000201E, 0xC000000C },
+ { 0x00000007, 0x10000000, 0x0003FFFE, 0x00230000, 0x00000006, 0x10000000, 0x000021FE, 0xFC00000C },
+ { 0x00000003, 0x90000000, 0x007FE01E, 0x0000000C, 0x00000004, 0x00000000, 0x00002001, 0x00000000 },
+ { 0x00000011, 0xD0000000, 0x007FFFC1, 0x0000000C, 0x00000002, 0x90000000, 0x00003040, 0x0000000C },
+ { 0x00000003, 0x18000000, 0x0000201E, 0x0000000C, 0x00000002, 0x00000000, 0x007C0400, 0x00000000 },
+ { 0x00000000, 0x07F20000, 0x00007F80, 0x00000000, 0x00000000, 0x1FF20000, 0x00007F00, 0x00000000 },
+ { 0x03000000, 0x02A00000, 0x00000000, 0x7FFE0000, 0xFFFFE0DF, 0x1FFFFFFF, 0x00000040, 0x00000000 },
+ { 0x00000000, 0x66FDE000, 0xC3000000, 0x001E0001, 0x20002064, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF },
+ { 0x00000000, 0x00000000, 0xE0000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x001C0000, 0x000C0000, 0x000C0000, 0x000C0000, 0x00000000, 0x3FB00000, 0x200FFE40, 0x00000000 },
+ { 0x0000F800, 0x00000000, 0x00000000, 0x00000000, 0x00000060, 0x00000200, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x0E040187, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x09800000, 0x00000000, 0xFF400000, 0xFFF81FE5, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFFF },
+ { 0x0000000F, 0x17D00000, 0x00000004, 0x000FF800, 0x00000003, 0x00003B3C, 0x00000000, 0x0003A340 },
+ { 0x00000000, 0x00CFF000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xFFF70000, 0x031021FD },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF },
+ { 0x0000F800, 0x00007C00, 0x00000000, 0x0000FFFF, 0x00000000, 0x00000000, 0xFFFF0000, 0x0001FFFF },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00038000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF },
+ { 0x00000000, 0x00003C00, 0x00000000, 0x00000000, 0x06000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x3FF78000, 0xC0000000, 0x00000000, 0x00000000, 0x00030000 },
+ { 0x00000844, 0x00001060, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000030, 0x8003FFFF },
+ { 0x00000000, 0x00003FC0, 0x0003FF80, 0x00000000, 0x00000007, 0x33C80000, 0x00000000, 0x00000020 },
+ { 0x00000000, 0x00667E00, 0x00001008, 0x10000000, 0x00000000, 0xC19D0000, 0x00000002, 0x00403000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00002120 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0x0FFFFFFF },
+ { 0x40000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x0000FFFF, 0x0000FFFF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x80000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0E000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x20000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x07C00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x0000FFFE, 0xFF000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000060 },
+ { 0x00000000, 0x000000F0, 0x00000000, 0x00003E00, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00001800, 0x0000F800, 0xFFFF0000 },
+ { 0x00000000, 0x00000000, 0x0001FFC0, 0x00000000, 0x0000003C, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000002, 0xFF000000, 0x0000007F, 0x80190000, 0x00000003, 0x06780000, 0x00000004, 0x00000000 },
+ { 0x00000007, 0x001FEF80, 0x00000000, 0x00080000, 0x00000003, 0x7FC00000, 0x00009E00, 0x00000000 },
+ { 0x00000000, 0x40D38000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x80000000, 0x000007F8 },
+ { 0x00000003, 0x18000000, 0x00000001, 0x001FFFC0, 0x00000000, 0xF8000000, 0x00054001, 0x00000006 },
+ { 0x00000000, 0xFF000000, 0x4000005C, 0x00000000, 0x00000000, 0x85F80000, 0x0000000D, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xB03C0000, 0x30000001, 0x00000000 },
+ { 0x00000000, 0xA7F80000, 0x00000001, 0x00000000, 0x00000000, 0x00BF2800, 0x00000000, 0x00000000 },
+ { 0xA0000000, 0x00000FBC, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x06FF8000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x58000000, 0x00000008, 0x00000000, 0x00000000, 0x00000000, 0x0FF00000, 0x00000001 },
+ { 0x000007FE, 0x79F80000, 0x0E7E0080, 0x00000000, 0x037FFC00, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x0000005D, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0xBFFF0000, 0x00000000, 0x00000000, 0xFFFC0000, 0x006DFCFF, 0x00000000, 0x00000000 },
+ { 0x00000000, 0xFFFE0000, 0x000000BF, 0x00000000, 0x00A30000, 0x00000000, 0x00000000, 0x00010000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00180000 },
+ { 0x00000003, 0x07C00000, 0x04000005, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0xFFFF0000, 0x003FFF81, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0xC0000000, 0x0000E3FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x001F0000 },
+ { 0x00000000, 0x007F0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00008000, 0x00000000, 0x00078000, 0x00000000, 0x00000000, 0x00000010 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x60000000, 0x0000000F, 0x00000000, 0x00000000 },
+ { 0xFFFFFFFF, 0xFFFFFFFF, 0x0000007F, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000180, 0x00000000, 0xFFF80380, 0x00000FE7, 0x00003C00, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x1800001C, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0xFFFFFFFF, 0xF87FFFFF, 0xFFFFFFFF, 0x00201FFF, 0xF8000010, 0x0000FFFF, 0x00000000, 0x00000000 },
+ { 0xFFFFFFFF, 0x000007FF, 0x00000000, 0x00000000, 0x00008000, 0x00000000, 0x00000000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004000, 0x00000000, 0x0000F000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000F000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000C000 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0020C048 },
+ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x007F0000, 0x00000000 },
+ { 0x00000000, 0x00000000, 0x000007F0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
+};
diff --git a/src/bin/termptydbl.h b/src/bin/termptydbl.h
index a1f453b8..810b024d 100644
--- a/src/bin/termptydbl.h
+++ b/src/bin/termptydbl.h
@@ -4,6 +4,8 @@
Eina_Bool _termpty_is_wide(const Eina_Unicode g, Eina_Bool emoji_dbl_width);
Eina_Bool _termpty_is_ambigous_wide(const Eina_Unicode g, Eina_Bool emoji_dbl_width);
+extern const unsigned char _termpty_zero_width_block[];
+extern const unsigned int _termpty_zero_width_bits[][8];
static inline Eina_Bool
_termpty_is_wide_table(const Termpty *ty, const Eina_Unicode g, Eina_Bool emoji)
@@ -31,4 +33,19 @@ _termpty_is_dblwidth_get(const Termpty *ty, const Eina_Unicode g, Eina_Bool vs16
_termpty_is_wide_table(ty, g, EINA_TRUE);
}
+/* Combining marks, format characters and Hangul medial vowels and final
+ * consonants: they take no cell. */
+static inline Eina_Bool
+_termpty_is_zero_width_get(const Eina_Unicode g)
+{
+ const unsigned int *bits;
+
+ if (g < 0x300)
+ return EINA_FALSE;
+ if (g >= 0x20000)
+ return ((g >= 0xE0001) && (g <= 0xE01EF));
+ bits = _termpty_zero_width_bits[_termpty_zero_width_block[g >> 8]];
+ return (bits[(g >> 5) & 7] >> (g & 31)) & 1;
+}
+
#endif
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index a7a26d91..2a9fb5e1 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -409,12 +409,7 @@ termpty_text_repeat_count(const Termpty *ty, Eina_Unicode codepoint,
static inline Eina_Bool
_zero_width_skip(Termpty *ty, Eina_Unicode g)
{
- /* 0-width space, RTL/LTR marks and variation selectors (U+FE0F was
- * already handled) */
- if (EINA_UNLIKELY((g >= 0x200b && g <= 0x200f) ||
- (g >= 0xfe00 && g <= 0xfe0f)))
- return EINA_TRUE;
- if (EINA_LIKELY(g < 0x300 || g > 0x36f))
+ if (EINA_LIKELY(!_termpty_is_zero_width_get(g)))
return EINA_FALSE;
if (EINA_UNLIKELY(g == 0x336))
ty->termstate.combining_strike = 1;
diff --git a/tests/tests.results b/tests/tests.results
index 952842c5..bff12af4 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -241,3 +241,4 @@ sd-region-to-bottom.sh a102ef27ade17a979473302b02ae78ea
scroll-region-counts.sh 342c990e76a9bcc7a6be7a939685d841
zero-width-wrapnext.sh 24fc65e89f6438b48ee2882e2cf2bb21
wide-unicode-18.sh 720a9c33382672f78d2045722b69d610
+zero-width.sh 13feb72c327f04b5891b256de112d1d9
diff --git a/tests/zero-width.sh b/tests/zero-width.sh
new file mode 100644
index 00000000..3328d111
--- /dev/null
+++ b/tests/zero-width.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# characters that take no cell, as wcwidth() in glibc: the bar after each
+# lands right after the base letter
+
+printf '\033[2J\033[H'
+
+# hebrew point, arabic mark, enclosing circle, combining marks extended
+# and supplement, half mark, variation selector supplement
+printf 'a\326\260|\r\n'
+printf 'a\331\213|\r\n'
+printf 'a\342\203\235|\r\n'
+printf 'a\341\252\260|\r\n'
+printf 'a\341\267\200|\r\n'
+printf 'a\357\270\240|\r\n'
+printf 'a\363\240\204\200|\r\n'
+
+# format characters: zero width joiner, word joiner, byte order mark,
+# bidi embedding
+printf 'a\342\200\215|\r\n'
+printf 'a\342\201\240|\r\n'
+printf 'a\357\273\277|\r\n'
+printf 'a\342\200\252|\r\n'
+
+# hangul initial consonant, medial vowel, final consonant
+printf '\341\204\200\341\205\241\341\206\250|\r\n'
+
+# these take a cell: soft hyphen, arabic number sign (prepended
+# concatenation mark), devanagari sign visarga (spacing mark)
+printf 'a\302\255|\r\n'
+printf 'a\330\200|\r\n'
+printf 'a\340\244\203|\r\n'
diff --git a/tools/unicode_dbl_width.py b/tools/unicode_dbl_width.py
index 28234e49..d276a188 100755
--- a/tools/unicode_dbl_width.py
+++ b/tools/unicode_dbl_width.py
@@ -12,6 +12,9 @@ import xml.etree.ElementTree as ET
URange = namedtuple('unicode_range', ['width', 'start', 'end'])
+# zero width code points below this are looked up in a bitmap
+ZW_TABLE_END = 0x20000
+
def get_ranges(xmlfile):
tree = ET.parse(xmlfile)
root = tree.getroot()
@@ -20,8 +23,10 @@ def get_ranges(xmlfile):
ranges_basic = []
ranges_emoji_double = []
+ ranges_zero = []
r_basic = URange('N', 0, 0)
r_emoji_dbl = URange('N', 0, 0)
+ r_zero = URange('N', 0, 0)
for c in chars:
ea = c.get('ea')
if ea in ('Na', 'H'):
@@ -33,6 +38,19 @@ def get_ranges(xmlfile):
continue
cp = int(cp, 16)
+ # zero width, as wcwidth() in glibc
+ gc = c.get('gc')
+ if (gc in ('Mn', 'Me') or c.get('hst') in ('V', 'T') or
+ (gc == 'Cf' and cp != 0xAD and c.get('PCM') != 'Y')):
+ zw = 'Z'
+ else:
+ zw = 'N'
+ if zw != r_zero[0]:
+ ranges_zero.append(r_zero)
+ r_zero = URange(zw, cp, cp)
+ else:
+ r_zero = r_zero._replace(end=cp)
+
# basic
if ea != r_basic[0]:
ranges_basic.append(r_basic)
@@ -57,8 +75,9 @@ def get_ranges(xmlfile):
ranges_basic.append(r_basic)
ranges_emoji_double.append(r_emoji_dbl)
+ ranges_zero.append(r_zero)
- return (ranges_basic, ranges_emoji_double)
+ return (ranges_basic, ranges_emoji_double, ranges_zero)
def merge_ranges(ranges, is_same_width):
@@ -80,7 +99,8 @@ def skip_ranges(ranges, width_skipped):
res.append(r)
return res
-def gen_header(mininum_codepoint, file_header):
+def gen_header(mininum_codepoint, minimum_zero_width, high_zero_ranges,
+ file_header):
file_header.write(
"""/* XXX: Code generated by tool unicode_dbl_width.py */
#ifndef TERMINOLOGY_TERMPTY_DBL_H_
@@ -88,6 +108,8 @@ def gen_header(mininum_codepoint, file_header):
Eina_Bool _termpty_is_wide(const Eina_Unicode g, Eina_Bool emoji_dbl_width);
Eina_Bool _termpty_is_ambigous_wide(const Eina_Unicode g, Eina_Bool emoji_dbl_width);
+extern const unsigned char _termpty_zero_width_block[];
+extern const unsigned int _termpty_zero_width_bits[][8];
static inline Eina_Bool
_termpty_is_wide_table(const Termpty *ty, const Eina_Unicode g, Eina_Bool emoji)
@@ -118,6 +140,30 @@ _termpty_is_dblwidth_get(const Termpty *ty, const Eina_Unicode g, Eina_Bool vs16
_termpty_is_wide_table(ty, g, EINA_TRUE);
}
+/* Combining marks, format characters and Hangul medial vowels and final
+ * consonants: they take no cell. */
+static inline Eina_Bool
+_termpty_is_zero_width_get(const Eina_Unicode g)
+{
+ const unsigned int *bits;
+
+""")
+ file_header.write(f" if (g < 0x{minimum_zero_width:X})")
+ file_header.write(
+"""
+ return EINA_FALSE;
+""")
+ file_header.write(f" if (g >= 0x{ZW_TABLE_END:X})\n")
+ file_header.write(" return ")
+ file_header.write(" ||\n ".join(
+ f"((g >= 0x{r.start:X}) && (g <= 0x{r.end:X}))"
+ for r in high_zero_ranges))
+ file_header.write(";\n")
+ file_header.write(
+""" bits = _termpty_zero_width_bits[_termpty_zero_width_block[g >> 8]];
+ return (bits[(g >> 5) & 7] >> (g & 31)) & 1;
+}
+
#endif
""")
@@ -223,9 +269,53 @@ _termpty_is_wide(Eina_Unicode g, Eina_Bool emoji_dbl_width)
""")
-def gen_c(ranges_basic, ranges_emoji_double, file_header, file_source):
+def zero_width_ranges(ranges_zero):
+ ranges = merge_ranges(ranges_zero[1:], lambda r1, r2: r1.width == r2.width)
+ return skip_ranges(ranges, ('N',))
+
+def gen_zero_width(ranges_zero, file_source):
+ bits = bytearray(ZW_TABLE_END // 8)
+ for r in zero_width_ranges(ranges_zero):
+ for cp in range(r.start, min(r.end + 1, ZW_TABLE_END)):
+ bits[cp >> 3] |= 1 << (cp & 7)
+ blocks = []
+ block_of_page = []
+ for page in range(ZW_TABLE_END >> 8):
+ block = bytes(bits[page * 32:(page + 1) * 32])
+ if block not in blocks:
+ blocks.append(block)
+ block_of_page.append(blocks.index(block))
+ assert len(blocks) <= 256
+
+ file_source.write(
+"""
+/* 256-bit block of each 256 code points below the table end */
+const unsigned char _termpty_zero_width_block[] = {
+""")
+ for i in range(0, len(block_of_page), 16):
+ line = ", ".join(f"{b}" for b in block_of_page[i:i + 16])
+ file_source.write(f" {line},\n")
+ file_source.write(
+"""};
+
+const unsigned int _termpty_zero_width_bits[][8] = {
+""")
+ for block in blocks:
+ words = [int.from_bytes(block[i:i + 4], 'little')
+ for i in range(0, 32, 4)]
+ line = ", ".join(f"0x{w:08X}" for w in words)
+ file_source.write(f" {{ {line} }},\n")
+ file_source.write("};\n")
+
+
+def gen_c(ranges_basic, ranges_emoji_double, ranges_zero,
+ file_header, file_source):
mininum_codepoint = min(ranges_basic[0].end, ranges_emoji_double[0].end)
- gen_header(mininum_codepoint, file_header)
+ zero = zero_width_ranges(ranges_zero)
+ high_zero_ranges = [r for r in zero if r.end >= ZW_TABLE_END]
+ assert all(r.start >= ZW_TABLE_END for r in high_zero_ranges)
+ gen_header(mininum_codepoint, zero[0].start, high_zero_ranges,
+ file_header)
file_source.write(
"""/* XXX: Code generated by tool unicode_dbl_width.py */
#include "private.h"
@@ -236,6 +326,7 @@ def gen_c(ranges_basic, ranges_emoji_double, file_header, file_source):
""")
gen_ambigous(ranges_basic, ranges_emoji_double, file_source)
gen_wide(ranges_basic, ranges_emoji_double, file_source)
+ gen_zero_width(ranges_zero, file_source)
parser = argparse.ArgumentParser(description='Generate code handling different widths of unicode codepoints.')
parser.add_argument('xml', type=argparse.FileType('r'))
@@ -244,5 +335,6 @@ parser.add_argument('source', type=argparse.FileType('w'))
args = parser.parse_args()
-(ranges_basic, ranges_emoji_double) = get_ranges(args.xml)
-gen_c(ranges_basic, ranges_emoji_double, args.header, args.source)
+(ranges_basic, ranges_emoji_double, ranges_zero) = get_ranges(args.xml)
+gen_c(ranges_basic, ranges_emoji_double, ranges_zero,
+ args.header, args.source)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.