cvs: pecl /gdchart gdchart.c php_gdchart.h /gdchart/gdchart-src gdchart.c
| From: | Rasmus Lerdorf | Date: | Wed, 27 Aug 2003 22:49:11 +0000 |
| Subject: | cvs: pecl /gdchart gdchart.c php_gdchart.h /gdchart/gdchart-src gdchart.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-428@lists.php.net to get a copy of this message | ||
rasmus Wed Aug 27 18:49:11 2003 EDT
Modified files:
/pecl/gdchart gdchart.c php_gdchart.h
/pecl/gdchart/gdchart-src gdchart.c
Log:
Add support for scatter points
Add jpeg and png background image support to bundled gdchart backend code
Implement some missing attributes
Index: pecl/gdchart/gdchart.c diff -u pecl/gdchart/gdchart.c:1.3 pecl/gdchart/gdchart.c:1.4 --- pecl/gdchart/gdchart.c:1.3 Wed Aug 27 05:51:56 2003 +++ pecl/gdchart/gdchart.c Wed Aug 27 18:49:10 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Rasmus Lerdorf | +----------------------------------------------------------------------+ - $Id: gdchart.c,v 1.3 2003/08/27 09:51:56 rasmus Exp $ + $Id: gdchart.c,v 1.4 2003/08/27 22:49:10 rasmus Exp $ */ /* @@ -58,6 +58,7 @@ PHP_FALIAS(out, php_gdchart_out, NULL) PHP_FALIAS(add, php_gdchart_add_set, NULL) PHP_FALIAS(add_combo, php_gdchart_add_combo_set, NULL) + PHP_FALIAS(add_scatter, php_gdchart_add_scatter, NULL) {NULL, NULL, NULL} }; /* }}} */ @@ -84,7 +85,7 @@ ZEND_GET_MODULE(gdchart) #endif -#define PHPGDC_MAX_SYMBOLS 20 +#define PHPGDC_MAX_SYMBOLS 21 /* {{{ php_gdchart_symbol_table */ static php_gdchart_symbol_table php_gdc_symbol_table[PHPGDC_MAX_SYMBOLS][20] = { @@ -119,14 +120,15 @@ }, /* 7 */ { - {"missing", PHPGDC_BOOLEAN_ARRAY, &GDCPIE_missing, NULL, NULL }, - {"explode", PHPGDC_INT_ARRAY, &GDCPIE_explode, NULL, NULL }, - {"ytitle2", PHPGDC_STRING, &GDC_ytitle2, NULL, NULL }, + { "missing", PHPGDC_BOOLEAN_ARRAY, &GDCPIE_missing, NULL, NULL }, + { "explode", PHPGDC_INT_ARRAY, &GDCPIE_explode, NULL, NULL }, + { "ytitle2", PHPGDC_STRING, &GDC_ytitle2, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }, /* 8 */ { { "bg_color", PHPGDC_ULONG, &GDC_BGColor, &GDCPIE_BGColor, 0xffffffL }, + { "bg_image", PHPGDC_STRING, &GDC_BGImage, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }, /* 9 */ @@ -134,9 +136,12 @@ { "bar_width", PHPGDC_UCHAR, &GDC_bar_width, NULL, 75 }, { "cap_width", PHPGDC_UCHAR, &GDC_HLC_cap_width, NULL, 25 }, { "vol_color", PHPGDC_ULONG, &GDC_VolColor, NULL, 0xA0A0FF }, + { "ext_color", PHPGDC_ULONG_ARRAY, &GDC_ExtColor, NULL, NULL }, { "pie_angle", PHPGDC_USHORT, &GDCPIE_3d_angle, NULL, 45 }, { "pie_depth", PHPGDC_USHORT, &GDCPIE_3d_depth, NULL, 10 }, + { "thumbnail", PHPGDC_CHAR, &GDC_thumbnail, NULL, 0 }, { "hlc_style", PHPGDC_INT, &GDC_HLC_style, NULL, GDC_HLC_CLOSE_CONNECTED }, + { "hard_size", PHPGDC_CHAR, &GDC_hard_size, NULL, 0 }, { NULL, 0, NULL, NULL } }, /* 10 */ @@ -158,6 +163,8 @@ { "zero_shelf", PHPGDC_CHAR, &GDC_0Shelf, NULL, 1 }, { "stack_type", PHPGDC_INT, &GDC_stack_type, NULL, GDC_STACK_DEPTH }, { "yval_style", PHPGDC_CHAR, &GDC_yval_style, NULL, 1 }, + { "hard_xorig", PHPGDC_INT, &GDC_hard_xorig, NULL, 0 }, + { "hard_yorig", PHPGDC_INT, &GDC_hard_yorig, NULL, 0 }, { NULL, 0, NULL, NULL } }, /* 11 */ @@ -205,12 +212,15 @@ { "interpolations", PHPGDC_CHAR, &GDC_interpolations, NULL, 0 }, { "requested_ymin", PHPGDC_FLOAT, &GDC_requested_ymin, NULL, 0 }, { "requested_ymax", PHPGDC_FLOAT, &GDC_requested_ymax, NULL, 0 }, + { "transparent_bg", PHPGDC_CHAR, &GDC_transparent_bg, NULL, 0 }, + { "hard_grapheigt", PHPGDC_INT, &GDC_hard_grapheight, NULL, 0 }, { NULL, 0, NULL, NULL } }, /* 15 */ { { "annotation_font", PHPGDC_STRING, &GDC_annotation_font, NULL, NULL }, { "other_threshold", PHPGDC_CHAR, &GDCPIE_other_threshold, NULL, -1 }, + { "hard_graphwidth", PHPGDC_INT, &GDC_hard_graphwidth, NULL, 0 }, { NULL, 0, NULL, NULL } }, /* 16 */ @@ -230,6 +240,11 @@ { { "requested_yinterval", PHPGDC_FLOAT, &GDC_requested_yinterval, NULL, 0 }, { NULL, 0, NULL, NULL } + }, + /* 20 */ + { + { "annotation_font_size", PHPGDC_INT, &GDC_annotation_font_size, NULL, GDC_SMALL }, + { NULL, 0, NULL, NULL } } }; /* }}} */ @@ -423,6 +438,10 @@ REGISTER_LONG_CONSTANT("HLC_CONNECTING", GDC_HLC_CONNECTING, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("HLC_I_CAP", GDC_HLC_I_CAP, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SCATTER_TRIANGLE_DOWN", GDC_SCATTER_TRIANGLE_DOWN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SCATTER_TRIANGLE_UP", GDC_SCATTER_TRIANGLE_UP, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SCATTER_CIRCLE", GDC_SCATTER_CIRCLE, CONST_CS | CONST_PERSISTENT); + REGISTER_DOUBLE_CONSTANT("NOVALUE", (double)GDC_NOVALUE, CONST_CS | CONST_PERSISTENT); _gdchart_set_defaults(); @@ -450,6 +469,11 @@ } GDC_annotation = NULL; _gdchart_set_defaults(); + if(GDC_scatter) { + efree(GDC_scatter); + GDC_scatter = NULL; + } + GDC_num_scatter_pts = 0; } return SUCCESS; } @@ -805,6 +829,40 @@ } /* }}} */ +/* {{{ proto add_scatter() + Add a dataset */ +PHP_FUNCTION(php_gdchart_add_scatter) +{ + int argc = ZEND_NUM_ARGS(); + pval **arr, *tmp = NULL; + double val, point; + long ind, color, width=6; + + if(zend_parse_parameters(argc, "ddll|l", &val, &point, &ind, &color, &width) == FAILURE) { + return; + } + + if(zend_hash_find(this_ptr->value.obj.properties, "scatter", sizeof("scatter"), (void **)&arr)==FAILURE) { + zval *scatter; + + MAKE_STD_ZVAL(scatter); + array_init(scatter); + add_property_zval(this_ptr, "scatter", scatter); + arr = &scatter; + } + + MAKE_STD_ZVAL(tmp); + array_init(tmp); + add_next_index_double(tmp, val); + add_next_index_double(tmp, point); + add_next_index_long(tmp, ind); + add_next_index_long(tmp, color); + add_next_index_long(tmp, width); + + add_next_index_zval(*arr, tmp); +} +/* }}} */ + /* {{{ proto add() Add a dataset */ PHP_FUNCTION(php_gdchart_add_set) @@ -867,6 +925,7 @@ num_sets = 0, num_combo_sets = 0, i = 0, cnt = 0, ret = 0; FILE *fp = NULL; GDC_ANNOTATION_T anno; + GDC_SCATTER_T *scatter; if(zend_parse_parameters(argc, "ll|ls", &width, &height, &image_type, &fname, &fname_len) == FAILURE) { RETVAL_FALSE; @@ -1027,6 +1086,42 @@ } else labels = NULL; } + if(zend_hash_find(Z_OBJPROP_P(this_ptr), "scatter", sizeof("scatter"), (void **)&tmp)!=FAILURE) { + cnt = zend_hash_num_elements(Z_ARRVAL_PP(tmp)); + if(cnt) { + i = 0; + scatter = (GDC_SCATTER_T *)emalloc((cnt+1) * sizeof(GDC_SCATTER_T)); + zend_hash_internal_pointer_reset(Z_ARRVAL_PP(tmp)); + while (zend_hash_get_current_data(Z_ARRVAL_PP(tmp), (void **)&val) == SUCCESS) { + zend_hash_internal_pointer_reset(Z_ARRVAL_PP(val)); + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].val = (float)Z_DVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].point = (float)Z_DVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].ind = (GDC_SCATTER_IND_T) Z_LVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].color = (unsigned long) Z_LVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].width = (unsigned short)Z_LVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; +no_more: + i++; + zend_hash_move_forward(Z_ARRVAL_PP(tmp)); + } + } else scatter = NULL; + GDC_num_scatter_pts = cnt; + GDC_scatter = scatter; + } if(zend_hash_find(Z_OBJPROP_P(this_ptr), "anno_note", sizeof("anno_note"), (void **)&tmp)!=FAILURE) { convert_to_string_ex(tmp); Index: pecl/gdchart/php_gdchart.h diff -u pecl/gdchart/php_gdchart.h:1.2 pecl/gdchart/php_gdchart.h:1.3 --- pecl/gdchart/php_gdchart.h:1.2 Fri Aug 22 15:39:00 2003 +++ pecl/gdchart/php_gdchart.h Wed Aug 27 18:49:10 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Rasmus Lerdorf | +----------------------------------------------------------------------+ - $Id: php_gdchart.h,v 1.2 2003/08/22 19:39:00 rasmus Exp $ + $Id: php_gdchart.h,v 1.3 2003/08/27 22:49:10 rasmus Exp $ */ #ifndef PHP_GDCHART_H @@ -38,6 +38,7 @@ PHP_FUNCTION(php_gdchart_out); PHP_FUNCTION(php_gdchart_add_set); PHP_FUNCTION(php_gdchart_add_combo_set); +PHP_FUNCTION(php_gdchart_add_scatter); typedef struct _php_gdchart_symbol_table { char *name; Index: pecl/gdchart/gdchart-src/gdchart.c diff -u pecl/gdchart/gdchart-src/gdchart.c:1.3 pecl/gdchart/gdchart-src/gdchart.c:1.4 --- pecl/gdchart/gdchart-src/gdchart.c:1.3 Wed Aug 27 05:51:56 2003 +++ pecl/gdchart/gdchart-src/gdchart.c Wed Aug 27 18:49:11 2003 @@ -16,6 +16,7 @@ #include <errno.h> #include "gdchart.h" +#include "ext/standard/php_image.h" #define HIGHSET 0 #define LOWSET 1 @@ -985,17 +986,28 @@ /* attempt to import optional background image */ if( GDC_BGImage ) { - FILE *in = fopen(GDC_BGImage, "rb"); - if( !in ) - { - ; /* Cant load background image, drop it */ + php_stream *stream; + FILE *in = NULL; + + stream = php_stream_open_wrapper(GDC_BGImage, "rb", REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); + php_stream_cast(stream, PHP_STREAM_AS_STDIO | PHP_STREAM_CAST_TRY_HARD, (void**)&in, REPORT_ERRORS); + if( !in ) { + php_error_docref(NULL, E_WARNING, "Unable to open %s", GDC_BGImage); + } else { + int itype = php_getimagetype(stream, NULL); + php_stream_seek(stream,0,SEEK_SET); /* checking the image type moves the file pointer, so reset it */ + switch(itype) { + case IMAGE_FILETYPE_GIF: + bg_img = gdImageCreateFromGif(in); + break; + case IMAGE_FILETYPE_JPEG: + bg_img = gdImageCreateFromJpeg(in); + break; + case IMAGE_FILETYPE_PNG: + bg_img = gdImageCreateFromPng(in); + break; } - else - { - /* assume GIF */ - /* should determine type by file extension, option, ... */ - if( bg_img = gdImageCreateFromGif(in) ) /* = */ - { + if(bg_img) { int bgxpos = gdImageSX(bg_img)<IMGWIDTH? IMGWIDTH/2 - gdImageSX(bg_img)/2: 0, bgypos = gdImageSY(bg_img)<IMGHEIGHT? IMGHEIGHT/2 - gdImageSY(bg_img)/2: 0; @@ -1013,11 +1025,11 @@ gdImageCopy( im, bg_img, /* dst, src */ bgxpos, bgypos, /* dstX, dstY */ 0, 0, /* srcX, srcY */ - IMGWIDTH, IMGHEIGHT ); /* W, H */ - } - fclose(in); + IMGWIDTH, IMGHEIGHT ); /* W, H */ } + php_stream_close(stream); } + } for( j=0; j<num_sets; ++j ) for( i=0; i<num_points; ++i ) @@ -2029,10 +2041,12 @@ if( uniq_clr != -1L ) /* the safe way */ { #if HAVE_LIBGD204 - int uc = uniq_clr; + gdImageFilledArc( im, scat_x, scat_y, + hlf_scatterwdth*2, hlf_scatterwdth*2, + s, e, + scatter_clr[i], gdArc ); #else int uc = gdImageColorAllocate( im, l2gdcal(uniq_clr) ); -#endif gdImageArc( im, scat_x, scat_y, hlf_scatterwdth*2, hlf_scatterwdth*2, s, e, @@ -2051,9 +2065,16 @@ scat_x, scat_y-hlf_scatterwdth, scatter_clr[i] ); gdImageColorDeallocate( im, uc ); +#endif } else /* chance it */ { +#if HAVE_LIBGD204 + gdImageFilledArc( im, scat_x, scat_y, + hlf_scatterwdth*2, hlf_scatterwdth*2, + s, e, + scatter_clr[i], gdArc); +#else gdImageArc( im, scat_x, scat_y, hlf_scatterwdth*2, hlf_scatterwdth*2, s, e, @@ -2064,6 +2085,7 @@ scatter_clr[i] ); gdImageFillToBorder( im, scat_x+fo, scat_y, scatter_clr[i], scatter_clr[i] ); +#endif } } break;
Index: pecl/gdchart/gdchart.c diff -u pecl/gdchart/gdchart.c:1.3 pecl/gdchart/gdchart.c:1.4 --- pecl/gdchart/gdchart.c:1.3 Wed Aug 27 05:51:56 2003 +++ pecl/gdchart/gdchart.c Wed Aug 27 18:49:10 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Rasmus Lerdorf | +----------------------------------------------------------------------+ - $Id: gdchart.c,v 1.3 2003/08/27 09:51:56 rasmus Exp $ + $Id: gdchart.c,v 1.4 2003/08/27 22:49:10 rasmus Exp $ */ /* @@ -58,6 +58,7 @@ PHP_FALIAS(out, php_gdchart_out, NULL) PHP_FALIAS(add, php_gdchart_add_set, NULL) PHP_FALIAS(add_combo, php_gdchart_add_combo_set, NULL) + PHP_FALIAS(add_scatter, php_gdchart_add_scatter, NULL) {NULL, NULL, NULL} }; /* }}} */ @@ -84,7 +85,7 @@ ZEND_GET_MODULE(gdchart) #endif -#define PHPGDC_MAX_SYMBOLS 20 +#define PHPGDC_MAX_SYMBOLS 21 /* {{{ php_gdchart_symbol_table */ static php_gdchart_symbol_table php_gdc_symbol_table[PHPGDC_MAX_SYMBOLS][20] = { @@ -119,14 +120,15 @@ }, /* 7 */ { - {"missing", PHPGDC_BOOLEAN_ARRAY, &GDCPIE_missing, NULL, NULL }, - {"explode", PHPGDC_INT_ARRAY, &GDCPIE_explode, NULL, NULL }, - {"ytitle2", PHPGDC_STRING, &GDC_ytitle2, NULL, NULL }, + { "missing", PHPGDC_BOOLEAN_ARRAY, &GDCPIE_missing, NULL, NULL }, + { "explode", PHPGDC_INT_ARRAY, &GDCPIE_explode, NULL, NULL }, + { "ytitle2", PHPGDC_STRING, &GDC_ytitle2, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }, /* 8 */ { { "bg_color", PHPGDC_ULONG, &GDC_BGColor, &GDCPIE_BGColor, 0xffffffL }, + { "bg_image", PHPGDC_STRING, &GDC_BGImage, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }, /* 9 */ @@ -134,9 +136,12 @@ { "bar_width", PHPGDC_UCHAR, &GDC_bar_width, NULL, 75 }, { "cap_width", PHPGDC_UCHAR, &GDC_HLC_cap_width, NULL, 25 }, { "vol_color", PHPGDC_ULONG, &GDC_VolColor, NULL, 0xA0A0FF }, + { "ext_color", PHPGDC_ULONG_ARRAY, &GDC_ExtColor, NULL, NULL }, { "pie_angle", PHPGDC_USHORT, &GDCPIE_3d_angle, NULL, 45 }, { "pie_depth", PHPGDC_USHORT, &GDCPIE_3d_depth, NULL, 10 }, + { "thumbnail", PHPGDC_CHAR, &GDC_thumbnail, NULL, 0 }, { "hlc_style", PHPGDC_INT, &GDC_HLC_style, NULL, GDC_HLC_CLOSE_CONNECTED }, + { "hard_size", PHPGDC_CHAR, &GDC_hard_size, NULL, 0 }, { NULL, 0, NULL, NULL } }, /* 10 */ @@ -158,6 +163,8 @@ { "zero_shelf", PHPGDC_CHAR, &GDC_0Shelf, NULL, 1 }, { "stack_type", PHPGDC_INT, &GDC_stack_type, NULL, GDC_STACK_DEPTH }, { "yval_style", PHPGDC_CHAR, &GDC_yval_style, NULL, 1 }, + { "hard_xorig", PHPGDC_INT, &GDC_hard_xorig, NULL, 0 }, + { "hard_yorig", PHPGDC_INT, &GDC_hard_yorig, NULL, 0 }, { NULL, 0, NULL, NULL } }, /* 11 */ @@ -205,12 +212,15 @@ { "interpolations", PHPGDC_CHAR, &GDC_interpolations, NULL, 0 }, { "requested_ymin", PHPGDC_FLOAT, &GDC_requested_ymin, NULL, 0 }, { "requested_ymax", PHPGDC_FLOAT, &GDC_requested_ymax, NULL, 0 }, + { "transparent_bg", PHPGDC_CHAR, &GDC_transparent_bg, NULL, 0 }, + { "hard_grapheigt", PHPGDC_INT, &GDC_hard_grapheight, NULL, 0 }, { NULL, 0, NULL, NULL } }, /* 15 */ { { "annotation_font", PHPGDC_STRING, &GDC_annotation_font, NULL, NULL }, { "other_threshold", PHPGDC_CHAR, &GDCPIE_other_threshold, NULL, -1 }, + { "hard_graphwidth", PHPGDC_INT, &GDC_hard_graphwidth, NULL, 0 }, { NULL, 0, NULL, NULL } }, /* 16 */ @@ -230,6 +240,11 @@ { { "requested_yinterval", PHPGDC_FLOAT, &GDC_requested_yinterval, NULL, 0 }, { NULL, 0, NULL, NULL } + }, + /* 20 */ + { + { "annotation_font_size", PHPGDC_INT, &GDC_annotation_font_size, NULL, GDC_SMALL }, + { NULL, 0, NULL, NULL } } }; /* }}} */ @@ -423,6 +438,10 @@ REGISTER_LONG_CONSTANT("HLC_CONNECTING", GDC_HLC_CONNECTING, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("HLC_I_CAP", GDC_HLC_I_CAP, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SCATTER_TRIANGLE_DOWN", GDC_SCATTER_TRIANGLE_DOWN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SCATTER_TRIANGLE_UP", GDC_SCATTER_TRIANGLE_UP, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SCATTER_CIRCLE", GDC_SCATTER_CIRCLE, CONST_CS | CONST_PERSISTENT); + REGISTER_DOUBLE_CONSTANT("NOVALUE", (double)GDC_NOVALUE, CONST_CS | CONST_PERSISTENT); _gdchart_set_defaults(); @@ -450,6 +469,11 @@ } GDC_annotation = NULL; _gdchart_set_defaults(); + if(GDC_scatter) { + efree(GDC_scatter); + GDC_scatter = NULL; + } + GDC_num_scatter_pts = 0; } return SUCCESS; } @@ -805,6 +829,40 @@ } /* }}} */ +/* {{{ proto add_scatter() + Add a dataset */ +PHP_FUNCTION(php_gdchart_add_scatter) +{ + int argc = ZEND_NUM_ARGS(); + pval **arr, *tmp = NULL; + double val, point; + long ind, color, width=6; + + if(zend_parse_parameters(argc, "ddll|l", &val, &point, &ind, &color, &width) == FAILURE) { + return; + } + + if(zend_hash_find(this_ptr->value.obj.properties, "scatter", sizeof("scatter"), (void **)&arr)==FAILURE) { + zval *scatter; + + MAKE_STD_ZVAL(scatter); + array_init(scatter); + add_property_zval(this_ptr, "scatter", scatter); + arr = &scatter; + } + + MAKE_STD_ZVAL(tmp); + array_init(tmp); + add_next_index_double(tmp, val); + add_next_index_double(tmp, point); + add_next_index_long(tmp, ind); + add_next_index_long(tmp, color); + add_next_index_long(tmp, width); + + add_next_index_zval(*arr, tmp); +} +/* }}} */ + /* {{{ proto add() Add a dataset */ PHP_FUNCTION(php_gdchart_add_set) @@ -867,6 +925,7 @@ num_sets = 0, num_combo_sets = 0, i = 0, cnt = 0, ret = 0; FILE *fp = NULL; GDC_ANNOTATION_T anno; + GDC_SCATTER_T *scatter; if(zend_parse_parameters(argc, "ll|ls", &width, &height, &image_type, &fname, &fname_len) == FAILURE) { RETVAL_FALSE; @@ -1027,6 +1086,42 @@ } else labels = NULL; } + if(zend_hash_find(Z_OBJPROP_P(this_ptr), "scatter", sizeof("scatter"), (void **)&tmp)!=FAILURE) { + cnt = zend_hash_num_elements(Z_ARRVAL_PP(tmp)); + if(cnt) { + i = 0; + scatter = (GDC_SCATTER_T *)emalloc((cnt+1) * sizeof(GDC_SCATTER_T)); + zend_hash_internal_pointer_reset(Z_ARRVAL_PP(tmp)); + while (zend_hash_get_current_data(Z_ARRVAL_PP(tmp), (void **)&val) == SUCCESS) { + zend_hash_internal_pointer_reset(Z_ARRVAL_PP(val)); + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].val = (float)Z_DVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].point = (float)Z_DVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].ind = (GDC_SCATTER_IND_T) Z_LVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].color = (unsigned long) Z_LVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; + if (zend_hash_get_current_data(Z_ARRVAL_PP(val), (void **)&val2) == SUCCESS) { + scatter[i].width = (unsigned short)Z_LVAL_PP(val2); + zend_hash_move_forward(Z_ARRVAL_PP(val)); + } else goto no_more; +no_more: + i++; + zend_hash_move_forward(Z_ARRVAL_PP(tmp)); + } + } else scatter = NULL; + GDC_num_scatter_pts = cnt; + GDC_scatter = scatter; + } if(zend_hash_find(Z_OBJPROP_P(this_ptr), "anno_note", sizeof("anno_note"), (void **)&tmp)!=FAILURE) { convert_to_string_ex(tmp); Index: pecl/gdchart/php_gdchart.h diff -u pecl/gdchart/php_gdchart.h:1.2 pecl/gdchart/php_gdchart.h:1.3 --- pecl/gdchart/php_gdchart.h:1.2 Fri Aug 22 15:39:00 2003 +++ pecl/gdchart/php_gdchart.h Wed Aug 27 18:49:10 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Rasmus Lerdorf | +----------------------------------------------------------------------+ - $Id: php_gdchart.h,v 1.2 2003/08/22 19:39:00 rasmus Exp $ + $Id: php_gdchart.h,v 1.3 2003/08/27 22:49:10 rasmus Exp $ */ #ifndef PHP_GDCHART_H @@ -38,6 +38,7 @@ PHP_FUNCTION(php_gdchart_out); PHP_FUNCTION(php_gdchart_add_set); PHP_FUNCTION(php_gdchart_add_combo_set); +PHP_FUNCTION(php_gdchart_add_scatter); typedef struct _php_gdchart_symbol_table { char *name; Index: pecl/gdchart/gdchart-src/gdchart.c diff -u pecl/gdchart/gdchart-src/gdchart.c:1.3 pecl/gdchart/gdchart-src/gdchart.c:1.4 --- pecl/gdchart/gdchart-src/gdchart.c:1.3 Wed Aug 27 05:51:56 2003 +++ pecl/gdchart/gdchart-src/gdchart.c Wed Aug 27 18:49:11 2003 @@ -16,6 +16,7 @@ #include <errno.h> #include "gdchart.h" +#include "ext/standard/php_image.h" #define HIGHSET 0 #define LOWSET 1 @@ -985,17 +986,28 @@ /* attempt to import optional background image */ if( GDC_BGImage ) { - FILE *in = fopen(GDC_BGImage, "rb"); - if( !in ) - { - ; /* Cant load background image, drop it */ + php_stream *stream; + FILE *in = NULL; + + stream = php_stream_open_wrapper(GDC_BGImage, "rb", REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); + php_stream_cast(stream, PHP_STREAM_AS_STDIO | PHP_STREAM_CAST_TRY_HARD, (void**)&in, REPORT_ERRORS); + if( !in ) { + php_error_docref(NULL, E_WARNING, "Unable to open %s", GDC_BGImage); + } else { + int itype = php_getimagetype(stream, NULL); + php_stream_seek(stream,0,SEEK_SET); /* checking the image type moves the file pointer, so reset it */ + switch(itype) { + case IMAGE_FILETYPE_GIF: + bg_img = gdImageCreateFromGif(in); + break; + case IMAGE_FILETYPE_JPEG: + bg_img = gdImageCreateFromJpeg(in); + break; + case IMAGE_FILETYPE_PNG: + bg_img = gdImageCreateFromPng(in); + break; } - else - { - /* assume GIF */ - /* should determine type by file extension, option, ... */ - if( bg_img = gdImageCreateFromGif(in) ) /* = */ - { + if(bg_img) { int bgxpos = gdImageSX(bg_img)<IMGWIDTH? IMGWIDTH/2 - gdImageSX(bg_img)/2: 0, bgypos = gdImageSY(bg_img)<IMGHEIGHT? IMGHEIGHT/2 - gdImageSY(bg_img)/2: 0; @@ -1013,11 +1025,11 @@ gdImageCopy( im, bg_img, /* dst, src */ bgxpos, bgypos, /* dstX, dstY */ 0, 0, /* srcX, srcY */ - IMGWIDTH, IMGHEIGHT ); /* W, H */ - } - fclose(in); + IMGWIDTH, IMGHEIGHT ); /* W, H */ } + php_stream_close(stream); } + } for( j=0; j<num_sets; ++j ) for( i=0; i<num_points; ++i ) @@ -2029,10 +2041,12 @@ if( uniq_clr != -1L ) /* the safe way */ { #if HAVE_LIBGD204 - int uc = uniq_clr; + gdImageFilledArc( im, scat_x, scat_y, + hlf_scatterwdth*2, hlf_scatterwdth*2, + s, e, + scatter_clr[i], gdArc ); #else int uc = gdImageColorAllocate( im, l2gdcal(uniq_clr) ); -#endif gdImageArc( im, scat_x, scat_y, hlf_scatterwdth*2, hlf_scatterwdth*2, s, e, @@ -2051,9 +2065,16 @@ scat_x, scat_y-hlf_scatterwdth, scatter_clr[i] ); gdImageColorDeallocate( im, uc ); +#endif } else /* chance it */ { +#if HAVE_LIBGD204 + gdImageFilledArc( im, scat_x, scat_y, + hlf_scatterwdth*2, hlf_scatterwdth*2, + s, e, + scatter_clr[i], gdArc); +#else gdImageArc( im, scat_x, scat_y, hlf_scatterwdth*2, hlf_scatterwdth*2, s, e, @@ -2064,6 +2085,7 @@ scatter_clr[i] ); gdImageFillToBorder( im, scat_x+fo, scat_y, scatter_clr[i], scatter_clr[i] ); +#endif } } break;