[cairo] Two usage questions( matrix and fill with dash stroke)

Bill Spitzak spitzak at thefoundry.co.uk
Wed Apr 9 11:00:31 PDT 2008

Fortunatly the 6-component matrix is far easier than the 4x4 matrix used 
for 3D:

cairo_matrix_t m = get_the_matrix();

double scale_x = hypot(m.xx, m.yx);
double scale_y = hypot(-m.xy, m.yy);
double rotate = atan2(m.xx, m.yx);
double rotate2 = atan2(-m.xy, m.yy);
double translate_x = m.x0;
double translate_y = m.y0;

If rotate==rotate2 then this will produce the correct values for a 
scale, rotate, translate calls in that order for Postscript/Cairo/PDF 
(some graphics apis such as OpenGL may take the three calls in the 
reverse order).

If rotate==-rotate2 then it is a reflection. Replace scale_y with 
-scale_y (I think...)

Else if rotate != rotate2 then the matrix has some "shear" which means 
that right angles are not preserved. There is no cairo api other than 
setting the matrix to produce this, and other graphics apis vary on 
whether they provide this and how it is specified. So you might just 
have to ignore this possibility.

If the determinant (m.xx*m.yy-m.yx*m.xy) is zero then it is a degenerate 
transform which transforms everything to a point or a line and the above 
results are garbage. It is best to skip these. You may be tempted to 
think you can figure out the rotation of the line but I have found that 
to be much harder than it looks.

If your api only takes a single scale then use the square root of the 

Warning: I may have the signs reversed on some of the above.

More information about the cairo mailing list