Mercurial > fife-parpg
changeset 160:9a05ba6735b1
Now textwrapping handles newlines correctly in trunk, too.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 14 Oct 2008 17:29:56 +0000 |
parents | c305c5eda7ed |
children | e62122d12727 |
files | engine/core/video/fonts/fontbase.cpp |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/video/fonts/fontbase.cpp Tue Oct 14 08:30:20 2008 +0000 +++ b/engine/core/video/fonts/fontbase.cpp Tue Oct 14 17:29:56 2008 +0000 @@ -106,13 +106,14 @@ int length = 0; int render_width = 0, render_height = 0; do { - pos = text.find("\n", last_pos); + pos = text.find('\n', last_pos); if (pos != std::string::npos) { length = pos - last_pos; } else { length = text.size() - last_pos; } std::string sub = text.substr(last_pos, length); + std::cerr << "substring: " << sub << "\n"; SDL_Surface* text_surface = renderString(sub); if (text_surface->w > render_width) { render_width = text_surface->w; @@ -164,6 +165,7 @@ firstLine = false; } + bool haveNewLine = false; while( getWidth(line) < render_width && pos < text.length() ) { if (text.at(pos) == ' ' && !line.empty()) @@ -173,13 +175,18 @@ // Special case: Already newlines in string: if( text.at(pos-1) == '\n' ) { - if( line[0] == '\n' && line.length() > 1 ) - line.erase(0); + if( line[line.size()-1] == '\n' ) + line.erase(line.size()-1); output.append(line); + line = ""; + haveNewLine = true; break; } } - if( pos >= text.length() ) + if( haveNewLine ) + continue; + + if( pos >= text.length()) break; if( break_pos.empty() ) {