Mercurial > vim
comparison src/libvterm/src/unicode.c @ 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 | b8299e742f41 |
children | 2449b6ce1456 |
comparison
equal
deleted
inserted
replaced
12209:71f25f291349 | 12210:b9b06aa0b6d9 |
---|---|
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) | |
71 struct interval { | 72 struct interval { |
72 int first; | 73 int first; |
73 int last; | 74 int last; |
74 }; | 75 }; |
75 | 76 |
124 { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD }, | 125 { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD }, |
125 { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F }, | 126 { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F }, |
126 { 0xE0100, 0xE01EF } | 127 { 0xE0100, 0xE01EF } |
127 }; | 128 }; |
128 | 129 |
129 | |
130 /* auxiliary function for binary search in interval table */ | 130 /* auxiliary function for binary search in interval table */ |
131 static int bisearch(uint32_t ucs, const struct interval *table, int max) { | 131 static int bisearch(uint32_t ucs, const struct interval *table, int max) { |
132 int min = 0; | 132 int min = 0; |
133 int mid; | 133 int mid; |
134 | 134 |
144 return 1; | 144 return 1; |
145 } | 145 } |
146 | 146 |
147 return 0; | 147 return 0; |
148 } | 148 } |
149 #endif | |
149 | 150 |
150 | 151 |
151 /* The following two functions define the column width of an ISO 10646 | 152 /* The following two functions define the column width of an ISO 10646 |
152 * character as follows: | 153 * character as follows: |
153 * | 154 * |
178 * | 179 * |
179 * This implementation assumes that uint32_t characters are encoded | 180 * This implementation assumes that uint32_t characters are encoded |
180 * in ISO 10646. | 181 * in ISO 10646. |
181 */ | 182 */ |
182 | 183 |
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 | |
183 | 189 |
184 static int mk_wcwidth(uint32_t ucs) | 190 static int mk_wcwidth(uint32_t ucs) |
185 { | 191 { |
186 /* test for 8-bit control characters */ | 192 /* test for 8-bit control characters */ |
187 if (ucs == 0) | 193 if (ucs == 0) |
194 sizeof(combining) / sizeof(struct interval) - 1)) | 200 sizeof(combining) / sizeof(struct interval) - 1)) |
195 return 0; | 201 return 0; |
196 | 202 |
197 /* if we arrive here, ucs is not a combining or C0/C1 control character */ | 203 /* if we arrive here, ucs is not a combining or C0/C1 control character */ |
198 | 204 |
199 return 1 + | 205 return 1 + |
200 (ucs >= 0x1100 && | 206 (ucs >= 0x1100 && |
201 (ucs <= 0x115f || /* Hangul Jamo init. consonants */ | 207 (ucs <= 0x115f || /* Hangul Jamo init. consonants */ |
202 ucs == 0x2329 || ucs == 0x232a || | 208 ucs == 0x2329 || ucs == 0x232a || |
203 (ucs >= 0x2e80 && ucs <= 0xa4cf && | 209 (ucs >= 0x2e80 && ucs <= 0xa4cf && |
204 ucs != 0x303f) || /* CJK ... Yi */ | 210 ucs != 0x303f) || /* CJK ... Yi */ |
209 (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ | 215 (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ |
210 (ucs >= 0xffe0 && ucs <= 0xffe6) || | 216 (ucs >= 0xffe0 && ucs <= 0xffe6) || |
211 (ucs >= 0x20000 && ucs <= 0x2fffd) || | 217 (ucs >= 0x20000 && ucs <= 0x2fffd) || |
212 (ucs >= 0x30000 && ucs <= 0x3fffd))); | 218 (ucs >= 0x30000 && ucs <= 0x3fffd))); |
213 } | 219 } |
220 #endif | |
214 | 221 |
215 #if 0 /* unused */ | 222 #if 0 /* unused */ |
216 static int mk_wcswidth(const uint32_t *pwcs, size_t n) | 223 static int mk_wcswidth(const uint32_t *pwcs, size_t n) |
217 { | 224 { |
218 int w, width = 0; | 225 int w, width = 0; |
315 | 322 |
316 return width; | 323 return width; |
317 } | 324 } |
318 #endif | 325 #endif |
319 | 326 |
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 | |
320 /* ################################ | 340 /* ################################ |
321 * ### The rest added by Paul Evans */ | 341 * ### The rest added by Paul Evans */ |
322 | 342 |
323 INTERNAL int vterm_unicode_width(uint32_t codepoint) | 343 INTERNAL int vterm_unicode_width(uint32_t codepoint) |
324 { | 344 { |
325 return mk_wcwidth(codepoint); | 345 return WCWIDTH_FUNCTION(codepoint); |
326 } | 346 } |
327 | 347 |
328 INTERNAL int vterm_unicode_is_combining(uint32_t codepoint) | 348 INTERNAL int vterm_unicode_is_combining(uint32_t codepoint) |
329 { | 349 { |
330 return bisearch(codepoint, combining, sizeof(combining) / sizeof(struct interval) - 1); | 350 return IS_COMBINING_FUNCTION(codepoint); |
331 } | 351 } |