[reportlab-users] Experimenting with new paragraphs, splitting issue

Robin Becker robin at reportlab.com
Thu Nov 29 13:20:45 EST 2007


Dinu Gherman wrote:

> Hi,

>

> I've experimented quite a bit with several variants of a new really

> simple Paragraph class. It mostly works as desired, at least as long

> as I used my own faked frames together with the drawOn method. As soon

> as I'm using my paragraphs inside a propperly set document template,

> I get a strange behaviour when it comes to splitting. It's basically

> an issue with creating and returning two pieces of a paragraph.

>

> The RL Userguide contains exactly one paragraph about splitting, some-

> thing I take as ironic, since it might also benefit from splitting into

> some more. In fact, I have never seen an official example with code

> on how to really write one's own wrappable/splittable flowable. So,

> I'd be glad to contribute my code if somebody can remove a bit of the

> magic behind the scenes.

>

> I attach an archive with the most minimal implementation I could come

> up with. The code includes a sample text and is very easy to play with.

> I'd be very glad if maybe Robin can have a look.

>

> Regards,

>

> Dinu

>

......

the splitting protocol is supposed to work as follows.

Given space W x X in which to fit W and a flowable f

1) f.split(W,H) should return a list.
2) if the list is empty then f refuses to split into that space.
3) if the list is non-empty then the first element should be a flowable that is
guaranteed to be wrappable into the available space ie f.wrap(W,H) <= (W,H) (<=
means fits into).
4) any other elements of the returned list should be flowables. What they
contain is entirely the responsibility of the called split method.

In the platypus doctemplate framework the frame acts as container and calls the
wrap and split methods of the flowable f. The frame is supposed to take care of
the space appropriately. The danger here is that f.wrap(W,H) --> w0,h0 is too
large, but errors cause f0 = f.split(W,H)[0] to be such that f0.wrap(W,H)
doesn't fit in the W,H box. The frame usually applies fuzz so arithmetic errors
won't cause problems. However, we rely on the flowables being honest.
--
Robin Becker


More information about the reportlab-users mailing list