📄 pdf.c
字号:
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); width = (int) PDF_get_value(pdf, "imagewidth", (float)Z_LVAL_PP(arg2)-PDFLIB_IMAGE_OFFSET); RETURN_LONG(width);}/* }}} *//* {{{ proto int pdf_get_image_height(int pdf, int pdfimage) Returns the height of an image */PHP_FUNCTION(pdf_get_image_height){ zval **arg1, **arg2; PDF *pdf; int height; 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); height = (int) PDF_get_value(pdf, "imageheight", (float)Z_LVAL_PP(arg2)-PDFLIB_IMAGE_OFFSET); RETURN_LONG(height);}/* }}} *//* {{{ proto void pdf_add_weblink(int pdfdoc, float llx, float lly, float urx, float ury, string url) Adds link to web resource */PHP_FUNCTION(pdf_add_weblink){ zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6; PDF *pdf; if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == 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); convert_to_double_ex(arg4); convert_to_double_ex(arg5); convert_to_string_ex(arg6); PDF_add_weblink(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4), (float) Z_DVAL_PP(arg5), Z_STRVAL_PP(arg6)); RETURN_TRUE;}/* }}} *//* {{{ proto void pdf_add_pdflink(int pdfdoc, float llx, float lly, float urx, float ury, string filename, int page, string dest) Adds link to PDF document */PHP_FUNCTION(pdf_add_pdflink){ zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7, **arg8; PDF *pdf; if (ZEND_NUM_ARGS() != 8 || zend_get_parameters_ex(8, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8) == 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); convert_to_double_ex(arg4); convert_to_double_ex(arg5); convert_to_string_ex(arg6); convert_to_long_ex(arg7); convert_to_string_ex(arg8); PDF_add_pdflink(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4), (float) Z_DVAL_PP(arg5), Z_STRVAL_PP(arg6), Z_LVAL_PP(arg7), Z_STRVAL_PP(arg8)); RETURN_TRUE;}/* }}} *//* {{{ proto void pdf_set_border_style(int pdfdoc, string style, float width) Sets style of box surounding all kinds of annotations and link */PHP_FUNCTION(pdf_set_border_style){ 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_string_ex(arg2); convert_to_double_ex(arg3); PDF_set_border_style(pdf, Z_STRVAL_PP(arg2), (float) Z_DVAL_PP(arg3)); RETURN_TRUE;}/* }}} *//* {{{ proto void pdf_set_border_color(int pdfdoc, float red, float green, float blue) Sets color of box surounded all kinds of annotations and links */PHP_FUNCTION(pdf_set_border_color){ zval **arg1, **arg2, **arg3, **arg4; PDF *pdf; if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == 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); convert_to_double_ex(arg4); PDF_set_border_color(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4)); RETURN_TRUE;}/* }}} *//* {{{ proto void pdf_set_border_dash(int pdfdoc, float black, float white) Sets the border dash style of all kinds of annotations and links */PHP_FUNCTION(pdf_set_border_dash){ 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_set_border_dash(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3)); RETURN_TRUE;}/* }}} *//* {{{ proto void pdf_add_annotation(int pdfdoc, float xll, float yll, float xur, float xur, string title, string text) Sets annotation (depreciated use pdf_add_note instead) */PHP_FUNCTION(pdf_add_annotation){ zval **argv[7]; PDF *pdf; if(ZEND_NUM_ARGS() != 7 || zend_get_parameters_array_ex(7, argv) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(pdf, PDF *, argv[0], -1, "pdf object", le_pdf); convert_to_double_ex(argv[1]); convert_to_double_ex(argv[2]); convert_to_double_ex(argv[3]); convert_to_double_ex(argv[4]); convert_to_string_ex(argv[5]); convert_to_string_ex(argv[6]); PDF_add_note(pdf, (float) Z_DVAL_PP(argv[1]), (float) Z_DVAL_PP(argv[2]), (float) Z_DVAL_PP(argv[3]), (float) Z_DVAL_PP(argv[4]), Z_STRVAL_PP(argv[6]), Z_STRVAL_PP(argv[5]), "note", 1); RETURN_TRUE;}/* }}} *//* RJS: START OF NEW CODE *//* {{{ proto int pdf_new() Creates a new PDF object */PHP_FUNCTION(pdf_new){ PDF *pdf; pdf = PDF_new2(custom_errorhandler, pdf_emalloc, pdf_realloc, pdf_efree, NULL);#if (PDFLIB_MAJORVERSION >= 4) PDF_set_parameter(pdf, "imagewarning", "true");#endif PDF_set_parameter(pdf, "binding", "PHP"); ZEND_REGISTER_RESOURCE(return_value, pdf, le_pdf);}/* }}} *//* {{{ proto int pdf_get_majorversion() Returns the major version number of the PDFlib */PHP_FUNCTION(pdf_get_majorversion){ if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } RETURN_LONG(PDF_get_majorversion());}/* {{{ proto int pdf_get_minorversion() Returns the minor version number of the PDFlib */PHP_FUNCTION(pdf_get_minorversion){ if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } RETURN_LONG(PDF_get_minorversion());}/* }}} *//* {{{ proto bool pdf_delete(int pdfdoc) Deletes the PDF object */PHP_FUNCTION(pdf_delete){ zval **arg1; PDF *pdf; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf); zend_list_delete(Z_RESVAL_PP(arg1)); RETURN_TRUE;}/* }}} *//* {{{ proto int pdf_open_file(int pdfdoc [, char filename]) Opens a new PDF document. If filename is NULL, document is created in memory. This is not yet fully supported */PHP_FUNCTION(pdf_open_file){ zval **arg1, **arg2; int pdf_file; char *filename; int argc; PDF *pdf; if((argc = ZEND_NUM_ARGS()) > 2) WRONG_PARAM_COUNT; if (argc == 1) { if (zend_get_parameters_ex(1, &arg1) == FAILURE) WRONG_PARAM_COUNT; } else { if (zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf); if (argc == 2) { convert_to_string_ex(arg2); filename = Z_STRVAL_PP(arg2); if (php_check_open_basedir(filename TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(filename, "wb+", CHECKUID_CHECK_MODE_PARAM))) { RETURN_FALSE; } pdf_file = PDF_open_file(pdf, filename); } else { /* open in memory */ pdf_file = PDF_open_file(pdf, ""); } if (pdf_file == -1) RETURN_FALSE; RETURN_TRUE;}/* }}} *//* {{{ proto int pdf_get_buffer(int pdfdoc) Fetches the full buffer containig the generated PDF data */PHP_FUNCTION(pdf_get_buffer){ zval **arg1; long size; PDF *pdf; const char *buffer; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf); buffer = PDF_get_buffer(pdf, &size); RETURN_STRINGL((char *)buffer, size, 1);}/* }}} *//* {{{ proto int pdf_findfont(int pdfdoc, string fontname, string encoding [, int embed]) Prepares the font fontname for later use with pdf_setfont() */PHP_FUNCTION(pdf_findfont){ zval **arg1, **arg2, **arg3, **arg4; int embed, font; const char *fontname, *encoding; PDF *pdf; switch (ZEND_NUM_ARGS()) { case 3: if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) { WRONG_PARAM_COUNT; } embed = 0; break; case 4: if (zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long_ex(arg4); embed = Z_LVAL_PP(arg4); break; default: WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf); convert_to_string_ex(arg2); fontname = Z_STRVAL_PP(arg2); convert_to_string_ex(arg3); encoding = Z_STRVAL_PP(arg3); font = PDF_findfont(pdf, fontname, encoding, embed); if (font == -1) { /* pdflib will do this for you, will throw some exception php_error(E_WARNING,"Font %s not found", fontname); */ RETURN_FALSE; } RETURN_LONG(font+PDFLIB_FONT_OFFSET);}/* }}} *//* {{{ proto void pdf_setfont(int pdfdoc, int font, float fontsize) Sets the current font in the fiven fontsize */PHP_FUNCTION(pdf_setfont){ zval **arg1, **arg2, **arg3; int font; float fontsize; PDF *pdf; if(ZEND_NUM_ARGS() != 3) WRONG_PARAM_COUNT; if (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_long_ex(arg2); font = Z_LVAL_PP(arg2); convert_to_double_ex(arg3); fontsize = (float)Z_DVAL_PP(arg3); PDF_setfont(pdf, font-PDFLIB_FONT_OFFSET, fontsize); RETURN_TRUE;}/* }}} *//* {{{ proto void pdf_setpolydash(int pdfdoc, float darray) Sets more complicated dash pattern */ 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); if (NULL == (darray = safe_emalloc(len, sizeof(double), 0))) { 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_concat(int pdf, float a, float b, float c, float d, float e, float f) Concatenates a matrix to the current transformation matrix for text and graphics */PHP_FUNCTION(pdf_concat){ zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6, **arg7; PDF *pdf; 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_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_concat(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 int pdf_open_ccitt(int pdf, string filename, int width, int height, int bitreverse, int k, int blackls1) Opens an image file with raw CCITT G3 or G4 compresed bitmap data */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 virtual_filepath(Z_STRVAL_PP(arg2), &image TSRMLS_CC);#else image = Z_STRVAL_PP(arg2);#endif if (php_check_open_basedir(image TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(image, "rb+", CHECKUID_CHECK_MODE_PARAM))) { RETURN_FALSE; } 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+PDFLIB_IMAGE_OFFSET);}/* }}} *//* {{{ proto int pdf_open_image(int pdf, string type, string source, string data, long length, int width, int height, int components, int bpc, string params) Opens an image of the given type and returns an image for placement in a PDF document */PHP_FUNCTION(pdf_open_image){ zval **arg1, **arg2, **arg3, **arg4, **arg5,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -