CVS update: php3/functions
| From: | steinm | Date: | Tue, 08 Jun 1999 09:16:34 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6701@lists.php.net to get a copy of this message | ||
Date: Tuesday June 8, 1999 @ 5:16
Author: steinm
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv6866/functions
Modified Files:
cpdf.c pdf.c php3_pdf.h
Log Message:
- lots of documentation, more examples
- cleaner implementation of pdf_close(), cpdf_close()
hopefully didn't break anything
- cpdf_finalize_page() made available
Index: php3/functions/cpdf.c
diff -u php3/functions/cpdf.c:1.10 php3/functions/cpdf.c:1.11
--- php3/functions/cpdf.c:1.10 Tue Jun 1 14:15:12 1999
+++ php3/functions/cpdf.c Tue Jun 8 05:16:34 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: cpdf.c,v 1.10 1999/06/01 18:15:12 steinm Exp $ */
+/* $Id: cpdf.c,v 1.11 1999/06/08 09:16:34 steinm Exp $ */
/* cpdflib.h -- C language API definitions for ClibPDF library
* Copyright (C) 1998 FastIO Systems, All Rights Reserved.
*/
@@ -89,6 +89,7 @@
{"cpdf_close", php3_cpdf_close, NULL},
{"cpdf_set_viewer_preferences", php3_cpdf_set_viewer_preferences,NULL},
{"cpdf_page_init", php3_cpdf_page_init, NULL},
+ {"cpdf_finalize_page", php3_cpdf_finalize_page, NULL},
{"cpdf_set_current_page", php3_cpdf_set_current_page, NULL},
{"cpdf_begin_text", php3_cpdf_begin_text, NULL},
{"cpdf_end_text", php3_cpdf_end_text, NULL},
@@ -167,9 +168,15 @@
{
}
+static void _free_doc(int *pdf)
+{
+ cpdf_close();
+}
+
int php3_minit_cpdf(INIT_FUNC_ARGS)
{
CPDF_GLOBAL(le_outline) = register_list_destructors(_free_outline, NULL);
+ CPDF_GLOBAL(le_cpdf) = register_list_destructors(_free_doc, NULL);
return SUCCESS;
}
@@ -401,8 +408,7 @@
php3_error(E_WARNING,"Unable to find identifier %d",id);
RETURN_FALSE;
}
- cpdf_close();
-/* php3_list_delete(id); */
+ php3_list_delete(id);
RETURN_TRUE;
}
@@ -2346,7 +2352,7 @@
gid=argv[1]->value.lval;
im = php3_list_find(gid, &type);
if (!im || type != php3i_get_le_gd()) {
- php3_error(E_WARNING, "ImageColorAllocate: Unable to find image pointer");
+ php3_error(E_WARNING, "cpdf: Unable to find image pointer");
RETURN_FALSE;
}
Index: php3/functions/pdf.c
diff -u php3/functions/pdf.c:1.31 php3/functions/pdf.c:1.32
--- php3/functions/pdf.c:1.31 Mon Jun 7 12:43:07 1999
+++ php3/functions/pdf.c Tue Jun 8 05:16:34 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pdf.c,v 1.31 1999/06/07 16:43:07 steinm Exp $ */
+/* $Id: pdf.c,v 1.32 1999/06/08 09:16:34 steinm Exp $ */
/* pdflib 0.6 is subject to the ALADDIN FREE PUBLIC LICENSE.
Copyright (C) 1997 Thomas Merz. */
@@ -44,6 +44,9 @@
#include "head.h"
#include <math.h>
#include "php3_pdf.h"
+#if HAVE_LIBGD13
+#include "gd.h"
+#endif
#if HAVE_SYS_WAIT_H
# include <sys/wait.h>
@@ -108,10 +111,10 @@
{"pdf_set_text_rise", php3_pdf_set_text_rise, NULL},
{"pdf_set_text_matrix", php3_pdf_set_text_matrix, NULL},
{"pdf_set_text_pos", php3_pdf_set_text_pos, NULL},
- {"pdf_set_char_spacing", php3_pdf_set_char_spacing, NULL},
- {"pdf_set_word_spacing", php3_pdf_set_word_spacing, NULL},
+ {"pdf_set_char_spacing", php3_pdf_set_char_spacing, NULL},
+ {"pdf_set_word_spacing", php3_pdf_set_word_spacing, NULL},
{"pdf_continue_text", php3_pdf_continue_text, NULL},
- {"pdf_stringwidth", php3_pdf_stringwidth, NULL},
+ {"pdf_stringwidth", php3_pdf_stringwidth, NULL},
{"pdf_save", php3_pdf_save, NULL},
{"pdf_restore", php3_pdf_restore, NULL},
{"pdf_translate", php3_pdf_translate, NULL},
@@ -144,10 +147,13 @@
{"pdf_setrgbcolor_stroke", php3_pdf_setrgbcolor_stroke,NULL},
{"pdf_setrgbcolor", php3_pdf_setrgbcolor, NULL},
{"pdf_add_outline", php3_pdf_add_outline, NULL},
- {"pdf_set_transition", php3_pdf_set_transition, NULL},
- {"pdf_set_duration", php3_pdf_set_duration, NULL},
- {"pdf_open_jpeg", php3_pdf_open_jpeg, NULL},
- {"pdf_open_gif", php3_pdf_open_gif, NULL},
+ {"pdf_set_transition", php3_pdf_set_transition, NULL},
+ {"pdf_set_duration", php3_pdf_set_duration, NULL},
+ {"pdf_open_jpeg", php3_pdf_open_jpeg, NULL},
+#if HAVE_LIBGD13 && HAVE_PDFLIB2
+ {"pdf_open_memory_image", php3_pdf_open_memory_image, NULL},
+#endif
+ {"pdf_open_gif", php3_pdf_open_gif, NULL},
{"pdf_close_image", php3_pdf_close_image, NULL},
{"pdf_place_image", php3_pdf_place_image, NULL},
{"pdf_put_image", php3_pdf_put_image, NULL},
@@ -182,11 +188,24 @@
static void _free_pdf_image(PDF_image *image)
#endif
{
+#if HAVE_PDFLIB2
+#else
/* In pdflib 0.6 the first parameter isn't used in any of the image
close functions. It later versions it is the PDF doc.
FIX ME: This probably causes in segm fault in pdflib 2.0
*/
PDF_close_image(NULL, image);
+#endif
+}
+
+static void _free_pdf_doc(PDF *pdf)
+{
+#if HAVE_PDFLIB2
+ PDF_close_fp(pdf);
+ PDF_delete(pdf);
+#else
+ PDF_close(pdf);
+#endif
}
int php3_minit_pdf(INIT_FUNC_ARGS)
@@ -196,7 +215,7 @@
#else
PDF_GLOBAL(le_pdf_info) = register_list_destructors(_free_pdf_info, NULL);
#endif
- PDF_GLOBAL(le_pdf) = register_list_destructors(php3_pdf_close, NULL);
+ PDF_GLOBAL(le_pdf) = register_list_destructors(_free_pdf_doc, NULL);
return SUCCESS;
}
@@ -500,7 +519,8 @@
if(!pdf)
RETURN_FALSE;
- /* Due to a problem with pdf_info() we need to get rid of it
+ /* Attention pdblib 0.6:
+ Due to a problem with pdf_info() we need to get rid of it
right here. The problem is: When pdf_close() is called it
will call the pdflib function pdf_finalize() which then
frees the space for the struct of pdf_info. At this point the
@@ -535,12 +555,8 @@
php3_error(E_WARNING,"Unable to find file identifier %d",id);
RETURN_FALSE;
}
-#if HAVE_PDFLIB2
- PDF_close_fp(pdf);
-#else
- PDF_close(pdf);
-#endif
-/* php3_list_delete(id); */
+
+ php3_list_delete(id);
RETURN_TRUE;
}
@@ -2035,7 +2051,7 @@
/* }}} */
/* {{{ proto int pdf_open_gif(int pdf, string giffile)
- Returns an image for placement in a pdf document */
+ Opens a gif file and returns an image for placement in a pdf document */
void php3_pdf_open_gif(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
@@ -2073,7 +2089,7 @@
/* }}} */
/* {{{ proto int pdf_open_jpeg(int pdf, string jpegfile)
- Returns an image for placement in a pdf document */
+ Opens a jpeg file and returns an image for placement in a pdf document */
void php3_pdf_open_jpeg(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
@@ -2109,6 +2125,67 @@
RETURN_LONG(id);
}
/* }}} */
+
+#if HAVE_PDFLIB2
+/* {{{ proto int pdf_open_memory_image(int pdf, string jpegfile)
+ Takes an gd image and returns an image for placement in a pdf document */
+void php3_pdf_open_memory_image(INTERNAL_FUNCTION_PARAMETERS) {
+ pval *argv[2];
+ int argc;
+ int i, j, id, gid, type, color, count;
+ int pdf_image;
+ gdImagePtr im;
+ unsigned char *buffer, *ptr;
+ PDF *pdf;
+ PDF_TLS_VARS;
+
+ argc = ARG_COUNT(ht);
+ if (getParametersArray(ht, argc, argv) == FAILURE)
+ WRONG_PARAM_COUNT;
+
+ convert_to_long(argv[0]);
+ id=argv[0]->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;
+ }
+
+ convert_to_long(argv[1]);
+ gid=argv[1]->value.lval;
+ im = php3_list_find(gid, &type);
+ if (!im || type != php3i_get_le_gd()) {
+ php3_error(E_WARNING, "pdf: Unable to find image pointer");
+ RETURN_FALSE;
+ }
+
+ count = 3 * im->sx * im->sy;
+ if(NULL == (buffer = (unsigned char *) emalloc(count)))
+ RETURN_FALSE;
+
+ ptr = buffer;
+ for(i=0; i<im->sy; i++) {
+ for(j=0; j<im->sx; j++) {
+ color = im->pixels[i][j];
+ *ptr++ = im->red[color];
+ *ptr++ = im->green[color];
+ *ptr++ = im->blue[color];
+ }
+ }
+
+
+ pdf_image = PDF_open_memory_image(pdf, buffer, im->sx, im->sy, 3, 8);
+
+ if(0 > pdf_image) {
+ 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);
+}
+/* }}} */
+#endif
/* {{{ proto void pdf_close_image(int pdfimage)
Closes the pdf image */
Index: php3/functions/php3_pdf.h
diff -u php3/functions/php3_pdf.h:1.9 php3/functions/php3_pdf.h:1.10
--- php3/functions/php3_pdf.h:1.9 Mon Jun 7 11:00:09 1999
+++ php3/functions/php3_pdf.h Tue Jun 8 05:16:34 1999
@@ -26,7 +26,7 @@
| Authors: Uwe Steinmann |
+----------------------------------------------------------------------+
*/
-/* $Id: php3_pdf.h,v 1.9 1999/06/07 15:00:09 steinm Exp $ */
+/* $Id: php3_pdf.h,v 1.10 1999/06/08 09:16:34 steinm Exp $ */
#ifndef _PHP3_PDF_H
#define _PHP3_PDF_H
@@ -108,6 +108,9 @@
extern void php3_pdf_set_transition(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pdf_set_duration(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pdf_open_jpeg(INTERNAL_FUNCTION_PARAMETERS);
+#if HAVE_LIBGD13 && HAVE_PDFLIB2
+extern void php3_pdf_open_memory_image(INTERNAL_FUNCTION_PARAMETERS);
+#endif
extern void php3_pdf_open_gif(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pdf_close_image(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pdf_place_image(INTERNAL_FUNCTION_PARAMETERS);