public class Matrix extends org.freedesktop.bindings.Proxy
You can apply this transformation to a Cairo Context with its
transform() method as follows:
matrix = new Matrix(); matrix.rotate(...); // and/or matrix.scale(...); // and/or matrix.translate(...); cr.transform(matrix);Calls to the
translatemethods are cumulative on a given Matrix.
Applying a transformation is what take you from device co-ordinates to user-space co-ordinates; you are in fact always working in the later but we tend not to focus on this as the default is naturally no transformation.
In each of the illustrations below, we draw a box as follows:
cr.setSource(0.7, 0.8, 0.8); cr.rectangle(5, 5, 25, 15); cr.stroke();We then apply the transform shown, change colour to blue, and then draw the exact same rectangle again:
cr.setSource(0.0, 0.0, 1.0); cr.rectangle(5, 5, 25, 15); cr.stroke();Thus both the original rectangle and the result of the matrix operation are shown.
|Constructor and Description|
Construct a new transformation matrix with the identity (no-op) transform.
|Modifier and Type||Method and Description|
Rotate the transformation by the given angle.
public void rotate(double angle)
angleis in radians.
matrix.rotate(-Math.PI / 4.0); cr.transform(matrix);
A negative angle is used in this example for the same reason as
public void scale(double sx, double sy)
matrix.scale(-0.8, 1.6); cr.transform(matrix);Note that in this example the
sxargument being negative results in a reflection through the y axis. Note also that the line widths are not the same as the original image's were; only scaling by
1.0would have left the widths alone.
Don't scale by
public void translate(double tx, double ty)
matrix.translate(5, 10); cr.transform(matrix);