Skip to content

Support SVG transform angle units - #2737

Merged
liZe merged 3 commits into
Kozea:mainfrom
moreaki:codex/svg-transform-angle-units
May 12, 2026
Merged

Support SVG transform angle units#2737
liZe merged 3 commits into
Kozea:mainfrom
moreaki:codex/svg-transform-angle-units

Conversation

@moreaki

@moreaki moreaki commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

What changed

Fixes #2735.

This adds SVG angle parsing for transform functions that take angles, so values such as rotate(90deg), rotate(.25turn), rotate(1.5708rad), and skew(20deg) are treated as angles instead of lengths.

Why

Generated SVGs commonly use explicit angle units in CSS transforms. Mermaid Gantt diagrams, for example, emit rules such as transform: rotate(45deg) scale(...) for milestones and rotate(90deg) for rotated tick labels. WeasyPrint previously parsed transform arguments as lengths before dispatching by transform function, which made angle units fail.

Tests

  • python -m pytest tests/draw/svg/test_transform.py -q
  • python -m pytest tests/draw/svg -q

@moreaki
moreaki marked this pull request as ready for review April 21, 2026 22:57

@liZe liZe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this pull request. 🙏

Here’s a small list of comments, that’s only minor changes.

Comment thread weasyprint/svg/utils.py
Comment thread weasyprint/svg/utils.py Outdated
Comment thread tests/draw/svg/test_transform.py Outdated
Comment thread tests/draw/svg/test_transform.py Outdated
Comment thread tests/draw/svg/test_transform.py Outdated
@liZe liZe added the feature New feature that should be supported label Apr 22, 2026
@liZe liZe added this to the 69.0 milestone Apr 22, 2026
@moreaki

moreaki commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks again for the careful review! I’ve addressed the angle-unit feedback in c2f8813f: angle parsing now uses ANGLE_TO_RADIANS and returns radians, rotate/skew consume radians directly, and the SVG transform test is now parametrized across deg, grad, rad, and turn.

@moreaki
moreaki requested a review from liZe April 22, 2026 19:05

@liZe liZe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@liZe
liZe merged commit 93d213c into Kozea:main May 12, 2026
8 checks passed
@moreaki
moreaki deleted the codex/svg-transform-angle-units branch July 19, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature that should be supported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG transform angle units such as deg are not parsed

2 participants