Debugs continue ...
[phpCairo.git] / individual_files / phpCairoMatrix.c
blob83c828021457c288e7c328b7c3a5b021a0a5a2b9
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 zend_class_entry * _this_ce;
13 zval * _this_zval;
15 double xx = 1.0;
16 double yx = 0.0;
17 double xy = 0.0;
18 double yy = 1.0;
19 double x0 = 0.0;
20 double y0 = 0.0;
24 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|dddddd", &xx, &yx, &xy, &yy, &x0, &y0) == FAILURE) {
25 return;
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);
34 /* }}} __construct */
38 /* {{{ proto object init_rotate(float radians)
40 PHP_METHOD(CairoMatrix, init_rotate)
42 zend_class_entry * _this_ce;
44 zval * _this_zval = NULL;
45 cairo_matrix_t matrix;
46 double radians = 0.0;
50 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Od", &_this_zval, CairoMatrix_ce_ptr, &radians) == FAILURE) {
51 return;
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;
61 /* }}} init_rotate */
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) {
76 return;
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);
84 /* }}} invert */
88 /* {{{ proto object multiply(object o2)
90 PHP_METHOD(CairoMatrix, multiply)
92 zend_class_entry * _this_ce;
94 zval * _this_zval = NULL;
95 zval * o2 = 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) {
101 return;
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;
112 /* }}} multiply */
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) {
128 return;
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);
136 /* }}} rotate */
140 /* {{{ proto void scale(float sx, float xy)
142 PHP_METHOD(CairoMatrix, scale)
144 zend_class_entry * _this_ce;
146 zval * _this_zval = NULL;
147 double sx = 1.0;
148 double xy = 1.0;
152 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &sx, &xy) == FAILURE) {
153 return;
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);
161 /* }}} scale */
165 /* {{{ proto array transform_distance(float dx, float dy)
167 PHP_METHOD(CairoMatrix, transform_distance)
169 zend_class_entry * _this_ce;
171 zval * _this_zval = NULL;
172 double dx = 0.0;
173 double dy = 0.0;
177 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &dx, &dy) == FAILURE) {
178 return;
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 /* }}} transform_distance */
194 /* {{{ proto array transform_point(float x, float y)
196 PHP_METHOD(CairoMatrix, transform_point)
198 zend_class_entry * _this_ce;
200 zval * _this_zval = NULL;
201 double x = 0.0;
202 double y = 0.0;
206 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &x, &y) == FAILURE) {
207 return;
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 /* }}} transform_point */
223 /* {{{ proto void translate(float tx, float ty)
225 PHP_METHOD(CairoMatrix, translate)
227 zend_class_entry * _this_ce;
229 zval * _this_zval = NULL;
230 double tx = 0.0;
231 double ty = 0.0;
235 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &tx, &ty) == FAILURE) {
236 return;
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);
244 /* }}} translate */
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, init_rotate, 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, transform_distance, CairoMatrix__transform_distance_args, /**/ZEND_ACC_PUBLIC)
255 PHP_ME(CairoMatrix, transform_point, CairoMatrix__transform_point_args, /**/ZEND_ACC_PUBLIC)
256 PHP_ME(CairoMatrix, translate, CairoMatrix__translate_args, /**/ZEND_ACC_PUBLIC)
257 { NULL, NULL, NULL }
260 /* }}} Methods */
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);
269 efree(object);
273 static zend_object_value CairoMatrix_object_new(zend_class_entry *ce)
275 zend_object_value retval;
276 matrix_object *matrix;
277 zval *temp;
278 matrix = emalloc(sizeof(matrix_object));
279 memset(matrix,0,sizeof(matrix_object));
280 matrix->std.ce = ce;
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;
286 return retval;
290 static void class_init_CairoMatrix(void)
292 zend_class_entry ce;
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 */