Avoid compile-time warnings re: wchar_t comparison
When assembling UTF-8 in render_text_w() (to send to SDL_Pango), we assumed `wchar_t` could encompass the entirety of Unicode (up to U+10FFFF); however, on Windows `wchar_t` is only 16-bits, meaning the test for characters <= U+FFFF was always true. This reworks the if/elseif/else block, via some "#ifndef WIN32" tests, to avoid this warning. In the end, we need to replace our internal use of `wchar_t` with something 32-bit, to allow for higher Unicode code points (e.g., to support Emoji via the Text and Label tools). Additonally, some work will need to be done to ensure that text stored as Labels within saved Tux Paint images (PNGs) continued to work correctly, and could be traded between platforms. (Untested, but right now I assume a picture drawn on Linux where `wchar_t` is 32-bit would break if you attempt to load it on Windows, and possibly vice-versa?) See https://sourceforge.net/p/tuxpaint/feature-requests/210/
This commit is contained in:
parent
f46df76736
commit
19db5e1b4a
1 changed files with 11 additions and 1 deletions
|
|
@ -1686,7 +1686,14 @@ static SDL_Surface *render_text_w(TuxPaint_Font * restrict font, const wchar_t *
|
|||
utfstr[j++] = (((str[i] & 0x003F)) | /* -------- --fghijk to --fghijk */
|
||||
(0x80)); /* add 10------ */
|
||||
}
|
||||
#ifndef WIN32
|
||||
else if (str[i] <= 0x0000FFFF)
|
||||
#else
|
||||
/* str[i] is a wchar_t, which is only 16-bit on Windows, so
|
||||
avoiding a "comparison is always true due to limited range
|
||||
of data type" compile-time warning */
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Range: 0x00000800 - 0x0000FFFF:
|
||||
|
||||
|
|
@ -1700,12 +1707,14 @@ static SDL_Surface *render_text_w(TuxPaint_Font * restrict font, const wchar_t *
|
|||
utfstr[j++] = (((str[i] & 0x003F)) | /* -------- --klmnop to --klmnop */
|
||||
(0x80)); /* add 10------ */
|
||||
}
|
||||
#ifndef WIN32
|
||||
else
|
||||
{
|
||||
/* Range: 0x00010000 - 0x001FFFFF:
|
||||
|
||||
In: 000abcde fghijklm nopqrstu
|
||||
Out: 11110abc 10defghi 10jklmno 10pqrstu */
|
||||
Out: 11110abc 10defghi 10jklmno 10pqrstu
|
||||
*/
|
||||
|
||||
utfstr[j++] = (((str[i] & 0x1C0000) >> 18) | /* ---abc-- -------- -------- to -----abc */
|
||||
(0xF0)); /* add 11110000 */
|
||||
|
|
@ -1718,6 +1727,7 @@ static SDL_Surface *render_text_w(TuxPaint_Font * restrict font, const wchar_t *
|
|||
utfstr[j++] = ((str[i] & 0x00003F) | /* -------- -------- --pqrstu to --prqstu */
|
||||
(0x80)); /* add 10------ */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
utfstr[j] = '\0';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue