cvs: php3 /functions pdf.c php3_pdf.h
| From: | Rui Hirokawa | Date: | Fri, 05 Jan 2001 06:31:54 +0000 |
| Subject: | cvs: php3 /functions pdf.c php3_pdf.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3376@lists.php.net to get a copy of this message | ||
hirokawa Thu Jan 4 22:31:54 2001 EDT
Modified files:
/php3/functions pdf.c php3_pdf.h
Log:
made compatibility with PDFLIB-3.x and back-port of pdf_open_image().
Index: php3/functions/pdf.c diff -u php3/functions/pdf.c:1.60 php3/functions/pdf.c:1.61 --- php3/functions/pdf.c:1.60 Wed Feb 23 07:05:08 2000 +++ php3/functions/pdf.c Thu Jan 4 22:31:54 2001 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdf.c,v 1.60 2000/02/23 15:05:08 steinm Exp $ */ +/* $Id: pdf.c,v 1.61 2001/01/05 06:31:54 hirokawa Exp $ */ /* pdflib 0.6 is subject to the ALADDIN FREE PUBLIC LICENSE. Copyright (C) 1997 Thomas Merz. */ @@ -130,6 +130,9 @@ PHP_FE(pdf_open_memory_image, NULL) #endif PHP_FE(pdf_open_gif, NULL) +#if HAVE_PDFLIB3 + PHP_FE(pdf_open_image_file, NULL) +#endif PHP_FE(pdf_close_image, NULL) PHP_FE(pdf_place_image, NULL) PHP_FE(pdf_put_image, NULL) @@ -213,7 +216,7 @@ void php3_info_pdf() { /* need to use a PHPAPI function here because it is external module in windows */ #if HAVE_PDFLIB2 - php3_printf("pdflib %d.%d", PDF_get_majorversion(), PDF_get_minorversion()); + php3_printf("pdflib %d.0%d", PDF_get_majorversion(), PDF_get_minorversion()); #if PDFLIB_MINORVERSION > 0 php3_printf("The function pdf_put_image() and pdf_execute_image() are <B>not</B> available"); #else @@ -672,7 +675,7 @@ } /* }}} */ -/* {{{ proto void pdf_set_font(int pdfdoc, string font, double size, int encoding [, int embed]) +/* {{{ proto void pdf_set_font(int pdfdoc, string font, double size, string encoding [, int embed]) Select the current font face, size and encoding */ PHP_FUNCTION(pdf_set_font) { pval *arg1, *arg2, *arg3, *arg4, *arg5; @@ -701,7 +704,11 @@ convert_to_long(arg1); convert_to_string(arg2); convert_to_double(arg3); +#if HAVE_PDFLIB3 + convert_to_string(arg4); +#else convert_to_long(arg4); +#endif id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { @@ -709,6 +716,15 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + font = PDF_findfont(pdf, arg2->value.str.val, arg4->value.str.val, embed); + if (font < 0){ + php3_error(E_WARNING,"Font %s not found",arg2->value.str.val); + RETURN_FALSE; + } + PDF_setfont(pdf, font, (float) arg3->value.dval); +#else + if((arg4->value.lval > 5) || (arg4->value.lval < 0)) { php3_error(E_WARNING,"Font encoding set to 4"); arg4->value.lval = 4; @@ -745,6 +761,7 @@ #else PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, arg4->value.lval); #endif +#endif RETURN_TRUE; } @@ -771,8 +788,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "leading", (float) arg2->value.dval); +#else PDF_set_leading(pdf, (float) arg2->value.dval); - +#endif RETURN_TRUE; } /* }}} */ @@ -798,11 +818,15 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "textrendering", (float) arg2->value.lval); +#else #if HAVE_PDFLIB2 PDF_set_text_rendering(pdf, arg2->value.lval); #else PDF_set_text_rendering(pdf, (byte) arg2->value.lval); #endif +#endif RETURN_TRUE; } @@ -829,7 +853,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "horizscaling", (float) arg2->value.dval); +#else PDF_set_horiz_scaling(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -855,8 +883,12 @@ php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } - + +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "textrise", (float) arg2->value.dval); +#else PDF_set_text_rise(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -971,7 +1003,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "charspacing", (float) arg2->value.dval); +#else PDF_set_char_spacing(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -998,7 +1034,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "wordspacing", (float) arg2->value.dval); +#else PDF_set_word_spacing(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -1053,12 +1093,15 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + width = (double) PDF_stringwidth(pdf, arg2->value.str.val, PDF_get_value(pdf, "font", 0), PDF_get_value(pdf, "fontsize", 0)); +#else #if HAVE_PDFLIB2 width = (double) PDF_stringwidth(pdf, arg2->value.str.val, PDF_get_font(pdf), PDF_get_fontsize(pdf)); #else width = (double) PDF_stringwidth(pdf, arg2->value.str.val); #endif - +#endif RETURN_DOUBLE((double)width); } /* }}} */ @@ -2059,6 +2102,37 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + switch(arg2->value.lval) { + case 0: + PDF_set_parameter(pdf, "transition", "none"); + break; + case 1: + PDF_set_parameter(pdf, "transition", "split"); + break; + case 2: + PDF_set_parameter(pdf, "transition", "blinds"); + break; + case 3: + PDF_set_parameter(pdf, "transition", "box"); + break; + case 4: + PDF_set_parameter(pdf, "transition", "wipe"); + break; + case 5: + PDF_set_parameter(pdf, "transition", "dissolve"); + break; + case 6: + PDF_set_parameter(pdf, "transition", "glitter"); + break; + case 7: + PDF_set_parameter(pdf, "transition", "replace"); + break; + default: + PDF_set_parameter(pdf, "transition", "none"); + + } +#else #if HAVE_PDFLIB2 switch(arg2->value.lval) { case 0: @@ -2092,6 +2166,7 @@ #else PDF_set_transition(pdf, arg2->value.lval); #endif +#endif RETURN_TRUE; } @@ -2118,7 +2193,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "duration", (float) arg2->value.dval); +#else PDF_set_duration(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -2150,7 +2229,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + pdf_image = PDF_open_image_file(pdf, "gif", arg2->value.str.val, "", 0); +#else pdf_image = PDF_open_GIF(pdf, arg2->value.str.val); +#endif if(pdf_image < 0) { php3_error(E_WARNING, "Could not open image"); @@ -2188,7 +2271,48 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + pdf_image = PDF_open_image_file(pdf, "jpeg", arg2->value.str.val, "", 0); +#else pdf_image = PDF_open_JPEG(pdf, arg2->value.str.val); +#endif + + if(pdf_image < 0) { + php3_error(E_WARNING, "Could not open image"); + RETURN_FALSE; + } + + id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image)); + RETURN_LONG(id); +} +/* }}} */ + +#if HAVE_PDFLIB3 +/* {{{ proto int pdf_open_image_file(int pdf, string type, string file) + Opens a image file of the given type and returns an image for placement in a pdf document */ +PHP_FUNCTION(pdf_open_image_file) { + pval *arg1, *arg2, *arg3; + int id, type; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_string(arg2); + convert_to_string(arg3); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + pdf_image = PDF_open_image_file(pdf, arg2->value.str.val, + arg3->value.str.val, "", 0); if(pdf_image < 0) { php3_error(E_WARNING, "Could not open image"); @@ -2199,6 +2323,7 @@ RETURN_LONG(id); } /* }}} */ +#endif #if HAVE_LIBGD #if HAVE_PDFLIB2 @@ -2509,7 +2634,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + width = PDF_get_value(pdf, "imagewidth", pdf_image); +#else width = PDF_get_image_width(pdf, pdf_image); +#endif RETURN_LONG(width); } @@ -2545,7 +2674,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + height = PDF_get_value(pdf, "imageheight", pdf_image); +#else height = PDF_get_image_height(pdf, pdf_image); +#endif RETURN_LONG(height); } Index: php3/functions/php3_pdf.h diff -u php3/functions/php3_pdf.h:1.17 php3/functions/php3_pdf.h:1.18 --- php3/functions/php3_pdf.h:1.17 Tue Jan 2 14:49:31 2001 +++ php3/functions/php3_pdf.h Thu Jan 4 22:31:54 2001 @@ -26,14 +26,14 @@ | Authors: Uwe Steinmann | +----------------------------------------------------------------------+ */ -/* $Id: php3_pdf.h,v 1.17 2001/01/02 22:49:31 hirokawa Exp $ */ +/* $Id: php3_pdf.h,v 1.18 2001/01/05 06:31:54 hirokawa Exp $ */ #ifndef _PHP3_PDF_H #define _PHP3_PDF_H #if HAVE_PDFLIB -#if HAVE_PDFLIB2 +#if HAVE_PDFLIB2 | HAVE_PDFLIB3 #include <pdflib.h> #else #include <pdf.h> @@ -112,6 +112,9 @@ PHP_FUNCTION(pdf_open_memory_image); #endif PHP_FUNCTION(pdf_open_gif); +#if HAVE_PDFLIB3 +PHP_FUNCTION(pdf_open_image_file); +#endif PHP_FUNCTION(pdf_close_image); PHP_FUNCTION(pdf_place_image); PHP_FUNCTION(pdf_put_image);
Index: php3/functions/pdf.c diff -u php3/functions/pdf.c:1.60 php3/functions/pdf.c:1.61 --- php3/functions/pdf.c:1.60 Wed Feb 23 07:05:08 2000 +++ php3/functions/pdf.c Thu Jan 4 22:31:54 2001 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdf.c,v 1.60 2000/02/23 15:05:08 steinm Exp $ */ +/* $Id: pdf.c,v 1.61 2001/01/05 06:31:54 hirokawa Exp $ */ /* pdflib 0.6 is subject to the ALADDIN FREE PUBLIC LICENSE. Copyright (C) 1997 Thomas Merz. */ @@ -130,6 +130,9 @@ PHP_FE(pdf_open_memory_image, NULL) #endif PHP_FE(pdf_open_gif, NULL) +#if HAVE_PDFLIB3 + PHP_FE(pdf_open_image_file, NULL) +#endif PHP_FE(pdf_close_image, NULL) PHP_FE(pdf_place_image, NULL) PHP_FE(pdf_put_image, NULL) @@ -213,7 +216,7 @@ void php3_info_pdf() { /* need to use a PHPAPI function here because it is external module in windows */ #if HAVE_PDFLIB2 - php3_printf("pdflib %d.%d", PDF_get_majorversion(), PDF_get_minorversion()); + php3_printf("pdflib %d.0%d", PDF_get_majorversion(), PDF_get_minorversion()); #if PDFLIB_MINORVERSION > 0 php3_printf("The function pdf_put_image() and pdf_execute_image() are <B>not</B> available"); #else @@ -672,7 +675,7 @@ } /* }}} */ -/* {{{ proto void pdf_set_font(int pdfdoc, string font, double size, int encoding [, int embed]) +/* {{{ proto void pdf_set_font(int pdfdoc, string font, double size, string encoding [, int embed]) Select the current font face, size and encoding */ PHP_FUNCTION(pdf_set_font) { pval *arg1, *arg2, *arg3, *arg4, *arg5; @@ -701,7 +704,11 @@ convert_to_long(arg1); convert_to_string(arg2); convert_to_double(arg3); +#if HAVE_PDFLIB3 + convert_to_string(arg4); +#else convert_to_long(arg4); +#endif id=arg1->value.lval; pdf = php3_list_find(id,&type); if(!pdf || type!=PDF_GLOBAL(le_pdf)) { @@ -709,6 +716,15 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + font = PDF_findfont(pdf, arg2->value.str.val, arg4->value.str.val, embed); + if (font < 0){ + php3_error(E_WARNING,"Font %s not found",arg2->value.str.val); + RETURN_FALSE; + } + PDF_setfont(pdf, font, (float) arg3->value.dval); +#else + if((arg4->value.lval > 5) || (arg4->value.lval < 0)) { php3_error(E_WARNING,"Font encoding set to 4"); arg4->value.lval = 4; @@ -745,6 +761,7 @@ #else PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, arg4->value.lval); #endif +#endif RETURN_TRUE; } @@ -771,8 +788,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "leading", (float) arg2->value.dval); +#else PDF_set_leading(pdf, (float) arg2->value.dval); - +#endif RETURN_TRUE; } /* }}} */ @@ -798,11 +818,15 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "textrendering", (float) arg2->value.lval); +#else #if HAVE_PDFLIB2 PDF_set_text_rendering(pdf, arg2->value.lval); #else PDF_set_text_rendering(pdf, (byte) arg2->value.lval); #endif +#endif RETURN_TRUE; } @@ -829,7 +853,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "horizscaling", (float) arg2->value.dval); +#else PDF_set_horiz_scaling(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -855,8 +883,12 @@ php3_error(E_WARNING,"Unable to find file identifier %d",id); RETURN_FALSE; } - + +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "textrise", (float) arg2->value.dval); +#else PDF_set_text_rise(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -971,7 +1003,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "charspacing", (float) arg2->value.dval); +#else PDF_set_char_spacing(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -998,7 +1034,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "wordspacing", (float) arg2->value.dval); +#else PDF_set_word_spacing(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -1053,12 +1093,15 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + width = (double) PDF_stringwidth(pdf, arg2->value.str.val, PDF_get_value(pdf, "font", 0), PDF_get_value(pdf, "fontsize", 0)); +#else #if HAVE_PDFLIB2 width = (double) PDF_stringwidth(pdf, arg2->value.str.val, PDF_get_font(pdf), PDF_get_fontsize(pdf)); #else width = (double) PDF_stringwidth(pdf, arg2->value.str.val); #endif - +#endif RETURN_DOUBLE((double)width); } /* }}} */ @@ -2059,6 +2102,37 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + switch(arg2->value.lval) { + case 0: + PDF_set_parameter(pdf, "transition", "none"); + break; + case 1: + PDF_set_parameter(pdf, "transition", "split"); + break; + case 2: + PDF_set_parameter(pdf, "transition", "blinds"); + break; + case 3: + PDF_set_parameter(pdf, "transition", "box"); + break; + case 4: + PDF_set_parameter(pdf, "transition", "wipe"); + break; + case 5: + PDF_set_parameter(pdf, "transition", "dissolve"); + break; + case 6: + PDF_set_parameter(pdf, "transition", "glitter"); + break; + case 7: + PDF_set_parameter(pdf, "transition", "replace"); + break; + default: + PDF_set_parameter(pdf, "transition", "none"); + + } +#else #if HAVE_PDFLIB2 switch(arg2->value.lval) { case 0: @@ -2092,6 +2166,7 @@ #else PDF_set_transition(pdf, arg2->value.lval); #endif +#endif RETURN_TRUE; } @@ -2118,7 +2193,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + PDF_set_value(pdf, "duration", (float) arg2->value.dval); +#else PDF_set_duration(pdf, (float) arg2->value.dval); +#endif RETURN_TRUE; } @@ -2150,7 +2229,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + pdf_image = PDF_open_image_file(pdf, "gif", arg2->value.str.val, "", 0); +#else pdf_image = PDF_open_GIF(pdf, arg2->value.str.val); +#endif if(pdf_image < 0) { php3_error(E_WARNING, "Could not open image"); @@ -2188,7 +2271,48 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + pdf_image = PDF_open_image_file(pdf, "jpeg", arg2->value.str.val, "", 0); +#else pdf_image = PDF_open_JPEG(pdf, arg2->value.str.val); +#endif + + if(pdf_image < 0) { + php3_error(E_WARNING, "Could not open image"); + RETURN_FALSE; + } + + id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image)); + RETURN_LONG(id); +} +/* }}} */ + +#if HAVE_PDFLIB3 +/* {{{ proto int pdf_open_image_file(int pdf, string type, string file) + Opens a image file of the given type and returns an image for placement in a pdf document */ +PHP_FUNCTION(pdf_open_image_file) { + pval *arg1, *arg2, *arg3; + int id, type; + int pdf_image; + PDF *pdf; + PDF_TLS_VARS; + + if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(arg1); + convert_to_string(arg2); + convert_to_string(arg3); + id=arg1->value.lval; + pdf = php3_list_find(id,&type); + if(!pdf || type!=PDF_GLOBAL(le_pdf)) { + php3_error(E_WARNING,"Unable to find file identifier %d",id); + RETURN_FALSE; + } + + pdf_image = PDF_open_image_file(pdf, arg2->value.str.val, + arg3->value.str.val, "", 0); if(pdf_image < 0) { php3_error(E_WARNING, "Could not open image"); @@ -2199,6 +2323,7 @@ RETURN_LONG(id); } /* }}} */ +#endif #if HAVE_LIBGD #if HAVE_PDFLIB2 @@ -2509,7 +2634,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + width = PDF_get_value(pdf, "imagewidth", pdf_image); +#else width = PDF_get_image_width(pdf, pdf_image); +#endif RETURN_LONG(width); } @@ -2545,7 +2674,11 @@ RETURN_FALSE; } +#if HAVE_PDFLIB3 + height = PDF_get_value(pdf, "imageheight", pdf_image); +#else height = PDF_get_image_height(pdf, pdf_image); +#endif RETURN_LONG(height); } Index: php3/functions/php3_pdf.h diff -u php3/functions/php3_pdf.h:1.17 php3/functions/php3_pdf.h:1.18 --- php3/functions/php3_pdf.h:1.17 Tue Jan 2 14:49:31 2001 +++ php3/functions/php3_pdf.h Thu Jan 4 22:31:54 2001 @@ -26,14 +26,14 @@ | Authors: Uwe Steinmann | +----------------------------------------------------------------------+ */ -/* $Id: php3_pdf.h,v 1.17 2001/01/02 22:49:31 hirokawa Exp $ */ +/* $Id: php3_pdf.h,v 1.18 2001/01/05 06:31:54 hirokawa Exp $ */ #ifndef _PHP3_PDF_H #define _PHP3_PDF_H #if HAVE_PDFLIB -#if HAVE_PDFLIB2 +#if HAVE_PDFLIB2 | HAVE_PDFLIB3 #include <pdflib.h> #else #include <pdf.h> @@ -112,6 +112,9 @@ PHP_FUNCTION(pdf_open_memory_image); #endif PHP_FUNCTION(pdf_open_gif); +#if HAVE_PDFLIB3 +PHP_FUNCTION(pdf_open_image_file); +#endif PHP_FUNCTION(pdf_close_image); PHP_FUNCTION(pdf_place_image); PHP_FUNCTION(pdf_put_image);