Skip to content

Support context paint in SVG use elements#2745

Draft
moreaki wants to merge 2 commits into
Kozea:mainfrom
moreaki:fix-svg-use-context-paint
Draft

Support context paint in SVG use elements#2745
moreaki wants to merge 2 commits into
Kozea:mainfrom
moreaki:fix-svg-use-context-paint

Conversation

@moreaki
Copy link
Copy Markdown
Contributor

@moreaki moreaki commented Apr 22, 2026

Stacked on #2744.

Context

#2744 adds marker-scoped support for the SVG 2 context-fill and context-stroke paint values, fixing the concrete marker case from #2667. The SVG 2 paint definition also says that an element inside a subtree instantiated by a use element has that use element as its context element.

This draft PR adds that second small context-paint case on top of #2744, so maintainers can decide whether they want to include it as a follow-up feature.

Changes

  • Reuse the context-paint tracking introduced by Support context paint in SVG markers #2744 when drawing children of a use element.
  • Treat the use element as the context element while its referenced subtree is drawn.
  • Add a pixel regression test proving that context-fill and context-stroke are resolved independently for multiple use instances with different solid paint values.

Scope and limitations

This intentionally supports the simple solid-color case. It does not try to solve the harder paint-server geometry case for contextual url(#gradient) or url(#pattern) values. For those, SVG 2 requires the paint server coordinate space and bounding box to come from the context element, which needs additional gradient/pattern plumbing beyond this small follow-up.

Until #2744 lands, this PR’s diff includes the marker context-paint groundwork from #2744 plus one additional commit for use elements.

Tests

  • venv/bin/python -m pytest tests/draw/svg/test_defs.py::test_use_context_paint tests/draw/svg/test_defs.py::test_use_symbol_color tests/draw/svg/test_markers.py::test_markers_context_paint
  • venv/bin/python -m pytest tests/draw/svg
  • venv/bin/python -m ruff check weasyprint/svg/__init__.py tests/draw/svg/test_defs.py tests/draw/svg/test_markers.py

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