index out of bounds
In ppPDFWrappedText unit, there is a bug only occurs in some situation.
" index(0) out of bounds "
{TppPDFWrappedText.WriteCenterRightText
Write Center or Right aligned text to the content stream. }
procedure TppPDFWrappedText.WriteCenterRightText;
var
ldLastOffset: Double;
liIndex: Integer;
lsText: String;
ldTextWidth: Double;
begin
FRunningOffset := 0;
{Write the first line in the memo/wrapped label}
lsText := TppPDFUtils.ProcessText(FWrappedText.Strings[0]);
//<------------// Bug is here
ldTextWidth := TextWidthPoints(FWrappedText.Strings[0]);
ldLastOffset := ProcessCenterRightJustification(lsText,
DrawTextCommand.TextAlignment, ldTextWidth, 0);
FLeftOffset := FLeftOffset + ldLastOffset;
WriteMSLine(MemoryStream, ExtToStr(FLeftOffset) + ' ' +
ExtToStr(FBottomOffset) + ' Td');
WriteMSLine(MemoryStream, '(' + lsText + ') Tj');
{Base the remaining lines on the initial offset}
for liIndex := 1 to FWrappedText.Count - 1 do
begin
lsText := TppPDFUtils.ProcessText(FWrappedText.Strings[liIndex]);
ldTextWidth := TextWidthPoints(FWrappedText.Strings[liIndex]);
FLeftOffset := ProcessCenterRightJustification(lsText,
DrawTextCommand.TextAlignment, ldTextWidth, ldLastOffset);
FBottomOffset := -FLineHeight;
WriteMSLine(MemoryStream, ExtToStr(FLeftOffset) + ' ' +
ExtToStr(FBottomOffset) + ' Td');
WriteMSLine(MemoryStream, '(' + lsText + ') Tj');
ldLastOffset := FLeftOffset;
end;
WriteMSLine(MemoryStream, 'ET');
end;
When the 2nd time this function is called, sometime the FWrappedText is
empty, then it cause the problem.
I make some changes for this procedure to test the 'Empty' situation, the
bug is gone and the PDF file is good as expected.
" index(0) out of bounds "
{TppPDFWrappedText.WriteCenterRightText
Write Center or Right aligned text to the content stream. }
procedure TppPDFWrappedText.WriteCenterRightText;
var
ldLastOffset: Double;
liIndex: Integer;
lsText: String;
ldTextWidth: Double;
begin
FRunningOffset := 0;
{Write the first line in the memo/wrapped label}
lsText := TppPDFUtils.ProcessText(FWrappedText.Strings[0]);
//<------------// Bug is here
ldTextWidth := TextWidthPoints(FWrappedText.Strings[0]);
ldLastOffset := ProcessCenterRightJustification(lsText,
DrawTextCommand.TextAlignment, ldTextWidth, 0);
FLeftOffset := FLeftOffset + ldLastOffset;
WriteMSLine(MemoryStream, ExtToStr(FLeftOffset) + ' ' +
ExtToStr(FBottomOffset) + ' Td');
WriteMSLine(MemoryStream, '(' + lsText + ') Tj');
{Base the remaining lines on the initial offset}
for liIndex := 1 to FWrappedText.Count - 1 do
begin
lsText := TppPDFUtils.ProcessText(FWrappedText.Strings[liIndex]);
ldTextWidth := TextWidthPoints(FWrappedText.Strings[liIndex]);
FLeftOffset := ProcessCenterRightJustification(lsText,
DrawTextCommand.TextAlignment, ldTextWidth, ldLastOffset);
FBottomOffset := -FLineHeight;
WriteMSLine(MemoryStream, ExtToStr(FLeftOffset) + ' ' +
ExtToStr(FBottomOffset) + ' Td');
WriteMSLine(MemoryStream, '(' + lsText + ') Tj');
ldLastOffset := FLeftOffset;
end;
WriteMSLine(MemoryStream, 'ET');
end;
When the 2nd time this function is called, sometime the FWrappedText is
empty, then it cause the problem.
I make some changes for this procedure to test the 'Empty' situation, the
bug is gone and the PDF file is good as expected.
This discussion has been closed.
Comments
There is a patch available for this bug. Please send an e-mail requesting
this patch to support@digital-metaphors.com and we'll send it right out to
you.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com