WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

Handle links contained within SVG documents

Open chtaylor opened this issue 3 years ago • 4 comments

Requesting a feature enhancement for WeasyPrint to handle links contained within SVG documents for both internal and external destinations.

Links, bookmarks and anchors are collected using _gather_links_and_bookmarks however the code doesn't find inline link elements contained within SVG documents.

Hyperlinks will need to be retrieved from individual elements and I believe the SVG 'Node’ class could be used to retrieve links for rendering. I was able to traverse these objects using the 'get_href' function to return link values for elements, however one issue I see is the 'style' properties are not available meaning I can't return (x, y, width, height) values for each element. If these style properties and coordinates are available on these individual objects then I believe this could be a straight-forward change-set.

Also see W3 for other additional functionality for SVG links.

  • https://www.w3.org/wiki/SVG_Links
  • https://developer.mozilla.org/en-US/docs/Web/SVG/Element/a

Sample SVG link file.

chtaylor avatar Feb 18 '22 12:02 chtaylor

As discussed on Gitter, the (x, y, width, height) values are available using the bounding_box module on a node. We should probably use this to define where links have to be positioned.

liZe avatar Mar 07 '22 15:03 liZe

Using bounding_box() I can't see the coordinates being available until after the document is drawn into a document stream object initialised by paint() and the draw methods contained within the SVG and Node classes.

When _gather_links_and_bookmarks() is called, the SVG elements only appear in their raw HTML format, so no (x, y, width, height) values in the styles properties are available for bounding_box() to use.

Would calling _gather_links_and_bookmarks() later so it's used after or during the drawing of the document to the stream object work? Or maybe the approach could be to create new code to gather links specifically for SVG's.

chtaylor avatar Mar 13 '22 10:03 chtaylor

Hi guys! any update on this? 🍿

enriquetolby avatar Apr 03 '23 15:04 enriquetolby

Hi guys! any update on this?

Nothing new.

liZe avatar Apr 06 '23 08:04 liZe