[reportlab-users] question re: paragraph bounding box vertical offset

Chris Jerdonek chris.jerdonek at gmail.com
Tue Aug 31 20:24:22 EDT 2010

> Date: Tue, 31 Aug 2010 13:58:01 +0100

> From: Matt Folwell <mjf at pearson.co.uk>


>> On Sun, Aug 29, 2010 at 10:59 AM, Chris Jerdonek

>> <chris.jerdonek at gmail.com> wrote:

>>> I've been doing some experiments, and it seems like a paragraph's

>>> bounding box is never flush with the text it contains.  It seems like

>>> the box is usually offset upwards a distance equal to a bit more than

>>> a third of the "leading" for lines in the paragraph (e.g. when the

>>> paragraph style has autoLeading='min').


> If you don't use autoLeading, the height of the paragraphs's bounding

> box is equal to <leading> * <number of lines>, and the position of the

> first line's baseline is <fontsize> below the top of the box. Subsequent

> lines have their baseline <leading> below the previous line's.


> I think in this case, where you don't have multiple fonts or sizes in

> the same paragraph, the effect of autoLeading='min' is just to read the

> font metrics and set the leading to <ascent>-<descent>, which is the

> maximum height of the actual text.


> Setting paraFontSizeHeightOffset = 0 changes the position of the first

> line's baseline to be <ascent> below the top of the bounding box.  The

> disadvantage of this is if you have a table containing both strings and

> paragraphs, the text won't line up nicely.

Thanks for the response, Matt.

Can you elaborate on the disadvantage of setting paraFontSizeHeightOffset = 0?

The default of setting it to 1 seems to have its own disadvantage:

For example, if you create a table with a single cell that contains a
Paragraph with one line of text, the paragraph text can protrude past
the bottom border of the table cell (even with positive border
padding). This is because of the observations above and the fact that
a table cell seems to care only about bounding a paragraph's bounding
box and not its text. Setting it to 0 ensures that the paragraph text
stays inside the paragraph's bounding box -- and so inside any
containing table cell.


More information about the reportlab-users mailing list