From 704677ec29a09b2d8f06f0f272df883741d258b8 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Tue, 15 Oct 2013 10:02:20 -0500 Subject: [PATCH] adjust scribble html renderer to fall back from svg to png and vice-versa original commit: 3ab82a7f8d1f48f5bab147214444dfad6503bc24 --- .../scribble-lib/scribble/html-render.rkt | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt b/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt index f64e987f..86f47dda 100644 --- a/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt +++ b/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt @@ -1100,23 +1100,17 @@ (cond [(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 - [(and (equal? (current-render-pict-as) 'png-images) + [(and (convertible? e) + (equal? (current-render-pict-as) 'png-images) (convertible? e) - (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)])))))] + (or (render-as-png e) + (render-as-svg e))) + => values] [(and (equal? (current-render-pict-as) 'svg-images) (convertible? e) - (convert e 'svg-bytes)) - => (lambda (bstr) - `((object - ([data ,(install-file "pict.svg" bstr)] - [type "image/svg+xml"]))))] + (or (render-as-svg e) + (render-as-png e))) + => values] [(image-element? e) (let* ([src (collects-relative->path (image-element-path e))] [suffixes (image-element-suffixes e)] @@ -1266,6 +1260,27 @@ (render-plain-content e part ri))))))))] [else (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 (attribs) (content-attribs e))