Open spdegabrielle opened 2 years ago
What is the best way to save a pict to a file?
I normally use pict->bitmap
and save the bitmap to a png file source:
(define (save-pict fn p [kind 'png])
(define bm (pict->bitmap p))
(send bm save-file fn 'png))
But the quality isn't good enough to use in a paper. Scribble does a better job when it converts picts to pdfs in a document.
For picts in papers I use this code to generate encapsulated PostScript files (modified from metapict):
(define (save-pict-eps path pict)
(define ps-setup (new ps-setup%))
(send ps-setup copy-from (current-ps-setup))
(send ps-setup set-file path)
(send ps-setup set-margin 0 0)
(send ps-setup set-scaling 1 1)
(send ps-setup set-translation 0 0)
(send ps-setup set-editor-margin 0 0)
(define dc
(parameterize ([current-ps-setup ps-setup])
(new post-script-dc%
[width (pict-width pict)]
[height (pict-height pict)]
[interactive #f]
[parent #f]
[use-paper-bbox #f]
[as-eps #t]
[output path])))
(send dc set-smoothing 'smoothed)
(send dc start-doc "")
(send dc start-page)
(draw-pict pict dc 0 0)
(send dc end-page)
(send dc end-doc))
Some journals (including JFP) request illustrations in EPS instead of PDF.
EDIT: Update with Robby's suggestion.
Nice! (Probably a good idea to make a new ps-setup object (copying it from current-ps-setup
and using parameterize to install it) if this gets turned into a library.)
It is one of those questions that comes up periodically and I'll do this soon