in reply to Dumping Tk canvas to postscript

The defaults for -height and -width are the full hw size of the canvas widget so you should just be able to:

my $ps = $canvas->postscript( '-pagewidth' => "8 i" );

and it will x:y symetrical scale to give a result 8 inches wide and X high. I presume you have tried this? The bbox (bounding box) co-ords are noted in the docs to be *approximate* ie (Returns a list with four elements giving an approximate bounding box for all the items named by the tagOrId arguments) which appears to be what you are seeing.

cheers

tachyon

Replies are listed 'Best First'.
Re: Re: Dumping Tk canvas to postscript
by TooNewbie (Acolyte) on Mar 15, 2004 at 14:25 UTC
    Hey there hmmm sorry but I think I've mislead you a bit. The canvas is a scrolled canvas:
    $c = $main_window -> Scrolled("Canvas")-> pack(); $canvas = $c->Subwidget("canvas");
    What you suggested works great for printing out the visible portion but I want to print out the whole canvas (all the objects) hence the bbox.
    Any ideas?

    Thanks,
    toonewbie
      I think this bit from the Tk::Canvas documentation:
      Note: by default Postscript is only generated for information that appears in the canvas's window on the screen.
      may be interpreted that only the visible part could be dumped.
        hmmm. I have actually generated ps files for the whole scrolled region, did a ps2png conversion and plotted them out just fine. It's when I actually specify the pagewidth or pageheight to be something that I could printout on a printer I get a portion of the diagram clipped.

        Actually the problem seems to be related to moving the objects on the canvas. The ps generated seems to be of the original area where the objects were created. If I move the objects from their start point a portion of the diagram gets clipped. I was starting suspect the bbox but I use it to set my scroll region and it seams to be capturing the bounding area correctly and updates correctly as I move objects around. The width and height values calculated from bbox are correct as well. postscript just does not seem to notice that the top&left edge have changed. The more I move stuff the worse the clipping gets. I tried to compensate by specifying top&left with the -x&-y using the first two values from bbox. This helped to lock the diagram in place but there is still some small amount of clipping occassionally. This I have found out is just a problem with my ps viewer. For some reason it does not recognise the ps as letter size. If I force it to respect letter then all is good.

        So it looks like a combination of issues:
        1. postscript can't seem to track the top&left edge but this can be compensated for with -x&-y settings.
        2. my ps viewer does not recognise the ps file as letter size.

        I've added a program to my scratch pad that lets you experiment with this problem. You can move the middle box all over and print out the canvas. if you comment out the -x,-y parameters in the print sub you will see the clipping issue.

        Thanks to all for your help!