PHP 4.0 Bug #3811 Updated: Unknown Symbol in PDFLIB 3.0
| From: | Bug Database | Date: | Fri, 24 Mar 2000 07:33:51 +0000 |
| Subject: | PHP 4.0 Bug #3811 Updated: Unknown Symbol in PDFLIB 3.0 | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-17189@lists.php.net to get a copy of this message | ||
ID: 3811
User Update by: tswan@ics.olemiss.edu
Old-Status: Open
Status: Feedback
Bug Type: Other
Description: Unknown Symbol in PDFLIB 3.0
I found some more things I left out... sorry...
I added some more functions the changes PDFlib 3.0 API. This
includes PDF_show_boxed(),PDF_open_png(), PDF_open_image_file().
I'm still learning to use PDFlib in PHP so I'm still assuming I
haven't botched anything... (It works so far)... I would
appreciate it if someone were to check it for me against what
they are doing.
The changes include the following...
pdf_show_boxed(pdfdoc pdf, string text, float left, float bottom,
float width, float height, string hmode, string reserved)
pdf = file descriptor
text = text to be displayed in the box
left = position from left side of page
bottom = position from bottom of page
width = width of the text box
height = height of the text box
hmode = justification for text box can be
"centered","left","right","justify", or
"fulljustify"
Added PDF_open_png(pdfdoc pdf, string filename)
opens a png_image if linked agains libPNG.
Added PDF_open_image_file(pdfdoc pdf, string imagetype, string filename)
where imagetype = "png","tiff","jpeg", or "gif"
All PDF_open_{imagetype} calls now use the PDF_open_image_file()
call in PDFlib instead of the older call.
Two patches are included... seperated by
****************** FOR {FILENAME} *******************
Sorry I didn't know how to diff for multiple files...
****************** FOR PHP_PDF.H *******************
--- /usr/src/php-4.0b4pl1/ext/pdf/php_pdf.h Mon Feb 21 10:23:07 2000
+++ php_pdf.h Fri Mar 24 00:04:45 2000
@@ -57,6 +57,9 @@
PHP_FUNCTION(pdf_begin_page);
PHP_FUNCTION(pdf_end_page);
PHP_FUNCTION(pdf_show);
+#if (PDFLIB_MAJORVERSION >= 3)
+PHP_FUNCTION(pdf_show_boxed);
+#endif
PHP_FUNCTION(pdf_show_xy);
PHP_FUNCTION(pdf_set_font);
PHP_FUNCTION(pdf_get_font);
@@ -110,6 +113,10 @@
PHP_FUNCTION(pdf_set_duration);
PHP_FUNCTION(pdf_open_jpeg);
PHP_FUNCTION(pdf_open_tiff);
+#if (PDFLIB_MAJORVERSION >=3 )
+PHP_FUNCTION(pdf_open_png);
+PHP_FUNCTION(pdf_open_image_file);
+#endif
#if HAVE_LIBGD13
PHP_FUNCTION(pdf_open_memory_image);
#endif
@@ -125,6 +132,9 @@
PHP_FUNCTION(pdf_set_border_color);
PHP_FUNCTION(pdf_get_image_width);
PHP_FUNCTION(pdf_get_image_height);
+#if (PDFLIB_MAJORVERSION >= 3)
+PHP_FUNCTION(pdf_text_box);
+#endif
#else
#define pdf_module_ptr NULL
#endif
****************** FOR PDF.C *******************
--- /usr/src/php-4.0b4pl1/ext/pdf/pdf.c Mon Feb 21 10:23:07 2000
+++ pdf.c Fri Mar 24 01:21:29 2000
@@ -92,6 +92,9 @@
PHP_FE(pdf_begin_page, NULL)
PHP_FE(pdf_end_page, NULL)
PHP_FE(pdf_show, NULL)
+#if (PDFLIB_MAJORVERSION >= 3)
+ PHP_FE(pdf_show_boxed, NULL)
+#endif
PHP_FE(pdf_show_xy, NULL)
PHP_FE(pdf_set_font, NULL)
PHP_FE(pdf_set_leading, NULL)
@@ -99,6 +102,7 @@
PHP_FE(pdf_set_horiz_scaling, NULL)
PHP_FE(pdf_set_text_rise, NULL)
#if PDFLIB_MAJORVERSION < 3 & PDFLIB_MINORVERSION < 30
+/* All Versions < 2.30 */
PHP_FE(pdf_set_text_matrix, NULL)
#endif
PHP_FE(pdf_set_text_pos, NULL)
@@ -187,7 +191,8 @@
if(outline) efree(outline);
}
-#if PDFLIB_MAJORVERSION > 1 & PDFLIB_MINORVERSION > 0
+#if (PDFLIB_MAJORVERSION == 2 && PDFLIB_MINORVERSION > 0) || (PDFLIB_MAJORVERSION >=
3)
+/* All Versions >= 2.01 */
static void custom_errorhandler(PDF *p, int type, const char*shortmsg) {
switch (type){
case PDF_NonfatalError:
@@ -223,7 +228,8 @@
}
#endif
-#if PDFLIB_MAJORVERSION >= 2 & PDFLIB_MINORVERSION >= 10
+#if (PDFLIB_MAJORVERSION == 2 && PDFLIB_MINORVERSION >= 10) || (PDFLIB_MAJORVERSION
>= 3)
+/* All Versions >= 2.10 */
static size_t pdf_flushwrite(PDF *p, void *data, size_t size){
if(php_header())
return(php_write(data, size));
@@ -242,14 +248,16 @@
PHP_MINFO_FUNCTION(pdf) {
/* need to use a PHPAPI function here because it is external module in windows */
php_printf("pdflib %d.%02d<BR>", PDF_get_majorversion(), PDF_get_minorversion());
-#if PDFLIB_MAJORVERSION >= 3 | (PDFLIB_MAJORVERSION >= 2 & PDFLIB_MINORVERSION >= 20)
+#if (PDFLIB_MAJORVERSION >= 3) || (PDFLIB_MAJORVERSION == 2 && PDFLIB_MINORVERSION >=
20)
+/* All Versions >= 2.20 */
php_printf("The CJK fonts supported.");
#endif
#ifdef PDF_OPEN_MEM_SUPPORTED
php_printf("Support for in memory pdf creation.");
#endif
-#if PDFLIB_MINORVERSION > 0
+#if (PDFLIB_MAJORVERSION == 2 && PDFLIB_MINORVERSION > 0) || (PDFLIB_MAJORVERSION >=
3)
+/* All Versions >= 2.01 */
php_printf("The function pdf_put_image() and pdf_execute_image() are <B>not</B>
available");
#else
php_printf("The function pdf_put_image() and pdf_execute_image() are available");
@@ -420,7 +428,8 @@
int argc;
PDF_TLS_VARS;
-#if PDFLIB_MAJORVERSION >= 2 & PDFLIB_MINORVERSION >= 10
+#if ((PDFLIB_MAJORVERSION == 2) && (PDFLIB_MINORVERSION >= 10)) || (PDFLIB_MAJORVERSION
>= 3)
+/* Versions >= 2.10 */
argc = ARG_COUNT(ht);
if(argc > 1)
WRONG_PARAM_COUNT;
@@ -440,18 +449,21 @@
/* XXX should do anzend_list_addref for <fp> here! */
#endif
-#if PDFLIB_MAJORVERSION > 1 & PDFLIB_MINORVERSION > 0
+#if ((PDFLIB_MAJORVERSION == 2) && (PDFLIB_MINORVERSION >= 1)) || (PDFLIB_MAJORVERSION
>= 3)
+/* All Versions >= 2.01 */
pdf = PDF_new2(custom_errorhandler, pdf_emalloc, pdf_realloc, pdf_efree, NULL);
#else
pdf = PDF_new();
#endif
-#if PDFLIB_MAJORVERSION >= 2 & PDFLIB_MINORVERSION >= 10 & defined
PDF_OPEN_MEM_SUPPORTED
+#if (PDFLIB_MAJORVERSION >= 3) || (PDFLIB_MAJORVERSION == 2 && PDFLIB_MINORVERSION >=
10 && defined PDF_OPEN_MEM_SUPPORTED)
+/* All Versions >= 2.10 */
if(fp) {
if (0 > PDF_open_fp(pdf, fp))
RETURN_FALSE;
} else {
-#if PDFLIB_MAJORVERSION >= 3 | (PDFLIB_MAJORVERSION >= 2 & PDFLIB_MINORVERSION >= 20)
& defined PDF_OPEN_MEM_SUPPORTED
+#if (PDFLIB_MAJORVERSION >= 3) || (PDFLIB_MAJORVERSION >= 2 && PDFLIB_MINORVERSION
>= 20 && defined PDF_OPEN_MEM_SUPPORTED)
+/* All Versions >= 2.20 */
PDF_open_mem(pdf, pdf_flushwrite);
#else
if (0 > PDF_open_mem(pdf, pdf_flushwrite))
@@ -578,6 +590,53 @@
}
/* }}} */
+/* {{{ proto void pdf_show_boxed(int pdfdoc, string text, float left, float bottom, float width,
+ float height, string hmode, string reserved)
+ Output text at constrained to a box defined by left, bottom, width, height
+ Options to fill are alignments (specified as a string in hmode):
+ left, right, center, justify, fulljustify
+ Returns false if the text could not fit in the region specified,
+ Returns the number of letters that couldn't fit in the box
+
+ */
+PHP_FUNCTION(pdf_show_boxed) {
+#if (PDFLIB_MAJORVERSION >= 3)
+ pval *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7;
+ int id, type, returnval;
+ PDF *pdf;
+ PDF_TLS_VARS;
+
+ if (ARG_COUNT(ht) != 7 ||
+ getParameters(ht, 7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7)
== FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(arg1);
+ convert_to_string(arg2);
+ convert_to_double(arg3);
+ convert_to_double(arg4);
+ convert_to_double(arg5);
+ convert_to_double(arg6);
+ convert_to_string(arg7);
+ id=arg1->value.lval;
+ pdf = zend_list_find(id,&type);
+ if(!pdf || type!=PDF_GLOBAL(le_pdf)) {
+ php_error(E_WARNING,"Unable to find file identifier %d",id);
+ RETURN_FALSE;
+ }
+
+ /* Note: The 8th argument is supposed to be null, otherwise it balks */
+ returnval = PDF_show_boxed(pdf, arg2->value.str.val, (float) arg3->value.dval, (float)
arg4->value.dval,
+ (float) arg5->value.dval, (float) arg6->value.dval, arg7->value.str.val,
+ NULL);
+ RETURN_LONG(returnval);
+#else
+ php_error(E_WARNING,"PDF_show_boxed() is not supported in this version of PDFlib
%d",id);
+ RETURN FALSE;
+#endif
+}
+/* }}} */
+
/* {{{ proto void pdf_show_xy(int pdfdoc, string text, double x-koor, double y-koor)
Output text at position */
PHP_FUNCTION(pdf_show_xy) {
@@ -637,6 +696,7 @@
convert_to_string(arg2);
convert_to_double(arg3);
#if PDFLIB_MAJORVERSION >= 2
+/* All Versions >= 2.00 */
convert_to_string(arg4);
#else
convert_to_long(arg4);
@@ -650,6 +710,7 @@
}
#if PDFLIB_MAJORVERSION >= 2
+/* All Versions >= 2.00 */
font = PDF_findfont(pdf, arg2->value.str.val, arg4->value.str.val, embed);
#else
if((arg4->value.lval > 5) || (arg4->value.lval < 0)) {
@@ -877,7 +938,8 @@
}
/* }}} */
-#if PDFLIB_MAJORVERSION < 3 & PDFLIB_MINORVERSION < 30
+#if PDFLIB_MAJORVERSION < 3 && PDFLIB_MINORVERSION < 30
+/* All Versions < 2.30 */
/* {{{ proto void pdf_set_text_matrix(int pdfdoc, arry matrix)
Sets the text matrix */
PHP_FUNCTION(pdf_set_text_matrix) {
@@ -2124,8 +2186,11 @@
RETURN_FALSE;
}
+#if (PDFLIB_MAJORVERSION >= 3)
+ 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) {
php_error(E_WARNING, "Could not open image");
RETURN_FALSE;
@@ -2158,7 +2223,11 @@
RETURN_FALSE;
}
+#if (PDFLIB_MAJORVERSION >= 3)
+ 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) {
php_error(E_WARNING, "Could not open image");
@@ -2192,7 +2261,11 @@
RETURN_FALSE;
}
+#if (PDFLIB_MAJORVERSION >= 3)
+ pdf_image = PDF_open_image_file(pdf, "tiff", arg2->value.str.val, "", 0);
+#else
pdf_image = PDF_open_TIFF(pdf, arg2->value.str.val);
+#endif
if(pdf_image < 0) {
php_error(E_WARNING, "Could not open image");
@@ -2203,6 +2276,86 @@
RETURN_LONG(id);
}
/* }}} */
+/* {{{ proto int pdf_open_png(int pdf, string tifffile)
+ Opens a PNG file and returns an image for placement in a pdf document.
+ Available on if PDFlib version is 3.0 or greater*/
+#ifdef HAVE_LIBPNG
+PHP_FUNCTION(pdf_open_png) {
+ pval *arg1, *arg2;
+ int id, type;
+ int pdf_image;
+ PDF *pdf;
+ PDF_TLS_VARS;
+
+ if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(arg1);
+ convert_to_string(arg2);
+ id=arg1->value.lval;
+ pdf = zend_list_find(id,&type);
+ if(!pdf || type!=PDF_GLOBAL(le_pdf)) {
+ php_error(E_WARNING,"Unable to find file identifier %d",id);
+ RETURN_FALSE;
+ }
+
+ pdf_image = PDF_open_image_file(pdf, "png", arg2->value.str.val, "", 0);
+
+ if(pdf_image < 0) {
+ php_error(E_WARNING, "Could not open image");
+ RETURN_FALSE;
+ }
+
+ id = zend_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image));
+ RETURN_LONG(id);
+}
+#endif
+/* }}} */
+
+#if (PDLIB_MAJORVERSION >= 3)
+/* All versions 3.0 or greater */
+/* {{{ proto int pdf_open_image_file(int pdf, string imagetype, string imagefile)
+ Opens a PNG file and returns an image for placement in a pdf document.
+ Replaces PDF_open_GIF,PDF_open_TIFF,PDF_open_JPEG, and adds the ability to
+ open PNG files.
+
+ Syntax: pdf_open_image_file($pdf, "gif" | "jpeg" | "tiff" |
"png", $filename);
+
+ Available if PDFlib version is 3.0 or greater*/
+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);
+ conver_to_string(arg3);
+ id=arg1->value.lval;
+ pdf = zend_list_find(id,&type);
+ if(!pdf || type!=PDF_GLOBAL(le_pdf)) {
+ php_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) {
+ php_error(E_WARNING, "Could not open image");
+ RETURN_FALSE;
+ }
+
+ id = zend_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image));
+ RETURN_LONG(id);
+}
+#endif
+/* }}} */
#if HAVE_LIBGD13
/* {{{ proto int pdf_open_memory_image(int pdf, int image)
@@ -2252,7 +2405,8 @@
}
-#if PDFLIB_MINORVERSION == 0
+#if ((PDFLIB_MINORVERSION < 1) && (PDFLIB_MAJORVERSION < 3))
+/* All Versions <= 2.00 */
pdf_image = PDF_open_memory_image(pdf, buffer, im->sx, im->sy, 3, 8);
#else
pdf_image = PDF_open_image(pdf, "raw", "memory", buffer,
im->sx*im->sy*3, im->sx, im->sy, 3, 8, NULL);
@@ -2348,7 +2502,8 @@
/* {{{ proto void pdf_put_image(int pdf, int pdfimage)
Stores image in the pdf document for later use */
PHP_FUNCTION(pdf_put_image) {
-#if PDFLIB_MINORVERSION > 0
+#if (PDFLIB_MINORVERSION > 0) || (PDFLIB_MAJORVERSION >= 3)
+/* All Versions >= 2.01 */
#else
pval *arg1, *arg2;
int id, type;
@@ -2357,7 +2512,8 @@
#endif
PDF_TLS_VARS;
-#if PDFLIB_MINORVERSION > 0
+#if (PDFLIB_MINORVERSION > 0) || (PDFLIB_MAJORVERSION >= 3)
+/* All Versions >= 2.01 */
php_error(E_WARNING, "Version 2.01 of pdflib does not need the pdf_put_image() anymore, check
the docs!");
#else
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
@@ -2390,7 +2546,8 @@
/* {{{ proto void pdf_execute_image(int pdf, int pdfimage, int x, int y, int scale)
Places stored image in the pdf document */
PHP_FUNCTION(pdf_execute_image) {
-#if PDFLIB_MINORVERSION >= 01
+#if ((PDFLIB_MAJORVERSION == 2) && (PDFLIB_MINORVERSION >= 1)) || (PDFLIB_MAJORVERSION
>= 3)
+/* All Versions >= 2.01 */
#else
pval *arg1, *arg2, *arg3, *arg4, *arg5;
int id, type;
@@ -2399,7 +2556,8 @@
PDF_TLS_VARS;
#endif
-#if PDFLIB_MINORVERSION >= 01
+#if ((PDFLIB_MAJORVERSION == 2) && (PDFLIB_MINORVERSION >= 01)) || (PDFLIB_MAJORVERSION
>= 3)
+/* All Versions >= 2.01 */
php_error(E_WARNING, "Version 2.01 of pdflib does not need the pdf_execute_image() anymore,
check the docs!");
#else
if (ARG_COUNT(ht) != 5 || getParameters(ht, 5, &arg1, &arg2, &arg3, &arg4,
&arg5) == FAILURE) {
Full Bug description available at: http://bugs.php.net/version4/?id=3811