Skip to content

Commit

Permalink
adjust the code that adds the "Save Image..." right-click menu item t…
Browse files Browse the repository at this point in the history
…o work with picts too
  • Loading branch information
rfindler committed Jul 17, 2024
1 parent d735688 commit 648f922
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 9 additions & 4 deletions drracket/drracket/private/pict-snip.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@
(inherit set-snipclass)
(set-snipclass snip-class)

(define/public (get-bitmap)
(define bm (make-bitmap (inexact->exact (ceiling w))
(inexact->exact (ceiling h))))
(define dc (send bm make-dc))
(draw dc 0 0 0 0 w h 0 0 #f)
(send dc set-bitmap #f)
bm)

(define/public (convert r d)
(case r
[(png-bytes)
(define bm (make-bitmap (inexact->exact (ceiling w))
(inexact->exact (ceiling h))))
(define dc (send bm make-dc))
(draw dc 0 0 0 0 w h 0 0 #f)
(define bm (get-bitmap))
(define b (open-output-bytes))
(send bm save-file b 'png)
(get-output-bytes b)]
Expand Down
7 changes: 5 additions & 2 deletions drracket/drracket/private/unit.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"parse-logger-args.rkt"
drracket/get-module-path
"named-undefined.rkt"
(prefix-in pict-snip: "pict-snip.rkt")
(prefix-in drracket:arrow: "../arrow.rkt")
(prefix-in icons: images/compile-time)
mred
Expand Down Expand Up @@ -165,7 +166,8 @@
(let ([snip (send text find-snip pos 'after-or-none)])
(when (or (is-a? snip image-snip%)
(is-a? snip image-core:image%)
(is-a? snip cache-image-snip%))
(is-a? snip cache-image-snip%)
(is-a? snip pict-snip:pict-snip%))
(add-sep)
(define (save-image-callback _1 _2)
(define fn
Expand All @@ -178,7 +180,8 @@
[kind
(cond
[(or (is-a? snip image-snip%)
(is-a? snip cache-image-snip%))
(is-a? snip cache-image-snip%)
(is-a? snip pict-snip:pict-snip%))
(send (send snip get-bitmap) save-file fn kind)]
[else
(image-core:save-image-as-bitmap snip fn kind)])]
Expand Down

0 comments on commit 648f922

Please sign in to comment.