Page 1 of 1

How to compute text length - e.g. for printing?

Posted: Thu Sep 11, 2008 6:09 am
by mol
I need to compute text length for given font. Can somebody help me?

Re: How to compute text length - e.g. for printing?

Posted: Thu Sep 11, 2008 8:13 am
by Rathinagiri
Yes. Here it is. The returned length is somewhat accurate. :)

It is used in GridPrint. The returned value is in mm.

Code: Select all

function printLen( cString,nFontsize,cFontname)
return round(gettextwidth(Nil,cString,cFontname)*0.072/72*25.4*nFontsize,2)

Re: How to compute text length - e.g. for printing?

Posted: Thu Sep 11, 2008 12:19 pm
by mol
Many thanks :)

Re: How to compute text length - e.g. for printing?

Posted: Thu Sep 11, 2008 12:20 pm
by Rathinagiri
Most welcome.

Re: How to compute text length - e.g. for printing?

Posted: Fri Jul 13, 2012 7:32 am
by mol
Hi everybody!
I need to return to this topic.
The method below computes text length with big margin of error when bold or italic is turned on.
I've added experimental factor = 1.2 for bold font, but, it isn't what I want
Do you know better method?

Regards, Marek

Code: Select all

function printLen( cString,nFontsize,cFontname)
return round(gettextwidth(Nil,cString,cFontname)*0.072/72*25.4*nFontsize,2)
Everything looks ALMOST fine for ARIAL font (too big error with too much capital letters) , but looks very bad with ARIAL NARROW FONT:
Image

I drew lines with length of computed text witdth...