aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--imagemap.py10
-rw-r--r--tests/data/refs/imagemap__--maptype__HTML__enclave__svg.out6
-rw-r--r--tests/data/refs/imagemap__--maptype__HTML__intersect__svg.out2
-rw-r--r--tests/data/refs/imagemap__--maptype__HTML__overlap__svg.out2
-rw-r--r--tests/data/svg/enclave.svg8
-rw-r--r--tests/test_imagemap_comparison.py1
6 files changed, 22 insertions, 7 deletions
diff --git a/imagemap.py b/imagemap.py
index 9a88a42..e595f08 100644
--- a/imagemap.py
+++ b/imagemap.py
@@ -72,6 +72,7 @@ class ImageMap(inkex.OutputExtension):
self.svg=self.load(newbytes).getroot()
seen=set()
+ shapes=[[] for i in range(len(links))]
for el in self.svg.iterdescendants():
if not isinstance(el,inkex.ShapeElement): continue
linkindex=el.cascaded_style().get(CSS_LINK_INDEX)
@@ -80,7 +81,6 @@ class ImageMap(inkex.OutputExtension):
link=links[linkindex]
href=link['href']
alt=link['alt'] if int(linkindex) not in seen else None
- shapes=[]
path=el.get_path().transform(el.composed_transform()).to_superpath()
bezier.cspsubdiv(path,0.5)
for subpath in path:
@@ -89,12 +89,12 @@ class ImageMap(inkex.OutputExtension):
while i<len(coords):
if coords[i]==coords[(i+1)%len(coords)]: coords.pop(i)
else: i+=1
- if rectifiable(coords): shapes.append(shapemarkup('rect',rectify(coords),href,alt))
- elif len(coords)>=3: shapes.append(shapemarkup('poly',coords,href,alt))
+ if rectifiable(coords): shapes[linkindex].insert(0,shapemarkup('rect',rectify(coords),href,alt))
+ elif len(coords)>=3: shapes[linkindex].insert(0,shapemarkup('poly',coords,href,alt))
href=None # because subsequent subpaths must be enclaves
- alt=None
+ alt=None # TODO make it come first even though the order's reversed
seen.add(linkindex)
- stream.write(bytes(''.join(reversed(shapes)),'utf-8'))
+ stream.write(bytes(''.join(sum(shapes,start=[])),'utf-8'))
if __name__ == "__main__":
ImageMap().run()
diff --git a/tests/data/refs/imagemap__--maptype__HTML__enclave__svg.out b/tests/data/refs/imagemap__--maptype__HTML__enclave__svg.out
new file mode 100644
index 0000000..611ef39
--- /dev/null
+++ b/tests/data/refs/imagemap__--maptype__HTML__enclave__svg.out
@@ -0,0 +1,6 @@
+<area shape=rect coords=40,40,60,60 href=http://example.com/1>
+<area shape=rect coords=30,30,70,70>
+<area shape=rect coords=20,20,80,80 href=http://example.com/1>
+<area shape=rect coords=140,40,160,60 href=http://example.com/2>
+<area shape=rect coords=130,30,170,70>
+<area shape=rect coords=120,20,180,80 href=http://example.com/2>
diff --git a/tests/data/refs/imagemap__--maptype__HTML__intersect__svg.out b/tests/data/refs/imagemap__--maptype__HTML__intersect__svg.out
index cab9492..5af12ea 100644
--- a/tests/data/refs/imagemap__--maptype__HTML__intersect__svg.out
+++ b/tests/data/refs/imagemap__--maptype__HTML__intersect__svg.out
@@ -1,2 +1,2 @@
-<area shape=poly coords=60,40,60,60,40,60,40,80,80,80,80,40 href=http://example.com>
<area shape=poly coords=20,20,20,60,40,60,40,40,60,40,60,20 href=http://example.com>
+<area shape=poly coords=60,40,60,60,40,60,40,80,80,80,80,40 href=http://example.com>
diff --git a/tests/data/refs/imagemap__--maptype__HTML__overlap__svg.out b/tests/data/refs/imagemap__--maptype__HTML__overlap__svg.out
index 8f8d95d..de38166 100644
--- a/tests/data/refs/imagemap__--maptype__HTML__overlap__svg.out
+++ b/tests/data/refs/imagemap__--maptype__HTML__overlap__svg.out
@@ -1,4 +1,4 @@
-<area shape=poly coords=30,40,30,70,60,70,60,60,40,60,40,40 href=http://example.com/1>
<area shape=poly coords=30,10,30,30,40,30,40,20,80,20,80,60,70,60,70,70,90,70,90,10 href=http://example.com/1>
+<area shape=poly coords=30,40,30,70,60,70,60,60,40,60,40,40 href=http://example.com/1>
<area shape=rect coords=20,40,60,80>
<area shape=rect coords=10,30,70,90 href=http://example.com/2>
diff --git a/tests/data/svg/enclave.svg b/tests/data/svg/enclave.svg
new file mode 100644
index 0000000..db8d777
--- /dev/null
+++ b/tests/data/svg/enclave.svg
@@ -0,0 +1,8 @@
+<svg width="200" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <a xlink:href="http://example.com/1">
+ <path d="M20 20H80V80H20M30 30V70H70V30M40 40H60V60H40"/>
+ </a>
+ <a xlink:href="http://example.com/2">
+ <path d="M140 40H160V60H140M130 30V70H170V30M120 20H180V80H120"/>
+ </a>
+</svg>
diff --git a/tests/test_imagemap_comparison.py b/tests/test_imagemap_comparison.py
index 087a3d8..959e98e 100644
--- a/tests/test_imagemap_comparison.py
+++ b/tests/test_imagemap_comparison.py
@@ -4,6 +4,7 @@ from imagemap import ImageMap
class ImageMapComparisonTest(ComparisonMixin, TestCase):
effect_class = ImageMap
compare_file = (
+ 'svg/enclave.svg',
'svg/intersect.svg',
'svg/overlap.svg',
'svg/rect.svg',