mupdf.git
3 years agoUpdate to zlib 1.2.12. 1.19.x 1.19.0-appkit-2.1.2 1.19.0-so-3.13.3
Sebastian Rasmussen [Mon, 28 Mar 2022 15:43:53 +0000 (17:43 +0200)]
Update to zlib 1.2.12.

3 years agoBug 704930: Check for Appearance Stream reuse. 1.19.0-appkit-2.1.0
Robin Watts [Fri, 11 Feb 2022 18:18:43 +0000 (18:18 +0000)]
Bug 704930: Check for Appearance Stream reuse.

We need to ensure that an object for an appearance stream, is not used
from more than one annotation before we reuse it.

Paul came up with the nice observation that any new appearance stream
we generate will go into the incremental section, and we'll never
put shared ones into that section. So, if and only if the appearance
stream from an annotation is in the incremental section, we can reuse
it.

3 years agoModify the Java platform to allow for adding source file to the build
Fred Ross-Perry [Mon, 25 Oct 2021 16:14:31 +0000 (09:14 -0700)]
Modify the Java platform to allow for adding source file to the build
by specifying certain new variables:

ADD_SOURCE_FILES - list of additional source file(s) to add
ADD_C_FLAGS - C compiler flag(s) to add
ADD_C_INCLUDES - C compiler include path(s) to add

3 years agoBug 704483: Avoid repeated xobjects created on form editing. 1.19.0
Robin Watts [Mon, 4 Oct 2021 16:43:29 +0000 (17:43 +0100)]
Bug 704483: Avoid repeated xobjects created on form editing.

If an XObject exists, reuse it.

3 years agoUpdate tesseract submodule to fix build issue on Windows. 1.19.0-rc2
Tor Andersson [Mon, 13 Sep 2021 16:26:32 +0000 (18:26 +0200)]
Update tesseract submodule to fix build issue on Windows.

3 years agoBump version number.
Tor Andersson [Mon, 13 Sep 2021 15:37:16 +0000 (17:37 +0200)]
Bump version number.

3 years agoUpdate CHANGES.
Tor Andersson [Fri, 10 Sep 2021 13:02:05 +0000 (15:02 +0200)]
Update CHANGES.

3 years agoBug 704341: Fix redaction of image masks.
Sebastian Rasmussen [Wed, 8 Sep 2021 15:12:30 +0000 (17:12 +0200)]
Bug 704341: Fix redaction of image masks.

Previously image masks were not handled specially when being
redacted. Because image masks a stored inverted in the PDF, when
redacting them we need to invert the samples, perform the redaction
including erasing pixels and drawing black boxes as requested. Finally
we need to remember the image mask flag so that the image is written
correctly when the PDF is saved.

3 years agoBug 704316: Emit embeddedd CFF fonts with subtype CIDFontType0C.
Tor Andersson [Tue, 7 Sep 2021 12:39:44 +0000 (14:39 +0200)]
Bug 704316: Emit embeddedd CFF fonts with subtype CIDFontType0C.

Apple Preview doesn't like the Type0 embedded font file to be Type1C.

3 years agoMakethird: fix Extract build error if python not 3.6 or later.
Julian Smith [Sun, 5 Sep 2021 09:18:32 +0000 (10:18 +0100)]
Makethird: fix Extract build error if python not 3.6 or later.

Don't attempt to run thirdparty/extract/src/docx_template_build.py if we don't
have python-3.6 or later. The generated files are in git so this works ok.

3 years agoSupport building with libcrypto (openssl) for MacOS
Fred Ross-Perry [Fri, 3 Sep 2021 15:34:42 +0000 (08:34 -0700)]
Support building with libcrypto (openssl) for MacOS
This relies on 2 other things that should be covered in documentation:

1.  install pkg-config, which does not come with MacOS.
     brew install pkg-config
     if this is not installed, you'll get a warning, but the build will continue
     without including libcrypto

2.  Install libcrypto, using brew:
     https://gist.github.com/aklap/e885721ef15c8668ed0a1dd64d2ea1a7
     this note explains a couple of symbolic links you need to add
     If you've installed pkg-config but not libcrypto, the build will
     continue without including libcrypto

3 years agoAdd copyright blobs to source files.
Tor Andersson [Wed, 25 Aug 2021 09:38:13 +0000 (11:38 +0200)]
Add copyright blobs to source files.

This commit was generated by running scripts/copyblob.sh

3 years agoScript to add copyright blobs to source files.
Tor Andersson [Wed, 25 Aug 2021 09:12:38 +0000 (11:12 +0200)]
Script to add copyright blobs to source files.

3 years agoAdd copyright lines to third party code snippets.
Tor Andersson [Wed, 25 Aug 2021 09:23:20 +0000 (11:23 +0200)]
Add copyright lines to third party code snippets.

3 years agoAdd 'automatically generated file' headers to automatically generated files.
Tor Andersson [Tue, 13 Apr 2021 21:37:11 +0000 (23:37 +0200)]
Add 'automatically generated file' headers to automatically generated files.

Makes it easier to avoid slapping on the copyright blob on these files in scripts.

3 years agoBug 701031: Do CMYK + Spots -> RGB conversion in 2 steps.
Robin Watts [Tue, 24 Aug 2021 15:28:17 +0000 (16:28 +0100)]
Bug 701031: Do CMYK + Spots -> RGB conversion in 2 steps.

First merge the spots into the CMYK, then convert to RGB.

Don't convert process colors to RGB and then attempt to merge
converted RGB spots with them, as that gives poor results.

3 years agoFix fz_copy_pixmap_area_converting_seps to cope with spot cases.
Robin Watts [Tue, 24 Aug 2021 10:26:54 +0000 (11:26 +0100)]
Fix fz_copy_pixmap_area_converting_seps to cope with spot cases.

When copying from CMYK + Spots to CMYK, we were incorrectly falling
into the 'just copy it' clause, resulting in spots being dropped.

This meant that:

 mutool draw -o spot1.psd -O 1 REWE2.pdf

(using REWE2.pdf from Bug 701031) was coming out in greyscale.

With this change in both the above command and:

 mutool draw -o spot2.psd -O 2 REWE2.pdf

appear almost identically in Photoshop (and are visually identical
to what Acrobat renders).

3 years agoFix some premultiplied problems.
Robin Watts [Wed, 25 Aug 2021 12:08:52 +0000 (13:08 +0100)]
Fix some premultiplied problems.

First, fix a typo in lcms2 that caused a non-premultiplied
transform to be used when a premultiplied one was required.

Next, allow for the limitations in lcms2's premultiplication
support by reinstating the 'do it by steam' routines that
undo/redo premultiplication for some cases.

LCMS2 can handle premultiplication in the cases where the
number of spot channels does not change. In rare cases (such
as folding spots down to process colors after overprint simulation)
we can need to operate not in this way.

We now make use of the faster lcms2 processing where possible,
and do it ourselves otherwise.

3 years agojni: Remove unused argument.
Sebastian Rasmussen [Mon, 23 Aug 2021 23:30:27 +0000 (01:30 +0200)]
jni: Remove unused argument.

3 years agojni: Remove accidentally included debug print.
Sebastian Rasmussen [Sat, 21 Aug 2021 15:15:39 +0000 (17:15 +0200)]
jni: Remove accidentally included debug print.

3 years agoPlug memory leak in OCR recognition code.
Sebastian Rasmussen [Tue, 24 Aug 2021 01:56:20 +0000 (03:56 +0200)]
Plug memory leak in OCR recognition code.

3 years agoBug 704244, 704245: updated thirdparty/extract to pick up recent fixes.
Julian Smith [Tue, 24 Aug 2021 09:30:29 +0000 (10:30 +0100)]
Bug 704244, 704245: updated thirdparty/extract to pick up recent fixes.

3 years agoUse LCMS2MT's new support for premultiplied data.
Robin Watts [Wed, 7 Jul 2021 23:15:08 +0000 (00:15 +0100)]
Use LCMS2MT's new support for premultiplied data.

We added support to lcms2 for premultiplied data. That commit
escaped into the tree a while ago. This commit updates MuPDF
to actually use it.

3 years agoPull in fixes for lcms2mt -> lcms2 merge.
Robin Watts [Mon, 23 Aug 2021 13:46:25 +0000 (06:46 -0700)]
Pull in fixes for lcms2mt -> lcms2 merge.

3 years agoandroid: Fix builds that include Tesseract.
Sebastian Rasmussen [Fri, 20 Aug 2021 00:24:28 +0000 (02:24 +0200)]
android: Fix builds that include Tesseract.

Commit 56fc1452c0fafd318cf09733b51c182986c2c4da accidentally
omitted adding the include directory for android when it added
a new header include to tessocr.cpp.

Thanks Fred for pointing this out.

3 years agoFix bug in hex_from_color.
Tor Andersson [Tue, 17 Aug 2021 13:16:29 +0000 (15:16 +0200)]
Fix bug in hex_from_color.

If no color is specified (when n is 0) then the color is either
transparent (for annotation borders) or default to black (for
variable text).

In the UI we convert the color array to an RGB hex in order to
display the color name. Use transparent/none rather than black when the
color is not set.

3 years agoBug 699103: Clamp link page coordinates to the page area.
Tor Andersson [Tue, 17 Aug 2021 12:44:29 +0000 (14:44 +0200)]
Bug 699103: Clamp link page coordinates to the page area.

3 years agoBug 704073: Remove FreeText annotations that touch redactions.
Tor Andersson [Tue, 17 Aug 2021 10:40:30 +0000 (12:40 +0200)]
Bug 704073: Remove FreeText annotations that touch redactions.

3 years agoUpdate existing Noto fonts to latest versions.
Tor Andersson [Tue, 6 Jul 2021 11:41:53 +0000 (13:41 +0200)]
Update existing Noto fonts to latest versions.

  * Replace TTF with OTF versions.
  * Replace sans with new serif variants.
  * Add more scripts.
  * Remove unused Arabic fonts.
  * Add font for Yezidi script.
  * Update fontdump.nmake and libresources.vcxproj.

3 years agoFollow-up to "Bug 703894: Flush text state and adjustments".
Tor Andersson [Mon, 16 Aug 2021 10:55:11 +0000 (12:55 +0200)]
Follow-up to "Bug 703894: Flush text state and adjustments".

Discard text adjustment instead of flushing it.

3 years agoBug 703894: Flush text state and adjustments before emitting newline.
Tor Andersson [Fri, 13 Aug 2021 15:07:29 +0000 (17:07 +0200)]
Bug 703894: Flush text state and adjustments before emitting newline.

The squote and dquote text operators decompose into a T* + Tj pair,
but we need to make sure to flush TL and buffered spacing adjustments
before emitting the newline, else we'll miss the TL and/or add the
spacing adjustments for redacted characters after the newline when
they should be before the newline.

3 years agoFix SEGV in pdf_add_journal_fragment.
Robin Watts [Thu, 12 Aug 2021 11:41:56 +0000 (12:41 +0100)]
Fix SEGV in pdf_add_journal_fragment.

With specific files we can get SEGVs in pdf_add_journal_fragment
on loading the document. We are arriving there with no journal
entries defined.

This is because we've hit a PDF repair, which has discarded the
journal, before we've continued though to make a change.

We fix this in two ways.

Firstly, we no longer discard the journal on a repair. The journal
should not be dependent on anything that can change during a repair,
so this should be safe. This should be nicer for a user, because
losing your undo history due to a repair triggered late on in
using a file is unhelpful.

Secondly, we introduce the ability to tell the core to 'throw after
repair'. For certain sections of the code (here, the annotation
synthesis code), if we get a repair during the code, we want to
perform the repair, then restart the operation from scratch.

Accordingly, we have start/end functions to trigger this behaviour,
changes to pdf_repair so that we throw as required, a new type of
error so we can recognise this case, tweaks to the catch/rethrow
routines used within the appearance synthesis, and top level changes
in the appearance synthesis routines to start/stop and restart as
required.

fix

3 years agoBug 704212: Fix race condition in fz_advance_glyph.
Robin Watts [Fri, 13 Aug 2021 11:51:34 +0000 (12:51 +0100)]
Bug 704212: Fix race condition in fz_advance_glyph.

Suppose one thread calls fz_advance_glyph, determines that we should
be using an advance cache, but one doesn't exist. It will then
allocate it, and start to fill it.

If at that point another thread calls fz_advance_glyph, it'll see
the newly created advance cache, and access it regardless of the
fact that it's newly only partially filled.

The way to avoid this is to hold the FREETYPE lock around the
use of the advance_cache.

3 years agojava: Expose API for layouting text widgets. 1.19.0-rc1 1.19.0-rc1-so-3.12.7
Sebastian Rasmussen [Tue, 10 Aug 2021 12:15:06 +0000 (14:15 +0200)]
java: Expose API for layouting text widgets.

3 years agoFix double free in document_has_redactions().
Tor Andersson [Wed, 11 Aug 2021 14:42:52 +0000 (16:42 +0200)]
Fix double free in document_has_redactions().

3 years agoBug 703970: Handle ToUnicode CMaps without codespacerange declaration.
Tor Andersson [Wed, 11 Aug 2021 14:21:59 +0000 (16:21 +0200)]
Bug 703970: Handle ToUnicode CMaps without codespacerange declaration.

Add a bogus <0000><FFFF> codespace range if none is declared.

3 years agojava: Resort class/field/method initializers.
Sebastian Rasmussen [Tue, 10 Aug 2021 13:12:42 +0000 (15:12 +0200)]
java: Resort class/field/method initializers.

3 years agojs: Expose API for layouting text widgets.
Sebastian Rasmussen [Mon, 9 Aug 2021 23:25:35 +0000 (01:25 +0200)]
js: Expose API for layouting text widgets.

3 years agoRename text widget layout members.
Sebastian Rasmussen [Tue, 10 Aug 2021 10:09:38 +0000 (12:09 +0200)]
Rename text widget layout members.

3 years agoAdd APIs for translating between indices and rune pointers.
Sebastian Rasmussen [Tue, 10 Aug 2021 10:46:24 +0000 (12:46 +0200)]
Add APIs for translating between indices and rune pointers.

3 years agojs: Add embedded file function bindings.
Tor Andersson [Mon, 9 Aug 2021 11:39:41 +0000 (13:39 +0200)]
js: Add embedded file function bindings.

3 years agoSet CJK font flag for Hangul, Hiragana and Katakana scripts too.
Tor Andersson [Thu, 5 Aug 2021 15:22:45 +0000 (17:22 +0200)]
Set CJK font flag for Hangul, Hiragana and Katakana scripts too.

3 years agoBug 703924: Only parse anchor using PDF function if it's a PDF!
Tor Andersson [Thu, 5 Aug 2021 11:22:45 +0000 (13:22 +0200)]
Bug 703924: Only parse anchor using PDF function if it's a PDF!

Also remove duplicated code by handling both PDF and non-PDF anchors
in the same block.

Also handle plain page numbers by converting to a location.

3 years agothirdparty/extract: update submodule to pick up fix for building on iOS.
Julian Smith [Thu, 5 Aug 2021 13:23:24 +0000 (14:23 +0100)]
thirdparty/extract: update submodule to pick up fix for building on iOS.

3 years agoscripts/: Improved constructors of fz_document_writer wrapper class.
Julian Smith [Wed, 4 Aug 2021 23:18:10 +0000 (00:18 +0100)]
scripts/: Improved constructors of fz_document_writer wrapper class.

Added support for constructing DocumentWriter instances from several
fz_new_*_writer() and fz_new_*_writer_with_output() functions that were
previously omitted.

Some constructors need to take an enum to differentiate between fz_ functions
that take identical types; have renamed these enums for consistency and added a
new enum.

Also changed constructors that wrap fz_new_*_writer_with_output()
functions to take a non-const 'Output& out' and set out.m_internal
to NULL before returning. This is necessary because the underlying
fz_new_*_writer_with_output() functions take ownership of the fz_output, which
does not support reference counting.

Patched up scripts/mupdfwrap_test.py and scripts/mutool.py to use the new
constructors.

3 years agogl: Drop distinguished name after formatting.
Sebastian Rasmussen [Wed, 4 Aug 2021 00:33:29 +0000 (02:33 +0200)]
gl: Drop distinguished name after formatting.

3 years agogl: Update trace file to adhere to PDFWidget.sign() API.
Sebastian Rasmussen [Wed, 4 Aug 2021 00:05:41 +0000 (02:05 +0200)]
gl: Update trace file to adhere to PDFWidget.sign() API.

3 years agoVisual Studio: Fix OpenSSL builds of mutool.
Robin Watts [Wed, 4 Aug 2021 10:41:54 +0000 (11:41 +0100)]
Visual Studio: Fix OpenSSL builds of mutool.

Previously, we weren't building OpenSSL variants of mutool. Now
we can do signing using mutool run, we need these.

3 years agoFix output ownership issues with document and zip writers.
Robin Watts [Wed, 4 Aug 2021 12:06:51 +0000 (13:06 +0100)]
Fix output ownership issues with document and zip writers.

Make it clear that ownership of the fz_output passes into
both document writers and zip writers immediately.

Ensure that the creation functions properly drop the output
in the event of an error.

Pull odt and docx writers into line with the others.

3 years agoExtend config.h to cover output formats too.
Robin Watts [Tue, 3 Aug 2021 15:54:30 +0000 (16:54 +0100)]
Extend config.h to cover output formats too.

Currently just extract and ocr using formats.

3 years agopdfwrite: Support substitute CJK fonts in output.
Tor Andersson [Wed, 4 Aug 2021 11:41:44 +0000 (13:41 +0200)]
pdfwrite: Support substitute CJK fonts in output.

Track CJK fonts when creating them and store the language in the font
flags. Use the language flag to create substitute CJK fonts with
the appropriate character collection encoding.

Use UCS2 CMaps for the text encoding when creating a substitute font.

The font metrics of the substitute font may not always match, but some
text is better than no text!

Also add in a generic substitute font creation stub.

3 years agoextract: Touch the generated files after running the python script.
Tor Andersson [Tue, 3 Aug 2021 16:02:48 +0000 (18:02 +0200)]
extract: Touch the generated files after running the python script.

The python script doesn't update the files unless they change, which
breaks makes dependency tracking which uses time stamps.

Work around that by manually touching the file.

3 years agoBug 704126: Create "Contents" stream if it is missing.
Tor Andersson [Tue, 3 Aug 2021 15:17:03 +0000 (17:17 +0200)]
Bug 704126: Create "Contents" stream if it is missing.

If the Contents are an array of streams we recreate a new Contents stream.
We should also do the same if it is null.

3 years agoBug 704162: Repair trailer when repair is triggered after initialization.
Tor Andersson [Tue, 3 Aug 2021 14:40:31 +0000 (16:40 +0200)]
Bug 704162: Repair trailer when repair is triggered after initialization.

3 years agoscripts/pypackage.py: fix manylinux builds that need python3.
Julian Smith [Tue, 3 Aug 2021 15:44:04 +0000 (16:44 +0100)]
scripts/pypackage.py: fix manylinux builds that need python3.

The manylinux docker container does not have a python3 (though it does have
python3.8, python3.9 etc) which can be required by some builds, so we now
always create a softlink inside the container.

This fixes build of Extract when creating MuPDF wheels.

Also fixed some issues caused by changes to jlib.Arg command-line parsing.

3 years agoRemove pdf_widget typedef.
Tor Andersson [Mon, 2 Aug 2021 10:55:26 +0000 (12:55 +0200)]
Remove pdf_widget typedef.

3 years agoBug 704154: Fix OSS-Fuzz found leak in fz_paint_shade.
Robin Watts [Mon, 2 Aug 2021 15:23:30 +0000 (16:23 +0100)]
Bug 704154: Fix OSS-Fuzz found leak in fz_paint_shade.

The cache used for painting shades has 2 parts. Depending on the
nature of the shade given, we may or may not use either part of
the cache.

For each part, if we have the correct prerequestites, then we check
to see if we 'hit' the cache. If we do, we pull stuff out and use it.
If we 'miss' it, then we throw away the stuff in the cache in the
knowledge that we will refill it with the current stuff in a minute.
Then in the always case we refill it.

Unfortunately, the 'refill' code was then filling the cache even
in some situations when it hadn't been emptied (because the
prerequestites for emptying it were not reflected in the refilling
it case).

This resulted in valid cache entries being overwritten repeatedly
meaning that the reference counting went wrong.

The fix, implemented here, is to keep track of whether we should
refill or not based upon whether we emptied.

3 years agoAlways build with extract.
Julian Smith [Fri, 30 Jul 2021 17:29:12 +0000 (18:29 +0100)]
Always build with extract.

Removed extract=yes/no option and all mention of USE_EXTRACT, HAVE_EXTRACT,
USE_SYSTEM_EXTRACT.

In Makethird, we now specify $(ZLIB_CFLAGS) when compiling Extract source; this
is required for wasm builds otherwise zlib.h is not found.

3 years agoMinor improvements to docx/odt code.
Julian Smith [Mon, 2 Aug 2021 10:42:13 +0000 (11:42 +0100)]
Minor improvements to docx/odt code.

Removed unused <format> arg from fz_new_docx_writer() and fz_new_odt_writer().

Added docx/odt support to fz_new_document_writer_with_output(), similar to
existing support in fz_new_document_writer().

Added docx and odt to fz_new_document_writer()'s comment's list of formats.

Removed unnecessary braces in docx/odt code in fz_new_document_writer().

3 years agoinclude/mupdf/fitz/shade.h: document fz_paint_shade()'s new <cache> arg.
Julian Smith [Mon, 2 Aug 2021 10:34:25 +0000 (11:34 +0100)]
include/mupdf/fitz/shade.h: document fz_paint_shade()'s new <cache> arg.

3 years agoRequest resynthesis for all annotations when a field is marked dirty.
Robin Watts [Mon, 2 Aug 2021 11:07:10 +0000 (12:07 +0100)]
Request resynthesis for all annotations when a field is marked dirty.

When resynthesising an annotation, we consider the field being
dirty as enough reason to resynthesise it. As such, whenever a
field is marked as dirty, we should trigger a resynthesis, so
that fields don't change later on when resynthesise are triggered
for other reasons.

calc2.pdf fails to update properly (type 123 x 45 = for example)
without this fix, so clearly we are not currently triggering a
resythesis when we should be.

Credit to Sebastian for spotting this.

3 years agoBug 704138: Don't overwrite good object with truncated one during repair.
Tor Andersson [Mon, 2 Aug 2021 12:07:49 +0000 (14:07 +0200)]
Bug 704138: Don't overwrite good object with truncated one during repair.

3 years agomupdf-gl: Ensure update_title called correctly on document dirty/clean.
Robin Watts [Thu, 29 Jul 2021 18:15:31 +0000 (19:15 +0100)]
mupdf-gl: Ensure update_title called correctly on document dirty/clean.

The existing code watches for the value pdf_has_unsaved_changes()
changing around the main edit loop, and calls update_title when
a change is spotted. Unfortunately this doesn't capture edits made
using dialog boxes (such as tx_dialog and ch_dialog).

Therefore move to a simpler version where we record the state in a
static.

3 years agoFix undo-to-vanilla in TestFormExpenses.pdf.
Robin Watts [Thu, 29 Jul 2021 18:15:05 +0000 (19:15 +0100)]
Fix undo-to-vanilla in TestFormExpenses.pdf.

If we load TestFormExpenses.pdf, fill in the name field, and then
undo, we do not return to the vanilla unchanged state.

This is because the first edit done to the file as part of editing
the name field is the addition of an object, rather than the
modification of an existing one. I had forgotten to add such objects
to the undo history, so they were left (unreferenced) in the
incremental history, making the document dirty.

The fix is to add these to the fragments too. The document now
behaves as expected.

3 years agoBug 704156: Truncate too long filenames to avoid buffer overflow.
Tor Andersson [Mon, 2 Aug 2021 10:45:38 +0000 (12:45 +0200)]
Bug 704156: Truncate too long filenames to avoid buffer overflow.

3 years agoscripts/mupdfwrap_gui.py: simple demo app using MuPDF python bindings and PyQt5.
Julian Smith [Tue, 13 Jul 2021 09:29:54 +0000 (10:29 +0100)]
scripts/mupdfwrap_gui.py: simple demo app using MuPDF python bindings and PyQt5.

3 years agoscripts/mupdfwrap.py: improved help, added support for clang-11.
Julian Smith [Thu, 29 Jul 2021 17:59:51 +0000 (18:59 +0100)]
scripts/mupdfwrap.py: improved help, added support for clang-11.

Added example build commands for Linux, Windows and OpenBSD.

3 years agoAdded convenience function fz_new_buffer_from_page_with_format().
Julian Smith [Wed, 14 Jul 2021 11:49:37 +0000 (12:49 +0100)]
Added convenience function fz_new_buffer_from_page_with_format().

3 years agosetup.py: remove support for making minimal test package.
Julian Smith [Tue, 25 May 2021 10:58:12 +0000 (11:58 +0100)]
setup.py: remove support for making minimal test package.

No longer required now the full build works ok.

3 years agoscripts/mupdfwrap.py: improved class-method wrappers for fz_paint_shade().
Julian Smith [Thu, 15 Jul 2021 09:13:40 +0000 (10:13 +0100)]
scripts/mupdfwrap.py: improved class-method wrappers for fz_paint_shade().

Cope with fz_paint_shade()'s new 'fz_shade_color_cache **cache' arg:

    The auto-generated class method that wraps fz_paint_shade() is
    mupdf::Shade::paint_shade(), which now takes new arg 'ShadeColorCache&
    cache'. The auto-generated implementation passes &cache.m_internal to
    fz_paint_shade(), which does the right thing, e.g. setting cache.m_internal
    if it is NULL.

    But have added new custom wrapper method
    mupdf::Shade::paint_shade_no_cache() that omits the <cache> arg and
    passes cache=NULL to fz_paint_shade(); this gives C++ access to the full
    functionality of the underlying C API.

    Have also added default constructor to fz_shade_color_cache wrapper
    ShadeColorCache which sets m_internal to NULL, to simplify usage with
    mupdf::Shade::paint_shade().

Other:
    Reduced various diagnostics when generating C++ code.

    With the -b arg, added optional '-d <details>'; we show extra details when
    wrapping fns whose name contain <details>.

    Improved some comments.

3 years agoscripts/mupdfwrap.py: added comment to custom Page::begin_page() method.
Julian Smith [Wed, 14 Jul 2021 11:50:20 +0000 (12:50 +0100)]
scripts/mupdfwrap.py: added comment to custom Page::begin_page() method.

[This custom method is required because fz_begin_page() returns a borrowed
reference.]

3 years agoscripts/mupdfwrap.py: fix operator<< for POD C structs.
Julian Smith [Fri, 28 May 2021 16:00:31 +0000 (17:00 +0100)]
scripts/mupdfwrap.py: fix operator<< for POD C structs.

Streaming operators for C PODs such as 'std::ostream& operator<< (std::ostream&
out, const fz_point& rhs)' used to be declared and defined inside 'namespace
mupdf {...}' so were not usable. Have moved them to top-level scope.

3 years agoscripts/mupdfwrap.py: allow '-b all -t' to work on Windows.
Julian Smith [Thu, 27 May 2021 13:40:06 +0000 (14:40 +0100)]
scripts/mupdfwrap.py: allow '-b all -t' to work on Windows.

Added support for deferring to cmd.exe and a venv with libclang installed. So
on Windows one can do:

    ./scripts/mupdfwrap.py --venv pylocal --swig-windows-auto -b all -t

Note that --venv does not upgrade pip - this appears to fail on some systems.

3 years agoscripts/pypackage.py: updated to match changes to jlib.py:Arg.
Julian Smith [Thu, 27 May 2021 16:59:00 +0000 (17:59 +0100)]
scripts/pypackage.py: updated to match changes to jlib.py:Arg.

3 years agoscripts/jlib.py: various improvements.
Julian Smith [Mon, 24 May 2021 15:26:12 +0000 (16:26 +0100)]
scripts/jlib.py: various improvements.

Added doctest for more fns.

Fixed nv handling of {...!=}.

log():
    Cope with encoding errors. If writing to out stream raises
    UnicodeEncodeError, we retry, writing text that has been encoded+decoded
    with errors='replace' so that this will succeed.

Arg:
    various improvements - reduce text with -h, improved output if second
    non-multi item was found. Result has extra namespace level so calling code
    needs to be changed to match.

3 years agoinclude/mupdf/fitz/getopt.h: removed unimplemented Windows unicode items.
Julian Smith [Thu, 27 May 2021 14:37:07 +0000 (15:37 +0100)]
include/mupdf/fitz/getopt.h: removed unimplemented Windows unicode items.

For example fz_getoptw() was removed in 2015, commit db3f7ffe32808fde8.

3 years agoTweak annotation flag setting.
Robin Watts [Wed, 28 Jul 2021 16:13:04 +0000 (17:13 +0100)]
Tweak annotation flag setting.

Call pdf_set_annot_resynthesised in pdf_update_button_appearance.
This both clears "needs_new_ap" and sets "has_new_ap", rather than
just setting "has_new_ap".

Also, this means that all the routes out of pdf_update_annotation
call pdf_set_annot_resynthesised, so there is no need to do it at
the top level.

3 years agoSimplify callers requirements for pdf_update_annot.
Robin Watts [Wed, 28 Jul 2021 11:59:20 +0000 (12:59 +0100)]
Simplify callers requirements for pdf_update_annot.

It used to be that callers calling pdf_update_annot would have to
spot annotations returning 'changed' and then run through the
list again to cope with resyntheses that went into the document
overriding synthesised appearances that lived in local_xref's.

Here, we tweak the implementation so that this all lives below
the interface.

Whenever an annotation is edited, and has its 'needs_new_ap' flag
set (i.e. is marked for needing resynthesis), we set a flag in
the document noting that the document needs a resynthesis pass
performed.

Whenever someone calls pdf_update_annot to check whether an
annotation has changed, we check that flag, and if set, we
perform such a pass. This involves running across every annotation
on every open page, twice, calling pdf_update_annotation. We
then clear the document flag.

Thus the same amount of work is done as before, but the caller
is freed from the need to do 2 passes, and to deal with the
complexities involved when multiple pages are open.

3 years agomupdf-gl: Tidy up on closedown.
Robin Watts [Wed, 28 Jul 2021 13:25:26 +0000 (14:25 +0100)]
mupdf-gl: Tidy up on closedown.

Free a couple of things (page bitmap and selected annot) on
closedown. This makes a memento run work cleanly which makes
it easier to spot future leaks.

3 years agojs: Expose API for begin-/beginImplicit-/endOperations.
Sebastian Rasmussen [Tue, 27 Jul 2021 23:25:31 +0000 (01:25 +0200)]
js: Expose API for begin-/beginImplicit-/endOperations.

3 years agoAdd callback to free js event callback data.
Sebastian Rasmussen [Tue, 27 Jul 2021 20:17:48 +0000 (22:17 +0200)]
Add callback to free js event callback data.

Consider the scenario where an app opens a PDF document, allocates
data to be passed to a js event callback, sets the document's
callback and provides the data. Later on the document is dropped.
At this point, whose responsibility is it to free the event callback
data?

Prior to this change it was up to the app to fetch the event callback
data from the document and drop it before the document itself was
dropped.

After this commit when the document is being dropped a callback will
be called, tasked with freeing the allocated js event callback data.
This way the app doesn't have to get and free the event callback data
when dropping the document.

3 years agojs: Free js event listener data when GCing PDF document objects.
Sebastian Rasmussen [Tue, 27 Jul 2021 20:36:25 +0000 (22:36 +0200)]
js: Free js event listener data when GCing PDF document objects.

3 years agojs: Call correct gc callback for PDF document objects.
Sebastian Rasmussen [Tue, 27 Jul 2021 20:35:55 +0000 (22:35 +0200)]
js: Call correct gc callback for PDF document objects.

3 years agojs: Expose undo/redo API.
Sebastian Rasmussen [Tue, 27 Jul 2021 20:26:20 +0000 (22:26 +0200)]
js: Expose undo/redo API.

3 years agojs: Rename event listener API to match C and Java APIs.
Sebastian Rasmussen [Tue, 27 Jul 2021 20:16:08 +0000 (22:16 +0200)]
js: Rename event listener API to match C and Java APIs.

3 years agoPlug memory leak of merged text field value.
Sebastian Rasmussen [Tue, 27 Jul 2021 17:36:13 +0000 (19:36 +0200)]
Plug memory leak of merged text field value.

3 years agoForget both local and normal xref when repairing PDFs. 1.18.1-so-3.12.6
Sebastian Rasmussen [Sun, 25 Jul 2021 01:57:12 +0000 (03:57 +0200)]
Forget both local and normal xref when repairing PDFs.

Also introduce a convenience function that does this.

This fixes OSS-fuzz issue 32037.

3 years agoSet text field value even when ignoring trigger events.
Sebastian Rasmussen [Tue, 27 Jul 2021 12:54:13 +0000 (14:54 +0200)]
Set text field value even when ignoring trigger events.

Previously MuPDF always set the text field value to NULL which gets
reinterpreted into the empty string.

3 years agomupdf-gl: Move selected_annot global.
Robin Watts [Tue, 27 Jul 2021 11:26:34 +0000 (12:26 +0100)]
mupdf-gl: Move selected_annot global.

Move into the ui structure. Read directly, but only ever set it
by calling ui_select_annot(). This allows us to drop references
as appropriate.

3 years agopdf_create_annot: return an owned reference not a borrowed one.
Robin Watts [Mon, 26 Jul 2021 17:35:51 +0000 (18:35 +0100)]
pdf_create_annot: return an owned reference not a borrowed one.

This seems much more logical - indeed, the Java, C++ and Python
bindings have all been written to assume this.

Knock on effects are for pdf_annot_create_raw and
pdf_create_signature_widget to also return owned references.

mupdf-gl has been updated to reflect the fact that it owns the
reference.

fz_create_link and pdf_create_link are similarly updated. The
java (and presumably C++ and python) handlers for this already
assumed that they returned an owned reference.

3 years agoMemento: Avoid underflow with very small blocks.
Robin Watts [Mon, 26 Jul 2021 16:33:08 +0000 (17:33 +0100)]
Memento: Avoid underflow with very small blocks.

3 years agoAFSpecial_KeystrokeEx must accept empty fields.
Robin Watts [Mon, 26 Jul 2021 16:31:25 +0000 (17:31 +0100)]
AFSpecial_KeystrokeEx must accept empty fields.

Otherwise you can change a field to something, and then not be
able to revert to the empty value without the form complaining.

Tests seem to indicate that Acrobat DOES call the javascript
in this case, so the empty string handling should be in the js
rather than the C.

3 years agoUpdate set_validate_field_value to accept javascript changed values.
Robin Watts [Mon, 26 Jul 2021 12:02:44 +0000 (13:02 +0100)]
Update set_validate_field_value to accept javascript changed values.

toupper-64-8.pdf demonstrates that the 'validation' javascript
event can change the final value that is supposed to be stored
into the document.

Support that here.

3 years agoAdd pdf_edit_text_field_value and make mupdf-gl use it.
Robin Watts [Mon, 26 Jul 2021 14:30:08 +0000 (15:30 +0100)]
Add pdf_edit_text_field_value and make mupdf-gl use it.

This allowed "format as you type" using javascript keystroke
methods.

3 years agoReplace 'event' variables with 'evt'.
Robin Watts [Fri, 23 Jul 2021 15:40:48 +0000 (16:40 +0100)]
Replace 'event' variables with 'evt'.

MSVC really dislikes 'event' as a name. It won't display values for
'event.foo', instead displaying whatever the value of 'foo' is.
Apparently this because C++/CLI uses 'event' as a reserved word.

I find this really confusing.

Rename our 'event' variables to 'evt'.

3 years agomupdf-gl: Add rudimentary js alert support.
Robin Watts [Fri, 23 Jul 2021 15:22:11 +0000 (16:22 +0100)]
mupdf-gl: Add rudimentary js alert support.

3 years agoFix AFSpecial_KeystrokeEx.
Robin Watts [Thu, 22 Jul 2021 17:26:26 +0000 (18:26 +0100)]
Fix AFSpecial_KeystrokeEx.

AFSpecial_KeystrokeEx takes 1) the current value of a field,
2) the area 'selected' within that field, and 3) the 'change'
to be pasted into that area.

When called without 'willCommit' set, it is expected to check
that the combined string is formatted OK. If it is OK, it
can return true, with no changes. If it can be made OK, then
'change' and 'selection' should be updated to make it OK, and
the routine should return false. Otherwise, it should just
return false.

When called with 'willCommit' set, it is expected that the call
has the proposed 'value' with no changes. It should check that
the combined string is formatted OK, and to just return yes or no.

Our implementation of AFSpecial_KeystrokeEx is clearly not doing
that. It attempts to walk the 'value' string without ever merging
the change string into it.

Our implementation also only ever sets event.value, so fix that too.

We also have to update our C code that calls this stuff to properly
use the returned values, and to call the willCommit state in
alignment with our new understanding of what the selection means.

3 years agoMark stream to be dropped during exception as fz_var.
Sebastian Rasmussen [Sun, 25 Jul 2021 01:14:06 +0000 (03:14 +0200)]
Mark stream to be dropped during exception as fz_var.

Previously the stream was not marked fz_var, hence its variable kept
being NULL when cleaning up after the exception, causing a leak of
the stream.

This fixes OSS-fuzz issue 33880.

3 years agoUpdate JS console.println so that it prints to fz_stddbg.
Robin Watts [Thu, 22 Jul 2021 18:04:25 +0000 (19:04 +0100)]
Update JS console.println so that it prints to fz_stddbg.

3 years agogl/x11: Cope with error while trying to handle relative URI.
Sebastian Rasmussen [Fri, 23 Jul 2021 01:07:07 +0000 (03:07 +0200)]
gl/x11: Cope with error while trying to handle relative URI.