On html5 canvas I am drawing objects (rectangle, circle, etc...), these objects have transformation properties like scale, skew, rotation etc... These objects can be nested.
Tom Larkworthy's answer is perfect, but with a minor typo. Correct formula to invert the matrix is:
[ d/M -c/M (c*dy - d*dx)/M ] [ -b/M a/M (b*dx - a*dy)/M ] [ 0 0 1 ]