comparison src/libvterm/src/unicode.c @ 18064:8b4f9be5db73 v8.1.2027

patch 8.1.2027: MS-Windows: problem with ambiwidth characters Commit: https://github.com/vim/vim/commit/57da69816872d53038e8a7e8dd4dc39a31192f0d Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 13 22:30:11 2019 +0200 patch 8.1.2027: MS-Windows: problem with ambiwidth characters Problem: MS-Windows: problem with ambiwidth characters. Solution: handle ambiguous width characters in ConPTY on Windows 10 (1903). (Nobuhiro Takasaki, closes #4411)
author Bram Moolenaar <Bram@vim.org>
date Fri, 13 Sep 2019 22:45:04 +0200
parents 811a12a78164
children 3be01cf0a632
comparison
equal deleted inserted replaced
18063:168f1eca04a2 18064:8b4f9be5db73
66 * disclaims all warranties with regard to this software. 66 * disclaims all warranties with regard to this software.
67 * 67 *
68 * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c 68 * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
69 */ 69 */
70 70
71 #if !defined(IS_COMBINING_FUNCTION) || !defined(WCWIDTH_FUNCTION)
72 struct interval { 71 struct interval {
73 int first; 72 int first;
74 int last; 73 int last;
75 }; 74 };
75
76 #if !defined(WCWIDTH_FUNCTION) || !defined(IS_COMBINING_FUNCTION)
76 77
77 // sorted list of non-overlapping intervals of non-spacing characters 78 // sorted list of non-overlapping intervals of non-spacing characters
78 // generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" 79 // generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c"
79 // Replaced by the combining table from Vim. 80 // Replaced by the combining table from Vim.
80 static const struct interval combining[] = { 81 static const struct interval combining[] = {
357 {0X1E2EC, 0X1E2EF}, 358 {0X1E2EC, 0X1E2EF},
358 {0X1E8D0, 0X1E8D6}, 359 {0X1E8D0, 0X1E8D6},
359 {0X1E944, 0X1E94A}, 360 {0X1E944, 0X1E94A},
360 {0XE0100, 0XE01EF} 361 {0XE0100, 0XE01EF}
361 }; 362 };
363 #endif
362 364
363 // auxiliary function for binary search in interval table 365 // auxiliary function for binary search in interval table
364 static int bisearch(uint32_t ucs, const struct interval *table, int max) { 366 static int bisearch(uint32_t ucs, const struct interval *table, int max) {
365 int min = 0; 367 int min = 0;
366 int mid; 368 int mid;
377 return 1; 379 return 1;
378 } 380 }
379 381
380 return 0; 382 return 0;
381 } 383 }
382 #endif
383
384 384
385 /* The following two functions define the column width of an ISO 10646 385 /* The following two functions define the column width of an ISO 10646
386 * character as follows: 386 * character as follows:
387 * 387 *
388 * - The null character (U+0000) has a column width of 0. 388 * - The null character (U+0000) has a column width of 0.
476 * the traditional terminal character-width behaviour. It is not 476 * the traditional terminal character-width behaviour. It is not
477 * otherwise recommended for general use. 477 * otherwise recommended for general use.
478 */ 478 */
479 static int mk_wcwidth_cjk(uint32_t ucs) 479 static int mk_wcwidth_cjk(uint32_t ucs)
480 { 480 {
481 #endif
481 /* sorted list of non-overlapping intervals of East Asian Ambiguous 482 /* sorted list of non-overlapping intervals of East Asian Ambiguous
482 * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ 483 * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */
483 static const struct interval ambiguous[] = { 484 static const struct interval ambiguous[] = {
484 { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 }, 485 { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 },
485 { 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 }, 486 { 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 },
532 { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 }, 533 { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 },
533 { 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F }, 534 { 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F },
534 { 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0xE000, 0xF8FF }, 535 { 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0xE000, 0xF8FF },
535 { 0xFFFD, 0xFFFD }, { 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD } 536 { 0xFFFD, 0xFFFD }, { 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD }
536 }; 537 };
538 #if 0
537 539
538 // binary search in table of non-spacing characters 540 // binary search in table of non-spacing characters
539 if (bisearch(ucs, ambiguous, 541 if (bisearch(ucs, ambiguous,
540 sizeof(ambiguous) / sizeof(struct interval) - 1)) 542 sizeof(ambiguous) / sizeof(struct interval) - 1))
541 return 2; 543 return 2;
554 width += w; 556 width += w;
555 557
556 return width; 558 return width;
557 } 559 }
558 #endif 560 #endif
561
562 INTERNAL int vterm_unicode_is_ambiguous(uint32_t codepoint)
563 {
564 return (bisearch(codepoint, ambiguous,
565 sizeof(ambiguous) / sizeof(struct interval) - 1)) ? 1 : 0;
566 }
559 567
560 #ifdef IS_COMBINING_FUNCTION 568 #ifdef IS_COMBINING_FUNCTION
561 // Use a provided is_combining() function. 569 // Use a provided is_combining() function.
562 int IS_COMBINING_FUNCTION(uint32_t codepoint); 570 int IS_COMBINING_FUNCTION(uint32_t codepoint);
563 #else 571 #else
567 { 575 {
568 return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1); 576 return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1);
569 } 577 }
570 #endif 578 #endif
571 579
580 #ifdef GET_SPECIAL_PTY_TYPE_FUNCTION
581 int GET_SPECIAL_PTY_TYPE_FUNCTION(void);
582 #else
583 # define GET_SPECIAL_PTY_TYPE_FUNCTION vterm_get_special_pty_type_placeholder
584 static int
585 vterm_get_special_pty_type_placeholder(void)
586 {
587 return 0;
588 }
589 #endif
590
572 // ################################ 591 // ################################
573 // ### The rest added by Paul Evans 592 // ### The rest added by Paul Evans
574 593
575 INTERNAL int vterm_unicode_width(uint32_t codepoint) 594 INTERNAL int vterm_unicode_width(uint32_t codepoint)
576 { 595 {
579 598
580 INTERNAL int vterm_unicode_is_combining(uint32_t codepoint) 599 INTERNAL int vterm_unicode_is_combining(uint32_t codepoint)
581 { 600 {
582 return IS_COMBINING_FUNCTION(codepoint); 601 return IS_COMBINING_FUNCTION(codepoint);
583 } 602 }
603
604 INTERNAL int vterm_get_special_pty_type(void)
605 {
606 return GET_SPECIAL_PTY_TYPE_FUNCTION();
607 }