1 /* {{{ Class CairoMatrix */
3 static zend_class_entry
* CairoMatrix_ce_ptr
= NULL
;
8 /* {{{ proto void construct([float xx, float yx, float xy, float yy, float x0, float y0])
10 PHP_METHOD(CairoMatrix
, __construct
)
23 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|dddddd", &xx
, &yx
, &xy
, &yy
, &x0
, &y0
) == FAILURE
) {
27 _this_zval
= getThis();
28 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
29 cairo_matrix_init(&curr
->matrix
, xx
, yx
, xy
, yy
, x0
, y0
);
36 /* {{{ proto object initRotate(float radians)
38 PHP_METHOD(CairoMatrix
, initRotate
)
41 zval
* _this_zval
= NULL
;
42 cairo_matrix_t matrix
;
47 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Od", &_this_zval
, CairoMatrix_ce_ptr
, &radians
) == FAILURE
) {
51 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
52 cairo_matrix_init_rotate(&matrix
, radians
);
53 object_init_ex(return_value
, CairoMatrix_ce_ptr
);
54 matrix_object
*mobj
= (matrix_object
*)zend_objects_get_address(return_value TSRMLS_CC
);
55 mobj
->matrix
= matrix
;
61 /* {{{ proto void invert()
63 PHP_METHOD(CairoMatrix
, invert
)
66 zval
* _this_zval
= NULL
;
67 cairo_status_t status
;
70 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoMatrix_ce_ptr
) == FAILURE
) {
74 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
75 status
= cairo_matrix_invert(&curr
->matrix
);
76 PHP_CAIRO_ERROR(status
);
82 /* {{{ proto object multiply(object o2)
84 PHP_METHOD(CairoMatrix
, multiply
)
87 zval
* _this_zval
= NULL
;
89 cairo_matrix_t result
;
93 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Oo", &_this_zval
, CairoMatrix_ce_ptr
, &o2
) == FAILURE
) {
97 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
98 matrix_object
*mobj
= (matrix_object
*)zend_objects_get_address(o2 TSRMLS_CC
);
99 cairo_matrix_multiply(&result
, &curr
->matrix
, &mobj
->matrix
);
100 object_init_ex(return_value
, CairoMatrix_ce_ptr
);
101 matrix_object
*mret
= (matrix_object
*)zend_objects_get_address(return_value TSRMLS_CC
);
102 mret
->matrix
= result
;
108 /* {{{ proto void rotate(float radians)
110 PHP_METHOD(CairoMatrix
, rotate
)
113 zval
* _this_zval
= NULL
;
114 double radians
= 0.0;
118 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Od", &_this_zval
, CairoMatrix_ce_ptr
, &radians
) == FAILURE
) {
122 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
123 cairo_matrix_rotate(&curr
->matrix
, radians
);
130 /* {{{ proto void scale(float sx, float xy)
132 PHP_METHOD(CairoMatrix
, scale
)
135 zval
* _this_zval
= NULL
;
141 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &sx
, &xy
) == FAILURE
) {
145 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
146 cairo_matrix_scale(&curr
->matrix
, sx
, xy
);
153 /* {{{ proto array transformDistance(float dx, float dy)
155 PHP_METHOD(CairoMatrix
, transformDistance
)
158 zval
* _this_zval
= NULL
;
164 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &dx
, &dy
) == FAILURE
) {
168 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
169 cairo_matrix_transform_distance(&curr
->matrix
, &dx
, &dy
);
171 array_init(return_value
);
172 add_assoc_double(return_value
, "x", dx
);
173 add_assoc_double(return_value
, "y", dy
);
176 /* }}} transformDistance */
180 /* {{{ proto array transformPoint(float x, float y)
182 PHP_METHOD(CairoMatrix
, transformPoint
)
185 zval
* _this_zval
= NULL
;
191 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &x
, &y
) == FAILURE
) {
196 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
197 cairo_matrix_transform_point(&curr
->matrix
, &x
, &y
);
198 array_init(return_value
);
199 add_assoc_double(return_value
, "x", x
);
200 add_assoc_double(return_value
, "y", y
);
203 /* }}} transformPoint */
207 /* {{{ proto void translate(float tx, float ty)
209 PHP_METHOD(CairoMatrix
, translate
)
212 zval
* _this_zval
= NULL
;
218 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &tx
, &ty
) == FAILURE
) {
222 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
223 cairo_matrix_translate(&curr
->matrix
, tx
, ty
);
229 static zend_function_entry CairoMatrix_methods
[] = {
230 PHP_ME(CairoMatrix
, __construct
, CairoMatrix____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
231 PHP_ME(CairoMatrix
, initRotate
, CairoMatrix__init_rotate_args
, /**/ZEND_ACC_PRIVATE
)
232 PHP_ME(CairoMatrix
, invert
, NULL
, /**/ZEND_ACC_PUBLIC
)
233 PHP_ME(CairoMatrix
, multiply
, CairoMatrix__multiply_args
, /**/ZEND_ACC_PUBLIC
)
234 PHP_ME(CairoMatrix
, rotate
, CairoMatrix__rotate_args
, /**/ZEND_ACC_PUBLIC
)
235 PHP_ME(CairoMatrix
, scale
, CairoMatrix__scale_args
, /**/ZEND_ACC_PUBLIC
)
236 PHP_ME(CairoMatrix
, transformDistance
, CairoMatrix__transform_distance_args
, /**/ZEND_ACC_PUBLIC
)
237 PHP_ME(CairoMatrix
, transformPoint
, CairoMatrix__transform_point_args
, /**/ZEND_ACC_PUBLIC
)
238 PHP_ME(CairoMatrix
, translate
, CairoMatrix__translate_args
, /**/ZEND_ACC_PUBLIC
)
244 static zend_object_handlers CairoMatrix_handlers
;
246 static void CairoMatrix_object_dtor(void *object
)
248 matrix_object
*matrix
= (matrix_object
*)object
;
249 zend_hash_destroy(matrix
->std
.properties
);
250 FREE_HASHTABLE(matrix
->std
.properties
);
255 static zend_object_value
CairoMatrix_object_new(zend_class_entry
*ce
)
257 zend_object_value retval
;
258 matrix_object
*matrix
;
260 matrix
= emalloc(sizeof(matrix_object
));
261 memset(matrix
,0,sizeof(matrix_object
));
263 ALLOC_HASHTABLE(matrix
->std
.properties
);
264 zend_hash_init(matrix
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
265 zend_hash_copy(matrix
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
266 retval
.handle
= zend_objects_store_put(matrix
, NULL
, (zend_objects_free_object_storage_t
)CairoMatrix_object_dtor
, NULL TSRMLS_CC
);
267 retval
.handlers
= &CairoMatrix_handlers
;
272 static void class_init_CairoMatrix(void)
276 INIT_CLASS_ENTRY(ce
, "CairoMatrix", CairoMatrix_methods
);
277 CairoMatrix_ce_ptr
= zend_register_internal_class(&ce
);
278 CairoMatrix_ce_ptr
->create_object
= CairoMatrix_object_new
;
279 memcpy(&CairoMatrix_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
280 CairoMatrix_handlers
.clone_obj
=NULL
;
284 /* }}} Class CairoMatrix */