Cairo: A Vector Graphics Library |
---|
cairo_matrix_tcairo_matrix_t — Transformation matrices |
typedef cairo_matrix_t; cairo_matrix_t* cairo_matrix_create (void); void cairo_matrix_destroy (cairo_matrix_t *matrix); cairo_status_t cairo_matrix_copy (cairo_matrix_t *matrix, const cairo_matrix_t *other); cairo_status_t cairo_matrix_set_identity (cairo_matrix_t *matrix); cairo_status_t cairo_matrix_set_affine (cairo_matrix_t *matrix, double a, double b, double c, double d, double tx, double ty); cairo_status_t cairo_matrix_get_affine (cairo_matrix_t *matrix, double *a, double *b, double *c, double *d, double *tx, double *ty); cairo_status_t cairo_matrix_translate (cairo_matrix_t *matrix, double tx, double ty); cairo_status_t cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy); cairo_status_t cairo_matrix_rotate (cairo_matrix_t *matrix, double radians); cairo_status_t cairo_matrix_invert (cairo_matrix_t *matrix); cairo_status_t cairo_matrix_multiply (cairo_matrix_t *result, const cairo_matrix_t *a, const cairo_matrix_t *b); cairo_status_t cairo_matrix_transform_distance (cairo_matrix_t *matrix, double *dx, double *dy); cairo_status_t cairo_matrix_transform_point (cairo_matrix_t *matrix, double *x, double *y);
cairo_matrix_t is used throughout Cairo to represents between different coordinates spaces. A cairo_matrix holds an affine transformation, such as a scale, rotation, or shear, or a combination of those. Mathematically, the effect of an affine transformation on a point (x,y) is given by:
x_new = x * a + y * c + tx; y_new = x * b + y * d + ty;
The parameters a, b, c, d, tx, ty can be retrieved with cairo_matrix_get_affine() and set with cairo_matrix_get_affine().
The primary use of transformation matrices in Cairo is as the current transformation matrix in a cairo_t. The current transformation matrix gives the transformation from user space coordinates to device coordinates. See cairo_set_matrix(), cairo_current_matrix().
cairo_matrix_t* cairo_matrix_create (void);
Creates a new identity matrix.
>
Returns : | a newly created matrix; free with cairo_matrix_destroy(), or NULL if memory couldn't be allocated. |
void cairo_matrix_destroy (cairo_matrix_t *matrix);
Frees a matrix created with cairo_matrix_create.
matrix : | a cairo_matrix_t |
cairo_status_t cairo_matrix_copy (cairo_matrix_t *matrix, const cairo_matrix_t *other);
Modifies matrix to be identical to other.
matrix : | a cairo_matrix_t |
other : | another cairo_ |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_set_identity (cairo_matrix_t *matrix);
Modifies matrix to be an identity transformation.
matrix : | a cairo_matrix_t |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_set_affine (cairo_matrix_t *matrix, double a, double b, double c, double d, double tx, double ty);
Sets matrix to be the affine transformation given by a, b, c, d, tx, ty. The transformation is given by:
x_new = x * a + y * c + tx; y_new = x * b + y * d + ty;
matrix : | a cairo_matrix_t |
a : | a component of the affine transformation |
b : | b component of the affine transformation |
c : | c component of the affine transformation |
d : | d component of the affine transformation |
tx : | X translation component of the affine transformation |
ty : | Y translation component of the affine transformation |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_get_affine (cairo_matrix_t *matrix, double *a, double *b, double *c, double *d, double *tx, double *ty);
Gets the matrix values for the affine tranformation that matrix represents. See cairo_matrix_set_affine().
matrix : | a cairo_matrix_t |
a : | location to store a component of affine transformation, or NULL |
b : | location to store b component of affine transformation, or NULL |
c : | location to store c component of affine transformation, or NULL |
d : | location to store d component of affine transformation, or NULL |
tx : | location to store X-translation component of affine transformation, or NULL |
ty : | location to store Y-translation component of affine transformation, or NULL |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_translate (cairo_matrix_t *matrix, double tx, double ty);
Applies a translation by tx, ty to the transformation in matrix. The new transformation is given by first translating by tx, ty then applying the original transformation
matrix : | a cairo_matrix_t |
tx : | amount to rotate in the X direction |
ty : | amount to rotate in the Y direction |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy);
Applies scaling by tx, ty to the transformation in matrix. The new transformation is given by first scaling by sx and sy then applying the original transformation
matrix : | a cairo_matrix_t |
sx : | Scale factor in the X direction |
sy : | Scale factor in the Y direction |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_rotate (cairo_matrix_t *matrix, double radians);
Applies rotation by radians to the transformation in matrix. The new transformation is given by first rotating by radians then applying the original transformation
matrix : | a cairo_matrix_t |
radians : | angle of rotation, in radians. Angles are defined so that an angle of 90 degrees (M_PI radians) rotates the positive X axis into the positive Y axis. With the default Cairo choice of axis orientation, positive rotations are clockwise. |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_invert (cairo_matrix_t *matrix);
Changes matrix to be the inverse of it's original value. Not all transformation matrices have inverses; if the matrix collapses points together (it is degenerate), then it has no inverse and this function will fail.
Returns: If matrix has an inverse, modifies matrix to be the inverse matrix and returns CAIRO_STATUS_SUCCESS. Otherwise,
matrix : | a cairo_matrix_t |
Returns : | CAIRO_STATUS_INVALID_MATRIX. |
cairo_status_t cairo_matrix_multiply (cairo_matrix_t *result, const cairo_matrix_t *a, const cairo_matrix_t *b);
Multiplies the affine transformations in a and b together and stores the result in result. The resulting transformation is given by first applying the transformation in b then applying the transformation in a.
result : | a cairo_matrix_t in which to store the result |
a : | a cairo_matrix_t |
b : | a cairo_matrix_t |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_transform_distance (cairo_matrix_t *matrix, double *dx, double *dy);
Transforms the vector (dx,dy) by matrix. Translation is ignored. In terms of the components of the affine transformation:
dx2 = dx1 * a + dy1 * c; dy2 = dx1 * b + dy1 * d;
Affine transformations are position invariant, so the same vector always transforms to the same vector. If (x1,y1) transforms to (x2,y2) then (x1+dx1,y1+dy1) will transform to (x1+dx2,y1+dy2) for all values of x1 and x2.
matrix : | a cairo_matrix_t |
dx : | a distance in the X direction. An in/out parameter |
dy : | a distance in the Y direction. An in/out parameter |
Returns : | CAIRO_STATUS_SUCCESS, always. |
cairo_status_t cairo_matrix_transform_point (cairo_matrix_t *matrix, double *x, double *y);
Transforms the point (x, y) by matrix.
matrix : | a cairo_matrix_t |
x : | X position. An in/out parameter |
y : | Y position. An in/out parameter |
Returns : | CAIRO_STATUS_SUCCESS, always. |
<< cairo_pattern_t | ATSUI Fonts >> |