# HG changeset patch # User phoku@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1224005396 0 # Node ID 9a05ba6735b18e7355cc7a39617f56330c4e6cbe # Parent c305c5eda7edbd9d5988f91ddc208aecc9d9bbae Now textwrapping handles newlines correctly in trunk, too. diff -r c305c5eda7ed -r 9a05ba6735b1 engine/core/video/fonts/fontbase.cpp --- 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() ) {