External `<use>` elements don't reference external elements correctly (only checks including document's defs)
Note: this is cross-posted from https://inkscape.org/forums/beyond/embedded-svg-does-not-display-markers/ - I have cross-posted it here because 1) this may be a bug in 0.92, and 2) when I try to open Edit: crash fixed, bug in 0.92 still occurs in 1.0foo.svg
in Inkscape 1.0 beta, Inkscape crashes (which is definitely a bug)
It was also reported in https://bugs.launchpad.net/inkscape/+bug/1777984
Steps to replicate
- Open foo.svg in inkscape (contains a
<use>
that references the root element ofbar.svg
- Compare to bar.svg in Inkscape (contains elements that have markers. These markers are defined in the
<defs>
ofbar.svg
)
What happened?
- the marker don't display in
foo.svg
, but do whenbar.svg
is opened directly.
Generally, what is happening is that
- If your document has a
<use>
element that references an element from a separate document, use directives or markers (basically just links) in that external document will not function properly (except for further external elements). - The links in the external document will match the original document instead (if there is a matching id)
- Even if the xlink:hrefs in the external document refer to elements that are nested within the 'd entity, those will not function correctly.
What should have happened?
- the marker should have displaced
- more generally,
<use>
elements should deeply clone the contents of the referenced element (see https://www.w3.org/TR/SVG11/struct.html#UseElement). Thus links inside the referenced elements should still work.
Attachments
foo.svg and bar.svg from this case
and from the launchpad issue (shows example where the referenced document links to a gradient and a shape, rather than a marker)
snippet from file.svg
<use xlink:href="external.svg#use-me" />
snippet from external.svg
<g id="use-me">
<circle id="path815" cx="32" cy="32" r="24"
style="fill:url(#linearGradient1758);fill-opacity:1" />
<use xlink:href="#path815" transform="translate(64)"
style="stroke:#800000" />
</g>
and another minimal case from the comments below: ink-linker.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg viewBox="0 0 50 50" height="50" width="50" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<use xlink:href="ink-linked.svg#root" />
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg id="root" viewBox="0 0 50 50" height="50" width="50" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="0" y="0" width="50" height="50" id="original_object" />
<use xlink:href="#original_object" id="clone" fill="blue" />
</svg>
We expect the blue clone to be visible, as it is if we explicitly reference the document the reference is from for all links. So ink-linked.svg is changed to
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg id="root" viewBox="0 0 50 50" height="50" width="50" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="0" y="0" width="50" height="50" id="original_object" />
<use xlink:href="ink-linked.svg#original_object" id="clone" fill="blue" />
</svg>
This doesn't work with markers afaik.
Version info
1.0beta and 0.92 and 0.92.2 2405546, 2018-03-11
Search terms: (launchpad, gitlab: inkscape/inkscape, gitlab: inkscape/inbox) "external reference" "external link" "reference file" "link file"