[reportlab-users] How are split, wrap, wrapOn supposed to work?

Robin Becker robin at reportlab.com
Fri Nov 7 12:26:47 EST 2014


On 07/11/2014 13:59, Henning von Bargen wrote:
> A week ago I asked for help regarding split, wrap and wrapOn.
>
> Unfortunately, I have not yet received any reply, that's why I'm asking
> again.
>
> While testing WordAxe, I found the test-case for ImageAndFlowables
> running into an endless loop because the flowable's wrap method
> is called with a negative availWidth argument and the Wordaxe
> implementation
> of a Paragraph obviously fails to handle this situation "in the right
> way".
>
> The question is: What is the right way then?
> What should a flowable do if wrap is called with availWidth <= 0?
> Or is that not supposed to happen at all?

I don't think the frame code is supposed to get into this situation. 
ImageAndFlowables might as it tries to lay out the flowables part itself. Even 
so I think this should not happen for reasonable cases.

Effectively the wrap method of ImageAndFlowables is doing

1) determine the size of the image

2) Subtract the space from the availWidth x availHeight rectangle (at the top 
left or top right). This leaves a narrow bit at the top of the rectangle.

3) Try to determine a split in the list of flowables that can use the narrow 
bit. If that can't be done the narrow bit is supposed to be ignored. If the 
split works then the trailing flowables are wrapped into the bit below the image 
and the total height is determined.

The wrap method of the flowables will be called in several phases of the above. 
If negative widths are passed to the wrap method it probably means the above 
algorithm is doing something silly. However, I believe that negative witdhs just 
mean you can't fit into the available space. I think wrap is supposed to return 
the width it needs. Paragraphs are special in that they are supposed to occupy 
the available width so normally the wrap method will return the availWidth 
value. However, probably there is some minimum width >0 required to lay out the 
para. I don't think wrap is supposed to raise any errors as it is an information 
function.

If you have a simple example where wordaxe fails and our Paragraph class 
succeeds I will try and work out what's happening given the image size etc etc.


> And then, why does reportlab.platypus.paragraph.Paragraph work
> with this test-case, but not wordaxe.rl.NewParagraph.Paragraph,
> while it passes all the other tests?
>
> I guess that only a member of the ReportLab team can answer this.
>
> Henning
.......
-- 
Robin Becker


More information about the reportlab-users mailing list