[reportlab-users] KeepInFrame.drawOn() working?

Dinu Gherman gherman at darwin.in-berlin.de
Fri Sep 29 19:28:29 EDT 2006


Hi,

I'm trying to code a slightly more complex layout algorithm,
which uses multiple columns, but can have single flowables
spanning more than one column.

Being unsure if Platypus is able to handle that with frames,
I thought of writing my own flowable placer. But some initial
experiments show, that either KeepInFrame.drawOn() does not
work as I expect or it has not been conceived or tested the
way I'd like it to behave.

In the sample code below I draw a larger rectangle in which I'm
trying to place a simple XBox flowable inside a KeepInFrame.
So far I could find only the "truncate" mode to be working as
expected, but not "shrink/error". And "overflow" behaves like
expected, but I'm not sure it is doing so on purpose.

Also, I would expect the XBox to be placed at the bottom of the
outer rectangle, not in the upper, BTW.

So my question is if the code below should be also working for
"shrink/error"?

Thanks,

Dinu



#!/usr/bin/env python

from reportlab.lib.units import mm
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus.flowables import KeepInFrame, XBox

canv = Canvas("sample.pdf", pagesize=A4)
x, y, w, h = 10*mm, 10*mm, 100*mm, 50*mm
canv.rect(x, y, w, h)

box = XBox(w + 20*mm, 10*mm, "XBox")
# in next line only "truncate" seems to work as expected
border = KeepInFrame(w, h, box, mode="shrink")

# the following three lines are needed to avoid
# AttributeErrors in KeepInFrame
border.width = w
border.height = h
border._content = [box]

border.drawOn(canv, x, y)

canv.showPage()
canv.save()



More information about the reportlab-users mailing list