[racket] Generating svg-images rather than png-images from Scribble

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Oct 13 11:11:12 EDT 2013

Hi All,

Currently the html-renderer of Scribble converts picts into png-images.
Is there an easy way to get svg-images instead?

A first look at the code seems to indicate the answer is no, but maybe I have
overlooked something?

The html-renderer converts anything (including picts) convertible to
png-bytes pngs.

Line 1090-... in scribble/html-render.rkt  :

(define/override (render-content e part ri)
      (define (attribs [extras null]) (content-attribs e extras))
      (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 (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)])))))]
        [(image-element? e)
           ...

In mrlib/image-core.rkt at line 232 one sees that images currently can
be converted to png-bytes only.

Is the right way to proceed, to
   1) add svg-bytes to mrlib/image-core.rkt.
   2) introduce a parameter in Scribble that controls what picts
should be converted to
   3) change render-content in scribble/html-render.rkt accordingly

?

https://github.com/plt/racket/blob/master/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt#L1090
https://github.com/plt/racket/blob/4b8bd2260543dfe7d6da58e7529f330a1cf19d7b/pkgs/gui-pkgs/gui-lib/mrlib/image-core.rkt#L232

--
Jens Axel Søgaard


Posted on the users mailing list.