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();
// TODO: Don't handle line breaks differently in wrapping and non-wrapping mode.
if( iWrapWidthPixels == -1 )
{
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
* and soft hyphens and pretty easily, too. -glenn */
// TODO: Move this wrapping logic into Font
CStringArray asLines;
split( sText, "\n", asLines );
for( unsigned line = 0; line < asLines.size(); ++line )
{
CStringArray asWords;
split( sText, " ", asWords );
split( asLines[line], " ", asWords );
CString sCurLine;
int iCurLineWidth = 0;
@@ -342,18 +346,12 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP
{
sCurLine = sWord;
iCurLineWidth = iWidthWord;
continue;
}
else
{
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,9 +363,9 @@ void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthP
iCurLineWidth = iWidthWord;
}
}
}
m_wTextLines.push_back( CStringToWstring(sCurLine) );
}
}
BuildChars();
UpdateBaseZoom();