Rendering text problem

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

Rendering text problem

Postby wooldy » Sun May 15, 2011 12:46 am

IDE: Delphi 2010, VPE: 6.10
I think, there is a problem rendering plain text with RenderPrint(). Calculating the height of a line with a given font with i.e. RenderPrint(0,0,'X') returns a wrong value.
Example:
SetFont('Arial', 11);
RenderPrint(0,0,'X');
hLine := nRenderHeight;
Write(x1, y1, x2, VFREE, SomeLongerPlainText); //in my case 23 Lines in the Preview
hText := nBottom - y1;
nLInes := hText / hLine;
In my case the result for nLines is 22.043..., the preview shows 23 lines.
I found, that the real line height is 0.4407..., the value of nRenderHeight returns 0.45992.
I need manual calculation to avoid single lines of a paragraph a the bottom or top of a page.
How can I calculate the lines count? In version 3.x this was very easy and returned exact values.
wooldy
 
Posts: 2
Joined: Thu Mar 04, 2010 4:40 pm

Re: Rendering text problem

Postby IDEAL Software Support » Mon May 16, 2011 8:49 am

The following is an explanation of VPE's text rendering code:

After rendering a chunk of text, be it a single line or multiple lines, VPE adds 0.02 cm to the result in order to fix round-off problems. This is required, because the preview uses a clipping rectangle when drawing text. This clipping rectangle has the exact dimensions of the rendered text. Internally, the text rendering code is also executed, if Write() with a VFREE coordinate or Print() is used.

Exactly the same code was in v3.x (at least v3.60 and higher).

In order to compute the height of a text object with multiple lines (without a frame), use the following code (assuming Centimeter units):

Code: Select all
LineHeight = RenderPrint(0, 0, "X") - 0.02
TotalHeight = NumberOfTextLines * LineHeight + 0.02


VPE's internal text rendering code might change in a future release, so the above code might not work (but this is rather unlikely).

If you want to be on the "safe side", and you have multiple lines of text in a single text object, we recommend you always render exactly the text you wish to output.
IDEAL Software Support
 
Posts: 1622
Joined: Thu Nov 18, 2004 4:03 pm

Re: Rendering text problem

Postby wooldy » Tue May 17, 2011 4:45 am

Thanks for your explanation.
wooldy
 
Posts: 2
Joined: Thu Mar 04, 2010 4:40 pm


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 62 guests