VPE 7 TVPETextBlock alignment issue

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

VPE 7 TVPETextBlock alignment issue

Postby Brent Rose » Fri Jul 18, 2014 10:34 am

Hi

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;

Brent Rose
 
Posts: 50
Joined: Wed Mar 21, 2012 8:13 pm

Re: VPE 7 TVPETextBlock alignment issue

Postby IDEAL Software Support » Mon Jul 21, 2014 8:23 am

Thanks for your bug report. We will fix this in the current beta version.
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm

Re: VPE 7 TVPETextBlock alignment issue

Postby IDEAL Software Support » Mon Jul 21, 2014 10:09 am

BTW it shouldn't be necessary to write the coordinates with trailing ".0".

I.e. VpeLine(hDoc, 8.0, 2.0, 8.0, 20.0);

can be written as VpeLine(hDoc, 8, 2, 8, 20);

I don't know the Pascal compiler well, but any C/C++ compiler translates the numeric constants into double values at compile-time.
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm

Re: VPE 7 TVPETextBlock alignment issue

Postby Brent Rose » Mon Jul 21, 2014 12:14 pm

Yes - I am aware that the ".0" is redundant in this case. This is just a wee habit I have when writing code :?

There are other cases, of course, where omitting the "redundant" decimal precision will cause the compiler to interpret the value as an integer, and result in a "wrong" computation... (ie you really do need to elevate the integer to a decimal).
Brent Rose
 
Posts: 50
Joined: Wed Mar 21, 2012 8:13 pm


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 12 guests

cron