1 #include "php_cairo_api.h"
2 #include "CairoMatrix.h"
3 #include "CairoExceptionMacro.h"
4 #include "php_cairo_ce_ptr.h"
6 /* {{{ Class CairoMatrix */
8 //static zend_class_entry * CairoMatrix_ce_ptr = NULL;
13 /* {{{ proto void construct([float xx, float yx, float xy, float yy, float x0, float y0])
15 PHP_METHOD(CairoMatrix
, __construct
)
28 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|dddddd", &xx
, &yx
, &xy
, &yy
, &x0
, &y0
) == FAILURE
) {
32 _this_zval
= getThis();
33 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
34 cairo_matrix_init(&curr
->matrix
, xx
, yx
, xy
, yy
, x0
, y0
);
41 /* {{{ proto object initRotate(float radians)
43 PHP_METHOD(CairoMatrix
, initRotate
)
46 zval
* _this_zval
= NULL
;
47 cairo_matrix_t matrix
;
52 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Od", &_this_zval
, CairoMatrix_ce_ptr
, &radians
) == FAILURE
) {
56 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
57 cairo_matrix_init_rotate(&matrix
, radians
);
58 object_init_ex(return_value
, CairoMatrix_ce_ptr
);
59 matrix_object
*mobj
= (matrix_object
*)zend_objects_get_address(return_value TSRMLS_CC
);
60 mobj
->matrix
= matrix
;
66 /* {{{ proto void invert()
68 PHP_METHOD(CairoMatrix
, invert
)
71 zval
* _this_zval
= NULL
;
72 cairo_status_t status
;
75 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "O", &_this_zval
, CairoMatrix_ce_ptr
) == FAILURE
) {
79 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
80 status
= cairo_matrix_invert(&curr
->matrix
);
81 PHP_CAIRO_ERROR(status
);
87 /* {{{ proto object multiply(object o2)
89 PHP_METHOD(CairoMatrix
, multiply
)
92 zval
* _this_zval
= NULL
;
94 cairo_matrix_t result
;
98 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Oo", &_this_zval
, CairoMatrix_ce_ptr
, &o2
) == FAILURE
) {
102 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
103 matrix_object
*mobj
= (matrix_object
*)zend_objects_get_address(o2 TSRMLS_CC
);
104 cairo_matrix_multiply(&result
, &curr
->matrix
, &mobj
->matrix
);
105 object_init_ex(return_value
, CairoMatrix_ce_ptr
);
106 matrix_object
*mret
= (matrix_object
*)zend_objects_get_address(return_value TSRMLS_CC
);
107 mret
->matrix
= result
;
113 /* {{{ proto void rotate(float radians)
115 PHP_METHOD(CairoMatrix
, rotate
)
118 zval
* _this_zval
= NULL
;
119 double radians
= 0.0;
123 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Od", &_this_zval
, CairoMatrix_ce_ptr
, &radians
) == FAILURE
) {
127 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
128 cairo_matrix_rotate(&curr
->matrix
, radians
);
135 /* {{{ proto void scale(float sx, float xy)
137 PHP_METHOD(CairoMatrix
, scale
)
140 zval
* _this_zval
= NULL
;
146 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &sx
, &xy
) == FAILURE
) {
150 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
151 cairo_matrix_scale(&curr
->matrix
, sx
, xy
);
158 /* {{{ proto array transformDistance(float dx, float dy)
160 PHP_METHOD(CairoMatrix
, transformDistance
)
163 zval
* _this_zval
= NULL
;
169 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &dx
, &dy
) == FAILURE
) {
173 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
174 cairo_matrix_transform_distance(&curr
->matrix
, &dx
, &dy
);
176 array_init(return_value
);
177 add_assoc_double(return_value
, "x", dx
);
178 add_assoc_double(return_value
, "y", dy
);
181 /* }}} transformDistance */
185 /* {{{ proto array transformPoint(float x, float y)
187 PHP_METHOD(CairoMatrix
, transformPoint
)
190 zval
* _this_zval
= NULL
;
196 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &x
, &y
) == FAILURE
) {
201 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
202 cairo_matrix_transform_point(&curr
->matrix
, &x
, &y
);
203 array_init(return_value
);
204 add_assoc_double(return_value
, "x", x
);
205 add_assoc_double(return_value
, "y", y
);
208 /* }}} transformPoint */
212 /* {{{ proto void translate(float tx, float ty)
214 PHP_METHOD(CairoMatrix
, translate
)
217 zval
* _this_zval
= NULL
;
223 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &tx
, &ty
) == FAILURE
) {
227 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
228 cairo_matrix_translate(&curr
->matrix
, tx
, ty
);
234 static zend_function_entry CairoMatrix_methods
[] = {
235 PHP_ME(CairoMatrix
, __construct
, CairoMatrix____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
236 PHP_ME(CairoMatrix
, initRotate
, CairoMatrix__init_rotate_args
, /**/ZEND_ACC_PRIVATE
)
237 PHP_ME(CairoMatrix
, invert
, NULL
, /**/ZEND_ACC_PUBLIC
)
238 PHP_ME(CairoMatrix
, multiply
, CairoMatrix__multiply_args
, /**/ZEND_ACC_PUBLIC
)
239 PHP_ME(CairoMatrix
, rotate
, CairoMatrix__rotate_args
, /**/ZEND_ACC_PUBLIC
)
240 PHP_ME(CairoMatrix
, scale
, CairoMatrix__scale_args
, /**/ZEND_ACC_PUBLIC
)
241 PHP_ME(CairoMatrix
, transformDistance
, CairoMatrix__transform_distance_args
, /**/ZEND_ACC_PUBLIC
)
242 PHP_ME(CairoMatrix
, transformPoint
, CairoMatrix__transform_point_args
, /**/ZEND_ACC_PUBLIC
)
243 PHP_ME(CairoMatrix
, translate
, CairoMatrix__translate_args
, /**/ZEND_ACC_PUBLIC
)
249 static zend_object_handlers CairoMatrix_handlers
;
251 static void CairoMatrix_object_dtor(void *object
)
253 matrix_object
*matrix
= (matrix_object
*)object
;
254 zend_hash_destroy(matrix
->std
.properties
);
255 FREE_HASHTABLE(matrix
->std
.properties
);
260 static zend_object_value
CairoMatrix_object_new(zend_class_entry
*ce
)
262 zend_object_value retval
;
263 matrix_object
*matrix
;
265 matrix
= emalloc(sizeof(matrix_object
));
266 memset(matrix
,0,sizeof(matrix_object
));
268 ALLOC_HASHTABLE(matrix
->std
.properties
);
269 zend_hash_init(matrix
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
270 zend_hash_copy(matrix
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
271 retval
.handle
= zend_objects_store_put(matrix
, NULL
, (zend_objects_free_object_storage_t
)CairoMatrix_object_dtor
, NULL TSRMLS_CC
);
272 retval
.handlers
= &CairoMatrix_handlers
;
277 void class_init_CairoMatrix(void)
281 INIT_CLASS_ENTRY(ce
, "CairoMatrix", CairoMatrix_methods
);
282 CairoMatrix_ce_ptr
= zend_register_internal_class(&ce
);
283 CairoMatrix_ce_ptr
->create_object
= CairoMatrix_object_new
;
284 memcpy(&CairoMatrix_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
285 CairoMatrix_handlers
.clone_obj
= NULL
;
289 /* }}} Class CairoMatrix */