Updating checkpoint ...
[phpCairo.git] / src / cairo / CairoMatrix.c
blobf2f0bbf061b87fe6ebb576038cfe733d843271c5
1 /* {{{ Class CairoMatrix */
3 static zend_class_entry * CairoMatrix_ce_ptr = NULL;
5 /* {{{ Methods */
8 /* {{{ proto void construct([float xx, float yx, float xy, float yy, float x0, float y0])
9 */
10 PHP_METHOD(CairoMatrix, __construct)
12 zval * _this_zval;
14 double xx = 1.0;
15 double yx = 0.0;
16 double xy = 0.0;
17 double yy = 1.0;
18 double x0 = 0.0;
19 double y0 = 0.0;
23 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|dddddd", &xx, &yx, &xy, &yy, &x0, &y0) == FAILURE) {
24 return;
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);
32 /* }}} __construct */
36 /* {{{ proto object initRotate(float radians)
38 PHP_METHOD(CairoMatrix, initRotate)
41 zval * _this_zval = NULL;
42 cairo_matrix_t matrix;
43 double radians = 0.0;
47 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Od", &_this_zval, CairoMatrix_ce_ptr, &radians) == FAILURE) {
48 return;
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;
57 /* }}} initRotate */
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) {
71 return;
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);
78 /* }}} invert */
82 /* {{{ proto object multiply(object o2)
84 PHP_METHOD(CairoMatrix, multiply)
87 zval * _this_zval = NULL;
88 zval * o2 = 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) {
94 return;
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;
104 /* }}} multiply */
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) {
119 return;
122 matrix_object *curr = (matrix_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
123 cairo_matrix_rotate(&curr->matrix, radians);
126 /* }}} rotate */
130 /* {{{ proto void scale(float sx, float xy)
132 PHP_METHOD(CairoMatrix, scale)
135 zval * _this_zval = NULL;
136 double sx = 1.0;
137 double xy = 1.0;
141 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &sx, &xy) == FAILURE) {
142 return;
145 matrix_object *curr = (matrix_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
146 cairo_matrix_scale(&curr->matrix, sx, xy);
149 /* }}} scale */
153 /* {{{ proto array transformDistance(float dx, float dy)
155 PHP_METHOD(CairoMatrix, transformDistance)
158 zval * _this_zval = NULL;
159 double dx = 0.0;
160 double dy = 0.0;
164 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &dx, &dy) == FAILURE) {
165 return;
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;
186 double x = 0.0;
187 double y = 0.0;
191 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &x, &y) == FAILURE) {
192 return;
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;
213 double tx = 0.0;
214 double ty = 0.0;
218 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &tx, &ty) == FAILURE) {
219 return;
222 matrix_object *curr = (matrix_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
223 cairo_matrix_translate(&curr->matrix, tx, ty);
226 /* }}} translate */
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)
239 { NULL, NULL, NULL }
242 /* }}} Methods */
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);
251 efree(object);
255 static zend_object_value CairoMatrix_object_new(zend_class_entry *ce)
257 zend_object_value retval;
258 matrix_object *matrix;
259 zval *temp;
260 matrix = emalloc(sizeof(matrix_object));
261 memset(matrix,0,sizeof(matrix_object));
262 matrix->std.ce = ce;
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;
268 return retval;
272 static void class_init_CairoMatrix(void)
274 zend_class_entry ce;
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 */