SFML community forums

Help => Window => Topic started by: UniversallyUniqueID on October 31, 2019, 03:48:22 pm

Title: [SOLVED] Unicode in window titles doesn't work properly (Linux)
Post by: UniversallyUniqueID on October 31, 2019, 03:48:22 pm
Hi!

Any non-ASCII characters in the Window/RenderWindow title seem to be simply skipped over by SFML, yet display correctly in the titles of other windows.

Code:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main(int argc, char ** argv) {
    sf::RenderWindow window(sf::VideoMode(300, 200), u8"Unicode: naïve こんにちは");
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
                        }
                }
                window.clear(sf::Color::White);
                window.display();
        }

    return 0;
}

Running it gives:

(https://i.imgur.com/E8ho4y3.png)

The non-ASCII characters are skipped or replaced with a space.

I have ruled out font/etc issues, since setting a webpage's title to the same string works perfectly:

(https://i.imgur.com/VZylDTm.png)

Any ideas?

Thanks in advance!
Title: Re: Unicode in window titles doesn't work properly (Linux)
Post by: UniversallyUniqueID on October 31, 2019, 04:44:36 pm
Also: it isn't an issue with how C++ might store the string, because if I print it, the output on console is perfect.
Title: Re: Unicode in window titles doesn't work properly (Linux)
Post by: texus on October 31, 2019, 06:00:48 pm
It works for me when replacing u8 by L:
sf::RenderWindow window(sf::VideoMode(300, 200), L"Unicode: naïve こんにちは");

I've noticed in the past that sf::String works more reliably when using wide-strings instead of UTF8 strings on linux (unless you manually use sf::String::fromUft8 and sf::String::toUtf8).
Title: Re: Unicode in window titles doesn't work properly (Linux)
Post by: UniversallyUniqueID on October 31, 2019, 06:24:36 pm
It works for me when replacing u8 by L:
sf::RenderWindow window(sf::VideoMode(300, 200), L"Unicode: naïve こんにちは");

I've noticed in the past that sf::String works more reliably when using wide-strings instead of UTF8 strings on linux (unless you manually use sf::String::fromUft8 and sf::String::toUtf8).

Thanks! That solves it.