#1 2010-10-15 11:29:45

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

getting text width

I'm having trouble with this line:

e := pdfDoc.Canvas.TextWidth('some text');

It always returns 0 but doesn't give any errors.

Any ideas on where it could be going wrong?

Thanks,
Esmond

Offline

#2 2010-10-15 11:49:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: getting text width

Is the font set?

What do you get using step by step debugger.

Offline

#3 2010-10-15 12:24:36

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: getting text width

Just did a test program (was using cgi so hard to debug). The problem seemed to be HorizontalScaling was being initialised to zero. Setting this to 100 solved it. Could this property be initialised to 100 in TPdfPage, to save having to set it each time?

Thanks

Offline

#4 2010-10-15 14:07:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: getting text width

I don't understand, normaly the 0 value inside this property will just ignore it:

See TPdfPage.TextWidth code:

    tmpWidth := FFont.GetAnsiCharWidth(Text, i) * FFontSize / 1000;
    if (FHorizontalScaling <> 0) and (FHorizontalScaling <> 100) then
      tmpWidth := tmpWidth * FHorizontalScaling / 100;

What's appending here?

Offline

#5 2010-10-15 16:14:28

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: getting text width

Looks like my source code was out of date. It went:

tmpWidth := FFont.GetAnsiCharWidth(Text, i) * FFontSize / 1000;
    if FHorizontalScaling <> 100 then
      tmpWidth := tmpWidth * FHorizontalScaling / 100;

Thanks for putting in createJpegDirect.

All working well

Offline

Board footer

Powered by FluxBB