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
)
12 zend_class_entry
* _this_ce
;
24 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|dddddd", &xx
, &yx
, &xy
, &yy
, &x0
, &y0
) == FAILURE
) {
28 _this_zval
= getThis();
29 _this_ce
= Z_OBJCE_P(_this_zval
);
30 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
31 cairo_matrix_init(&curr
->matrix
, xx
, yx
, xy
, yy
, x0
, y0
);
38 /* {{{ proto object initRotate(float radians)
40 PHP_METHOD(CairoMatrix
, initRotate
)
42 zend_class_entry
* _this_ce
;
44 zval
* _this_zval
= NULL
;
45 cairo_matrix_t matrix
;
50 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Od", &_this_zval
, CairoMatrix_ce_ptr
, &radians
) == FAILURE
) {
54 _this_ce
= Z_OBJCE_P(_this_zval
);
55 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
56 cairo_matrix_init_rotate(&matrix
, radians
);
57 object_init_ex(return_value
, CairoMatrix_ce_ptr
);
58 matrix_object
*mobj
= (matrix_object
*)zend_objects_get_address(return_value TSRMLS_CC
);
59 mobj
->matrix
= matrix
;
65 /* {{{ proto void invert()
67 PHP_METHOD(CairoMatrix
, invert
)
69 zend_class_entry
* _this_ce
;
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 _this_ce
= Z_OBJCE_P(_this_zval
);
80 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
81 status
= cairo_matrix_invert(&curr
->matrix
);
82 phpCAIRO_ERROR(status
);
88 /* {{{ proto object multiply(object o2)
90 PHP_METHOD(CairoMatrix
, multiply
)
92 zend_class_entry
* _this_ce
;
94 zval
* _this_zval
= NULL
;
96 cairo_matrix_t result
;
100 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Oo", &_this_zval
, CairoMatrix_ce_ptr
, &o2
) == FAILURE
) {
104 _this_ce
= Z_OBJCE_P(_this_zval
);
105 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
106 matrix_object
*mobj
= (matrix_object
*)zend_objects_get_address(o2 TSRMLS_CC
);
107 cairo_matrix_multiply(&result
, &curr
->matrix
, &mobj
->matrix
);
108 object_init_ex(return_value
, CairoMatrix_ce_ptr
);
109 matrix_object
*mret
= (matrix_object
*)zend_objects_get_address(return_value TSRMLS_CC
);
110 mret
->matrix
= result
;
116 /* {{{ proto void rotate(float radians)
118 PHP_METHOD(CairoMatrix
, rotate
)
120 zend_class_entry
* _this_ce
;
122 zval
* _this_zval
= NULL
;
123 double radians
= 0.0;
127 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Od", &_this_zval
, CairoMatrix_ce_ptr
, &radians
) == FAILURE
) {
131 _this_ce
= Z_OBJCE_P(_this_zval
);
132 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
133 cairo_matrix_rotate(&curr
->matrix
, radians
);
140 /* {{{ proto void scale(float sx, float xy)
142 PHP_METHOD(CairoMatrix
, scale
)
144 zend_class_entry
* _this_ce
;
146 zval
* _this_zval
= NULL
;
152 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &sx
, &xy
) == FAILURE
) {
156 _this_ce
= Z_OBJCE_P(_this_zval
);
157 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
158 cairo_matrix_scale(&curr
->matrix
, sx
, xy
);
165 /* {{{ proto array transformDistance(float dx, float dy)
167 PHP_METHOD(CairoMatrix
, transformDistance
)
169 zend_class_entry
* _this_ce
;
171 zval
* _this_zval
= NULL
;
177 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &dx
, &dy
) == FAILURE
) {
181 _this_ce
= Z_OBJCE_P(_this_zval
);
182 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
183 cairo_matrix_transform_distance(&curr
->matrix
, &dx
, &dy
);
185 array_init(return_value
);
186 add_assoc_double(return_value
, "x", dx
);
187 add_assoc_double(return_value
, "y", dy
);
190 /* }}} transformDistance */
194 /* {{{ proto array transformPoint(float x, float y)
196 PHP_METHOD(CairoMatrix
, transformPoint
)
198 zend_class_entry
* _this_ce
;
200 zval
* _this_zval
= NULL
;
206 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &x
, &y
) == FAILURE
) {
210 _this_ce
= Z_OBJCE_P(_this_zval
);
212 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
213 cairo_matrix_transform_point(&curr
->matrix
, &x
, &y
);
214 array_init(return_value
);
215 add_assoc_double(return_value
, "x", x
);
216 add_assoc_double(return_value
, "y", y
);
219 /* }}} transformPoint */
223 /* {{{ proto void translate(float tx, float ty)
225 PHP_METHOD(CairoMatrix
, translate
)
227 zend_class_entry
* _this_ce
;
229 zval
* _this_zval
= NULL
;
235 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, getThis(), "Odd", &_this_zval
, CairoMatrix_ce_ptr
, &tx
, &ty
) == FAILURE
) {
239 _this_ce
= Z_OBJCE_P(_this_zval
);
240 matrix_object
*curr
= (matrix_object
*)zend_objects_get_address(_this_zval TSRMLS_CC
);
241 cairo_matrix_translate(&curr
->matrix
, tx
, ty
);
247 static zend_function_entry CairoMatrix_methods
[] = {
248 PHP_ME(CairoMatrix
, __construct
, CairoMatrix____construct_args
, /**/ZEND_ACC_PUBLIC
| ZEND_ACC_CTOR
)
249 PHP_ME(CairoMatrix
, initRotate
, CairoMatrix__init_rotate_args
, /**/ZEND_ACC_PRIVATE
)
250 PHP_ME(CairoMatrix
, invert
, NULL
, /**/ZEND_ACC_PUBLIC
)
251 PHP_ME(CairoMatrix
, multiply
, CairoMatrix__multiply_args
, /**/ZEND_ACC_PUBLIC
)
252 PHP_ME(CairoMatrix
, rotate
, CairoMatrix__rotate_args
, /**/ZEND_ACC_PUBLIC
)
253 PHP_ME(CairoMatrix
, scale
, CairoMatrix__scale_args
, /**/ZEND_ACC_PUBLIC
)
254 PHP_ME(CairoMatrix
, transformDistance
, CairoMatrix__transform_distance_args
, /**/ZEND_ACC_PUBLIC
)
255 PHP_ME(CairoMatrix
, transformPoint
, CairoMatrix__transform_point_args
, /**/ZEND_ACC_PUBLIC
)
256 PHP_ME(CairoMatrix
, translate
, CairoMatrix__translate_args
, /**/ZEND_ACC_PUBLIC
)
262 static zend_object_handlers CairoMatrix_handlers
;
264 static void CairoMatrix_object_dtor(void *object
)
266 matrix_object
*matrix
= (matrix_object
*)object
;
267 zend_hash_destroy(matrix
->std
.properties
);
268 FREE_HASHTABLE(matrix
->std
.properties
);
273 static zend_object_value
CairoMatrix_object_new(zend_class_entry
*ce
)
275 zend_object_value retval
;
276 matrix_object
*matrix
;
278 matrix
= emalloc(sizeof(matrix_object
));
279 memset(matrix
,0,sizeof(matrix_object
));
281 ALLOC_HASHTABLE(matrix
->std
.properties
);
282 zend_hash_init(matrix
->std
.properties
, 0, NULL
, ZVAL_PTR_DTOR
,0);
283 zend_hash_copy(matrix
->std
.properties
, &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, (void *) &temp
, sizeof(zval
*));
284 retval
.handle
= zend_objects_store_put(matrix
, NULL
, (zend_objects_free_object_storage_t
)CairoMatrix_object_dtor
, NULL TSRMLS_CC
);
285 retval
.handlers
= &CairoMatrix_handlers
;
290 static void class_init_CairoMatrix(void)
294 INIT_CLASS_ENTRY(ce
, "CairoMatrix", CairoMatrix_methods
);
295 CairoMatrix_ce_ptr
= zend_register_internal_class(&ce
);
296 CairoMatrix_ce_ptr
->create_object
= CairoMatrix_object_new
;
297 memcpy(&CairoMatrix_handlers
, zend_get_std_object_handlers(), sizeof(zend_object_handlers
));
298 CairoMatrix_handlers
.clone_obj
=NULL
;
302 /* }}} Class CairoMatrix */