Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add instruction for saving pict to a file to Misc docs #74

Open
spdegabrielle opened this issue Feb 23, 2022 · 3 comments
Open

add instruction for saving pict to a file to Misc docs #74

spdegabrielle opened this issue Feb 23, 2022 · 3 comments
Assignees

Comments

@spdegabrielle
Copy link
Member

It is one of those questions that comes up periodically and I'll do this soon

@spdegabrielle spdegabrielle self-assigned this Feb 23, 2022
@bennn
Copy link
Contributor

bennn commented Oct 2, 2022

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.

@camoy
Copy link
Contributor

camoy commented Oct 2, 2022

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.

@rfindler
Copy link
Member

rfindler commented Oct 2, 2022

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants