better line wrapping respecting \n too now
This commit is contained in:
parent
c72cd2ac4c
commit
d2928459a0
|
@ -184,7 +184,7 @@ float FontMetrics::getHeight(const string &str) const {
|
||||||
|
|
||||||
string FontMetrics::wordWrapText(string text, int maxWidth) {
|
string FontMetrics::wordWrapText(string text, int maxWidth) {
|
||||||
// Strip newlines from source
|
// Strip newlines from source
|
||||||
//replaceAll(text, "\n", " ");
|
replaceAll(text, "\n", " \n ");
|
||||||
|
|
||||||
// Get all words (space separated text)
|
// Get all words (space separated text)
|
||||||
vector<string> words;
|
vector<string> words;
|
||||||
|
@ -195,13 +195,19 @@ string FontMetrics::wordWrapText(string text, int maxWidth) {
|
||||||
|
|
||||||
for(unsigned int i = 0; i < words.size(); ++i) {
|
for(unsigned int i = 0; i < words.size(); ++i) {
|
||||||
string word = words[i];
|
string word = words[i];
|
||||||
float wordWidth = this->getTextWidth(word);
|
if(word=="\n"){
|
||||||
if (lineWidth + wordWidth > maxWidth) {
|
wrappedText += word;
|
||||||
wrappedText += "\n";
|
lineWidth = 0;
|
||||||
lineWidth = 0;
|
}
|
||||||
}
|
else {
|
||||||
lineWidth += wordWidth;
|
float wordWidth = this->getTextWidth(word);
|
||||||
wrappedText += word + " ";
|
if (lineWidth + wordWidth > maxWidth) {
|
||||||
|
wrappedText += "\n";
|
||||||
|
lineWidth = 0;
|
||||||
|
}
|
||||||
|
lineWidth += this->getTextWidth(word+" ");
|
||||||
|
wrappedText += word + " ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrappedText;
|
return wrappedText;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user