Skip to content

SVG: accept clip-path="none" and any url(#id) clip path reference - #2143

Merged
andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-clip-path-none
Nov 10, 2026
Merged

andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-clip-path-none

Conversation

@RavSinghChandan

Copy link
Copy Markdown

apply_clipping_path() reads the clip-path value with re.search(r"url\((\#\w+)\)", ...), which has two problems:

  • clip-path="none", the CSS initial value, which Inkscape writes, fails with an AssertionError.
  • An id that contains a - or a . is cut at that character: url(#clip-1) looks up #clip, so it either fails with a KeyError, or, worse, silently clips with another clip path whose id is clip. A quoted reference, url("#clip1"), is not found either.

The method now reads the reference with _extract_gradient_id(), the helper that already parses url(#id) for gradient fills (it accepts quotes, spaces and any id character), and applies no clipping when the value is not a url(#id) reference.

Berlin_location_map.svg (Wikipedia, in svglib's test samples) uses clip-path="none" on 29 elements and fails on master with the AssertionError; it renders with this change and the separate nested <defs> fix.

Added test_svg_clip_path_none (attribute and style) and test_svg_clip_path_reference (ids with - and ., and a quoted reference, next to a decoy #clip); all 5 cases fail on master. pytest test/svg test/drawing, black, pylint and mypy pass

@andersonhc
andersonhc merged commit a2b9fcc into py-pdf:master Nov 10, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants