#include "nsIDOMSVGMatrix.h"#include "gfxMatrix.h"#include "nsAutoPtr.h"

Defines | |
| #define | NS_ENSURE_NATIVE_MATRIX(obj, retval) |
Functions | |
| nsresult | NS_NewSVGMatrix (nsIDOMSVGMatrix **result, float a=1.0f, float b=0.0f, float c=0.0f, float d=1.0f, float e=0.0f, float f=0.0f) |
| Notes on transforms in Mozilla and the SVG code. | |
| already_AddRefed< nsIDOMSVGMatrix > | NS_NewSVGMatrix (const gfxMatrix &aMatrix) |
| #define NS_ENSURE_NATIVE_MATRIX | ( | obj, | |||
| retval | ) |
{ \
nsresult rv; \
if (retval) \
*retval = nsnull; \
nsCOMPtr<nsISVGValue> val = do_QueryInterface(obj, &rv); \
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_SVG_WRONG_TYPE_ERR); \
}
| already_AddRefed<nsIDOMSVGMatrix> NS_NewSVGMatrix | ( | const gfxMatrix & | aMatrix | ) |
| nsresult NS_NewSVGMatrix | ( | nsIDOMSVGMatrix ** | result, | |
| float | a = 1.0f, |
|||
| float | b = 0.0f, |
|||
| float | c = 0.0f, |
|||
| float | d = 1.0f, |
|||
| float | e = 0.0f, |
|||
| float | f = 0.0f | |||
| ) |
Notes on transforms in Mozilla and the SVG code.
It's important to note that the matrix convention used in the SVG standard is the opposite convention to the one used in the Mozilla code or, more specifically, the convention used in Thebes code (code using gfxMatrix). Whereas the SVG standard uses the column vector convention, Thebes code uses the row vector convention. Thus, whereas in the SVG standard you have [M1][M2][M3]|p|, in Thebes you have |p|'[M3]'[M2]'[M1]'. In other words, the following are equivalent:
/ a1 c1 tx1 \ / a2 c2 tx2 \ / a3 c3 tx3 \ / x \ SVG: | b1 d1 ty1 | | b2 d2 ty2 | | b3 d3 ty3 | | y | \ 0 0 1 / \ 0 0 1 / \ 0 0 1 / \ 1 /
/ a3 b3 0 \ / a2 b2 0 \ / a1 b1 0 \ Thebes: [ x y 1 ] | c3 d3 0 | | c2 d2 0 | | c1 d1 0 | \ tx3 ty3 1 / \ tx2 ty2 1 / \ tx1 ty1 1 /
Because the Thebes representation of a transform is the transpose of the SVG representation, our transform order must be reversed when representing SVG transforms using gfxMatrix in the SVG code. Since the SVG implementation stores and obtains matrices in SVG order, to do this we must pre-multiply gfxMatrix objects that represent SVG transforms instead of post-multiplying them as we would for matrices using SVG's column vector convention. Pre-multiplying may look wrong if you're only familiar with the SVG convention, but in that case hopefully the above explanation clears things up.
1.6.1