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

Author Topic: Character encoding problem  (Read 1807 times)

0 Members and 1 Guest are viewing this topic.

zslevi

  • Newbie
  • *
  • Posts: 2
    • View Profile
Character encoding problem
« on: December 15, 2011, 10:09:52 pm »
I've tried the font drawing tutorial program, worked without a problem. Then I tried to draw text that uses non-ASCII characters.
I read the text to be displayed from an UTF-8 file.


Code: [Select]

const sf::Uint8* readStringCpp(){
    std::string line("");
    std::ifstream mfile("utf8text.txt");
    if (mfile.is_open()){
        std::getline(mfile,line);    
    }
    return (sf::Uint8*)line.c_str();        
}


Code: [Select]
   
    ...
    sf::Unicode::Text ucText(readStringCpp());    
    sf::String Hello(ucText);
   
    Hello.SetFont(MyFont);
    Hello.SetColor(sf::Color(0, 128, 128));
    Hello.SetPosition(60.f, 120.f);
    ...


And choose Arial Unicode for font.

The standard text to test Hungarian characters is "Árvíztűrő tükörfúrógép". Most of the accented characters of this are already in ASCII, except for Ő and Ű.

What I've got:
http://i.imgur.com/dpHyN.png

As you can see, the non-ASCII characters didn't got displayed.
What did I wrong?

If I use wide character literals, I get the same.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Character encoding problem
« Reply #1 on: December 15, 2011, 10:39:56 pm »
Quote
Most of the accented characters of this are already in ASCII

ASCII only defines 128 characters. You're rather referring to one of the extended ASCII encodings, probably latin-1.

But anyway, your problem is that the font is loaded with a predefined character set, which probably doesn't contain the characters that you don't see.

Use the 3rd parameter of Font::LoadFromFile to specify a custom characters set. Or use SFML 2, which is easier.
Laurent Gomila - SFML developer

zslevi

  • Newbie
  • *
  • Posts: 2
    • View Profile
Character encoding problem
« Reply #2 on: December 17, 2011, 12:24:24 am »
Thanks, that was it, I somehow missed that for the first reading of the tutorial. However it would be nice to have some utility function initializing the characterset for a certain ISO-8859-x characterset for merely convenience.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Character encoding problem
« Reply #3 on: December 17, 2011, 11:14:33 am »
There's no more explicit characters set to define in SFML 2.
Laurent Gomila - SFML developer

 

anything