aboutsummaryrefslogtreecommitdiff
path: root/imagemap.py
diff options
context:
space:
mode:
authorViatrix2026-03-12 16:13:40 -0700
committerViatrix2026-03-12 17:20:47 -0700
commitc29ac06954bf29f25c64f1f658d20b4e2a28d19e (patch)
tree4852eaa2ea03e0a9e78c558fdc07befd6675ae3a /imagemap.py
parent5aca421003b008e116c170d6be789ac28e602cf7 (diff)
Nested SVGs now work.
Diffstat (limited to 'imagemap.py')
-rw-r--r--imagemap.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/imagemap.py b/imagemap.py
index 8ab6558..30d0399 100644
--- a/imagemap.py
+++ b/imagemap.py
@@ -57,6 +57,7 @@ class ImageMap(inkex.OutputExtension):
# after this, the shapes within the image must: look the same as before (barring colour/alpha), not be clones, have no stroke, not intersect, and be visually unaffected by `fill-rule`.
# TODO pay attention to clip-path
links=[]
+ svgIDs=[i.get_id() for i in self.svg.iterdescendants('{http://www.w3.org/2000/svg}svg')]
for a in self.svg.iterdescendants('{http://www.w3.org/2000/svg}a'):
# save link attributes because they get removed when flattening
link={attr:AREA_ATTRS[attr](a) for attr in AREA_ATTRS.keys()}
@@ -72,8 +73,9 @@ class ImageMap(inkex.OutputExtension):
if len(links)==0:
raise inkex.AbortExtension(_("Image has no hyperlinks.\nAdd a hyperlink to an object with right-click → \"{}\".").format(_("Create Anchor (Hyperlink)")))
command=\
- ';'.join(f'select-clear;select-by-selector:[style~="{CSS_LINK_INDEX}-{i}"];object-stroke-to-path;selection-ungroup;path-union;object-set-attribute:style,{CSS_LINK_INDEX}:" {CSS_LINK_INDEX}-{i} "' for i in range(len(links))) \
- +';select-all;path-flatten;path-split'
+ ''.join(f'select-clear;select-by-id:{i};selection-ungroup;' for i in reversed(svgIDs)) \
+ +''.join(f'select-clear;select-by-selector:[style~="{CSS_LINK_INDEX}-{i}"];object-stroke-to-path;selection-ungroup;path-union;object-set-attribute:style,{CSS_LINK_INDEX}:" {CSS_LINK_INDEX}-{i} ";' for i in range(len(links))) \
+ +'select-all;path-flatten;path-split'
# (we re-set the existing style attribute in case it got unset on non-paths)
newbytes=inkscape_command(self.svg,actions=command)
self.svg=self.load(newbytes).getroot()