Skip to content

Support context paint in SVG markers#2744

Open
moreaki wants to merge 1 commit into
Kozea:mainfrom
moreaki:fix-svg-context-paint-markers
Open

Support context paint in SVG markers#2744
moreaki wants to merge 1 commit into
Kozea:mainfrom
moreaki:fix-svg-context-paint-markers

Conversation

@moreaki
Copy link
Copy Markdown
Contributor

@moreaki moreaki commented Apr 22, 2026

Fixes #2667.

Context

SVG 2 adds context-fill and context-stroke paint values so marker contents can use the fill or stroke paint of the element referencing the marker. The motivating issue uses a marker circle with stroke="context-stroke" and fill="context-fill" on a dashed red path. In browsers such as Firefox, the marker takes the path paint values, but WeasyPrint did not recognize these keywords.

While investigating this, there was also an older rendering problem exposed by the same example: the dashed PDF graphics state from the referencing path could leak into marker contents. That meant a marker stroke could become dashed even if the marker child itself had no stroke-dasharray. This was not specific to the new SVG 2 keywords; it could happen with a plain stroke="red" marker too.

Changes

  • Track the marker-referencing SVG node while marker children are rendered.
  • Resolve context-fill and context-stroke paint values from that context node.
  • Keep the implementation scoped to marker rendering, which is the context element defined by the reported issue and the SVG 2 paint spec.
  • Reset the SVG dash state to a solid stroke when the current node has no valid stroke-dasharray, preventing marker strokes from inheriting a dashed graphics state from the referencing path.
  • Add regression tests for both the SVG 2 context-paint behavior and the pre-existing dashed-marker state leak.

Scope and follow-up

This is intentionally a first, narrow slice of SVG 2 context paint support. It does not try to implement every context-paint case from the spec. In particular, use-element context paint and paint-server coordinate-space continuity for contextual paint values remain follow-up work.

Tests

  • venv/bin/python -m pytest tests/draw/svg/test_markers.py
  • venv/bin/python -m pytest tests/draw/svg
  • venv/bin/python -m ruff check weasyprint/svg/__init__.py tests/draw/svg/test_markers.py

@moreaki moreaki marked this pull request as ready for review April 22, 2026 09:44
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.

Support context-stroke and context-fill SVG painting values

1 participant