views:

294

answers:

2

How can I determine the current transform that's being applied by an html5 canvas.

It seems that it only supports two methods for dealing with transforms "transform", "setTransform" but I can't seem to discover the results of applying the transforms.

Short of tracking them all myself and duplicating the the matrix mathematics that it must be doing natively, how can I figure out the current transform?

+1  A: 

You can look here for the functions that affect transformation:

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#transformations

If you use the setTransform function, then the current transform matrix is set to the identity matrix, then it uses what was set.

At that point you have the current transform matrix.

Now, if you are going to reset it, then start to call the other transformation methods, if you need to know what it is, it is easy to do the math to calculate the transformation matrix, so just do the operations, using your own transformation functions, then you can set the transform, as you have calculated it.

If you can't do that, then you are currently out of luck, but this post also has the same problem, so you may want to petition to have a new function added, getTransform.

http://forums.whatwg.org/viewtopic.php?t=4164

James Black
thanks. that's exactly what I've been doing, just figured that they're doing them natively, and me doing the operations is just doing the work for nothing.
Allain Lalonde
+2  A: 

I've made a wrapper which adds this method to Canvas.

http://proceduralgraphics.blogspot.com/2010/03/canvas-wrapper-with-gettransform.html

Dave Lawrence