diff options
| -rw-r--r-- | imagemap.py | 6 | ||||
| -rw-r--r-- | tests/data/refs/imagemap__--maptype__HTML__viewbox__svg.out | 4 | ||||
| -rw-r--r-- | tests/data/svg/viewbox.svg | 14 |
3 files changed, 19 insertions, 5 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() diff --git a/tests/data/refs/imagemap__--maptype__HTML__viewbox__svg.out b/tests/data/refs/imagemap__--maptype__HTML__viewbox__svg.out index 0fc648a..b1cd4fb 100644 --- a/tests/data/refs/imagemap__--maptype__HTML__viewbox__svg.out +++ b/tests/data/refs/imagemap__--maptype__HTML__viewbox__svg.out @@ -1 +1,3 @@ -<area shape=poly coords=50,25,25,75,75,75 href=http://example.com> +<area shape=poly coords=50,25,25,75,75,75 href=http://example.com/1> +<area shape=poly coords=150,12,125,38,175,38 href=http://example.com/2> +<area shape=poly coords=175,56,162,69,188,69 href=http://example.com/3> diff --git a/tests/data/svg/viewbox.svg b/tests/data/svg/viewbox.svg index a0cdc1d..7894a76 100644 --- a/tests/data/svg/viewbox.svg +++ b/tests/data/svg/viewbox.svg @@ -1,5 +1,15 @@ -<svg width="100" height="100" viewBox="-100 -100 200 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> - <a xlink:href="http://example.com"> +<svg width="200" height="100" viewBox="-100 -100 400 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + <a xlink:href="http://example.com/1"> <polyline points="0,-50 50,50 -50,50"/> </a> + <svg x="100" y="-100" height="200" width="200" viewBox="-100 -100 200 400" preserveAspectRatio="none"> + <a xlink:href="http://example.com/2"> + <polyline points="0,-50 50,50 -50,50"/> + </a> + <svg x="-100" y="100" height="100" width="200" viewBox="-100 -100 200 200" preserveAspectRatio="xMaxYMax"> + <a xlink:href="http://example.com/3"> + <polyline points="0,-50 50,50 -50,50"/> + </a> + </svg> + </svg> </svg> |
