Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apply all transform matrices

I am looking for a possibly fast way to apply all transform matrices of a given svg-graphic. In other words: the algorithm should remove all "transform" attributes and transform all coordinates of the graphic to absolute coordinates.

Is their any library that can do this, or is their any SVGDomInterface method that coulld do that?

EDIT::

If I call the consolidate method like this:

$.each( svg.find( 'path' ), function( i ){
        this.transform.baseVal.consolidate();
});

nothing happens, if i call it like this:

$.each( svg.find( 'path' ), function( i ){
        this.transform.animVal.consolidate();
});

i get this error:

error

So, how should i use the "consolidate" method, on which elements shall I call it?

Greetings philipp

like image 765
philipp Avatar asked Apr 12 '12 15:04

philipp


2 Answers

Here's a jsFiddle with some javascript library code (based in part on Raphael.js) to bake the transforms into all paths' data:

http://jsfiddle.net/ecmanaut/2Wez8/

(Not sure what's up with Opera here, though; it's usually best in class on SVG. I may be stumbling in some way the other browsers are more forgiving about.)

like image 74
ecmanaut Avatar answered Oct 18 '22 15:10

ecmanaut


The consolidate method only reduces the list of matrices to a single matrix. And the error you get on the animVal example is because you are not allowed to modify the animated values (consolidate destructively modifies the transform list).

To answer your question, no there's no existing method in SVG DOM that applies the transforms by modifying the values of paths etc. There are options in Inkscape (and Illustrator too IIRC) for applying transforms like that.

If you're looking for a library or utility that does this you can try SVG Cleaner.

like image 34
Erik Dahlström Avatar answered Oct 18 '22 17:10

Erik Dahlström