changeset 12210:b9b06aa0b6d9 v8.0.0985

patch 8.0.0985: libvterm has its own idea of character width commit https://github.com/vim/vim/commit/6d0826dfbba9880820d9ec221327e4250bbf6540 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 22 22:12:17 2017 +0200 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)
author Christian Brabandt <cb@256bit.org>
date Tue, 22 Aug 2017 22:15:04 +0200
parents 71f25f291349
children 7a4fb06f700b
files src/Make_cyg_ming.mak src/Make_mvc.mak src/Makefile src/libvterm/src/unicode.c src/mbyte.c src/proto/mbyte.pro src/version.c
diffstat 7 files changed, 66 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/Make_cyg_ming.mak
+++ b/src/Make_cyg_ming.mak
@@ -971,7 +971,11 @@ endif
 	$(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 $@
 
--- a/src/Make_mvc.mak
+++ b/src/Make_mvc.mak
@@ -1474,7 +1474,12 @@ dimm.h dimm_i.c: dimm.idl
 $(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
 
--- 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
 
--- 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 
 
   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 
  * 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_
 }
 #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);
 }
--- 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.
--- 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);
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    985,
+/**/
     984,
 /**/
     983,