diff --git a/collects/racket/draw/private/bitmap-dc.rkt b/collects/racket/draw/private/bitmap-dc.rkt index 2758407159..6364a69387 100644 --- a/collects/racket/draw/private/bitmap-dc.rkt +++ b/collects/racket/draw/private/bitmap-dc.rkt @@ -82,7 +82,10 @@ (inherit draw-bitmap-section internal-set-bitmap internal-get-bitmap - get-size) + get-size + get-transformation + set-transformation + scale) (super-new) @@ -131,13 +134,20 @@ (def/public (draw-bitmap-section-smooth [bitmap% src] [real? dest-x] [real? dest-y] + [nonnegative-real? dest-w] + [nonnegative-real? dest-h] [real? src-x] [real? src-y] - [real? src-w] - [real? src-h] + [nonnegative-real? src-w] + [nonnegative-real? src-h] [(symbol-in solid opaque xor) [style 'solid]] [(make-or-false color%) [color black]] [(make-or-false bitmap%) [mask #f]]) - (draw-bitmap-section src dest-x dest-y src-x src-y src-w src-h style color mask)))) + (let ([sx (if (zero? src-w) 1.0 (/ dest-w src-w))] + [sy (if (zero? src-h) 1.0 (/ dest-h src-h))]) + (let ([t (get-transformation)]) + (scale sx sy) + (draw-bitmap-section src (/ dest-x sx) (/ dest-y sy) src-x src-y src-w src-h style color mask) + (set-transformation t)))))) (install-bitmap-dc-class! bitmap-dc%) diff --git a/collects/racket/draw/private/dc.rkt b/collects/racket/draw/private/dc.rkt index 9a33b84cd9..320d880818 100644 --- a/collects/racket/draw/private/dc.rkt +++ b/collects/racket/draw/private/dc.rkt @@ -1450,8 +1450,8 @@ [real? dest-y] [real? src-x] [real? src-y] - [real? src-w] - [real? src-h] + [nonnegative-real? src-w] + [nonnegative-real? src-h] [(symbol-in solid opaque xor) [style 'solid]] [(make-or-false color%) [color black]] [(make-or-false bitmap%) [mask #f]]) diff --git a/collects/scribblings/draw/bitmap-dc-class.scrbl b/collects/scribblings/draw/bitmap-dc-class.scrbl index ac591d7c98..4200395217 100644 --- a/collects/scribblings/draw/bitmap-dc-class.scrbl +++ b/collects/scribblings/draw/bitmap-dc-class.scrbl @@ -39,10 +39,14 @@ Creates a new memory DC. If @scheme[bitmap] is not @scheme[#f], it is [mask (or/c (is-a?/c bitmap%) false/c)]) boolean?]{ -The same as @method[dc<%> draw-bitmap-section]. In older version, this - method smoothed drawing more than @method[dc<%> draw-bitmap-section], but - smoothing is now provided by @method[dc<%> draw-bitmap-section]. +The same as @method[dc<%> draw-bitmap-section], except that + @racket[dest-width] and @racket[dest-height] cause the DC's + transformation to be adjusted while drawing the bitmap so + that the bitmap is scaled. +In older versions, this method smoothed drawing more than + @method[dc<%> draw-bitmap-section], but smoothing is now provided by + @method[dc<%> draw-bitmap-section]. } @defmethod[(get-argb-pixels [x real?] diff --git a/collects/tests/gracket/dc.rktl b/collects/tests/gracket/dc.rktl index 5e7d0f6f78..afce8bc4c5 100644 --- a/collects/tests/gracket/dc.rktl +++ b/collects/tests/gracket/dc.rktl @@ -194,6 +194,27 @@ #"\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0"))) (test #t 'same-bits (equal? bs bs2))) +;; ---------------------------------------- +;; Test draw-bitmap-section-smooth + +(let* ([bm (make-bitmap 100 100)] + [dc (make-object bitmap-dc% bm)] + [bm2 (make-bitmap 70 70)] + [dc2 (make-object bitmap-dc% bm2)] + [bm3 (make-bitmap 70 70)] + [dc3 (make-object bitmap-dc% bm3)]) + (send dc draw-ellipse 0 0 100 100) + (send dc2 draw-bitmap-section-smooth bm + 10 10 50 50 + 0 0 100 100) + (send dc3 scale 0.5 0.5) + (send dc3 draw-bitmap bm 20 20) + (let ([s2 (make-bytes (* 4 70 70))] + [s3 (make-bytes (* 4 70 70))]) + (send bm2 get-argb-pixels 0 0 70 70 s2) + (send bm3 get-argb-pixels 0 0 70 70 s3) + (test #t 'same-scaled (equal? s2 s3)))) + ;; ---------------------------------------- (report-errs)