|
|
|
|
Index: PyMuPDF-1.22.5/setup.py
|
|
|
|
|
--- PyMuPDF-1.22.5/setup.py.orig 2023-06-21 20:22:28.000000000 +0200
|
|
|
|
|
+++ PyMuPDF-1.22.5/setup.py 2023-06-22 09:45:45.630844000 +0200
|
|
|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
|
+
|
|
|
|
|
'''
|
|
|
|
|
Overview:
|
|
|
|
|
|
|
|
|
|
@@ -576,271 +577,6 @@
|
|
|
|
|
# Create local mupdf.tgz, for inclusion in sdist.
|
|
|
|
|
get_mupdf_tgz()
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-if ('-h' not in sys.argv and '--help' not in sys.argv
|
|
|
|
|
- and (0
|
|
|
|
|
- or 'bdist_wheel' in sys.argv
|
|
|
|
|
- or 'build' in sys.argv
|
|
|
|
|
- or 'bdist' in sys.argv
|
|
|
|
|
- or 'install' in sys.argv
|
|
|
|
|
- )
|
|
|
|
|
- ):
|
|
|
|
|
-
|
|
|
|
|
- # Build MuPDF before setuptools runs, so that it can link with the MuPDF
|
|
|
|
|
- # libraries.
|
|
|
|
|
- #
|
|
|
|
|
- mupdf_local = get_mupdf()
|
|
|
|
|
- if mupdf_local:
|
|
|
|
|
- if mupdf_local.endswith( '/'):
|
|
|
|
|
- mupdf_local = mupdf_local[:-1]
|
|
|
|
|
-
|
|
|
|
|
- log( f'mupdf_local={mupdf_local!r}')
|
|
|
|
|
- unix_build_dir = None
|
|
|
|
|
-
|
|
|
|
|
- # Always force clean build of PyMuPDF SWIG files etc, because setuptools
|
|
|
|
|
- # doesn't seem to notice when our mupdf headers etc are newer than the
|
|
|
|
|
- # SWIG-generated files.
|
|
|
|
|
- #
|
|
|
|
|
- remove( os.path.abspath( f'{__file__}/../build/'))
|
|
|
|
|
- remove( os.path.abspath( f'{__file__}/../install/'))
|
|
|
|
|
-
|
|
|
|
|
- if mupdf_local:
|
|
|
|
|
- # Build MuPDF before deferring to setuptools.setup().
|
|
|
|
|
- #
|
|
|
|
|
-
|
|
|
|
|
- log( f'Building mupdf.')
|
|
|
|
|
- # Copy PyMuPDF's config file into mupdf. For example it #define's TOFU,
|
|
|
|
|
- # which excludes various fonts in the MuPDF binaries.
|
|
|
|
|
- if os.environ.get('PYMUPDF_SETUP_MUPDF_OVERWRITE_CONFIG') == '0':
|
|
|
|
|
- # Use MuPDF default config.
|
|
|
|
|
- log( f'Not copying fitz/_config.h to {mupdf_local}/include/mupdf/fitz/config.h.')
|
|
|
|
|
- s = os.stat( f'{mupdf_local}/include/mupdf/fitz/config.h')
|
|
|
|
|
- log( f'{mupdf_local}/include/mupdf/fitz/config.h: {s} mtime={time.strftime("%F-%T", time.gmtime(s.st_mtime))}')
|
|
|
|
|
- else:
|
|
|
|
|
- # Use our special config in MuPDF.
|
|
|
|
|
- log( f'Copying fitz/_config.h to {mupdf_local}/include/mupdf/fitz/config.h')
|
|
|
|
|
- shutil.copy2( 'fitz/_config.h', f'{mupdf_local}/include/mupdf/fitz/config.h')
|
|
|
|
|
-
|
|
|
|
|
- if windows:
|
|
|
|
|
- # Windows build.
|
|
|
|
|
- devenv = os.environ.get('PYMUPDF_SETUP_DEVENV')
|
|
|
|
|
- log( 'PYMUPDF_SETUP_DEVENV={PYMUPDF_SETUP_DEVENV!r}')
|
|
|
|
|
- if not devenv:
|
|
|
|
|
- # Search for devenv in some known locations.
|
|
|
|
|
- devenv = glob.glob('C:/Program Files (x86)/Microsoft Visual Studio/2019/*/Common7/IDE/devenv.com')
|
|
|
|
|
- if devenv:
|
|
|
|
|
- devenv = devenv[0]
|
|
|
|
|
- if not devenv:
|
|
|
|
|
- devenv = 'devenv.com'
|
|
|
|
|
- log( f'Cannot find devenv.com in default locations, using: {devenv!r}')
|
|
|
|
|
- windows_config = 'Win32' if word_size()==32 else 'x64'
|
|
|
|
|
- command = (
|
|
|
|
|
- f'cd {mupdf_local}&&'
|
|
|
|
|
- f'"{devenv}"'
|
|
|
|
|
- f' platform/win32/mupdf.sln'
|
|
|
|
|
- f' /Build "ReleaseTesseract|{windows_config}"'
|
|
|
|
|
- f' /Project mupdf'
|
|
|
|
|
- )
|
|
|
|
|
- else:
|
|
|
|
|
- # Unix build.
|
|
|
|
|
- #
|
|
|
|
|
- flags = 'HAVE_X11=no HAVE_GLFW=no HAVE_GLUT=no HAVE_LEPTONICA=yes HAVE_TESSERACT=yes'
|
|
|
|
|
- flags += ' verbose=yes'
|
|
|
|
|
- env = ''
|
|
|
|
|
- make = 'make'
|
|
|
|
|
- if linux:
|
|
|
|
|
- env += ' CFLAGS="-fPIC"'
|
|
|
|
|
- if openbsd or freebsd:
|
|
|
|
|
- make = 'gmake'
|
|
|
|
|
- env += ' CFLAGS="-fPIC" CXX=clang++'
|
|
|
|
|
-
|
|
|
|
|
- unix_build_type = os.environ.get( 'PYMUPDF_SETUP_MUPDF_BUILD_TYPE', 'release')
|
|
|
|
|
- assert unix_build_type in ('debug', 'memento', 'release')
|
|
|
|
|
- flags += f' build={unix_build_type}'
|
|
|
|
|
-
|
|
|
|
|
- # This is for MacOS cross-compilation, where ARCHFLAGS can be
|
|
|
|
|
- # '-arch arm64'.
|
|
|
|
|
- #
|
|
|
|
|
- archflags = os.environ.get( 'ARCHFLAGS')
|
|
|
|
|
- if archflags:
|
|
|
|
|
- flags += f' XCFLAGS="{archflags}" XLIBS="{archflags}"'
|
|
|
|
|
-
|
|
|
|
|
- # We specify a build directory path containing 'pymupdf' so that we
|
|
|
|
|
- # coexist with non-pymupdf builds (because pymupdf builds have a
|
|
|
|
|
- # different config.h).
|
|
|
|
|
- #
|
|
|
|
|
- # We also append further text to try to allow different builds to
|
|
|
|
|
- # work if they reuse the mupdf directory.
|
|
|
|
|
- #
|
|
|
|
|
- # Using platform.machine() (e.g. 'amd64') ensures that different
|
|
|
|
|
- # builds of mupdf on a shared filesystem can coexist. Using
|
|
|
|
|
- # $_PYTHON_HOST_PLATFORM allows cross-compiled cibuildwheel builds
|
|
|
|
|
- # to coexist, e.g. on github.
|
|
|
|
|
- #
|
|
|
|
|
- build_prefix = f'pymupdf-{platform.machine()}-'
|
|
|
|
|
- build_prefix_extra = os.environ.get( '_PYTHON_HOST_PLATFORM')
|
|
|
|
|
- if build_prefix_extra:
|
|
|
|
|
- build_prefix += f'{build_prefix_extra}-'
|
|
|
|
|
- flags += f' build_prefix={build_prefix}'
|
|
|
|
|
-
|
|
|
|
|
- unix_build_dir = f'{mupdf_local}/build/{build_prefix}{unix_build_type}'
|
|
|
|
|
-
|
|
|
|
|
- if os.environ.get( 'PYMUPDF_SETUP_MUPDF_CLEAN') == '1':
|
|
|
|
|
- # Force clean build.
|
|
|
|
|
- log(f'Removing {unix_build_dir} because PYMUPDF_SETUP_MUPDF_CLEAN=1')
|
|
|
|
|
- assert '/build/' in unix_build_dir
|
|
|
|
|
- remove(unix_build_dir)
|
|
|
|
|
-
|
|
|
|
|
- command = f'cd {mupdf_local} && {env} {make} {flags}'
|
|
|
|
|
- command += f' && echo {unix_build_dir}:'
|
|
|
|
|
- command += f' && ls -l build/{build_prefix}{unix_build_type}'
|
|
|
|
|
-
|
|
|
|
|
- if os.environ.get( 'PYMUPDF_SETUP_MUPDF_REBUILD') == '0':
|
|
|
|
|
- log( f'PYMUPDF_SETUP_MUPDF_REBUILD is "0" so not building MuPDF; would have run: {command}')
|
|
|
|
|
- else:
|
|
|
|
|
- log( f'Building MuPDF by running: {command}')
|
|
|
|
|
- subprocess.run( command, shell=True, check=True)
|
|
|
|
|
- log( f'Finished building mupdf.')
|
|
|
|
|
- else:
|
|
|
|
|
- # Use installed MuPDF.
|
|
|
|
|
- log( f'Using system mupdf.')
|
|
|
|
|
- unix_build_type = ''
|
|
|
|
|
-
|
|
|
|
|
- # Set include and library paths for building PyMuPDF.
|
|
|
|
|
- #
|
|
|
|
|
- # We also add MuPDF's include directory to include path for Swig so that
|
|
|
|
|
- # fitz/fitz.i can do `%include "mupdf/fitz/version.h"` and .i code can use
|
|
|
|
|
- # `#if` with FZ_VERSION_* macros.
|
|
|
|
|
- #
|
|
|
|
|
- if mupdf_local:
|
|
|
|
|
- assert os.path.isdir( mupdf_local), f'Not a directory: {mupdf_local!r}'
|
|
|
|
|
- include_dirs.append( f'{mupdf_local}/include')
|
|
|
|
|
- include_dirs.append( f'{mupdf_local}/include/mupdf')
|
|
|
|
|
- include_dirs.append( f'{mupdf_local}/thirdparty/freetype/include')
|
|
|
|
|
- if unix_build_dir:
|
|
|
|
|
- library_dirs.append( unix_build_dir)
|
|
|
|
|
- extra_swig_args.append(f'-I{mupdf_local}/include')
|
|
|
|
|
-
|
|
|
|
|
- if mupdf_local and (linux or openbsd or freebsd):
|
|
|
|
|
- # setuptools' link command always seems to put '-L
|
|
|
|
|
- # /usr/local/lib' before any <library_dirs> that we specify,
|
|
|
|
|
- # so '-l mupdf -l mupdf-third' will end up using the system
|
|
|
|
|
- # libmupdf.so (if installed) instead of the one we've built in
|
|
|
|
|
- # <mupdf_local>.
|
|
|
|
|
- #
|
|
|
|
|
- # So we force linking with our mupdf libraries by specifying
|
|
|
|
|
- # them in <extra_link_args>.
|
|
|
|
|
- #
|
|
|
|
|
- extra_link_args.append( f'{unix_build_dir}/libmupdf.a')
|
|
|
|
|
- extra_link_args.append( f'{unix_build_dir}/libmupdf-third.a')
|
|
|
|
|
- library_dirs = []
|
|
|
|
|
- libraries = []
|
|
|
|
|
- if openbsd or freebsd:
|
|
|
|
|
- if os.environ.get( 'PYMUPDF_SETUP_MUPDF_BUILD_TYPE') == 'memento':
|
|
|
|
|
- extra_link_args.append( f'-lexecinfo')
|
|
|
|
|
-
|
|
|
|
|
- elif mupdf_local and darwin:
|
|
|
|
|
- library_dirs.append(f'{unix_build_dir}')
|
|
|
|
|
- libraries = [
|
|
|
|
|
- f'mupdf',
|
|
|
|
|
- f'mupdf-third',
|
|
|
|
|
- ]
|
|
|
|
|
-
|
|
|
|
|
- elif linux:
|
|
|
|
|
- # Use system libraries.
|
|
|
|
|
- include_dirs.append( '/usr/include/mupdf')
|
|
|
|
|
- include_dirs.append( '/usr/local/include/mupdf')
|
|
|
|
|
- include_dirs.append( '/usr/include/freetype2')
|
|
|
|
|
- libraries = load_libraries()
|
|
|
|
|
- extra_link_args = []
|
|
|
|
|
- extra_swig_args.append(f'-I/usr/local/include')
|
|
|
|
|
- extra_swig_args.append(f'-I/usr/include')
|
|
|
|
|
-
|
|
|
|
|
- elif darwin or openbsd or freebsd:
|
|
|
|
|
- # Use system libraries.
|
|
|
|
|
- include_dirs.append("/usr/local/include/mupdf")
|
|
|
|
|
- include_dirs.append("/usr/local/include")
|
|
|
|
|
- include_dirs.append("/opt/homebrew/include/mupdf")
|
|
|
|
|
- library_dirs.append("/usr/local/lib")
|
|
|
|
|
- libraries = ["mupdf", "mupdf-third"]
|
|
|
|
|
- library_dirs.append("/opt/homebrew/lib")
|
|
|
|
|
-
|
|
|
|
|
- include_dirs.append("/usr/include/freetype2")
|
|
|
|
|
- include_dirs.append("/usr/local/include/freetype2")
|
|
|
|
|
- include_dirs.append("/usr/X11R6/include/freetype2")
|
|
|
|
|
- include_dirs.append("/opt/homebrew/include")
|
|
|
|
|
- include_dirs.append("/opt/homebrew/include/freetype2")
|
|
|
|
|
-
|
|
|
|
|
- extra_swig_args.append(f'-I/usr/local/include')
|
|
|
|
|
- extra_swig_args.append(f'-I/opt/homebrew/include')
|
|
|
|
|
-
|
|
|
|
|
- library_dirs.append("/opt/homebrew/lib")
|
|
|
|
|
-
|
|
|
|
|
- if freebsd:
|
|
|
|
|
- libraries += [
|
|
|
|
|
- 'freetype',
|
|
|
|
|
- 'harfbuzz',
|
|
|
|
|
- ]
|
|
|
|
|
-
|
|
|
|
|
- elif windows:
|
|
|
|
|
- # Windows.
|
|
|
|
|
- assert mupdf_local
|
|
|
|
|
- if word_size() == 32:
|
|
|
|
|
- library_dirs.append( f'{mupdf_local}/platform/win32/ReleaseTesseract')
|
|
|
|
|
- library_dirs.append( f'{mupdf_local}/platform/win32/Release')
|
|
|
|
|
- else:
|
|
|
|
|
- library_dirs.append( f'{mupdf_local}/platform/win32/x64/ReleaseTesseract')
|
|
|
|
|
- library_dirs.append( f'{mupdf_local}/platform/win32/x64/Release')
|
|
|
|
|
- libraries = [
|
|
|
|
|
- "libmupdf",
|
|
|
|
|
- "libresources",
|
|
|
|
|
- "libthirdparty",
|
|
|
|
|
- ]
|
|
|
|
|
- extra_link_args = ["/NODEFAULTLIB:MSVCRT"]
|
|
|
|
|
-
|
|
|
|
|
- else:
|
|
|
|
|
- assert 0, 'Unrecognised OS'
|
|
|
|
|
-
|
|
|
|
|
- if linux or openbsd or freebsd or darwin:
|
|
|
|
|
- extra_compile_args.append( '-Wno-incompatible-pointer-types')
|
|
|
|
|
- extra_compile_args.append( '-Wno-pointer-sign')
|
|
|
|
|
- extra_compile_args.append( '-Wno-sign-compare')
|
|
|
|
|
- if unix_build_type == 'memento':
|
|
|
|
|
- extra_compile_args.append( '-DMEMENTO')
|
|
|
|
|
- if openbsd:
|
|
|
|
|
- extra_compile_args.append( '-Wno-deprecated-declarations')
|
|
|
|
|
-
|
|
|
|
|
- # add any local include and library folders
|
|
|
|
|
- pymupdf_dirs = os.environ.get("PYMUPDF_DIRS", None)
|
|
|
|
|
- if pymupdf_dirs:
|
|
|
|
|
- with open(pymupdf_dirs) as dirfile:
|
|
|
|
|
- local_dirs = json.load(dirfile)
|
|
|
|
|
- include_dirs += local_dirs.get("include_dirs", [])
|
|
|
|
|
- library_dirs += local_dirs.get("library_dirs", [])
|
|
|
|
|
-
|
|
|
|
|
- with open(f'fitz/helper-git-versions.i', 'w') as f:
|
|
|
|
|
- f.write('%pythoncode %{\n')
|
|
|
|
|
-
|
|
|
|
|
- def repr_escape(text):
|
|
|
|
|
- text = repr(text)
|
|
|
|
|
- text = text.replace('{', '{{')
|
|
|
|
|
- text = text.replace('}', '}}')
|
|
|
|
|
- text = text.replace('%', '{chr(37)})') # Avoid confusing swig.
|
|
|
|
|
- return 'f' + text
|
|
|
|
|
- def write_git(name, directory):
|
|
|
|
|
- sha, comment, diff, branch = get_git_id(directory)
|
|
|
|
|
- f.write(f'{name}_git_sha = \'{sha}\'\n')
|
|
|
|
|
- f.write(f'{name}_git_comment = {repr_escape(comment)}\n')
|
|
|
|
|
- f.write(f'{name}_git_diff = {repr_escape(diff)}\n')
|
|
|
|
|
- f.write(f'{name}_git_branch = {repr_escape(branch)}\n')
|
|
|
|
|
- f.write('\n')
|
|
|
|
|
-
|
|
|
|
|
- write_git('pymupdf', '.')
|
|
|
|
|
- if mupdf_local:
|
|
|
|
|
- write_git('mupdf', mupdf_local)
|
|
|
|
|
-
|
|
|
|
|
- f.write('%}\n')
|
|
|
|
|
-
|
|
|
|
|
# Disable bogus SWIG warning 509, 'Overloaded method ... effectively ignored,
|
|
|
|
|
# as it is shadowed by ...'.
|
|
|
|
|
extra_swig_args.append( '-w509')
|
|
|
|
|
@@ -856,9 +592,9 @@
|
|
|
|
|
"fitz._fitz",
|
|
|
|
|
["fitz/fitz.i"],
|
|
|
|
|
language="c++",
|
|
|
|
|
- include_dirs=include_dirs,
|
|
|
|
|
- library_dirs=library_dirs,
|
|
|
|
|
- libraries=libraries,
|
|
|
|
|
+ include_dirs=[ "@l_prefix@/include/mupdf", "@l_prefix@/include/freetype", "@l_prefix@/include", ],
|
|
|
|
|
+ library_dirs=[ "@l_prefix@/lib/", ],
|
|
|
|
|
+ libraries=[ "mupdf", "mupdf-third", ],
|
|
|
|
|
extra_compile_args=extra_compile_args,
|
|
|
|
|
extra_link_args=extra_link_args,
|
|
|
|
|
swig_opts=extra_swig_args,
|
|
|
|
|
Index: pdfrw-0.4/pdfrw/crypt.py
|
|
|
|
|
--- pdfrw-0.4/pdfrw/crypt.py.orig 2017-09-14 15:27:27.000000000 +0200
|
|
|
|
|
+++ pdfrw-0.4/pdfrw/crypt.py 2023-06-22 09:45:15.362164000 +0200
|
|
|
|
|
@@ -7,11 +7,7 @@
|
|
|
|
|
import hashlib
|
|
|
|
|
import struct
|
|
|
|
|
|
|
|
|
|
-try:
|
|
|
|
|
- from Crypto.Cipher import ARC4, AES
|
|
|
|
|
- HAS_CRYPTO = True
|
|
|
|
|
-except ImportError:
|
|
|
|
|
- HAS_CRYPTO = False
|
|
|
|
|
+HAS_CRYPTO = False
|
|
|
|
|
|
|
|
|
|
from .objects import PdfDict, PdfName
|
|
|
|
|
|