Commit Graph

2899 Commits

Author SHA1 Message Date
Jonas Jenwald
4cedc12341 Restore the collectFields parameter in the Annotation code (issue 17000)
Rather than trying to be "clever" here, and possibly affect code readability negatively, let's just restore the `collectFields` parameter to address the unneeded parsing that now happens when printing new Annotations.
2023-09-21 19:49:31 +02:00
Jonas Jenwald
0ac8f33e13 Ignore optional content with missing /Type-entries
In the rare situation that an optional content dictionary lacks a /Type-entry we currently throw, which may prevent e.g. Form XObjects from rendering completely.

Fixes https://bugs.ghostscript.com/show_bug.cgi?id=707147
2023-09-19 14:11:03 +02:00
calixteman
3afb717eed
Merge pull request #16938 from calixteman/update_struct_tree
[Editor] Add the ability to create/update the structure tree when saving a pdf containing newly added annotations (bug 1845087)
2023-09-18 13:04:52 +02:00
Calixte Denizet
a8573d4e1b [Editor] Add the ability to create/update the structure tree when saving a pdf containing newly added annotations (bug 1845087)
When there is no tree, the tags for the new annotions are just put under the root element.
When there is a tree, we insert the new tags at the right place in using the value
of structTreeParentId (added in PR #16916).
2023-09-16 18:34:58 +02:00
Jonas Jenwald
0304b65fcd Remove the closure from the CipherTransformFactory class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-16 16:34:24 +02:00
Tim van der Meij
7f8de83e96
Merge pull request #16957 from Snuffleupagus/SaveDocument-more-await
Use `await` even more in the "SaveDocument" worker-thread handler
2023-09-16 14:31:05 +02:00
Tim van der Meij
89c8f90a14
Merge pull request #16956 from Snuffleupagus/opMap-rm-getLookupTableFactory
Simplify the `EvaluatorPreprocessor.opMap` getter a little bit
2023-09-16 13:51:33 +02:00
Jonas Jenwald
ff96c413d3 Use await even more in the "SaveDocument" worker-thread handler
Given that the function is already asynchronous we can make use of `await` even more and reduce the amount of indentation a little bit.
2023-09-16 13:06:48 +02:00
Jonas Jenwald
316d1ec5ef Simplify the EvaluatorPreprocessor.opMap getter a little bit
Given that this is a shadowed getter, the `opMap` is already lazily initialized and it shouldn't be necessary to *also* use the `getLookupTableFactory` helper function here. Looking at the history of the code, it seems that this is simply a leftover from before JavaScript classes existed.
2023-09-16 12:26:38 +02:00
Jonas Jenwald
8cb5d01acd Remove the closure from the LabCS class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-16 12:20:14 +02:00
Jonas Jenwald
52fa66a98b Remove the closure from the CalRGBCS class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-16 12:20:12 +02:00
Jonas Jenwald
4d615f087f Remove the closure from the CalGrayCS class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-15 15:53:16 +02:00
Jonas Jenwald
d2c8997380 Remove the closure from the DeviceCmykCS class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-15 15:53:05 +02:00
Jonas Jenwald
628ca737dd Make it possible to clear the cache, used by the getB function in src/core/pattern.js
While this cache will not contain a huge amount of data in practice, it's nonetheless a *global* cache that currently will never be cleared.

This patch also removes the existing closure, since it shouldn't really be necessary nowadays given that the code is a JavaScript module which means that only explicitly listed properties will be exported.
2023-09-15 12:23:06 +02:00
Jonas Jenwald
93ce7c5a89 Change the getB function, in src/core/pattern.js, to use the exponentiation operator 2023-09-15 11:46:00 +02:00
Jonas Jenwald
50937a3539 Ensure that the entire PDF document is loaded *before* we begin saving it
When I started looking at PR 16938 it occurred to me that some of the new structTree-methods are synchronously accessing certain dictionary-data (not used during "normal" structTree-parsing), which may not be generally safe since everything in a dictionary could be a reference (and the relevant data may not have been loaded yet).

Rather than suggesting that we make all those new methods even more asynchronous, to me the overall simplest and safest solution is to ensure that the *entire* PDF document has been loaded *before* we begin saving it. In practice this shouldn't really affect "performance" of saving noticeably, since it's always depended on the entire PDF document being downloaded.

Finally note that with the exception of the PDF document possibly not having been fully downloaded when saving is triggered, all other "global" document properties are pretty much guaranteed to already be available at this point.
2023-09-12 13:26:57 +02:00
Jonas Jenwald
18a661b6a0
Merge pull request #16920 from Snuffleupagus/annotationGlobals
Slightly reduce asynchronicity when parsing Annotations
2023-09-09 09:55:49 +02:00
Calixte Denizet
52cc1220e4 Simplify writeObject function
It'll avoid to have the duplication of the code to get the encrypt transform,
and last but not least, it'll avoid to forget about encryption.
2023-09-08 19:59:59 +02:00
Jonas Jenwald
b5b061cdb6 Slightly re-factor the parameter handling in Catalog.parseDestDictionary
While it makes sense to check that the `destDict` parameter is indeed a Dictionary, since that data comes from the PDF document itself, the `resultObj` parameter is an internal PDF.js implementation detail that should always be correct (or tests will fail).
2023-09-08 13:27:31 +02:00
Jonas Jenwald
df9cce39c0 Slightly reduce asynchronicity when parsing Annotations
Over time the amount of "document level" data potentially needed during parsing of Annotations have increased a fair bit, which means that we currently need to ensure that a bunch of data is available for each individual Annotation.
Given that this data is "constant" for a PDF document we can instead create (and cache) it lazily, only when needed, *before* starting to parse the Annotations on a page. This way the parsing of individual Annotations should become slightly less asynchronous, which really cannot hurt.

An additional benefit of these changes is that we can reduce the number of parameters that need to be explicitly passed around in the annotation-code, which helps overall readability in my opinion.

One potential drawback of these changes is that the `AnnotationFactory.create` method no longer handles "everything" on its own, however given how few call-sites there are I don't think that's too much of a problem.
2023-09-08 13:27:27 +02:00
Calixte Denizet
a8a50c567a Construct the correct field name and strip out classes when searching
The classes were stripped out during when creating the field name but
it led to a wrong name.
Since class components in a path are irrelevant, they're just ignored
when searching for a node in the datasets.
2023-09-07 15:56:47 +02:00
Calixte Denizet
d185db2b70 Add tagged annotations in the structure tree (bug 1850797) 2023-08-31 12:35:32 +02:00
Jonas Jenwald
ec3d2be761 Introduce more optional chaining in the code-base
Also, use logical OR assignment a bit more.
2023-08-26 10:52:23 +02:00
Jonas Jenwald
598421b11f
Merge pull request #16856 from Snuffleupagus/limit-lineEndings
Exclude `lineEndings`, in Annotation-data, in MOZCENTRAL builds (PR 14899 follow-up)
2023-08-24 15:58:32 +02:00
Calixte Denizet
24b480fabe Don't reset all fields when the resetForm argument is an array
correctly set the readonly property in the annotation layer and set the default checkbox value to Off when none is provided.
2023-08-24 09:10:27 -04:00
Calixte Denizet
ee3ac35e05 Revert fix for bug 1838855 (bug 1849876)
The issue described in the mentioned bug is reall because
Acrobat is rendering the XFA instead of the Acroform.
The original patch just tried to workaround the issue but it
induces some regressions.
2023-08-23 12:34:41 -04:00
Jonas Jenwald
cd181eb746 Exclude lineEndings, in Annotation-data, in MOZCENTRAL builds (PR 14899 follow-up)
This was added in PR 14899, over a year ago, however it's still completely unused in the PDF.js library/viewer. In hindsight I think that it was a mistake to add unused functionality, and the issue should probably have been WONTFIXed instead, however we probably can't just remove it now.
Thanks to the pre-processor, we can at least exclude this code in the *built-in* Firefox PDF Viewer.
2023-08-21 10:15:04 +02:00
Jonas Jenwald
4d19db0b19 Re-format the code to account for prettier and globals updates
The `prettier` update slightly changed the formatting of some await-expressions; please see https://github.com/prettier/prettier/blob/main/CHANGELOG.md#302

The `globals` update removed the need for some eslint-disable statements; please see https://github.com/sindresorhus/globals/releases/tag/v13.21.0
2023-08-19 09:30:34 +02:00
Jonas Jenwald
6669a99299 Remove the "no-babel-preset" comment used with the LIB build-target (PR 16829 follow-up)
Similar to the changes in PR 16829, this no longer seems necessary now.
2023-08-13 08:55:58 +02:00
Jonas Jenwald
389a26c115 Fallback to check all pages when getting the pageIndex of FieldObjects
Given that the FieldObjects are parsed in parallel, in combination with the existing caching in the `getPage`-method and `annotations`-getter, adding additional caches for this fallback code-path doesn't seem entirely necessary.
2023-08-10 17:10:04 +02:00
Calixte Denizet
7a5b3423d6 [Editor] Don't forget to encrypt image streams (see issue #16821)
and encrypt a compressed stream after having been compressed.
2023-08-10 15:19:45 +02:00
Jonas Jenwald
ec7746350d Introduce even more optional chaining in the code-base
This replaces a few more small/simple if-statements with optional chaining.
2023-08-09 17:04:54 +02:00
Jonas Jenwald
2e9f2e630c
Merge pull request #16804 from Snuffleupagus/issue-16800
Take fill-alpha into account with default icons for FileAttachment annotations (issue 16800)
2023-08-08 16:39:37 +02:00
Jonas Jenwald
e2819d0c67 Take fill-alpha into account with default icons for FileAttachment annotations (issue 16800) 2023-08-08 15:53:48 +02:00
Calixte Denizet
e2f20a1afe [Annotation] Strip out the array index in the path only when the path is from a terminal node (bug 1847733) 2023-08-08 15:05:27 +02:00
Jonas Jenwald
64e8557fb5 [api-minor] Deprecate the PDFDocumentProxy.getJavaScript method
This method is very old, however with the exception of the auto-print hack (when scripting is disabled) in the viewer it's never actually been used.

Most likely the idea with `PDFDocumentProxy.getJavaScript` was that it'd be useful if scripting support was added, however it turned out that it was a bit too simplistic and instead a number of new methods were added for the scripting use-cases.
2023-08-01 09:02:05 +02:00
Calixte Denizet
71960bea64 Don't print hidden annotatons (bug 1815196)
and handle correctly the NoView and NoPrint flags when they're changed
from JS.
2023-07-31 13:04:15 +02:00
Jonas Jenwald
d6c0950389 Avoid eagerly matching "trailer"-strings when searching for incomplete objects in XRef.indexObjects (issue 16759, PR 15854 follow-up, bug 1845762)
When searching for "endobj"-operators, make sure that we don't accidentally match a "trailer"-string in /Content-streams without /Filter-entries (i.e. streams that contain "raw" and thus human-readable data).
2023-07-27 17:57:12 +02:00
Jonas Jenwald
c0fe96b8fe Additional *manual* unicorn/prefer-ternary changes
Not all cases could be automatically fixed, and the changes also triggered a number of `prefer-const` errors that needed to be handled manually.
2023-07-27 09:48:24 +02:00
Jonas Jenwald
674e7ee381 Enable the unicorn/prefer-ternary ESLint plugin rule
To limit the readability impact of these changes, the `only-single-line` option was used; please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-ternary.md

These changes were done automatically, using the `gulp lint --fix` command.
2023-07-27 09:18:26 +02:00
Jonas Jenwald
3b6d2554a8 Fix copying of the reduced Planck constant
Please see https://en.wikipedia.org/wiki/H_with_stroke
2023-07-24 18:42:46 +02:00
calixteman
71f113bf85
Merge pull request #16718 from calixteman/bug1844572
Don't replace Acroform dictionary if nothing has changed when saving (bug 1844572)
2023-07-24 10:00:43 +02:00
Calixte Denizet
33fdec1392 Don't replace Acroform dictionary if nothing has changed when saving (bug 1844572) 2023-07-22 17:51:06 +02:00
Jonas Jenwald
c018070e80 Enable the no-lonely-if ESLint rule
These changes were mostly done automatically, using `gulp lint --fix`, and only a few spots with comments needed manual tweaking; please see https://eslint.org/docs/latest/rules/no-lonely-if
2023-07-21 20:10:44 +02:00
Calixte Denizet
d470e91223 Don't get the text content for an annotation when /NeedAppearances is true (bug 1844583)
When the flag is set, the appearance has to be generated from the value so it's
useless/meaningless to extract the content from the existing appearance.
2023-07-21 12:26:27 +02:00
Calixte Denizet
9277801493 Text annotations must use their own canvas when their appearance is generated (bug 1844576)
When a pdf has /NeedAppearances set to true, the annotation appearance must be
generated from its value and we must take into account the hasOwnCanvas property.
2023-07-21 09:51:50 +02:00
Jonas Jenwald
88524bf9ae Don't reset temporary XRef-entries during saving (PR 16392 follow-up)
*Please note:* I'm not aware of any bugs caused by this, however that might be more luck than anything else.

In PR 16392 the `incrementalUpdate` function, and all of its various helpers, were made asynchronous. However the call-site in `src/core/worker.js` wasn't updated, which means that we currently reset temporary XRef-entries while saving is ongoing.
2023-07-20 15:49:59 +02:00
Calixte Denizet
7ac3bf6f17 [Editor] Don't forget to generate non-missing images when printing (bug 1844036) 2023-07-18 15:39:18 +02:00
Jonas Jenwald
3a886e7264 Move the isNodeJS-helper into the src/shared/util.js file
With the changes in the previous patch the `isNodeJS`-helper no longer needs to live in its own file, which helps get rid of a closure in the *built* files.
2023-07-17 16:42:25 +02:00
Jonas Jenwald
9660ca53af Enable more ESLint unicorn plugin rules
- `prefer-array-some`, which didn't require any code changes; please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-some.md

 - `prefer-modern-math-apis`, which should be fine given the currently supported browsers; please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-modern-math-apis.md
2023-07-16 09:24:14 +02:00