PHPlib 3.0 and PHP4.0PL1 Patch...
| From: | Thomas Swan | Date: | Wed, 15 Mar 2000 10:39:39 +0000 |
| Subject: | PHPlib 3.0 and PHP4.0PL1 Patch... | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-16826@lists.php.net to get a copy of this message | ||
I apologize if this has been addressed already. I just joined the list....
Also, if this needs to go someplace else, please let me know...
Anyway, I had problems (frustrating) with PDFlib 3.0 and PHP4.0 PL1 (even file a bug report). A
series of the #ifdefs assumed a version of a minor revision level of pdflib > 0.01 and when 3.00
came around it threw everything in to hock thinking it was less than version 2.01 or later
revisions.
With PDFlib 3.0 came the ability to layout text constrained to a box with the PDF_show_boxed
function... I thought while I was at it that I would fix the incompatibilities and add the
show_boxed function at the same time. Included are two patch files both in-line and as
attachments. These are for the pdf.c and php_pdf.h files in ext/pdf.
Syntax for the pdf_show_boxed( ) function is as follows...
pdf_show_boxed(document, String text, float bottom_position, float_horizontal_position, float
height, float width, String options)
document = the file descriptor for the pdf document,
bottom_position = the position of the bottom of the box
horizontal_position = the position from the left side of the page
height = height of the box
width = width of the text box
options = a string of any of the following:
"left","right","centered", "justify", or
"fulljustify"
It returns true if the text could be rendered in the region or false if the text could not fit in
the region (font too large, , text too long, etc.)
It gives the ability to some scaling to fit with a little work...
$fontname = "Helvetica-Bold";
$fontsize = 24.0;
pdf_save($pdf); // Save current font state
pdf_set_font($pdf, $fontname, $size, "winansi");
while (!pdf_show_boxed($pdf, "Nuf Foo Frone Round", 50,400,80,100,"right")) {
$fontsize -= 0.5;
pdf_set_font($pdf, $fontname, $fontsize, "winansi");
}
pdf_restore($pdf); // Restore previous font state
Hope this is useful to someone...
It's late, very very late, and I'm going to bed now... :)
Thomas
************ PATCH FOR PDF.C in ext/pdf *************
--- pdf.c Mon Feb 21 10:23:07 2000
+++ pdf.c Wed Mar 15 04:04:56 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,58 @@
}
/* }}} */
+/* {{{ 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 true if the text was displayed...
+
+ */
+PHP_FUNCTION(pdf_show_boxed) {
+#if (PDFLIB_MAJORVERSION >= 3)
+ pval *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7;
+ int id, type;
+ 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;
+ }
+
+ if (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_FALSE;
+ } else {
+ RETURN_TRUE;
+ }
+
+ /* Note: The 8th argument is supposed to be null, otherwise it balks */
+// RETURN_TRUE;
+#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 +701,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 +715,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 +943,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) {
@@ -2252,7 +2319,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 +2416,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 +2426,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 +2460,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 +2470,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) {
************ PATCH FOR PHP_PDF.H in ext/pdf **********
--- php_pdf.h Mon Feb 21 10:23:07 2000
+++ php_pdf.h Wed Mar 15 03:44:21 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);
@@ -125,6 +128,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
Attachment: [application/octet-stream] pdf.c.patch
Attachment: [application/octet-stream] php_pdf.h.patch
Attachment: [application/octet-stream] pdf.c.patch
Attachment: [application/octet-stream] php_pdf.h.patch