<div dir="ltr">Hi,<div><br></div><div>I'm reviving this thread because the problem is still present in the current snapshot builds.</div><div><br></div><div>Just to remind you what the problem is:</div><div><br></div><div><div style="font-family:arial,sans-serif;font-size:13px">Scribble's <span class="">image</span>-<span class="">element</span> allows for a scale argument, but the html-render ignores it when processing SVG files.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">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</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"><div>(define/override (render-content e part ri)</div><div>...</div><div> [(image-element? e)</div><div> (let* ([src (collects-relative->path (image-element-path e))]</div><div> [suffixes (image-element-suffixes e)]</div><div> [scale (image-element-scale e)]</div><div> [to-scaled-num</div><div> (lambda (s)</div><div> (number->string</div><div> (inexact->exact</div><div> (floor (* scale (if (number? s)</div><div> s</div><div> (integer-bytes->integer s #f #t)))))))]</div><div>;;Quickly hacked function to parse SVG lengths<br></div><div> [to-scaled-num-from-str</div><div> (lambda (s)</div><div> (let ((parts</div><div> (regexp-match</div><div> #rx"^([+-]?[0-9]*\\.?([0-9]+)?)(em|ex|px|in|cm|mm|pt|pc|%|)$"</div><div> s)))</div><div> (string-append</div><div> (number->string</div><div> (* scale</div><div> (string->number (list-ref parts 1))))</div><div> (list-ref parts 3))))]</div><div>...</div><div><br></div><div>;;Processing SVG file</div><div> [svg?<br></div><div> (call-with-input-file*</div><div> src</div><div> (lambda (in)</div><div> (with-handlers ([exn:fail? (lambda (exn) </div><div> (log-warning</div><div> (format "warning: error while reading SVG file for size: ~a"</div><div> (if (exn? exn)</div><div> (exn-message exn)</div><div> (format "~e" exn))))</div><div> null)])</div><div> (let* ([d (xml:read-xml in)]</div><div> [attribs (xml:element-attributes </div><div> (xml:document-element d))]</div><div> [check-name (lambda (n)</div><div> (lambda (a)</div><div> (and (eq? n (xml:attribute-name a))</div><div> (xml:attribute-value a))))]</div><div> [w (ormap (check-name 'width) attribs)]</div><div> [h (ormap (check-name 'height) attribs)])</div><div> (if (and w h)</div><div>;;This is needed to scale SVG lengths<br></div><div> `([width ,(to-scaled-num-from-str w)]</div><div> [height ,(to-scaled-num-from-str h)])</div><div> null)))))]</div><div>...</div></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div></div><div style="font-family:arial,sans-serif;font-size:13px">So, what I'm saying is that it would be great if something like this could be included in the Racket sources.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Best regards,</div><div style="font-family:arial,sans-serif;font-size:13px">António.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 4, 2014 at 1:20 PM, Antonio Menezes Leitao <span dir="ltr"><<a href="mailto:antonio.menezes.leitao@ist.utl.pt" target="_blank">antonio.menezes.leitao@ist.utl.pt</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Mon, Aug 4, 2014 at 10:35 AM, Jens Axel Søgaard <span dir="ltr"><<a href="mailto:jensaxel@soegaard.net" target="_blank">jensaxel@soegaard.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">It is not intended. I am not sure whether it simply doesn't work, or whether<br>
it is browser related.<br>
<br>
SVG images are currently inserted with an html <object> tag where as the other<br>
images are inserted as <img>. The width and height attributes are set in both<br>
cases.<br></blockquote><div><br></div></span><div>Indeed. But in the case of PNGs and GIFs they have their width and height adjusted by the scale, while SVGs do not.</div><div>I did not test other browsers, but recent versions of Chrome and IE seem to honor the scaled size.</div>
<div><br></div><div>In fact, I'm currently using a patched html-render.rkt to generate documentation containing tons of tikz pictures, and it looks great.</div><div>Each picture is converted to svg by pdflatex+standalone+pdf2svg and then included in an image-element with an appropriate scaling factor. </div>
<div>Before, I was converting everything to PNGs but the documentation was taking inordinate amounts of disk space.</div><div><br></div><div>Obviously, I would prefer to use an officially maintained version of Scribble that supports scaled SVGs.</div>
<div><br></div><div>Best,</div><div>Antonio.</div></div></div></div>
</blockquote></div><br></div></div>