Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG transform-origin ignored #2256

Open
febdoctor opened this issue Sep 19, 2024 · 2 comments
Open

SVG transform-origin ignored #2256

febdoctor opened this issue Sep 19, 2024 · 2 comments
Labels
feature New feature that should be supported good first issue Issues that can be quite easily solved by Python developers with a good CSS background

Comments

@febdoctor
Copy link

The attribute "transform-origin" sets the reference point used in transformations set by the "transform" attribute. In the examples below, a rotation was used with the origin set to the center of the triangle. In WeasyPrint, the origin is ignored and the triangle is rotated relative to (0, 0). When the object is far from (0, 0), it can rotate far from it's intended location and far outside the viewport.

The following SVG reproduces the problem. The rotation is small in order to make the error more visible.

<svg xmlns="http://www.w3.org/2000/svg"  viewBox="0 0 400 400">

<defs>
  <g id="triangle" transform="scale(0.6)">
    <path d="M 0,-20 l 23,40 l -46,0 Z" stroke="purple" fill="none" />
  </g>
</defs>


<use href="#triangle" x="10mm" y="10mm"/>
<use href="#triangle" x="10mm" y="10mm" transform-origin="10mm 10mm" transform="rotate(9)" />

</svg>

In Firefox, the triangle is rotated relative to the center of the triangle:

svgtransformorigin-firefox

But WeasyPrint rotates it relative to (0, 0). It this example it looks slightly offset because the rotation is small.

svgtransformorigin-weasyprint

Reference files:
svgtransformorigin-firefox.pdf
svgtransformorigin.pdf

@liZe
Copy link
Member

liZe commented Sep 24, 2024

Thanks for the bug report.

It is supported by browsers, but it’s not in the SVG specification, even in SVG2. It’s in this draft, overridden by this CSS module.

@liZe liZe added the feature New feature that should be supported label Sep 24, 2024
@liZe
Copy link
Member

liZe commented Sep 24, 2024

If anyone is interested in adding this feature, we need to update this function (and the utils.transform function it calls) to take care of transform-origin:

def transform(self, transform_string, font_size):
"""Apply a transformation string to the node."""
if not transform_string:
return
matrix = transform(transform_string, font_size, self.inner_diagonal)
if matrix.determinant:
self.stream.transform(*matrix.values)

@liZe liZe added the good first issue Issues that can be quite easily solved by Python developers with a good CSS background label Sep 24, 2024
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 good first issue Issues that can be quite easily solved by Python developers with a good CSS background
Projects
None yet
Development

No branches or pull requests

2 participants