Changed the entire file structure to remove the .c includes from cairo.c
[phpCairo.git] / src / cairo / CairoMatrix.c
blob0024af34dddaa1751e3cb3a6fda003aa5934ce11
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;
10 /* {{{ Methods */
13 /* {{{ proto void construct([float xx, float yx, float xy, float yy, float x0, float y0])
15 PHP_METHOD(CairoMatrix, __construct)
17 zval * _this_zval;
19 double xx = 1.0;
20 double yx = 0.0;
21 double xy = 0.0;
22 double yy = 1.0;
23 double x0 = 0.0;
24 double y0 = 0.0;
28 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|dddddd", &xx, &yx, &xy, &yy, &x0, &y0) == FAILURE) {
29 return;
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);
37 /* }}} __construct */
41 /* {{{ proto object initRotate(float radians)
43 PHP_METHOD(CairoMatrix, initRotate)
46 zval * _this_zval = NULL;
47 cairo_matrix_t matrix;
48 double radians = 0.0;
52 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Od", &_this_zval, CairoMatrix_ce_ptr, &radians) == FAILURE) {
53 return;
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;
62 /* }}} initRotate */
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) {
76 return;
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);
83 /* }}} invert */
87 /* {{{ proto object multiply(object o2)
89 PHP_METHOD(CairoMatrix, multiply)
92 zval * _this_zval = NULL;
93 zval * o2 = 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) {
99 return;
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;
109 /* }}} multiply */
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) {
124 return;
127 matrix_object *curr = (matrix_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
128 cairo_matrix_rotate(&curr->matrix, radians);
131 /* }}} rotate */
135 /* {{{ proto void scale(float sx, float xy)
137 PHP_METHOD(CairoMatrix, scale)
140 zval * _this_zval = NULL;
141 double sx = 1.0;
142 double xy = 1.0;
146 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &sx, &xy) == FAILURE) {
147 return;
150 matrix_object *curr = (matrix_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
151 cairo_matrix_scale(&curr->matrix, sx, xy);
154 /* }}} scale */
158 /* {{{ proto array transformDistance(float dx, float dy)
160 PHP_METHOD(CairoMatrix, transformDistance)
163 zval * _this_zval = NULL;
164 double dx = 0.0;
165 double dy = 0.0;
169 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &dx, &dy) == FAILURE) {
170 return;
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;
191 double x = 0.0;
192 double y = 0.0;
196 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &x, &y) == FAILURE) {
197 return;
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;
218 double tx = 0.0;
219 double ty = 0.0;
223 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odd", &_this_zval, CairoMatrix_ce_ptr, &tx, &ty) == FAILURE) {
224 return;
227 matrix_object *curr = (matrix_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
228 cairo_matrix_translate(&curr->matrix, tx, ty);
231 /* }}} translate */
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)
244 { NULL, NULL, NULL }
247 /* }}} Methods */
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);
256 efree(object);
260 static zend_object_value CairoMatrix_object_new(zend_class_entry *ce)
262 zend_object_value retval;
263 matrix_object *matrix;
264 zval *temp;
265 matrix = emalloc(sizeof(matrix_object));
266 memset(matrix,0,sizeof(matrix_object));
267 matrix->std.ce = ce;
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;
273 return retval;
277 void class_init_CairoMatrix(void)
279 zend_class_entry ce;
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 */