adjust scribble html renderer to fall back from svg to png

and vice-versa

original commit: 3ab82a7f8d1f48f5bab147214444dfad6503bc24
This commit is contained in:
Robby Findler 2013-10-15 10:02:20 -05:00
parent 0724d20135
commit 704677ec29

View File

@ -1100,23 +1100,17 @@
(cond (cond
[(string? e) (super render-content e part ri)] ; short-cut for common case [(string? e) (super render-content e part ri)] ; short-cut for common case
[(list? e) (super render-content e part ri)] ; also a short-cut [(list? e) (super render-content e part ri)] ; also a short-cut
[(and (equal? (current-render-pict-as) 'png-images) [(and (convertible? e)
(equal? (current-render-pict-as) 'png-images)
(convertible? e) (convertible? e)
(convert e 'png-bytes)) (or (render-as-png e)
=> (lambda (bstr) (render-as-svg e)))
(let ([w (integer-bytes->integer (subbytes bstr 16 20) #f #t)] => values]
[h (integer-bytes->integer (subbytes bstr 20 24) #f #t)])
`((img ([src ,(install-file "pict.png" bstr)]
[alt "image"]
[width ,(number->string w)]
[height ,(number->string h)])))))]
[(and (equal? (current-render-pict-as) 'svg-images) [(and (equal? (current-render-pict-as) 'svg-images)
(convertible? e) (convertible? e)
(convert e 'svg-bytes)) (or (render-as-svg e)
=> (lambda (bstr) (render-as-png e)))
`((object => values]
([data ,(install-file "pict.svg" bstr)]
[type "image/svg+xml"]))))]
[(image-element? e) [(image-element? e)
(let* ([src (collects-relative->path (image-element-path e))] (let* ([src (collects-relative->path (image-element-path e))]
[suffixes (image-element-suffixes e)] [suffixes (image-element-suffixes e)]
@ -1266,6 +1260,27 @@
(render-plain-content e part ri))))))))] (render-plain-content e part ri))))))))]
[else [else
(render-plain-content e part ri)])) (render-plain-content e part ri)]))
(define/private (render-as-png e)
(cond
[(convert e 'png-bytes)
=>
(lambda (bstr)
(let ([w (integer-bytes->integer (subbytes bstr 16 20) #f #t)]
[h (integer-bytes->integer (subbytes bstr 20 24) #f #t)])
`((img ([src ,(install-file "pict.png" bstr)]
[alt "image"]
[width ,(number->string w)]
[height ,(number->string h)])))))]
[else #f]))
(define/private (render-as-svg e)
(cond
[(convert e 'svg-bytes)
=> (lambda (bstr)
`((object
([data ,(install-file "pict.svg" bstr)]
[type "image/svg+xml"]))))]
[else #f]))
(define/private (render-plain-content e part ri) (define/private (render-plain-content e part ri)
(define (attribs) (content-attribs e)) (define (attribs) (content-attribs e))