Rendering "X"

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

Rendering "X"

Postby Frigyes » Mon Feb 11, 2013 12:30 pm

Hallo!

I try to calculate the font width with fixed space Fonts like Courier or Consolas,

Code: Select all
   
VpeSetFont(hDoc,"Courier",10); 
VpeRenderPrint(hDoc,0,0,"X");
sobreit  = VpeGet(hDoc, VRENDERWIDTH);
onecharwidth = sobreit;     // onecharwidth 0.231

VpeRenderPrint(hDoc,0,0,"XXXXXXXXXX");
sobreit  = VpeGet(hDoc, VRENDERWIDTH);
onecharwidth  = sobreit / 10;   // onecharwidth 0.2132



should be the one character width not the same in both cases ?

TIA

Regards
Frigyes
Frigyes
 
Posts: 26
Joined: Thu Jun 29, 2006 12:09 pm

Re: Rendering "X"

Postby IDEAL Software Support » Mon Feb 11, 2013 2:16 pm

Versions of VPE prior to VPE v4.x used internally a virtual device with 600 DPI resolution to compute the layout of text and graphics. This rather low resolution was required, because back in 1995 when the first version of VPE was officially released, we had a 16-bit version of VPE, so we needed to avoid numeric overflows for 16-bit integers.

To compensate possible round-off errors for text rendering, our code needed to add a constant value of 0.02cm to the whole width computed for text. This was required, otherwise characters at the end of a line could have been truncated. The same applies to the height of a whole text block.

In 2007 - with the release of VPE v4.0 - we changed the internal virtual device's resolution to 2.540 DPI, which yields much higher precision.

But to keep the rendering - and therefore the computed layout - compatible to old versions, we still do add those constant values. Therefore the width returned by Render() is the width of the characters + 0.02cm, which explains your different results. In practice this doesn't hurt, especially because for proportional fonts you should always compute the whole width of text blocks.
IDEAL Software Support
 
Posts: 1621
Joined: Thu Nov 18, 2004 4:03 pm


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 3 guests