Permalink
Browse files

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)
  • Loading branch information...
brammool committed Aug 22, 2017
1 parent 5830232 commit 6d0826dfbba9880820d9ec221327e4250bbf6540
Showing with 66 additions and 7 deletions.
  1. +5 −1 src/Make_cyg_ming.mak
  2. +6 −1 src/Make_mvc.mak
  3. +5 −1 src/Makefile
  4. +24 −4 src/libvterm/src/unicode.c
  5. +22 −0 src/mbyte.c
  6. +2 −0 src/proto/mbyte.pro
  7. +2 −0 src/version.c
View
@@ -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 $@
View
@@ -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
View
@@ -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
View
@@ -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);
}
View
@@ -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.
View
@@ -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);
View
@@ -769,6 +769,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
985,
/**/
984,
/**/

0 comments on commit 6d0826d

Please sign in to comment.