diff --git a/collects/2htdp/image.ss b/collects/2htdp/image.ss index 3ca112db06..25dc30a30e 100644 --- a/collects/2htdp/image.ss +++ b/collects/2htdp/image.ss @@ -90,4 +90,5 @@ and they all have good sample contracts. (It is amazing what we can do with kids side-count? image-width - image-height) + image-height + image-baseline) diff --git a/collects/teachpack/2htdp/scribblings/image-toc.ss b/collects/teachpack/2htdp/scribblings/image-toc.ss index adc68393fa..b7ce3a649f 100644 --- a/collects/teachpack/2htdp/scribblings/image-toc.ss +++ b/collects/teachpack/2htdp/scribblings/image-toc.ss @@ -6,6 +6,10 @@ (define mapping (list + (list '(image-height (rectangle 100 100 "solid" "black")) 'val 100) + (list '(image-baseline (rectangle 100 100 "solid" "black")) 'val 100) + (list '(image-height (text "Hello" 24 "black")) 'val 24.0) + (list '(image-baseline (text "Hello" 24 "black")) 'val 18.0) (list '(image-height (overlay (circle 20 "solid" "orange") (circle 30 "solid" "purple"))) diff --git a/collects/teachpack/2htdp/scribblings/image-util.ss b/collects/teachpack/2htdp/scribblings/image-util.ss index 651d706b39..cae3d90dc7 100644 --- a/collects/teachpack/2htdp/scribblings/image-util.ss +++ b/collects/teachpack/2htdp/scribblings/image-util.ss @@ -36,11 +36,11 @@ (schemeblock #,(schemeresult #,(cadr line)))] [(image) (let ([fn (format "2htdp/scribblings/img/~a" (cadr line))]) - (if (file-exists? fn) - (schemeblock #,(image fn)) - (make-paragraph - error-color - (format "missing image! ~a" (cadr line)))))])))) + (schemeblock #,(image fn)))] + [(missing) + (make-paragraph + error-color + "missing result; need to re-run image-gen.ss")])))) expr-paras val-list+outputs))))) @@ -51,4 +51,4 @@ [else (unless (getenv "PLTSHOWIMAGES") (fprintf (current-error-port) "exp->filename: unknown exp ~s\n" exp)) - (list 'image "unk.png")]))) + (list 'missing)]))) diff --git a/collects/teachpack/2htdp/scribblings/image.scrbl b/collects/teachpack/2htdp/scribblings/image.scrbl index 81a0403719..0fb8ed7b72 100644 --- a/collects/teachpack/2htdp/scribblings/image.scrbl +++ b/collects/teachpack/2htdp/scribblings/image.scrbl @@ -451,6 +451,17 @@ other. The top and bottom pair of angles is @scheme[angle] and the left and righ (circle 30 "solid" "purple")))] } +@defproc[(image-baseline [i image?]) (and/c number? positive?)]{ + Returns the distance from the top of the image to its baseline. + Unless the image was constructed with @scheme[text] or @scheme[text/font], + this will be the same as its height. + + @image-examples[(image-baseline (text "Hello" 24 "black")) + (image-height (text "Hello" 24 "black")) + (image-baseline (rectangle 100 100 "solid" "black")) + (image-height (rectangle 100 100 "solid" "black"))] +} + @section{Image Predicates} This section lists predicates for the basic structures provided by the image library.