Commit Graph

13667 Commits

Author SHA1 Message Date
Tim van der Meij
fafe039849
Merge pull request #13008 from timvandermeij/webpack-stream
Allow minor and patch versions for the `webpack-stream` dependency again
2021-02-21 15:21:38 +01:00
Tim van der Meij
62d5b15a24
Allow minor and patch versions for the webpack-stream dependency again
Fixes #11996.
2021-02-21 15:13:41 +01:00
Tim van der Meij
f3aa4408a5
Merge pull request #13005 from calixteman/colors
JS - Fix setting a color on an annotation
2021-02-21 14:50:03 +01:00
Tim van der Meij
34fd197621
Merge pull request #13007 from Snuffleupagus/update-packages
Update packages and translations
2021-02-21 14:37:43 +01:00
Jonas Jenwald
476230bd17 Update l10n files 2021-02-21 12:07:32 +01:00
Jonas Jenwald
385bf67bc9 Update npm packages 2021-02-21 11:52:55 +01:00
Tim van der Meij
2194fb940d
Merge pull request #13004 from Snuffleupagus/cancelBound
Add a `this`-bound method for `InternalRenderTask.cancel`
2021-02-20 18:50:31 +01:00
Calixte Denizet
4a5f1d1b7a JS - Fix setting a color on an annotation
- strokeColor corresponds to borderColor;
 - support fillColor and textColor;
 - support colors on the different annotations;
 - fix typo in aforms (+test).
2021-02-20 15:24:37 +01:00
Jonas Jenwald
d69cf702f3 Add a this-bound method for InternalRenderTask.cancel
This is similar to the other methods, and the only reason for this not having been done originally is that the `cancel` functionality is a later addition.
2021-02-20 14:47:57 +01:00
Tim van der Meij
3d80c21a8e
Merge pull request #13001 from Snuffleupagus/AnnotationStorage-serializable
Send the `AnnotationStorage`-data to the worker-thread as a `Map`
2021-02-19 00:01:44 +01:00
Jonas Jenwald
e9038cc3d1 Send the AnnotationStorage-data to the worker-thread as a Map
Rather than converting the `AnnotationStorage`-data to an Object, before sending it to the worker-thread, we should be able to simply send the internal `Map` directly.
The "structured clone algorithm" doesn't have a problem with `Map`s, however the `LoopbackPort` used when workers are *disabled* (e.g. in Node.js environments) didn't use to support them. With PR 12997 having lifted that restriction, we should now be able to simply send the `AnnotationStorage`-data as-is rather than having to iterate through it to first create an Object.

*Please note:* The changes in `src/core/annotation.js` could have been a lot more compact if we were able to use optional chaining in the `src/core` folder. Unfortunately that's still not possible, since SystemJS is being used in the development viewer (i.g. `gulp server`) and fixing that is *still* blocked by [bug 1247687](https://bugzilla.mozilla.org/show_bug.cgi?id=1247687).
2021-02-18 17:13:43 +01:00
calixteman
0fa9976268
XFA - Add support for prototypes (#12979)
- specifications: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=225&zoom=auto,-207,784
 - add a clone method on nodes in order to be able to clone a proto;
 - support ids in template namespace;
 - prevent from cycle when applying protos.
2021-02-18 10:32:25 +01:00
Tim van der Meij
4619b1b568
Merge pull request #12997 from Snuffleupagus/metadata-worker
Move the Metadata parsing to the worker-thread
2021-02-17 20:57:46 +01:00
Tim van der Meij
77862bdb8e
Merge pull request #12999 from Snuffleupagus/LoopbackPort-rm-sync
[api-minor] Remove support for synchronous event dispatching in `LoopbackPort`
2021-02-17 20:39:54 +01:00
Tim van der Meij
1d3af89cae
Merge pull request #12998 from Snuffleupagus/renderInteractiveForms-defaults
Simplify the default value handling of `renderInteractiveForms` in the viewer components
2021-02-17 20:37:03 +01:00
calixteman
b5be515375
XFA - Add a lexer/parser for FormCalc language (#12936)
- the language specifications are: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=1049
 - it can be used to:
   * as a scripting language for calculation, validations, ...
   * in SOM expressions to select nodes: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=101
2021-02-17 20:28:06 +01:00
Brendan Dahl
4de8b7e433
Merge pull request #12830 from calixteman/field
JS -- Fix doc.getField and add missing field methods
2021-02-17 10:38:09 -08:00
Jonas Jenwald
3398070e26 [api-minor] Remove support for synchronous event dispatching in LoopbackPort
*Please note:* The `defer` parameter has been enabled by default ever since PR 9777 (in 2018), which first shipped in PDF.js release `2.0.943`.
With workers *disabled*, e.g. in Node.js environments, this has been used ever since without any problems reported[1].

The impetus for this change was that I happened to notice that *if* the `LoopbackPort` was used with synchronous event dispatching, we'd simply send that data as-is to the listeners. This created an inconsistency in the data returned from the `pdf.worker.js` file, since `postMessage` used with *actual* workers (or the `LoopbackPort` with `defer = true`) will ignore/throw when encountering unclonable data.
Originally my intention was simply to just call `cloneValue` regardless of the event dispatching used in `LoopbackPort`, however looking at the use-cases (or lack thereof) of the `LoopbackPort` it seemed reasonable to simply remove the `defer` parameter instead.

This patch is tagged "[api-minor]" since the `LoopbackPort` is still exposed in the API, although I really hope that no third-party is using this (since disabling workers leads to bad performance).

Finally, this patch changes a `forEach` loop to `for...of` and makes uses of optional changing in existing code.

---
[1] As evident by the `npm test` command run by Github Actions, and previously by Travis.
2021-02-17 16:12:29 +01:00
Jonas Jenwald
d366bbdf51 Move the encodeToXmlString helper function to src/core/core_utils.js
With the previous patch this function is now *only* accessed on the worker-thread, hence it's no longer necessary to include it in the *built* `pdf.js` file.
2021-02-17 13:12:01 +01:00
Jonas Jenwald
b66f294f64 Move the XML-parser to the src/core/-folder
With the previous patch this functionality is now *only* accessed on the worker-thread, hence it's no longer necessary to include it in the *built* `pdf.js` file.
2021-02-17 13:12:01 +01:00
Jonas Jenwald
cc3a6563ee Move the Metadata parsing to the worker-thread
The only reason, as far as I can tell, for parsing the Metadata on the main-thread is how it was originally implemented. When Metadata support was first implemented, it utilized the [`DOMParser`](https://developer.mozilla.org/en-US/docs/Web/API/DOMParser) which isn't available in workers.
Today, with the custom XML-parser being used, that's no longer an issue and it seems reasonable to move the Metadata parsing to the worker-thread[1], since that's where all parsing should happen (for performance reasons).

Based on these changes, we'll be able to reduce the now unnecessary duplication of the XML-parser (and related code) in both of the *built* `pdf.js`/`pdf.worker.js` files.

Finally, this patch changes the `_repair` method to use "Array + join" rather than string concatenation.

---
[1] This needed the previous patch, to enable sending of `Map`s between threads with workers disabled.
2021-02-17 13:12:01 +01:00
Jonas Jenwald
73bf45e64b Support Map and Set, with postMessage, when workers are disabled
The `LoopbackPort` currently doesn't support `Map` and `Set`, which it should since the "structured clone algorithm" used in browsers does support both of them; please see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types
2021-02-17 13:11:59 +01:00
Calixte Denizet
ccef734ebb Remove Promise.all and async+done from unit/scripting_spec 2021-02-17 11:19:39 +01:00
Jonas Jenwald
0a28e51e40 Simplify the default value handling of renderInteractiveForms in the viewer components
I happened to look at this code, and I can't for the life of me figure out why I didn't just implement it like this patch in the first place (since the current format feels overly verbose).
2021-02-17 10:47:55 +01:00
Calixte Denizet
82f75a8ac2 JS -- Fix doc.getField and add missing field methods
- getField("foo") was wrongly returning a field named "foobar";
 - field object had few missing unimplemented methods
2021-02-17 10:42:52 +01:00
Tim van der Meij
952bc08ec0
Merge pull request #12995 from Snuffleupagus/errorFontMissing-no-fallback-bar
Stop showing the fallback bar for "errorFontMissing" errors (PR 11218 follow-up)
2021-02-16 22:43:13 +01:00
Tim van der Meij
bab059d8fd
Merge pull request #12964 from calixteman/12963
Avoid infinite loop when getting annotation field name
2021-02-16 22:36:24 +01:00
Jonas Jenwald
9887644702 Stop showing the fallback bar for "errorFontMissing" errors (PR 11218 follow-up)
*This is somewhat similar to PR 12931.*

For PDF documents where fonts are completely missing in the /Resources dictionaries, there's basically no "correct" way of rendering the document.
Hence it's very unlikely that another PDF viewer will do a better job than PDF.js in these cases, and consequently it seems highly questionable if the fallback bar really helps here.
2021-02-16 16:29:13 +01:00
Tim van der Meij
b5735f2017
Merge pull request #12993 from Snuffleupagus/metadata-subject
[api-minor] Change the `dc:subject` Metadata field to an Array
2021-02-15 20:27:34 +01:00
Calixte Denizet
0fc8267576 Avoid infinite loop when getting annotation field name
- aims to fix issue #12963;
 - use a Set to track already visited objects;
 - remove the loop limit in getInheritableProperty and use a RefSet too.
2021-02-14 19:58:19 +01:00
Jonas Jenwald
b26c7974fe [api-minor] Change the dc:subject Metadata field to an Array
This patch simply extends the existing handling of the `dc:creator` field, which should hopefully suffice here; please refer to https://wwwimages2.adobe.com/content/dam/acom/en/devnet/xmp/pdfs/XMP%20SDK%20Release%20cc-2016-08/XMPSpecificationPart1.pdf#page=34
2021-02-14 17:16:40 +01:00
Tim van der Meij
f892c00275
Merge pull request #12991 from Snuffleupagus/viewer-Firefox-rm-misc-code
Stop including unused/unnecessary code in the viewer, for `MOZCENTRAL`-builds
2021-02-14 15:17:16 +01:00
Tim van der Meij
b9beca90c7
Merge pull request #12992 from Snuffleupagus/scripting-compact-fallback-events
Use a more compact format for the fallback EventBus-listeners in `PDFViewerApplication_initializeJavaScript`
2021-02-14 15:13:48 +01:00
Jonas Jenwald
209fe60472 Use a more compact format for the fallback EventBus-listeners in PDFViewerApplication_initializeJavaScript
Given that these event listeners should essentially never be needed, but are included simply to avoid breakage in edge-cases, it can't hurt to make this code slightly less verbose.
2021-02-14 12:37:37 +01:00
Jonas Jenwald
48f4580991 A couple of small BaseViewer tweaks
- Mark `BaseViewer.initializeScriptingEvents` as an `async` method, since that's actually how it's being used in the default viewer (see `PDFViewerApplication-_initializeJavaScript`).

 - Change `BaseViewer._pageWidthScaleFactor` to access the *internal* scroll/spread-modes directly, rather than using the getters, since that's consistent with the rest of the code (and not just for these properties).
2021-02-14 12:32:50 +01:00
Jonas Jenwald
4c107d8d7c Remove the useless PresentationModeState.CHANGING-case in PDFCursorTools (PR 12788 follow-up)
For reasons that I now can't for the life of me understand, I included handling of the `PresentationModeState.CHANGING`-case despite it not actually doing anything.
2021-02-14 10:39:49 +01:00
Jonas Jenwald
1ca816d724 Directly use requestIdleCallback in MOZCENTRAL-builds
Given the following compatibility information, we really shouldn't need to check for the availability of `requestIdleCallback` in Firefox; see https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback#browser_compatibility
2021-02-14 10:39:42 +01:00
Jonas Jenwald
7f8a9b12d9 Stop including the "errorWrapper" HTML code in MOZCENTRAL-builds
Given that these HTML elements are not being used at all in `MOZCENTRAL`-builds, note the preprocessor check in `PDFViewerApplication._otherError`, we obviously don't need the HTML code either.
2021-02-14 10:39:34 +01:00
Tim van der Meij
c79fd71457
Merge pull request #12896 from calixteman/text_layer
Modifiy the way to compute baseline to have a better match between canvas and text layer
2021-02-13 15:12:58 +01:00
Tim van der Meij
4b639d5d44
Merge pull request #12988 from Snuffleupagus/rm-unneeded-MissingDataException
Remove unneeded `instanceof MissingDataException` checks
2021-02-13 13:07:01 +01:00
Jonas Jenwald
1ee747a620 Remove unneeded instanceof MissingDataException checks
The following checks are all unneeded, and could easily cause confusion when reading the code. (All of them are my fault as well, since I've sometimes added those checks without really thinking about the surrounding code.)

 - In `PartialEvaluator.hasBlendModes` there cannot be any `MissingDataException`s thrown, given that the `Page.getOperatorList` method waits for all the necessary /Resources to load first. Furthermore, note also that if an error is thrown from `PartialEvaluator.hasBlendModes` then it'd completely break rendering of that page, since any errors thrown from `Page.getOperatorList` are simply sent to the main-thread.

 - In `PartialEvaluator.handleColorN` there cannot be any `MissingDataException`s thrown, given that again the `Page.getOperatorList` method waits for all the necessary /Resources to load before operatorList parsing starts.

 - In `XRef.readXRef` there cannot be any `MissingDataException`s thrown, given that we're *explicitly* requesting (and waiting for) the entire document in `pdfManagerReady` (in `src/core/worker.js`) before re-parsing of a corrupt document starts.
2021-02-13 12:26:05 +01:00
Brendan Dahl
3f3b01b710
Merge pull request #12759 from calixteman/font_size
Annotation -- Don't compute appearance when nothing has changed
2021-02-12 14:33:55 -08:00
Tim van der Meij
dee75c1764
Merge pull request #12986 from Snuffleupagus/rm-loading_error_indicator
Remove the unused "loading_error_indicator" l10n string (PR 2719 follow-up)
2021-02-12 21:25:37 +01:00
Calixte Denizet
ea06bb0e36 [api-minor] Annotation -- Don't compute appearance when nothing has changed
* don't set a value in annotationStorage by default:
   - having an undefined when the annotation is rendered for saving/printing means nothing has changed so use normal appearance
   - aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1681687
 * change the way to compute font size when this one is null in DA:
   - make fontSize proportional to line height
   - in multiline case, take into account the number of lines for text entered to adapt the font size
2021-02-12 19:27:21 +01:00
calixteman
a8021208ea
Restore window.alert after use in scripting test (#12987) 2021-02-12 14:19:58 +01:00
Jonas Jenwald
6e2ae2264b Remove the unused "loading_error_indicator" l10n string (PR 2719 follow-up)
This l10n string has been completely unused ever since PR 2719, which is now *eight* years ago.
2021-02-12 13:12:37 +01:00
Calixte Denizet
b4421b076a Modifiy the way to compute baseline to have a better match between canvas and text layer
- use ascent of the fallback font instead of the one from pdf to position spans
 - use TextMetrics.fontBoundingBoxAscent if available or
 - use a basic heuristic to guess ascent in drawing char on a canvas
 - compute ascent as a ratio of font height
2021-02-12 11:28:02 +01:00
dhufnagel
fc925827b2
fix initial state of checkboxes in display layer (#12904)
consider the export value when multiple checkboxes have the same name
2021-02-12 11:22:54 +01:00
Tim van der Meij
d5cad9ad3f
Merge pull request #12981 from Snuffleupagus/app-localizeMessage
Collect the l10n error/warning message lookup, in `web/app.js`, in a new helper method
2021-02-12 00:14:05 +01:00
Tim van der Meij
069d5b1086
Merge pull request #12984 from Snuffleupagus/more-Date-now
Replace a few `new Date().getTime()` instances with `Date.now()`
2021-02-12 00:06:45 +01:00