Updating checkpoint ...
[phpCairo.git] / src / cairo / CairoPath.c
blob9fdeac0390696b0f464b47f269bc15e62fe1c08b
1 /* {{{ Class CairoPath */
3 static zend_class_entry * CairoPath_ce_ptr = NULL;
5 /* {{{ Methods */
8 /* {{{ proto void construct()
9 */
10 PHP_METHOD(CairoPath, __construct)
12 zval * _this_zval;
16 if (ZEND_NUM_ARGS()>0) {
17 WRONG_PARAM_COUNT;
21 php_error(E_WARNING, "Can not call directly"); RETURN_FALSE;
24 /* }}} __construct */
28 /* {{{ proto array toStr()
30 PHP_METHOD(CairoPath, toStr)
33 zval * _this_zval = NULL;
35 _this_zval = getThis();
36 path_object *curr = (path_object *)zend_objects_get_address(_this_zval TSRMLS_CC);
38 cairo_path_t *path = curr->path;
39 array_init(return_value);
41 cairo_path_data_t *data;
42 int i, ret;
43 char buf[80];
45 for (i=0; i < path->num_data; i += path->data[i].header.length) {
46 data = &path->data[i];
47 switch (data->header.type) {
48 case CAIRO_PATH_MOVE_TO:
49 sprintf(buf, "move_to %f %f", data[1].point.x, data[1].point.y);
50 add_next_index_string(return_value, buf, 1);
51 break;
52 case CAIRO_PATH_LINE_TO:
53 sprintf(buf, "line_to %f %f", data[1].point.x, data[1].point.y);
54 add_next_index_string(return_value, buf, 1);
55 break;
56 case CAIRO_PATH_CURVE_TO:
57 sprintf(buf, "curve_to %f %f %f %f %f %f", data[1].point.x, data[1].point.y, data[2].point.x, data[2].point.y, data[3].point.x, data[3].point.y);
58 add_next_index_string(return_value, buf, 1);
59 break;
60 case CAIRO_PATH_CLOSE_PATH:
61 sprintf(buf, "close_path");
62 add_next_index_string(return_value, buf, 1);
63 break;
67 //free(buf);
69 /* }}} str */
72 static zend_function_entry CairoPath_methods[] = {
73 PHP_ME(CairoPath, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
74 PHP_ME(CairoPath, toStr, NULL, /**/ZEND_ACC_PUBLIC)
75 { NULL, NULL, NULL }
78 /* }}} Methods */
80 static zend_object_handlers CairoPath_handlers;
83 static void CairoPath_object_dtor(void *object)
85 path_object *path = (path_object *)object;
86 zend_hash_destroy(path->std.properties);
87 FREE_HASHTABLE(path->std.properties);
89 if(path->path){
90 cairo_path_destroy(path->path);
92 efree(object);
95 static zend_object_value CairoPath_object_new(zend_class_entry *ce)
97 zend_object_value retval;
98 path_object *path;
99 zval *temp;
101 path=emalloc(sizeof(path_object));
102 memset(path,0,sizeof(path_object));
103 path->std.ce = ce;
104 ALLOC_HASHTABLE(path->std.properties);
105 zend_hash_init(path->std.properties, 0, NULL, ZVAL_PTR_DTOR,0);
106 zend_hash_copy(path->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &temp, sizeof(zval *));
107 retval.handle = zend_objects_store_put(path, NULL, (zend_objects_free_object_storage_t)CairoPath_object_dtor, NULL TSRMLS_CC);
108 retval.handlers = &CairoPath_handlers;
109 return retval;
112 static void class_init_CairoPath(void)
114 zend_class_entry ce;
116 INIT_CLASS_ENTRY(ce, "CairoPath", CairoPath_methods);
117 CairoPath_ce_ptr = zend_register_internal_class(&ce);
118 CairoPath_ce_ptr->create_object = CairoPath_object_new;
119 memcpy(&CairoPath_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
120 CairoPath_handlers.clone_obj=NULL;
124 /* }}} Class CairoPath */