Gradient definition referenced elsewhere not duplicated when parent is deleted
Migrated from: https://bugs.launchpad.net/inkscape/+bug/184705
Steps to reproduce:
- open Inkscape
- open example file bug.svg
- delete the bottom right K
What happened?
The top-left K loses its gradient.
What should have happened?
The gradient, which is defined inside the group of the bottom K, is silently duplicated.
In this document, the bottom group has their own <defs>
, in which the gradient is defined.
The top K references a gradient defined in the global <defs>
, which in turn references the gradient of the lower K. On deleting the lower K, the gradient in the global <defs>
doesn't find it's reference anymore.
Typically, Inkscape follows the "principle of least confusion", where such elements are silently duplicated.
Such a document structure is actually encouraged by the SVG 1.1 spec:
To provide some SVG user agents with an opportunity to implement efficient implementations in streaming environments, creators of SVG content are encouraged to place all elements which are targets of local IRI references within a ‘defs’ element which is a direct child of one of the ancestors of the referencing element.
Inkscape Version and Operating System:
- Inkscape Version: 1.1-dev (6b4d57f5, 2020-04-01)
- Operating System: Windows 10
- Operating System version: 10.0.18362
Migration info
replicated since 0.45.1
The problem is that the group representing the lower K has its own svg:defs element in which the gradient (which is used by both K's) is defined. The global (i.e., document-wide) svg:defs element simply references this gradient. The upper K in turn references the gradient in the global svg:defs element. Thus when the lower K is deleted, the reference in the global svg:defs suddenly points into nirvana and Inkscape stops rendering the gradient because it can't find its definition. If the gradient definition is moved to the global svg:defs element (as in the attached file bug2.svg) then it is not lost when the lower group is deleted and the bug goes away.
I can only mark this as confirmed. The reason it happens as it does make perfect sense from a document structure standpoint. However, in just about every other case where we "use" another item in a document, if the source is deleted, we gracefully "duplicate" it without the user having to worry about it.