FW: [reportlab-users] Working out height of text

Ian Sparks reportlab-users@reportlab.com
Fri, 11 Apr 2003 09:26:32 -0400


Good points Fran=E7ois,

This should probably go in the docs somewhere and/or this function added =
to the library.

- Ian.

-----Original Message-----
From: Fran=E7ois Heredero - Top Music SA [mailto:fheredero@topmusic.ch]
Sent: Friday, April 11, 2003 9:24 AM
To: Ian Sparks
Subject: RE: [reportlab-users] Working out height of text


> Ah..thanks Fran=E7ois. I managed to fix my real program but the
> test program was puzzling me - thanks for debugging it for me!

Your welcome :-)

Another thing, face.descent returns a negative float with integrated =
fonts,
and positive float with ttf fonts... so, you can calculate the height =
with :

>>> height =3D ascent + abs(descent)

or make a function:

>>>def fontHeight(fontName, fontSize):
>>>	face =3D pdfmetrics.getFont(fontName).face
>>>	size =3D fontSize / 1000.0
>>>	ascent, descent =3D face.ascent * size, abs(face.descent * size)
>>>	return ascent+descent, (ascent, descent)

Fran=E7ois