Re: [Tuxpaint-devel] Is this warning harmless?
An award-winning drawing program for children of all ages
Brought to you by:
wkendrick
|
From: Bill K. <nb...@so...> - 2021-11-04 04:53:12
|
On Wed, Nov 03, 2021 at 09:27:36PM -0700, Bill Kendrick wrote: > On Tue, Nov 02, 2021 at 09:44:39PM +0900, TOYAMA Shin-ichi wrote: > > Hi, > > > > I think the reason for this warning is that the size of wchar_t is > > 4 bytes on linux but 2 bytes on windows. > > > > I don't know what render_text_w() is doing, so I'm not sure if > > this is the problem or not. > > > > For example, the text circled in red in onscreen_keyboard (see > > attached) does not seem to be rendered on windows. > > > > Does this seem relevant ? > > Hrm, we have some clues about this in the code from John P. from > way back in 2006: > > https://sourceforge.net/p/tuxpaint/tuxpaint/ci/304f49672/ > > Specifically, this part of the commit message: > > Modified the text gadget so that it correctly handles the 16-bit unicode > characters that SDL sends. The text buffer is held internally as an array > of wchar_t, and makes uses of various wide-character functions. > It is converted back into 16-bit unicode characters to satisfy SDL_ttf. > Tested on Windows and Linux. > > And it's this function: > > // This conversion is required on platforms where Uint16 doesn't match wchar_t. > // On Windows, wchar_t is 16-bit, elsewhere it is 32-bit. > // Mismatch caused by the use of Uint16 for unicode characters by SDL, SDL_ttf. > // I guess wchar_t is really only suitable for internal use ... > static Uint16 *wcstou16(const wchar_t *str) > ... > > It is used in exactly one place, within render_text_w(): > > if (font->typ == FONT_TYPE_TTF) > { > ustr = wcstou16(str); > ret = TTF_RenderUNICODE_Blended(font->ttf_font, ustr, color); > free(ustr); > } > > > However, we're talking about the bit of code that constructs > UTF-8 Unicode within Tux Paint, to deliver it to SDL_Pango. > > I think it might be worth replacing `wchar` with something > like Uint32 for these purposes... Ugh, so another problem I'm seeing is we actually store strings in `wchar` form as the Label tool's text inside the PNG images. I assume that, because of this, Tux Paint pictures drawn on Linux might not work under Tux Paint on Windows, and vice-versa, due to the different sizes (16- vs 32-bit). Back to the issue at hand, it actually seems like anything about 0xFFFF isn't really useful to us. https://unicodebook.readthedocs.io/unicode.html#unicode-categories says: There are 3 ranges reserved for private use (Co subcategory): U+E000 - U+F8FF (6,400 code points), U+F0000 - U+FFFFD (65,534) and U+100000 - U+10FFFD (65,534). Surrogates (Cs subcategory) use the range U+D800 - U+DFFF (2,048 code points). I'm thinking it's probably safe to just ignore str[] values above 0xFFFF (which are impossible on environments, like Windows, with 16-bit `wchar`). I'll see what happens on Linux. If it seems okay, I'll commit, and you can test things on Windows. Regarding those characters that did not appear in the OSK for you, I made the above discover by simply replacing the code that converts any >= 0x00010000 values in str[] to UTF-8, for sending to SDL_Pango, and just doing this: utfstr[j++] = 'X'; ...But I could still see the symbols (and not an "X"). :) Perhaps that's a font issue? Can you play around with it? -bill! > > I'm digging around the code right now. > > -bill! > > > > > > > > TOYAMA Shin-ichi wrote in <617e94b2.5007%sh...@wm...> > > >Hi, > > > > > >Recently, I've been dealing with a lot of bugs in the Windows > > >version, and I've noticed that many clue of the bugs had been > > >appeared in the compile-time warnings. > > > > > >So,I checked the warnings again, and the following warning, > > >which does not appear when compiling on Linux, caught my > > >attention. > > > > > >------------------------------------------------------------ > > >src/tuxpaint.c: In function 'render_text_w': > > >src/tuxpaint.c:1685:27: warning: comparison is always true due to limited range > > >of data type [-Wtype-limits] > > > 1685 | else if (str[i] <= 0x0000FFFF) > > >------------------------------------------------------------ > > > > > >If this warning is correct, it means that the next conditional > > >branch (0x00100000 - 001FFFFF) will never be reached. > > > > > >How can I confirm if it were a problem or not? > > > > > >Thanks! > > > > -- > > TOYAMA Shin-ichi mailto:sh...@wm... > > > > > _______________________________________________ > > Tuxpaint-devel mailing list > > Tux...@li... > > https://lists.sourceforge.net/lists/listinfo/tuxpaint-devel > > > -- > -bill! > Sent from my computer > > > _______________________________________________ > Tuxpaint-devel mailing list > Tux...@li... > https://lists.sourceforge.net/lists/listinfo/tuxpaint-devel -- -bill! Sent from my computer |