add scale-to-fit to slideshow/pict

This commit is contained in:
Robby Findler 2012-08-22 22:03:49 -05:00
parent f40277df89
commit 7647e94eee
2 changed files with 22 additions and 0 deletions

View File

@ -543,6 +543,18 @@ Scales a pict drawing, as well as its @tech{bounding box}. The drawing
is scaled by adjusting the destination @racket[dc<%>]'s scale while is scaled by adjusting the destination @racket[dc<%>]'s scale while
drawing the original @racket[pict].} drawing the original @racket[pict].}
@defproc*[([(scale-to-fit [pict pict?] [size-pict pict?]) pict?]
[(scale-to-fit [pict pict?] [width real?] [height real?]) pict?])]{
Scales @racket[pict] so that it fits within the bounding box of
@racket[size-pict] (if two arguments are supplied) or
into a box of size @racket[width] by @racket[height]
(if three arguments are supplied).
The aspect ratio of the pict is preserved, so the resulting pict
will have either the width or the height of the @racket[size-pict]
(or @racket[width] by @racket[height] box), but not necessarily
both.
}
@defproc[(rotate [pict pict?] [theta real?]) pict?]{ @defproc[(rotate [pict pict?] [theta real?]) pict?]{

View File

@ -71,6 +71,8 @@
(provide/contract (provide/contract
[scale (case-> (-> pict? number? number? pict?) [scale (case-> (-> pict? number? number? pict?)
(-> pict? number? pict?))] (-> pict? number? pict?))]
[scale-to-fit (case-> (-> pict? number? number? pict?)
(-> pict? pict? pict?))]
[rotate (case-> (-> pict? number? pict?))] [rotate (case-> (-> pict? number? pict?))]
[pin-line (->* (pict? [pin-line (->* (pict?
pict-path? (-> pict? pict-path? (values number? number?)) pict-path? (-> pict? pict-path? (values number? number?))
@ -1068,6 +1070,14 @@
(s (send c green)) (s (send c green))
(s (send c blue)))))) (s (send c blue))))))
(define scale-to-fit
(case-lambda
[(main-pict size-pict)
(scale-to-fit main-pict (pict-width size-pict) (pict-height size-pict))]
[(main-pict w h)
(scale main-pict (min (/ w (pict-width main-pict))
(/ h (pict-height main-pict))))]))
(define scale (define scale
(case-lambda (case-lambda
[(p x-factor y-factor) [(p x-factor y-factor)