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

Author Topic: [SOLVED] SFML2 Unicode  (Read 4514 times)

0 Members and 2 Guests are viewing this topic.

Elarys

  • Newbie
  • *
  • Posts: 5
    • View Profile
[SOLVED] SFML2 Unicode
« on: July 29, 2012, 12:39:24 am »
I'm still relatively new to C++, and I chose SFML over SDL based on advise from various others. Working in a multi-language environment, I figured I'd try and get something working with multiple languages.

I've used the initial SFML2 Tutorial, and modified it a little after poking around the documentation. But I still can't get a simple hello world to work with anything outside the ASCII range. What am I doing wrong please?

All I get is 5 square blocks displayed. And so far this is just Japanese, I'd like to throw Korean and Chinese at this too.

My source code is here:
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");

        sf::Font myFont;
        myFont.loadFromFile("arial.ttf");
        //myFont.getDefaultFont();

        sf::String s;
        s = L"&#12371;&#12435;&#12395;&#12385;&#12399;";
        //s = "Test";

        sf::Text myText;
        myText.setString(s);

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

        window.clear();
        window.draw(myText);
        window.display();
    }

    return 0;
}
« Last Edit: July 29, 2012, 12:59:13 pm by Elarys »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML2 Unicode
« Reply #1 on: July 29, 2012, 12:59:50 am »
I'm not sure, but I'd say Arial doesn't support Japanese nor Korean nor Chinese symbols. If you want to use them, then you'll have to switch to more richer fonts.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Elarys

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML2 Unicode
« Reply #2 on: July 29, 2012, 01:13:41 am »
I've also tried the 22mb arialuni.ttf Arial Unicode MS, that comes with office which supports

Quote
Arabic script (Arabic, Balochi, Persian, Shahmukhi, Urdu), Armenian, Cyrillic (all or most of range), Devanagari, Georgian (Mkhedruli and Asomtavruli), Greek (including polytonic and Coptic characters), Gurmukhi, Hebrew, IPA, Japanese (Hiragana, Katakana, Kanji/Han Ideographs), Kannada, Korean (Hangul only), Latin, Tamil, Thai, Vietnamese

Same thing happens even with this font file.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML2 Unicode
« Reply #3 on: July 29, 2012, 10:29:12 am »
It works for me with the DFKai-SB font included in Windows 7.

You should also encode your Unicode characters rather than writing them directly in source code, to avoid potential problems with the file's own encoding.

sf::String s = L"\u3053\u3093\u306b\u3061\u306f";
Laurent Gomila - SFML developer

Elarys

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML2 Unicode
« Reply #4 on: July 29, 2012, 12:59:00 pm »
Thanks, and I found my problem too. When I was trying this late at night I ended up removing this line

myText.setFont(myFont);

So my chosen font wasn't actually being loaded at all. I had it there for my first few attempts, but removed it to let SFML use the default font... I forgot to put that line back in! My fault, sorry.

Thanks for the advice on Unicode though, I need to research encoding next.

Edit: On this note, is it possible SFML can load the font from the OS itself? Or do I need to specify a fully qualified path to the ttf file?
« Last Edit: July 29, 2012, 01:01:44 pm by Elarys »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML2 Unicode
« Reply #5 on: July 29, 2012, 02:11:11 pm »
Edit: On this note, is it possible SFML can load the font from the OS itself? Or do I need to specify a fully qualified path to the ttf file?
No the use of system fonts is not (yet) implemented, specially because you can't guarantee that system fonts it's available on all diffrent systems. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/