[reportlab-users] Paragraph vertical offset?
Tim Roberts
timr at probo.com
Thu Jan 10 12:51:33 EST 2013
Buganini wrote:
> Hi, I'm tring to use paragraph with border:
> ...
> but it appears to have some weird vertical offset, I've checked "class
> ParaBox2" in rl_doc_utils.py, there is nothing special but some
> hardcoded calculation (*10.0/9.0 *0.95), even if I apply those
> calculation, there is still incorrect offset.
>
> Could someone give me an idea?
The problem here seems to be that you are tweaking the font size without
adjusting the leading. It's the leading that determines the interline
spacing. So, even though you start out setting a font size of 100
points, you are doing all of your formatting with a leading of 12. If
you actually printed your text at 100 points, you'd find the lines
almost entirely overlap each other.
Try doing this:
while w>mw or h>mh:
style.fontSize -= 0.5
style.leading = style.fontSize + 2
...
That looks pretty good for me.
> BTW, is there a way to tell paragraph to keep original linebreaks?
The whole purpose of the Paragraph flowable is to allow your text to be
reformatted as needed. If you need a new paragraph, then you create
another Paragraph flowable. If you really need a line break, just
insert a <br/> tag.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list