[reportlab-users] canvas inside canvas?

Oliver Bleutgen reportlab-users@reportlab.com
Thu, 18 Sep 2003 10:50:34 +0200


Robin Becker wrote:

> In article <3F68A08B.1000602@gmx.net>, Oliver Bleutgen <myzope@gmx.net>
> writes
> 
>>Hi all,
>>
>>I have a canvas which contains several fixed sized areas, in which my 
>>application adds images (via canvas.drawImage(...)). Now I want to 
>>extend that to canvas-like objects, i.e. something like
>>
>>canv =  canv.Canvas(filename, pagesize=(1000,1000))
>>subcanv1 = canv.Canvas('dummy.pdf', pagesize=(500,500))
>>subcanv1.lines( ... ) # draw some lines
>>subcanv1.drawImage( ... ) # draw an image
>># this doesn't exist:
>>canv.drawCanvas(subcanv1, 0,0,500,500)
>>
>>Any tricks how to do something like that? Perhaps by mucking around with 
>>subcanv1._code?
>>
>>Or would the graphics.Drawing class be the thing to look at?
>>It seems to be able to hold Bitmap Images, though this is undocumented.
>>
>>Thanks for the great product, btw.
>>
>>cheers,
>>oliver
> 
> you need canvas forms. I think these are in canvas.py
> 
>         see methods beginForm, endForm, doForm.

Thanks for the answer Robin, and as I see it, Forms would exactly solve 
the problem I described with the code, but I fear that I should have 
written some more pseudocode:

canv =  canv.Canvas(filename, pagesize=(1000,1000))
subcanv1 = canv.Canvas('dummy.pdf', pagesize=(500,500))
subcanv1.lines( ... ) # draw some lines
subcanv1.drawImage( ... ) # draw an image
# this doesn't exist:
canv.drawCanvas(subcanv1, 0,0,500,500)
# plot the same "subcanvas somewhere else ...
canv.drawCanvas(subcanv1, 0,500,500,1000)
# let's change subcanv1 somewhat
subcanv1.lines(...) # some more lines to subcanv1
canv.drawCanvas(subcanv1,500,500,1000,1000)

That's not possible with Forms, right?

So, wouldn't the Drawing class be the way to go, with the (undocumented, 
but existing) feature that it can also contain bitmaps?

cheers,
oliver