From 556d076744c0499063e6515608d5fa367d108b54 Mon Sep 17 00:00:00 2001 From: aki Date: Sat, 7 Jun 2008 01:03:52 +0530 Subject: [PATCH] Pattern Class is complete -- Testing to be done ;) --- individual_files/phpCairoPattern.c | 746 +++++++++++++++++++++++++++++++++++++ individual_files/phpCairoSurface.c | 41 ++ individual_files/php_phpCairo.h | 7 + 3 files changed, 794 insertions(+) create mode 100644 individual_files/phpCairoPattern.c diff --git a/individual_files/phpCairoPattern.c b/individual_files/phpCairoPattern.c new file mode 100644 index 0000000..8dc9d1b --- /dev/null +++ b/individual_files/phpCairoPattern.c @@ -0,0 +1,746 @@ + +/* {{{ Class CairoPattern */ + +static zend_class_entry * CairoPattern_ce_ptr = NULL; + +/* {{{ Methods */ + + +/* {{{ proto void contruct() + */ +PHP_METHOD(CairoPattern, __construct) +{ + zend_class_entry * _this_ce; + zval * _this_zval; + + + + if (ZEND_NUM_ARGS()>0) { + WRONG_PARAM_COUNT; + } + + + php_error(E_ERROR, "Pattern Cannot be initialized"); RETURN_FALSE; + +} +/* }}} __construct */ + + + +/* {{{ proto object get_matrix() + */ +PHP_METHOD(CairoPattern, get_matrix) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + cairo_matrix_t matrix; + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoPattern_ce_ptr) == FAILURE) { + return; + } + + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + _this_ce = Z_OBJCE_P(_this_zval); + + cairo_pattern_get_matrix(curr->pattern, &matrix); + object_init(return_value); + matrix_object *mobj = (matrix_object *)zend_objects_get_address(return_value TSRMLS_CC); + mobj->matrix = matrix; +} +/* }}} get_matrix */ + + + +/* {{{ proto void set_matrix(object m) + */ +PHP_METHOD(CairoPattern, set_matrix) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + zval * m = NULL; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oo", &_this_zval, CairoPattern_ce_ptr, &m) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + matrix_object *mobj = (matrix_object *)zend_objects_get_address(m TSRMLS_CC); + cairo_pattern_set_matrix(curr->pattern, &mobj->matrix); +} +/* }}} set_matrix */ + + +static zend_function_entry CairoPattern_methods[] = { + PHP_ME(CairoPattern, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(CairoPattern, get_matrix, NULL, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoPattern, set_matrix, CairoPattern__set_matrix_args, /**/ZEND_ACC_PUBLIC) + { NULL, NULL, NULL } +}; + +/* }}} Methods */ + +static zend_object_handlers CairoPattern_handlers; + +static void CairoPattern_object_dtor(void *object) +{ + pattern_object *pattern = (pattern_object *)object; + zend_hash_destroy(pattern->std.properties); + FREE_HASHTABLE(pattern->std.properties); + if(pattern->pattern){ + cairo_pattern_destroy(pattern->pattern); + } + efree(object); +} + +static zend_object_value CairoPattern_object_new(zend_class_entry *ce) +{ + zend_object_value retval; + pattern_object *pattern; + zval *temp; + pattern=emalloc(sizeof(pattern_object)); + memset(pattern,0,sizeof(pattern_object)); + pattern->std.ce = ce; + ALLOC_HASHTABLE(pattern->std.properties); + zend_hash_init(pattern->std.properties, 0, NULL, ZVAL_PTR_DTOR,0); + zend_hash_copy(pattern->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &temp, sizeof(zval *)); + retval.handle = zend_objects_store_put(pattern, NULL, (zend_objects_free_object_storage_t)CairoPattern_object_dtor, NULL TSRMLS_CC); + retval.handlers = &CairoPattern_handlers; + return retval; +} + + +static void class_init_CairoPattern(void) +{ + zend_class_entry ce; + + INIT_CLASS_ENTRY(ce, "CairoPattern", CairoPattern_methods); + CairoPattern_ce_ptr = zend_register_internal_class(&ce); + CairoPattern_ce_ptr->create_object = CairoPattern_object_new; + memcpy(&CairoPattern_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + CairoPattern_handlers.clone_obj = NULL; +} + +/* }}} Class CairoPattern */ + +/* {{{ Class CairoGradient */ + +static zend_class_entry * CairoGradient_ce_ptr = NULL; + +/* {{{ Methods */ + + +/* {{{ proto void construct() + */ +PHP_METHOD(CairoGradient, __contruct) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoGradient_ce_ptr) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + + + php_error(E_ERROR, "Gradient cannot be initialized"); RETURN_FALSE; + +} +/* }}} __contruct */ + + + +/* {{{ proto void add_color_stop_rgb(float offset, float red, float green, float blue) + */ +PHP_METHOD(CairoGradient, add_color_stop_rgb) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + double offset = 0.0; + double red = 0.0; + double green = 0.0; + double blue = 0.0; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odddd", &_this_zval, CairoGradient_ce_ptr, &offset, &red, &green, &blue) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_pattern_add_color_stop_rgb(curr->pattern, offset, red, green, blue); + php_CAIRO_PATTERN_ERROR(curr->pattern); +} +/* }}} add_color_stop_rgb */ + + + +/* {{{ proto void add_color_stop_rgba(float offset, float red, float green, float blue, float alpha) + */ +PHP_METHOD(CairoGradient, add_color_stop_rgba) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + double offset = 0.0; + double red = 0.0; + double green = 0.0; + double blue = 0.0; + double alpha = 0.0; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oddddd", &_this_zval, CairoGradient_ce_ptr, &offset, &red, &green, &blue, &alpha) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_pattern_add_color_stop_rgba(curr->pattern, offset, red, green, blue, alpha); + php_CAIRO_PATTERN_ERROR(curr->pattern); +} +/* }}} add_color_stop_rgba */ + + +static zend_function_entry CairoGradient_methods[] = { + PHP_ME(CairoGradient, __contruct, NULL, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoGradient, add_color_stop_rgb, CairoGradient__add_color_stop_rgb_args, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoGradient, add_color_stop_rgba, CairoGradient__add_color_stop_rgba_args, /**/ZEND_ACC_PUBLIC) + { NULL, NULL, NULL } +}; + +/* }}} Methods */ + +static zend_object_handlers CairoGradient_handlers; + +static zend_object_value CairoGradient_object_new(zend_class_entry *ce TSRMLS_CC) +{ + zend_object_value retval; + retval = CairoPattern_object_new(ce TSRMLS_CC); + retval.handlers = &CairoGradient_handlers; + return retval; +} + +static void class_init_CairoGradient(void) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "CairoGradient", CairoGradient_methods); + CairoGradient_ce_ptr = zend_register_internal_class_ex(&ce, CairoPattern_ce_ptr, "CairoPattern" TSRMLS_CC); + CairoGradient_ce_ptr->create_object = CairoGradient_object_new; + memcpy(&CairoGradient_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); +} + + +/* }}} Class CairoGradient */ + +/* {{{ Class CairoLinearGradient */ + +static zend_class_entry * CairoLinearGradient_ce_ptr = NULL; + +/* {{{ Methods */ + + +/* {{{ proto void construct(float x0, float y0, float x1, float y1) + */ +PHP_METHOD(CairoLinearGradient, __construct) +{ + zend_class_entry * _this_ce; + zval * _this_zval; + + double x0 = 0.0; + double y0 = 0.0; + double x1 = 0.0; + double y1 = 0.0; + + + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dddd", &x0, &y0, &x1, &y1) == FAILURE) { + return; + } + + _this_zval = getThis(); + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + curr->pattern = cairo_pattern_create_linear(x0, y0, x1, y1); + +} +/* }}} __construct */ + + + +/* {{{ proto array get_linear_points() + */ +PHP_METHOD(CairoLinearGradient, get_linear_points) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + double x0, y0, x1, y1; + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoLinearGradient_ce_ptr) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_pattern_get_linear_points(curr->pattern, &x0, &y0, &x1, &y1); + + array_init(return_value); + add_assoc_double(return_value, "x0", x0); + add_assoc_double(return_value, "y0", y0); + add_assoc_double(return_value, "x1", x1); + add_assoc_double(return_value, "y1", y1); + +} +/* }}} get_linear_points */ + + +static zend_function_entry CairoLinearGradient_methods[] = { + PHP_ME(CairoLinearGradient, __construct, CairoLinearGradient____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(CairoLinearGradient, get_linear_points, NULL, /**/ZEND_ACC_PUBLIC) + { NULL, NULL, NULL } +}; + +/* }}} Methods */ + +static zend_object_handlers CairoLinearGradient_handlers; + +static zend_object_value CairoLinearGradient_object_new(zend_class_entry *ce TSRMLS_CC) +{ + zend_object_value retval; + retval = CairoPattern_object_new(ce TSRMLS_CC); + retval.handlers = &CairoLinearGradient_handlers; + return retval; +} + +static void class_init_CairoLinearGradient(void) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "CairoLinearGradient", CairoLinearGradient_methods); + CairoLinearGradient_ce_ptr = zend_register_internal_class_ex(&ce, CairoGradient_ce_ptr, "CairoGradient" TSRMLS_CC); + CairoLinearGradient_ce_ptr->create_object = CairoLinearGradient_object_new; + memcpy(&CairoLinearGradient_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); +} + + +/* }}} Class CairoLinearGradient */ + +/* {{{ Class CairoRadialGradient */ + +static zend_class_entry * CairoRadialGradient_ce_ptr = NULL; + +/* {{{ Methods */ + + +/* {{{ proto void construct(float cx0, float cy0, float radius0, float cx1, float cy1, float radius1) + */ +PHP_METHOD(CairoRadialGradient, __constuct) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + double cx0 = 0.0; + double cy0 = 0.0; + double radius0 = 0.0; + double cx1 = 0.0; + double cy1 = 0.0; + double radius1 = 0.0; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odddddd", &_this_zval, CairoRadialGradient_ce_ptr, &cx0, &cy0, &radius0, &cx1, &cy1, &radius1) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + curr->pattern = cairo_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1); + +} +/* }}} __constuct */ + + + +/* {{{ proto array get_radial_circles() + */ +PHP_METHOD(CairoRadialGradient, get_radial_circles) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + double x0, y0, r0, x1, y1, r1; + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoRadialGradient_ce_ptr) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_pattern_get_radial_circles(curr->pattern, &x0, &y0, &r0, &x1, &y1, &r1); + + array_init(return_value); + add_assoc_double(return_value, "x0", x0); + add_assoc_double(return_value, "y0", y0); + add_assoc_double(return_value, "r0", r0); + add_assoc_double(return_value, "x1", x1); + add_assoc_double(return_value, "y1", y1); + add_assoc_double(return_value, "r1", r1); + +} +/* }}} get_radial_circles */ + + +static zend_function_entry CairoRadialGradient_methods[] = { + PHP_ME(CairoRadialGradient, __constuct, CairoRadialGradient____constuct_args, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoRadialGradient, get_radial_circles, NULL, /**/ZEND_ACC_PUBLIC) + { NULL, NULL, NULL } +}; + +/* }}} Methods */ + +static zend_object_handlers CairoRadialGradient_handlers; + +static zend_object_value CairoRadialGradient_object_new(zend_class_entry *ce TSRMLS_CC) +{ + zend_object_value retval; + retval = CairoPattern_object_new(ce TSRMLS_CC); + retval.handlers = &CairoRadialGradient_handlers; + return retval; +} + +static void class_init_CairoRadialGradient(void) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "CairoRadialGradient", CairoRadialGradient_methods); + CairoRadialGradient_ce_ptr = zend_register_internal_class_ex(&ce, CairoGradient_ce_ptr, "CairoGradient" TSRMLS_CC); + CairoRadialGradient_ce_ptr->create_object = CairoRadialGradient_object_new; + memcpy(&CairoRadialGradient_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); +} + +/* }}} Class CairoRadialGradient */ + +/* {{{ Class CairoSolidPattern */ + +static zend_class_entry * CairoSolidPattern_ce_ptr = NULL; + +/* {{{ Methods */ + + +/* {{{ proto void construct(float r, float g, float b [, float a]) + */ +PHP_METHOD(CairoSolidPattern, __construct) +{ + zend_class_entry * _this_ce; + zval * _this_zval; + + double r = 0.0; + double g = 0.0; + double b = 0.0; + double a = 1.0; + + + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddd|d", &r, &g, &b, &a) == FAILURE) { + return; + } + + _this_zval = getThis(); + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + curr->pattern = cairo_pattern_create_rgba(r, g, b, a); + +} +/* }}} __construct */ + + + +/* {{{ proto array get_rgba() + */ +PHP_METHOD(CairoSolidPattern, get_rgba) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + double r,g,b,a; + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSolidPattern_ce_ptr) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_pattern_get_rgba(curr->pattern, &r, &g, &b, &a); + + array_init(return_value); + add_assoc_double(return_value, "red", r); + add_assoc_double(return_value, "green", g); + add_assoc_double(return_value, "blue", b); + add_assoc_double(return_value, "alpha", a); + +} +/* }}} get_rgba */ + + +static zend_function_entry CairoSolidPattern_methods[] = { + PHP_ME(CairoSolidPattern, __construct, CairoSolidPattern____construct_args, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(CairoSolidPattern, get_rgba, NULL, /**/ZEND_ACC_PUBLIC) + { NULL, NULL, NULL } +}; + +/* }}} Methods */ + +static zend_object_handlers CairoSolidPattern_handlers; + +static zend_object_value CairoSolidPattern_object_new(zend_class_entry *ce TSRMLS_CC) +{ + zend_object_value retval; + retval = CairoPattern_object_new(ce TSRMLS_CC); + retval.handlers = &CairoSolidPattern_handlers; + return retval; + +} + +static void class_init_CairoSolidPattern(void) +{ + zend_class_entry ce; + + INIT_CLASS_ENTRY(ce, "CairoSolidPattern", CairoSolidPattern_methods); + CairoSolidPattern_ce_ptr = zend_register_internal_class_ex(&ce, CairoPattern_ce_ptr, "CairoPattern" TSRMLS_CC); + CairoSolidPattern_ce_ptr->create_object = CairoSolidPattern_object_new; + memcpy(&CairoSolidPattern_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); +} + +/* }}} Class CairoSolidPattern */ + +/* {{{ Class CairoSurfacePattern */ + +static zend_class_entry * CairoSurfacePattern_ce_ptr = NULL; + +/* {{{ Methods */ + + +/* {{{ proto void construct(object s) + */ +PHP_METHOD(CairoSurfacePattern, __construct) +{ + zend_class_entry * _this_ce; + zval * _this_zval; + + zval * s = NULL; + + + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &s) == FAILURE) { + return; + } + + _this_zval = getThis(); + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + surface_object *sobj = (surface_object *)zend_objects_get_address(s TSRMLS_CC); + curr->pattern = cairo_pattern_create_for_surface(sobj->surface); + +} +/* }}} __construct */ + + + +/* {{{ proto int get_extend() + */ +PHP_METHOD(CairoSurfacePattern, get_extend) +{ + zend_class_entry * _this_ce; + long extend; + zval * _this_zval = NULL; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurfacePattern_ce_ptr) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + + extend = cairo_pattern_get_extend(curr->pattern); + RETURN_LONG(extend); + +} +/* }}} get_extend */ + + + +/* {{{ proto int get_filter() + */ +PHP_METHOD(CairoSurfacePattern, get_filter) +{ + zend_class_entry * _this_ce; + int filter; + zval * _this_zval = NULL; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurfacePattern_ce_ptr) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + filter = cairo_pattern_get_filter(curr->pattern); + RETURN_LONG(filter); +} +/* }}} get_filter */ + + + +/* {{{ proto object get_surface() + */ +PHP_METHOD(CairoSurfacePattern, get_surface) +{ + zend_class_entry * _this_ce; + zend_class_entry *surface_ce; + cairo_surface_t *surface; + zval * _this_zval = NULL; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &_this_zval, CairoSurfacePattern_ce_ptr) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_pattern_get_surface(curr->pattern, &surface); + surface_ce = get_CairoSurface_ce_ptr(surface); + + object_init_ex(return_value,surface_ce); + surface_object *sobj = (surface_object *)zend_objects_get_address(return_value TSRMLS_CC); + sobj->surface = cairo_surface_reference(surface); +} +/* }}} get_surface */ + + + +/* {{{ proto void set_extend(int extend) + */ +PHP_METHOD(CairoSurfacePattern, set_extend) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + long extend = 0; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &_this_zval, CairoSurfacePattern_ce_ptr, &extend) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + cairo_pattern_set_extend(curr->pattern, extend); + +} +/* }}} set_extend */ + + + +/* {{{ proto void set_filter(int filter) + */ +PHP_METHOD(CairoSurfacePattern, set_filter) +{ + zend_class_entry * _this_ce; + + zval * _this_zval = NULL; + long filter = 0; + + + + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &_this_zval, CairoSurfacePattern_ce_ptr, &filter) == FAILURE) { + return; + } + + _this_ce = Z_OBJCE_P(_this_zval); + pattern_object *curr = (pattern_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + + cairo_pattern_set_filter(curr->pattern, filter); +} +/* }}} set_filter */ + + +static zend_function_entry CairoSurfacePattern_methods[] = { + PHP_ME(CairoSurfacePattern, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(CairoSurfacePattern, get_extend, NULL, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoSurfacePattern, get_filter, NULL, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoSurfacePattern, get_surface, NULL, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoSurfacePattern, set_extend, CairoSurfacePattern__set_extend_args, /**/ZEND_ACC_PUBLIC) + PHP_ME(CairoSurfacePattern, set_filter, CairoSurfacePattern__set_filter_args, /**/ZEND_ACC_PUBLIC) + { NULL, NULL, NULL } +}; + +/* }}} Methods */ + +static zend_object_handlers CairoSurfacePattern_handlers; + +static zend_object_value CairoSurfacePattern_object_new(zend_class_entry *ce TSRMLS_CC) +{ + zend_object_value retval; + retval = CairoPattern_object_new(ce TSRMLS_CC); + retval.handlers = &CairoSurfacePattern_handlers; + return retval; +} + +static void class_init_CairoSurfacePattern(void) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "CairoSurfacePattern", CairoSurfacePattern_methods); + CairoSurfacePattern_ce_ptr = zend_register_internal_class_ex(&ce, CairoPattern_ce_ptr, "CairoPattern" TSRMLS_CC); + CairoSurfacePattern_ce_ptr->create_object = CairoSurfacePattern_object_new; + memcpy(&CairoSurfacePattern_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); +} + + +/* }}} Class CairoSurfacePattern */ + +/* {{{ Helper functions */ + +zend_class_entry * +get_CairoPattern_ce_ptr(cairo_pattern_t *pattern) +{ + zend_class_entry *type; + if(pattern == NULL) + return NULL; + switch(cairo_pattern_get_type(pattern)) { + case CAIRO_PATTERN_TYPE_SOLID: + type = CairoSolidPattern_ce_ptr; + break; + case CAIRO_PATTERN_TYPE_SURFACE: + type = CairoSurfacePattern_ce_ptr; + break; + case CAIRO_PATTERN_TYPE_LINEAR: + type = CairoLinearGradient_ce_ptr; + break; + case CAIRO_PATTERN_TYPE_RADIAL: + type = CairoRadialGradient_ce_ptr; + break; + default: + php_error(E_ERROR,"Unsupported Pattern"); + return NULL; + } + return type; +} +/* }}} Helper functions */ + diff --git a/individual_files/phpCairoSurface.c b/individual_files/phpCairoSurface.c index 289b622..4a53e27 100644 --- a/individual_files/phpCairoSurface.c +++ b/individual_files/phpCairoSurface.c @@ -1515,3 +1515,44 @@ static void class_init_CairoXlibSurface(void) } /* }}} Class CairoXlibSurface */ + +/* {{{ Helper Functions */ +zend_class_entry * +get_CairoSurface_ce_ptr(cairo_surface_t *surface) +{ + zend_class_entry *type; + if(surface == NULL) + return; + + switch(cairo_surface_get_type(surface)) { + case CAIRO_SURFACE_TYPE_IMAGE: + type = CairoImageSurface_ce_ptr; + break; + case CAIRO_SURFACE_TYPE_PDF: + type = CairoPDFSurface_ce_ptr; + break; + case CAIRO_SURFACE_TYPE_PS: + type = CairoPSSurface_ce_ptr; + break; + case CAIRO_SURFACE_TYPE_SVG: + type = CairoSVGSurface_ce_ptr; + break; + case CAIRO_SURFACE_TYPE_WIN32: + type = CairoWin32Surface_ce_ptr; + break; + case CAIRO_SURFACE_TYPE_XLIB: + type = CairoXlibSurface_ce_ptr; + break; + case CAIRO_SURFACE_TYPE_QUARTZ: + type = CairoQuartzSurface_ce_ptr; + break; + default: + php_error(E_ERROR,"Unsupported Surface Type"); + return NULL; + } + return type; +} + +/* }}} Helper Function*/ + + diff --git a/individual_files/php_phpCairo.h b/individual_files/php_phpCairo.h index 9e12fb1..b06f374 100644 --- a/individual_files/php_phpCairo.h +++ b/individual_files/php_phpCairo.h @@ -1778,6 +1778,13 @@ ZEND_END_ARG_INFO() #endif /* PHP_PHPCAIRO_H */ +/* {{{ Proto's */ + +zend_class_entry* get_CairoSurface_ce_ptr(cairo_surface_t *); +zend_class_entry* get_CairoPattern_ce_ptr(cairo_pattern_t *); + +/* }}} */ + /* * Local variables: -- 2.11.4.GIT