Skip to content

Issue with transformation order?

Working on #248, I ran into an issue using the add_scale function. I have had trouble getting multiple transforms to work correctly together, as though the transforms were not being applied (multiplied) in the correct order. (Or, perhaps I am just not using the functions correctly-- but I could use some assistance in verifying the situation.)

As a test case, attached is a file, transform_none.svg, with a single rectangle:

    <rect
       y="25"
       x="25"
       height="100"
       width="25"
       id="rect1"
       style="fill:#008000;stroke:#000000;stroke-width:0.01" /> 

In a second file, transform_inline.svg, I've applied two nested transformations:

    <g transform="translate(200,10)">
        <g transform="rotate(45)">
            <rect
               y="25"
               x="25"
               height="100"
               width="25"
               id="rect1"
               style="fill:#008000;stroke:#000000;stroke-width:0.01" /> 
        </g>
    </g>

This should rotate the rectangle 45°, and then translate it. As far as I can see, this file appears to render correctly in Inkscape.

Now, it should also be possible to instead apply transformations in an extension, using inkex/transforms.py. In particular, if we take our transform_none.svg file, it seems like the following should apply the same transforms:

        for element in self.svg: 
            element.transform.add_rotate(45) 
            element.transform.add_translate(200,10)

However, it turns out that this does not produce the correct output. Rather, I need to use the following in order to get an output SVG that appears to have the correct transforms applied.

        for element in self.svg: 
            element.transform.add_translate(200,10)
            element.transform.add_rotate(45) 

Attached here is a test extension docinfo.py for ease of reproducing the issue.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information