[racket] Why does drawing to pdf require a scaling factor of 1.25?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Jan 8 17:48:21 EST 2014

Instantiating `pdf-dc%` gets some configuration from
`(current-ps-setup)`, and the default values of that parameter is a
`ps-setup%` that has a scaling factor 0.8.

Instead of scaling the drawing, you could install a `ps-setup%` with a
scaling factor of 1.0 while instantiating `pdf-dc%`.

At Thu, 9 Jan 2014 09:34:40 +1100, Daniel Prager wrote:
> I found empirically that when I save a image to pdf I need to scale it by
> 1.25.
> 
> Code below.
> 
> Why?  Is there a setting I should use instead?
> 
> 
> Thanks
> 
> Dan
> 
> 
> #lang racket
> 
> (provide image->pdf)
> 
> (require racket/draw
>          (only-in 2htdp/image
>                   save-image
>                   image-width
>                   image-height
>                   scale
>                   ))
> 
> (define (image->bitmap image)
>   (let* ([width (image-width image)]
>          [height (image-height image)]
>          [bm (make-bitmap width height)]
>          [dc (send bm make-dc)])
>     (send dc clear)
>     (send image draw dc 0 0 0 0 width height 0 0 #f)
>     bm))
> 
> (define (image->pdf image output-file)
>   (define dc
>     (new pdf-dc%
>          [ interactive #f ]
>          [ use-paper-bbox #f ]
>          [ width (image-width image)]
>          [ height (image-height image)]
>          [ output output-file ]))
> 
>   (send* dc
>     (start-doc "useless string")
>     (start-page))
> 
>   (send dc draw-bitmap (image->bitmap (scale 1.25 image)) 0 0)
> 
>   (send* dc
>     (end-page)
>     (end-doc)))
> 
> (module+ test
>   (require (only-in 2htdp/image
>                     circle text square overlay above))
> 
>   (define im
>     (overlay
>      (above
>       (circle 50 'solid 'red)
>       (text "This is a red circle" 12 'black))
>      (square 150 'solid 'lightblue)))
> 
>   (image->pdf im "image-test.pdf")
>   (save-image im "image-test.png"))
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.