SFML community forums

Help => Graphics => Topic started by: exafi on March 30, 2013, 12:56:29 am

Title: I don't find the problem with the size of "sf::Text::findCharacterPos" (SOLVED)
Post by: exafi on March 30, 2013, 12:56:29 am
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:
(http://i46.tinypic.com/1zevbyd.png)

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
Title: Re: I don't find the problem with the size of "sf :: Text :: findCharacterPos"
Post by: Laurent on March 30, 2013, 12:05:31 pm
This function returns local coordinates, donc forget to transform them (by text.getTransform()) to get global ones.
Title: Re: I don't find the problem with the size of "sf :: Text :: findCharacterPos"
Post by: exafi on March 30, 2013, 01:07:26 pm
ok thank you,I'll investigate what you say
Title: Re: I don't find the problem with the size of "sf :: Text :: findCharacterPos"
Post by: exafi on March 30, 2013, 05:55:34 pm
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
------------------------
Title: Re: I don't find the problem with the size of "sf :: Text :: findCharacterPos"
Post by: Laurent on April 01, 2013, 08:40:02 pm
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.
Title: Re: I don't find the problem with the size of "sf :: Text :: findCharacterPos"
Post by: exafi on April 01, 2013, 10:31:05 pm
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;