fix odd newline behavior in wrap mode

This commit is contained in:
Glenn Maynard
2004-09-08 01:21:52 +00:00
parent 96e96f042f
commit eff24b6380
+10 -12
View File
@@ -310,7 +310,6 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP
// //
m_wTextLines.clear(); m_wTextLines.clear();
// TODO: Don't handle line breaks differently in wrapping and non-wrapping mode.
if( iWrapWidthPixels == -1 ) if( iWrapWidthPixels == -1 )
{ {
split( CStringToWstring(sText), L"\n", m_wTextLines, false ); split( CStringToWstring(sText), L"\n", m_wTextLines, false );
@@ -325,8 +324,13 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP
/* It doesn't. I can add Japanese wrapping, at least. We could handle hyphens /* It doesn't. I can add Japanese wrapping, at least. We could handle hyphens
* and soft hyphens and pretty easily, too. -glenn */ * and soft hyphens and pretty easily, too. -glenn */
// TODO: Move this wrapping logic into Font // TODO: Move this wrapping logic into Font
CStringArray asLines;
split( sText, "\n", asLines );
for( unsigned line = 0; line < asLines.size(); ++line )
{
CStringArray asWords; CStringArray asWords;
split( sText, " ", asWords ); split( asLines[line], " ", asWords );
CString sCurLine; CString sCurLine;
int iCurLineWidth = 0; int iCurLineWidth = 0;
@@ -342,18 +346,12 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP
{ {
sCurLine = sWord; sCurLine = sWord;
iCurLineWidth = iWidthWord; iCurLineWidth = iWidthWord;
continue;
} }
else
{
CString sToAdd = " " + sWord; CString sToAdd = " " + sWord;
int iWidthToAdd = m_pFont->GetLineWidthInSourcePixels(L" ") + iWidthWord; int iWidthToAdd = m_pFont->GetLineWidthInSourcePixels(L" ") + iWidthWord;
if( sWord == "\n" ) //Check to see if it's a forced newline if( iCurLineWidth + iWidthToAdd <= iWrapWidthPixels ) // will fit on current line
{
m_wTextLines.push_back( CStringToWstring(sCurLine) );
sCurLine = "";
iCurLineWidth = 0;
}
else if( iCurLineWidth + iWidthToAdd <= iWrapWidthPixels ) // will fit on current line
{ {
sCurLine += sToAdd; sCurLine += sToAdd;
iCurLineWidth += iWidthToAdd; iCurLineWidth += iWidthToAdd;
@@ -365,9 +363,9 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP
iCurLineWidth = iWidthWord; iCurLineWidth = iWidthWord;
} }
} }
}
m_wTextLines.push_back( CStringToWstring(sCurLine) ); m_wTextLines.push_back( CStringToWstring(sCurLine) );
} }
}
BuildChars(); BuildChars();
UpdateBaseZoom(); UpdateBaseZoom();