CVS update: php3/functions
| From: | steinm | Date: | Mon, 07 Jun 1999 15:00:09 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6653@lists.php.net to get a copy of this message | ||
Date: Monday June 7, 1999 @ 11:00
Author: steinm
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv15929/functions
Modified Files:
pdf.c php3_pdf.h
Log Message:
- added support for upcoming pdflib 2.0
Index: php3/functions/pdf.c
diff -u php3/functions/pdf.c:1.29 php3/functions/pdf.c:1.30
--- php3/functions/pdf.c:1.29 Thu May 27 14:11:06 1999
+++ php3/functions/pdf.c Mon Jun 7 11:00:09 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pdf.c,v 1.29 1999/05/27 18:11:06 steinm Exp $ */
+/* $Id: pdf.c,v 1.30 1999/06/07 15:00:09 steinm Exp $ */
/* pdflib 0.6 is subject to the ALADDIN FREE PUBLIC LICENSE.
Copyright (C) 1997 Thomas Merz. */
@@ -64,7 +64,10 @@
typedef struct pdflib_global_struct{
int le_pdf_image;
+#if HAVE_PDFLIB2
+#else
int le_pdf_info;
+#endif
int le_pdf;
} pdflib_global_struct;
@@ -75,12 +78,18 @@
# define PDF_GLOBAL(a) a
# define PDF_TLS_VARS
int le_pdf_image;
+#if HAVE_PDFLIB2
+#else
int le_pdf_info;
+#endif
int le_pdf;
#endif
function_entry pdf_functions[] = {
+#if HAVE_PDFLIB2
+#else
{"pdf_get_info", php3_pdf_get_info, NULL},
+#endif
{"pdf_set_info_creator", php3_pdf_set_info_creator, NULL},
{"pdf_set_info_title", php3_pdf_set_info_title, NULL},
{"pdf_set_info_subject", php3_pdf_set_info_subject, NULL},
@@ -155,6 +164,8 @@
DLEXPORT php3_module_entry *get_module(void) { return &pdf_module_entry; }
#endif
+#if HAVE_PDFLIB2
+#else
static void _free_pdf_info(PDF_info *info)
{
if(info->Title) efree(info->Title);
@@ -163,11 +174,17 @@
if(info->Keywords) efree(info->Keywords);
if(info->Creator) efree(info->Creator);
}
+#endif
+#if HAVE_PDFLIB2
+static void _free_pdf_image(int image)
+#else
static void _free_pdf_image(PDF_image *image)
+#endif
{
- /* The first parameter isn't used in any of the image close
- functions. It should be the PDF doc.
+ /* 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);
}
@@ -175,20 +192,29 @@
int php3_minit_pdf(INIT_FUNC_ARGS)
{
PDF_GLOBAL(le_pdf_image) = register_list_destructors(_free_pdf_image, NULL);
+#if HAVE_PDFLIB2
+#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);
return SUCCESS;
}
void php3_info_pdf(void) {
/* need to use a PHPAPI function here because it is external module in windows */
+#if HAVE_PDFLIB2
+ php3_printf("pdflib %s.", PDFLIB_VERSIONSTRING);
+#else
php3_printf("%s. AFM files in %s", PDFLIB_VERSION, PDF_DEFAULT_FONT_PATH);
+#endif
}
int php3_mend_pdf(void){
return SUCCESS;
}
+#if HAVE_PDFLIB2
+#else
/* {{{ proto int pdf_get_info(void)
Returns a default info structure for a pdf document */
void php3_pdf_get_info(INTERNAL_FUNCTION_PARAMETERS) {
@@ -215,13 +241,18 @@
RETURN_LONG(id);
}
/* }}} */
+#endif
/* {{{ proto pdf_set_info_creator(int info, string creator)
Fills the creator field of the info structure */
void php3_pdf_set_info_creator(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ PDF *pdf;
+#else
PDF_info *pdf_info;
+#endif
PDF_TLS_VARS;
@@ -232,13 +263,22 @@
convert_to_long(arg1);
convert_to_string(arg2);
id=arg1->value.lval;
+#if HAVE_PDFLIB2
+ pdf = php3_list_find(id,&type);
+ if (!pdf || type!=PDF_GLOBAL(le_pdf)) {
+#else
pdf_info = php3_list_find(id,&type);
if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) {
+#endif
php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type);
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_set_info(pdf, "Creator", arg2->value.str.val);
+#else
pdf_info->Creator = estrdup(arg2->value.str.val);
+#endif
RETURN_TRUE;
}
@@ -249,7 +289,11 @@
void php3_pdf_set_info_title(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ PDF *pdf;
+#else
PDF_info *pdf_info;
+#endif
PDF_TLS_VARS;
@@ -260,13 +304,22 @@
convert_to_long(arg1);
convert_to_string(arg2);
id=arg1->value.lval;
+#if HAVE_PDFLIB2
+ pdf = php3_list_find(id,&type);
+ if (!pdf || type!=PDF_GLOBAL(le_pdf)) {
+#else
pdf_info = php3_list_find(id,&type);
if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) {
+#endif
php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type);
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_set_info(pdf, "Title", arg2->value.str.val);
+#else
pdf_info->Title = estrdup(arg2->value.str.val);
+#endif
RETURN_TRUE;
}
@@ -277,7 +330,11 @@
void php3_pdf_set_info_subject(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ PDF *pdf;
+#else
PDF_info *pdf_info;
+#endif
PDF_TLS_VARS;
@@ -288,13 +345,22 @@
convert_to_long(arg1);
convert_to_string(arg2);
id=arg1->value.lval;
+#if HAVE_PDFLIB2
+ pdf = php3_list_find(id,&type);
+ if (!pdf || type!=PDF_GLOBAL(le_pdf)) {
+#else
pdf_info = php3_list_find(id,&type);
if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) {
+#endif
php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type);
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_set_info(pdf, "Subject", arg2->value.str.val);
+#else
pdf_info->Subject = estrdup(arg2->value.str.val);
+#endif
RETURN_TRUE;
}
@@ -305,7 +371,11 @@
void php3_pdf_set_info_author(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ PDF *pdf;
+#else
PDF_info *pdf_info;
+#endif
PDF_TLS_VARS;
@@ -316,13 +386,22 @@
convert_to_long(arg1);
convert_to_string(arg2);
id=arg1->value.lval;
+#if HAVE_PDFLIB2
+ pdf = php3_list_find(id,&type);
+ if (!pdf || type!=PDF_GLOBAL(le_pdf)) {
+#else
pdf_info = php3_list_find(id,&type);
if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) {
+#endif
php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type);
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_set_info(pdf, "Author", arg2->value.str.val);
+#else
pdf_info->Author = estrdup(arg2->value.str.val);
+#endif
RETURN_TRUE;
}
@@ -333,7 +412,11 @@
void php3_pdf_set_info_keywords(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ PDF *pdf;
+#else
PDF_info *pdf_info;
+#endif
PDF_TLS_VARS;
@@ -344,13 +427,22 @@
convert_to_long(arg1);
convert_to_string(arg2);
id=arg1->value.lval;
+#if HAVE_PDFLIB2
+ pdf = php3_list_find(id,&type);
+ if (!pdf || type!=PDF_GLOBAL(le_pdf)) {
+#else
pdf_info = php3_list_find(id,&type);
if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) {
+#endif
php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type);
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_set_info(pdf, "Keywords", arg2->value.str.val);
+#else
pdf_info->Keywords = estrdup(arg2->value.str.val);
+#endif
RETURN_TRUE;
}
@@ -363,7 +455,10 @@
pval *info;
int id, type;
FILE *fp;
+#if HAVE_PDFLIB2
+#else
PDF_info *pdf_info;
+#endif
PDF *pdf;
PDF_TLS_VARS;
@@ -373,7 +468,6 @@
}
convert_to_long(file);
- convert_to_long(info);
id=file->value.lval;
fp = php3_list_find(id,&type);
if (!fp || type!=php3i_get_le_fp()) {
@@ -381,13 +475,23 @@
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+#else
+ convert_to_long(info);
id=info->value.lval;
pdf_info = php3_list_find(id,&type);
if (!pdf_info || type!=PDF_GLOBAL(le_pdf_info)) {
php3_error(E_WARNING,"Unable to find pdf info identifier %d (%d!=%d)",id, type,
PDF_GLOBAL(le_pdf_info));
RETURN_FALSE;
}
+#endif
+#if HAVE_PDFLIB2
+ pdf = PDF_new();
+ if (0 > PDF_open_fp(pdf, fp)) {
+ RETURN_FALSE;
+ }
+#else
pdf = PDF_open(fp, pdf_info);
if(!pdf)
RETURN_FALSE;
@@ -402,6 +506,7 @@
an segm fault. This shouldn't happen anymore.
*/
php3_list_delete(id);
+#endif
id = php3_list_insert(pdf,PDF_GLOBAL(le_pdf));
RETURN_LONG(id);
}
@@ -426,7 +531,11 @@
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); */
RETURN_TRUE;
@@ -569,11 +678,35 @@
RETURN_FALSE;
}
- if(arg4->value.lval > 6) {
- php3_error(E_WARNING,"Font encoding set to 5");
- arg4->value.lval = 5;
+ if((arg4->value.lval > 5) || (arg4->value.lval < 0)) {
+ php3_error(E_WARNING,"Font encoding set to 4");
+ arg4->value.lval = 4;
+ }
+
+#if HAVE_PDFLIB2
+ switch(arg4->value.lval) {
+ case 0:
+ PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, "builtin");
+ break;
+ case 1:
+ PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, "pdfdoc");
+ break;
+ case 2:
+ PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, "macroman");
+ break;
+ case 3:
+ PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, "macexpert");
+ break;
+ case 4:
+ PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, "winansi");
+ break;
+ default:
+ php3_error(E_WARNING,"Encoding out of range, using 0");
+ PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, "builtin");
}
+#else
PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, arg4->value.lval);
+#endif
RETURN_TRUE;
}
@@ -627,7 +760,11 @@
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_set_text_rendering(pdf, arg2->value.lval);
+#else
PDF_set_text_rendering(pdf, (byte) arg2->value.lval);
+#endif
RETURN_TRUE;
}
@@ -694,7 +831,11 @@
int id, type, i;
HashTable *matrix;
PDF *pdf;
+#if HAVE_PDFLIB2
+ float pdfmatrix[6];
+#else
PDF_matrix pdfmatrix;
+#endif
float *pdfmatrixptr;
PDF_TLS_VARS;
@@ -732,7 +873,12 @@
_php3_hash_move_forward(matrix);
}
+#if HAVE_PDFLIB2
+ PDF_set_text_matrix(pdf, pdfmatrix[0], pdfmatrix[1], pdfmatrix[2],
+ pdfmatrix[3], pdfmatrix[4], pdfmatrix[5]);
+#else
PDF_set_text_matrix(pdf, pdfmatrix);
+#endif
RETURN_TRUE;
}
@@ -869,7 +1015,11 @@
RETURN_FALSE;
}
+#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
RETURN_DOUBLE((double)width);
}
@@ -1068,7 +1218,11 @@
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_setlinejoin(pdf, arg2->value.lval);
+#else
PDF_setlinejoin(pdf, (byte) arg2->value.lval);
+#endif
RETURN_TRUE;
}
@@ -1100,7 +1254,11 @@
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_setlinecap(pdf, arg2->value.lval);
+#else
PDF_setlinecap(pdf, (byte) arg2->value.lval);
+#endif
RETURN_TRUE;
}
@@ -1776,7 +1934,11 @@
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_add_bookmark(pdf, estrdup(arg2->value.str.val), 0, 0);
+#else
PDF_add_outline(pdf, estrdup(arg2->value.str.val));
+#endif
RETURN_TRUE;
}
@@ -1803,7 +1965,39 @@
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ switch(arg2->value.lval) {
+ case 0:
+ PDF_set_transition(pdf, "none");
+ break;
+ case 1:
+ PDF_set_transition(pdf, "split");
+ break;
+ case 2:
+ PDF_set_transition(pdf, "blinds");
+ break;
+ case 3:
+ PDF_set_transition(pdf, "box");
+ break;
+ case 4:
+ PDF_set_transition(pdf, "wipe");
+ break;
+ case 5:
+ PDF_set_transition(pdf, "dissolve");
+ break;
+ case 6:
+ PDF_set_transition(pdf, "glitter");
+ break;
+ case 7:
+ PDF_set_transition(pdf, "replace");
+ break;
+ default:
+ PDF_set_transition(pdf, "none");
+
+ }
+#else
PDF_set_transition(pdf, arg2->value.lval);
+#endif
RETURN_TRUE;
}
@@ -1841,7 +2035,11 @@
void php3_pdf_open_gif(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ int pdf_image;
+#else
PDF_image *pdf_image;
+#endif
PDF *pdf;
PDF_TLS_VARS;
@@ -1865,7 +2063,7 @@
RETURN_FALSE;
}
- id = php3_list_insert(pdf_image,PDF_GLOBAL(le_pdf_image));
+ id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image));
RETURN_LONG(id);
}
/* }}} */
@@ -1875,7 +2073,11 @@
void php3_pdf_open_jpeg(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ int pdf_image;
+#else
PDF_image *pdf_image;
+#endif
PDF *pdf;
PDF_TLS_VARS;
@@ -1899,7 +2101,7 @@
RETURN_FALSE;
}
- id = php3_list_insert(pdf_image,PDF_GLOBAL(le_pdf_image));
+ id = php3_list_insert((void *) pdf_image,PDF_GLOBAL(le_pdf_image));
RETURN_LONG(id);
}
/* }}} */
@@ -1907,25 +2109,54 @@
/* {{{ proto void pdf_close_image(int pdfimage)
Closes the pdf image */
void php3_pdf_close_image(INTERNAL_FUNCTION_PARAMETERS) {
- pval *arg1;
+ pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ int pdf_image;
+#else
PDF_image *pdf_image;
+#endif
+ PDF *pdf;
PDF_TLS_VARS;
- if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
+#if HAVE_PDFLIB2
+ if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+#else
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
+#endif
+#if HAVE_PDFLIB2
convert_to_long(arg1);
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;
+ }
+#else
+#endif
+ convert_to_long(arg2);
+ id=arg2->value.lval;
+#if HAVE_PDFLIB2
+ pdf_image = (int) php3_list_find(id,&type);
+#else
pdf_image = php3_list_find(id,&type);
+#endif
if(!pdf_image || type!=PDF_GLOBAL(le_pdf_image)) {
php3_error(E_WARNING,"Unable to find file identifier %d",id);
RETURN_FALSE;
}
+#if HAVE_PDFLIB2
+ PDF_close_image(pdf, pdf_image);
+#else
/* See comment in _free_pdf_image() */
PDF_close_image(NULL, pdf_image);
+#endif
RETURN_TRUE;
}
@@ -1936,7 +2167,11 @@
void php3_pdf_place_image(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2, *arg3, *arg4, *arg5;
int id, type;
+#if HAVE_PDFLIB2
+ int pdf_image;
+#else
PDF_image *pdf_image;
+#endif
PDF *pdf;
PDF_TLS_VARS;
@@ -1954,7 +2189,11 @@
convert_to_long(arg2);
id=arg2->value.lval;
+#if HAVE_PDFLIB2
+ pdf_image = (int) php3_list_find(id,&type);
+#else
pdf_image = php3_list_find(id,&type);
+#endif
if(!pdf_image || type!=PDF_GLOBAL(le_pdf_image)) {
php3_error(E_WARNING,"Unable to find file identifier %d",id);
RETURN_FALSE;
@@ -1975,7 +2214,11 @@
void php3_pdf_put_image(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int id, type;
+#if HAVE_PDFLIB2
+ int pdf_image;
+#else
PDF_image *pdf_image;
+#endif
PDF *pdf;
PDF_TLS_VARS;
@@ -1993,7 +2236,11 @@
convert_to_long(arg2);
id=arg2->value.lval;
+#if HAVE_PDFLIB2
+ pdf_image = (int) php3_list_find(id,&type);
+#else
pdf_image = php3_list_find(id,&type);
+#endif
if(!pdf_image || type!=PDF_GLOBAL(le_pdf_image)) {
php3_error(E_WARNING,"Unable to find file identifier %d",id);
RETURN_FALSE;
@@ -2010,7 +2257,11 @@
void php3_pdf_execute_image(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2, *arg3, *arg4, *arg5;
int id, type;
+#if HAVE_PDFLIB2
+ int pdf_image;
+#else
PDF_image *pdf_image;
+#endif
PDF *pdf;
PDF_TLS_VARS;
@@ -2028,7 +2279,11 @@
convert_to_long(arg2);
id=arg2->value.lval;
+#if HAVE_PDFLIB2
+ pdf_image = (int) php3_list_find(id,&type);
+#else
pdf_image = php3_list_find(id,&type);
+#endif
if(!pdf_image || type!=PDF_GLOBAL(le_pdf_image)) {
php3_error(E_WARNING,"Unable to find file identifier %d",id);
RETURN_FALSE;
Index: php3/functions/php3_pdf.h
diff -u php3/functions/php3_pdf.h:1.8 php3/functions/php3_pdf.h:1.9
--- php3/functions/php3_pdf.h:1.8 Sun Feb 28 18:03:51 1999
+++ php3/functions/php3_pdf.h Mon Jun 7 11:00:09 1999
@@ -26,14 +26,18 @@
| Authors: Uwe Steinmann |
+----------------------------------------------------------------------+
*/
-/* $Id: php3_pdf.h,v 1.8 1999/02/28 23:03:51 steffann Exp $ */
+/* $Id: php3_pdf.h,v 1.9 1999/06/07 15:00:09 steinm Exp $ */
#ifndef _PHP3_PDF_H
#define _PHP3_PDF_H
#if HAVE_PDFLIB
+#if HAVE_PDFLIB2
+#include <pdflib.h>
+#else
#include <pdf.h>
+#endif
extern int le_fp;
@@ -43,7 +47,10 @@
extern void php3_info_pdf(void);
extern int php3_minit_pdf(INIT_FUNC_ARGS);
extern int php3_mend_pdf(void);
+#if HAVE_PDFLIB2
+#else
extern void php3_pdf_get_info(INTERNAL_FUNCTION_PARAMETERS);
+#endif
extern void php3_pdf_set_info_creator(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pdf_set_info_title(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pdf_set_info_subject(INTERNAL_FUNCTION_PARAMETERS);