There is an issue with right aligned text in TVPETextBlock. It appears that when WriteTextBlock is used to print line-by-line, whitespace is not being trimmed from the end of the lines, so they do not align correctly.
The code below demonstrates the problem by printing the same text 3 times: A direct print using "Write" (first) and then using TVPETextBlock WriteTextBlock to output the text as a single block (second) both give the same correctly right-aligned result. However, if WriteTextBlock is used to output line-by-line instead, trailing whitespce throws the alignment out.
Using the same code with ALIGN_CENTER instead, it would appear that the same issue affects centred text as well.
- Code: Select all
procedure TForm8.Button2Click(Sender: TObject);
const
SampleText = (
'Due to the free positioning of objects by program code, ' +
'VPE is not just a report generator or a static PDF Library, ' +
'but a report engine to create dynamically any type of complex document, ' +
'for example reports, forms, documents, diagrams, labels, etc. ' +
'Your applications and projects have practically no limits.');
var
AVPETextBlock: TVPETextBlock;
i: Integer;
ATop, ALineHeight: Double;
begin
with VPEngine1 do
begin
OpenDoc;
//direct Write
TextAlignment := ALIGN_RIGHT;
Write(2.0, 2.0, 8.0, VFREE, SampleText);
//using TextBlock as one block
AVPETextBlock := CreateTextBlock(SampleText);
try
AVPETextBlock.Width := 6.0;
WriteTextBlock(AVPETextBlock, 2.0, 7.0, AVPETextBlock.LineCount);
finally
AVPETextBlock.Delete;
end;
//using TextBlock line-by-line
RenderWrite(0.0, 0.0, 1.0, VFREE, 'X');
ALineHeight := nRenderHeight;
AVPETextBlock := CreateTextBlock(SampleText);
ATop := 12.0;
try
AVPETextBlock.Width := 6.0;
for i := 1 to AVPETextBlock.LineCount do
begin
WriteTextBlock(AVPETextBlock, 2.0, ATop, 1);
ATop := (ATop + ALineHeight);
end;
finally
AVPETextBlock.Delete;
end;
Line(8.0, 2.0, 8.0, 20.0);
Preview;
end;
end;