pdf.c

来自「windows下PDF文档的开发包」· C语言 代码 · 共 2,468 行 · 第 1/5 页

C
2,468 行
字号
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);

	convert_to_double_ex(arg2);
	convert_to_double_ex(arg3);
	convert_to_double_ex(arg4);
	convert_to_double_ex(arg5);
	convert_to_double_ex(arg6);
	convert_to_double_ex(arg7);

	PDF_setmatrix(pdf,
	    (float) Z_DVAL_PP(arg2),
	    (float) Z_DVAL_PP(arg3),
	    (float) Z_DVAL_PP(arg4),
	    (float) Z_DVAL_PP(arg5),
	    (float) Z_DVAL_PP(arg6),
	    (float) Z_DVAL_PP(arg7));

	RETURN_TRUE;
}
/* }}} */

/* {{{ proto void pdf_setmiterlimit(int pdfdoc, float value)
 * Set the miter limit to a value greater than or equal to 1. */
PHP_FUNCTION(pdf_setmiterlimit)
{
	zval **arg1, **arg2;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);

	convert_to_double_ex(arg2);

	PDF_setmiterlimit(pdf, (float) Z_DVAL_PP(arg2));
	RETURN_TRUE;
}
/* }}} */

/* {{{ proto void pdf_setpolydash(int pdfdoc, float darray)
 * Deprecated, use PDF_setdashpattern() instead. */ 
PHP_FUNCTION(pdf_setpolydash)
{
	zval **arg1, **arg2;
	HashTable *array;
	int len, i;
	float *darray;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);

	convert_to_array_ex(arg2);
	array = Z_ARRVAL_PP(arg2);
	len = zend_hash_num_elements(array);

	/* TODO: ohne Malloc: maximum ist 8 ... */
	if (NULL == (darray = emalloc(len * sizeof(double)))) {
	    RETURN_FALSE;
	}
	zend_hash_internal_pointer_reset(array);
	for (i=0; i<len; i++) {
	    zval *keydata, **keydataptr;

	    zend_hash_get_current_data(array, (void **) &keydataptr);
	    keydata = *keydataptr;
	    if (Z_TYPE_P(keydata) == IS_DOUBLE) {
		darray[i] = (float) Z_DVAL_P(keydata);
	    } else if (Z_TYPE_P(keydata) == IS_LONG) {
		darray[i] = (float) Z_LVAL_P(keydata);
	    } else {
		php_error(E_WARNING,"PDFlib set_polydash: illegal darray value");
	    }
	    zend_hash_move_forward(array);
	}

	PDF_setpolydash(pdf, darray, len);

	efree(darray);
	RETURN_TRUE;
}
/* }}} */

/* {{{ proto void pdf_skew(int pdfdoc, float xangle, float yangle)
 * Skew the coordinate system in x and y direction by alpha and beta degrees. */
PHP_FUNCTION(pdf_skew)
{
	zval **arg1, **arg2, **arg3;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);

	convert_to_double_ex(arg2);
	convert_to_double_ex(arg3);
	PDF_skew(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
	RETURN_TRUE;
}
/* }}} */

/* {{{ proto void pdf_translate(int pdfdoc, float x, float y)
 * Translate the origin of the coordinate system. */
PHP_FUNCTION(pdf_translate) 
{
	zval **arg1, **arg2, **arg3;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);

	convert_to_double_ex(arg2);
	convert_to_double_ex(arg3);
	PDF_translate(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
	RETURN_TRUE;
}
/* }}} */

/* p_hyper.c */

/* {{{ proto int pdf_add_bookmark(int pdfdoc, string text [, int parent, int open]) 
 * 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. */
PHP_FUNCTION(pdf_add_bookmark)
{
	zval **p, **text, **parent, **open;
	int parentid, p_open, id;
	PDF *pdf;

	switch (ZEND_NUM_ARGS()) {
	case 2:
		if (zend_get_parameters_ex(2, &p, &text) == FAILURE) {
			WRONG_PARAM_COUNT;
		}
		break;
	case 3:
		if (zend_get_parameters_ex(3, &p, &text, &parent) == FAILURE) {
			WRONG_PARAM_COUNT;
		}
		break;
	case 4:
		if (zend_get_parameters_ex(4, &p, &text, &parent, &open) == FAILURE) {
			WRONG_PARAM_COUNT;
		}
	break;
	default:
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);

	convert_to_string_ex(text);

	if (ZEND_NUM_ARGS() > 2) {
		convert_to_long_ex(parent);
		parentid = Z_LVAL_PP(parent);

		if (ZEND_NUM_ARGS() > 3) {
			convert_to_long_ex(open);
			p_open = Z_LVAL_PP(open);
		} else {
			p_open = 0;
		}
	} else {
		parentid = 0;
		p_open = 0;
	}

	/* will never return 0 */
	id = PDF_add_bookmark2(pdf,
			Z_STRVAL_PP(text),
			Z_STRLEN_PP(text),
			parentid,
			p_open);

	RETURN_LONG(id);
}
/* }}} */

/* TODO [optlist] */
/* {{{ proto void pdf_add_nameddest(int pdfdoc, string name, string optlist)
 * Set a more complicated dash pattern defined by an optlist. */
PHP_FUNCTION(pdf_add_nameddest) 
{
	zval **p, **name, **optlist;
	PDF *pdf;
	int reserved = 0;

	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &p, &name, &optlist) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);

	convert_to_string_ex(name);
	convert_to_string_ex(optlist);

	PDF_add_nameddest(pdf,
		Z_STRVAL_PP(name),
		reserved,
		Z_STRVAL_PP(optlist));

	RETURN_TRUE;
}
/* }}} */

/* {{{ proto bool pdf_set_info(int pdfdoc, string key, string value)
 * Fill document information field key with value. key is one of "Subject", "Title", "Creator", "Author", "Keywords", or a user-defined key. */
PHP_FUNCTION(pdf_set_info) 
{
	zval **p, **key, **value;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &p, &key, &value) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);

	convert_to_string_ex(key);
	convert_to_string_ex(value);

	PDF_set_info2(pdf,
		Z_STRVAL_PP(key),
		Z_STRVAL_PP(value),
		Z_STRLEN_PP(value));

	RETURN_TRUE;
}
/* }}} */

/* p_icc.c */

/* TODO [optlist] */
/* {{{ proto int pdf_load_iccprofile(int pdfdoc, string profilename, string optlist);
 * Search an ICC profile, and prepare it for later use. */
PHP_FUNCTION(pdf_load_iccprofile)
{
	zval **p, **profilename, **optlist;
	PDF *pdf;
	int reserved = 0;
	char * vprofilename;
	int retval;

	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &p, &profilename, &optlist) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);

	convert_to_string_ex(profilename);
	convert_to_string_ex(optlist);

#ifdef VIRTUAL_DIR
#    if ZEND_MODULE_API_NO >= 20010901
	virtual_filepath(Z_STRVAL_PP(profilename), &vprofilename TSRMLS_CC);
#    else
	virtual_filepath(Z_STRVAL_PP(profilename), &vprofilename);
#    endif
#else
	vprofilename = Z_STRVAL_PP(profilename);
#endif  


	retval = PDF_load_iccprofile(pdf,
		vprofilename,
		reserved,
		Z_STRVAL_PP(optlist));

	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
}
/* }}} */

/* p_image.c */

/* {{{ proto void pdf_add_thumbnail(int pdfdoc, int image);
 * Add an existing image as thumbnail for the current page. */
PHP_FUNCTION(pdf_add_thumbnail)
{
	zval **arg1, **arg2;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);

	convert_to_long_ex(arg2);

	PDF_add_thumbnail(pdf,
		Z_LVAL_PP(arg2));

	RETURN_TRUE;
}
/* }}} */

/* {{{ proto void pdf_close_image(int pdfdoc, int image)
 * Close an image retrieved with PDF_load_image(). */
PHP_FUNCTION(pdf_close_image)
{
	zval **arg1, **arg2;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
	convert_to_long_ex(arg2);

	PDF_close_image(pdf, Z_LVAL_PP(arg2));
}
/* }}} */

/* TODO [optlist] */
/* {{{ proto void pdf_fit_image(int pdfdoc, int image, float x, float y, string optlist);
 * Place an image or template at (x, y) with various options. */
PHP_FUNCTION(pdf_fit_image)
{
	zval **p, **image, **x, **y, **optlist;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &image, &x, &y, &optlist) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);

	convert_to_long_ex(image);
	convert_to_double_ex(x);
	convert_to_double_ex(y);
	convert_to_string_ex(optlist);

	PDF_fit_image(pdf,
		Z_LVAL_PP(image),
		(float)Z_DVAL_PP(x),
		(float)Z_DVAL_PP(y),
		Z_STRVAL_PP(optlist));

	RETURN_TRUE
}
/* }}} */

/* TODO [optlist] */
/* {{{ proto int pdf_load_image(int pdfdoc, string imagetype, string filename, string optlist);
 * Open a (disk-based or virtual) image file with various options.*/
PHP_FUNCTION(pdf_load_image)
{
	zval **p, **imagetype, **filename, **optlist;
	PDF *pdf;
	const char *vfilename;
	int reserved = 0;
	int retval;

	if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &p, &imagetype, &filename, &optlist) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);

	convert_to_string_ex(imagetype);
	convert_to_string_ex(filename);
	convert_to_string_ex(optlist);

#ifdef VIRTUAL_DIR
#    if ZEND_MODULE_API_NO >= 20010901
	virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
#    else
	virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
#    endif
#else
	vfilename = Z_STRVAL_PP(filename);
#endif  

	retval = PDF_load_image(pdf,
		Z_STRVAL_PP(imagetype),
		vfilename,
		reserved,
		Z_STRVAL_PP(optlist));

	RETURN_LONG(retval); /* offset handled in PDFlib Kernel */
}
/* }}} */

/* {{{ proto int pdf_open_ccitt(int pdfdoc, string filename, int width, int height, int bitreverse, int k, int blackls1)
 * Deprecated, use PDF_load_image() instead. */
PHP_FUNCTION(pdf_open_ccitt)
{
	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7;
	PDF *pdf;
	int pdf_image;
	char *image;

	if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);

	convert_to_string_ex(arg2);
#ifdef VIRTUAL_DIR
#    if ZEND_MODULE_API_NO >= 20010901
	virtual_filepath(Z_STRVAL_PP(arg2), &image TSRMLS_CC);
#    else
	virtual_filepath(Z_STRVAL_PP(arg2), &image);
#    endif
#else
	image = Z_STRVAL_PP(arg2);
#endif  

	convert_to_long_ex(arg3);
	convert_to_long_ex(arg4);
	convert_to_long_ex(arg5);
	convert_to_long_ex(arg6);
	convert_to_long_ex(arg7);

	pdf_image = PDF_open_CCITT(pdf,
	    image,
	    Z_LVAL_PP(arg3),
	    Z_LVAL_PP(arg4),
	    Z_LVAL_PP(arg5),
	    Z_LVAL_PP(arg6),
	    Z_LVAL_PP(arg7));

	RETURN_LONG(pdf_image); /* offset handled in PDFlib Kernel */
}
/* }}} */

/* {{{ 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)
 * Deprecated, use PDF_load_image() with virtual files instead. */
PHP_FUNCTION(pdf_open_image)
{
	zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7, **arg8, **arg9, **arg10;
	PDF *pdf;
	int pdf_image;

	if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);

	convert_to_string_ex(arg2);
	convert_to_string_ex(arg3);
	convert_to_string_ex(arg4);
	convert_to_long_ex(arg5);
	convert_to_long_ex(arg6);
	convert_to_long_ex(arg7);
	convert_to_long_ex(arg8);
	convert_to_long_ex(arg9);
	convert_to_string_ex(arg10);

	pdf_image = PDF_open_image(pdf,
		Z_STRVAL_PP(arg2),
		Z_STRVAL_PP(arg3),
		Z_STRVAL_PP(arg4),
		Z_LVAL_PP(arg5),
		Z_LVAL_PP(arg6),
		Z_LVAL_PP(arg7),
		Z_LVAL_PP(arg8),
		Z_LVAL_PP(arg9),
		Z_STRVAL_PP(arg10));

	RETURN_LONG(pdf_image); /* offset handled in PDFlib Kernel */
}
/* }}} */

/* {{{ proto int pdf_open_image_file(int pdfdoc, string imagetype, string filename, string stringparam, int intparam)
 * Deprecated, use PDF_load_image() instead. */
PHP_FUNCTION(pdf_open_image_file)
{
	zval **p, **imagetype, **filename, **stringparam, **intparam;
	PDF *pdf;
	int pdf_image, argc;
	const char *vfilename;

	switch ((argc = ZEND_NUM_ARGS())) {
	case 3:
		if (zend_get_parameters_ex(3, &p, &imagetype, &fi

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?