Skip to content

SVG: draw nothing for a <use> of an id that is not defined - #2188

Open
RavSinghChandan wants to merge 3 commits into
py-pdf:masterfrom
RavSinghChandan:svg-use-missing-ref
Open

RavSinghChandan wants to merge 3 commits into
py-pdf:masterfrom
RavSinghChandan:svg-use-missing-ref

Conversation

@RavSinghChandan

Copy link
Copy Markdown

The matplotlib charts in the RapidFuzz documentation (docs/Usage/img/*.svg, 18 files) were minified, and the glyph of the space character was dropped while the <use xlink:href="#AG"/> that place it were kept. pdf.image() fails on all of them:

ValueError: use <Element '{http://www.w3.org/2000/svg}use' at 0x...> references nonexistent ref id #AG

Browsers draw nothing for such a <use> and render the rest of the chart, which here only loses the spaces between words. build_xref() now logs a warning ("Ignoring of nonexistent ref id #AG") and returns the empty group, as it already does for a <use> of a hidden element. A <use> without any href still raises, as test_bad_xref checks.

This changes test_missing_xref, which expected the ValueError: it now checks the warning, that the <use> draws nothing and that a shape after it is still drawn; it fails without the change. All 18 RapidFuzz charts now render. Changelog entry under 2.9.1 / Fixed.

This branch has not been deployed

No deployments
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.

1 participant