meerk40t / svgelements

SVG Parsing for Elements, Paths, and other SVG Objects.
MIT License
127 stars 28 forks source link

How to rotate the whole SVG structure?? #164

Closed chibai closed 2 years ago

chibai commented 2 years ago

I'm trying to rotate the whole svg, but it seems not supported~~ Is there any approach to do this? Thank you.

from svgelements import svgelements, SVG, Matrix

with open(file='1.svg', mode='rb') as f:
    svg = SVG.parse(f)
rotate_svg = svg * Matrix.rotate(45)
print(svg)
print(rotate_svg)
tatarize commented 2 years ago

You can pass a matrix to the SVG.parse() routine. This should be applied to everything below it.

tatarize commented 2 years ago
    @staticmethod
    def parse(
        source,
        reify=True,
        ppi=DEFAULT_PPI,
        width=None,
        height=None,
        color="black",
        transform=None,
        context=None,
    ):
        """
        Parses the SVG file. All attributes are things which the SVG document itself could not be aware of, such as
        the real size of pixels and the size of the viewport (as opposed to the viewbox).
        :param source: Source svg file or stream.
        :param reify: Should the Geometry sized or have lazy matrices.
        :param ppi: How many physical pixels per inch are there in this view.
        :param width: The physical width of the viewport
        :param height: The physical height of the viewport
        :param color: the `currentColor` value from outside the current scope.
        :param transform: Any required transformations to be pre-applied to this document
        :param context: Any existing document context.
        :return:
        """

The svg object itself in the spec wasn't very clear as to how to apply a matrix on it with regard to the viewport etc. I think it just had height and width and the viewport.