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

Author Topic: I don't find the problem with the size of "sf::Text::findCharacterPos" (SOLVED)  (Read 2757 times)

0 Members and 1 Guest are viewing this topic.

exafi

  • Newbie
  • *
  • Posts: 41
    • View Profile
I don't find the problem with the size of "sf :: Text :: findCharacterPos"
I'm trying to get the sf :: text makes a line break when the text arrives to the size of 500

Here an image:


Here code
void Text::setText(string texto){
    isChange=true;
    sfText->setString(texto);
    string t1=texto;
    int newline=500;
    for(int i=0;i< t1.size();i++){
        if(sfText->findCharacterPos(i).x>newline){
            t1 = sfText->getString();
            for(int j=i;j>0;j--){
                if(t1[j]==' '){
                    cout <<  sfText->findCharacterPos(j).x << "-" << newline<< "-" << t1[j+1] <<endl;
                    i=j+1;
                    t1.insert(j,"\n");
                    sfText->setString(t1);
                    break;
                }
            }
        }
    }
}

GL
« Last Edit: April 02, 2013, 01:33:06 pm by exafi »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
This function returns local coordinates, donc forget to transform them (by text.getTransform()) to get global ones.
Laurent Gomila - SFML developer

exafi

  • Newbie
  • *
  • Posts: 41
    • View Profile
ok thank you,I'll investigate what you say
« Last Edit: March 30, 2013, 05:55:22 pm by exafi »

exafi

  • Newbie
  • *
  • Posts: 41
    • View Profile
Lauren, I'm not clear what I should do. :(

combinated transform of the object
------------------------
1
0
0
0
-0
1
0
0
0
0
1
0
0
0
0
1
----------INVERSE--------------
1
-0
0
0
0
1
0
-0
0
0
1
0
-0
-0
0
1
------------------------
« Last Edit: April 01, 2013, 06:57:42 pm by exafi »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
You problem is not clear, and I don't know what to tell you. You should write a complete and minimal example that reproduces the problem, so that I can test it and find a solution.
Laurent Gomila - SFML developer

exafi

  • Newbie
  • *
  • Posts: 41
    • View Profile
I want real size of sf::Text


thanks for any inconvenience

SOLVED
f::Font font;
    font.loadFromFile("./data/fonts/arial.ttf");
    int linespacing = font.getLineSpacing(sfText->getCharacterSize());
    int lengthstring=0;
    int t;
    ifstream file("./data/text/text1.txt");
    texto.clear();
    for(;file.eof()==false;){
        string t1;
        file >> t1;
        texto = texto+t1+' ';
    }
    for(int i=0;i<texto.length();i++){
        t=font.getGlyph(texto[i], 18, false ).advance;
        lengthstring = lengthstring + t;
        if(lengthstring>=500){
            lengthstring = 0;
            for(int j=i;j>0;j--){
                if(texto[j]==' '){
                    texto.replace(j,1,"\n");
                    i=j;
                    break;
                }
            }
        }
        cout << i  << "-" << (int)texto[i] << "-" << t  << endl;
    }
    sfText->setString(texto);
    cout << "tamaƱos: "<<  lengthstring << endl;
    isChange=true;
« Last Edit: April 02, 2013, 01:33:43 pm by exafi »