Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: wchar_t to sfUint32 issue on WIndows  (Read 20700 times)

0 Members and 1 Guest are viewing this topic.

serg

  • Newbie
  • *
  • Posts: 9
    • View Profile
wchar_t to sfUint32 issue on WIndows
« on: May 31, 2020, 05:13:39 pm »
Hi All

i'm on my way to make a text editor using CSFML
i've experienced an issue to get input from keyboard and draw utf text

removed by TS

please assist with my misunderstanding

thnx.
« Last Edit: June 01, 2020, 02:34:41 pm by serg »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: wchar_t to sfUint32 issue on WIndows
« Reply #1 on: May 31, 2020, 08:39:00 pm »
Quote
i've experienced an issue
Please describe it. Nobody wants to guess.
Laurent Gomila - SFML developer

serg

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: wchar_t to sfUint32 issue on WIndows
« Reply #2 on: May 31, 2020, 08:51:39 pm »
Quote
i've experienced an issue
Please describe it. Nobody wants to guess.

sorry. it was under the quote. is it possible for you to check it?

sfText_setUnicodeString(text, (sfUint32 *) wstr); // wrong: display the char but then override it with blank square

i see the proper wchat_t * wstr  using cmd.exe and wcslen(wstr) returns the proper count of utf chars

so looks like i don't understand how to cast sfUint32 to wchar_t on Windows where wchar_t is 2 bytes long
and not 4 bytes to draw it correctly

how to pass whcar_t *wstr on Win10 to sfText_setUnicodeString() to get it working?

i've the same result using gcc 7.3 and clang 10 (msvc)

thanks.

serg

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: wchar_t to sfUint32 issue on WIndows
« Reply #3 on: May 31, 2020, 09:15:06 pm »
Quote
i've experienced an issue
Please describe it. Nobody wants to guess.

and

dear sir

would you please be so kind to provide a short example how to add event.text.unicode to wchar_t *str and how to pass that str to sfText_setUnicodeString() ( where wchar_t is 2 byte long on Win10)

thnx.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: wchar_t to sfUint32 issue on WIndows
« Reply #4 on: May 31, 2020, 09:52:59 pm »
A pointer cast on primitive types is never a good idea, it makes the compiler think that the pointed data is of another type than its actual type. There's no conversion at all, so it almost ends up in undefined behaviour.

sfEvent gives you a sfUint32 character, and sfText_setUnicodeString takes a const sfUint32*. Is there a good reason for storing your string as a wchar_t? If so, you'll have to convert using dedicated functions, as wchar_t uses UCS-2 encoding on Windows, and SFML gives you UTF-32 characters.
Laurent Gomila - SFML developer

serg

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: wchar_t to sfUint32 issue on WIndows
« Reply #5 on: June 01, 2020, 02:34:06 pm »
Is there a good reason for storing your string as a wchar_t?
text should be parsed using <string.h> f(x) 
 is there any way to parse UTF-32 string using C lang string functions and not char by char?
 
pls advice

thnx.

serg

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: wchar_t to sfUint32 issue on WIndows
« Reply #6 on: June 01, 2020, 03:52:41 pm »
...
sfEvent gives you a sfUint32 character, and sfText_setUnicodeString takes a const sfUint32*. Is there a good reason for storing your string as a wchar_t? If so, you'll have to convert using dedicated functions, as wchar_t uses UCS-2 encoding on Windows, and SFML gives you UTF-32 characters.

so my solution here is to draw chars as UTF-32 and store another wchar_t array to parse it

thnx.

ps: big thanks for C_SFML. it's superb!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: wchar_t to sfUint32 issue on WIndows
« Reply #7 on: June 01, 2020, 05:58:28 pm »
What do you mean with "parse"? What do you do with the text?
Laurent Gomila - SFML developer

serg

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: wchar_t to sfUint32 issue on WIndows
« Reply #8 on: June 02, 2020, 06:34:40 am »
What do you mean with "parse"? What do you do with the text?

i meant working with strings (arrays) using wcsncmp(), wcstok() and so on

and i don't now how to do it with UTF-32  on windows
definetely  it's offtopic here.

thnx
« Last Edit: June 02, 2020, 06:42:13 am by serg »