diff options
| author | Viatrix | 2026-03-11 07:36:02 -0700 |
|---|---|---|
| committer | Viatrix | 2026-03-11 07:36:02 -0700 |
| commit | 1896ef89104109adffcaeb87274abbfe6759c986 (patch) | |
| tree | 68b0eacedcee1c5deb3310cc0a2e4ce54231e7c1 | |
| parent | f138950cbf5908fb75fbf1de17d41eb2bf28007e (diff) | |
`<text>` elements now working
| -rw-r--r-- | imagemap.py | 8 | ||||
| -rw-r--r-- | tests/data/refs/imagemap__--maptype__HTML__text__svg.out | 3 | ||||
| -rw-r--r-- | tests/data/svg/text.svg | 2 |
3 files changed, 9 insertions, 4 deletions
diff --git a/imagemap.py b/imagemap.py index 4c4c931..a1bd093 100644 --- a/imagemap.py +++ b/imagemap.py @@ -59,13 +59,15 @@ class ImageMap(inkex.OutputExtension): 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()} - for el in a.iterdescendants(): # CSS is preserved when flattening BUT NOT IN TEXT SO WE GOTTA FIGURE OUT HOW TODO TEXT + for el in a.iterdescendants(): # CSS is preserved when flattening (for paths) if not isinstance(el,inkex.ShapeElement): continue style=el.effective_style() style[CSS_LINK_INDEX]=f'" {CSS_LINK_INDEX}-{len(links)} "' links += [link] - command='select-all;path-flatten;'+ \ - ';'.join(f'select-clear;select-by-selector:[style~="{CSS_LINK_INDEX}-{i}"];path-union;path-split' for i in range(len(links))) + command=\ + ';'.join(f'select-clear;select-by-selector:[style~="{CSS_LINK_INDEX}-{i}"];object-stroke-to-path;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__text__svg.out b/tests/data/refs/imagemap__--maptype__HTML__text__svg.out new file mode 100644 index 0000000..1ffeffe --- /dev/null +++ b/tests/data/refs/imagemap__--maptype__HTML__text__svg.out @@ -0,0 +1,3 @@ +<area shape=poly coords=75,20,67,20,56,22,45,24,35,27,27,32,21,37,17,42,15,48,15,54,18,60,23,65,30,70,38,74,48,77,59,79,71,80,83,80,94,78,105,76,115,73,123,68,129,63,133,58,135,52,135,46,132,40,127,35,120,30,112,26,102,23,91,21,79,20 href=http://example.com/1> +<area shape=poly coords=225,20,217,20,206,22,195,24,185,27,177,32,171,37,167,42,165,48,165,54,168,60,173,65,180,70,188,74,198,77,209,79,221,80,233,80,244,78,255,76,265,73,273,68,279,63,283,58,285,52,285,46,282,40,277,35,270,30,262,26,252,23,241,21,229,20 href=http://example.com/2> +<area shape=poly coords=150,120,142,120,131,122,120,124,110,127,102,132,96,137,92,142,90,148,90,154,93,160,98,165,105,170,113,174,123,177,134,179,146,180,158,180,169,178,180,176,190,173,198,168,204,163,208,158,210,152,210,146,207,140,202,135,195,130,187,126,177,123,166,121,154,120 href=http://example.com/3> diff --git a/tests/data/svg/text.svg b/tests/data/svg/text.svg index 6b0a130..2bdf01e 100644 --- a/tests/data/svg/text.svg +++ b/tests/data/svg/text.svg @@ -7,7 +7,7 @@ <ellipse cx="225" cy="50" rx="60" ry="30"/> <text x="225" y="50" fill="#fff" text-anchor="middle" font-size="16">B</text> </a> - <a xlink:href="http://example.com/1"> + <a xlink:href="http://example.com/3"> <ellipse cx="150" cy="150" rx="60" ry="30"/> <text x="150" y="150" fill="#fff" text-anchor="middle" font-size="16">C</text> </a> |
