📄 cpdf.c
字号:
/* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Uwe Steinmann <Uwe.Steinmann@fernuni-hagen.de> | +----------------------------------------------------------------------+ *//* $Id: cpdf.c,v 1.43.4.7.2.2 2007/01/01 09:46:40 sebastian Exp $ *//* cpdflib.h -- C language API definitions for ClibPDF library * Copyright (C) 1998 FastIO Systems, All Rights Reserved.*//* Note that there is no code from the cpdflib package in this file */#if defined(THREAD_SAFE)#undef THREAD_SAFE#endif#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_globals.h"#include "zend_list.h"#include "ext/standard/php_standard.h"#include "ext/standard/head.h"#include <math.h>#if HAVE_LIBGD13#include <gd.h>#endif#include <cpdflib.h>#ifdef HAVE_UNISTD_H# include <unistd.h>#endif#ifdef PHP_WIN32# include <io.h># include <fcntl.h>#endif#if HAVE_CPDFLIB#include "php_cpdf.h"#include "ext/standard/info.h"#ifdef THREAD_SAFEDWORD CPDFlibTls;static int numthreads=0;typedef struct cpdflib_global_struct{ int le_cpdf; int le_outline;#if HAVE_LIBGD13 int le_gd;#endif} cpdflib_global_struct;# define CPDF_GLOBAL(v) TSRMG(CPDFlibTls, cpdflib_global_struct *, v)#else# define CPDF_GLOBAL(a) astatic int le_cpdf;static int le_outline;#if HAVE_LIBGD13static int le_gd;#endif#endiffunction_entry cpdf_functions[] = { PHP_FE(cpdf_global_set_document_limits, NULL) PHP_FE(cpdf_set_creator, NULL) PHP_FE(cpdf_set_title, NULL) PHP_FE(cpdf_set_subject, NULL) PHP_FE(cpdf_set_keywords, NULL) PHP_FE(cpdf_open, NULL) PHP_FE(cpdf_close, NULL) PHP_FE(cpdf_set_viewer_preferences, NULL) PHP_FE(cpdf_page_init, NULL) PHP_FE(cpdf_finalize_page, NULL) PHP_FE(cpdf_set_current_page, NULL) PHP_FE(cpdf_begin_text, NULL) PHP_FE(cpdf_end_text, NULL) PHP_FE(cpdf_show, NULL) PHP_FE(cpdf_show_xy, NULL) PHP_FE(cpdf_text, NULL) PHP_FE(cpdf_continue_text, NULL) PHP_FE(cpdf_set_font, NULL) PHP_FE(cpdf_set_font_directories, NULL) PHP_FE(cpdf_set_font_map_file, NULL) PHP_FE(cpdf_set_leading, NULL) PHP_FE(cpdf_set_text_rendering, NULL) PHP_FE(cpdf_set_horiz_scaling, NULL) PHP_FE(cpdf_set_text_rise, NULL) PHP_FE(cpdf_set_text_matrix, NULL) PHP_FE(cpdf_set_text_pos, NULL) PHP_FE(cpdf_rotate_text, NULL) PHP_FE(cpdf_set_char_spacing, NULL) PHP_FE(cpdf_set_word_spacing, NULL) PHP_FE(cpdf_stringwidth, NULL) PHP_FE(cpdf_save, NULL) PHP_FE(cpdf_restore, NULL) PHP_FE(cpdf_translate, NULL) PHP_FE(cpdf_scale, NULL) PHP_FE(cpdf_rotate, NULL) PHP_FE(cpdf_setflat, NULL) PHP_FE(cpdf_setlinejoin, NULL) PHP_FE(cpdf_setlinecap, NULL) PHP_FE(cpdf_setmiterlimit, NULL) PHP_FE(cpdf_setlinewidth, NULL) PHP_FE(cpdf_setdash, NULL) PHP_FE(cpdf_moveto, NULL) PHP_FE(cpdf_rmoveto, NULL) PHP_FE(cpdf_lineto, NULL) PHP_FE(cpdf_rlineto, NULL) PHP_FE(cpdf_curveto, NULL) PHP_FE(cpdf_circle, NULL) PHP_FE(cpdf_arc, NULL) PHP_FE(cpdf_rect, NULL) PHP_FE(cpdf_newpath, NULL) PHP_FE(cpdf_closepath, NULL) PHP_FE(cpdf_stroke, NULL) PHP_FE(cpdf_closepath_stroke, NULL) PHP_FE(cpdf_fill, NULL) PHP_FE(cpdf_fill_stroke, NULL) PHP_FE(cpdf_closepath_fill_stroke, NULL) PHP_FE(cpdf_clip, NULL) PHP_FE(cpdf_setgray_fill, NULL) PHP_FE(cpdf_setgray_stroke, NULL) PHP_FE(cpdf_setgray, NULL) PHP_FE(cpdf_setrgbcolor_fill, NULL) PHP_FE(cpdf_setrgbcolor_stroke, NULL) PHP_FE(cpdf_setrgbcolor, NULL) PHP_FE(cpdf_set_page_animation, NULL) PHP_FE(cpdf_finalize, NULL) PHP_FE(cpdf_output_buffer, NULL) PHP_FE(cpdf_save_to_file, NULL) PHP_FE(cpdf_import_jpeg, NULL)#if HAVE_LIBGD13 PHP_FE(cpdf_place_inline_image, NULL)#endif PHP_FE(cpdf_add_annotation, NULL) PHP_FE(cpdf_add_outline, NULL) PHP_FE(cpdf_set_action_url, NULL) {NULL, NULL, NULL}};zend_module_entry cpdf_module_entry = { STANDARD_MODULE_HEADER, "cpdf", cpdf_functions, PHP_MINIT(cpdf), PHP_MSHUTDOWN(cpdf), PHP_RINIT(cpdf), NULL, PHP_MINFO(cpdf), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_CPDFZEND_GET_MODULE(cpdf)#endifstatic void _free_outline(zend_rsrc_list_entry *rsrc TSRMLS_DC){}static void _free_doc(zend_rsrc_list_entry *rsrc TSRMLS_DC){ CPDFdoc *pdf = (CPDFdoc *)rsrc->ptr; cpdf_close(pdf);}PHP_MINIT_FUNCTION(cpdf){ CPDF_GLOBAL(le_outline) = zend_register_list_destructors_ex(_free_outline, NULL, "cpdf outline", module_number); CPDF_GLOBAL(le_cpdf) = zend_register_list_destructors_ex(_free_doc, NULL, "cpdf", module_number); REGISTER_LONG_CONSTANT("CPDF_PM_NONE", PM_NONE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CPDF_PM_OUTLINES", PM_OUTLINES, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CPDF_PM_THUMBS", PM_THUMBS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CPDF_PM_FULLSCREEN", PM_FULLSCREEN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CPDF_PL_SINGLE", PL_SINGLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CPDF_PL_1COLUMN", PL_1COLUMN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CPDF_PL_2LCOLUMN", PL_2LCOLUMN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CPDF_PL_2RCOLUMN", PL_2RCOLUMN, CONST_CS | CONST_PERSISTENT); return SUCCESS;}PHP_RINIT_FUNCTION(cpdf){/* CPDF_GLOBAL(le_outline) = NULL; */ return SUCCESS;}PHP_MINFO_FUNCTION(cpdf) { /* need to use a PHPAPI function here because it is external module in windows */ /* (don't knwo if that still applies (cmv) */ php_info_print_table_start(); php_info_print_table_row(2, "CPDF Support", "enabled"); php_info_print_table_row(2, "Version", cpdf_version() ); php_info_print_table_end();}PHP_MSHUTDOWN_FUNCTION(cpdf){ return SUCCESS;}/* {{{ proto bool cpdf_global_set_document_limits(int maxPages, int maxFonts, int maxImages, int maxAnnots, int maxObjects) Sets document settings for all documents */PHP_FUNCTION(cpdf_global_set_document_limits){ pval *argv[5]; int argc; argc = ZEND_NUM_ARGS(); if(argc != 5) WRONG_PARAM_COUNT; if (getParametersArray(ht, argc, argv) == FAILURE) WRONG_PARAM_COUNT; convert_to_long(argv[0]); convert_to_long(argv[1]); convert_to_long(argv[2]); convert_to_long(argv[3]); convert_to_long(argv[4]); cpdf_setGlobalDocumentLimits(Z_LVAL_P(argv[0]), Z_LVAL_P(argv[1]), Z_LVAL_P(argv[2]), Z_LVAL_P(argv[3]), Z_LVAL_P(argv[4])); RETURN_TRUE;}/* }}} *//* {{{ proto bool cpdf_set_creator(int pdfdoc, string creator) Sets the creator field */PHP_FUNCTION(cpdf_set_creator){ pval *arg1, *arg2; int id, type; CPDFdoc *pdf; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); convert_to_string(arg2); id=Z_LVAL_P(arg1); pdf = zend_list_find(id, &type); if (!pdf || type!=CPDF_GLOBAL(le_cpdf)) { php_error(E_WARNING, "%s(): Unable to find identifier %d (type=%d)", get_active_function_name(TSRMLS_C), id, type); RETURN_FALSE; } cpdf_setCreator(pdf, Z_STRVAL_P(arg2)); RETURN_TRUE;}/* }}} *//* {{{ proto bool cpdf_set_title(int pdfptr, string title) Fills the title field of the info structure */PHP_FUNCTION(cpdf_set_title){ pval *arg1, *arg2; int id, type; CPDFdoc *pdf; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); convert_to_string(arg2); id=Z_LVAL_P(arg1); pdf = zend_list_find(id, &type); if (!pdf || type!=CPDF_GLOBAL(le_cpdf)) { php_error(E_WARNING, "%s(): Unable to find identifier %d (type=%d)", get_active_function_name(TSRMLS_C), id, type); RETURN_FALSE; } cpdf_setTitle(pdf, Z_STRVAL_P(arg2)); RETURN_TRUE;}/* }}} *//* {{{ proto bool cpdf_set_subject(int pdfptr, string subject) Fills the subject field of the info structure */PHP_FUNCTION(cpdf_set_subject){ pval *arg1, *arg2; int id, type; CPDFdoc *pdf; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); convert_to_string(arg2); id=Z_LVAL_P(arg1); pdf = zend_list_find(id, &type); if (!pdf || type!=CPDF_GLOBAL(le_cpdf)) { php_error(E_WARNING, "%s(): Unable to find identifier %d (type=%d)", get_active_function_name(TSRMLS_C), id, type); RETURN_FALSE; } cpdf_setSubject(pdf, Z_STRVAL_P(arg2)); RETURN_TRUE;}/* }}} *//* {{{ proto bool cpdf_set_keywords(int pdfptr, string keywords) Fills the keywords field of the info structure */PHP_FUNCTION(cpdf_set_keywords){ pval *arg1, *arg2; int id, type; CPDFdoc *pdf; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); convert_to_string(arg2); id=Z_LVAL_P(arg1); pdf = zend_list_find(id, &type); if (!pdf || type!=CPDF_GLOBAL(le_cpdf)) { php_error(E_WARNING, "%s(): Unable to find identifier %d (type=%d)", get_active_function_name(TSRMLS_C), id, type); RETURN_FALSE; } cpdf_setKeywords(pdf, Z_STRVAL_P(arg2)); RETURN_TRUE;}/* }}} *//* {{{ proto bool cpdf_set_viewer_preferences(int pdfdoc, array preferences) How to show the document in the viewer */PHP_FUNCTION(cpdf_set_viewer_preferences){ zval *arg1, *arg2; zval **zvalue; int id, type; CPDFdoc *pdf; CPDFviewerPrefs vP = { 0, 0, 0, 0, 0, 0, 0, 0 }; if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT; if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) WRONG_PARAM_COUNT; convert_to_long(arg1); convert_to_array(arg2); id = Z_LVAL_P (arg1); pdf = zend_list_find(id, &type); if(!pdf || type!=CPDF_GLOBAL(le_cpdf)) { php_error(E_WARNING, "%s(): Unable to find identifier %d", get_active_function_name(TSRMLS_C), id); RETURN_FALSE; } if (zend_hash_find (Z_ARRVAL_P(arg2), "pagemode", sizeof ("pagemode"), (void **) &zvalue) == SUCCESS) { convert_to_long_ex (zvalue); vP.pageMode = Z_LVAL_PP (zvalue); } if (zend_hash_find (Z_ARRVAL_P(arg2), "hidetoolbar", sizeof ("hidetoolbar"), (void **) &zvalue) == SUCCESS) { convert_to_long_ex (zvalue); vP.hideToolbar = Z_LVAL_PP (zvalue); } if (zend_hash_find (Z_ARRVAL_P(arg2), "hidemenubar", sizeof ("hidemenubar"), (void **) &zvalue) == SUCCESS) { convert_to_long_ex (zvalue); vP.hideMenubar = Z_LVAL_PP (zvalue); } if (zend_hash_find (Z_ARRVAL_P(arg2), "hidewindowui", sizeof ("hidewindowui"), (void **) &zvalue) == SUCCESS) { convert_to_long_ex (zvalue); vP.hideWindowUI = Z_LVAL_PP (zvalue); } if (zend_hash_find (Z_ARRVAL_P(arg2), "fitwindow", sizeof ("fitwindow"), (void **) &zvalue) == SUCCESS) { convert_to_long_ex (zvalue); vP.fitWindow = Z_LVAL_PP (zvalue); } if (zend_hash_find (Z_ARRVAL_P(arg2), "centerwindow", sizeof ("centerwindow"), (void **) &zvalue) == SUCCESS) { convert_to_long_ex (zvalue); vP.centerWindow = Z_LVAL_PP (zvalue); } if (zend_hash_find (Z_ARRVAL_P(arg2), "pagelayout", sizeof ("pagelayout"), (void **) &zvalue) == SUCCESS) { convert_to_long_ex (zvalue); vP.pageLayout = Z_LVAL_PP (zvalue); } if (zend_hash_find (Z_ARRVAL_P(arg2), "nonfspagemode", sizeof ("nonfspagemode"), (void **) &zvalue) == SUCCESS) { convert_to_long_ex (zvalue); vP.nonFSPageMode = Z_LVAL_PP (zvalue); } cpdf_setViewerPreferences(pdf, &vP); RETURN_TRUE;}/* }}} *//* {{{ proto int cpdf_open(int compression [, string filename [, array doc_limits]]) Opens a new pdf document */PHP_FUNCTION(cpdf_open){ pval *arg1, *arg2, *arg3; int id, argc; CPDFdoc *cpdf; argc = ZEND_NUM_ARGS(); switch(argc) { case 1: if (getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; } break; case 2: if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } break; case 3: if (getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) { WRONG_PARAM_COUNT; } break; default: WRONG_PARAM_COUNT; } convert_to_long(arg1); cpdf = cpdf_open(0, NULL); if(!cpdf) RETURN_FALSE; if(Z_LVAL_P(arg1) == 1) cpdf_enableCompression(cpdf, YES); else cpdf_enableCompression(cpdf, NO); if(argc > 1) { convert_to_string(arg2);#if APACHE if(strcmp(Z_STRVAL_P(arg2), "-") == 0) php_error(E_WARNING, "%s(): Writing to stdout as described in the ClibPDF manual is not possible if php is used as an Apache module. Write to a memory stream and use cpdf_output_buffer() instead.", get_active_function_name(TSRMLS_C));#endif if (php_check_open_basedir(Z_STRVAL_P(arg2) TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(Z_STRVAL_P(arg2), "rb+", CHECKUID_CHECK_MODE_PARAM))) { cpdf_close(cpdf); RETURN_FALSE; } cpdf_setOutputFilename(cpdf, Z_STRVAL_P(arg2)); } cpdf_init(cpdf); id = zend_list_insert(cpdf, CPDF_GLOBAL(le_cpdf)); RETURN_LONG(id);}/* }}} *//* {{{ proto void cpdf_close(int pdfdoc) Closes the pdf document */PHP_FUNCTION(cpdf_close){ pval *arg1; int id, type; CPDFdoc *pdf; if (ZEND_NUM_ARGS() != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg1); id=Z_LVAL_P(arg1); pdf = zend_list_find(id, &type); if(!pdf || type!=CPDF_GLOBAL(le_cpdf)) { php_error(E_WARNING, "%s(): Unable to find identifier %d", get_active_function_name(TSRMLS_C), id); RETURN_FALSE; } zend_list_delete(id); RETURN_TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -