Handle links contained within SVG documents
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.
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.
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.
Hi guys! any update on this? 🍿
Hi guys! any update on this?
Nothing new.