-
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
-
This function returns local coordinates, donc forget to transform them (by text.getTransform()) to get global ones.
-
ok thank you,I'll investigate what you say
-
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
------------------------
-
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.
-
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;