bodoni / svg

Composer and parser for SVG
Other
305 stars 44 forks source link

Add support for transformations #64

Open jdbosser opened 1 year ago

jdbosser commented 1 year ago

If I am not mistaken, current API does not include support for transformations of the svgs.

This can likely be solved for those who need to apply transformations to their code by the .add("transformation", "rotate(45)"), for example.

However, it would be nice to create some rust interface that enumerates the possible transformations and their parameters that is included in this repo, like the commands in the paths module.

IvanUkhov commented 1 year ago

Hello, yes, indeed. There is no higher-level interface for doing this. I myself use exactly the approach you described. Since for constructing data for paths we have it, it could make sense to have it for transformations too.

https://github.com/bodoni/svg/blob/main/src/node/element/path/data.rs

dustdfg commented 10 months ago

I just want to add that stored transforms must be a list Vec<Transform> because svg allows several different transforms at the same time: translate(100 100) scale(0.5 0.5). Also the API should be not element.transform(transform: Transform) but rather element.transform(transform: Transform, squash: bool) because user can want to get one matrix after several transforms and not a list of transforms

P.S If you want to know when the list of transforms is more preferable than matrix:

  1. The svg is suited for people reading/editing
  2. You can easily emulate transfom-origin property from svg2 via several sequential transforms