[racket] Bug in scribble's image-element?

From: Antonio Menezes Leitao (antonio.menezes.leitao at ist.utl.pt)
Date: Sat Oct 25 19:45:08 EDT 2014


I'm reviving this thread because the problem is still present in the
current snapshot builds.

Just to remind you what the problem is:

Scribble's image-element allows for a scale argument, but the html-render
ignores it when processing SVG files.

The problem is in the following function, in file
shared/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt, which I
quickly modified. I'll only show a few fragments because the function is

(define/override (render-content e part ri)
        [(image-element? e)
         (let* ([src (collects-relative->path (image-element-path e))]
                [suffixes (image-element-suffixes e)]
                [scale (image-element-scale e)]
                 (lambda (s)
                     (floor (* scale (if (number? s)
                                         (integer-bytes->integer s #f
;;Quickly hacked function to parse SVG lengths
                 (lambda (s)
                   (let ((parts

                       (* scale
                          (string->number (list-ref parts 1))))
                      (list-ref parts 3))))]

;;Processing SVG file
                       (lambda (in)
                         (with-handlers ([exn:fail? (lambda (exn)
                                                       (format "warning:
error while reading SVG file for size: ~a"
                                                               (if (exn?

 (exn-message exn)
"~e" exn))))
                           (let* ([d (xml:read-xml in)]
                                  [attribs (xml:element-attributes
                                            (xml:document-element d))]
                                  [check-name (lambda (n)
                                                (lambda (a)
                                                  (and (eq? n
(xml:attribute-name a))
                                  [w (ormap (check-name 'width) attribs)]
                                  [h (ormap (check-name 'height) attribs)])
                             (if (and w h)
;;This is needed to scale SVG lengths
                                   `([width ,(to-scaled-num-from-str w)]
                                     [height ,(to-scaled-num-from-str h)])

So, what I'm saying is that it would be great if something like this could
be included in the Racket sources.

Best regards,

On Mon, Aug 4, 2014 at 1:20 PM, Antonio Menezes Leitao <
antonio.menezes.leitao at ist.utl.pt> wrote:

> On Mon, Aug 4, 2014 at 10:35 AM, Jens Axel Søgaard <jensaxel at soegaard.net>
> wrote:
>> It is not intended. I am not sure whether it simply doesn't work, or
>> whether
>> it is browser related.
>> SVG images are currently inserted with an html <object> tag where as the
>> other
>> images are inserted as <img>. The width and height attributes are set in
>> both
>> cases.
> Indeed. But in the case of PNGs and GIFs they have their width and height
> adjusted by the scale, while SVGs do not.
> I did not test other browsers, but recent versions of Chrome and IE seem
> to honor the scaled size.
> In fact, I'm currently using a patched html-render.rkt to generate
> documentation containing tons of tikz pictures, and it looks great.
> Each picture is converted to svg by pdflatex+standalone+pdf2svg and then
> included in an image-element with an appropriate scaling factor.
> Before, I was converting everything to PNGs but the documentation was
> taking inordinate amounts of disk space.
> Obviously, I would prefer to use an officially maintained version of
> Scribble that supports scaled SVGs.
> Best,
> Antonio.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141026/62b1759b/attachment.html>

Posted on the users mailing list.