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

Author Topic: Drawing UTF-8 string extracted from variable/xml with sf::Text  (Read 8047 times)

0 Members and 1 Guest are viewing this topic.

bokoblin

  • Newbie
  • *
  • Posts: 24
    • View Profile
Drawing UTF-8 string extracted from variable/xml with sf::Text
« on: January 25, 2017, 07:30:50 pm »
Hello,

I'm trying for some time to draw french text with sf::Text.
This works using setString(L"français");
But it obviously can't work with text contained in variable/parsed from elsewhere
because you can't do
string test = "français";
setString(Ltest); or setString(L\"test\"); or setString(test); (the latter returns strange characters)

I just tried using sf::String but while the official tuto says I can draw this because it is inherited from sf::Drawable, my compiler says that sf::String is not compatible with class sf::Drawable.

So what can I do to draw UTF-8 parsed text ?


I'm on Windows 10 with SFML 2.3.2 on CLion IDE

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #1 on: January 25, 2017, 08:48:58 pm »
std::string utf8_string = <extracted from file>;

sf::Text text;
text.setString(sf::String::fromUtf8(utf8_string.begin(), utf8_string.end()));
Laurent Gomila - SFML developer

bokoblin

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #2 on: January 25, 2017, 10:23:34 pm »
Merci, ça fonctionne, je commençais à désespérer de trouver une solution !

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #3 on: January 26, 2017, 06:29:51 am »
In english please :P
Laurent Gomila - SFML developer

bokoblin

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #4 on: February 02, 2017, 03:49:33 pm »
I know, but it was because you are french ^^

Anyway, It works great on Windows, but when I try compiling my project on linux I have the following error :

In member function ‘virtual void Button::sync(DataBase*)’:
158:27: error: ‘fromUtf8’ is not a member of ‘sf::String’
m_label.setString(sf::String::fromUtf8(utf8_string.begin(), utf8_string.end()));
make[2]: *** [CMakeFiles/runner.dir/src/view/Button.cpp.o]
Erreur 1
make[1]: *** [CMakeFiles/runner.dir/all] Erreur 2
make: *** [all] Erreur 2

I'm using SFML 2.3.2, located in <project directory>/libs/SFML-2.3.2
« Last Edit: February 02, 2017, 03:55:44 pm by bokoblin »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #5 on: February 02, 2017, 06:50:10 pm »
You must include a old header, sf::String::fromUtf8 was added in SFML 2.2.
Laurent Gomila - SFML developer

bokoblin

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #6 on: February 02, 2017, 06:57:07 pm »
What do you mean by including an old header ? I tried
#include <SFML/System/String.hpp> because it is in this header where fromUtf8 is, but it doesn't work

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #7 on: February 02, 2017, 07:05:14 pm »
What I say is that the version of <SFML/System/String.hpp> that gets included in your code (which is often not the one we expect) is older than SFML 2.2. Make sure that your version is up-to-date, and that you don't have other older versions of SFML installed elsewhere.
Laurent Gomila - SFML developer

bokoblin

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #8 on: February 02, 2017, 07:27:08 pm »
I had indeed an old version on my system. I understood "you must" as what I should do
« Last Edit: February 02, 2017, 09:00:13 pm by bokoblin »

bokoblin

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #9 on: February 02, 2017, 09:05:24 pm »
Cmake is working by replacing :
FIND_PACKAGE(SFML 2 COMPONENTS system window graphics audio REQUIRED )
by
FIND_PACKAGE(SFML 2.3 COMPONENTS system window graphics audio REQUIRED )

but "make" have undefined references for sf::color and sf::renderstate only

here is attached the command that make executes for linking into an executable

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #10 on: February 02, 2017, 10:18:28 pm »
The order of the libraries to link is wrong.

FIND_PACKAGE(SFML 2.3 COMPONENTS audio graphics window system REQUIRED )
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

bokoblin

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #11 on: February 02, 2017, 10:27:43 pm »
Hello, thanks but same issue with your proposition :/ I did thought about it this afternoon (and had forgotten it just after, though)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #12 on: February 02, 2017, 10:31:53 pm »
Make sure you do clean CMake's cache and run CMake again.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

bokoblin

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #13 on: February 02, 2017, 10:40:31 pm »
Yes it's what I do each time by deleting build folder, just checked again and it fails at "linking CXX executable"

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Drawing UTF-8 string extracted from variable/xml with sf::Text
« Reply #14 on: February 03, 2017, 01:01:57 am »
So what's the exact error message?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything