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

Matt Folwell mjf at pearson.co.uk
Tue Aug 31 08:58:01 EDT 2010


On 30/08/2010 17:20, Chris Jerdonek wrote:

> 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').

>

> A bit more info on this:

>

> For fontSize = 24, it seems that setting borderPadding = (-7.5, 0,

> 7.5, 0) makes the paragraph text flush with its bounding box. I don't

> know the significance of 7.5 relative to 24.

>

> After digging into the code, I also found that changing

> paraFontSizeHeightOffset in rl_config.py from its default of 1 to 0

> makes the text flush. So I guess that is the right solution. I can't

> explain the default behavior though.



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.

Matt


More information about the reportlab-users mailing list