[racket] Bug in scribble's image-element?
Hi,
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
huge
(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)]
[to-scaled-num
(lambda (s)
(number->string
(inexact->exact
(floor (* scale (if (number? s)
s
(integer-bytes->integer s #f
#t)))))))]
;;Quickly hacked function to parse SVG lengths
[to-scaled-num-from-str
(lambda (s)
(let ((parts
(regexp-match
#rx"^([+-]?[0-9]*\\.?([0-9]+)?)(em|ex|px|in|cm|mm|pt|pc|%|)$"
s)))
(string-append
(number->string
(* scale
(string->number (list-ref parts 1))))
(list-ref parts 3))))]
...
;;Processing SVG file
[svg?
(call-with-input-file*
src
(lambda (in)
(with-handlers ([exn:fail? (lambda (exn)
(log-warning
(format "warning:
error while reading SVG file for size: ~a"
(if (exn?
exn)
(exn-message exn)
(format
"~e" exn))))
null)])
(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))
(xml:attribute-value
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)])
null)))))]
...
So, what I'm saying is that it would be great if something like this could
be included in the Racket sources.
Best regards,
António.
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>