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

Author Topic: sf::Text, UTF-8 and Debian  (Read 2894 times)

0 Members and 1 Guest are viewing this topic.

Krofna

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
sf::Text, UTF-8 and Debian
« on: October 24, 2013, 11:23:04 am »
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Bug");
    sf::Text text;
    sf::Font font;
    sf::Event event;

    if (!font.loadFromFile("test.ttf"))
        return 0;

    std::basic_string<sf::Uint32> utf32line;
    std::string line = "&#12384;&#12365;&#12414;&#12367;&#12425;";
    sf::Utf8::toUtf32(line.begin(), line.end(), back_inserter(utf32line));
   
    text.setFont(font);
    text.setCharacterSize(30);
    text.setColor(sf::Color::Red);
    text.setString(utf32line);

    while (window.isOpen())
    {
        while (window.pollEvent(event))
            if (event.type == sf::Event::Closed)
                window.close();

        window.clear(sf::Color::White);
        window.draw(text);
        window.display();
    }
}

test.ttf is Freemono from Debian package fonts-freefont-ttf. line variable contains UTF-8 encoded string だきまくら, but code tag somehow breaks it.
And here is some FAQ from irc: Yes, freemono supports kana(see; http://www.gnu.org/software/freefont/coverage.html ), No  wchar_t is not going to work. I see (correct number of) boxes with ? in them.

tl;dr: Should work, doesn't.
« Last Edit: October 24, 2013, 11:28:31 am by Krofna »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Text, UTF-8 and Debian
« Reply #1 on: October 24, 2013, 11:37:52 am »
Your code looks good, I'll test it ASAP.
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::Text, UTF-8 and Debian
« Reply #2 on: October 24, 2013, 05:23:14 pm »
Well.... I downloaded the package, checked the contained TTFs and none of them had support for the glyphs you want. Correct me if I'm wrong but what I understand from that table is that it also says that none of the fonts have Hiragana or Katakana support (the row is empty). So... I guess the people on IRC lied? :-\

On Windows, if I copy Arial Unicode MS (which has almost full unicode glyph support) into the test directory and use it instead, the glyphs show up perfectly, so I don't think SFML can fix your problem...
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Krofna

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: sf::Text, UTF-8 and Debian
« Reply #3 on: October 24, 2013, 06:54:46 pm »
Well.... I downloaded the package, checked the contained TTFs and none of them had support for the glyphs you want. Correct me if I'm wrong but what I understand from that table is that it also says that none of the fonts have Hiragana or Katakana support (the row is empty). So... I guess the people on IRC lied? :-\

On Windows, if I copy Arial Unicode MS (which has almost full unicode glyph support) into the test directory and use it instead, the glyphs show up perfectly, so I don't think SFML can fix your problem...

... Then how can I display those characters in both terminal and text editor?

Krofna

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: sf::Text, UTF-8 and Debian
« Reply #4 on: October 24, 2013, 07:01:23 pm »
Looks like this is not SFML issue. Apparently Debian picks different font for displaying japanese characters and with correct style and size if current one doesn't support it. I solved the issue by loading correct font.

I'm sorry for bothering.  :'(

 

anything