2
* Java-Gnome Bindings Library
4
* Copyright 1998-2005 the Java-Gnome Team, all rights reserved.
6
* The Java-Gnome bindings library is free software distributed under
7
* the terms of the GNU Library General Public License version 2.
9
package org.freedesktop.cairo;
11
import org.gnu.glib.Struct;
12
import org.gnu.glib.Handle;
15
* TODO: error handling
17
public class Matrix extends CairoObject {
24
* Creates a new matrix initialized with a noop transform.
27
super(new_identity_matrix());
31
* Disposes all the native resources used by the matrix.
33
protected void finalize() throws Throwable {
34
free_matrix(getHandle());
39
* Sets the matrix to be the affine transformation given by xx, yx, xy, yy,
40
* x0, y0. The transformation is given by: <code>
41
* x_new = xx * x + xy * y + x0;
42
* y_new = yx * x + yy * y + y0;
45
public void init(double xx, double yx, double xy, double yy, double x0,
47
cairo_matrix_init(getHandle(), xx, yx, xy, yy, x0, y0);
51
* Modifies the matrix to be an identity transformation.
53
public void initIdentity() {
54
cairo_matrix_init_identity(getHandle());
58
* Initializes the matrix to a transformation that translates by tx and ty
59
* in the X and Y dimensions, respectively.
62
* amount to translate in the X direction.
64
* amount to translate in the Y direction.
66
public void initTranslate(double tx, double ty) {
67
cairo_matrix_init_translate(getHandle(), tx, ty);
71
* Initializes the matrix to a transformation that scales by sx and sy in
72
* the X and Y dimensions, respectively.
75
* scale factor in the X direction.
77
* scale factor in the Y direction.
79
public void initScale(double sx, double sy) {
80
cairo_matrix_init_scale(getHandle(), sx, sy);
84
* Initialized the matrix to a transformation that rotates by
89
* angle of rotation, in radians. The direction of rotation is
90
* defined such that positive angles rotate in the direction from
91
* the positive X axis toward the positive Y axis. With the
92
* default axis orientation of cairo, positive angles rotate in a
93
* clockwise direction.
95
public void initRotate(double radians) {
96
cairo_matrix_init_rotate(getHandle(), radians);
100
* Appends a transaltion transformation to this matrix.
107
public void translate(double tx, double ty) {
108
cairo_matrix_translate(getHandle(), tx, ty);
112
* Appends non-uniform scaling to this matrix.
115
* X axis scaling factor
117
* Y axis scaling factor
119
public void scale(double sx, double sy) {
120
cairo_matrix_scale(getHandle(), sx, sy);
124
* Appends rotation transformation to this matrix.
127
* The rotation angle in radians.
129
public void rotate(double radians) {
130
cairo_matrix_rotate(getHandle(), radians);
134
* Inverts this matrix.
136
public void invert() {
137
cairo_matrix_invert(getHandle());
141
* Multiplies 2 matrices and returns the result.
147
* @return The product
149
static public Matrix multiply(Matrix a, Matrix b) {
150
Handle hndl = cairo_matrix_multiply(a.getHandle(), b.getHandle());
151
return new Matrix(hndl);
155
* Transforms the given distance and returns transformed co-ordinates
157
public Point transformDistance(Point distance) {
158
double[] dx = new double[] { distance.getX() };
159
double[] dy = new double[] { distance.getY() };
160
cairo_matrix_transform_distance(getHandle(), dx, dy);
161
return new Point(dx[0], dy[0]);
165
* Transforms the given point and returns transformed co-ordinates
167
public Point transformPoint(Point point) {
168
double[] dx = new double[] { point.getX() };
169
double[] dy = new double[] { point.getY() };
170
cairo_matrix_transform_distance(getHandle(), dx, dy);
171
return new Point(dx[0], dy[0]);
174
public double getXX() {
175
return getXX(getHandle());
178
public void setXX(double xx) {
179
setXX(getHandle(), xx);
182
public double getYX() {
183
return getYX(getHandle());
186
public void setYX(double yx) {
187
setYX(getHandle(), yx);
190
public double getXY() {
191
return getXY(getHandle());
194
public void setXY(double xy) {
195
setXY(getHandle(), xy);
198
public double getYY() {
199
return getYY(getHandle());
202
public void setYY(double yy) {
203
setYY(getHandle(), yy);
206
public double getX0() {
207
return getX0(getHandle());
210
public void setX0(double x0) {
211
setX0(getHandle(), x0);
214
public double getY0() {
215
return getY0(getHandle());
218
public void setY0(double y0) {
219
setY0(getHandle(), y0);
225
native static final private double getXX(Handle matrix);
227
native static final private double getYX(Handle matrix);
229
native static final private double getXY(Handle matrix);
231
native static final private double getYY(Handle matrix);
233
native static final private double getX0(Handle matrix);
235
native static final private double getY0(Handle matrix);
237
native static final private void setXX(Handle matrix, double xx);
239
native static final private void setYX(Handle matrix, double yx);
241
native static final private void setXY(Handle matrix, double xy);
243
native static final private void setYY(Handle matrix, double yy);
245
native static final private void setX0(Handle matrix, double x0);
247
native static final private void setY0(Handle matrix, double y0);
249
native static final private Handle new_identity_matrix();
251
native static final private void free_matrix(Handle matrix);
253
native static final private void cairo_matrix_init(Handle matrix,
254
double xx, double yx, double xy, double yy, double x0, double y0);
256
native static final private void cairo_matrix_init_identity(Handle matrix);
258
native static final private void cairo_matrix_init_translate(Handle matrix,
259
double tx, double ty);
261
native static final private void cairo_matrix_init_scale(Handle matrix,
262
double sx, double sy);
264
native static final private void cairo_matrix_init_rotate(Handle matrix,
267
native static final private void cairo_matrix_translate(Handle matrix,
268
double tx, double ty);
270
native static final private void cairo_matrix_scale(Handle matrix,
271
double sx, double sy);
273
native static final private void cairo_matrix_rotate(Handle matrix,
276
native static final private void cairo_matrix_invert(Handle matrix);
278
native static final private Handle cairo_matrix_multiply(Handle a,
281
native static final private void cairo_matrix_transform_distance(
282
Handle handle, double[] dx, double[] dy);
284
native static final private void cairo_matrix_transform_point(
285
Handle handle, double[] x, double[] y);