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

Author Topic: [SOLVED] Unicode in window titles doesn't work properly (Linux)  (Read 1952 times)

0 Members and 1 Guest are viewing this topic.

UniversallyUniqueID

  • Newbie
  • *
  • Posts: 6
    • View Profile
[SOLVED] Unicode in window titles doesn't work properly (Linux)
« 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:



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:



Any ideas?

Thanks in advance!
« Last Edit: October 31, 2019, 06:24:51 pm by UniversallyUniqueID »

UniversallyUniqueID

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unicode in window titles doesn't work properly (Linux)
« Reply #1 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.

texus

  • Sr. Member
  • ****
  • Posts: 486
    • View Profile
    • TGUI
    • Email
Re: Unicode in window titles doesn't work properly (Linux)
« Reply #2 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).
TGUI: C++ SFML GUI

UniversallyUniqueID

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unicode in window titles doesn't work properly (Linux)
« Reply #3 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.