[reportlab-users] Nested Flowables?

Kevin D Smith Kevin.Smith at sixquickrun.com
Thu Jan 7 11:43:36 EST 2010


On Jan 7, 2010, at 10:16 AM, Robin Becker wrote:


> On 07/01/2010 15:50, Kevin D Smith wrote:

>> I did find out part of my problem. My outer flowable was being drawn, then the next one was drawn above it which happened to be above the page. So I'm trying to figure out how to get the placement of the nested flowables correct. I can't quite follow what's going on with them right now because they go off the page. I've tried doing translates after each nested flowable to put the cursor back into the correct place, but that doesn't seem to be working reliably for me. Is there a way to get the absolute position of the cursor on the canvas? I think if I could get that value it might help me figure out what's going on.

>>

>>

>> On Jan 6, 2010, at 10:21 AM, Kevin D Smith wrote:

>>

>>> I'm working on a renderer that needs to handle nested flowables. I essentially want to be able to render something equivalent to the following:

>>>

>>> <div>

>>> <div>

>>> <span>text</span>

>>> <div>

>>> <span>more text</span>

>>> </div>

>>> </div>

>>> </div>

>>>

>>> where each div can have its own borders and padding and can break across a page. I've got the page breaking worked out, but drawing on the page is giving me some trouble. I'm not exactly sure where I am on the page when I start drawing. I did some random translations just to get something on the page and I found out that I needed to translate by -380 vertically to get my content in the right place. I also had trouble drawing each piece within a nested div. I'm trying to figure out where I left off on the previously drawn div, but it isn't working as well as I had hoped. If someone can enlighten me on what might be going wrong, I'd appreciate it.

>>>

>>> Kevin D Smith

>>> Kevin.Smith at sixquickrun.com

> .........

> well without knowing what you mean by renderer it's hard to answer your questions. You can draw flowables directly to a canvas or use the doctemplate/frames framework. Which approach or style are you using?

>

> One thing that confuses people is that although flowables are supposed to flow down their frames they are actually drawn bottom up like all objects that get drawn to the canvas (in which 0,0 is at the bottom left corner). Obviously frames have to take account of this so they find the width/height first and then adjust the drawing position based on that and the internal height from the top of the frame represented by how much has been place therein already.

> --

> Robin Becker



I'm kind of taking a hybrid approach. I'm using the overall template/frames framework to do the page breaking and page layouts, but I draw my flowables directly to the canvas in the draw method. In a way, my flowables are acting both as flowables and frames. Because my flowables are nested, they get layered on top of each other when drawn; that's where my problem occurs. I'm trying to set the correct position for the inner flowables after drawing the outer flowables, but I just get bizarre behavior when I do that. I do realize that they get drawn from the bottom up and have taken that into consideration. If I could know the absolute position (x,y) on the page where I'm starting each of the flowables I might be able to figure out where my error is. Right now it just seems kind of random to me, but I realize that I'm doing something out of the ordinary for the template/frames paradigm.

Kevin D Smith
Kevin.Smith at sixquickrun.com





More information about the reportlab-users mailing list