I need to write some C# code that flatten transforms programmatically of any SVG file.
This option is available in SVG editors like Affinity Designer (~$40 / Mac) or Inkscape (FOSS):
But how do you do this programmatically? Even good SVG c# libraries do not provide a method to do this.
There are many discussions open on this on SO (i.e. here, here, here and here ). In those it is suggested some tool, but no one gives the code to do it (except from some javascript snippet that is useless to me because it uses the browser API to get the transformed coordinates).
I need to do this in C# code because to manipulate the svg elements I need those to be independent of parents transforms, including elliptical arcs, gradients, text and tspan elements.
EDIT to clarify: I don't need to necessarily transform the elements. I just need to have transform matrices present only in the deepest child nodes, so I don't need to consider the parents anymore. For this I need all parent matrices concatenated in a single matrix and assigned to svg elements as a single transform attribute. I don't necessarily need to transform paths or arcs, convert ellipses to paths, for example, or resampling bitmaps. I just need to be able to compute only ONE matrix transform for each element, its own, assigned to it as a transform attribute, instead of having to consider all the parent groups transforms every time.