Sebastian Rasmussen [Tue, 10 Aug 2021 10:46:24 +0000 (12:46 +0200)]
Add APIs for translating between indices and rune pointers.
Tor Andersson [Mon, 9 Aug 2021 11:39:41 +0000 (13:39 +0200)]
js: Add embedded file function bindings.
Tor Andersson [Thu, 5 Aug 2021 15:22:45 +0000 (17:22 +0200)]
Set CJK font flag for Hangul, Hiragana and Katakana scripts too.
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.
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.
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.
Sebastian Rasmussen [Wed, 4 Aug 2021 00:33:29 +0000 (02:33 +0200)]
gl: Drop distinguished name after formatting.
Sebastian Rasmussen [Wed, 4 Aug 2021 00:05:41 +0000 (02:05 +0200)]
gl: Update trace file to adhere to PDFWidget.sign() API.
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.
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.
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.
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.
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.
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.
Tor Andersson [Tue, 3 Aug 2021 14:40:31 +0000 (16:40 +0200)]
Bug 704162: Repair trailer when repair is triggered after initialization.
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.
Tor Andersson [Mon, 2 Aug 2021 10:55:26 +0000 (12:55 +0200)]
Remove pdf_widget typedef.
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.
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.
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().
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.
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.
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.
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.
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.
Tor Andersson [Mon, 2 Aug 2021 10:45:38 +0000 (12:45 +0200)]
Bug 704156: Truncate too long filenames to avoid buffer overflow.
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.
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.
Julian Smith [Wed, 14 Jul 2021 11:49:37 +0000 (12:49 +0100)]
Added convenience function fz_new_buffer_from_page_with_format().
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.
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.
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.]
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.
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.
Julian Smith [Thu, 27 May 2021 16:59:00 +0000 (17:59 +0100)]
scripts/pypackage.py: updated to match changes to jlib.py:Arg.
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.
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.
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.
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.
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.
Sebastian Rasmussen [Tue, 27 Jul 2021 23:25:31 +0000 (01:25 +0200)]
js: Expose API for begin-/beginImplicit-/endOperations.
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.
Sebastian Rasmussen [Tue, 27 Jul 2021 20:36:25 +0000 (22:36 +0200)]
js: Free js event listener data when GCing 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.
Sebastian Rasmussen [Tue, 27 Jul 2021 20:26:20 +0000 (22:26 +0200)]
js: Expose undo/redo API.
Sebastian Rasmussen [Tue, 27 Jul 2021 20:16:08 +0000 (22:16 +0200)]
js: Rename event listener API to match C and Java APIs.
Sebastian Rasmussen [Tue, 27 Jul 2021 17:36:13 +0000 (19:36 +0200)]
Plug memory leak of merged text field value.
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.
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.
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.
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.
Robin Watts [Mon, 26 Jul 2021 16:33:08 +0000 (17:33 +0100)]
Memento: Avoid underflow with very small blocks.
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.
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.
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.
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'.
Robin Watts [Fri, 23 Jul 2021 15:22:11 +0000 (16:22 +0100)]
mupdf-gl: Add rudimentary js alert support.
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.
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.
Robin Watts [Thu, 22 Jul 2021 18:04:25 +0000 (19:04 +0100)]
Update JS console.println so that it prints to fz_stddbg.
Sebastian Rasmussen [Fri, 23 Jul 2021 01:07:07 +0000 (03:07 +0200)]
gl/x11: Cope with error while trying to handle relative URI.
Sebastian Rasmussen [Fri, 23 Jul 2021 10:20:48 +0000 (12:20 +0200)]
Remember to push empty clip onto draw stack in error case.
Commit
b1e505d1824d4356e48ce9e11cc5a02d6fa785dc accidentally omitted
pushing an empty clip onto the draw stack when returning early from
fz_draw_clip_image_mask(). The calling function assumes that the
clip is always pushed and so will always pop the clip. This situation
caused a later function to access the already popped clip causing a
segmentation fault.
This fixes OSS-fuzz issue 36463.
Sebastian Rasmussen [Thu, 22 Jul 2021 12:52:01 +0000 (14:52 +0200)]
js: Add interface to set a PDF document event listener.
This makes it possible to track alert events from PDF document when
e.g. field formatting or field value validation actions are triggered.
Sebastian Rasmussen [Thu, 22 Jul 2021 12:51:22 +0000 (14:51 +0200)]
js: Expose interface to get the widget field label.
This is useful when debugging to know what field is being a problem.
Sebastian Rasmussen [Wed, 21 Jul 2021 22:20:52 +0000 (00:20 +0200)]
js: Expose setting of widget editing state.
Sebastian Rasmussen [Wed, 21 Jul 2021 22:53:31 +0000 (00:53 +0200)]
js: Use the API that will include any locally synthesised changes.
Sebastian Rasmussen [Thu, 22 Jul 2021 12:39:05 +0000 (14:39 +0200)]
Plug leak of recalculation action result.
Robin Watts [Thu, 22 Jul 2021 11:53:25 +0000 (12:53 +0100)]
Bug 704078: Resolve stray javascript validation events.
pdf_field_event_format is calling the keystroke event, rather than
the format event. This means we are giving spurious warnings at
unexpected times (document load/widget resynthesis etc).
The fix is just to call the correct event. Credit to Tor for spotting
the 1 character typo!
Robin Watts [Wed, 21 Jul 2021 17:14:56 +0000 (18:14 +0100)]
Update pdf_update_page to cope with local xrefs.
pdf_update_page runs across all the annotations on a page
calling pdf_update_annot. This in turn calls pdf_update_appearance.
A call to pdf_update_appearance can either a) do nothing,
b) synthesise an appearance in a local_xref or c) synthesise
an appearance in the real document, discarding any local_xref.
Thus a call to update the appearance of an annotation that does c)
can 'undo' the update of earlier annotations.
The fix for this is to spot the change, and to rerun the updates
for earlier annotations. This requirement is now documented in
the header file.
We update the implementation of pdf_update_page to perform this
correctly.
We also take the opportunity to hide pdf_update_appearance from
the API, as people should just be calling pdf_update_annot.
Sebastian Rasmussen [Tue, 20 Jul 2021 18:19:19 +0000 (20:19 +0200)]
Remove unused function causing compilation warning.
Robin Watts [Wed, 21 Jul 2021 15:46:16 +0000 (16:46 +0100)]
Bug 704045: Purge local_xref keyed objects from store on local_xref destruction.
This avoids us being left with fonts in the store keyed on
objects that no longer exist.
Part of this commit is that we make pdf_is_local_object respond
whether the xref is in force or not. The current place it is
called from always has the local xref in force, so this doesn't
alter any behaviour.
Robin Watts [Wed, 21 Jul 2021 15:32:14 +0000 (16:32 +0100)]
Extend PDF_DEBUG_APPEARANCE_SYNTHESIS printouts.
Disabled by default, obviously.
Robin Watts [Wed, 21 Jul 2021 15:31:40 +0000 (16:31 +0100)]
Add pdf_debug_doc_changes debug function.
Sebastian Rasmussen [Fri, 16 Jul 2021 14:14:40 +0000 (16:14 +0200)]
Bug 704045: Consider all used local xref entries as being local.
The document from the bug has three unsigned signature fields, each
with an appearance stream consisting of the empty string. Before this
commit only one would be visibly rendered, while the two others would
still be there but not have any visible appearance rendered.
The reason that the first unsigned signature field is visible is that
when loading annotations pdf_update_appearance() is called for that
field it detects that it has an appearance stream but according to
pdf_is_local_object() that it is not local, i.e. not synthesised by
MuPDF. This causes MuPDF to first create a local xref, then do local
synthesis for the signature field, which means that the generated
appearance stream ends up in the local xref. The reason for it to be
stored there is that it should not be considered a change to the
document that would make it to file if the document is saved.
When the second unsigned signature field is specified when calling
pdf_update_appearance() MuPDF will simiarly detect that it has an
appearance stream, but when checking whether this appearance is local
there is a local xref in force. The object entry corresponding to the
stream is checked whether it is marked 'f'ree. Since the object has
never been stored into the local xref the entry is marked 0 as in
unused. This causes pdf_is_local_object() to return true, which in
turn causes pdf_update_appearance() to deduce that the appearance is
local, i.e. synthesised by MuPDF, thus no local synthesis is
performed. This is incorrect.
pdf_is_local_object() should treat any used entries in the local
xref as being local, and any unused entries as being non-local. E.g.
entries marked 'n'ew, 'o'bject stream or 'f'ree should all be
considered local, only entries marked 0 should be considered to be
non-local. This commit fixes this issue.
Sebastian Rasmussen [Thu, 15 Jul 2021 14:04:19 +0000 (16:04 +0200)]
Bug 704045: Set all annotations affected as changed.
Previously not all annotations belonging to a radio group would be
set as changed, hence pdf_update_annot() would not return TRUE to
indicate that its visual appearance had changed.
Sebastian Rasmussen [Thu, 15 Jul 2021 14:03:20 +0000 (16:03 +0200)]
Bug 704045: Generalize processing of opened document pages.
Robin Watts [Tue, 20 Jul 2021 17:27:35 +0000 (18:27 +0100)]
Bug 704045: pdf_set_annot_appearance_from_display_list should not dirty annot.
'Dirtying' an annotation marks it as needing to have its appearance
stream resynthesised. When we set the appearance of an annotation,
we should not dirty it, becase we have just set the appearance
stream. Therefore, remove this call.
Robin Watts [Tue, 20 Jul 2021 17:03:25 +0000 (18:03 +0100)]
Check entry is not NULL before dereferencing it.
In refactoring within prepare_object_for_alteration, I'd moved
a section of code to before we check whether entry is NULL.
Robin Watts [Mon, 19 Jul 2021 12:09:18 +0000 (13:09 +0100)]
Remove the dirty flag from pdf_document.
Previously, we have tracked whether a document contains changes
by using a 'dirty' flag, that we have had to keep up to date
during edits.
Here, we move to remove it entirely, and instead base our
choice of 'dirty or not' upon whether the incremental xref
contains any objects.
This means we can now do things like:
1) Load a document, tick a checkbox (doc appears dirty),
undo (doc appears clean), redo (doc appears dirty),
save snapshot, undo (doc appears clean).
2) Reload the snapshot (doc appears dirty), undo (doc appears clean).
Robin Watts [Mon, 19 Jul 2021 17:53:47 +0000 (18:53 +0100)]
Tweak trailer object handling for snapshotting.
When we read a document in, if it has a new format xref, we read
the trailer object and insert it into the xref entry. We have
(until now) forgotten to set the parent number for that object.
Do so.
When we read a journal in, if we 'reopen' the incremental section
of the document, remove the trailer object we read from the xref.
This will be recreated anyway on any future save.
The advantage of doing this is that it puts us back into the same
state as we would be had we never snapshotted and reloaded (which
is, after all, the purpose of snapshotting).
This sets us up nicely to be able to "undo" back to a state of
"no changes" (based upon the contents of the incremental xref).
Robin Watts [Mon, 19 Jul 2021 17:53:08 +0000 (18:53 +0100)]
Avoid stray objects in incremental xref after pdf_delete_object.
When we create an object, it is put into the incremental xref.
If we delete that object, then a 'free' object is overwritten
in its place.
We have it in mind to move to spotting objects in the incremental
xref as meaning 'we have unsaved changes', and this is scuppered
by having needless 'free' objects in there.
Objects that existed in previous versions of the document and have
now been removed, certainly need to have 'free' object entries
(and these should count as changes). Objects that have never
existed until this version should be deleted entirely, by being
given a 0 type (and hence should not count as changes).
Accordingly in pdf_delete_object, we check back through the
previous xrefs; if the most recent entry for this object is free
(or if there is no reference at all), then we know we can delete
it by removing the entry entirely.
Robin Watts [Mon, 19 Jul 2021 15:27:53 +0000 (16:27 +0100)]
Tweak where we gridfit images, so it happens before subarea.
Currently, we find any subarea of an image we can restrict our
rendering too, decode that area, and then grid fit that reduced
area. This means that rendering in tiles, we might get different
results to rendering the whole page - something that really ought
not to happen.
Move the gridfitting out of fz_paint_image (and
fz_paint_image_with_color) into the callers, before the subarea
calculations are done.
This restores sanity.
Robin Watts [Mon, 19 Jul 2021 15:16:23 +0000 (16:16 +0100)]
Fix graphical glitches seen with undying-dusk.pdf
Apply same subarea logic to clipping images as to drawing images.
The difference between taking a subarea of an image and then
gridfitting it (as we were doing when filling) and gridfitting
the entire image (as we were doing when clipping) was causing
stray 'gaps' in images.
Robin Watts [Mon, 19 Jul 2021 15:31:37 +0000 (16:31 +0100)]
Remove ALT-Right support in mupdf-x11 (and mupdf on windows).
We don't support going 'forwards' in history yet, so the previously
set up mapping for Alt-Right was incorrect.
Robin Watts [Mon, 19 Jul 2021 11:38:27 +0000 (12:38 +0100)]
Support ALT-Left, ALT-Right in both mupdf and mupdf-gl.
Thanks to Lucas Cimon for the suggestion.
Robin Watts [Tue, 13 Jul 2021 09:52:53 +0000 (10:52 +0100)]
Fix Leptonica to use MuPDF memory allocators.
A typo in the Leptonica build options was causing Leptonica to use
native malloc/free on non-windows platforms.
Tesseract allocates via new/delete/new[]/delete[]. While these
can be trapped (see tessocr.cpp in the Ghostscript source for
an example of how), this does not help us here.
Tesseract calls new/delete etc as part of the static init it does
on startup. This means that any redirection of new/delete to
other allocators would have to happen before MuPDF starts up. This
does not fit with MuPDF's method of having the allocators defined
in the context.
We therefore live with Tesseract using the standard allocators
(new/delete). If this really is a problem for any particular
integrator, then we work with them to hardwire in allocator changes.
Sebastian Rasmussen [Tue, 13 Jul 2021 12:41:19 +0000 (14:41 +0200)]
Plug leaks of name PDF objects when setting annotation appearance.
Sebastian Rasmussen [Mon, 12 Jul 2021 16:09:55 +0000 (18:09 +0200)]
Estimate negative stream lengths as being zero.
PDF object 5 in tests_private/pdf/customer394/problems/normal_994.pdf
has a /Length field of -1121. In pdf_load_image_stream() we propagate
this signed integer value to an unsigned size_t and it gets
interpreted as a large value, causing a memory allocation to fail and
the PDF not to be rendered.
This commit adapts the stream length guessing function to assume that
negative lengths are supposed to be zero. This guess is probably not
the correct stream length, so warnings about incorrect stream lengths
are likely. After this commit MuPDF can parse and render normal_994.pdf
with warnings.
Sebastian Rasmussen [Sat, 10 Jul 2021 11:57:16 +0000 (13:57 +0200)]
Bug 704035: Adjust size of buffer for glyph name.
Sebastian Rasmussen [Fri, 9 Jul 2021 14:46:34 +0000 (16:46 +0200)]
Avoid new gcc-11 warning about mismatched array bounds.
gcc-11 introduced -Warray-parameter that produces the warnings
this commit fixes.
Sebastian Rasmussen [Fri, 9 Jul 2021 11:07:09 +0000 (13:07 +0200)]
Avoid more aggressive gcc-11 warning about accessing undersized arrays.
Starting from gcc-11 -Wstringop-overflow now produces the warnings
this commit fixes.
Robin Watts [Wed, 7 Jul 2021 23:12:53 +0000 (00:12 +0100)]
Add FZ_UNUSED to fz_keep_page_locked definition.
Avoids warning. Thanks to malc for the report and patch.
Sebastian Rasmussen [Sat, 3 Jul 2021 00:38:32 +0000 (02:38 +0200)]
When selecting appearance stream fall back to AP/N when AP/R is missing.
The mouse pointer location and mouse button state are used to select
the current annotation appearance stream. Those two states are
converted into the annotation properties hot and active. Hot is when
the mouse pointer is hovering over the annotation, while active is
when the annotation has grabbed mouse input because the mouse pointer
was pressed down while on top of it.
The algorithm for selecting the current appearance stream looked like this:
* if annotation is hot and active select AP/D
* otherwise if annotation is hot select AP/R
* otherwise select AP/N
This worked well for annotations that have all appearance streams present:
1. Mouse pointer outside annotation => AP/N was selected.
2. Mouse pointer moved to hover over annotation => AP/R was selected.
3. Mouse button pressed => AP/D was selected.
4. Mouse button released => AP/R was selected.
5. Mouse pointer moved outside annotation => AP/N was selected.
For annotations that only had AP/N and AP/D, but were lacking AP/R, this
approach caused no appearance stream to be selected in step 4, and the
annotation was not rendered until step 5 when it reappeared.
To resolve this issue MuPDF this commit implements a fall back mechanism,
such that AP/N would be used instead of AP/R in step 4 above:
* if annotation is hot and active and AP/D is present, select AP/D
* otherwise if annotation is hot and AP/R is present, select AP/R
* otherwise select AP/N
After this commit MuPDF again selects annotation appearance streams
the same way was Acrobat Reader.
Sebastian Rasmussen [Sat, 3 Jul 2021 00:14:06 +0000 (02:14 +0200)]
gl: Only trigger widget enter events if they were not previously hot.
Robin Watts [Wed, 7 Jul 2021 09:54:21 +0000 (10:54 +0100)]
Fix race condition in reflow_layout.
There was a race condition between us dropping 'kept', relocking,
and using 'page'.
Robin Watts [Wed, 7 Jul 2021 09:53:16 +0000 (10:53 +0100)]
Fix buffer leakage in reflow_load_page.
Robin Watts [Fri, 4 Jun 2021 14:47:15 +0000 (15:47 +0100)]
Add reflow document handler.
Robin Watts [Thu, 1 Jul 2021 14:45:59 +0000 (15:45 +0100)]
Add fz_keep_page_locked.
Internal function required to avoid race condition while walking
the open page lists for a document.
Robin Watts [Mon, 5 Jul 2021 14:59:59 +0000 (15:59 +0100)]
Accelerate premultiplied data case for calling lcms2.
Spot when whole lines are 0 or 1.
Robin Watts [Mon, 5 Jul 2021 14:59:04 +0000 (15:59 +0100)]
Update lcms2mt to latest lcms2.
Also add accelerations for alpha cases.