I would like to submit a patch that makes the Canvas object capable of exporting not only to Postscript but also to the Tk_Photo format. Using the Tk_Photo format a user will then be able to export canvas images directly to many other different formats and not just Postscript.
Exporting to Postscript is pretty much only usefull on Unix systems. If you work under Windows it can be a bit troublesome to convert Postscript files to the native formats... especially if you want to do this in the background in runtime...
I submitted this idea as a patch a few years ago, but it seams to have gotten 'buried'. It seems the Canvas object still only exports to Postscript, so I think the patch still fills a 'hole'. Hobbs gladly greeted the suggestion back then so I (modestly) imagine that it will still be gladly accepted...
( I submitted the patch as a part of my original feature request: '[923890] saving canvas area as PNG/BMP/GIF')
This patch modifies the file 'generic/tkCanvas.c' and adds a the test-example 'tests/canvGetImgPhoto.tcl'
I tested this patch on Tcl8.5b1/Tk8.5b1. Compiles and works fine.
modifies generic/tkCanvas.c, adds tests/canvGetImgPhoto.tcl
Logged In: YES
user_id=72656
Originator: NO
The key issue here is that as a clear new feature, it does require a TIP to add to the core. The TIP process is discussed here:
http://tip.tcl.tk/
Also, I'm not sure that the patch is actually complete. Is it correct for OS X as well? I would also be tempted to integrate the photo image part into tkCanvPs.c since you pull helper functions from there. I didn't try to compile it, but does it work properly for off-screen stuff? That has classically been a problem to get right across platforms.
Did you know that the Img package already has this functionality as well? I'm not sure it handles all the cases above, but it is there (img::window).
Also, the patch doesn't follow Tcl C coding conventions.
Logged In: YES
user_id=1005553
Originator: YES
Hi Jeffrey,
ok, thanks for the answers
* I admit I didn't know about img::window and there is a clear overlap; but the Img package is an additional package, that has to be installed additionally, right?
* the patch works completely off-screen; one can get a selected region, the visible screen region, the scroll region, the minimal region containing all items or the complete canvas region
* The patch does not use an OS specific calls and essentially the code is based on similar code from other parts of Tk (that are also not OS specific). I am confident that it will work on all OSes.
* I am not acquainted with OS X, but I do have a colleague with an OS X notebook... (so I can ask him to compile...)
* I'll look into the TIP process
* Tcl C coding conventions: most of the code is based on similar code from other parts of Tk... so I guess the problem is actually the placement, i.e. that I put the 'externs', the 'typedef' and the one additional function all right above the main additional function 'GetImagePhoto'. The reason I did that is because these extras are only needed by 'GetImagePhoto' and I though it would be more practical for the maintainers. I will move the 'externs' and 'typedefs' to where they belong. I also found the following documents and will look into them: tcl.tk/doc/engManual.pdf, tcl.tk/doc/styleGuide.pdf .