mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Fix incorrect string handling in pfJournalBook::IRenderPage()
Unify references to HTML string chunk as being accessed as wchar_t[] strings rather than repeatedly calling std::wstring.c_str() on the chunk, then using character positions obtained from those strings to index directly into the std::wstring[] form from chunk->fText.
This commit is contained in:
@ -2647,7 +2647,7 @@ void pfJournalBook::IRenderPage( UInt32 page, UInt32 whichDTMap, hsBool suppress
|
|||||||
|
|
||||||
switch( chunk->fType )
|
switch( chunk->fType )
|
||||||
{
|
{
|
||||||
case pfEsHTMLChunk::kParagraph:
|
case pfEsHTMLChunk::kParagraph:
|
||||||
if( ( chunk->fFlags & pfEsHTMLChunk::kAlignMask ) == pfEsHTMLChunk::kLeft )
|
if( ( chunk->fFlags & pfEsHTMLChunk::kAlignMask ) == pfEsHTMLChunk::kLeft )
|
||||||
{
|
{
|
||||||
dtMap->SetJustify( plDynamicTextMap::kLeftJustify );
|
dtMap->SetJustify( plDynamicTextMap::kLeftJustify );
|
||||||
@ -2668,10 +2668,14 @@ void pfJournalBook::IRenderPage( UInt32 page, UInt32 whichDTMap, hsBool suppress
|
|||||||
width = (UInt16)(512 - fPageLMargin - fPageRMargin);
|
width = (UInt16)(512 - fPageLMargin - fPageRMargin);
|
||||||
height = (UInt16)(512 - fPageBMargin - y);
|
height = (UInt16)(512 - fPageBMargin - y);
|
||||||
UInt32 lastChar;
|
UInt32 lastChar;
|
||||||
dtMap->CalcWrappedStringSize( chunk->fText.c_str(), &width, &height, &lastChar, &ascent, &lastX, &lastY );
|
const wchar_t *fTextStr; // initialize later to avoid compile errors inside case block
|
||||||
|
int fTextStrLen;
|
||||||
|
fTextStr = chunk->fText.c_str();
|
||||||
|
fTextStrLen = chunk->fText.length();
|
||||||
|
dtMap->CalcWrappedStringSize( fTextStr, &width, &height, &lastChar, &ascent, &lastX, &lastY );
|
||||||
width = (UInt16)(512 - fPageLMargin - fPageRMargin);
|
width = (UInt16)(512 - fPageLMargin - fPageRMargin);
|
||||||
if( !suppressRendering )
|
if( !suppressRendering )
|
||||||
dtMap->DrawWrappedString( (UInt16)fPageLMargin, y, chunk->fText.c_str(), width, (UInt16)(512 - fPageBMargin - y), &lastX, &lastY );
|
dtMap->DrawWrappedString( (UInt16)fPageLMargin, y, fTextStr, width, (UInt16)(512 - fPageBMargin - y), &lastX, &lastY );
|
||||||
|
|
||||||
if( lastChar == 0 )
|
if( lastChar == 0 )
|
||||||
{
|
{
|
||||||
@ -2682,17 +2686,16 @@ void pfJournalBook::IRenderPage( UInt32 page, UInt32 whichDTMap, hsBool suppress
|
|||||||
idx--;
|
idx--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( chunk->fText[ lastChar ] != 0 )
|
if( fTextStr[ lastChar ] != L'\0' )
|
||||||
{
|
{
|
||||||
// Didn't get to render the whole paragraph in this go, so we're going to cheat
|
// Didn't get to render the whole paragraph in this go, so we're going to cheat
|
||||||
// and split the paragraph up into two so that we can handle it properly. Note:
|
// and split the paragraph up into two so that we can handle it properly. Note:
|
||||||
// this changes the chunk array beyond this point, so we need to invalidate the
|
// this changes the chunk array beyond this point, so we need to invalidate the
|
||||||
// cache, but that's ok 'cause if we're doing this, it's probably invalid (or empty)
|
// cache, but that's ok 'cause if we're doing this, it's probably invalid (or empty)
|
||||||
// anyway
|
// anyway
|
||||||
int fTextLen = chunk->fText.length();
|
wchar_t *s = TRACKED_NEW wchar_t[fTextStrLen+1];
|
||||||
wchar_t *s = TRACKED_NEW wchar_t[fTextLen+1];
|
wcscpy(s,fTextStr);
|
||||||
wcscpy(s,chunk->fText.c_str());
|
s[fTextStrLen] = L'\0';
|
||||||
s[fTextLen] = L'\0';
|
|
||||||
|
|
||||||
// Note: Makes a copy of the string
|
// Note: Makes a copy of the string
|
||||||
pfEsHTMLChunk *c2 = TRACKED_NEW pfEsHTMLChunk( &s[ lastChar ] );
|
pfEsHTMLChunk *c2 = TRACKED_NEW pfEsHTMLChunk( &s[ lastChar ] );
|
||||||
|
Reference in New Issue
Block a user