file/convertible: declare 'png@2x-bytes conversion variant

The 'png@2x-bytes variant is like 'png-bytes, but where the decoded
bytes are intended to be scaled by 1/2.

Consumers:

 - DrRacket's print handler

 - Scribble's HTML renderer

Producers:

 - `bitmap%`s where the scaling factor is 2

 - picts

Examples: Quick docs, docs for `images/icons/misc`, DrRacket interactions
for results of `images/icons/misc` functions.

original commit: eda4f357463fc8803726881f57cdd1cec6822660
This commit is contained in:
Matthew Flatt 2014-01-06 18:52:51 -07:00
parent baded0251a
commit 4014cb57b6

View File

@ -105,7 +105,7 @@
(define extra-breaking? (make-parameter #f))
(define current-version (make-parameter (version)))
(define current-part-files (make-parameter #f))
(define current-render-convertible-requests (make-parameter '(png-bytes svg-bytes)))
(define current-render-convertible-requests (make-parameter '(png@2x-bytes png-bytes svg-bytes)))
(define (url->string* u)
(parameterize ([current-url-encode-mode 'unreserved])
@ -1295,16 +1295,21 @@
(define/private (render-as-convertible e requests)
(for/or ([request (in-list requests)])
(cond
[(and (equal? request 'png-bytes)
(convert e 'png-bytes))
[(and (or (equal? request 'png-bytes)
(equal? request 'png@2x-bytes))
(convert e request))
=>
(lambda (bstr)
(let ([w (integer-bytes->integer (subbytes bstr 16 20) #f #t)]
[h (integer-bytes->integer (subbytes bstr 20 24) #f #t)])
[h (integer-bytes->integer (subbytes bstr 20 24) #f #t)]
[scale (lambda (v)
(if (equal? request 'png@2x-bytes)
(/ v 2.0)
v))])
`((img ([src ,(install-file "pict.png" bstr)]
[alt "image"]
[width ,(number->string w)]
[height ,(number->string h)])))))]
[width ,(number->string (scale w))]
[height ,(number->string (scale h))])))))]
[(and (equal? request 'svg-bytes)
(convert e 'svg-bytes))
=> (lambda (bstr)