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

Author Topic: Encoding problem, Xcode  (Read 2027 times)

0 Members and 1 Guest are viewing this topic.

poq

  • Newbie
  • *
  • Posts: 3
    • View Profile
Encoding problem, Xcode
« on: September 26, 2012, 02:09:40 pm »
Hi,

Just found this promising library and then stumbled with an encoding problem.

I use Xcode 4.2 and SFML 2 RC (installer). Source files are encoded in UTF-8.

I am trying to get Cyrillic chars to be shown properly using the SFML Application template:

    // Create a graphical text to display
    sf::Font font;
    if (!font.loadFromFile(resourcePath() + "mplus-1p-medium.ttf"))
        return EXIT_FAILURE;
    sf::Text text(L"\u043A к k", font, 50);
    text.setColor(sf::Color::Black);

(there's a Cyrillic K instead of html code in the source, seems there's a problem with encoding on the forums too  :D).

Default font which comes in Resources doesn't have non-Latin characters, so I've tried some other unicode-compitable fonts. And tried to follow similar issues posted on the forum but without much luck.

So, unicode sequence works, but the same Cyrillic letter typed as usual doesn't:



Is there a way to solve this in my case?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Encoding problem, Xcode
« Reply #1 on: September 26, 2012, 02:20:06 pm »
It seems that your compiler doesn't interpret the input file as UTF-8: your Cyrillic 'k' in UTF-8 is encoded as 0xD0 0xBA, but we can see that the printed characters are the 0xD0 and 0xBA characters of the Latin-1 character set (might be another one, a lot of character sets are compatible with Latin-1). So the compiler interprets your 2-byte UTF-8 character as two seperate 1-byte characters.
Laurent Gomila - SFML developer

poq

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Encoding problem, Xcode
« Reply #2 on: September 27, 2012, 06:31:09 pm »
Thanks.

So far two options solved it for me when rendering text:

1. Changing compiler from Apple LLVM to LLVM GCC in project properties.
2. Or converting strings from utf-8 to wide (while still using Apple LLVM). I have not figured how Utf::toWide works yet though, but it showed typed characters correctly.

Neither of them will help with title encoding.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Encoding problem, Xcode
« Reply #3 on: September 27, 2012, 07:02:01 pm »
Quote
1. Changing compiler from Apple LLVM to LLVM GCC in project properties.
Or maybe you should just play with the corresponding compiler flags (which I don't know, but I know that they exist).

Quote
2. Or converting strings from utf-8 to wide (while still using Apple LLVM). I have not figured how Utf::toWide works yet though, but it showed typed characters correctly.
So how do you convert them?

Quote
Neither of them will help with title encoding.
Nothing helps with title encoding, it's not supported yet ;)
Laurent Gomila - SFML developer

poq

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Encoding problem, Xcode
« Reply #4 on: September 27, 2012, 08:27:28 pm »
Nothing helps with title encoding, it's not supported yet ;)

Works perfectly on Windows  :). I've tried it on Windows 7 with VS 2010, and both title and sf::Text worked correctly from scratch.

So how do you convert them?

Just this way:

sf::Utf<8>::toWide(str.begin(), str.end(), str1.begin());


Also, seems to be relevant to the issue:

http://stackoverflow.com/questions/9246043/wcslen-works-differently-in-xcode-and-vc