Textsize Computation

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

Textsize Computation

Postby IDEAL Software Support » Tue Nov 23, 2004 4:31 pm

Hi *,

i print a text with a font size of 42 centered on a page.
But this text is variable, so, if the text would get more
chars as visible, i would use a smaller font.
Is there any function that tells me wich font size i have
to use so that the text would be visible ?

Ecki
IDEAL Software Support
 
Posts: 1621
Joined: Thu Nov 18, 2004 4:03 pm

Postby IDEAL Software Support » Tue Nov 23, 2004 4:32 pm

Hi,

This is rather easy if you have VPE 3.2 (perhaps also in earlier
versions): you can use the VpeRenderWrite / VpeRenderPrint functions.
These functions return the coordinates as VpeWrite / VpePrint do, except
they do not actually output anything.

Based upon the coordinates VpeRender returns, you can pick a
smaller/larger font. Works great for us.


Patrick Elsen
IDEAL Software Support
 
Posts: 1621
Joined: Thu Nov 18, 2004 4:03 pm

Postby IDEAL Software Support » Tue Nov 23, 2004 4:35 pm

Patrick is correct.

Let me add that you could for example use RenderWrite(0, 0, 100000, VFREE, "<your text>").

Afterwards you can check whether the text did fit into your required width (and height).

You could use a binary search algorithm over the font size to find the best maximum.

Regards
Thorsten Radde
IDEAL Software GmbH
IDEAL Software Support
 
Posts: 1621
Joined: Thu Nov 18, 2004 4:03 pm

Postby MHjerpe » Wed Feb 09, 2005 11:13 am

IDEAL Software Support wrote:Patrick is correct.

You could use a binary search algorithm over the font size to find the best maximum.

Regards
Thorsten Radde
IDEAL Software GmbH


Nice a Fourm... did't know about until now..

Can you explain the binary search algorithm to get the maximum ?
We loop and test until it fits.. ( kind of slow way )
Start with a to big font and tries until it's small enough

//Mikael H
MHjerpe
 
Posts: 9
Joined: Wed Feb 09, 2005 11:03 am
Location: Sweden

Postby IDEAL Software Support » Wed Feb 09, 2005 3:12 pm

"Binary search" is a standard algorithm, you can read about in many books or also in the internet.

For finding a matching font, the algorithm must be modified to turn over to linear search after an approximation has bee made. This is necessary, because it is unlikely that an *exact* matching font size will be found, i.e. it will be a maximum font size, which makes the given text fit into the given rectangle. For this reason the search must be done with a tolerance factor. If the search result is within the tolerance range, turn over to linear search.

Regards
Thorsten Radde
IDEAL Software GmbH
IDEAL Software Support
 
Posts: 1621
Joined: Thu Nov 18, 2004 4:03 pm

Postby MHjerpe » Wed Feb 09, 2005 3:24 pm

Ok :) got it.. should use that insted of linear as we have now.
Thanks.
MHjerpe
 
Posts: 9
Joined: Wed Feb 09, 2005 11:03 am
Location: Sweden


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 51 guests