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

Author Topic: Does sf::Text render dashes?  (Read 2073 times)

0 Members and 1 Guest are viewing this topic.

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Does sf::Text render dashes?
« on: November 12, 2014, 02:25:50 pm »
I'm trying to make a graphical representation of an Emily Dickinson poem, which is full of dashes in its lines. I open a text file with the poem and read from it, copying the lines into sf::text objects, but when displayed the dashes just appear as empty boxes. Any suggestions?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Does sf::Text render dashes?
« Reply #1 on: November 12, 2014, 02:33:13 pm »
Use a different font, which supports these dashes?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Does sf::Text render dashes?
« Reply #2 on: November 12, 2014, 02:41:13 pm »
Both TNR and Arial don't work, which is surprising. Do you know what fonts do work for this?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
AW: Does sf::Text render dashes?
« Reply #3 on: November 12, 2014, 03:27:09 pm »
No idea what sort of dashes you use.
If you want more help you need to provide a complete and minimal code example.
Also a screenshot and example input would be useful.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wh1t3crayon

  • Jr. Member
  • **
  • Posts: 93
    • View Profile
Re: Does sf::Text render dashes?
« Reply #4 on: November 13, 2014, 03:47:20 am »
Code: [Select]
Well, this is annoying. If I hardcode my string instead of reading from a file, the hyphen shows up (I meant hyphen earlier). code=cpp]
//this works
std::string str = "One need not be a Chamber -";
sf::Font font;
font.loadFromFile("fonts/times.ttf");
sf::Text text(str, font);
text.setPosition(50, 50);
text.setCharacterSize(30);
text.setColor(sf::Color::White);
window.draw(text);
window.display();


//this does not work, hyphen shows up as a outlined box
font.loadFromFile("fonts/times.ttf");
std::string line;
std::ifstream poem;
poem.open("files/poem.txt");
//for poem iteration
int i = 0;
while(getline(poem, line)){
Text text(line, font);
text.AssignVals();
texts_.push_back(text);
i++;
}
I'll take this to a c++ forum as it's not a sfml problem, but does anybody know why the hardcoded string would render but reading from a file wouldn't?

Edit:
Answer: the "hyphens" in my file weren't actually hyphens... thanks copy and paste :P
« Last Edit: November 13, 2014, 03:51:47 am by wh1t3crayon »