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

Author Topic: UTF32String and sf::String not displaying ALL characters  (Read 5045 times)

0 Members and 3 Guests are viewing this topic.

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
UTF32String and sf::String not displaying ALL characters
« on: September 22, 2010, 11:33:11 pm »
Hey everyone,

I am in the process of creating a text-input field for my game, and I am saving text value in a sf::Unicode::UTF32String and displaying it using sf::String. I am currently running SFML 1.6 because I like stable releases. On to my problem:

It works fine as long as I type in "normal" characters: ABCD123$§®üåäö but on my Mac keyboard I can type some of the more esoteric characters: "†ƒfi", and they are not displayed. I know this is REALLY REALLY picky and nobody will probably ever use them, and whatnot, but the bug is as I see it that I am using a UTF32-string which AFAIK should be able to contain every possible character known to man, but it it isn't. The code needed to recreate this problem:

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(640, 480), "SFML Graphics");

// The unicode string and sprite
sf::String sprite("Type... ");
sf::Unicode::UTF32String str;

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();

// Text entered
if (Event.Type == sf::Event::TextEntered)
{
str += Event.Text.Unicode;
sprite.SetText(str);
}
        }

        App.Clear();

// Draw the text
App.Draw(sprite);

        App.Display();
    }

    return EXIT_SUCCESS;
}


Why do you think this is? Is this a bug in my code or a limitation with SFML/C++? I get the same results if I add "setlocale(LC_ALL, "")".

And the problem is not really that I think I need those characters, just that if I am using an UTF32-string, shouldn't understand them?

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
UTF32String and sf::String not displaying ALL characters
« Reply #1 on: September 23, 2010, 01:56:25 pm »
If you display your character in your TextEntered condition block, you'll see that the text event *is* received, but the character is not displayed (I'm using Mac OS X too).

This could have been because the font is missing this specific character, but I tried to use an external font file (and checked it contained the requested characters), and it did not work too.

So I suppose it depends on the sf::String general implementation. Let's see what Laurant has to say on this point :P .
Want to play movies in your SFML application? Check out sfeMovie!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UTF32String and sf::String not displaying ALL characters
« Reply #2 on: October 03, 2010, 11:23:13 am »
In SFML 1, sf::Font uses a limited characters set. The default one doesn't contain those characters, so you have to load a font and use your own custom characters set (it is impossible to use the built-in default font with a custom characters set).
Laurent Gomila - SFML developer

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
UTF32String and sf::String not displaying ALL characters
« Reply #3 on: October 04, 2010, 04:51:23 pm »
Is there a tutorial in defining charsets? Or somewhere where I can find a list of them. By that I mean the UTF32-array used in sf::Font::LoadFromFile and that is used on http://www.sfml-dev.org/tutorials/1.6/graphics-fonts.php

Code: [Select]
sf::Font   MyFont;
sf::Uint32 MyCharset[] = {0x4E16, 0x754C, 0x60A8, 0x597D, 0x0}; // a set of unicode chinese characters
if (!MyFont.LoadFromFile("arial.ttf", 50, MyCharset))
{
    // Error...
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UTF32String and sf::String not displaying ALL characters
« Reply #4 on: October 04, 2010, 05:55:37 pm »
I don't understand what you're looking for. Everything that you need to know is in the font tutorial.
Laurent Gomila - SFML developer

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
UTF32String and sf::String not displaying ALL characters
« Reply #5 on: October 04, 2010, 06:00:03 pm »
This line.

Code: [Select]
sf::Uint32 MyCharset[] = {0x4E16, 0x754C, 0x60A8, 0x597D, 0x0}; // a set of unicode chinese characters

It defines a charset. Why does it have to be a set of chinese characters, what do they mean in the context? I know that there are a number of different charsets ISO-8859, UTF-32/, etc, what does it mean?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UTF32String and sf::String not displaying ALL characters
« Reply #6 on: October 04, 2010, 07:43:53 pm »
I chose chinese characters in the tutorial to demonstrate the Unicode capabilities of the sf::Font class, but these are chosen randomly. You must put in the charset the characters that you're going to display with your sf::Strings.
Laurent Gomila - SFML developer

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
UTF32String and sf::String not displaying ALL characters
« Reply #7 on: October 04, 2010, 08:29:19 pm »
You mean their unicode code ?
Want to play movies in your SFML application? Check out sfeMovie!

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
UTF32String and sf::String not displaying ALL characters
« Reply #8 on: October 04, 2010, 08:30:32 pm »
What happens if I don't specify a charset then? And if I specify a charset, shouldn't I have to specify the entire alphabet and everything in between? Or do I just specify "special" characters (as in the example, a couple chinese characters)?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UTF32String and sf::String not displaying ALL characters
« Reply #9 on: October 04, 2010, 09:39:37 pm »
Quote
You mean their unicode code ?

Yes.

Quote
What happens if I don't specify a charset then?

Then the default one will be used.

Quote
And if I specify a charset, shouldn't I have to specify the entire alphabet and everything in between?

Yes, you have to specify every single character that will potentially be displayed.

The example above is... just an example. A real chinese character set would most likely contain hundreds of characters, but that doesn't fit in a tutorial :)
Laurent Gomila - SFML developer

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
UTF32String and sf::String not displaying ALL characters
« Reply #10 on: October 04, 2010, 09:49:32 pm »
There must be somewhere where one can download tables of these charsets? And how do I see what characters the default one defines?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UTF32String and sf::String not displaying ALL characters
« Reply #11 on: October 04, 2010, 10:12:20 pm »
Quote
There must be somewhere where one can download tables of these charsets?

You don't need to use a predefined one, you can simply build a list of the characters that you need. But if you want, yes, you can easily find tables of the most common charsets available (for example on wikipedia).

Quote
And how do I see what characters the default one defines?

Look at latin-1, or ISO 8859-1.
Laurent Gomila - SFML developer

ErikPerik

  • Newbie
  • *
  • Posts: 19
    • View Profile
UTF32String and sf::String not displaying ALL characters
« Reply #12 on: October 04, 2010, 10:51:52 pm »
But if I plan to use the font for a chat in a game, I would need a lot of characters. And that would be one huge table. And maybe I would like to mix both chinese and latin characters?

If I get this correct: The charset you specify to LoadFromFile is a list of all characters that you want to use for that font. What it does is to load those characters into memory, so the reason not all characters are loaded from the beginning is because it would take huge amounts of memory: 4*2^32 bytes = 16 gb? But the all the characters ARE available (if the font has them), only not loaded. And that is what the charset does. Am I correct?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UTF32String and sf::String not displaying ALL characters
« Reply #13 on: October 04, 2010, 10:56:40 pm »
This is 100% correct :)

And this potential issue has already been solved in SFML 2, there's no more charset, characters are loaded on the fly.
Laurent Gomila - SFML developer