[reportlab-users] Several questions about text output

Robin Becker robin at reportlab.com
Mon Jul 14 18:59:51 EDT 2008

Grzegorz Adam Hankiewicz wrote:


> El 13/07/2008, a las 22:48, Grzegorz Adam Hankiewicz escribió:


>> On the font issue, how can I clip the text to a region? Let's say that

>> I have a text too long to fit and don't want it to go out of the page.

>> Is this done with the paths?


> I found the answer at

> http://two.pairlist.net/pipermail/reportlab-users/2005-February/003717.html.

> However, now I am having a problem calculating the bounding box of a font.


> When I draw a text string at 0,0, letters like 'g' or 'j' descend below

> the 0 y coordinate into negative numbers. I know the font size, but I

> don't know how much do I have to displace my bounding box in order to

> not have the lower part of the letters being clipped.


> In the reference manual I found the word "baseline" ppear in the setRise

> documentation, but that doesn't help me. Any suggestions?


if you use String objects from the graphics library you can see the
bounding boxes with getBounds, but as in the canvas we use the old
standards from Gutenberg etc etc.

When we draw a string the x coord is the start of the first character,
but the y coord always refers to the baseline of the font. Typically in
western glyphs that's the same as the bottom of cap A. That being the
case then always stuff like y/j descends below. In recent reportlab you
can do this

ascent,descent = getAscentDescent(fontName,fontSize)

if you don't specify fontSize then 1000 is assumed.

This will return the values for the ascent and descent of the font from
the baseline. So for fontSize x your string box will be


hope this isn't too arcane
Robin Becker

More information about the reportlab-users mailing list