From 6d0826dfbba9880820d9ec221327e4250bbf6540 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 22 Aug 2017 22:12:17 +0200 Subject: 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) --- src/Make_cyg_ming.mak | 6 +++++- src/Make_mvc.mak | 7 ++++++- src/Makefile | 6 +++++- src/libvterm/src/unicode.c | 28 ++++++++++++++++++++++++---- src/mbyte.c | 22 ++++++++++++++++++++++ src/proto/mbyte.pro | 2 ++ src/version.c | 2 ++ 7 files changed, 66 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak index 5b0719f7d..1c368badf 100644 --- a/src/Make_cyg_ming.mak +++ b/src/Make_cyg_ming.mak @@ -971,7 +971,11 @@ $(OUTDIR)/terminal.o: terminal.c $(INCL) $(TERM_DEPS) $(CC) -c $(CFLAGS) terminal.c -o $(OUTDIR)/terminal.o -CCCTERM = $(CC) -c $(CFLAGS) -Ilibvterm/include -DINLINE="" -DVSNPRINTF=vim_vsnprintf +CCCTERM = $(CC) -c $(CFLAGS) -Ilibvterm/include -DINLINE="" \ + -DVSNPRINTF=vim_vsnprintf \ + -DIS_COMBINING_FUNCTION=utf_iscomposing_uint \ + -DWCWIDTH_FUNCTION=utf_uint2cells + $(OUTDIR)/term_encoding.o: libvterm/src/encoding.c $(TERM_DEPS) $(CCCTERM) libvterm/src/encoding.c -o $@ diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index d1221d0f0..4180b7c76 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -1474,7 +1474,12 @@ $(OUTDIR)/dimm_i.obj: $(OUTDIR) dimm_i.c $(INCL) $(OUTDIR)/glbl_ime.obj: $(OUTDIR) glbl_ime.cpp dimm.h $(INCL) -CCCTERM = $(CC) $(CFLAGS) -Ilibvterm/include -DINLINE="" -DVSNPRINTF=vim_vsnprintf -D_CRT_SECURE_NO_WARNINGS +CCCTERM = $(CC) $(CFLAGS) -Ilibvterm/include -DINLINE="" \ + -DVSNPRINTF=vim_vsnprintf \ + -DIS_COMBINING_FUNCTION=utf_iscomposing_uint \ + -DWCWIDTH_FUNCTION=utf_uint2cells \ + -D_CRT_SECURE_NO_WARNINGS + $(OUTDIR)/term_encoding.obj: $(OUTDIR) libvterm/src/encoding.c $(TERM_DEPS) $(CCCTERM) -Fo$@ libvterm/src/encoding.c diff --git a/src/Makefile b/src/Makefile index 1f252f056..e4da3b4b6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3296,7 +3296,11 @@ objects/channel.o: channel.c Makefile: @echo The name of the makefile MUST be "Makefile" (with capital M)!!!! -CCCTERM = $(CCC) -Ilibvterm/include -DINLINE="" -DVSNPRINTF=vim_vsnprintf +CCCTERM = $(CCC) -Ilibvterm/include -DINLINE="" \ + -DVSNPRINTF=vim_vsnprintf \ + -DIS_COMBINING_FUNCTION=utf_iscomposing_uint \ + -DWCWIDTH_FUNCTION=utf_uint2cells + objects/term_encoding.o: libvterm/src/encoding.c $(TERM_DEPS) $(CCCTERM) -o $@ libvterm/src/encoding.c diff --git a/src/libvterm/src/unicode.c b/src/libvterm/src/unicode.c index b989add3c..e5a25a5e7 100644 --- a/src/libvterm/src/unicode.c +++ b/src/libvterm/src/unicode.c @@ -68,6 +68,7 @@ * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c */ +#if !defined(IS_COMBINING_FUNCTION) || !defined(WCWIDTH_FUNCTION) struct interval { int first; int last; @@ -126,7 +127,6 @@ static const struct interval combining[] = { { 0xE0100, 0xE01EF } }; - /* auxiliary function for binary search in interval table */ static int bisearch(uint32_t ucs, const struct interval *table, int max) { int min = 0; @@ -146,6 +146,7 @@ static int bisearch(uint32_t ucs, const struct interval *table, int max) { return 0; } +#endif /* 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) { * in ISO 10646. */ +#ifdef WCWIDTH_FUNCTION +/* use a provided wcwidth() function */ +int WCWIDTH_FUNCTION(uint32_t ucs); +#else +# define WCWIDTH_FUNCTION mk_wcwidth static int mk_wcwidth(uint32_t ucs) { @@ -196,7 +202,7 @@ static int mk_wcwidth(uint32_t ucs) /* if we arrive here, ucs is not a combining or C0/C1 control character */ - return 1 + + return 1 + (ucs >= 0x1100 && (ucs <= 0x115f || /* Hangul Jamo init. consonants */ ucs == 0x2329 || ucs == 0x232a || @@ -211,6 +217,7 @@ static int mk_wcwidth(uint32_t ucs) (ucs >= 0x20000 && ucs <= 0x2fffd) || (ucs >= 0x30000 && ucs <= 0x3fffd))); } +#endif #if 0 /* unused */ 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) } #endif +#ifdef IS_COMBINING_FUNCTION +/* Use a provided is_combining() function. */ +int IS_COMBINING_FUNCTION(uint32_t codepoint); +#else +# define IS_COMBINING_FUNCTION vterm_is_combining + static int +vterm_is_combining(uint32_t codepoint) +{ + return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1); +} +#endif + + /* ################################ * ### The rest added by Paul Evans */ INTERNAL int vterm_unicode_width(uint32_t codepoint) { - return mk_wcwidth(codepoint); + return WCWIDTH_FUNCTION(codepoint); } INTERNAL int vterm_unicode_is_combining(uint32_t codepoint) { - return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1); + return IS_COMBINING_FUNCTION(codepoint); } diff --git a/src/mbyte.c b/src/mbyte.c index 33fa0a254..e3c47d6a5 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -1395,6 +1395,17 @@ static struct interval ambiguous[] = {0x100000, 0x10fffd} }; +#if defined(FEAT_TERMINAL) || defined(PROTO) +/* + * utf_char2cells() with different argument type for libvterm. + */ + int +utf_uint2cells(uint32_t c) +{ + return utf_char2cells((int)c); +} +#endif + /* * For UTF-8 character "c" return 2 for a double-width character, 1 for others. * Returns 4 or 6 for an unprintable character. @@ -2296,6 +2307,17 @@ utf_char2bytes(int c, char_u *buf) return 6; } +#if defined(FEAT_TERMINAL) || defined(PROTO) +/* + * utf_iscomposing() with different argument type for libvterm. + */ + int +utf_iscomposing_uint(uint32_t c) +{ + return utf_iscomposing((int)c); +} +#endif + /* * Return TRUE if "c" is a composing UTF-8 character. This means it will be * drawn on top of the preceding character. diff --git a/src/proto/mbyte.pro b/src/proto/mbyte.pro index 83bcadc69..b37064b8e 100644 --- a/src/proto/mbyte.pro +++ b/src/proto/mbyte.pro @@ -10,6 +10,7 @@ int latin_char2len(int c); int latin_char2bytes(int c, char_u *buf); int latin_ptr2len(char_u *p); int latin_ptr2len_len(char_u *p, int size); +int utf_uint2cells(uint32_t c); int utf_char2cells(int c); int latin_ptr2cells(char_u *p); int utf_ptr2cells(char_u *p); @@ -37,6 +38,7 @@ int utfc_ptr2len(char_u *p); int utfc_ptr2len_len(char_u *p, int size); int utf_char2len(int c); int utf_char2bytes(int c, char_u *buf); +int utf_iscomposing_uint(uint32_t c); int utf_iscomposing(int c); int utf_printable(int c); int utf_class(int c); diff --git a/src/version.c b/src/version.c index 0383e58c1..ef0209e57 100644 --- a/src/version.c +++ b/src/version.c @@ -769,6 +769,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 985, /**/ 984, /**/ -- cgit v1.2.1