mupdf.git
2 years agoinclude/mupdf/fitz/version.h: increment version to 1.21.2. 1.21.x
Julian Smith [Fri, 27 Jan 2023 12:30:24 +0000 (12:30 +0000)]
include/mupdf/fitz/version.h: increment version to 1.21.2.

2 years agoBug 706147: Fix text positioning error in filter processor.
Robin Watts [Wed, 11 Jan 2023 19:13:34 +0000 (19:13 +0000)]
Bug 706147: Fix text positioning error in filter processor.

When filtering, we were failing to reset the stored pending Td
values when we hit a BT. This meant that when we elide a Td
(perhaps due to redaction), we'd incorrectly add the stored
offset onto the next one.

2 years agodocs/bindings.rst: Updated changelog.
Julian Smith [Sun, 15 Jan 2023 12:58:13 +0000 (12:58 +0000)]
docs/bindings.rst: Updated changelog.

2 years agoscripts/wrap/: Python Story support, fixes for Windows.
Julian Smith [Fri, 13 Jan 2023 13:16:03 +0000 (13:16 +0000)]
scripts/wrap/: Python Story support, fixes for Windows.

Added Python Story support.

scripts/wrap/cpp.py:
    Output C++ header comment when class-aware fn not available because
    returned value is non-copyable.

    Show warnings if env settings will be ignored - e.g. release builds will
    now output a diagnostic to std::cerr if environment variables such as
    MUPDF_trace are set, because they are ignored in release builds.

scripts/wrap/swig.py:
    Don't disable SWIG Directors on windows; they seem to work fine. This
    allows Python callbacks to work, e.g. for devices implemented in Python.

    Also monkey-patch FzDocumentWriter.__init__() to keep any FZOutput2 args
    alive for the lifetime of the FzDocumentWriter; otherwise SEGV can occur if
    C++ attempts to call the FZOutput2's Python derived methods.

scripts/wrap/__main__.py:
    Preliminary support for debug builds on windows.

    Added --refcheck-if; allows release builds to include refcount-checking
    code. E.g. useful on Windows where debug builds do not quite work.

2 years agosetup.py: reduce size of sdist.
Julian Smith [Thu, 12 Jan 2023 11:45:42 +0000 (11:45 +0000)]
setup.py: reduce size of sdist.

We remove some large test directories in thirdparty/. Reduces sdist from 127M
to 79M.

2 years agoscripts/wrap/: fixes for windows python builds.
Julian Smith [Mon, 2 Jan 2023 23:52:09 +0000 (23:52 +0000)]
scripts/wrap/: fixes for windows python builds.

scripts/wrap/cpp.py
    Added FZ_FUNCTION to some generated functions.

scripts/wrap/state.py
scripts/wrap/swig.py
    Don't exclude fz_arc4_final.

    Exclude a small number of windows-only fns that break sdist => wheel
    builds. Sdists contain C++ code generated with clang on Unix, which will
    exclude fns inside #ifdef _WIN32...#endif. But when using an sdist to
    build a wheel on Windows, SWIG will see these functions when it parses the
    MuPDF headers, so will generate code that attempts to call the omitted
    functions. The solution here is to simply exclude these functions from the
    C++ and Python APIs.

scripts/wrap/__main__.py
    Fixed bug in build() introduced when moving code into new _get_m_command()
    fn.

scripts/wrap/__main__.py
    Use sysconfig.get_path('include') to find include path for Python.h.

    Cleaned up code that finds a matching python on Windows.

scripts/jlib.py:
    Added fs_find_in_paths() to allow looking up executable in $PATH.

    log_text(): added `nl` arg, to control whether we append newline.

scripts/pipcl.py:
    build_wheel(): show os.environ; useful for debugging.

2 years agopyproject.toml: added requirements 'libclang' and 'swig'.
Julian Smith [Mon, 9 Jan 2023 23:13:42 +0000 (23:13 +0000)]
pyproject.toml: added requirements 'libclang' and 'swig'.

This simplifies building Python bindings - no need for manual installation of
clang and swig when building Python bindings via setup.py.

This will remove the need in the future for sdists to contain output from
clang-python with `scripts/mupdfwrap.py -b 12`, which will make building
simpler, e.g. no confusion about different interpretation of size_t on
different platforms.

2 years agodocs/bindings.rst: added information about windows specifics - FZ_FUNCTION etc.
Julian Smith [Mon, 2 Jan 2023 23:23:51 +0000 (23:23 +0000)]
docs/bindings.rst: added information about windows specifics - FZ_FUNCTION etc.

2 years agoUpdate Version numbers for 1.21.1 source release. 1.21.1
Robin Watts [Mon, 12 Dec 2022 14:52:08 +0000 (14:52 +0000)]
Update Version numbers for 1.21.1 source release.

2 years agoBug 706090: Fix calculation of invalid Type3 font bbox.
Tor Andersson [Wed, 7 Dec 2022 13:23:37 +0000 (14:23 +0100)]
Bug 706090: Fix calculation of invalid Type3 font bbox.

Only take into account glyphs that have a definition.

2 years agodocs/bindings.rst: minor update to description of environmental variable MUPDF_mt_ctx.
Julian Smith [Thu, 17 Nov 2022 19:26:07 +0000 (19:26 +0000)]
docs/bindings.rst: minor update to description of environmental variable MUPDF_mt_ctx.

Also mention mupdf::reinit_singlethreaded().

2 years agoscripts/wrap/: various improvements to C++ and Python bindings.
Julian Smith [Wed, 23 Nov 2022 13:19:11 +0000 (13:19 +0000)]
scripts/wrap/: various improvements to C++ and Python bindings.

scripts/wrap/__main__.py

    Added support for -fPIC .a builds. Building in build/fpic-* will generate
    .a files containing code built with -fPIC, which can then be used to make
    .so's.

    Simplified running of tests after improved rpath link args - with improved
    rpath args, we don't need to specify LD_LIBRARY_PATH on Linux or OpenBSD.

    Allow misc prefixes in build directory; useful for PyMuPDF.

scripts/wrap/classes.py

    Added accessors to fz_text_span wrapper class. This simplifies use from
    Python, e.g. returning class wrappers for .font and .trm members, and
    giving access to the .items[] array.

scripts/wrap/cpp.py

    Improved single-threaded behaviour.

    If MUPDF_mt_ctx is '0', we now call fz_new_context() with locks=null,
    so MuPDF will never use the C++ wrappers' mutexes. This gives a small
    performance increase.

    Added reinit_singlethreaded() as alternative to setting MUPDF_mt_ctx=0.

scripts/wrap/swig.py

    Disabled a build optimisation which caused unnecessary rebuilds.

    Removed unnecessary OpenBSD-specific python prefix. With improved rpath arg
    when linking _mupdf.so, we don't need to do anything special to allow it to
    load with LD_LIBRARY_PATH.

    Fixed python wrappers for fz_set_warning_callback() and
    fz_set_error_callback() - SWIG Python renames print() to _print().

    Fixed incorrect custom implementation of ll_pdf_set_annot_color().

    Fixed naming of Python fz_pixmap_samples2() memoryview fn.

2 years agoscripts/jlib.py: improved link_l_flags() and expand_nv().
Julian Smith [Wed, 23 Nov 2022 13:18:39 +0000 (13:18 +0000)]
scripts/jlib.py: improved link_l_flags() and expand_nv().

link_l_flags(): work with .a files and improved setting of rpath. We now also
specify `-Wl,-z,origin` as well as `-Wl,-rpath='$ORIGIN'`. The former appears
to be necessary on OpenBSD and harmless on Linux.

expand_nv(): added PEP-501 compatibility.

2 years agothirdparty/extract: minor update to submodule version, fixes build warning.
Julian Smith [Tue, 15 Nov 2022 14:40:26 +0000 (14:40 +0000)]
thirdparty/extract: minor update to submodule version, fixes build warning.

2 years agoBug 706093: Don't layout empty documents!
Tor Andersson [Tue, 22 Nov 2022 12:44:27 +0000 (13:44 +0100)]
Bug 706093: Don't layout empty documents!

2 years agoFix pdf_objcmp assuming that all dicts were sorted.
Robin Watts [Tue, 22 Nov 2022 19:41:45 +0000 (19:41 +0000)]
Fix pdf_objcmp assuming that all dicts were sorted.

2 years agoBug 706094: Fix mutool clean garbage collection.
Robin Watts [Tue, 22 Nov 2022 19:36:08 +0000 (19:36 +0000)]
Bug 706094: Fix mutool clean garbage collection.

A while ago, we spotted that pdf_objcmp was comparing any 2 stream
objects as being identical if the dict portions matched, without
considering any differences in the stream sections.

We didn't want to take the hit of having pdf_objcmp compare stream
contents, so we modified the code so that any stream objects would
always differ.

Unfortunately, mutool clean was relying on stream dicts being matched
so it could do its own comparison of the stream contents. This meant
that mutool clean with garbage >= 4 was failing to properly common up
repeated streams.

To solve that here, we have introduced a new pdf_objcmp_deep that
performs as pdf_objcmp does, but also checks the stream contents.
We make mutool clean (actually removeduplicateobjs in pdf-write.c)
call that, and correct operation is restored.

2 years agoUpdate MuJS to include fix for bug 706057. 1.21.0
Tor Andersson [Mon, 7 Nov 2022 12:48:18 +0000 (13:48 +0100)]
Update MuJS to include fix for bug 706057.

2 years agoBug 705883: Fix overflows in PNG dimension expressions.
Sebastian Rasmussen [Mon, 31 Oct 2022 23:08:18 +0000 (00:08 +0100)]
Bug 705883: Fix overflows in PNG dimension expressions.

MuPDF accidentally truncated the image size when allocating, but
not when processing the image samples, leading to out of bounds
accesses.

2 years agoFix compression bomb detection; incorrect worst case calculation.
Robin Watts [Mon, 31 Oct 2022 18:19:28 +0000 (18:19 +0000)]
Fix compression bomb detection; incorrect worst case calculation.

2 years agoSupport libressl 3.6.x
orbea [Fri, 7 Oct 2022 10:33:15 +0000 (03:33 -0700)]
Support libressl 3.6.x

2 years agoAdd href to fz_story_positions callback info. 1.21.0-rc1
Robin Watts [Tue, 25 Oct 2022 15:27:48 +0000 (16:27 +0100)]
Add href to fz_story_positions callback info.

2 years agowasm: Fix single-threaded demo.
Tor Andersson [Wed, 12 Oct 2022 11:16:06 +0000 (13:16 +0200)]
wasm: Fix single-threaded demo.

2 years agoSupport deprecated <a name="foo"> link targets.
Tor Andersson [Tue, 25 Oct 2022 11:33:49 +0000 (13:33 +0200)]
Support deprecated <a name="foo"> link targets.

Link targets use "id" attribute on any element, but older HTML versions
used "name" attribute on empty "a" tags.

2 years agoUpdate CHANGES and bump version number.
Tor Andersson [Mon, 24 Oct 2022 13:03:25 +0000 (15:03 +0200)]
Update CHANGES and bump version number.

# Conflicts:
# CHANGES

2 years agoUpdate MuJS submodule to 1.3.1.
Tor Andersson [Thu, 20 Oct 2022 11:04:38 +0000 (13:04 +0200)]
Update MuJS submodule to 1.3.1.

2 years agodocs/bindings.rst: minor change to changelog.
Julian Smith [Fri, 21 Oct 2022 12:18:58 +0000 (13:18 +0100)]
docs/bindings.rst: minor change to changelog.

2 years agoCHANGES: added info on C++/Python/C# bindings.
Julian Smith [Fri, 21 Oct 2022 12:01:23 +0000 (13:01 +0100)]
CHANGES: added info on C++/Python/C# bindings.

2 years agoUpdate lcms2mt with lcms2 2.14 changes.
Robin Watts [Mon, 17 Oct 2022 14:28:30 +0000 (15:28 +0100)]
Update lcms2mt with lcms2 2.14 changes.

2 years agoandroid: Remove java object references to dropped resources.
Sebastian Rasmussen [Wed, 19 Oct 2022 21:45:49 +0000 (23:45 +0200)]
android: Remove java object references to dropped resources.

Without this patch these stale pointers will be queried and
dropped/freed in NativeDevice.finalize(), which may lead to
segfaults.

2 years agoUpdate thirdparty version in documentation.
Sebastian Rasmussen [Wed, 19 Oct 2022 20:45:58 +0000 (22:45 +0200)]
Update thirdparty version in documentation.

2 years agoAdd missing openjpeg file to VS project.
Robin Watts [Mon, 17 Oct 2022 18:36:13 +0000 (19:36 +0100)]
Add missing openjpeg file to VS project.

2 years agoUpdate to zlib 1.2.13.
Sebastian Rasmussen [Tue, 18 Oct 2022 10:46:53 +0000 (12:46 +0200)]
Update to zlib 1.2.13.

2 years agoUpdate to libjpeg v9e.
Sebastian Rasmussen [Thu, 13 Oct 2022 15:13:24 +0000 (17:13 +0200)]
Update to libjpeg v9e.

2 years agoTry harder to shut up Harfbuzz warning spam.
Tor Andersson [Thu, 13 Oct 2022 10:21:08 +0000 (12:21 +0200)]
Try harder to shut up Harfbuzz warning spam.

2 years agosource/fitz/output-pdfocr.c: added assert for no division-by-zero.
Julian Smith [Sat, 15 Oct 2022 10:09:06 +0000 (11:09 +0100)]
source/fitz/output-pdfocr.c: added assert for no division-by-zero.

2 years agoMakelists: removed incorrect thirdparty/harfbuzz/src/graph/test-classdef-graph.cc.
Julian Smith [Mon, 17 Oct 2022 10:55:56 +0000 (11:55 +0100)]
Makelists: removed incorrect thirdparty/harfbuzz/src/graph/test-classdef-graph.cc.

2 years agoMakefile: Use filter-out to remove TOFU'd font files.
Tor Andersson [Fri, 14 Oct 2022 11:21:18 +0000 (13:21 +0200)]
Makefile: Use filter-out to remove TOFU'd font files.

In case the TOFU is set in config.h rather than via XCFLAGS, build the
font files and rely on the linker to exclude them.

2 years agoForward trylater exceptions from system font loading callbacks.
Tor Andersson [Thu, 13 Oct 2022 10:55:16 +0000 (12:55 +0200)]
Forward trylater exceptions from system font loading callbacks.

2 years agoUse "None" prediction filter for PNG output.
Tor Andersson [Wed, 12 Oct 2022 18:20:27 +0000 (20:20 +0200)]
Use "None" prediction filter for PNG output.

This results in significantly smaller files for typical text pages.

2 years agoscripts/mutool_draw.py: fixed incorrect name that was breaking mudrawpy test.
Julian Smith [Fri, 14 Oct 2022 21:43:58 +0000 (22:43 +0100)]
scripts/mutool_draw.py: fixed incorrect name that was breaking mudrawpy test.

Changed last remaining occurence of mupdf.Output to mupdf.FzOutput.

2 years agoscripts/wrap/cpp.py: minor typo in generated diagnostic.
Julian Smith [Wed, 12 Oct 2022 14:04:16 +0000 (15:04 +0100)]
scripts/wrap/cpp.py: minor typo in generated diagnostic.

2 years agoMakelists: add missing thirdparty/harfbuzz/src/graph/*.cc files.
Julian Smith [Fri, 14 Oct 2022 17:21:44 +0000 (18:21 +0100)]
Makelists: add missing thirdparty/harfbuzz/src/graph/*.cc files.

When these source files were missing, we get missing symbols, and this ends up
being an error in shared builds because the missing symbols are declared with:

    #define HB_INTERNAL __attribute__((__visibility__("hidden")))

2 years agoFix VS project file openjpeg source file references.
Sebastian Rasmussen [Fri, 14 Oct 2022 18:25:09 +0000 (20:25 +0200)]
Fix VS project file openjpeg source file references.

2 years agoFix VS project file harfbuzz source file references.
Sebastian Rasmussen [Fri, 14 Oct 2022 18:02:57 +0000 (20:02 +0200)]
Fix VS project file harfbuzz source file references.

2 years agoSanity check header dimensions/setup in band writer code.
Robin Watts [Fri, 14 Oct 2022 16:02:12 +0000 (17:02 +0100)]
Sanity check header dimensions/setup in band writer code.

This should fix PyMuPDF issue 1965.

2 years agoUpdate to OpenJPEG 2.5.0.
Sebastian Rasmussen [Fri, 14 Oct 2022 15:18:36 +0000 (17:18 +0200)]
Update to OpenJPEG 2.5.0.

2 years agoUpdate to Harfbuzz 5.3.0.
Sebastian Rasmussen [Thu, 13 Oct 2022 18:07:34 +0000 (20:07 +0200)]
Update to Harfbuzz 5.3.0.

2 years agoUpdate freetype to version 2.12.1.
Sebastian Rasmussen [Thu, 13 Oct 2022 14:15:35 +0000 (16:15 +0200)]
Update freetype to version 2.12.1.

2 years agoCheck for pdf before assuming that document has js support.
Sebastian Rasmussen [Thu, 13 Oct 2022 09:00:44 +0000 (11:00 +0200)]
Check for pdf before assuming that document has js support.

2 years agoSearch for non-language specific fonts even if language is specified.
Tor Andersson [Wed, 12 Oct 2022 11:17:31 +0000 (13:17 +0200)]
Search for non-language specific fonts even if language is specified.

2 years agoMirror TOFU ifdefs in Makefile.
Tor Andersson [Tue, 27 Sep 2022 12:13:27 +0000 (14:13 +0200)]
Mirror TOFU ifdefs in Makefile.

Avoid building and including object files for fonts that are not used.

Add tofu_cjk_ext and tofu_cjk_lang makefile configuration variables.

Fix build_suffix concatenation without adding spaces (like += does).

2 years agoOops! Move #endif so that TOFU doesn't imply TOFU_CJK!
Tor Andersson [Wed, 12 Oct 2022 11:15:38 +0000 (13:15 +0200)]
Oops! Move #endif so that TOFU doesn't imply TOFU_CJK!

2 years agoBug 705901: Remove questionable code...
Tor Andersson [Fri, 23 Sep 2022 14:45:37 +0000 (16:45 +0200)]
Bug 705901: Remove questionable code...

2 years agoBug 705680: Fix resource dictionary cycle detection.
Sebastian Rasmussen [Tue, 11 Oct 2022 15:14:11 +0000 (17:14 +0200)]
Bug 705680: Fix resource dictionary cycle detection.

2 years agoBug 704718: Throw exception upon negative/zero page dimensions.
Sebastian Rasmussen [Tue, 11 Oct 2022 11:36:39 +0000 (13:36 +0200)]
Bug 704718: Throw exception upon negative/zero page dimensions.

2 years agoRemove redundant comment that has already been implemented.
Sebastian Rasmussen [Mon, 10 Oct 2022 17:33:03 +0000 (19:33 +0200)]
Remove redundant comment that has already been implemented.

2 years agoBug 704832: Do not cast coordinate to int prematurely.
Sebastian Rasmussen [Mon, 10 Oct 2022 18:39:45 +0000 (20:39 +0200)]
Bug 704832: Do not cast coordinate to int prematurely.

There is a check in place to clamp the value to safe int values,
but the coordinates were cast to int causing overflow/underflow
prematurely.

2 years agoBug 704582: Avoid SEGV in filter code.
Robin Watts [Mon, 10 Oct 2022 17:55:03 +0000 (18:55 +0100)]
Bug 704582: Avoid SEGV in filter code.

We were neglecting to make the fontdesc current, which lead
to a NULL dereference in adjust_text.

2 years agomuraster: Fix printing of default values.
Sebastian Rasmussen [Mon, 10 Oct 2022 16:51:11 +0000 (18:51 +0200)]
muraster: Fix printing of default values.

2 years agoBug 704833: Fix div by zero when resolution is set to zero.
Sebastian Rasmussen [Mon, 10 Oct 2022 16:39:18 +0000 (18:39 +0200)]
Bug 704833: Fix div by zero when resolution is set to zero.

Take the opportunity to handle negative resolutions the same way.

2 years agoAdd bit writing functions.
Robin Watts [Wed, 28 Sep 2022 16:30:49 +0000 (17:30 +0100)]
Add bit writing functions.

Writing bits to fz_output streams mirrors reading bits from
fz_streams.

2 years agoImprove handling of [/Pattern] cs.
Robin Watts [Mon, 3 Oct 2022 16:21:33 +0000 (17:21 +0100)]
Improve handling of [/Pattern] cs.

Treat "[/Pattern] cs" as being /Pattern cs. They do the same, so
send them both as the same simplified form. This helps reduce
complexity in the filters.

2 years agoFix omission in shading handling.
Robin Watts [Mon, 3 Oct 2022 12:14:16 +0000 (13:14 +0100)]
Fix omission in shading handling.

Function-based shadings can either have 1 "2-in, n-out" function,
or they can have n "2-in, 1-out" function. We were not coping
with this latter case. Fixed here.

2 years agoImproved the use of Memento with C++.
Julian Smith [Tue, 4 Oct 2022 12:19:26 +0000 (13:19 +0100)]
Improved the use of Memento with C++.

We expose a new C API Memento_cpp_new(), Memento_delete() etc,
that is always built. This API needs to be called by operator
new/delete/new[]/delete[] etc. There are various ways this
can happen.

If memento.c is built with a C compiler, no global new/delete
operators are provided.

If memento.c is built with a C++ compiler, and MEMENTO_NO_CPLUSPLUS
is not defined global new/delete operators are provided.

If memento.h is included by a C++ file, and MEMENTO_NO_CPLUSPLUS
is not defined the library user must provide their own.

This can be done by copying a bunch of lines from memento.c into
a C++ file in the project, or by #including memento.c, with
MEMENTO_CPP_EXTRAS_ONLY defined.

Work around problems with C++ on Linux; if MEMENTO is defined we #include
<string.h> early on in memento.h to avoid an obscure conflict with strdup()
having a `throw()` attribute, unlike Memento_strdup().

Git may get the attribution wrong here; the original work was from
Julian Smith, reworked by Robin Watts. Credit to Julian, blame to Robin.

2 years agoscripts/jlib.py: find_in_paths(): handle names that contain '/'.
Julian Smith [Mon, 19 Sep 2022 11:37:20 +0000 (12:37 +0100)]
scripts/jlib.py: find_in_paths(): handle names that contain '/'.

2 years agosource/fitz/memento.c: Added verbose control.
Julian Smith [Tue, 27 Sep 2022 13:55:30 +0000 (14:55 +0100)]
source/fitz/memento.c: Added verbose control.

Omit detailed diagnostics if environmental variable MEMENTO_VERBOSE is '0';
useful when there are many leaked blocks, provides similar runtime equivalent
to build-time MEMENTO_DETAILS. Also controllable with new Memento_setVerbose()
function.

For clarity, explicitly show zero leaked blocks if no leaks.

showInfo(): show "Known Leak" like showBlock().

2 years agodocs/bindings.rst: various updates and improvements.
Julian Smith [Mon, 19 Sep 2022 14:45:40 +0000 (15:45 +0100)]
docs/bindings.rst: various updates and improvements.

Improved description of C++ API.

Improved description of env vars and include info about new MUPDF_mt_ctx.

Added Limitations section, describing that global class-wrapper instances are
not supported.

Fixed various issues with code blocks.

2 years agoinclude/: document return of kept references from fns with non-standard names.
Julian Smith [Wed, 28 Sep 2022 16:19:42 +0000 (17:19 +0100)]
include/: document return of kept references from fns with non-standard names.

These functions return kept references but their names do not contain any of
the usual terms such as '_add_' or '_new_':

    pdf_page_write()
    fz_decomp_image_from_stream()
    fz_get_pixmap_from_image()

fz_get_pixmap_from_image() internally calls a fz_image_get_pixmap_fn() which is
documented as returning a reference that the caller owns.

2 years agoscripts/wrap/: various improvements to C++/Python bindings.
Julian Smith [Fri, 9 Sep 2022 12:28:11 +0000 (13:28 +0100)]
scripts/wrap/: various improvements to C++/Python bindings.

scripts/wrap/cpp.py:
    Don't use fz_try()/fz_catch() when wrapping functions without ctx arg. They
    cannot throw MuPDF exceptions, so there's no point having code to convert
    to C++ exceptions. This might give a small speed improvement.

    Don't use fz_var() for `ctx` or `ret` variables, as unnecessary.

    Mark class-aware wrapper args with const, to enable use with temporaries.

    Added C++ class-aware out-param fns (we used to only low-level out-param
    methods, and created class-aware versions in Python SWIG, which was
    clumsy).

    Generate operator== and operator!= for pod structs and class wrappers.
    Also added operator== and != as class methods to allow SWIG to generate
    Python __eq__() etc.

    Put generated operator<< and operator== etc into top-level namespace.

    Mention 'low-level'/'class-aware' terms in function/method docs.

    Use '::' prefix when mentioning underlying MuPDF fns in comments.

    Disabled some diagnostics.

    Added comments to generated `#if 0 ...` blocks.

    Improved how we determine whether C fns returns kept or borrowed
    references:

        New fn function_name_implies_kept_references().

        Added 'add', 'parse', 'graft', 'copy', 'deep_copy' to list of fn names
        infixes that indicate returned references are kept (e.g. fixes a leak
        in pdf_add_*() wrappers).

        Added specific exceptions - pdf_page_write(),
        fz_decomp_image_from_stream() and fz_get_pixmap_from_image() all return
        kept references despite their names not having any useful keyword such
        as 'new'.

    Fixed ref-counting in wrappers for fns with out-params.

        Previously we never kept the return value and always kept the
        out-params.

        We now use function_name_implies_kept_references() to decide whether to
        keep the underlying fn's return and out-params.

    Attempt to output diagnostic if `thread_local` ctx code is called too late,
    typically because of the use of a global class-wrapper instance, which is
    not supported.

        C++ mandates that thread_local objects are destroyed before global
        objects. This means that we cannot support global instances of
        MuPDF wrapper classes, because their destructors will call our
        fz_drop() wrappers which end up trying to use our (already destroyed)
        thread_local objects in order to get a fz_context*.

        This diagnostic is best-effort only - by the time it is generated, we
        are already in undefined behaviour.

    Added some disabled experimental code options.

        In make_fncall(), setting use_fz_try=False removes all conversion of
        MuPDF exceptions to C++ exceptions. Gives a small increase in speed
        but is obviously unsafe.

        In make_internal_functions(), added disabled code to register operator
        new/delete with Memento. Not particularly useful because our generated
        code doesn't use operator new.

    Optional global fz_context* for all threads.

        Setting MUPDF_mt_ctx=0 forces the use of a single fz_context* for all
        threads. This is unsafe for multi-threaded programmes, but might give a
        small performance increase.

        New generated function mupdf::mt_ctx() allows control of this at
        runtime.

Misc:

    Added default constructors for wrappers for fz_point and fz_rect, so that
    SWIG-generated code works for fns that return instances by value.

    Added custom C++ wrappers for pdf_dict_getl() that SWIG can handle.

    New -b option: --clang-verbose shows extra diagnostics when looking for
    libclang.so.

    Minor change to generated docs' index.html.

    Improved wrapping of fz_document_handler fnptrs; fz_document_handler
    wrappers are now in the C++ API, instead of being only available to SWIG
    bindings, and all fz_document_handler fnptrs are wrapped now.

    Allow default construction of fz_document.

    Improved wrappers for pdf_field_name(); pdf_field_name() returns char*
    buffer that must be freed by caller. So added new fns to C++ API which
    returns std::string:

        mupdf::ll_pdf_field_name2()
        mupdf::pdf_field_name2()
        mupdf::PdfObj::pdf_field_name2()

    Also modified Python API to make all original variants call
    pdf_field_name2() which makes it impossible to leak via pdf_field_name().

scripts/wrap/swig.py:
    Improved handling of raw memory - added python_buffer_to_memoryview() etc
    to give no-copy access to fz_buffer data.

    Fixed disabling of selected swig warnings - need to not use `swig -Wall`
    because it overrides all warning filters.

    Disabled debug diagnostic.

scripts/wrap/classes.py:
    Allow default-constuction of fz_link wrapper class.

scripts/wrap/parse.py:
    Removed debug diagnostic.

2 years agoSplit error message in fz_open_document_with_stream
Olivier FAURE [Tue, 4 Oct 2022 10:09:05 +0000 (12:09 +0200)]
Split error message in fz_open_document_with_stream

Throw a different error message for 'magic == NULL' and 'stream == NULL'

2 years agoUpdate pdf filter processor to better handle Td.
Robin Watts [Thu, 8 Sep 2022 12:09:11 +0000 (13:09 +0100)]
Update pdf filter processor to better handle Td.

Previously we were rewriting every Td as a Tm. Now preserve
them as Td. We *could* maybe do better than this and rewrite
some Tm's as Td's, but that's harder than you'd think.

2 years agoCorrect documentation of pdf_insert_page.
Robin Watts [Wed, 28 Sep 2022 15:57:47 +0000 (16:57 +0100)]
Correct documentation of pdf_insert_page.

2 years agoKeep reference counts correct on error with pdf_delete_annot.
Robin Watts [Wed, 28 Sep 2022 15:51:55 +0000 (16:51 +0100)]
Keep reference counts correct on error with pdf_delete_annot.

2 years agoWhen comparing objects, beware streams with matching dicts.
Robin Watts [Tue, 27 Sep 2022 17:31:04 +0000 (18:31 +0100)]
When comparing objects, beware streams with matching dicts.

It's not enough for 2 streams to have matching dicts, as the stream
contents might differ. Accordingly, when comparing dicts, check to
see if either is a stream. If it is, they can't match.

2 years agoAdd some more names to the name table.
Robin Watts [Tue, 20 Sep 2022 18:15:02 +0000 (19:15 +0100)]
Add some more names to the name table.

These are all things mentioned in the spec that I've needed for
customer projects.

2 years agoBug 705770: Improve redaction handling of clipping text.
Robin Watts [Thu, 8 Sep 2022 18:10:49 +0000 (19:10 +0100)]
Bug 705770: Improve redaction handling of clipping text.

If a text rendering mode with bit 2 is set, then the idea is that
the union of the text in the text object is intersected with the
existing clip path.

If we redact all the text, then we really want the clip path to be
left as being empty.

Unfortunately, the special case of the BT/ET being empty is resolved
(according to the spec) as being 'no change to the clippath', so
we need to spot this case and handle it differently.

We can't even replace the BT/ET with something like:

 0 0 0 0 re W n

as that will corrupt any path currently being generated.

So, instead, we handle the 'empty_clip_path' as being a state that
we recognise in the gstate in the filter, and simply don't forward
any calls once we reach that state.

To recognise reaching that state we have to spot a) whether we've
sent any marking characters within a BT/ET, and b) whether we've
removed any. If we reach the ET and we've removed some, and not
sent some, we know that we should now have an 'empty_clip_path'.

The nasty bit here is that we need to know if characters are
marking or not. Currently, the code assumes that space (cid 32)
is non-marking, and all others are marking.

2 years agoTweak flushing of text operations in filter code.
Robin Watts [Wed, 7 Sep 2022 15:19:34 +0000 (16:19 +0100)]
Tweak flushing of text operations in filter code.

Only output font changes etc if we are in a text object. This
avoids us eliding a BT/ET entirely and still outputting font
changes etc. This way such changes should be held over for the
next BT.

This was found during investigation for bug 705770; it does NOT
solve the bug, but tidies up the output in question.

2 years agoBug 705880: Limit binary search to bounds of predefines color list.
Sebastian Rasmussen [Sun, 18 Sep 2022 16:03:28 +0000 (18:03 +0200)]
Bug 705880: Limit binary search to bounds of predefines color list.

Previously the end of the list was one element too large causing
segmentation faults.

2 years agoBug 705738: Remove action/field references to removed pages.
Sebastian Rasmussen [Fri, 16 Sep 2022 19:55:07 +0000 (21:55 +0200)]
Bug 705738: Remove action/field references to removed pages.

Previously when cleaning a file mutool would not ascend the hiearchy
for fields to remove references to removed pages from non-terminal
fields. When later marking and sweeping objects starting from the
trailer the non-terminal fields still referenced removed page
objects. Therefore those page objects and all their resources were
retained in the cleaned PDF even though the page objects were no
longer reference in the page tree.

Additionally, mutool did not analyze widget actions to determine if
their destination referenced removed pages. For the same reason as
above they would keep page and resource objects of removed pages in
the cleaned PDF.

This commit adds a pass to remove annotations belonging to removed
pages from non-terminal fields, and remove widget actions if their
destination refers to a removed page. After this commit mutool can
be used to remove pages from the PDF attached to the bug in order
to reduce its size.

2 years agoList debug flag for mark and sweep so it is easy to find.
Sebastian Rasmussen [Sat, 17 Sep 2022 00:12:27 +0000 (02:12 +0200)]
List debug flag for mark and sweep so it is easy to find.

2 years agoUpdate UCDN for Unicode 15.0.0.
Sebastian Rasmussen [Thu, 15 Sep 2022 12:18:29 +0000 (14:18 +0200)]
Update UCDN for Unicode 15.0.0.

2 years agomuwasm: Reset page cache when loading a new document.
Olivier FAURE [Fri, 16 Sep 2022 16:14:18 +0000 (18:14 +0200)]
muwasm: Reset page cache when loading a new document.

This fixes an issue where pages would render as blank when a document was open from disk.

2 years agomuwasm: Restore text selection and search
Olivier FAURE [Fri, 16 Sep 2022 12:56:38 +0000 (14:56 +0200)]
muwasm: Restore text selection and search

2 years agomuwasm: Have editor mode be a parameter of the URL
Olivier FAURE [Fri, 16 Sep 2022 12:56:07 +0000 (14:56 +0200)]
muwasm: Have editor mode be a parameter of the URL

2 years agoscripts/wrap/ docs/bindings.rst: Fixes for recent versions of libclang.so.
Julian Smith [Fri, 16 Sep 2022 17:29:09 +0000 (18:29 +0100)]
scripts/wrap/ docs/bindings.rst: Fixes for recent versions of libclang.so.

In scripts/wrap/state.py, expanded search for libclang.so to also try versions
12..20. Current max known version is 14.

Improvements to docs:
    Use Debian package name `python3-clang` instead of `python-clang` to fix
    building on Ubuntu.

    Added info on building C# bindings to scripts/wrap/__main__.py.

2 years agoBug 705763: Stop decoding broken LZW streams.
Tor Andersson [Wed, 14 Sep 2022 11:27:00 +0000 (13:27 +0200)]
Bug 705763: Stop decoding broken LZW streams.

Return EOF when we get an out-of-range code instead of soldiering on
and returning garbage data.

2 years agomuwasm: Add logging to test server
Olivier FAURE [Wed, 14 Sep 2022 11:33:49 +0000 (13:33 +0200)]
muwasm: Add logging to test server

2 years agomuwasm: Small fixes
Olivier FAURE [Tue, 13 Sep 2022 18:30:12 +0000 (20:30 +0200)]
muwasm: Small fixes

2 years agomuasm: Use fz_malloc inside JS API.
Olivier FAURE [Tue, 13 Sep 2022 13:12:03 +0000 (15:12 +0200)]
muasm: Use fz_malloc inside JS API.

2 years agomuwasm: Use Map instead of objects where relevant
Olivier FAURE [Tue, 13 Sep 2022 13:04:58 +0000 (15:04 +0200)]
muwasm: Use Map instead of objects where relevant

2 years agomuwasm: Tidy up eslint code
Olivier FAURE [Tue, 13 Sep 2022 13:03:28 +0000 (15:03 +0200)]
muwasm: Tidy up eslint code

2 years agomuwasm: Make APIs accept arrays where matrices are expected.
Olivier FAURE [Tue, 13 Sep 2022 13:02:40 +0000 (15:02 +0200)]
muwasm: Make APIs accept arrays where matrices are expected.

2 years agoFix indentation of preprocessor directives in error.c
Olivier FAURE [Tue, 13 Sep 2022 11:51:03 +0000 (13:51 +0200)]
Fix indentation of preprocessor directives in error.c

2 years agomuwasm: Have aborted renders not return an image.
Olivier FAURE [Tue, 13 Sep 2022 11:47:39 +0000 (13:47 +0200)]
muwasm: Have aborted renders not return an image.

2 years agomuwasm: Add canceling cookies
Olivier FAURE [Mon, 12 Sep 2022 13:10:53 +0000 (15:10 +0200)]
muwasm: Add canceling cookies

Fix bug where image wouldn't re-render on zoom.
Clean up code.

Co-authored-by: Tor Andersson <[email protected]>
2 years agomuwasm: Add Device class to JS API.
Olivier FAURE [Fri, 9 Sep 2022 14:03:01 +0000 (16:03 +0200)]
muwasm: Add Device class to JS API.

Add `run`, `runContents`, `runAnnots` and `runWidgets` methods to the Page class.
Add `Page.toPixmapTest` method which uses the above methods.

Co-authored-by: Tor Andersson <[email protected]>
2 years agomuwasm: Add multithreading support to build
Olivier FAURE [Fri, 9 Sep 2022 08:58:17 +0000 (10:58 +0200)]
muwasm: Add multithreading support to build

Add basic test server with cross-origin headers to support multithreading.

2 years agomuwasm: Fix format of date methods in annotations
Olivier FAURE [Wed, 7 Sep 2022 17:26:19 +0000 (19:26 +0200)]
muwasm: Fix format of date methods in annotations

Methods returned int64_t, which in JS translated to BigInt.
JS Dates can't accept BigInts as arguments.
The methods now return double, which translate seamlessly to the JS Number type.

2 years agomuwasm: Add editor-mode toggle
Olivier FAURE [Wed, 7 Sep 2022 15:17:09 +0000 (17:17 +0200)]
muwasm: Add editor-mode toggle