Skip to content

Commit 6d0826d

Browse files
committed
patch 8.0.0985: libvterm has its own idea of character width
Problem: Libvterm has its own idea of character width. Solution: Use the Vim functions for character width and composing to avoid a mismatch. (idea by Yasuhiro Matsumoto)
1 parent 5830232 commit 6d0826d

7 files changed

Lines changed: 66 additions & 7 deletions

File tree

src/Make_cyg_ming.mak

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,11 @@ $(OUTDIR)/terminal.o: terminal.c $(INCL) $(TERM_DEPS)
971971
$(CC) -c $(CFLAGS) terminal.c -o $(OUTDIR)/terminal.o
972972

973973

974-
CCCTERM = $(CC) -c $(CFLAGS) -Ilibvterm/include -DINLINE="" -DVSNPRINTF=vim_vsnprintf
974+
CCCTERM = $(CC) -c $(CFLAGS) -Ilibvterm/include -DINLINE="" \
975+
-DVSNPRINTF=vim_vsnprintf \
976+
-DIS_COMBINING_FUNCTION=utf_iscomposing_uint \
977+
-DWCWIDTH_FUNCTION=utf_uint2cells
978+
975979
$(OUTDIR)/term_encoding.o: libvterm/src/encoding.c $(TERM_DEPS)
976980
$(CCCTERM) libvterm/src/encoding.c -o $@
977981

src/Make_mvc.mak

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,12 @@ $(OUTDIR)/dimm_i.obj: $(OUTDIR) dimm_i.c $(INCL)
14741474
$(OUTDIR)/glbl_ime.obj: $(OUTDIR) glbl_ime.cpp dimm.h $(INCL)
14751475

14761476

1477-
CCCTERM = $(CC) $(CFLAGS) -Ilibvterm/include -DINLINE="" -DVSNPRINTF=vim_vsnprintf -D_CRT_SECURE_NO_WARNINGS
1477+
CCCTERM = $(CC) $(CFLAGS) -Ilibvterm/include -DINLINE="" \
1478+
-DVSNPRINTF=vim_vsnprintf \
1479+
-DIS_COMBINING_FUNCTION=utf_iscomposing_uint \
1480+
-DWCWIDTH_FUNCTION=utf_uint2cells \
1481+
-D_CRT_SECURE_NO_WARNINGS
1482+
14781483
$(OUTDIR)/term_encoding.obj: $(OUTDIR) libvterm/src/encoding.c $(TERM_DEPS)
14791484
$(CCCTERM) -Fo$@ libvterm/src/encoding.c
14801485

src/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3296,7 +3296,11 @@ objects/channel.o: channel.c
32963296
Makefile:
32973297
@echo The name of the makefile MUST be "Makefile" (with capital M)!!!!
32983298

3299-
CCCTERM = $(CCC) -Ilibvterm/include -DINLINE="" -DVSNPRINTF=vim_vsnprintf
3299+
CCCTERM = $(CCC) -Ilibvterm/include -DINLINE="" \
3300+
-DVSNPRINTF=vim_vsnprintf \
3301+
-DIS_COMBINING_FUNCTION=utf_iscomposing_uint \
3302+
-DWCWIDTH_FUNCTION=utf_uint2cells
3303+
33003304
objects/term_encoding.o: libvterm/src/encoding.c $(TERM_DEPS)
33013305
$(CCCTERM) -o $@ libvterm/src/encoding.c
33023306

src/libvterm/src/unicode.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
* Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
6969
*/
7070

71+
#if !defined(IS_COMBINING_FUNCTION) || !defined(WCWIDTH_FUNCTION)
7172
struct interval {
7273
int first;
7374
int last;
@@ -126,7 +127,6 @@ static const struct interval combining[] = {
126127
{ 0xE0100, 0xE01EF }
127128
};
128129

129-
130130
/* auxiliary function for binary search in interval table */
131131
static int bisearch(uint32_t ucs, const struct interval *table, int max) {
132132
int min = 0;
@@ -146,6 +146,7 @@ static int bisearch(uint32_t ucs, const struct interval *table, int max) {
146146

147147
return 0;
148148
}
149+
#endif
149150

150151

151152
/* The following two functions define the column width of an ISO 10646
@@ -180,6 +181,11 @@ static int bisearch(uint32_t ucs, const struct interval *table, int max) {
180181
* in ISO 10646.
181182
*/
182183

184+
#ifdef WCWIDTH_FUNCTION
185+
/* use a provided wcwidth() function */
186+
int WCWIDTH_FUNCTION(uint32_t ucs);
187+
#else
188+
# define WCWIDTH_FUNCTION mk_wcwidth
183189

184190
static int mk_wcwidth(uint32_t ucs)
185191
{
@@ -196,7 +202,7 @@ static int mk_wcwidth(uint32_t ucs)
196202

197203
/* if we arrive here, ucs is not a combining or C0/C1 control character */
198204

199-
return 1 +
205+
return 1 +
200206
(ucs >= 0x1100 &&
201207
(ucs <= 0x115f || /* Hangul Jamo init. consonants */
202208
ucs == 0x2329 || ucs == 0x232a ||
@@ -211,6 +217,7 @@ static int mk_wcwidth(uint32_t ucs)
211217
(ucs >= 0x20000 && ucs <= 0x2fffd) ||
212218
(ucs >= 0x30000 && ucs <= 0x3fffd)));
213219
}
220+
#endif
214221

215222
#if 0 /* unused */
216223
static int mk_wcswidth(const uint32_t *pwcs, size_t n)
@@ -317,15 +324,28 @@ static int mk_wcswidth_cjk(const uint32_t *pwcs, size_t n)
317324
}
318325
#endif
319326

327+
#ifdef IS_COMBINING_FUNCTION
328+
/* Use a provided is_combining() function. */
329+
int IS_COMBINING_FUNCTION(uint32_t codepoint);
330+
#else
331+
# define IS_COMBINING_FUNCTION vterm_is_combining
332+
static int
333+
vterm_is_combining(uint32_t codepoint)
334+
{
335+
return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1);
336+
}
337+
#endif
338+
339+
320340
/* ################################
321341
* ### The rest added by Paul Evans */
322342

323343
INTERNAL int vterm_unicode_width(uint32_t codepoint)
324344
{
325-
return mk_wcwidth(codepoint);
345+
return WCWIDTH_FUNCTION(codepoint);
326346
}
327347

328348
INTERNAL int vterm_unicode_is_combining(uint32_t codepoint)
329349
{
330-
return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1);
350+
return IS_COMBINING_FUNCTION(codepoint);
331351
}

src/mbyte.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,17 @@ static struct interval ambiguous[] =
13951395
{0x100000, 0x10fffd}
13961396
};
13971397

1398+
#if defined(FEAT_TERMINAL) || defined(PROTO)
1399+
/*
1400+
* utf_char2cells() with different argument type for libvterm.
1401+
*/
1402+
int
1403+
utf_uint2cells(uint32_t c)
1404+
{
1405+
return utf_char2cells((int)c);
1406+
}
1407+
#endif
1408+
13981409
/*
13991410
* For UTF-8 character "c" return 2 for a double-width character, 1 for others.
14001411
* Returns 4 or 6 for an unprintable character.
@@ -2296,6 +2307,17 @@ utf_char2bytes(int c, char_u *buf)
22962307
return 6;
22972308
}
22982309

2310+
#if defined(FEAT_TERMINAL) || defined(PROTO)
2311+
/*
2312+
* utf_iscomposing() with different argument type for libvterm.
2313+
*/
2314+
int
2315+
utf_iscomposing_uint(uint32_t c)
2316+
{
2317+
return utf_iscomposing((int)c);
2318+
}
2319+
#endif
2320+
22992321
/*
23002322
* Return TRUE if "c" is a composing UTF-8 character. This means it will be
23012323
* drawn on top of the preceding character.

src/proto/mbyte.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ int latin_char2len(int c);
1010
int latin_char2bytes(int c, char_u *buf);
1111
int latin_ptr2len(char_u *p);
1212
int latin_ptr2len_len(char_u *p, int size);
13+
int utf_uint2cells(uint32_t c);
1314
int utf_char2cells(int c);
1415
int latin_ptr2cells(char_u *p);
1516
int utf_ptr2cells(char_u *p);
@@ -37,6 +38,7 @@ int utfc_ptr2len(char_u *p);
3738
int utfc_ptr2len_len(char_u *p, int size);
3839
int utf_char2len(int c);
3940
int utf_char2bytes(int c, char_u *buf);
41+
int utf_iscomposing_uint(uint32_t c);
4042
int utf_iscomposing(int c);
4143
int utf_printable(int c);
4244
int utf_class(int c);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
985,
772774
/**/
773775
984,
774776
/**/

0 commit comments

Comments
 (0)