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
rotate()
, scale()
, and
translate
methods 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 |
---|
Matrix()
Construct a new transformation matrix with the identity (no-op)
transform.
|
public Matrix()
public void rotate(double angle)
angle
is in radians.
matrix.rotate(-Math.PI / 4.0); cr.transform(matrix);
A negative angle is used in this example for the same reason as
discussed in
arc()
.
public void scale(double sx, double sy)
sx
horizontally and sy
vertically.
matrix.scale(-0.8, 1.6); cr.transform(matrix);Note that in this example the
sx
argument 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.0
would have left the widths alone.
Don't scale by 0
.
public void translate(double tx, double ty)
tx
horizontally and ty
vertically.
matrix.translate(5, 10); cr.transform(matrix);