Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Test wrappers bug (COR-9) #55

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#-----------------------------------------------------------------------------------------------------------------------

project(PDFNetLanguageBindings CXX)
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)

set(BUILD_PDFNetPython OFF CACHE BOOL "Build PDFNet language bindings for Python.")
set(BUILD_PDFNetRuby OFF CACHE BOOL "Build PDFNet language bindings for Ruby.")
Expand Down
57 changes: 32 additions & 25 deletions PDFNetPHP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
#-----------------------------------------------------------------------------------------------------------------------

project(PDFNetPHP CXX)
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)

find_program(PHP_CONFIG_EXECUTABLE NAMES php-config7 php-config5 php-config4 php-config)
if (NOT PHP_CONFIG_EXECUTABLE)
message(FATAL_ERROR "Cannot find php-config, please set the variable PHP_CONFIG_EXECUTABLE to the location of php-config then try again.")
return ()
endif ()

if (WIN32)
message(STATUS "Windows host platform detected.")
Expand All @@ -15,14 +21,8 @@ if (WIN32)
return ()
endif ()
else ()
find_program(PHP_CONFIG php-config)
if (PHP_CONFIG-NOTFOUND)
message(FATAL_ERROR "Cannot find php-config, please set the variable PHP_CONFIG to the location of php-config then try again.")
return ()
endif ()

execute_process(
COMMAND ${PHP_CONFIG} --includes
COMMAND ${PHP_CONFIG_EXECUTABLE} --includes
RESULT_VARIABLE PHP_CONFIG_INCLUDES_RESULT
OUTPUT_VARIABLE PHP_CONFIG_INCLUDES
ERROR_VARIABLE PHP_CONFIG_INCLUDES_ERR
Expand All @@ -39,7 +39,7 @@ else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PHP_CONFIG_INCLUDES}")

execute_process(
COMMAND ${PHP_CONFIG} --extension-dir
COMMAND ${PHP_CONFIG_EXECUTABLE} --extension-dir
RESULT_VARIABLE PHP_CONFIG_EXT_DIR_RESULT
OUTPUT_VARIABLE PHP_CONFIG_EXT_DIR
ERROR_VARIABLE PHP_CONFIG_EXT_DIR_ERR
Expand All @@ -58,7 +58,6 @@ message(STATUS "Generating sources for PHP bindings using swig...")
set(PDFNetPHP_SourcesDir ${PROJECT_BINARY_DIR})

#configure PHP version
find_program(PHP_CONFIG_EXECUTABLE NAMES php-config7 php-config5 php-config4 php-config)
if (PHP_CONFIG_EXECUTABLE)

execute_process(
Expand Down Expand Up @@ -99,13 +98,27 @@ if (("${SWIG_VERSION}" MATCHES "^2[\\.0-9]*[a-zA-Z0-9\\+]*$") AND (PHP_MAJOR_VER
return ()
endif()

string(REGEX REPLACE "\([0-9]+\)([.a-zA-Z0-9]+)*" "\\1" SWIG_MAJOR_VERSION ${SWIG_VERSION})
string(REGEX REPLACE "[0-9]+\\.\([0-9]+\)([.a-zA-Z0-9])*" "\\1" SWIG_MINOR_VERSION ${SWIG_VERSION})

message(STATUS "====================================================")
message(STATUS "*** WARNING: SWIG2 doesn't work with PHP7. Please make sure either SWIG2/PHP5 or SWIG3+/PHP7 are installed. Note that only SWIG-3.0.12 and above works with PHP7. Any other combination of SWIG and PHP VERSION is likely to encounter problems!")
message(STATUS "====================================================")
message(STATUS "SWIG VERSION = ${SWIG_VERSION}")
message(STATUS "PHP_MAJOR_VERSION = ${PHP_MAJOR_VERSION}")
message(STATUS "PHP_MINOR_VERSION = ${PHP_MINOR_VERSION}")
message(STATUS "${SWIG_EXECUTABLE} -c++ -${php_version} -D${swig_php_major_arg}...")
message(STATUS "CMAKE VERSION = ${CMAKE_VERSION}")
message(STATUS "SWIG VERSION = ${SWIG_VERSION}")
message(STATUS "SWIG_MAJOR_VERSION = ${SWIG_MAJOR_VERSION}")
message(STATUS "SWIG_MINOR_VERSION = ${SWIG_MINOR_VERSION}")
message(STATUS "PHP_MAJOR_VERSION = ${PHP_MAJOR_VERSION}")
message(STATUS "PHP_MINOR_VERSION = ${PHP_MINOR_VERSION}")

set(PHP_TARGET_FILE ON)
if((SWIG_MAJOR_VERSION LESS 4) OR (SWIG_MAJOR_VERSION EQUAL 4 AND SWIG_MINOR_VERSION LESS 1))
if (PHP_MAJOR_VERSION GREATER 7)
message(FATAL_ERROR "ERROR! Cannot run PHP8 with SWIG 4.0 or below. Minimum is SWIG 4.1/PHP8. Please make sure you have the correct SWIG package before proceeding!")
return ()
endif()
else ()
set(PHP_TARGET_FILE OFF)
endif()
message(STATUS "PHP_TARGET_FILE = ${PHP_TARGET_FILE}")

execute_process(
COMMAND ${SWIG_EXECUTABLE} -c++ -${php_version} -DNTS -DSWIGHIDDEN_SIG -D${swig_php_major_arg} -I${PDFNetC_Include_Dir} -outdir ${PDFNetPHP_SourcesDir} -o ${PDFNetPHP_SourcesDir}/PDFNetPHP.cpp -oh ${PDFNetPHP_SourcesDir}/PDFNetPHP.hpp PDFNetPHP.i
Expand Down Expand Up @@ -166,15 +179,7 @@ endif()
# - PDFNetPHP.so/.dll
set_property(TARGET PDFNetPHP PROPERTY PREFIX "")

# add namespace
execute_process(
COMMAND php ${CMAKE_SOURCE_DIR}/PDFNetPHP/script.php ${PDFNetPHP_SourcesDir}/PDFNetPHP.php
RESULT_VARIABLE SOURCE_GEN_RESULT
OUTPUT_FILE ${PROJECT_BINARY_DIR}/swig.log
ERROR_FILE ${PROJECT_BINARY_DIR}/swig.err.log
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

if(PHP_TARGET_FILE)
# Copy the bridge file
configure_file(${PDFNetPHP_SourcesDir}/PDFNetPHP.php ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/PDFNetPHP.php COPYONLY)

Expand All @@ -195,6 +200,8 @@ install(
FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/PDFNetPHP_core.php
DESTINATION ${INSTALL_DESTINATION_LIB_DIR}
)
endif(PHP_TARGET_FILE)

install(
TARGETS PDFNetPHP
LIBRARY DESTINATION ${INSTALL_DESTINATION_LIB_DIR}
Expand Down
55 changes: 50 additions & 5 deletions PDFNetPHP/PDFNetPHP.i
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
* SWIG interface file for PHP
*/
%module(directors="1") PDFNetPHP
#if PHP_MAJOR_VERSION > 7
%feature("php:type", "0");
#endif

%rename (OCGConfig) pdftron::PDF::OCG::Config;

%include "PDFNet_StdStringPHP.i"
/**
Expand Down Expand Up @@ -187,6 +192,8 @@
#include "PDF/StructuredOutputModule.h"
#include "PDF/RefreshOptions.h"
#include "PDF/DocumentConversion.h"
#include "PDF/DiffOptions.h"
#include "PDF/TextDiffOptions.h"
#include "PDF/PDFDoc.h"
#include "PDF/Convert.h"
#include "PDF/PDFDocInfo.h"
Expand All @@ -204,7 +211,8 @@
#include "PDF/Stamper.h"
#include "PDF/TextExtractor.h"
#include "PDF/TextSearch.h"

#include "PDF/WebFontDownloader.h"

// header files in /PDFNetC/Headers/SDF
#include "SDF/DictIterator.h"
#include "SDF/NameTree.h"
Expand Down Expand Up @@ -412,7 +420,7 @@ namespace pdftron {
arr_hash = Z_ARRVAL_P(&$input);
array_count = zend_hash_num_elements(arr_hash);

Unicode* $temp = new Unicode[array_count];
pdftron::Unicode* $temp = new pdftron::Unicode[array_count];

for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
(data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL && i < array_count;
Expand All @@ -429,7 +437,7 @@ namespace pdftron {
arr_hash = Z_ARRVAL_PP($input);
array_count = zend_hash_num_elements(arr_hash);

Unicode* $temp = new Unicode[array_count];
pdftron::Unicode* $temp = new pdftron::Unicode[array_count];

for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS && i < array_count;
Expand Down Expand Up @@ -462,7 +470,7 @@ namespace pdftron {
*/
%typemap(freearg) const pdftron::Unicode* text_data
%{
delete[]($1);
if($1){ delete[]($1); $1 = 0; }
%}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -580,7 +588,7 @@ namespace pdftron {

%typemap(freearg) std::vector<double>&
%{
delete ($1);
if($1){ delete($1);$1 = 0;}
%}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -776,6 +784,40 @@ namespace pdftron {
%rename (WriteUInt64) pdftron::Filters::FilterWriter::WriteInt(UInt64);
%rename (IsEqual) operator==;

// rename overridden methods of different signatures from base', which causes fatal errors in PHP8
#if PHP_MAJOR_VERSION > 7
%ignore pdftron::PDF::Annots::Popup::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::FileAttachment::Create(SDF::SDFDoc&, const Rect&, FileSpec);
%ignore pdftron::PDF::Annots::FileAttachment::Create(SDF::SDFDoc&, const Rect&, FileSpec, Icon);
%ignore pdftron::PDF::Annots::FileAttachment::Create(SDF::SDFDoc&, const Rect&, const UString&);
%ignore pdftron::PDF::Annots::FileAttachment::Create(SDF::SDFDoc&, const Rect&, const UString&, Icon);
%ignore pdftron::PDF::Annots::FileAttachment::Create(SDF::SDFDoc&, const Rect&, const UString&, const char*);
%ignore pdftron::PDF::Annots::Ink::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Circle::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::HighlightAnnot::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::LineAnnot::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::FreeText::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Movie::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::RedactionAnnot::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Screen::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Square::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Squiggly::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::StrikeOut::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Underline::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Watermark::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::RubberStamp::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::RubberStamp::Create(SDF::SDFDoc&, const Rect&, Icon);
%ignore pdftron::PDF::Annots::Sound::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Sound::Create(SDF::SDFDoc&, const Rect&, Icon);
%ignore pdftron::PDF::Annots::Sound::Create(SDF::SDFDoc&, const Point&);
%ignore pdftron::PDF::Annots::Sound::Create(SDF::SDFDoc&, const Point&, Icon);
%ignore pdftron::PDF::Annots::Text::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Text::Create(SDF::SDFDoc&, const Rect&, const UString&);
%ignore pdftron::PDF::Annots::Text::Create(SDF::SDFDoc&, const Point&);
%ignore pdftron::PDF::Annots::Text::Create(SDF::SDFDoc&, const Point&, const UString&);
%ignore pdftron::PDF::Annots::Link::Create(SDF::SDFDoc&, const Rect&);
%ignore pdftron::PDF::Annots::Link::Create(SDF::SDFDoc&, const Rect&, const Action&);
#endif
//----------------------------------------------------------------------------------------------
// Fixes the python not recognizing default arguments problem
// Instead of generating overloaded method for default arguments, only a single method
Expand Down Expand Up @@ -888,6 +930,8 @@ namespace pdftron {
%include "PDF/Bookmark.h"
%include "PDF/CharData.h"
%include "PDF/ContentReplacer.h"
%include "PDF/DiffOptions.h"
%include "PDF/TextDiffOptions.h"
%include "PDF/ConversionOptions.h"
%include "PDF/OfficeToPDFOptions.h"
%include "PDF/WordToPDFOptions.h"
Expand Down Expand Up @@ -958,6 +1002,7 @@ namespace pdftron {
%include "PDF/PDFDC.h"
%include "PDF/PDFDCEX.h"
%include "PDF/PDFDraw.h"
%include "PDF/WebFontDownloader.h"

//Extend Initialize method to call overloaded one internally
%extend pdftron::PDFNet{
Expand Down
12 changes: 7 additions & 5 deletions PDFNetPHP/PDFNetPHP.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
if (PHP_MAJOR_VERSION >= 7) {
set_error_handler(function ($errno, $errstr) {
return strpos($errstr, 'Declaration of') === 0;
}, E_WARNING);
if (PHP_MAJOR_VERSION <= 7) {
if (PHP_MAJOR_VERSION == 7){
set_error_handler(function ($errno, $errstr) {
return strpos($errstr, 'Declaration of') === 0;
}, E_WARNING);
}
include ("PDFNetPHP_core.php");
}
include ("PDFNetPHP_core.php");
?>
8 changes: 4 additions & 4 deletions PDFNetPHP/PDFNetUStringPHP.i
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace pdftron {
convert_to_string_ex($input);
char* temp$argnum = Z_STRVAL_PP($input);
#endif
$1 = UString(temp$argnum);
$1 = pdftron::UString(temp$argnum);
}

%typemap(out) UString, const UString
Expand All @@ -40,7 +40,7 @@ namespace pdftron {
}

/**
* Typemap between UString const & and Python string
* Typemap between UString const & and PHP string
*/
%typemap(in) UString const &
{
Expand All @@ -51,7 +51,7 @@ namespace pdftron {
convert_to_string_ex($input);
char* temp$argnum = Z_STRVAL_PP($input);
#endif
$1 = new UString(temp$argnum);
$1 = new pdftron::UString(temp$argnum);
}

/**
Expand All @@ -71,7 +71,7 @@ namespace pdftron {
*/
%typemap(freearg) UString const &
%{
delete($1);
if($1){ delete($1); $1 = 0; }
%}

/**
Expand Down
2 changes: 1 addition & 1 deletion PDFNetPHP/PDFNet_StdStringPHP.i
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@

%typemap(freearg) std::vector<std::string>&
%{
delete ($1);
if($1){ delete($1); $1 = 0; }
%}

13 changes: 0 additions & 13 deletions PDFNetPHP/script.php

This file was deleted.

2 changes: 1 addition & 1 deletion PDFNetPython/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#-----------------------------------------------------------------------------------------------------------------------

project(PDFNetPython CXX)
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)

find_package(PythonLibs)

Expand Down
12 changes: 9 additions & 3 deletions PDFNetPython/PDFNetPython.i
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@
#include "PDF/StructuredOutputModule.h"
#include "PDF/RefreshOptions.h"
#include "PDF/DocumentConversion.h"
#include "PDF/DiffOptions.h"
#include "PDF/TextDiffOptions.h"
#include "PDF/PDFDoc.h"
#include "PDF/Convert.h"
#include "PDF/PDFDocInfo.h"
Expand All @@ -205,6 +207,7 @@
#include "PDF/Stamper.h"
#include "PDF/TextExtractor.h"
#include "PDF/TextSearch.h"
#include "PDF/WebFontDownloader.h"

// header files in /PDFNetC/Headers/SDF
#include "SDF/DictIterator.h"
Expand Down Expand Up @@ -392,7 +395,7 @@ namespace pdftron {
#ifdef PYTHON2
%typemap(in) const pdftron::Unicode* text_data
{
Unicode* $temp = new Unicode[PyList_Size($input)];
pdftron::Unicode* $temp = new pdftron::Unicode[PyList_Size($input)];
int i;

for (i = 0; i < PyList_Size($input); i++) {
Expand Down Expand Up @@ -463,7 +466,7 @@ namespace pdftron {
*/
%typemap(freearg) const pdftron::Unicode* text_data
%{
delete[]($1);
if($1){ delete[]($1); $1 = 0; }
%}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -504,7 +507,7 @@ namespace pdftron {

%typemap(freearg) std::vector<double>&
%{
delete ($1);
if($1){ delete($1);$1 = 0;}
%}

%typemap(typecheck) std::vector<double> {
Expand Down Expand Up @@ -760,6 +763,8 @@ namespace pdftron {
%include "PDF/Bookmark.h"
%include "PDF/CharData.h"
%include "PDF/ContentReplacer.h"
%include "PDF/DiffOptions.h"
%include "PDF/TextDiffOptions.h"
%include "PDF/ConversionOptions.h"
%include "PDF/OfficeToPDFOptions.h"
%include "PDF/WordToPDFOptions.h"
Expand Down Expand Up @@ -830,6 +835,7 @@ namespace pdftron {
%include "PDF/PDFDC.h"
%include "PDF/PDFDCEX.h"
%include "PDF/PDFDraw.h"
%include "PDF/WebFontDownloader.h"

//Extend Initialize method to call overloaded one internally
%extend pdftron::PDFNet{
Expand Down