JS SVG getCTM and setCTM?

If I use getCTM () to get the current transformation matrix, how can I use this object to set the matrix if I want to restore it later (I know about saving and restoring, but they relate to the canvas and not the items)

I know that I set the attribute:

var m = someitem.getCTM(); $(someitem).attr("transform", "matrix("+m.a+","+m.b+","+m.c+","+ m.d+","+m.e+","+m.f+")"); 

But it seems like a long way. I cannot find the setCTM function of any such close function.

Development for webkit, if that matters.

Thanks!

+6
source share
2 answers
 var transform = ownerSVGElement.createSVGTransform() transform.setMatrix(elem.getCTM()) someelement.transform.baseVal.initialize(transform) 
+4
source
 function setCTM(someitem,m) { return someitem.transform.baseVal.initialize( someitem.ownerSVGElement.createSVGTransformFromMatrix(m)); } 

If instead of saving someItem.getCTM() you save someitem.transform.baseVal.getitem(0) , you can use:

 function setTransform(someitem,t) { return someitem.transform.baseVal.initialize(t)); } 
+5
source

Source: https://habr.com/ru/post/913936/


All Articles