From fb268dfaf5f97a5e1dd6be6f266a8473afdcf01b Mon Sep 17 00:00:00 2001 From: aki Date: Sat, 31 May 2008 03:39:43 +0530 Subject: [PATCH] Surface Class its over :) --- individual_files/phpCairoSurface.c | 195 ++++++++++++++++++++++++++++++++----- 1 file changed, 171 insertions(+), 24 deletions(-) diff --git a/individual_files/phpCairoSurface.c b/individual_files/phpCairoSurface.c index 62326cf..289b622 100644 --- a/individual_files/phpCairoSurface.c +++ b/individual_files/phpCairoSurface.c @@ -335,6 +335,7 @@ PHP_METHOD(CairoSurface, write_to_png_stream) /* }}} */ + static zend_function_entry CairoSurface_methods[] = { PHP_ME(CairoSurface, __construct, NULL, /**/ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) PHP_ME(CairoSurface, create_similar, CairoSurface__create_similar_args, /**/ZEND_ACC_PUBLIC) @@ -700,25 +701,70 @@ PHP_METHOD(CairoPDFSurface, __construct) { zend_class_entry * _this_ce; zval * _this_zval; - + zval *zstream = NULL; const char * file = NULL; int file_len = 0; double wpts = 0.0; double hpts = 0.0; + php_stream *stream; + int argc = ZEND_NUM_ARGS(); + zval ***args, *obj; + + args = (zval **)safe_emalloc(argc, sizeof(zval *),0); + if(ZEND_NUM_ARGS()== 0 || + zend_get_parameters_array_ex(argc, args)== FAILURE) { + printf("ERROR"); + efree(args); + WRONG_PARAM_COUNT; + } - - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sdd", &file, &file_len, &wpts, &hpts) == FAILURE) { - return; + obj = *(args[1]); + switch(Z_TYPE_P(obj)) { + case IS_DOUBLE: + wpts = Z_DVAL_P(obj); + break; + case IS_LONG: + wpts = Z_LVAL_P(obj); + break; + default : + printf("Error!!!"); + return; } + + obj = *(args[2]); + + switch(Z_TYPE_P(obj)) { + case IS_DOUBLE: + hpts = Z_DVAL_P(obj); + break; + case IS_LONG: + hpts = Z_LVAL_P(obj); + break; + default : + printf("Error!!!"); + return; + } + _this_zval = getThis(); _this_ce = Z_OBJCE_P(_this_zval); surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - curr->surface = cairo_pdf_surface_create(file, wpts, hpts); - - + + obj = *(args[0]); + if(Z_TYPE_P(obj)==IS_STRING) { + file = Z_STRVAL_P(obj); + curr->surface = cairo_pdf_surface_create(file, wpts, hpts); + } + else if(Z_TYPE_P(obj)==IS_RESOURCE) { + zstream = obj; + php_stream_from_zval(stream, &zstream); + curr->surface = cairo_pdf_surface_create_for_stream(_write_func, stream, wpts, hpts); + } + else { + printf("ERROR\n"); + } + efree(args); } /* }}} __construct */ @@ -784,28 +830,79 @@ static zend_object_handlers CairoPSSurface_handlers; /* {{{ Methods */ -/* {{{ proto void construct(string file, float wpts, float hpts) +/* {{{ proto void construct(string file | stream stream, float wpts, float hpts) */ PHP_METHOD(CairoPSSurface, __construct) { zend_class_entry * _this_ce; zval * _this_zval; - + zval *zstream = NULL; const char * file = NULL; int file_len = 0; double wpts = 0.0; double hpts = 0.0; + php_stream *stream; + int argc = ZEND_NUM_ARGS(); + zval ***args, *obj; + + args = (zval **)safe_emalloc(argc, sizeof(zval *),0); + if(ZEND_NUM_ARGS()== 0 || + zend_get_parameters_array_ex(argc, args)== FAILURE) { + printf("ERROR"); + efree(args); + WRONG_PARAM_COUNT; + } - - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sdd", &file, &file_len, &wpts, &hpts) == FAILURE) { - return; + obj = *(args[1]); + switch(Z_TYPE_P(obj)) { + case IS_DOUBLE: + wpts = Z_DVAL_P(obj); + break; + case IS_LONG: + wpts = Z_LVAL_P(obj); + break; + default : + printf("Error!!!"); + return; } + + obj = *(args[2]); + + switch(Z_TYPE_P(obj)) { + case IS_DOUBLE: + hpts = Z_DVAL_P(obj); + break; + case IS_LONG: + hpts = Z_LVAL_P(obj); + break; + default : + printf("Error!!!"); + return; + } + _this_zval = getThis(); _this_ce = Z_OBJCE_P(_this_zval); - surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - curr->surface = cairo_ps_surface_create(file, wpts, hpts); + surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + + obj = *(args[0]); + if(Z_TYPE_P(obj)==IS_STRING) { + file = Z_STRVAL_P(obj); + curr->surface = cairo_ps_surface_create(file, wpts, hpts); + } + else if(Z_TYPE_P(obj)==IS_RESOURCE) { + zstream = obj; + php_stream_from_zval(stream, &zstream); + curr->surface = cairo_ps_surface_create_for_stream(_write_func, stream, wpts, hpts); + } + else { + printf("ERROR\n"); + } + + efree(args); + + + } /* }}} __construct */ @@ -1118,6 +1215,8 @@ static void class_init_CairoQuartzSurface(void) static zend_class_entry * CairoSVGSurface_ce_ptr = NULL; static zend_object_handlers CairoSVGSurface_handlers; + + /* {{{ Methods */ @@ -1127,22 +1226,70 @@ PHP_METHOD(CairoSVGSurface, __construct) { zend_class_entry * _this_ce; zval * _this_zval; - + zval *zstream = NULL; const char * file = NULL; int file_len = 0; double wpts = 0.0; double hpts = 0.0; + php_stream *stream; + int argc = ZEND_NUM_ARGS(); + zval ***args, *obj; + + args = (zval **)safe_emalloc(argc, sizeof(zval *),0); + if(ZEND_NUM_ARGS()== 0 || + zend_get_parameters_array_ex(argc, args)== FAILURE) { + printf("ERROR"); + efree(args); + WRONG_PARAM_COUNT; + } - - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sdd", &file, &file_len, &wpts, &hpts) == FAILURE) { - return; + obj = *(args[1]); + switch(Z_TYPE_P(obj)) { + case IS_DOUBLE: + wpts = Z_DVAL_P(obj); + break; + case IS_LONG: + wpts = Z_LVAL_P(obj); + break; + default : + printf("error!!!"); + return; } + + obj = *(args[2]); + + switch(Z_TYPE_P(obj)) { + case IS_DOUBLE: + hpts = Z_DVAL_P(obj); + break; + case IS_LONG: + hpts = Z_LVAL_P(obj); + break; + default : + printf("Error!!!"); + return; + } + _this_zval = getThis(); _this_ce = Z_OBJCE_P(_this_zval); - surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - curr->surface = cairo_svg_surface_create(file, wpts, hpts); + surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC); + + obj = *(args[0]); + if(Z_TYPE_P(obj)==IS_STRING) { + file = Z_STRVAL_P(obj); + curr->surface = cairo_svg_surface_create(file, wpts, hpts); + } + else if(Z_TYPE_P(obj)==IS_RESOURCE) { + zstream = obj; + php_stream_from_zval(stream, &zstream); + curr->surface = cairo_svg_surface_create_for_stream(_write_func, stream, wpts, hpts); + } + else { + printf("ERROR\n"); + } + + efree(args); } @@ -1259,7 +1406,7 @@ PHP_METHOD(CairoXlibSurface, __construct) _this_zval = getThis(); surface_object *curr =(surface_object *)zend_objects_get_address(_this_zval TSRMLS_CC); - php_error(E_WARNING, "__construct: not yet implemented"); RETURN_FALSE; + php_error(E_WARNING, "Cannot Be Initialized"); RETURN_FALSE; } /* }}} __construct */ -- 2.11.4.GIT