From 7647e94eee4fe59ba62362c15445bf2feaae1e36 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Wed, 22 Aug 2012 22:03:49 -0500 Subject: [PATCH] add scale-to-fit to slideshow/pict --- collects/scribblings/slideshow/picts.scrbl | 12 ++++++++++++ collects/texpict/utils.rkt | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/collects/scribblings/slideshow/picts.scrbl b/collects/scribblings/slideshow/picts.scrbl index 7c45936192..c7091f0fca 100644 --- a/collects/scribblings/slideshow/picts.scrbl +++ b/collects/scribblings/slideshow/picts.scrbl @@ -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 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?]{ diff --git a/collects/texpict/utils.rkt b/collects/texpict/utils.rkt index 965038c6e5..0347edc972 100644 --- a/collects/texpict/utils.rkt +++ b/collects/texpict/utils.rkt @@ -71,6 +71,8 @@ (provide/contract [scale (case-> (-> pict? number? number? pict?) (-> pict? number? pict?))] + [scale-to-fit (case-> (-> pict? number? number? pict?) + (-> pict? pict? pict?))] [rotate (case-> (-> pict? number? pict?))] [pin-line (->* (pict? pict-path? (-> pict? pict-path? (values number? number?)) @@ -1068,6 +1070,14 @@ (s (send c green)) (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 (case-lambda [(p x-factor y-factor)