When running extensions, relative paths to images break

Continuation of https://bugs.launchpad.net/inkscape/+bug/498649

Steps to reproduce:

  • open Inkscape
  • save the file
  • Link am image by dragging it onto the canvas and selecting "Link"
  • Run a Python extension (i.e. Render -> Layout -> Printing marks)

What happened?

The linked image now shows "Linked image not found". Checking the path with the XML edit reveals that image.png (located in Desktop/testfolder/image.png, the SVG is stored in the same folder became ../../Desktop/testfolder/image.png. That's one ../ too many. Running the extension again adds another ../. When there's enough ../-s in front of the path to reach the root directory of the hard drive, the path is converted to an absolute path (file:///Desktop/testfolder/image.png), which also doesn't exist.

What should have happened?

Relative paths should be kept.

Inkscape Version and Operating System:

  • Inkscape Version: 1.1-dev (c990a67, 2020-04-09)
  • Operating System: Windows 10
  • Operating System version: 10.0.18362

Migration info

Tried again with python extensions from various menus, and the bug can be reproduced every time with trunk revision 11398. Not reproduced with internal extensions (Render>Grids>Grid, filters...), and import/export extensions (XSLT and and python based).

In the Launchpad issue, the paths are always made absolute. Observations:

Apparently, all the xlink:href attributes of the document are converted to absolute links by Script::solve_reldir (in src/extensions/implementation/script.cpp) so that the scripts can use them. But they don't get their relative value when the script is terminated.

The links of the elements are converted to relative by rebase_hrefs (in src/xml/rebase-hrefs.cpp) when saving the document, but nothing is done for elements. Improving rebase_href to take all elements into account (and maybe calling rebase_href after the script execution) should fix the issue.

Edited by Nathan Lee