1
General / Re: hebrew and arabic strings
« on: December 05, 2013, 03:56:34 pm »Looks like the text file is in a different encoding than you assume when reading it in your code.1) I fixed the format (it was UTF-8 but probably with BOM)
Try to use a text editor to load the file and save it as UTF-8 (thats the most compatible format for files) without BOM (to avoid the 3 funny characters at start), then change your code to not use those w-things (because wide char is only vaguely defined in C and can be different on another system), then use the appropriate function to construct an sf::String (that internally is UTF-32) from UTF-8 data (I personally use sf::Utf but there may be a helper function in sf::String), then give that to sf::Text.
2) I changed the std::wstrings to normal std::strings
3) I didn't get all the sf::Utf stuff. I don't think I do it right. Can you give me an example of how to use it or how you use it please? I tried to work with it but I get compiler-errors which brings me to the definition of utf (utf.inl).
This is what I tried:
#include <SFML/Graphics.hpp>
#include <fstream>
#include <string>
int main()
{
sf::RenderWindow window(sf::VideoMode(500, 500), "SFML");
sf::Font font;
font.loadFromFile("arial.ttf");
sf::Text engText;
sf::Text hebText;
engText.setFont(font);
hebText.setFont(font);
engText.setPosition(200.0f, 200.0f);
hebText.setPosition(200.0f, 240.0f);
std::ifstream ifs("text.txt");
std::string engStr;
std::string hebStr;
sf::String str;
sf::Utf8 utf8;
while ( ifs >> engStr >> hebStr)
{
engText.setString(engStr);
str = utf8.fromAnsi(hebStr.begin(),hebStr.end(),str);
hebText.setString(hebStr);
}
ifs.close();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(engText);
window.draw(hebText);
window.display();
}
return 0;
}
This is the error:#include <fstream>
#include <string>
int main()
{
sf::RenderWindow window(sf::VideoMode(500, 500), "SFML");
sf::Font font;
font.loadFromFile("arial.ttf");
sf::Text engText;
sf::Text hebText;
engText.setFont(font);
hebText.setFont(font);
engText.setPosition(200.0f, 200.0f);
hebText.setPosition(200.0f, 240.0f);
std::ifstream ifs("text.txt");
std::string engStr;
std::string hebStr;
sf::String str;
sf::Utf8 utf8;
while ( ifs >> engStr >> hebStr)
{
engText.setString(engStr);
str = utf8.fromAnsi(hebStr.begin(),hebStr.end(),str);
hebText.setString(hebStr);
}
ifs.close();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(engText);
window.draw(hebText);
window.display();
}
return 0;
}
Error 4 error C2676: binary '++' : 'sf::String' does not define this operator or a conversion to a type acceptable to the predefined operator.
I get this error 5 times exactly the same.
And this warning:
Warning 1 warning C4101: 'utf8' : unreferenced local variable