From 177dfc6384b926dd19e3b7e98a995ccb4da9167c Mon Sep 17 00:00:00 2001 From: mano-wii Date: Fri, 22 Nov 2019 12:26:54 -0300 Subject: Fix T71273: Bad encoding of utf-8 for Text objects `BLI_strncpy_wchar_from_utf8` internally assumes `wchar_t` is 32 bits which is not the case on windows. The solution is to replace `wchar_t` with `char32_t`. Thanks to @robbott for compatibility on macOS. Differential Revision: https://developer.blender.org/D6198 --- extern/wcwidth/README.blender | 4 +++- extern/wcwidth/wcwidth.c | 12 +++++------- extern/wcwidth/wcwidth.h | 18 +++++++++++++----- 3 files changed, 21 insertions(+), 13 deletions(-) (limited to 'extern/wcwidth') diff --git a/extern/wcwidth/README.blender b/extern/wcwidth/README.blender index 27c8574d1d7..3b32ddc5bc9 100644 --- a/extern/wcwidth/README.blender +++ b/extern/wcwidth/README.blender @@ -2,4 +2,6 @@ Project: WC Width URL: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c License: ICS Upstream version: 2007-05-26 -Local modifications: None +Local modifications: +* Fix T33192 + Bad encoding of utf-8 on windows systems. diff --git a/extern/wcwidth/wcwidth.c b/extern/wcwidth/wcwidth.c index 8cab81e32cd..8922ffe0842 100644 --- a/extern/wcwidth/wcwidth.c +++ b/extern/wcwidth/wcwidth.c @@ -59,8 +59,6 @@ * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c */ -#include - #include "wcwidth.h" struct interval { @@ -69,7 +67,7 @@ struct interval { }; /* auxiliary function for binary search in interval table */ -static int bisearch(wchar_t ucs, const struct interval *table, int max) { +static int bisearch(char32_t ucs, const struct interval *table, int max) { int min = 0; int mid; @@ -121,7 +119,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) { * in ISO 10646. */ -int mk_wcwidth(wchar_t ucs) +int mk_wcwidth(char32_t ucs) { /* sorted list of non-overlapping intervals of non-spacing characters */ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ @@ -206,7 +204,7 @@ int mk_wcwidth(wchar_t ucs) } -int mk_wcswidth(const wchar_t *pwcs, size_t n) +int mk_wcswidth(const char32_t *pwcs, size_t n) { int w, width = 0; @@ -229,7 +227,7 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n) * the traditional terminal character-width behaviour. It is not * otherwise recommended for general use. */ -int mk_wcwidth_cjk(wchar_t ucs) +int mk_wcwidth_cjk(char32_t ucs) { /* sorted list of non-overlapping intervals of East Asian Ambiguous * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ @@ -297,7 +295,7 @@ int mk_wcwidth_cjk(wchar_t ucs) } -int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) +int mk_wcswidth_cjk(const char32_t *pwcs, size_t n) { int w, width = 0; diff --git a/extern/wcwidth/wcwidth.h b/extern/wcwidth/wcwidth.h index 9ae6ec9ef14..d87eaf20695 100644 --- a/extern/wcwidth/wcwidth.h +++ b/extern/wcwidth/wcwidth.h @@ -20,11 +20,19 @@ #ifndef __WCWIDTH_H__ #define __WCWIDTH_H__ -#include +#ifndef __cplusplus +# if defined(__APPLE__) +/* The standard header is missing on macOS. */ +#include +typedef unsigned int char32_t; +# else +# include +# endif +#endif -int mk_wcwidth(wchar_t ucs); -int mk_wcswidth(const wchar_t *pwcs, size_t n); -int mk_wcwidth_cjk(wchar_t ucs); -int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n); +int mk_wcwidth(char32_t ucs); +int mk_wcswidth(const char32_t *pwcs, size_t n); +int mk_wcwidth_cjk(char32_t ucs); +int mk_wcswidth_cjk(const char32_t *pwcs, size_t n); #endif -- cgit v1.2.3