From eff24b6380a9f15b4934fb62cb894de5e5d41448 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 8 Sep 2004 01:21:52 +0000 Subject: [PATCH] fix odd newline behavior in wrap mode --- stepmania/src/BitmapText.cpp | 50 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index 10557a5bf2..e8ce5cb96e 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -310,7 +310,6 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP // m_wTextLines.clear(); - // TODO: Don't handle line breaks differently in wrapping and non-wrapping mode. if( iWrapWidthPixels == -1 ) { split( CStringToWstring(sText), L"\n", m_wTextLines, false ); @@ -319,41 +318,40 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP { // // Break sText into lines that don't exceed iWrapWidthPixels - // (if only one word fits on the line, it may be larger than iWrapWidthPixels ). + // (if only one word fits on the line, it may be larger than iWrapWidthPixels). // // TODO: Investigate whether this works in all languages /* It doesn't. I can add Japanese wrapping, at least. We could handle hyphens * and soft hyphens and pretty easily, too. -glenn */ // TODO: Move this wrapping logic into Font - CStringArray asWords; - split( sText, " ", asWords ); + CStringArray asLines; + split( sText, "\n", asLines ); - CString sCurLine; - int iCurLineWidth = 0; - - /* Note that GetLineWidthInSourcePixels does not include horizontal overdraw - * right now (eg. italic fonts), so it's possible to go slightly over. */ - for( unsigned i=0; iGetLineWidthInSourcePixels( CStringToWstring(sWord) ); + CStringArray asWords; + split( asLines[line], " ", asWords ); - if( sCurLine.empty() ) - { - sCurLine = sWord; - iCurLineWidth = iWidthWord; - } - else + CString sCurLine; + int iCurLineWidth = 0; + + /* Note that GetLineWidthInSourcePixels does not include horizontal overdraw + * right now (eg. italic fonts), so it's possible to go slightly over. */ + for( unsigned i=0; iGetLineWidthInSourcePixels( CStringToWstring(sWord) ); + + if( sCurLine.empty() ) + { + sCurLine = sWord; + iCurLineWidth = iWidthWord; + continue; + } + CString sToAdd = " " + sWord; int iWidthToAdd = m_pFont->GetLineWidthInSourcePixels(L" ") + iWidthWord; - if( sWord == "\n" ) //Check to see if it's a forced newline - { - m_wTextLines.push_back( CStringToWstring(sCurLine) ); - sCurLine = ""; - iCurLineWidth = 0; - } - else if( iCurLineWidth + iWidthToAdd <= iWrapWidthPixels ) // will fit on current line + if( iCurLineWidth + iWidthToAdd <= iWrapWidthPixels ) // will fit on current line { sCurLine += sToAdd; iCurLineWidth += iWidthToAdd; @@ -365,8 +363,8 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP iCurLineWidth = iWidthWord; } } + m_wTextLines.push_back( CStringToWstring(sCurLine) ); } - m_wTextLines.push_back( CStringToWstring(sCurLine) ); } BuildChars();