1/*
2   +----------------------------------------------------------------------+
3   | PHP version 4                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2003 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 2.02 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available at through the world-wide-web at                           |
10   | http://www.php.net/license/2_02.txt.                                 |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Authors: Uwe Steinmann <Uwe.Steinmann@fernuni-hagen.de>              |
16   |          Rainer Schaaf <rjs@pdflib.com>                              |
17   +----------------------------------------------------------------------+
18*/
19
20/* $Id: pdf.c 14574 2005-10-29 16:27:43Z bonefish $ */
21
22/* Bootstrap of PDFlib Feature setup */
23#define PDF_FEATURE_SERIAL
24
25
26/* derived from:
27    Id: pdf.c,v 1.112.2.5 2003/04/30 21:54:02 iliaa Exp
28
29    with some exeptions:
30    - pdf_get_major/minorversion not included, as pdf_get_value supports this
31      without a PDF-object
32    - #if ZEND_MODULE_API_NO >= 20010901 for new ZEND_MODULE support,
33      so that it compiles with older PHP Versions too
34    - TSRMLS fixes included only with ZEND_MODULE_API_NO >= 20010901
35      would break older builds otherwise
36	- new PHP streams #if ZEND_MODULE_API_NO >= 20020429 && HAVE_PHP_STREAM
37	  TODO: CVS (1.107/108/109/112)
38	- added better support to see if it comes as binary from PDFlib GmbH.
39	- change from emalloc to safe_emalloc (112.2.4 -> 112.2.5) not included
40	  (would not be backwardcompatible with older php builds)
41	- TODO: merge back to PHP-CVS
42   */
43
44/* pdflib 2.02 ... 4.0x is subject to the ALADDIN FREE PUBLIC LICENSE.
45   Copyright (C) 1997-1999 Thomas Merz. 2000-2002 PDFlib GmbH */
46
47/* Note that there is no code from the pdflib package in this file */
48
49/* {{{ includes
50 */
51#ifdef HAVE_CONFIG_H
52#include "config.h"
53#endif
54
55#include "php.h"
56#include "php_ini.h"
57#include "php_globals.h"
58#include "zend_list.h"
59#include "ext/standard/head.h"
60#include "ext/standard/info.h"
61#include "ext/standard/file.h"
62
63#if HAVE_LIBGD13
64#include "ext/gd/php_gd.h"
65#if HAVE_GD_BUNDLED
66#include "ext/gd/libgd/gd.h"
67#else
68#include "gd.h"
69#endif
70static int le_gd;
71#endif
72
73#ifdef HAVE_UNISTD_H
74# include <unistd.h>
75#endif
76#ifdef PHP_WIN32
77# include <io.h>
78# include <fcntl.h>
79#endif
80/* }}} */
81
82#if HAVE_PDFLIB
83
84#include "php_pdf.h"
85
86#if ((100*PDFLIB_MAJORVERSION+10*PDFLIB_MINORVERSION+PDFLIB_REVISION) >= 500)
87	/* This wrapper code will work only with PDFlib V5 or greater,
88	 * because the special handling for returning 0 instead of -1
89	 * for PHP is now done in the PDFlib kernel
90	 */
91#else
92
93#error "PDFlib version does not match PHP-wrapper code"
94
95#endif /* PDFlib >= V5 */
96
97#undef VIRTUAL_DIR
98
99static int le_pdf;
100
101/* {{{ pdf_functions[]
102 */
103function_entry pdf_functions[] = {
104	/* p_font.c */
105	PHP_FE(pdf_add_launchlink, NULL)
106	PHP_FE(pdf_add_locallink, NULL)
107	PHP_FE(pdf_add_note, NULL)
108	PHP_FE(pdf_add_pdflink, NULL)
109	PHP_FE(pdf_add_weblink, NULL)
110	PHP_FE(pdf_attach_file, NULL)
111	PHP_FE(pdf_set_border_color, NULL)
112	PHP_FE(pdf_set_border_dash, NULL)
113	PHP_FE(pdf_set_border_style, NULL)
114
115	/* p_basic.c */
116	PHP_FE(pdf_begin_page, NULL)
117	PHP_FE(pdf_close, NULL)
118	PHP_FE(pdf_delete, NULL)
119	PHP_FE(pdf_end_page, NULL)
120	PHP_FE(pdf_get_buffer, NULL)
121	PHP_FE(pdf_new, NULL)
122	PHP_FE(pdf_open_file, NULL)
123
124	/* p_block.c */
125	PHP_FE(pdf_fill_imageblock, NULL)
126	PHP_FE(pdf_fill_pdfblock, NULL)
127	PHP_FE(pdf_fill_textblock, NULL)
128
129	/* p_color.c */
130	PHP_FE(pdf_makespotcolor, NULL)
131	PHP_FE(pdf_setcolor, NULL)
132	PHP_FE(pdf_setgray_fill, NULL)		/* deprecated (since 4.0) */
133	PHP_FE(pdf_setgray_stroke, NULL)	/* deprecated (since 4.0) */
134	PHP_FE(pdf_setgray, NULL)			/* deprecated (since 4.0) */
135	PHP_FE(pdf_setrgbcolor_fill, NULL)	/* deprecated (since 4.0) */
136	PHP_FE(pdf_setrgbcolor_stroke, NULL)/* deprecated (since 4.0) */
137	PHP_FE(pdf_setrgbcolor, NULL)		/* deprecated (since 4.0) */
138
139	/* p_draw.c */
140	PHP_FE(pdf_arc, NULL)
141	PHP_FE(pdf_arcn, NULL)
142	PHP_FE(pdf_circle, NULL)
143	PHP_FE(pdf_clip, NULL)
144	PHP_FE(pdf_closepath, NULL)
145	PHP_FE(pdf_closepath_fill_stroke, NULL)
146	PHP_FE(pdf_closepath_stroke, NULL)
147	PHP_FE(pdf_curveto, NULL)
148	PHP_FE(pdf_endpath, NULL)
149	PHP_FE(pdf_fill, NULL)
150	PHP_FE(pdf_fill_stroke, NULL)
151	PHP_FE(pdf_lineto, NULL)
152	PHP_FE(pdf_moveto, NULL)
153	PHP_FE(pdf_rect, NULL)
154	PHP_FE(pdf_stroke, NULL)
155
156	/* p_encoding.c */
157	PHP_FE(pdf_encoding_set_char, NULL)
158
159	/* p_font.c */
160	PHP_FE(pdf_findfont, NULL)
161	PHP_FE(pdf_load_font, NULL)
162	PHP_FE(pdf_setfont, NULL)
163
164	/* p_gstate.c */
165	PHP_FE(pdf_concat, NULL)
166	PHP_FE(pdf_initgraphics, NULL)
167	PHP_FE(pdf_restore, NULL)
168	PHP_FE(pdf_rotate, NULL)
169	PHP_FE(pdf_save, NULL)
170	PHP_FE(pdf_scale, NULL)
171	PHP_FE(pdf_setdash, NULL)
172	PHP_FE(pdf_setdashpattern, NULL)
173	PHP_FE(pdf_setflat, NULL)
174	PHP_FE(pdf_setlinecap, NULL)
175	PHP_FE(pdf_setlinejoin, NULL)
176	PHP_FE(pdf_setlinewidth, NULL)
177	PHP_FE(pdf_setmatrix, NULL)
178	PHP_FE(pdf_setmiterlimit, NULL)
179	PHP_FE(pdf_setpolydash, NULL)		/* deprecated since V5.0 */
180	PHP_FE(pdf_skew, NULL)
181	PHP_FE(pdf_translate, NULL)
182
183	/* p_hyper.c */
184	PHP_FE(pdf_add_bookmark, NULL)
185	PHP_FE(pdf_add_nameddest, NULL)
186	PHP_FE(pdf_set_info, NULL)
187
188	/* p_icc.c */
189	PHP_FE(pdf_load_iccprofile, NULL)
190
191	/* p_image.c */
192	PHP_FE(pdf_add_thumbnail, NULL)
193	PHP_FE(pdf_close_image, NULL)
194	PHP_FE(pdf_fit_image, NULL)
195	PHP_FE(pdf_load_image, NULL)
196	PHP_FE(pdf_open_ccitt, NULL)		/* deprecated since V5.0 */
197	PHP_FE(pdf_open_image, NULL)		/* deprecated since V5.0 */
198	PHP_FE(pdf_open_image_file, NULL)	/* deprecated since V5.0 */
199	PHP_FE(pdf_place_image, NULL)		/* deprecated since V5.0 */
200
201	/* p_params.c */
202	PHP_FE(pdf_get_parameter, NULL)
203	PHP_FE(pdf_get_value, NULL)
204	PHP_FE(pdf_set_parameter, NULL)
205	PHP_FE(pdf_set_value, NULL)
206
207	/* p_pattern.c */
208	PHP_FE(pdf_begin_pattern, NULL)
209	PHP_FE(pdf_end_pattern, NULL)
210
211	/* p_pdi.c */
212	PHP_FE(pdf_close_pdi, NULL)
213	PHP_FE(pdf_close_pdi_page, NULL)
214	PHP_FE(pdf_fit_pdi_page, NULL)
215	PHP_FE(pdf_get_pdi_parameter, NULL)
216	PHP_FE(pdf_get_pdi_value, NULL)
217	PHP_FE(pdf_open_pdi, NULL)
218	PHP_FE(pdf_open_pdi_page, NULL)
219	PHP_FE(pdf_place_pdi_page, NULL)	/* deprecated since V5.0 */
220	PHP_FE(pdf_process_pdi, NULL)
221
222	/* p_resource.c */
223	PHP_FE(pdf_create_pvf, NULL)
224	PHP_FE(pdf_delete_pvf, NULL)
225
226	/* p_shading.c */
227	PHP_FE(pdf_shading, NULL)
228	PHP_FE(pdf_shading_pattern, NULL)
229	PHP_FE(pdf_shfill, NULL)
230
231	/* p_template.c */
232	PHP_FE(pdf_begin_template, NULL)
233	PHP_FE(pdf_end_template, NULL)
234
235	/* p_text.c */
236	PHP_FE(pdf_continue_text, NULL)
237	PHP_FE(pdf_fit_textline, NULL)
238	PHP_FE(pdf_set_text_pos, NULL)
239	PHP_FE(pdf_show, NULL)
240	PHP_FE(pdf_show_boxed, NULL)
241	PHP_FE(pdf_show_xy, NULL)
242	PHP_FE(pdf_stringwidth, NULL)
243
244	/* p_type3.c */
245	PHP_FE(pdf_begin_font, NULL)
246	PHP_FE(pdf_begin_glyph, NULL)
247	PHP_FE(pdf_end_font, NULL)
248	PHP_FE(pdf_end_glyph, NULL)
249
250	/* p_xgstate.c */
251	PHP_FE(pdf_create_gstate, NULL)
252	PHP_FE(pdf_set_gstate, NULL)
253
254	/* exception handling */
255	PHP_FE(pdf_get_errnum, NULL)
256	PHP_FE(pdf_get_errmsg, NULL)
257	PHP_FE(pdf_get_apiname, NULL)
258
259	/* End of the official PDFLIB V3.x/V4.x/V5.x API */
260
261#if HAVE_LIBGD13
262	/* not supported by PDFlib GmbH */
263	PHP_FE(pdf_open_memory_image, NULL)
264#endif
265
266	{NULL, NULL, NULL}
267};
268/* }}} */
269
270/* {{{ pdf_module_entry
271 */
272zend_module_entry pdf_module_entry = {
273#if ZEND_MODULE_API_NO >= 20010901
274    STANDARD_MODULE_HEADER,
275#endif
276	"pdf",
277	pdf_functions,
278	PHP_MINIT(pdf),
279	PHP_MSHUTDOWN(pdf),
280	NULL,
281	NULL,
282	PHP_MINFO(pdf),
283#if ZEND_MODULE_API_NO >= 20010901
284    NO_VERSION_YET,
285#endif
286	STANDARD_MODULE_PROPERTIES
287};
288/* }}} */
289
290#ifdef COMPILE_DL_PDF
291ZEND_GET_MODULE(pdf)
292#endif
293
294/* PHP/PDFlib internal functions */
295/* {{{ _free_pdf_doc
296 */
297static void _free_pdf_doc(zend_rsrc_list_entry *rsrc)
298{
299	PDF *pdf = (PDF *)rsrc->ptr;
300	PDF_delete(pdf);
301}
302/* }}} */
303
304/* {{{ custom_errorhandler
305 */
306static void custom_errorhandler(PDF *p, int errnum, const char *shortmsg)
307{
308    if (errnum == PDF_NonfatalError)
309    {
310		/*
311		 * PDFlib warnings should be visible to the user.
312		 * If he decides to live with PDFlib warnings
313		 * he may use the PDFlib function
314		 * pdf_set_parameter($p, "warning" 0) to switch off
315		 * the warnings inside PDFlib.
316		 */
317		php_error(E_WARNING, "PDFlib warning %s", shortmsg);
318    }
319    else
320    {
321        /* give up in all other cases */
322		php_error(E_ERROR, "PDFlib error %s", shortmsg);
323    }
324}
325/* }}} */
326
327/* {{{ pdf_emalloc
328 */
329static void *pdf_emalloc(PDF *p, size_t size, const char *caller)
330{
331	return(emalloc(size));
332}
333/* }}} */
334
335/* {{{ pdf_realloc
336 */
337static void *pdf_realloc(PDF *p, void *mem, size_t size, const char *caller)
338{
339	return(erealloc(mem, size));
340}
341/* }}} */
342
343/* {{{ pdf_efree
344 */
345static void pdf_efree(PDF *p, void *mem)
346{
347	efree(mem);
348}
349/* }}} */
350
351/* {{{ PHP_MINFO_FUNCTION
352 */
353PHP_MINFO_FUNCTION(pdf)
354{
355	char tmp[32];
356
357	snprintf(tmp, 31, "%d.%02d", PDF_get_majorversion(), PDF_get_minorversion() );
358	tmp[31]=0;
359
360	php_info_print_table_start();
361	php_info_print_table_row(2, "PDF Support", "enabled" );
362	php_info_print_table_row(2, "PDFlib GmbH Version", PDFLIB_VERSIONSTRING );
363	php_info_print_table_row(2, "Revision", "$Revision: 1.1 $" );
364	php_info_print_table_end();
365
366}
367/* }}} */
368
369/* {{{ PHP_MINIT_FUNCTION
370 */
371PHP_MINIT_FUNCTION(pdf)
372{
373	if ((PDF_get_majorversion() != PDFLIB_MAJORVERSION) ||
374			(PDF_get_minorversion() != PDFLIB_MINORVERSION)) {
375		php_error(E_ERROR,"PDFlib error: Version mismatch in wrapper code");
376	}
377	le_pdf = zend_register_list_destructors_ex(_free_pdf_doc, NULL, "pdf object", module_number);
378
379	/* this does something like setlocale("C", ...) in PDFlib 3.x */
380	PDF_boot();
381	return SUCCESS;
382}
383/* }}} */
384
385/* {{{ PHP_MSHUTDOWN_FUNCTION
386 */
387PHP_MSHUTDOWN_FUNCTION(pdf)
388{
389	PDF_shutdown();
390	return SUCCESS;
391}
392/* }}} */
393
394
395/* p_annots.c */
396
397/* {{{ proto void pdf_add_launchlink(int pdfdoc, float llx, float lly, float urx, float ury, string filename)
398 * Add a launch annotation (to a target of arbitrary file type). */
399PHP_FUNCTION(pdf_add_launchlink)
400{
401	zval **p, **llx, **lly, **urx, **ury, **filename;
402	PDF *pdf;
403	const char * vfilename;
404
405	if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &p, &llx, &lly, &urx, &ury, &filename) == FAILURE) {
406		WRONG_PARAM_COUNT;
407	}
408
409	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
410
411	convert_to_double_ex(llx);
412	convert_to_double_ex(lly);
413	convert_to_double_ex(urx);
414	convert_to_double_ex(ury);
415	convert_to_string_ex(filename);
416
417#ifdef VIRTUAL_DIR
418#    if ZEND_MODULE_API_NO >= 20010901
419	virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
420#    else
421	virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
422#    endif
423#else
424	vfilename = Z_STRVAL_PP(filename);
425#endif
426
427	PDF_add_launchlink(pdf,
428		(float) Z_DVAL_PP(llx),
429		(float) Z_DVAL_PP(lly),
430		(float) Z_DVAL_PP(urx),
431		(float) Z_DVAL_PP(ury),
432		vfilename);
433
434	RETURN_TRUE;
435}
436/* }}} */
437
438/* TODO [optlist] */
439/* {{{ proto void pdf_add_locallink(int pdfdoc, float llx, float lly, float urx, float ury, int page, string optlist)
440 * Add a link annotation to a target within the current PDF file. */
441PHP_FUNCTION(pdf_add_locallink)
442{
443	zval **p, **llx, **lly, **urx, **ury, **page, **optlist;
444	PDF *pdf;
445
446	if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &p, &llx, &lly, &urx, &ury, &page, &optlist) == FAILURE) {
447		WRONG_PARAM_COUNT;
448	}
449
450	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
451
452	convert_to_double_ex(llx);
453	convert_to_double_ex(lly);
454	convert_to_double_ex(urx);
455	convert_to_double_ex(ury);
456	convert_to_long_ex(page);
457	convert_to_string_ex(optlist);
458
459	PDF_add_locallink(pdf,
460		(float) Z_DVAL_PP(llx),
461		(float) Z_DVAL_PP(lly),
462		(float) Z_DVAL_PP(urx),
463		(float) Z_DVAL_PP(ury),
464		Z_LVAL_PP(page),
465		Z_STRVAL_PP(optlist));
466
467	RETURN_TRUE;
468}
469/* }}} */
470
471/* {{{ proto void pdf_add_note(int pdfdoc, float llx, float lly, float urx, float ury, string contents, string title, string icon, int open)
472 * Add a note annotation. icon is one of of "comment", "insert", "note", "paragraph", "newparagraph", "key", or "help". */
473PHP_FUNCTION(pdf_add_note)
474{
475	zval **p, **llx, **lly, **urx, **ury, **contents, **title, **icon, **open;
476	PDF *pdf;
477
478	if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &p, &llx, &lly, &urx, &ury, &contents, &title, &icon, &open) == FAILURE) {
479		WRONG_PARAM_COUNT;
480	}
481
482	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
483
484	convert_to_double_ex(llx);
485	convert_to_double_ex(lly);
486	convert_to_double_ex(urx);
487	convert_to_double_ex(ury);
488	convert_to_string_ex(contents);
489	convert_to_string_ex(title);
490	convert_to_string_ex(icon);
491	convert_to_long_ex(open);
492
493	PDF_add_note2(pdf,
494		 (float) Z_DVAL_PP(llx),
495		 (float) Z_DVAL_PP(lly),
496		 (float) Z_DVAL_PP(urx),
497		 (float) Z_DVAL_PP(ury),
498		 Z_STRVAL_PP(contents),
499		 Z_STRLEN_PP(contents),
500		 Z_STRVAL_PP(title),
501		 Z_STRLEN_PP(title),
502		 Z_STRVAL_PP(icon),
503		 Z_LVAL_PP(open));
504
505	RETURN_TRUE;
506}
507/* }}} */
508
509/* TODO [optlist] */
510/* {{{ proto void pdf_add_pdflink(int pdfdoc, float llx, float lly, float urx, float ury, string filename, int page, string optlist)
511 * Add a file link annotation (to a PDF target). */
512PHP_FUNCTION(pdf_add_pdflink)
513{
514	zval **p, **llx, **lly, **urx, **ury, **filename, **page, **optlist;
515	PDF *pdf;
516	const char * vfilename;
517
518	if (ZEND_NUM_ARGS() != 8 || zend_get_parameters_ex(8, &p, &llx, &lly, &urx, &ury, &filename, &page, &optlist) == FAILURE) {
519		WRONG_PARAM_COUNT;
520	}
521
522	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
523
524	convert_to_double_ex(llx);
525	convert_to_double_ex(lly);
526	convert_to_double_ex(urx);
527	convert_to_double_ex(ury);
528	convert_to_string_ex(filename);
529	convert_to_long_ex(page);
530	convert_to_string_ex(optlist);
531#ifdef VIRTUAL_DIR
532#    if ZEND_MODULE_API_NO >= 20010901
533	virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
534#    else
535	virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
536#    endif
537#else
538	vfilename = Z_STRVAL_PP(filename);
539#endif
540
541	PDF_add_pdflink(pdf, (float) Z_DVAL_PP(llx),
542						 (float) Z_DVAL_PP(lly),
543						 (float) Z_DVAL_PP(urx),
544						 (float) Z_DVAL_PP(ury),
545						 vfilename,
546						 Z_LVAL_PP(page),
547						 Z_STRVAL_PP(optlist));
548
549	RETURN_TRUE;
550}
551/* }}} */
552
553/* {{{ proto void pdf_add_weblink(int pdfdoc, float llx, float lly, float urx, float ury, string url)
554 * Add a weblink annotation to a target URL on the Web. */
555PHP_FUNCTION(pdf_add_weblink)
556{
557	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6;
558	PDF *pdf;
559
560	if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) {
561		WRONG_PARAM_COUNT;
562	}
563
564	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
565
566	convert_to_double_ex(arg2);
567	convert_to_double_ex(arg3);
568	convert_to_double_ex(arg4);
569	convert_to_double_ex(arg5);
570	convert_to_string_ex(arg6);
571	PDF_add_weblink(pdf, (float) Z_DVAL_PP(arg2),
572						 (float) Z_DVAL_PP(arg3),
573						 (float) Z_DVAL_PP(arg4),
574						 (float) Z_DVAL_PP(arg5),
575						 Z_STRVAL_PP(arg6));
576	RETURN_TRUE;
577}
578/* }}} */
579
580/* {{{ proto void pdf_attach_file(int pdfdoc, float lly, float lly, float urx, float ury, string filename, string description, string author, string mimetype, string icon)
581 * Add a file attachment annotation. icon is one of "graph", "paperclip", "pushpin", or "tag". */
582PHP_FUNCTION(pdf_attach_file)
583{
584	zval **p, **llx, **lly, **urx, **ury, **filename, **description, **author, **mimetype, **icon;
585	PDF *pdf;
586	const char * vfilename;
587
588	if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &p, &llx, &lly, &urx, &ury, &filename, &description, &author, &mimetype, &icon) == FAILURE) {
589		WRONG_PARAM_COUNT;
590	}
591
592	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
593
594	convert_to_double_ex(llx);
595	convert_to_double_ex(lly);
596	convert_to_double_ex(urx);
597	convert_to_double_ex(ury);
598	convert_to_string_ex(filename);
599	convert_to_string_ex(description);
600	convert_to_string_ex(author);
601	convert_to_string_ex(mimetype);
602	convert_to_string_ex(icon);
603
604#ifdef VIRTUAL_DIR
605#    if ZEND_MODULE_API_NO >= 20010901
606	virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
607#    else
608	virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
609#    endif
610#else
611	vfilename = Z_STRVAL_PP(filename);
612#endif
613
614
615	PDF_attach_file2(pdf,
616		(float) Z_DVAL_PP(llx),
617		(float) Z_DVAL_PP(lly),
618		(float) Z_DVAL_PP(urx),
619		(float) Z_DVAL_PP(ury),
620		vfilename,
621		0,
622		Z_STRVAL_PP(description),
623		Z_STRLEN_PP(description),
624		Z_STRVAL_PP(author),
625		Z_STRLEN_PP(author),
626		Z_STRVAL_PP(mimetype),
627		Z_STRVAL_PP(icon));
628
629	RETURN_TRUE;
630}
631/* }}} */
632
633/* {{{ proto void pdf_set_border_color(int pdfdoc, float red, float green, float blue)
634 * Set the border color for all kinds of annotations. */
635PHP_FUNCTION(pdf_set_border_color)
636{
637	zval **arg1, **arg2, **arg3, **arg4;
638	PDF *pdf;
639
640	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
641		WRONG_PARAM_COUNT;
642	}
643
644	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
645
646	convert_to_double_ex(arg2);
647	convert_to_double_ex(arg3);
648	convert_to_double_ex(arg4);
649	PDF_set_border_color(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4));
650	RETURN_TRUE;
651}
652/* }}} */
653
654/* {{{ proto void pdf_set_border_dash(int pdfdoc, float b, float w)
655 * Set the border dash style for all kinds of annotations. See PDF_setdash(). */
656PHP_FUNCTION(pdf_set_border_dash)
657{
658	zval **arg1, **arg2, **arg3;
659	PDF *pdf;
660
661	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
662		WRONG_PARAM_COUNT;
663	}
664
665	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
666
667	convert_to_double_ex(arg2);
668	convert_to_double_ex(arg3);
669	PDF_set_border_dash(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
670	RETURN_TRUE;
671}
672/* }}} */
673
674/* {{{ proto void pdf_set_border_style(int pdfdoc, string style, float width)
675 * Set the border style for all kinds of annotations. style is "solid" or "dashed". */
676PHP_FUNCTION(pdf_set_border_style)
677{
678	zval **arg1, **arg2, **arg3;
679	PDF *pdf;
680
681	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
682		WRONG_PARAM_COUNT;
683	}
684
685	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
686
687	convert_to_string_ex(arg2);
688	convert_to_double_ex(arg3);
689	PDF_set_border_style(pdf, Z_STRVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
690	RETURN_TRUE;
691}
692/* }}} */
693
694/* p_basic.c */
695
696/* {{{ proto void pdf_begin_page(int pdfdoc, float width, float height)
697 * Add a new page to the document. */
698PHP_FUNCTION(pdf_begin_page)
699{
700	zval **arg1, **arg2, **arg3;
701	PDF *pdf;
702
703	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
704		WRONG_PARAM_COUNT;
705	}
706
707	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
708
709	convert_to_double_ex(arg2);
710	convert_to_double_ex(arg3);
711	PDF_begin_page(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
712	RETURN_TRUE;
713}
714/* }}} */
715
716/* {{{ proto void pdf_close(int pdfdoc)
717 * Close the generated PDF file, and release all document-related resources. */
718PHP_FUNCTION(pdf_close)
719{
720	zval **arg1;
721	PDF *pdf;
722
723	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
724		WRONG_PARAM_COUNT;
725	}
726
727	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
728
729	PDF_close(pdf);
730
731	RETURN_TRUE;
732}
733
734/* }}} */
735
736/* {{{ proto bool pdf_delete(int pdfdoc)
737 * Delete the PDF object, and free all internal resources. */
738PHP_FUNCTION(pdf_delete)
739{
740	zval **arg1;
741	PDF *pdf;
742
743	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
744		WRONG_PARAM_COUNT;
745	}
746
747	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
748
749#ifndef Z_RESVAL        /* for php 4.0.3pl1 */
750#define Z_RESVAL(zval)            (zval).value.lval
751#define Z_RESVAL_PP(zval_pp)      Z_RESVAL(**zval_pp)
752#endif
753	zend_list_delete(Z_RESVAL_PP(arg1));
754
755	RETURN_TRUE;
756}
757
758/* }}} */
759
760/* {{{ proto void pdf_end_page(int pdfdoc)
761 * Finish the page. */
762PHP_FUNCTION(pdf_end_page)
763{
764	zval **arg1;
765	PDF *pdf;
766
767	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
768		WRONG_PARAM_COUNT;
769	}
770
771	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
772
773	PDF_end_page(pdf);
774	RETURN_TRUE;
775}
776/* }}} */
777
778/* {{{ proto int pdf_get_apiname(int pdfdoc);
779 * Get the name of the API function which threw the last exception or failed. */
780PHP_FUNCTION(pdf_get_apiname)
781{
782        zval **p;
783        PDF *pdf;
784		char *buffer;
785
786        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p) == FAILURE) {
787                WRONG_PARAM_COUNT;
788        }
789
790        ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
791
792        buffer = PDF_get_apiname(pdf);
793
794		RETURN_STRING(buffer, 1);
795}
796/* }}} */
797
798/* {{{ proto int pdf_get_buffer(int pdfdoc)
799 * Get the contents of the PDF output buffer. The result must be used by the client before calling any other PDFlib function. */
800PHP_FUNCTION(pdf_get_buffer)
801{
802	zval **arg1;
803	long size;
804	PDF *pdf;
805	const char *buffer;
806
807	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
808		WRONG_PARAM_COUNT;
809	}
810
811	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
812
813	buffer = PDF_get_buffer(pdf, &size);
814
815	RETURN_STRINGL((char *)buffer, size, 1);
816}
817
818/* }}} */
819
820/* {{{ proto int pdf_get_errmsg(int pdfdoc);
821 * Get the contents of the PDF output buffer. The result must be used by
822 * the client before calling any other PDFlib function. */
823PHP_FUNCTION(pdf_get_errmsg)
824{
825        zval **p;
826        PDF *pdf;
827		char *buffer;
828
829        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p) == FAILURE) {
830                WRONG_PARAM_COUNT;
831        }
832
833        ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
834
835        buffer = PDF_get_errmsg(pdf);
836
837		RETURN_STRING(buffer, 1);
838}
839/* }}} */
840
841/* {{{ proto int pdf_get_errnum(int pdfdoc);
842 * Get the descriptive text of the last thrown exception, or the reason of
843 * a failed function call.*/
844PHP_FUNCTION(pdf_get_errnum)
845{
846        zval **p;
847        PDF *pdf;
848		int retval;
849
850        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p) == FAILURE) {
851                WRONG_PARAM_COUNT;
852        }
853
854        ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
855
856        retval = PDF_get_errnum(pdf);
857
858		RETURN_LONG(retval);
859}
860/* }}} */
861
862/* {{{ proto int pdf_new()
863 * Creates a new PDF object */
864PHP_FUNCTION(pdf_new)
865{
866	PDF *pdf;
867
868	pdf = PDF_new2(custom_errorhandler, pdf_emalloc, pdf_realloc, pdf_efree, NULL);
869	if (pdf != NULL) {
870		PDF_set_parameter(pdf, "imagewarning", "true");
871
872		/* Trigger special handling of PDFlib-handles for PHP */
873		PDF_set_parameter(pdf, "hastobepos", "true");
874		PDF_set_parameter(pdf, "binding", "PHP");
875		ZEND_REGISTER_RESOURCE(return_value, pdf, le_pdf);
876	} else {
877		php_error(E_ERROR, "PDF_new: internal error");
878	}
879
880}
881
882/* }}} */
883
884/* {{{ proto int pdf_open_file(int pdfdoc [, char filename])
885 * Create a new PDF file using the supplied file name. */
886PHP_FUNCTION(pdf_open_file)
887{
888	zval **p, **filename;
889	int pdf_file;
890	const char *vfilename;
891	int argc;
892	PDF *pdf;
893
894	if((argc = ZEND_NUM_ARGS()) > 2)
895		WRONG_PARAM_COUNT;
896
897	if (argc == 1) {
898		if (zend_get_parameters_ex(1, &p) == FAILURE)
899			WRONG_PARAM_COUNT;
900	} else {
901		if (zend_get_parameters_ex(2, &p, &filename) == FAILURE)
902			WRONG_PARAM_COUNT;
903	}
904
905	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
906
907	if (argc == 2) {
908		convert_to_string_ex(filename);
909#ifdef VIRTUAL_DIR
910#    if ZEND_MODULE_API_NO >= 20010901
911		virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
912#    else
913		virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
914#    endif
915#else
916		vfilename = Z_STRVAL_PP(filename);
917#endif
918
919		pdf_file = PDF_open_file(pdf, vfilename);
920	} else {
921		/* open in memory */
922		pdf_file = PDF_open_file(pdf, "");
923	}
924
925	RETURN_LONG(pdf_file); /* change return from -1 to 0 handled by PDFlib */
926}
927
928/* }}} */
929
930/* p_block.c */
931
932/* TODO [optlist] */
933/* {{{ proto int pdf_fill_imageblock(int pdfdoc, int page, string spotname, int image, string optlist);
934 * Process an image block according to its properties. */
935PHP_FUNCTION(pdf_fill_imageblock)
936{
937	zval **p, **page, **blockname, **image, **optlist;
938	PDF *pdf;
939	int retval;
940
941	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &page, &blockname, &image, &optlist) == FAILURE) {
942		WRONG_PARAM_COUNT;
943	}
944
945	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
946
947	convert_to_long_ex(page);
948	convert_to_string_ex(blockname);
949	convert_to_long_ex(image);
950	convert_to_string_ex(optlist);
951
952	retval = PDF_fill_imageblock(pdf,
953		Z_LVAL_PP(page),
954		Z_STRVAL_PP(blockname),
955		Z_LVAL_PP(image),
956		Z_STRVAL_PP(optlist));
957
958	RETURN_LONG(retval); /* change return from -1 to 0 handled by PDFlib */
959}
960/* }}} */
961
962/* TODO [optlist] */
963/* {{{ proto int pdf_fill_pdfblock(int pdfdoc, int page, string spotname, int contents, string optlist);
964 * Process a PDF block according to its properties. */
965PHP_FUNCTION(pdf_fill_pdfblock)
966{
967	zval **p, **page, **blockname, **contents, **optlist;
968	PDF *pdf;
969	int retval;
970
971	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &page, &blockname, &contents, &optlist) == FAILURE) {
972		WRONG_PARAM_COUNT;
973	}
974
975	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
976
977	convert_to_long_ex(page);
978	convert_to_string_ex(blockname);
979	convert_to_long_ex(contents);
980	convert_to_string_ex(optlist);
981
982	retval = PDF_fill_pdfblock(pdf,
983		Z_LVAL_PP(page),
984		Z_STRVAL_PP(blockname),
985		Z_LVAL_PP(contents),
986		Z_STRVAL_PP(optlist));
987
988	RETURN_LONG(retval); /* change return from -1 to 0 handled by PDFlib */
989}
990/* }}} */
991
992/* TODO [optlist] */
993/* {{{ proto int pdf_fill_textblock(int pdfdoc, int page, string spotname, string text, string optlist);
994 * Process a text block according to its properties. */
995PHP_FUNCTION(pdf_fill_textblock)
996{
997	zval **p, **page, **blockname, **text, **optlist;
998	PDF *pdf;
999	int retval;
1000
1001	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &page, &blockname, &text, &optlist) == FAILURE) {
1002		WRONG_PARAM_COUNT;
1003	}
1004
1005	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
1006
1007	convert_to_long_ex(page);
1008	convert_to_string_ex(blockname);
1009	convert_to_string_ex(text);
1010	convert_to_string_ex(optlist);
1011
1012	retval = PDF_fill_textblock(pdf,
1013		Z_LVAL_PP(page),
1014		Z_STRVAL_PP(blockname),
1015		Z_STRVAL_PP(text),
1016		Z_STRLEN_PP(text),
1017		Z_STRVAL_PP(optlist));
1018
1019	RETURN_LONG(retval); /* change return from -1 to 0 handled by PDFlib */
1020}
1021/* }}} */
1022
1023/* p_color.c */
1024
1025/* {{{ proto int pdf_makespotcolor(int pdfdoc, string spotname);
1026 * Make a named spot color from the current color. */
1027PHP_FUNCTION(pdf_makespotcolor)
1028{
1029	zval **arg1, **arg2;
1030	PDF *pdf;
1031	int spotcolor;
1032
1033	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1034		WRONG_PARAM_COUNT;
1035	}
1036
1037	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1038
1039	convert_to_string_ex(arg2);
1040
1041	spotcolor = PDF_makespotcolor(pdf,
1042		Z_STRVAL_PP(arg2),
1043		Z_STRLEN_PP(arg2));
1044
1045	RETURN_LONG(spotcolor); /* offset handled in PDFlib Kernel */
1046}
1047/* }}} */
1048
1049/* {{{ proto void pdf_setcolor(int pdfdoc, string fstype, string colorspace, float c1 [, float c2 [, float c3 [, float c4]]]);
1050 * Set the current color space and color. fstype is "fill", "stroke", or "both". */
1051PHP_FUNCTION(pdf_setcolor)
1052{
1053	zval **p, **fstype, **colorspace, **c1, **c2, **c3, **c4;
1054	PDF *pdf;
1055	int argc = ZEND_NUM_ARGS();
1056
1057	if(argc < 4 || argc > 7) {
1058		WRONG_PARAM_COUNT;
1059	}
1060	switch(argc) {
1061		case 4:
1062			if(zend_get_parameters_ex(4, &p, &fstype, &colorspace, &c1) == FAILURE) {
1063				WRONG_PARAM_COUNT;
1064			}
1065			break;
1066		case 5:
1067			if(zend_get_parameters_ex(5, &p, &fstype, &colorspace, &c1, &c2) == FAILURE) {
1068				WRONG_PARAM_COUNT;
1069			}
1070			break;
1071		case 6:
1072			if(zend_get_parameters_ex(6, &p, &fstype, &colorspace, &c1, &c2, &c3) == FAILURE) {
1073				WRONG_PARAM_COUNT;
1074			}
1075			break;
1076		case 7:
1077			if(zend_get_parameters_ex(7, &p, &fstype, &colorspace, &c1, &c2, &c3, &c4) == FAILURE) {
1078				WRONG_PARAM_COUNT;
1079			}
1080			break;
1081	}
1082
1083	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
1084
1085	convert_to_string_ex(fstype);
1086	convert_to_string_ex(colorspace);
1087	convert_to_double_ex(c1);
1088	if(argc > 4) convert_to_double_ex(c2);
1089	if(argc > 5) convert_to_double_ex(c3);
1090	if(argc > 6) convert_to_double_ex(c4);
1091
1092
1093	PDF_setcolor(pdf,
1094		Z_STRVAL_PP(fstype),
1095		Z_STRVAL_PP(colorspace),
1096	    (float) Z_DVAL_PP(c1),
1097		(float) ((argc>4) ? Z_DVAL_PP(c2):0),
1098		(float) ((argc>5) ? Z_DVAL_PP(c3):0),
1099		(float) ((argc>6) ? Z_DVAL_PP(c4):0));
1100
1101	RETURN_TRUE;
1102}
1103/* }}} */
1104
1105/* {{{ proto void pdf_setgray(int pdfdoc, float value)
1106 * Depricated user pdf_setcolor instead */
1107PHP_FUNCTION(pdf_setgray)
1108{
1109	zval **arg1, **arg2;
1110	PDF *pdf;
1111
1112	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1113		WRONG_PARAM_COUNT;
1114	}
1115
1116	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1117
1118	convert_to_double_ex(arg2);
1119	PDF_setcolor(pdf, "both", "gray", (float) Z_DVAL_PP(arg2), 0, 0, 0);
1120	RETURN_TRUE;
1121}
1122/* }}} */
1123
1124/* {{{ proto void pdf_setgray_fill(int pdfdoc, float value)
1125 * Depricated user pdf_setcolor instead */
1126PHP_FUNCTION(pdf_setgray_fill)
1127{
1128	zval **arg1, **arg2;
1129	PDF *pdf;
1130
1131	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1132		WRONG_PARAM_COUNT;
1133	}
1134
1135	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1136
1137	convert_to_double_ex(arg2);
1138	PDF_setcolor(pdf, "fill", "gray", (float) Z_DVAL_PP(arg2), 0, 0, 0);
1139	RETURN_TRUE;
1140}
1141/* }}} */
1142
1143/* {{{ proto void pdf_setgray_stroke(int pdfdoc, float value)
1144 * Depricated user pdf_setcolor instead */
1145PHP_FUNCTION(pdf_setgray_stroke)
1146{
1147	zval **arg1, **arg2;
1148	PDF *pdf;
1149
1150	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1151		WRONG_PARAM_COUNT;
1152	}
1153
1154	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1155
1156	convert_to_double_ex(arg2);
1157	PDF_setcolor(pdf, "stroke", "gray", (float) Z_DVAL_PP(arg2), 0, 0, 0);
1158	RETURN_TRUE;
1159}
1160/* }}} */
1161
1162/* {{{ proto void pdf_setrgbcolor(int pdfdoc, float red, float green, float blue)
1163 * Depricated user pdf_setcolor instead */
1164PHP_FUNCTION(pdf_setrgbcolor)
1165{
1166	zval **arg1, **arg2, **arg3, **arg4;
1167	PDF *pdf;
1168
1169	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
1170		WRONG_PARAM_COUNT;
1171	}
1172
1173	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1174
1175	convert_to_double_ex(arg2);
1176	convert_to_double_ex(arg3);
1177	convert_to_double_ex(arg4);
1178	PDF_setcolor(pdf, "both", "rgb", (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4), 0);
1179	RETURN_TRUE;
1180}
1181/* }}} */
1182
1183/* {{{ proto void pdf_setrgbcolor_fill(int pdfdoc, float red, float green, float blue)
1184 * Depricated user pdf_setcolor instead */
1185PHP_FUNCTION(pdf_setrgbcolor_fill)
1186{
1187	zval **arg1, **arg2, **arg3, **arg4;
1188	PDF *pdf;
1189
1190	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
1191		WRONG_PARAM_COUNT;
1192	}
1193
1194	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1195
1196	convert_to_double_ex(arg2);
1197	convert_to_double_ex(arg3);
1198	convert_to_double_ex(arg4);
1199	PDF_setcolor(pdf, "fill", "rgb", (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4), 0);
1200	RETURN_TRUE;
1201}
1202/* }}} */
1203
1204/* {{{ proto void pdf_setrgbcolor_stroke(int pdfdoc, float red, float green, float blue)
1205 * Depricated user pdf_setcolor instead */
1206PHP_FUNCTION(pdf_setrgbcolor_stroke)
1207{
1208	zval **arg1, **arg2, **arg3, **arg4;
1209	PDF *pdf;
1210
1211	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
1212		WRONG_PARAM_COUNT;
1213	}
1214
1215	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1216
1217	convert_to_double_ex(arg2);
1218	convert_to_double_ex(arg3);
1219	convert_to_double_ex(arg4);
1220	PDF_setcolor(pdf, "stroke", "rgb", (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4), 0);
1221	RETURN_TRUE;
1222}
1223/* }}} */
1224
1225/* p_draw.c */
1226
1227/* {{{ proto void pdf_arc(int pdfdoc, float x, float y, float r, float alpha, float beta)
1228 * Draw a counterclockwise circular arc from alpha to beta degrees. */
1229PHP_FUNCTION(pdf_arc)
1230{
1231	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6;
1232	PDF *pdf;
1233
1234	if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) {
1235		WRONG_PARAM_COUNT;
1236	}
1237
1238	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1239
1240	convert_to_double_ex(arg2);
1241	convert_to_double_ex(arg3);
1242	convert_to_double_ex(arg4);
1243	convert_to_double_ex(arg5);
1244	convert_to_double_ex(arg6);
1245
1246	PDF_arc(pdf, (float) Z_DVAL_PP(arg2),
1247				 (float) Z_DVAL_PP(arg3),
1248				 (float) Z_DVAL_PP(arg4),
1249				 (float) Z_DVAL_PP(arg5),
1250				 (float) Z_DVAL_PP(arg6));
1251
1252	RETURN_TRUE;
1253}
1254/* }}} */
1255
1256/* {{{ proto void pdf_arcn(int pdfdoc, float x, float y, float r, float alpha, float beta);
1257 * Draw a clockwise circular arc from alpha to beta degrees. */
1258PHP_FUNCTION(pdf_arcn)
1259{
1260	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6;
1261	PDF *pdf;
1262
1263	if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) {
1264		WRONG_PARAM_COUNT;
1265	}
1266
1267	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1268
1269	convert_to_double_ex(arg2);
1270	convert_to_double_ex(arg3);
1271	convert_to_double_ex(arg4);
1272	convert_to_double_ex(arg5);
1273	convert_to_double_ex(arg6);
1274
1275	PDF_arcn(pdf,
1276		(float) Z_DVAL_PP(arg2),
1277		(float) Z_DVAL_PP(arg3),
1278		(float) Z_DVAL_PP(arg4),
1279		(float) Z_DVAL_PP(arg5),
1280		(float) Z_DVAL_PP(arg6));
1281
1282	RETURN_TRUE;
1283}
1284/* }}} */
1285
1286/* {{{ proto void pdf_circle(int pdfdoc, float x, float y, float r)
1287 * Draw a circle with center (x, y) and radius r. */
1288PHP_FUNCTION(pdf_circle)
1289{
1290	zval **arg1, **arg2, **arg3, **arg4;
1291	PDF *pdf;
1292
1293	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
1294		WRONG_PARAM_COUNT;
1295	}
1296
1297	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1298
1299	convert_to_double_ex(arg2);
1300	convert_to_double_ex(arg3);
1301	convert_to_double_ex(arg4);
1302	PDF_circle(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4));
1303	RETURN_TRUE;
1304}
1305/* }}} */
1306
1307/* {{{ proto void pdf_clip(int pdfdoc)
1308 * Use the current path as clipping path. */
1309PHP_FUNCTION(pdf_clip)
1310{
1311	zval **arg1;
1312	PDF *pdf;
1313
1314	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1315		WRONG_PARAM_COUNT;
1316	}
1317
1318	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1319
1320	PDF_clip(pdf);
1321	RETURN_TRUE;
1322}
1323/* }}} */
1324
1325/* {{{ proto void pdf_closepath(int pdfdoc)
1326 * Close the current path. */
1327PHP_FUNCTION(pdf_closepath)
1328{
1329	zval **arg1;
1330	PDF *pdf;
1331
1332	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1333		WRONG_PARAM_COUNT;
1334	}
1335
1336	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1337
1338	PDF_closepath(pdf);
1339	RETURN_TRUE;
1340}
1341/* }}} */
1342
1343/* {{{ proto void pdf_closepath_fill_stroke(int pdfdoc)
1344 * Close the path, fill, and stroke it. */
1345PHP_FUNCTION(pdf_closepath_fill_stroke)
1346{
1347	zval **arg1;
1348	PDF *pdf;
1349
1350	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1351		WRONG_PARAM_COUNT;
1352	}
1353
1354	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1355
1356	PDF_closepath_fill_stroke(pdf);
1357	RETURN_TRUE;
1358}
1359/* }}} */
1360
1361/* {{{ proto void pdf_closepath_stroke(int pdfdoc)
1362 * Close the path, and stroke it. */
1363PHP_FUNCTION(pdf_closepath_stroke)
1364{
1365	zval **arg1;
1366	PDF *pdf;
1367
1368	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1369		WRONG_PARAM_COUNT;
1370	}
1371
1372	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1373
1374	PDF_closepath_stroke(pdf);
1375	RETURN_TRUE;
1376}
1377/* }}} */
1378
1379/* {{{ proto void pdf_curveto(int pdfdoc, float x1, float y1, float x2, float y2, float x3, float y3)
1380 * Draw a Bezier curve from the current point, using 3 more control points. */
1381PHP_FUNCTION(pdf_curveto)
1382{
1383	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7;
1384	PDF *pdf;
1385
1386	if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7) == FAILURE) {
1387		WRONG_PARAM_COUNT;
1388	}
1389
1390	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1391
1392	convert_to_double_ex(arg2);
1393	convert_to_double_ex(arg3);
1394	convert_to_double_ex(arg4);
1395	convert_to_double_ex(arg5);
1396	convert_to_double_ex(arg6);
1397	convert_to_double_ex(arg7);
1398
1399	PDF_curveto(pdf, (float) Z_DVAL_PP(arg2),
1400					 (float) Z_DVAL_PP(arg3),
1401					 (float) Z_DVAL_PP(arg4),
1402					 (float) Z_DVAL_PP(arg5),
1403					 (float) Z_DVAL_PP(arg6),
1404					 (float) Z_DVAL_PP(arg7));
1405
1406	RETURN_TRUE;
1407}
1408/* }}} */
1409
1410/* {{{ proto void pdf_endpath(int pdfdoc)
1411 *  End the current path without filling or stroking it. */
1412PHP_FUNCTION(pdf_endpath)
1413{
1414	zval **arg1;
1415	PDF *pdf;
1416
1417	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1418		WRONG_PARAM_COUNT;
1419	}
1420
1421	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1422
1423	PDF_endpath(pdf);
1424	RETURN_TRUE;
1425}
1426/* }}} */
1427
1428/* {{{ proto void pdf_fill(int pdfdoc)
1429 * Fill the interior of the path with the current fill color. */
1430PHP_FUNCTION(pdf_fill)
1431{
1432	zval **arg1;
1433	PDF *pdf;
1434
1435	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1436		WRONG_PARAM_COUNT;
1437	}
1438
1439	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1440
1441	PDF_fill(pdf);
1442	RETURN_TRUE;
1443}
1444/* }}} */
1445
1446/* {{{ proto void pdf_fill_stroke(int pdfdoc)
1447 * Fill and stroke the path with the current fill and stroke color. */
1448PHP_FUNCTION(pdf_fill_stroke)
1449{
1450	zval **arg1;
1451	PDF *pdf;
1452
1453	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1454		WRONG_PARAM_COUNT;
1455	}
1456
1457	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1458
1459	PDF_fill_stroke(pdf);
1460	RETURN_TRUE;
1461}
1462/* }}} */
1463
1464/* {{{ proto void pdf_lineto(int pdfdoc, float x, float y)
1465 * Draw a line from the current point to (x, y). */
1466PHP_FUNCTION(pdf_lineto)
1467{
1468	zval **arg1, **arg2, **arg3;
1469	PDF *pdf;
1470
1471	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
1472		WRONG_PARAM_COUNT;
1473	}
1474
1475	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1476
1477	convert_to_double_ex(arg2);
1478	convert_to_double_ex(arg3);
1479	PDF_lineto(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
1480	RETURN_TRUE;
1481}
1482/* }}} */
1483
1484/* {{{ proto void pdf_moveto(int pdfdoc, float x, float y)
1485 * Set the current point. */
1486PHP_FUNCTION(pdf_moveto)
1487{
1488	zval **arg1, **arg2, **arg3;
1489	PDF *pdf;
1490
1491	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
1492		WRONG_PARAM_COUNT;
1493	}
1494
1495	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1496
1497	convert_to_double_ex(arg2);
1498	convert_to_double_ex(arg3);
1499	PDF_moveto(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
1500	RETURN_TRUE;
1501}
1502/* }}} */
1503
1504/* {{{ proto void pdf_rect(int pdfdoc, float x, float y, float width, float height)
1505 * Draw a rectangle at lower left (x, y) with width and height. */
1506PHP_FUNCTION(pdf_rect)
1507{
1508	zval **arg1, **arg2, **arg3, **arg4, **arg5;
1509	PDF *pdf;
1510
1511	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &arg1, &arg2, &arg3, &arg4, &arg5) == FAILURE) {
1512		WRONG_PARAM_COUNT;
1513	}
1514
1515	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1516
1517	convert_to_double_ex(arg2);
1518	convert_to_double_ex(arg3);
1519	convert_to_double_ex(arg4);
1520	convert_to_double_ex(arg5);
1521
1522	PDF_rect(pdf, (float) Z_DVAL_PP(arg2),
1523				  (float) Z_DVAL_PP(arg3),
1524				  (float) Z_DVAL_PP(arg4),
1525				  (float) Z_DVAL_PP(arg5));
1526
1527	RETURN_TRUE;
1528}
1529/* }}} */
1530
1531/* {{{ proto void pdf_stroke(int pdfdoc)
1532 * Stroke the path with the current color and line width, and clear it. */
1533PHP_FUNCTION(pdf_stroke)
1534{
1535	zval **arg1;
1536	PDF *pdf;
1537
1538	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1539		WRONG_PARAM_COUNT;
1540	}
1541
1542	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1543
1544	PDF_stroke(pdf);
1545	RETURN_TRUE;
1546}
1547/* }}} */
1548
1549/* p_encoding.c */
1550
1551/* {{{ proto void pdf_encoding_set_char(int pdfdoc, string encoding, int slot, string glyphname, int uv);
1552 * Add a glyph name to a custom encoding. */
1553PHP_FUNCTION(pdf_encoding_set_char)
1554{
1555        zval **p, **encoding, **slot, **glyphname, **uv;
1556        PDF *pdf;
1557
1558        if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &encoding, &slot, &glyphname, &uv) == FAILURE) {
1559                WRONG_PARAM_COUNT;
1560        }
1561
1562        ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
1563
1564        convert_to_string_ex(encoding);
1565        convert_to_long_ex(slot);
1566        convert_to_string_ex(glyphname);
1567        convert_to_long_ex(uv);
1568
1569        PDF_encoding_set_char(pdf,
1570                Z_STRVAL_PP(encoding),
1571                Z_LVAL_PP(slot),
1572                Z_STRVAL_PP(glyphname),
1573                Z_LVAL_PP(uv));
1574
1575        RETURN_TRUE;
1576}
1577/* }}} */
1578
1579
1580/* p_font.c */
1581
1582/* {{{ proto int pdf_findfont(int pdfdoc, string fontname, string encoding [, int embed])
1583 * Search a font, and prepare it for later use. PDF_load_font() is recommended. */
1584PHP_FUNCTION(pdf_findfont)
1585{
1586	zval **arg1, **arg2, **arg3, **arg4;
1587	int embed, font;
1588	const char *fontname, *encoding;
1589	PDF *pdf;
1590
1591	switch (ZEND_NUM_ARGS()) {
1592	case 3:
1593		if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
1594			WRONG_PARAM_COUNT;
1595		}
1596		embed = 0;
1597		break;
1598	case 4:
1599		if (zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
1600			WRONG_PARAM_COUNT;
1601		}
1602		convert_to_long_ex(arg4);
1603		embed = Z_LVAL_PP(arg4);
1604		break;
1605	default:
1606		WRONG_PARAM_COUNT;
1607	}
1608
1609	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1610
1611	convert_to_string_ex(arg2);
1612	fontname = Z_STRVAL_PP(arg2);
1613
1614	convert_to_string_ex(arg3);
1615	encoding = Z_STRVAL_PP(arg3);
1616
1617	font = PDF_findfont(pdf, fontname, encoding, embed);
1618
1619	RETURN_LONG(font); /* offset handled in PDFlib Kernel */
1620}
1621/* }}} */
1622
1623/* TODO [optlist] */
1624/* {{{ proto int pdf_load_font(int pdfdoc, string fontname, string encoding, string optlist);
1625 * Open and search a font, and prepare it for later use.*/
1626PHP_FUNCTION(pdf_load_font)
1627{
1628	zval **p, **fontname, **encoding, **optlist;
1629	PDF *pdf;
1630	int reserved = 0;
1631	int retval;
1632
1633	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &p, &fontname, &encoding, &optlist) == FAILURE) {
1634		WRONG_PARAM_COUNT;
1635	}
1636
1637	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
1638
1639	convert_to_string_ex(fontname);
1640	convert_to_string_ex(encoding);
1641	convert_to_string_ex(optlist);
1642
1643	retval = PDF_load_font(pdf,
1644		Z_STRVAL_PP(fontname),
1645		reserved,
1646		Z_STRVAL_PP(encoding),
1647		Z_STRVAL_PP(optlist));
1648
1649	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
1650}
1651/* }}} */
1652
1653/* {{{ proto void pdf_setfont(int pdfdoc, int font, float fontsize)
1654 * Set the current font in the given size, using a font handle returned by PDF_load_font(). */
1655PHP_FUNCTION(pdf_setfont)
1656{
1657	zval **arg1, **arg2, **arg3;
1658	int font;
1659	float fontsize;
1660	PDF *pdf;
1661
1662	if(ZEND_NUM_ARGS() != 3)
1663		WRONG_PARAM_COUNT;
1664	if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE)
1665		WRONG_PARAM_COUNT;
1666
1667	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1668
1669	convert_to_long_ex(arg2);
1670	font = Z_LVAL_PP(arg2);
1671
1672	convert_to_double_ex(arg3);
1673	fontsize = (float)Z_DVAL_PP(arg3);
1674
1675	PDF_setfont(pdf, font, fontsize);
1676
1677	RETURN_TRUE;
1678}
1679/* }}} */
1680
1681/* p_gstate.c */
1682
1683/* {{{ proto void pdf_concat(int pdfdoc, float a, float b, float c, float d, float e, float f)
1684 * Concatenate a matrix to the current transformation matrix. */
1685PHP_FUNCTION(pdf_concat)
1686{
1687	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7;
1688	PDF *pdf;
1689
1690	if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7) == FAILURE) {
1691		WRONG_PARAM_COUNT;
1692	}
1693
1694	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1695
1696	convert_to_double_ex(arg2);
1697	convert_to_double_ex(arg3);
1698	convert_to_double_ex(arg4);
1699	convert_to_double_ex(arg5);
1700	convert_to_double_ex(arg6);
1701	convert_to_double_ex(arg7);
1702
1703	PDF_concat(pdf,
1704	    (float) Z_DVAL_PP(arg2),
1705	    (float) Z_DVAL_PP(arg3),
1706	    (float) Z_DVAL_PP(arg4),
1707	    (float) Z_DVAL_PP(arg5),
1708	    (float) Z_DVAL_PP(arg6),
1709	    (float) Z_DVAL_PP(arg7));
1710
1711	RETURN_TRUE;
1712}
1713/* }}} */
1714
1715/* {{{ proto void pdf_initgraphics(int pdfdoc);
1716 * Reset all color and graphics state parameters to their defaults. */
1717PHP_FUNCTION(pdf_initgraphics)
1718{
1719	zval **arg1;
1720	PDF *pdf;
1721
1722	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1723		WRONG_PARAM_COUNT;
1724	}
1725
1726	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1727
1728	PDF_initgraphics(pdf);
1729
1730	RETURN_TRUE;
1731}
1732/* }}} */
1733
1734/* {{{ proto void pdf_restore(int pdfdoc)
1735 * Restore the most recently saved graphics state. */
1736PHP_FUNCTION(pdf_restore)
1737{
1738	zval **arg1;
1739	PDF *pdf;
1740
1741	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1742		WRONG_PARAM_COUNT;
1743	}
1744
1745	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1746
1747	PDF_restore(pdf);
1748	RETURN_TRUE;
1749}
1750/* }}} */
1751
1752/* {{{ proto void pdf_rotate(int pdfdoc, float angle)
1753 * Rotate the coordinate system by phi degrees. */
1754PHP_FUNCTION(pdf_rotate)
1755{
1756	zval **arg1, **arg2;
1757	PDF *pdf;
1758
1759	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1760		WRONG_PARAM_COUNT;
1761	}
1762
1763	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1764
1765	convert_to_double_ex(arg2);
1766	PDF_rotate(pdf, (float) Z_DVAL_PP(arg2));
1767	RETURN_TRUE;
1768}
1769/* }}} */
1770
1771/* {{{ proto void pdf_save(int pdfdoc)
1772 * Save the current graphics state. */
1773PHP_FUNCTION(pdf_save)
1774{
1775	zval **arg1;
1776	PDF *pdf;
1777
1778	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
1779		WRONG_PARAM_COUNT;
1780	}
1781
1782	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1783
1784	PDF_save(pdf);
1785	RETURN_TRUE;
1786}
1787/* }}} */
1788
1789/* {{{ proto void pdf_scale(int pdfdoc, float x_scale, float y_scale)
1790 * Scale the coordinate system. */
1791PHP_FUNCTION(pdf_scale)
1792{
1793	zval **arg1, **arg2, **arg3;
1794	PDF *pdf;
1795
1796	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
1797		WRONG_PARAM_COUNT;
1798	}
1799
1800	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1801
1802	convert_to_double_ex(arg2);
1803	convert_to_double_ex(arg3);
1804	PDF_scale(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
1805	RETURN_TRUE;
1806}
1807/* }}} */
1808
1809/* {{{ proto void pdf_setdash(int pdfdoc, float black, float white)
1810 * Set the current dash pattern to b black and w white units. */
1811PHP_FUNCTION(pdf_setdash)
1812{
1813	zval **arg1, **arg2, **arg3;
1814	PDF *pdf;
1815
1816	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
1817		WRONG_PARAM_COUNT;
1818	}
1819
1820	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1821
1822	convert_to_double_ex(arg2);
1823	convert_to_double_ex(arg3);
1824	PDF_setdash(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
1825	RETURN_TRUE;
1826}
1827/* }}} */
1828
1829/* {{{ proto void pdf_setdashpattern(int pdfdoc, string optlist)
1830 * Set a more complicated dash pattern defined by an optlist. */
1831PHP_FUNCTION(pdf_setdashpattern)
1832{
1833	zval **p, **optlist;
1834	PDF *pdf;
1835
1836	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &p, &optlist) == FAILURE) {
1837		WRONG_PARAM_COUNT;
1838	}
1839
1840	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
1841
1842	convert_to_string_ex(optlist);
1843
1844	PDF_setdashpattern(pdf, Z_STRVAL_PP(optlist));
1845
1846	RETURN_TRUE;
1847}
1848/* }}} */
1849
1850/* {{{ proto void pdf_setflat(int pdfdoc, float flatness)
1851 * Set the flatness to a value between 0 and 100 inclusive. */
1852PHP_FUNCTION(pdf_setflat)
1853{
1854	zval **arg1, **arg2;
1855	PDF *pdf;
1856
1857	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1858		WRONG_PARAM_COUNT;
1859	}
1860
1861	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1862
1863	convert_to_double_ex(arg2);
1864
1865	PDF_setflat(pdf, (float) Z_DVAL_PP(arg2));
1866	RETURN_TRUE;
1867}
1868/* }}} */
1869
1870/* {{{ proto void pdf_setlinecap(int pdfdoc, int linecap)
1871 * Set the linecap parameter to a value between 0 and 2 inclusive. */
1872PHP_FUNCTION(pdf_setlinecap)
1873{
1874	zval **arg1, **arg2;
1875	PDF *pdf;
1876
1877	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1878		WRONG_PARAM_COUNT;
1879	}
1880
1881	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1882
1883	convert_to_long_ex(arg2);
1884
1885	PDF_setlinecap(pdf, Z_LVAL_PP(arg2));
1886	RETURN_TRUE;
1887}
1888/* }}} */
1889
1890/* {{{ proto void pdf_setlinejoin(int pdfdoc, int linejoin)
1891 * Set the line join parameter to a value between 0 and 2 inclusive. */
1892PHP_FUNCTION(pdf_setlinejoin)
1893{
1894	zval **arg1, **arg2;
1895	PDF *pdf;
1896
1897	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1898		WRONG_PARAM_COUNT;
1899	}
1900
1901	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1902
1903	convert_to_long_ex(arg2);
1904
1905	PDF_setlinejoin(pdf, Z_LVAL_PP(arg2));
1906	RETURN_TRUE;
1907}
1908/* }}} */
1909
1910/* {{{ proto void pdf_setlinewidth(int pdfdoc, float width)
1911 * Set the current linewidth to width. */
1912PHP_FUNCTION(pdf_setlinewidth)
1913{
1914	zval **arg1, **arg2;
1915	PDF *pdf;
1916
1917	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1918		WRONG_PARAM_COUNT;
1919	}
1920
1921	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1922
1923	convert_to_double_ex(arg2);
1924	PDF_setlinewidth(pdf, (float) Z_DVAL_PP(arg2));
1925	RETURN_TRUE;
1926}
1927/* }}} */
1928
1929/* {{{ proto void pdf_setmatrix(int pdfdoc, float a, float b, float c, float d, float e, float f)
1930 * Explicitly set the current transformation matrix. */
1931PHP_FUNCTION(pdf_setmatrix)
1932{
1933	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7;
1934	PDF *pdf;
1935
1936	if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7) == FAILURE) {
1937		WRONG_PARAM_COUNT;
1938	}
1939
1940	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1941
1942	convert_to_double_ex(arg2);
1943	convert_to_double_ex(arg3);
1944	convert_to_double_ex(arg4);
1945	convert_to_double_ex(arg5);
1946	convert_to_double_ex(arg6);
1947	convert_to_double_ex(arg7);
1948
1949	PDF_setmatrix(pdf,
1950	    (float) Z_DVAL_PP(arg2),
1951	    (float) Z_DVAL_PP(arg3),
1952	    (float) Z_DVAL_PP(arg4),
1953	    (float) Z_DVAL_PP(arg5),
1954	    (float) Z_DVAL_PP(arg6),
1955	    (float) Z_DVAL_PP(arg7));
1956
1957	RETURN_TRUE;
1958}
1959/* }}} */
1960
1961/* {{{ proto void pdf_setmiterlimit(int pdfdoc, float value)
1962 * Set the miter limit to a value greater than or equal to 1. */
1963PHP_FUNCTION(pdf_setmiterlimit)
1964{
1965	zval **arg1, **arg2;
1966	PDF *pdf;
1967
1968	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1969		WRONG_PARAM_COUNT;
1970	}
1971
1972	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1973
1974	convert_to_double_ex(arg2);
1975
1976	PDF_setmiterlimit(pdf, (float) Z_DVAL_PP(arg2));
1977	RETURN_TRUE;
1978}
1979/* }}} */
1980
1981/* {{{ proto void pdf_setpolydash(int pdfdoc, float darray)
1982 * Deprecated, use PDF_setdashpattern() instead. */
1983PHP_FUNCTION(pdf_setpolydash)
1984{
1985	zval **arg1, **arg2;
1986	HashTable *array;
1987	int len, i;
1988	float *darray;
1989	PDF *pdf;
1990
1991	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
1992		WRONG_PARAM_COUNT;
1993	}
1994
1995	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
1996
1997	convert_to_array_ex(arg2);
1998	array = Z_ARRVAL_PP(arg2);
1999	len = zend_hash_num_elements(array);
2000
2001	/* TODO: ohne Malloc: maximum ist 8 ... */
2002	if (NULL == (darray = emalloc(len * sizeof(double)))) {
2003	    RETURN_FALSE;
2004	}
2005	zend_hash_internal_pointer_reset(array);
2006	for (i=0; i<len; i++) {
2007	    zval *keydata, **keydataptr;
2008
2009	    zend_hash_get_current_data(array, (void **) &keydataptr);
2010	    keydata = *keydataptr;
2011	    if (Z_TYPE_P(keydata) == IS_DOUBLE) {
2012		darray[i] = (float) Z_DVAL_P(keydata);
2013	    } else if (Z_TYPE_P(keydata) == IS_LONG) {
2014		darray[i] = (float) Z_LVAL_P(keydata);
2015	    } else {
2016		php_error(E_WARNING,"PDFlib set_polydash: illegal darray value");
2017	    }
2018	    zend_hash_move_forward(array);
2019	}
2020
2021	PDF_setpolydash(pdf, darray, len);
2022
2023	efree(darray);
2024	RETURN_TRUE;
2025}
2026/* }}} */
2027
2028/* {{{ proto void pdf_skew(int pdfdoc, float xangle, float yangle)
2029 * Skew the coordinate system in x and y direction by alpha and beta degrees. */
2030PHP_FUNCTION(pdf_skew)
2031{
2032	zval **arg1, **arg2, **arg3;
2033	PDF *pdf;
2034
2035	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
2036		WRONG_PARAM_COUNT;
2037	}
2038
2039	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2040
2041	convert_to_double_ex(arg2);
2042	convert_to_double_ex(arg3);
2043	PDF_skew(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
2044	RETURN_TRUE;
2045}
2046/* }}} */
2047
2048/* {{{ proto void pdf_translate(int pdfdoc, float x, float y)
2049 * Translate the origin of the coordinate system. */
2050PHP_FUNCTION(pdf_translate)
2051{
2052	zval **arg1, **arg2, **arg3;
2053	PDF *pdf;
2054
2055	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
2056		WRONG_PARAM_COUNT;
2057	}
2058
2059	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2060
2061	convert_to_double_ex(arg2);
2062	convert_to_double_ex(arg3);
2063	PDF_translate(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
2064	RETURN_TRUE;
2065}
2066/* }}} */
2067
2068/* p_hyper.c */
2069
2070/* {{{ proto int pdf_add_bookmark(int pdfdoc, string text [, int parent, int open])
2071 * Add a nested bookmark under parent, or a new top-level bookmark if parent = 0. Returns a bookmark descriptor which may be used as parent for subsequent nested bookmarks. If open = 1, child bookmarks will be folded out, and invisible if open = 0. */
2072PHP_FUNCTION(pdf_add_bookmark)
2073{
2074	zval **p, **text, **parent, **open;
2075	int parentid, p_open, id;
2076	PDF *pdf;
2077
2078	switch (ZEND_NUM_ARGS()) {
2079	case 2:
2080		if (zend_get_parameters_ex(2, &p, &text) == FAILURE) {
2081			WRONG_PARAM_COUNT;
2082		}
2083		break;
2084	case 3:
2085		if (zend_get_parameters_ex(3, &p, &text, &parent) == FAILURE) {
2086			WRONG_PARAM_COUNT;
2087		}
2088		break;
2089	case 4:
2090		if (zend_get_parameters_ex(4, &p, &text, &parent, &open) == FAILURE) {
2091			WRONG_PARAM_COUNT;
2092		}
2093	break;
2094	default:
2095		WRONG_PARAM_COUNT;
2096	}
2097
2098	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2099
2100	convert_to_string_ex(text);
2101
2102	if (ZEND_NUM_ARGS() > 2) {
2103		convert_to_long_ex(parent);
2104		parentid = Z_LVAL_PP(parent);
2105
2106		if (ZEND_NUM_ARGS() > 3) {
2107			convert_to_long_ex(open);
2108			p_open = Z_LVAL_PP(open);
2109		} else {
2110			p_open = 0;
2111		}
2112	} else {
2113		parentid = 0;
2114		p_open = 0;
2115	}
2116
2117	/* will never return 0 */
2118	id = PDF_add_bookmark2(pdf,
2119			Z_STRVAL_PP(text),
2120			Z_STRLEN_PP(text),
2121			parentid,
2122			p_open);
2123
2124	RETURN_LONG(id);
2125}
2126/* }}} */
2127
2128/* TODO [optlist] */
2129/* {{{ proto void pdf_add_nameddest(int pdfdoc, string name, string optlist)
2130 * Set a more complicated dash pattern defined by an optlist. */
2131PHP_FUNCTION(pdf_add_nameddest)
2132{
2133	zval **p, **name, **optlist;
2134	PDF *pdf;
2135	int reserved = 0;
2136
2137	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &p, &name, &optlist) == FAILURE) {
2138		WRONG_PARAM_COUNT;
2139	}
2140
2141	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2142
2143	convert_to_string_ex(name);
2144	convert_to_string_ex(optlist);
2145
2146	PDF_add_nameddest(pdf,
2147		Z_STRVAL_PP(name),
2148		reserved,
2149		Z_STRVAL_PP(optlist));
2150
2151	RETURN_TRUE;
2152}
2153/* }}} */
2154
2155/* {{{ proto bool pdf_set_info(int pdfdoc, string key, string value)
2156 * Fill document information field key with value. key is one of "Subject", "Title", "Creator", "Author", "Keywords", or a user-defined key. */
2157PHP_FUNCTION(pdf_set_info)
2158{
2159	zval **p, **key, **value;
2160	PDF *pdf;
2161
2162	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &p, &key, &value) == FAILURE) {
2163		WRONG_PARAM_COUNT;
2164	}
2165
2166	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2167
2168	convert_to_string_ex(key);
2169	convert_to_string_ex(value);
2170
2171	PDF_set_info2(pdf,
2172		Z_STRVAL_PP(key),
2173		Z_STRVAL_PP(value),
2174		Z_STRLEN_PP(value));
2175
2176	RETURN_TRUE;
2177}
2178/* }}} */
2179
2180/* p_icc.c */
2181
2182/* TODO [optlist] */
2183/* {{{ proto int pdf_load_iccprofile(int pdfdoc, string profilename, string optlist);
2184 * Search an ICC profile, and prepare it for later use. */
2185PHP_FUNCTION(pdf_load_iccprofile)
2186{
2187	zval **p, **profilename, **optlist;
2188	PDF *pdf;
2189	int reserved = 0;
2190	char * vprofilename;
2191	int retval;
2192
2193	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &p, &profilename, &optlist) == FAILURE) {
2194		WRONG_PARAM_COUNT;
2195	}
2196
2197	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2198
2199	convert_to_string_ex(profilename);
2200	convert_to_string_ex(optlist);
2201
2202#ifdef VIRTUAL_DIR
2203#    if ZEND_MODULE_API_NO >= 20010901
2204	virtual_filepath(Z_STRVAL_PP(profilename), &vprofilename TSRMLS_CC);
2205#    else
2206	virtual_filepath(Z_STRVAL_PP(profilename), &vprofilename);
2207#    endif
2208#else
2209	vprofilename = Z_STRVAL_PP(profilename);
2210#endif
2211
2212
2213	retval = PDF_load_iccprofile(pdf,
2214		vprofilename,
2215		reserved,
2216		Z_STRVAL_PP(optlist));
2217
2218	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
2219}
2220/* }}} */
2221
2222/* p_image.c */
2223
2224/* {{{ proto void pdf_add_thumbnail(int pdfdoc, int image);
2225 * Add an existing image as thumbnail for the current page. */
2226PHP_FUNCTION(pdf_add_thumbnail)
2227{
2228	zval **arg1, **arg2;
2229	PDF *pdf;
2230
2231	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
2232		WRONG_PARAM_COUNT;
2233	}
2234
2235	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2236
2237	convert_to_long_ex(arg2);
2238
2239	PDF_add_thumbnail(pdf,
2240		Z_LVAL_PP(arg2));
2241
2242	RETURN_TRUE;
2243}
2244/* }}} */
2245
2246/* {{{ proto void pdf_close_image(int pdfdoc, int image)
2247 * Close an image retrieved with PDF_load_image(). */
2248PHP_FUNCTION(pdf_close_image)
2249{
2250	zval **arg1, **arg2;
2251	PDF *pdf;
2252
2253	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
2254		WRONG_PARAM_COUNT;
2255	}
2256
2257	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2258	convert_to_long_ex(arg2);
2259
2260	PDF_close_image(pdf, Z_LVAL_PP(arg2));
2261}
2262/* }}} */
2263
2264/* TODO [optlist] */
2265/* {{{ proto void pdf_fit_image(int pdfdoc, int image, float x, float y, string optlist);
2266 * Place an image or template at (x, y) with various options. */
2267PHP_FUNCTION(pdf_fit_image)
2268{
2269	zval **p, **image, **x, **y, **optlist;
2270	PDF *pdf;
2271
2272	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &image, &x, &y, &optlist) == FAILURE) {
2273		WRONG_PARAM_COUNT;
2274	}
2275
2276	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2277
2278	convert_to_long_ex(image);
2279	convert_to_double_ex(x);
2280	convert_to_double_ex(y);
2281	convert_to_string_ex(optlist);
2282
2283	PDF_fit_image(pdf,
2284		Z_LVAL_PP(image),
2285		(float)Z_DVAL_PP(x),
2286		(float)Z_DVAL_PP(y),
2287		Z_STRVAL_PP(optlist));
2288
2289	RETURN_TRUE
2290}
2291/* }}} */
2292
2293/* TODO [optlist] */
2294/* {{{ proto int pdf_load_image(int pdfdoc, string imagetype, string filename, string optlist);
2295 * Open a (disk-based or virtual) image file with various options.*/
2296PHP_FUNCTION(pdf_load_image)
2297{
2298	zval **p, **imagetype, **filename, **optlist;
2299	PDF *pdf;
2300	const char *vfilename;
2301	int reserved = 0;
2302	int retval;
2303
2304	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &p, &imagetype, &filename, &optlist) == FAILURE) {
2305		WRONG_PARAM_COUNT;
2306	}
2307
2308	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2309
2310	convert_to_string_ex(imagetype);
2311	convert_to_string_ex(filename);
2312	convert_to_string_ex(optlist);
2313
2314#ifdef VIRTUAL_DIR
2315#    if ZEND_MODULE_API_NO >= 20010901
2316	virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
2317#    else
2318	virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
2319#    endif
2320#else
2321	vfilename = Z_STRVAL_PP(filename);
2322#endif
2323
2324	retval = PDF_load_image(pdf,
2325		Z_STRVAL_PP(imagetype),
2326		vfilename,
2327		reserved,
2328		Z_STRVAL_PP(optlist));
2329
2330	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
2331}
2332/* }}} */
2333
2334/* {{{ proto int pdf_open_ccitt(int pdfdoc, string filename, int width, int height, int bitreverse, int k, int blackls1)
2335 * Deprecated, use PDF_load_image() instead. */
2336PHP_FUNCTION(pdf_open_ccitt)
2337{
2338	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7;
2339	PDF *pdf;
2340	int pdf_image;
2341	char *image;
2342
2343	if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7) == FAILURE) {
2344		WRONG_PARAM_COUNT;
2345	}
2346
2347	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2348
2349	convert_to_string_ex(arg2);
2350#ifdef VIRTUAL_DIR
2351#    if ZEND_MODULE_API_NO >= 20010901
2352	virtual_filepath(Z_STRVAL_PP(arg2), &image TSRMLS_CC);
2353#    else
2354	virtual_filepath(Z_STRVAL_PP(arg2), &image);
2355#    endif
2356#else
2357	image = Z_STRVAL_PP(arg2);
2358#endif
2359
2360	convert_to_long_ex(arg3);
2361	convert_to_long_ex(arg4);
2362	convert_to_long_ex(arg5);
2363	convert_to_long_ex(arg6);
2364	convert_to_long_ex(arg7);
2365
2366	pdf_image = PDF_open_CCITT(pdf,
2367	    image,
2368	    Z_LVAL_PP(arg3),
2369	    Z_LVAL_PP(arg4),
2370	    Z_LVAL_PP(arg5),
2371	    Z_LVAL_PP(arg6),
2372	    Z_LVAL_PP(arg7));
2373
2374	RETURN_LONG(pdf_image); /* offset handled in PDFlib Kernel */
2375}
2376/* }}} */
2377
2378/* {{{ proto int pdf_open_image(int pdfdoc, string imagetype, string source, string data, long length, int width, int height, int components, int bpc, string params)
2379 * Deprecated, use PDF_load_image() with virtual files instead. */
2380PHP_FUNCTION(pdf_open_image)
2381{
2382	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7, **arg8, **arg9, **arg10;
2383	PDF *pdf;
2384	int pdf_image;
2385
2386	if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10) == FAILURE) {
2387		WRONG_PARAM_COUNT;
2388	}
2389
2390	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2391
2392	convert_to_string_ex(arg2);
2393	convert_to_string_ex(arg3);
2394	convert_to_string_ex(arg4);
2395	convert_to_long_ex(arg5);
2396	convert_to_long_ex(arg6);
2397	convert_to_long_ex(arg7);
2398	convert_to_long_ex(arg8);
2399	convert_to_long_ex(arg9);
2400	convert_to_string_ex(arg10);
2401
2402	pdf_image = PDF_open_image(pdf,
2403		Z_STRVAL_PP(arg2),
2404		Z_STRVAL_PP(arg3),
2405		Z_STRVAL_PP(arg4),
2406		Z_LVAL_PP(arg5),
2407		Z_LVAL_PP(arg6),
2408		Z_LVAL_PP(arg7),
2409		Z_LVAL_PP(arg8),
2410		Z_LVAL_PP(arg9),
2411		Z_STRVAL_PP(arg10));
2412
2413	RETURN_LONG(pdf_image); /* offset handled in PDFlib Kernel */
2414}
2415/* }}} */
2416
2417/* {{{ proto int pdf_open_image_file(int pdfdoc, string imagetype, string filename, string stringparam, int intparam)
2418 * Deprecated, use PDF_load_image() instead. */
2419PHP_FUNCTION(pdf_open_image_file)
2420{
2421	zval **p, **imagetype, **filename, **stringparam, **intparam;
2422	PDF *pdf;
2423	int pdf_image, argc;
2424	const char *vfilename;
2425
2426	switch ((argc = ZEND_NUM_ARGS())) {
2427	case 3:
2428		if (zend_get_parameters_ex(3, &p, &imagetype, &filename) == FAILURE)
2429			WRONG_PARAM_COUNT;
2430		break;
2431	case 5:
2432		if (zend_get_parameters_ex(5, &p, &imagetype, &filename, &stringparam, &intparam) == FAILURE)
2433			WRONG_PARAM_COUNT;
2434		break;
2435	default:
2436		WRONG_PARAM_COUNT;
2437	}
2438
2439	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2440
2441	convert_to_string_ex(imagetype);
2442	convert_to_string_ex(filename);
2443
2444#ifdef VIRTUAL_DIR
2445#    if ZEND_MODULE_API_NO >= 20010901
2446	virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
2447#    else
2448	virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
2449#    endif
2450#else
2451	vfilename = Z_STRVAL_PP(filename);
2452#endif
2453
2454	if (argc == 3) {
2455		pdf_image = PDF_open_image_file(pdf, Z_STRVAL_PP(imagetype), vfilename, "", 0);
2456	} else {
2457	    convert_to_string_ex(stringparam);
2458	    convert_to_long_ex(intparam);
2459
2460	    pdf_image = PDF_open_image_file(pdf,
2461				Z_STRVAL_PP(imagetype),
2462				vfilename,
2463				Z_STRVAL_PP(stringparam),
2464				Z_LVAL_PP(intparam));
2465	}
2466
2467	RETURN_LONG(pdf_image); /* offset handled in PDFlib Kernel */
2468
2469}
2470/* }}} */
2471
2472/* {{{ proto void pdf_place_image(int pdfdoc, int image, float x, float y, float scale)
2473 * Deprecated, use PDF_fit_image() instead. */
2474PHP_FUNCTION(pdf_place_image)
2475{
2476	zval **arg1, **arg2, **arg3, **arg4, **arg5;
2477	PDF *pdf;
2478
2479	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &arg1, &arg2, &arg3, &arg4, &arg5) == FAILURE) {
2480		WRONG_PARAM_COUNT;
2481	}
2482
2483	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2484
2485	convert_to_long_ex(arg2);
2486	convert_to_double_ex(arg3);
2487	convert_to_double_ex(arg4);
2488	convert_to_double_ex(arg5);
2489
2490	PDF_place_image(pdf, Z_LVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4), (float) Z_DVAL_PP(arg5));
2491	RETURN_TRUE;
2492}
2493/* }}} */
2494
2495/* p_params.c */
2496
2497/* {{{ proto string pdf_get_parameter(int pdfdoc, string key, float modifier)
2498 * Get the contents of some PDFlib parameter with string type. */
2499PHP_FUNCTION(pdf_get_parameter)
2500{
2501	zval **argv[3];
2502	int argc = ZEND_NUM_ARGS();
2503	PDF *pdf;
2504	char *value;
2505
2506	if(((argc < 2) || (argc > 3)) || zend_get_parameters_array_ex(argc, argv) == FAILURE) {
2507		WRONG_PARAM_COUNT;
2508	}
2509
2510	convert_to_string_ex(argv[1]);
2511
2512	if(0 == (strcmp(Z_STRVAL_PP(argv[1]), "version"))) {
2513	    value = (char *) PDF_get_parameter(0, Z_STRVAL_PP(argv[1]), 0.0);
2514	    RETURN_STRING(value, 1);
2515	} else if(0 == (strcmp(Z_STRVAL_PP(argv[1]), "pdi"))) {
2516	    value = (char *) PDF_get_parameter(0, Z_STRVAL_PP(argv[1]), 0.0);
2517	    RETURN_STRING(value, 1);
2518	} else {
2519	    ZEND_FETCH_RESOURCE(pdf, PDF *, argv[0], -1, "pdf object", le_pdf);
2520	}
2521
2522	if(argc == 3) {
2523		convert_to_double_ex(argv[2]);
2524		value = (char *) PDF_get_parameter(pdf, Z_STRVAL_PP(argv[1]), (float) Z_DVAL_PP(argv[2]));
2525	} else {
2526		value = (char *) PDF_get_parameter(pdf, Z_STRVAL_PP(argv[1]), 0.0);
2527	}
2528
2529	RETURN_STRING(value, 1);
2530}
2531/* }}} */
2532
2533/* {{{ proto float pdf_get_value(int pdfdoc, string key, float modifier)
2534 * Get the value of some PDFlib parameter with float type. */
2535PHP_FUNCTION(pdf_get_value)
2536{
2537	zval **argv[3];
2538	int argc = ZEND_NUM_ARGS();
2539	PDF *pdf;
2540	double value;
2541
2542	if(((argc < 2) || (argc > 3)) || zend_get_parameters_array_ex(argc, argv) == FAILURE) {
2543		WRONG_PARAM_COUNT;
2544	}
2545
2546	convert_to_string_ex(argv[1]);
2547	if(argc == 3)
2548	    convert_to_double_ex(argv[2]);
2549
2550	if(0 == (strcmp(Z_STRVAL_PP(argv[1]), "major"))) {
2551		value = PDF_get_value(0, Z_STRVAL_PP(argv[1]), 0);
2552		RETURN_DOUBLE(value);
2553	} else if(0 == (strcmp(Z_STRVAL_PP(argv[1]), "minor"))) {
2554		value = PDF_get_value(0, Z_STRVAL_PP(argv[1]), 0);
2555		RETURN_DOUBLE(value);
2556	} else if(0 == (strcmp(Z_STRVAL_PP(argv[1]), "revision"))) {
2557		value = PDF_get_value(0, Z_STRVAL_PP(argv[1]), 0);
2558		RETURN_DOUBLE(value);
2559	} else {
2560	    ZEND_FETCH_RESOURCE(pdf, PDF *, argv[0], -1, "pdf object", le_pdf);
2561	}
2562
2563	if(argc < 3) {
2564		value = PDF_get_value(pdf,
2565					Z_STRVAL_PP(argv[1]),
2566					0.0);
2567	} else {
2568		value = PDF_get_value(pdf,
2569					Z_STRVAL_PP(argv[1]),
2570					(float)Z_DVAL_PP(argv[2]));
2571	}
2572
2573	RETURN_DOUBLE(value);
2574}
2575/* }}} */
2576
2577/* {{{ proto void pdf_set_parameter(int pdfdoc, string key, string value)
2578 *  Set some PDFlib parameter with string type. */
2579PHP_FUNCTION(pdf_set_parameter)
2580{
2581	zval **arg1, **arg2, **arg3;
2582	PDF *pdf;
2583
2584	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
2585		WRONG_PARAM_COUNT;
2586	}
2587
2588	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2589
2590	convert_to_string_ex(arg2);
2591	convert_to_string_ex(arg3);
2592
2593	PDF_set_parameter(pdf, Z_STRVAL_PP(arg2), Z_STRVAL_PP(arg3));
2594	RETURN_TRUE;
2595}
2596/* }}} */
2597
2598/* {{{ proto void pdf_set_value(int pdfdoc, string key, float value)
2599 * Set the value of some PDFlib parameter with float type. */
2600PHP_FUNCTION(pdf_set_value)
2601{
2602	zval **arg1, **arg2, **arg3;
2603	PDF *pdf;
2604
2605	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
2606		WRONG_PARAM_COUNT;
2607	}
2608
2609	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2610
2611	convert_to_string_ex(arg2);
2612	convert_to_double_ex(arg3);
2613	PDF_set_value(pdf, Z_STRVAL_PP(arg2), (float)Z_DVAL_PP(arg3));
2614
2615	RETURN_TRUE;
2616}
2617/* }}} */
2618
2619/* p_pattern.c */
2620
2621/* {{{ proto int pdf_begin_pattern(int pdfdoc, float width, float height, float xstep, float ystep, int painttype);
2622 * Start a new pattern definition. */
2623PHP_FUNCTION(pdf_begin_pattern)
2624{
2625	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6;
2626	PDF *pdf;
2627	int pattern_image;
2628
2629	if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) {
2630		WRONG_PARAM_COUNT;
2631	}
2632
2633	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2634
2635	convert_to_double_ex(arg2);
2636	convert_to_double_ex(arg3);
2637	convert_to_double_ex(arg4);
2638	convert_to_double_ex(arg5);
2639	convert_to_long_ex(arg6);
2640
2641	pattern_image = PDF_begin_pattern(pdf,
2642		(float) Z_DVAL_PP(arg2),
2643		(float) Z_DVAL_PP(arg3),
2644		(float) Z_DVAL_PP(arg4),
2645		(float) Z_DVAL_PP(arg5),
2646		Z_LVAL_PP(arg6));
2647
2648	RETURN_LONG(pattern_image); /* offset handled in PDFlib Kernel */
2649}
2650/* }}} */
2651
2652/* {{{ proto void pdf_end_pattern(int pdfdoc);
2653 * Finish the pattern definition. */
2654PHP_FUNCTION(pdf_end_pattern)
2655{
2656	zval **arg1;
2657	PDF *pdf;
2658
2659	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
2660		WRONG_PARAM_COUNT;
2661	}
2662
2663	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2664
2665	PDF_end_pattern(pdf);
2666
2667	RETURN_TRUE;
2668}
2669/* }}} */
2670
2671/* p_pdi.c */
2672
2673/* {{{ proto void pdf_close_pdi(int pdfdoc, int doc);
2674 * Close all open page handles, and close the input PDF document. */
2675PHP_FUNCTION(pdf_close_pdi)
2676{
2677	zval **arg1, **arg2;
2678	PDF *pdf;
2679
2680	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
2681		WRONG_PARAM_COUNT;
2682	}
2683
2684	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2685
2686	convert_to_long_ex(arg2);
2687
2688	PDF_close_pdi(pdf,
2689		Z_LVAL_PP(arg2));
2690
2691	RETURN_TRUE;
2692}
2693/* }}} */
2694
2695/* {{{ proto void pdf_close_pdi_page(int pdfdoc, int page);
2696 * Close the page handle, and free all page-related resources. */
2697PHP_FUNCTION(pdf_close_pdi_page)
2698{
2699	zval **arg1, **arg2;
2700	PDF *pdf;
2701
2702	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
2703		WRONG_PARAM_COUNT;
2704	}
2705
2706	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2707
2708	convert_to_long_ex(arg2);
2709
2710	PDF_close_pdi_page(pdf,
2711		Z_LVAL_PP(arg2));
2712
2713	RETURN_TRUE;
2714}
2715/* }}} */
2716
2717/* TODO [optlist] */
2718/* {{{ proto void pdf_fit_pdi_page(int pdfdoc, int page, float x, float y, string optlist);
2719 * Place an imported PDF page with the lower left corner at (x, y) with
2720 * various options.*/
2721PHP_FUNCTION(pdf_fit_pdi_page)
2722{
2723	zval **p, **page, **x, **y, **optlist;
2724	PDF *pdf;
2725
2726	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &page, &x, &y, &optlist) == FAILURE) {
2727		WRONG_PARAM_COUNT;
2728	}
2729
2730	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2731
2732	convert_to_long_ex(page);
2733	convert_to_double_ex(x);
2734	convert_to_double_ex(y);
2735	convert_to_string_ex(optlist);
2736
2737	PDF_fit_pdi_page(pdf,
2738		Z_LVAL_PP(page),
2739		(float)Z_DVAL_PP(x),
2740		(float)Z_DVAL_PP(y),
2741		Z_STRVAL_PP(optlist));
2742
2743	RETURN_TRUE
2744}
2745/* }}} */
2746
2747/* TODO [reserved] */
2748/* {{{ proto string pdf_get_pdi_parameter(int pdfdoc, string key, int doc, int page, int reserved);
2749 * Get the contents of some PDI document parameter with string type. */
2750PHP_FUNCTION(pdf_get_pdi_parameter)
2751{
2752	zval **arg1, **arg2, **arg3, **arg4, **arg5;
2753	PDF *pdf;
2754	const char *buffer;
2755	int size;
2756
2757	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &arg1, &arg2, &arg3, &arg4, &arg5) == FAILURE) {
2758		WRONG_PARAM_COUNT;
2759	}
2760
2761	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2762
2763	convert_to_string_ex(arg2);
2764	convert_to_long_ex(arg3);
2765	convert_to_long_ex(arg4);
2766	convert_to_long_ex(arg5);
2767
2768	buffer = PDF_get_pdi_parameter(pdf,
2769		Z_STRVAL_PP(arg2),
2770		Z_LVAL_PP(arg3),
2771		Z_LVAL_PP(arg4),
2772		Z_LVAL_PP(arg5),
2773		&size);
2774
2775	RETURN_STRINGL((char *)buffer, size, 1);
2776}
2777/* }}} */
2778
2779/* TODO [reserved] */
2780/* {{{ proto float pdf_get_pdi_value(int pdfdoc, string key, int doc, int page, int reserved);
2781 * Get the contents of some PDI document parameter with numerical type. */
2782PHP_FUNCTION(pdf_get_pdi_value)
2783{
2784	zval **arg1, **arg2, **arg3, **arg4, **arg5;
2785	PDF *pdf;
2786	double value;
2787
2788	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &arg1, &arg2, &arg3, &arg4, &arg5) == FAILURE) {
2789		WRONG_PARAM_COUNT;
2790	}
2791
2792	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2793
2794	convert_to_string_ex(arg2);
2795	convert_to_long_ex(arg3);
2796	convert_to_long_ex(arg4);
2797	convert_to_long_ex(arg5);
2798
2799	value = (double)PDF_get_pdi_value(pdf,
2800		Z_STRVAL_PP(arg2),
2801		Z_LVAL_PP(arg3),
2802		Z_LVAL_PP(arg4),
2803		Z_LVAL_PP(arg5));
2804
2805	RETURN_DOUBLE(value);
2806}
2807/* }}} */
2808
2809/* TODO [optlist, reserved] */
2810/* {{{ proto int pdf_open_pdi(int pdfdoc, string filename, string optlist, int reserved);
2811 * Open a (disk-based or virtual) PDF document and prepare it for later use. */
2812PHP_FUNCTION(pdf_open_pdi)
2813{
2814	zval **arg1, **arg2, **arg3, **arg4;
2815	PDF *pdf;
2816	int pdi_handle;
2817	char *file;
2818
2819	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
2820		WRONG_PARAM_COUNT;
2821	}
2822
2823	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
2824
2825	convert_to_string_ex(arg2);
2826	convert_to_string_ex(arg3);
2827	convert_to_long_ex(arg4);
2828
2829#ifdef VIRTUAL_DIR
2830#    if ZEND_MODULE_API_NO >= 20010901
2831	virtual_filepath(Z_STRVAL_PP(arg2), &file TSRMLS_CC);
2832#    else
2833	virtual_filepath(Z_STRVAL_PP(arg2), &file);
2834#    endif
2835#else
2836	file = Z_STRVAL_PP(arg2);
2837#endif
2838
2839	pdi_handle = PDF_open_pdi(pdf,
2840		file,
2841		Z_STRVAL_PP(arg3),
2842		Z_LVAL_PP(arg4));
2843
2844	RETURN_LONG(pdi_handle); /* offset handled in PDFlib Kernel */
2845}
2846/* }}} */
2847
2848/* TODO [optlist] */
2849/* {{{ proto int pdf_open_pdi_page(int pdfdoc, int doc, int pagenumber, string optlist);
2850 * Prepare a page for later use with PDF_place_pdi_page(). */
2851PHP_FUNCTION(pdf_open_pdi_page)
2852{
2853	zval **p, **doc, **pagenumber, **optlist;
2854	PDF *pdf;
2855	int pdi_image;
2856
2857	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &p, &doc, &pagenumber, &optlist) == FAILURE) {
2858		WRONG_PARAM_COUNT;
2859	}
2860
2861	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2862
2863	convert_to_long_ex(doc);
2864	convert_to_long_ex(pagenumber);
2865	convert_to_string_ex(optlist);
2866
2867	pdi_image = PDF_open_pdi_page(pdf,
2868		Z_LVAL_PP(doc),
2869		Z_LVAL_PP(pagenumber),
2870		Z_STRVAL_PP(optlist));
2871
2872	RETURN_LONG(pdi_image); /* offset handled in PDFlib Kernel */
2873}
2874/* }}} */
2875
2876/* {{{ proto void pdf_place_pdi_page(int pdfdoc, int page, float x, float y, float sx, float sy)
2877 * Deprecated, use PDF_fit_pdi_page( ) instead. */
2878PHP_FUNCTION(pdf_place_pdi_page)
2879{
2880	zval **p, **page, **x, **y, **sx, **sy;
2881	PDF *pdf;
2882
2883	if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &p, &page, &x, &y, &sx, &sy) == FAILURE) {
2884		WRONG_PARAM_COUNT;
2885	}
2886
2887	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2888
2889	convert_to_long_ex(page);
2890	convert_to_double_ex(x);
2891	convert_to_double_ex(y);
2892	convert_to_double_ex(sx);
2893	convert_to_double_ex(sy);
2894
2895	PDF_place_pdi_page(pdf,
2896		Z_LVAL_PP(page),
2897		(float) Z_DVAL_PP(x),
2898		(float) Z_DVAL_PP(y),
2899		(float) Z_DVAL_PP(sx),
2900		(float) Z_DVAL_PP(sy));
2901
2902	RETURN_TRUE;
2903}
2904/* }}} */
2905
2906/* {{{ proto int pdf_process_pdi(int pdfdoc, int doc, int page, string optlist);
2907 * Perform various actions on a PDI document. */
2908PHP_FUNCTION(pdf_process_pdi)
2909{
2910	zval **p, **doc, **page, **optlist;
2911	PDF *pdf;
2912	int retval;
2913
2914	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &p, &doc, &page, &optlist) == FAILURE) {
2915		WRONG_PARAM_COUNT;
2916	}
2917
2918	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2919
2920	convert_to_long_ex(doc);
2921	convert_to_long_ex(page);
2922	convert_to_string_ex(optlist);
2923
2924	retval = PDF_process_pdi(pdf,
2925		Z_LVAL_PP(doc),
2926		Z_LVAL_PP(page),
2927		Z_STRVAL_PP(optlist));
2928
2929	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
2930}
2931/* }}} */
2932
2933/* p_resource.c */
2934
2935/* TODO [optlist] */
2936/* {{{ proto void pdf_create_pvf(int pdfdoc, string filename, string data, string optlist);
2937 * Create a new virtual file. */
2938PHP_FUNCTION(pdf_create_pvf)
2939{
2940	zval **p, **filename, **data, **optlist;
2941	PDF *pdf;
2942	int reserved = 0;
2943
2944	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &p, &filename, &data, &optlist) == FAILURE) {
2945		WRONG_PARAM_COUNT;
2946	}
2947
2948	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2949
2950	convert_to_string_ex(filename);
2951	convert_to_string_ex(data);
2952	convert_to_string_ex(optlist);
2953
2954	PDF_create_pvf(pdf,
2955		Z_STRVAL_PP(filename),
2956		reserved,
2957		Z_STRVAL_PP(data),
2958		Z_STRLEN_PP(data),
2959		Z_STRVAL_PP(optlist));
2960
2961	RETURN_TRUE
2962}
2963/* }}} */
2964
2965/* {{{ proto int pdf_delete_pvf(int pdfdoc, string filname);
2966 * Delete a virtual file. */
2967PHP_FUNCTION(pdf_delete_pvf)
2968{
2969	zval **p, **filename;
2970	PDF *pdf;
2971	int retval;
2972	int reserved = 0;
2973
2974	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &p, &filename) == FAILURE) {
2975		WRONG_PARAM_COUNT;
2976	}
2977
2978	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
2979
2980	convert_to_string_ex(filename);
2981
2982	retval = PDF_delete_pvf(pdf,
2983		Z_STRVAL_PP(filename),
2984		reserved);
2985
2986	RETURN_LONG(retval); /* change return from -1 to 0 handled by PDFlib */
2987}
2988/* }}} */
2989
2990/* p_shading.c */
2991
2992/* TODO [optlist] */
2993/* {{{ proto int pdf_shading(int pdfdoc, string type, float x0, float y0, float x1, float y1, float c1, float c2, float c3, float c4, string optlist);
2994 * Define a color blend (smooth shading) from the current fill color to the supplied color. */
2995PHP_FUNCTION(pdf_shading)
2996{
2997	zval **p, **type, **x0, **y0, **x1, **y1, **c1, **c2, **c3, **c4, **optlist;
2998	PDF *pdf;
2999	int retval;
3000
3001	if (ZEND_NUM_ARGS() != 11 || zend_get_parameters_ex(11, &p, &type, &x0, &y0, &x1, &y1, &c1, &c2, &c3, &c4, &optlist) == FAILURE) {
3002		WRONG_PARAM_COUNT;
3003	}
3004
3005	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3006
3007	convert_to_string_ex(type);
3008	convert_to_double_ex(x0);
3009	convert_to_double_ex(y0);
3010	convert_to_double_ex(x1);
3011	convert_to_double_ex(y1);
3012	convert_to_double_ex(c1);
3013	convert_to_double_ex(c2);
3014	convert_to_double_ex(c3);
3015	convert_to_double_ex(c4);
3016	convert_to_string_ex(optlist);
3017
3018	retval = PDF_shading(pdf,
3019		Z_STRVAL_PP(type),
3020		(float) Z_DVAL_PP(x0),
3021		(float) Z_DVAL_PP(y0),
3022		(float) Z_DVAL_PP(x1),
3023		(float) Z_DVAL_PP(y1),
3024		(float) Z_DVAL_PP(c1),
3025		(float) Z_DVAL_PP(c2),
3026		(float) Z_DVAL_PP(c3),
3027		(float) Z_DVAL_PP(c4),
3028		Z_STRVAL_PP(optlist));
3029
3030	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
3031}
3032/* }}} */
3033
3034/* TODO [optlist] */
3035/* {{{ proto int pdf_shading_pattern(int pdfdoc, int shading, string optlist);
3036 * Define a shading pattern using a shading object. */
3037PHP_FUNCTION(pdf_shading_pattern)
3038{
3039	zval **p, **shading, **optlist;
3040	PDF *pdf;
3041	int retval;
3042
3043	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &p, &shading, &optlist) == FAILURE) {
3044		WRONG_PARAM_COUNT;
3045	}
3046
3047	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3048
3049	convert_to_long_ex(shading);
3050	convert_to_string_ex(optlist);
3051
3052	retval = PDF_shading_pattern(pdf,
3053		Z_LVAL_PP(shading),
3054		Z_STRVAL_PP(optlist));
3055
3056	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
3057}
3058/* }}} */
3059
3060/* {{{ proto void pdf_shfill(int pdfdoc, int shading);
3061 * Fill an area with a shading, based on a shading object. */
3062PHP_FUNCTION(pdf_shfill)
3063{
3064	zval **p, **shading;
3065	PDF *pdf;
3066
3067	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &p, &shading) == FAILURE) {
3068		WRONG_PARAM_COUNT;
3069	}
3070
3071	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3072
3073	convert_to_long_ex(shading);
3074
3075	PDF_shfill(pdf,
3076		Z_LVAL_PP(shading));
3077
3078	RETURN_TRUE;
3079}
3080/* }}} */
3081
3082/* p_template.c */
3083
3084/* {{{ proto int pdf_begin_template(int pdfdoc, float width, float height);
3085 * Start a new template definition. */
3086PHP_FUNCTION(pdf_begin_template)
3087{
3088	zval **arg1, **arg2, **arg3;
3089	PDF *pdf;
3090	int tmpl_image;
3091
3092	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
3093		WRONG_PARAM_COUNT;
3094	}
3095
3096	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
3097
3098	convert_to_double_ex(arg2);
3099	convert_to_double_ex(arg3);
3100
3101	tmpl_image = PDF_begin_template(pdf,
3102		(float) Z_DVAL_PP(arg2),
3103		(float) Z_DVAL_PP(arg3));
3104
3105	RETURN_LONG(tmpl_image); /* offset handled in PDFlib Kernel */
3106}
3107/* }}} */
3108
3109/* {{{ proto void pdf_end_template(int pdfdoc);
3110 * Finish a template definition. */
3111PHP_FUNCTION(pdf_end_template)
3112{
3113	zval **arg1;
3114	PDF *pdf;
3115
3116	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
3117		WRONG_PARAM_COUNT;
3118	}
3119
3120	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
3121
3122
3123	PDF_end_template(pdf);
3124
3125	RETURN_TRUE;
3126}
3127/* }}} */
3128
3129/* p_text.c */
3130
3131/* {{{ proto void pdf_continue_text(int pdfdoc, string text)
3132 * Print text at the next line. The spacing between lines is determined by the "leading" parameter. */
3133PHP_FUNCTION(pdf_continue_text)
3134{
3135	zval **p, **text;
3136	PDF *pdf;
3137
3138	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &p, &text) == FAILURE) {
3139		WRONG_PARAM_COUNT;
3140	}
3141
3142	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3143
3144	convert_to_string_ex(text);
3145
3146	PDF_continue_text2(pdf,
3147		Z_STRVAL_PP(text),
3148		Z_STRLEN_PP(text));
3149	RETURN_TRUE;
3150}
3151/* }}} */
3152
3153/* TODO [optlist] */
3154/* {{{ proto void pdf_fit_textline(int pdfdoc, int text, float x, float y, string optlist);
3155 * Place an imported PDF page with the lower left corner at (x, y) with
3156 * various options.*/
3157PHP_FUNCTION(pdf_fit_textline)
3158{
3159	zval **p, **text, **x, **y, **optlist;
3160	PDF *pdf;
3161
3162	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &text, &x, &y, &optlist) == FAILURE) {
3163		WRONG_PARAM_COUNT;
3164	}
3165
3166	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3167
3168	convert_to_string_ex(text);
3169	convert_to_double_ex(x);
3170	convert_to_double_ex(y);
3171	convert_to_string_ex(optlist);
3172
3173	PDF_fit_textline(pdf,
3174		Z_STRVAL_PP(text),
3175		Z_STRLEN_PP(text),
3176		(float)Z_DVAL_PP(x),
3177		(float)Z_DVAL_PP(y),
3178		Z_STRVAL_PP(optlist));
3179
3180	RETURN_TRUE
3181}
3182/* }}} */
3183
3184/* {{{ proto void pdf_set_text_pos(int pdfdoc, float x, float y)
3185 * Set the text output position. */
3186PHP_FUNCTION(pdf_set_text_pos)
3187{
3188	zval **arg1, **arg2, **arg3;
3189	PDF *pdf;
3190
3191	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
3192		WRONG_PARAM_COUNT;
3193	}
3194
3195	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
3196
3197	convert_to_double_ex(arg2);
3198	convert_to_double_ex(arg3);
3199	PDF_set_text_pos(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
3200	RETURN_TRUE;
3201}
3202/* }}} */
3203
3204/* {{{ proto void pdf_show(int pdfdoc, string text)
3205 * Print text in the current font and size at the current position. */
3206PHP_FUNCTION(pdf_show)
3207{
3208	zval **arg1, **arg2;
3209	PDF *pdf;
3210
3211	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
3212		WRONG_PARAM_COUNT;
3213	}
3214
3215	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
3216
3217	convert_to_string_ex(arg2);
3218	PDF_show2(pdf, Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2));
3219	RETURN_TRUE;
3220}
3221/* }}} */
3222
3223/* {{{ proto int pdf_show_boxed(int pdfdoc, string text, float x, float y, float width, float height, string hmode [, string feature])
3224 * Format text in the current font and size into the supplied text box according to the requested formatting mode, which must be one of "left", "right", "center", "justify", or "fulljustify". If width and height are 0, only a single line is placed at the point (left, top) in the requested mode. */
3225PHP_FUNCTION(pdf_show_boxed)
3226{
3227	zval **argv[8];
3228	int argc = ZEND_NUM_ARGS();
3229	int nr;
3230	char *feature;
3231	PDF *pdf;
3232
3233	if (((argc < 7) || (argc > 8)) || zend_get_parameters_array_ex(argc, argv) == FAILURE) {
3234		WRONG_PARAM_COUNT;
3235	}
3236
3237	ZEND_FETCH_RESOURCE(pdf, PDF *, argv[0], -1, "pdf object", le_pdf);
3238
3239	convert_to_string_ex(argv[1]);
3240	convert_to_double_ex(argv[2]);
3241	convert_to_double_ex(argv[3]);
3242	convert_to_double_ex(argv[4]);
3243	convert_to_double_ex(argv[5]);
3244	convert_to_string_ex(argv[6]);
3245
3246	if(argc == 8) {
3247		convert_to_string_ex(argv[7]);
3248		feature = Z_STRVAL_PP(argv[7]);
3249	} else {
3250		feature = NULL;
3251	}
3252
3253	nr = PDF_show_boxed(pdf, Z_STRVAL_PP(argv[1]),
3254							(float) Z_DVAL_PP(argv[2]),
3255							(float) Z_DVAL_PP(argv[3]),
3256							(float) Z_DVAL_PP(argv[4]),
3257							(float) Z_DVAL_PP(argv[5]),
3258							Z_STRVAL_PP(argv[6]),
3259							feature);
3260
3261	RETURN_LONG(nr);
3262}
3263/* }}} */
3264
3265/* {{{ proto void pdf_show_xy(int pdfdoc, string text, float x, float y)
3266 * Print text in the current font at (x, y). */
3267PHP_FUNCTION(pdf_show_xy)
3268{
3269	zval **p, **text, **x, **y;
3270	PDF *pdf;
3271
3272	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &p, &text, &x, &y) == FAILURE) {
3273		WRONG_PARAM_COUNT;
3274	}
3275
3276	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3277
3278	convert_to_string_ex(text);
3279	convert_to_double_ex(x);
3280	convert_to_double_ex(y);
3281
3282	PDF_show_xy2(pdf,
3283		Z_STRVAL_PP(text),
3284		Z_STRLEN_PP(text),
3285		(float) Z_DVAL_PP(x),
3286		(float) Z_DVAL_PP(y));
3287
3288	RETURN_TRUE;
3289}
3290/* }}} */
3291
3292/* {{{ proto float pdf_stringwidth(int pdfdoc, string text [, int font, float fontsize])
3293 * Return the width of text in an arbitrary font. */
3294PHP_FUNCTION(pdf_stringwidth)
3295{
3296	zval **p, **text, **font, **fontsize;
3297	int p_font;
3298	double width, p_fontsize;
3299	PDF *pdf;
3300
3301	switch (ZEND_NUM_ARGS()) {
3302	case 2:
3303		if (zend_get_parameters_ex(2, &p, &text) == FAILURE)
3304			WRONG_PARAM_COUNT;
3305		break;
3306	case 4:
3307		if (zend_get_parameters_ex(4, &p, &text, &font, &fontsize) == FAILURE)
3308			WRONG_PARAM_COUNT;
3309		convert_to_long_ex(font);
3310		break;
3311	default:
3312		WRONG_PARAM_COUNT;
3313	}
3314
3315	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3316
3317	convert_to_string_ex(text);
3318	if (ZEND_NUM_ARGS() == 2) {
3319	    p_font = (int)PDF_get_value(pdf, "font", 0);
3320	    p_fontsize = PDF_get_value(pdf, "fontsize", 0);
3321	} else {
3322	    convert_to_long_ex(font);
3323	    p_font = Z_LVAL_PP(font);
3324	    convert_to_double_ex(fontsize);
3325	    p_fontsize = Z_DVAL_PP(fontsize);
3326	}
3327	width = (double) PDF_stringwidth2(pdf,
3328				Z_STRVAL_PP(text),
3329				Z_STRLEN_PP(text),
3330				p_font,
3331				(float)p_fontsize);
3332
3333	RETURN_DOUBLE(width);
3334}
3335/* }}} */
3336
3337/* p_type3.c */
3338
3339/* TODO [optlist] */
3340/* {{{ proto void pdf_begin_font(string fontname, int subtype, float a, float b,
3341    float c, float d, float e, float f, string optlist);
3342 * Start a type 3 font definition. */
3343PHP_FUNCTION(pdf_begin_font)
3344{
3345	zval **p, **fontname, **a, **b, **c, **d, **e, **f, **optlist;
3346	PDF *pdf;
3347
3348	if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &p, &fontname, &a, &b, &c, &d, &e, &f, &optlist) == FAILURE) {
3349		WRONG_PARAM_COUNT;
3350	}
3351
3352	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3353
3354	convert_to_string_ex(fontname);
3355	convert_to_double_ex(a);
3356	convert_to_double_ex(b);
3357	convert_to_double_ex(c);
3358	convert_to_double_ex(d);
3359	convert_to_double_ex(e);
3360	convert_to_double_ex(f);
3361	convert_to_string_ex(optlist);
3362
3363	PDF_begin_font(pdf,
3364		Z_STRVAL_PP(fontname),
3365		0,
3366		(float) Z_DVAL_PP(a),
3367		(float) Z_DVAL_PP(b),
3368		(float) Z_DVAL_PP(c),
3369		(float) Z_DVAL_PP(d),
3370		(float) Z_DVAL_PP(e),
3371		(float) Z_DVAL_PP(f),
3372		Z_STRVAL_PP(optlist));
3373
3374	RETURN_TRUE;
3375}
3376/* }}} */
3377
3378/* {{{ proto void pdf_begin_glyph(int pdfdoc, string glyphname, float wx, float llx, float lly, float urx, float ury)
3379 * Start a type 3 glyph definition. */
3380PHP_FUNCTION(pdf_begin_glyph)
3381{
3382        zval **p, **glyphname, **wx, **llx, **lly, **urx, **ury;
3383        PDF *pdf;
3384
3385        if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &p, &glyphname, &wx, &llx, &lly, &urx, &ury) == FAILURE) {
3386                WRONG_PARAM_COUNT;
3387        }
3388
3389        ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3390
3391        convert_to_string_ex(glyphname);
3392        convert_to_double_ex(wx);
3393        convert_to_double_ex(llx);
3394        convert_to_double_ex(lly);
3395        convert_to_double_ex(urx);
3396        convert_to_double_ex(ury);
3397
3398        PDF_begin_glyph(pdf,
3399                Z_STRVAL_PP(glyphname),
3400                (float) Z_DVAL_PP(wx),
3401                (float) Z_DVAL_PP(llx),
3402                (float) Z_DVAL_PP(lly),
3403                (float) Z_DVAL_PP(urx),
3404                (float) Z_DVAL_PP(ury));
3405
3406        RETURN_TRUE;
3407}
3408/* }}} */
3409
3410/* {{{ proto void pdf_end_font(int pdfdoc);
3411 * Terminate a type 3 font definition. */
3412PHP_FUNCTION(pdf_end_font)
3413{
3414        zval **p;
3415        PDF *pdf;
3416
3417        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p) == FAILURE) {
3418                WRONG_PARAM_COUNT;
3419        }
3420
3421        ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3422
3423
3424        PDF_end_font(pdf);
3425
3426        RETURN_TRUE;
3427}
3428/* }}} */
3429
3430/* {{{ proto void pdf_end_glyph(int pdfdoc);
3431 * Terminate a type 3 glyph definition. */
3432PHP_FUNCTION(pdf_end_glyph)
3433{
3434        zval **p;
3435        PDF *pdf;
3436
3437        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p) == FAILURE) {
3438                WRONG_PARAM_COUNT;
3439        }
3440
3441        ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3442
3443
3444        PDF_end_glyph(pdf);
3445
3446        RETURN_TRUE;
3447}
3448/* }}} */
3449
3450/* p_xgstate.c */
3451
3452/* {{{ proto int pdf_create_gstate(int pdfdoc, string optlist);
3453 * Create a gstate object definition. */
3454PHP_FUNCTION(pdf_create_gstate)
3455{
3456	zval **p, **optlist;
3457	PDF *pdf;
3458	int retval;
3459
3460	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &p, &optlist) == FAILURE) {
3461		WRONG_PARAM_COUNT;
3462	}
3463
3464	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3465
3466	convert_to_string_ex(optlist);
3467
3468	retval = PDF_create_gstate(pdf,
3469		Z_STRVAL_PP(optlist));
3470
3471	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
3472}
3473/* }}} */
3474
3475/* {{{ proto void pdf_set_gstate(int pdfdoc, int gstate);
3476 * Activate a gstate object. */
3477PHP_FUNCTION(pdf_set_gstate)
3478{
3479        zval **p, **gstate;
3480        PDF *pdf;
3481
3482        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &p, &gstate) == FAILURE) {
3483                WRONG_PARAM_COUNT;
3484        }
3485
3486        ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
3487
3488        convert_to_long_ex(gstate);
3489
3490        PDF_set_gstate(pdf,
3491                Z_LVAL_PP(gstate));
3492
3493        RETURN_TRUE;
3494}
3495/* }}} */
3496
3497/* End of the official PDFlib GmbH V3.x/V4.x/V5.x API */
3498
3499#if HAVE_LIBGD13
3500/* {{{ proto int pdf_open_memory_image(int pdfdoc, int image)
3501   Takes an GD image and returns an image for placement in a PDF document */
3502PHP_FUNCTION(pdf_open_memory_image)
3503{
3504	zval **arg1, **arg2;
3505	int i, j, color, count;
3506	int pdf_image;
3507	gdImagePtr im;
3508	unsigned char *buffer, *ptr;
3509	PDF *pdf;
3510
3511	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
3512		WRONG_PARAM_COUNT;
3513	}
3514
3515	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
3516	ZEND_GET_RESOURCE_TYPE_ID(le_gd,"gd");
3517	if(!le_gd)
3518	{
3519		php_error(E_ERROR, "Unable to find handle for GD image stream. Please check the GD extension is loaded.");
3520	}
3521	ZEND_FETCH_RESOURCE(im, gdImagePtr, arg2, -1, "Image", le_gd);
3522
3523	count = 3 * im->sx * im->sy;
3524	buffer = (unsigned char *) emalloc(count);
3525
3526	ptr = buffer;
3527	for(i=0; i<im->sy; i++) {
3528		for(j=0; j<im->sx; j++) {
3529#if HAVE_LIBGD20
3530			if(gdImageTrueColor(im)) {
3531				if (im->tpixels && gdImageBoundsSafe(im, j, i)) {
3532					color = gdImageTrueColorPixel(im, j, i);
3533                    *ptr++ = (color >> 16) & 0xFF;
3534                    *ptr++ = (color >> 8) & 0xFF;
3535                    *ptr++ = color & 0xFF;
3536				}
3537			} else {
3538#endif
3539				if (im->pixels && gdImageBoundsSafe(im, j, i)) {
3540					color = im->pixels[i][j];
3541					*ptr++ = im->red[color];
3542					*ptr++ = im->green[color];
3543					*ptr++ = im->blue[color];
3544				}
3545#if HAVE_LIBGD20
3546			}
3547#endif
3548		}
3549	}
3550
3551	pdf_image = PDF_open_image(pdf, "raw", "memory", buffer, im->sx*im->sy*3, im->sx, im->sy, 3, 8, NULL);
3552	efree(buffer);
3553
3554	if (pdf_image == 0) {
3555		efree(buffer);
3556		RETURN_FALSE;
3557	}
3558
3559	RETURN_LONG(pdf_image); /* offset handled in PDFlib Kernel */
3560}
3561/* }}} */
3562#endif /* HAVE_LIBGD13 */
3563
3564#endif
3565
3566/*
3567 * Local variables:
3568 * tab-width: 4
3569 * c-basic-offset: 4
3570 * End:
3571 * vim600: sw=4 ts=4 fdm=marker
3572 * vim<600: sw=4 ts=4
3573 */
3574