prawn-svg icon indicating copy to clipboard operation
prawn-svg copied to clipboard

Support referenced SVG images

Open CWempe opened this issue 3 years ago • 7 comments

I am using asciidoctor to create PDFs. I created an SVG file for the title page of my document. This SVG file has two other images referenced like this:

    <image
       preserveAspectRatio="none"
       inkscape:svg-dpi="512"
       width="33.599998"
       height="33.599998"
       style="image-rendering:optimizeQuality"
       xlink:href="my_image.svg"
       id="image8061"
       x="23.083784"
       y="239.09735" />

This does not work because prawn-svg does not support linked SVG files in a SVG file. It works when I change it to PNG.

       xlink:href="my_image.png"

It would be great if prawn-svg would support this.

I initially created an issue here: https://github.com/asciidoctor/asciidoctor-pdf/issues/1937

CWempe avatar Jun 11 '21 19:06 CWempe

Hi, it is supported with the file:// scheme but you’ll need to enable it and use a full URL. See readme for details.

On Sat, 12 Jun 2021 at 7:41 AM, Christoph Wempe @.***> wrote:

I am using asciidoctor to create PDFs. I created an SVG file for the title page of my document. This SVG file has two other images referenced like this:

<image
   preserveAspectRatio="none"
   inkscape:svg-dpi="512"
   width="33.599998"
   height="33.599998"
   style="image-rendering:optimizeQuality"
   xlink:href="my_image.svg"
   id="image8061"
   x="23.083784"
   y="239.09735" />

This does not work because prawn-svg does not support linked SVG files in a SVG file. It works when I change it to PNG.

   xlink:href="my_image.png"

It would be great if prawn-svg would support this.

I initially created an issue here: asciidoctor/asciidoctor-pdf#1937 https://github.com/asciidoctor/asciidoctor-pdf/issues/1937

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mogest/prawn-svg/issues/137, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAFUXLSH3C5KU2SG3QFWY3TSJRGLANCNFSM46RLTMGA .

mogest avatar Jun 11 '21 19:06 mogest

Interesting. I was not aware of that. I suppose it would be possible in Asciidoctor PDF to rewrite the target automatically.

Is there a reason that the relative path cannot be supported? Just curious.

mojavelinux avatar Jun 11 '21 19:06 mojavelinux

Oh, apologies. You were referring to it not supporting svg files. That’s correct. I don’t have any plans to implement this but you’re welcome to contribute.

On Sat, 12 Jun 2021 at 7:41 AM, Christoph Wempe @.***> wrote:

I am using asciidoctor to create PDFs. I created an SVG file for the title page of my document. This SVG file has two other images referenced like this:

<image
   preserveAspectRatio="none"
   inkscape:svg-dpi="512"
   width="33.599998"
   height="33.599998"
   style="image-rendering:optimizeQuality"
   xlink:href="my_image.svg"
   id="image8061"
   x="23.083784"
   y="239.09735" />

This does not work because prawn-svg does not support linked SVG files in a SVG file. It works when I change it to PNG.

   xlink:href="my_image.png"

It would be great if prawn-svg would support this.

I initially created an issue here: asciidoctor/asciidoctor-pdf#1937 https://github.com/asciidoctor/asciidoctor-pdf/issues/1937

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mogest/prawn-svg/issues/137, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAFUXLSH3C5KU2SG3QFWY3TSJRGLANCNFSM46RLTMGA .

mogest avatar Jun 11 '21 19:06 mogest

Apparently I can’t remember my own code. It does in fact support refs without the file: schema specified! The problem here is it doesn’t support svg images. Serves me right for replying to emails when I’ve just woken up.

On Sat, 12 Jun 2021 at 7:46 AM, Dan Allen @.***> wrote:

Interesting. I was not aware of that. I suppose it would be possible in Asciidoctor PDF to rewrite the target automatically.

Is there a reason that the relative path cannot be supported? Just curious.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/mogest/prawn-svg/issues/137#issuecomment-859802370, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAFUXJFAUGIBV7B55XJP6DTSJRZFANCNFSM46RLTMGA .

mogest avatar Jun 11 '21 19:06 mogest

I'll see if someone in the community is available to contribute.

mojavelinux avatar Jun 11 '21 19:06 mojavelinux

I would need this feature too since asciidoctor-diagram (with graphviz) generates this syntax when you use an SVG for a node. I am not a Ruby programmer, but I think instead of skipping the element it should be replaced with the raw SVG code.

https://github.com/mogest/prawn-svg/blob/e085b1d6d84ac417a92685be2d2d32d919702bfd/lib/prawn/svg/elements/image.rb#L75

Alwinator avatar Mar 11 '22 18:03 Alwinator

Sadly it's not that straight forward @Alwinator. The SVG has its own context and view box; things that happen in the main SVG shouldn't affect things in the embedded SVG, and it has to be scaled correctly. It shouldn't be super hard to implement, but it's definitely not as simple as just copying the SVG code inline.

mogest avatar Mar 18 '22 19:03 mogest