Commit Graph

14646 Commits

Author SHA1 Message Date
Jonas Jenwald
66c8a0897a Enable the ESLint object-shorthand rule in the extensions/chromium/-folder
Based on the following compatibility information, there can't be any compelling reason to not enable this ESLint rule now: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#browser_compatibility

See also https://eslint.org/docs/rules/object-shorthand
2021-08-22 12:33:02 +02:00
Tim van der Meij
83e1064360
Merge pull request #13920 from Snuffleupagus/issue-13916
Extend the glyph maps for standard respectively Calibri fonts (issue 13916)
2021-08-21 15:05:08 +02:00
Tim van der Meij
db11ba024d
Merge pull request #13899 from Snuffleupagus/includeAnnotationStorage-fix-caching
[Regression] Re-factor the *internal* `includeAnnotationStorage` handling, since it's currently subtly wrong
2021-08-21 15:04:28 +02:00
Tim van der Meij
1b3382f921
Merge pull request #13904 from Snuffleupagus/fix-LocalTilingPatternCache
Re-factor the LocalTilingPatternCache to cache by Ref rather than Name (PR 12458 follow-up, issue 13780)
2021-08-21 14:46:34 +02:00
Tim van der Meij
50dffdaf55
Merge pull request #13905 from Snuffleupagus/refactor-loadAndEnablePDFBug
Re-factor `loadAndEnablePDFBug` and `PDFBug.init`
2021-08-21 14:39:57 +02:00
Jonas Jenwald
ac27f96987 Extend the glyph maps for standard respectively Calibri fonts (issue 13916) 2021-08-21 00:48:38 +02:00
Jonas Jenwald
6b2c913413
Merge pull request #13913 from michael-yx-wu/mw/fix-typings
Fix pdf_viewer definitions
2021-08-20 22:10:30 +02:00
Michael Wu
acfb54a836 Fix pdf_viewer definitions
Current pdf_viewer definitions result in errors like the following when
trying to use them in a ts project:

[error] TypeScript error
node_modules/.pnpm/pdfjs-dist@2.10.377/node_modules/pdfjs-dist/web/pdf_viewer.d.ts:1:15
- error TS2691: An import path cannot end with a '.d.ts' extension.
Consider importing 'pdfjs-dist/types/web/pdf_viewer.component.js'
instead.

1 export * from "pdfjs-dist/types/web/pdf_viewer.component.d.ts";

Import/export statements in typescript should not include file extensions.
2021-08-20 12:23:43 -04:00
Brendan Dahl
3c8ee25e05
Merge pull request #13911 from Snuffleupagus/gulpfile-fix-TESTING-define
Ensure that the `TESTING` define can always be overridden in `gulpfile.js`
2021-08-19 13:15:47 -07:00
Jonas Jenwald
88d39e51c3 When running tests, enable XFA by default in the viewer (PR 13745 follow-up) 2021-08-19 20:13:19 +02:00
Jonas Jenwald
1f468e523f Ensure that the TESTING define can always be overridden in gulpfile.js
Currently a `TESTING = true` environment variable will *always* take precedence in the various build-tasks, and there's no way to explicitly disable it for a particular build. That's clearly an oversight on my part, however it's easy enough to fix this; sorry about breaking this!
2021-08-19 19:54:36 +02:00
Jonas Jenwald
bc8787b049 Re-factor loadAndEnablePDFBug and PDFBug.init
The `loadAndEnablePDFBug` helper function, in `web/app.js`, can be simplified a little bit by making it `async`. Furthermore, given how `PDFBug` is being used, we can also (slightly) re-factor `PDFBug.init` such that the `PDFBug.enable`-call is done internally rather than having to handle that manually at the call-site.

(Finally, utilize `await` more in the `loadFakeWorker` helper function.)
2021-08-19 12:06:23 +02:00
Jonas Jenwald
5f25fea0fe Re-factor the LocalTilingPatternCache to cache by Ref rather than Name (PR 12458 follow-up, issue 13780)
This way there cannot be any *incorrect* cache hits, since Refs are guaranteed to be unique.
Please note that the reason for caching by Ref rather than doing something along the lines of the `localShadingPatternCache` (which uses a `Map` directly), is that TilingPatterns are streams and those cannot be cached on the `XRef`-instance (this way we avoid unnecessary parsing).
2021-08-18 12:49:01 +02:00
Jonas Jenwald
8ee5acd85d Tweak handling of the onlyRefs-option in the BaseLocalCache class 2021-08-18 12:24:51 +02:00
Jonas Jenwald
a7f0301f21 [Regression] Re-factor the *internal* includeAnnotationStorage handling, since it's currently subtly wrong
*This patch is very similar to the recently fixed `renderInteractiveForms`-options, see PR 13867.*
As far as I can tell, this *subtle* bug has existed ever since `AnnotationStorage`-support was first added in PR 12106 (a little over a year ago).

The value of the `includeAnnotationStorage`-option, as passed to the `PDFPageProxy.render` method, will (potentially) affect the size/content of the operatorList that's returned from the worker (for documents with forms).
Given that operatorLists will generally, unless they contain huge images, be cached in the API, repeated `PDFPageProxy.render` calls where the form-data has been changed by the user in between, can thus *wrongly* return a cached operatorList.

In the viewer we're only using the `includeAnnotationStorage`-option when printing, which is probably why this has gone unnoticed for so long. Note that we, for performance reasons, don't cache printing-operatorLists in the API.
However, there's nothing stopping an API-user from using the `includeAnnotationStorage`-option during "normal" rendering, which could thus result in *subtle* (and difficult to understand) rendering bugs.

In order to handle this, we need to know if the `AnnotationStorage`-instance has been updated since the last `PDFPageProxy.render` call. The most "correct" solution would obviously be to create a hash of the `AnnotationStorage` contents, however that would require adding a bunch of code, complexity, and runtime overhead.
Given that operatorList caching in the API doesn't have to be perfect[1], but only have to avoid *false* cache-hits, we can simplify things significantly be only keeping track of the last time that the `AnnotationStorage`-data was modified.

*Please note:* While working on this patch, I also noticed that the `renderInteractiveForms`- and `includeAnnotationStorage`-options in the `PDFPageProxy.render` method are mutually exclusive.[2]
Given that the various Annotation-related options in `PDFPageProxy.render` have been added at different times, this has unfortunately led to the current "messy" situation.[3]

---
[1] Note how we're already not caching operatorLists for pages with *huge* images, in order to save memory, hence there's no guarantee that operatorLists will always be cached.

[2] Setting both to `true` will result in undefined behaviour, since trying to insert `AnnotationStorage`-values into fields that are being excluded from the operatorList-building will obviously not work, which isn't at all clear from the documentation.

[3] My intention is to try and fix this in a follow-up PR, and I've got a WIP patch locally, however it will result in a number of API-observable changes.
2021-08-18 10:09:03 +02:00
Jonas Jenwald
1465b1670f [src/display/api.js] Move the getRenderingIntent helper function into WorkerTransport
By doing this re-factoring *separately*, since it's mostly a mechanical change, the size/scope of the next patch will be reduced somewhat.
2021-08-18 09:58:26 +02:00
Tim van der Meij
a936509b77
Merge pull request #13900 from Snuffleupagus/rm-babel-logical-assignment
[api-minor] Stop translating logical assignment in non-`legacy` builds (PR 12887 follow-up)
2021-08-17 22:01:27 +02:00
Jonas Jenwald
b9a6258ad2 [api-minor] Stop translating logical assignment in non-legacy builds (PR 12887 follow-up)
When we started using logical assignment operators in the PDF.js project, the feature was new enough that browser support was somewhat limited. That should no longer be the case, since logical assignment has now been available for approximately one year.
Hence this patch, which (basically) reverts PR 12887, since using the Babel plugin unconditionally was never intended to be a permanent thing. For browsers/environments without native logical assignment support, users will now have to use a `legacy` build instead.

Please refer to the browser compatibility information on MDN:
 - https://wiki.mozilla.org/RapidRelease/Calendar
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment#browser_compatibility

Note also the release information for the major browsers:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment#browser_compatibility
 - https://en.wikipedia.org/wiki/Google_Chrome_version_history
 - https://en.wikipedia.org/wiki/Safari_version_history#Safari_14
2021-08-17 12:21:10 +02:00
Tim van der Meij
e9146b19e6
Merge pull request #13892 from Snuffleupagus/Dict-merge-refactor-2
Move some validation, in `Dict.merge`, used during merging of sub-dictionaries (PR 13775 follow-up)
2021-08-14 12:26:19 +02:00
Tim van der Meij
0e7df95e90
Merge pull request #13896 from Snuffleupagus/cleanup-ReadableStream-polyfill
Simplify the `ReadableStream` polyfill
2021-08-14 12:21:55 +02:00
Jonas Jenwald
e2aa067603 Simplify the ReadableStream polyfill
At this point in time, all of the supported browsers (in the PDF.js project) have native `ReadableStream` implementations; see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#browser_compatibility

Hence the polyfill is *only* necessary in Node.js environments now, and we shouldn't need to do any detailed feature detection either (since that was only done for the non-Chromium versions of the MS Edge browser).
Finally, we can slightly reduce the size of the Chromium-extension since the polyfill shouldn't be needed there either.
2021-08-13 12:28:55 +02:00
Jonas Jenwald
3369f9a783 Move some validation, in Dict.merge, used during merging of sub-dictionaries (PR 13775 follow-up)
By not adding any additional non-`Dict` entries to the list of candidates for merging of sub-dictionaries, we can very slightly reduce the amount of parsing required by not having to *again* iterate through unmergeable data.
2021-08-12 11:32:11 +02:00
Tim van der Meij
14a0d612c4
Merge pull request #13886 from Snuffleupagus/BaseException-name
Re-factor the `BaseException.name` handling, and clean-up some code
2021-08-11 22:35:05 +02:00
Tim van der Meij
f154bbfc1f
Merge pull request #13890 from Snuffleupagus/eslint-deprecated-rules
Update some deprecated ESLint rules
2021-08-11 22:18:44 +02:00
Jonas Jenwald
96dbe38544 Update some deprecated ESLint rules
Please see https://eslint.org/docs/rules/#deprecated where the following rules apply to the PDF.js project:
 - [`no-buffer-constructor`](https://eslint.org/docs/rules/no-buffer-constructor), which we can replace with the `unicorn/no-new-buffer` rule; see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-new-buffer.md
 - [`no-catch-shadow`](https://eslint.org/docs/rules/no-catch-shadow), which was replaced by the `no-shadow` rule (that we're already using).
2021-08-11 17:35:56 +02:00
Jonas Jenwald
d3c9c08aca
Merge pull request #13887 from mozilla/dependabot/npm_and_yarn/path-parse-1.0.7
Bump path-parse from 1.0.5 to 1.0.7
2021-08-10 22:43:42 +02:00
dependabot[bot]
91ef2e19aa
Bump path-parse from 1.0.5 to 1.0.7
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.5 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-10 18:23:47 +00:00
Jonas Jenwald
474659be8b Fix the inconsistent return types in PDFViewerApplication._parseHashParameters
While not really relevant to the previous patches, this fixes a small inconsistency in the code.
2021-08-10 11:27:49 +02:00
Jonas Jenwald
5ac139dea1 Remove the BaseViewer._name property, used only when logging errors
The original idea behind including the class name, when logging errors, was to improve things in the *hypothetical case* where `PDFViewer`- and `PDFSinglePageViewer`-instances would be used side-by-side.
Given that all of the relevant methods are synchronous this seem unlikely to really be necessary, and furthermore it's probably best to avoid using `this.constructor.name` since that's not guaranteed to do what you intend (we've seen repeated issues with minifiers mangling function/class names).
2021-08-10 11:27:49 +02:00
Jonas Jenwald
6167566f1b Re-factor the BaseException.name handling, and clean-up some code
Once we're finally able to get rid of SystemJS, which is unfortunately still blocked on [bug 1247687](https://bugzilla.mozilla.org/show_bug.cgi?id=1247687), we might also want to clean-up (or even completely remove) the `BaseException` abstraction and simply extend `Error` directly instead.

At that point we'd need to (explicitly) set the `name` on each class anyway, so this patch is essentially preparing for future clean-up. Furthermore, after the `BaseException` abstraction was added there's been *multiple* issues filed about third-party minification breaking our code since `this.constructor.name` is not guaranteed to always do what you intended.

While hard-coding the strings indeed feels quite unfortunate, it's likely the "best" solution to avoid the problem described above.
2021-08-10 11:27:47 +02:00
Tim van der Meij
745d5cc819
Merge pull request #13884 from Snuffleupagus/update-packages
Update packages and translations
2021-08-08 11:58:56 +02:00
Tim van der Meij
43060d39ad
Merge pull request #13883 from Snuffleupagus/api-cache-annotations
Improve caching of Annotations-data, by using a `Map`, in the API
2021-08-08 11:30:31 +02:00
Jonas Jenwald
d24476e02c Update l10n files 2021-08-08 10:52:26 +02:00
Jonas Jenwald
d0c87e13ce Update the eslint-plugin-unicorn package to the latest version
Also enables the `no-useless-spread` rule, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-spread.md, which didn't require any code changes.
2021-08-08 10:49:57 +02:00
Jonas Jenwald
014d00e4fb Update npm packages 2021-08-08 10:45:36 +02:00
Jonas Jenwald
7f2d524df5 Improve caching of Annotations-data, by using a Map, in the API
Rather than caching only the *last* `PDFPageProxy.getAnnotations` call, and having to handle the intent separately, we can instead implement the caching in exactly the same way as done in the `PDFPageProxy.{render, getOperatorList}` methods.
2021-08-08 08:14:51 +02:00
Tim van der Meij
036b81496e
Merge pull request #13882 from Snuffleupagus/PDFWorker-rm-closure
[api-minor] Remove the closure from the `PDFWorker` class, in the `src/display/api.js` file
2021-08-07 19:52:39 +02:00
Tim van der Meij
952f6366bf
Merge pull request #13867 from Snuffleupagus/RenderingIntentFlag
[api-minor] Re-factor the *internal* renderingIntent, and change the default `intent` value in the `PDFPageProxy.getAnnotations` method
2021-08-07 19:25:51 +02:00
Tim van der Meij
f3960a65d3
Merge pull request #13879 from Snuffleupagus/test-resources-fix-globals
Fix the global variable definitions in `test/resources/reftest-analyzer.js` (issue 13862)
2021-08-07 19:00:42 +02:00
Jonas Jenwald
1cf9405281 [api-minor] Remove the closure from the PDFWorker class, in the src/display/api.js file
This patch removes the only remaining closure in the `src/display/api.js` file, utilizing a similar approach as used in lots of other parts of the code-base, which results in a small decrease in the size of the *build* `pdf.js` file.

Given that `PDFWorker` is exposed through the *public* API, this complicates things somewhat since there's a couple of worker-related properties that really should stay *private*. Initially, while working on PR 13813, I believed that we'd need support for private (static) class fields in order to get rid of this closure, however I've managed to come up with what's hopefully deemed an acceptable work-around here.
Furthermore, some helper functions were simply moved into the `PDFWorker` class as static methods, thus simplifying the overall implementation (e.g. we don't need to manually cache the Promise in the `PDFWorker._setupFakeWorkerGlobal`-method).

Finally, as part of this re-factoring a number of missing JSDoc-comments were added which *together* with the removal of the closure significantly improves the `gulp jsdoc` output for the `PDFWorker` class.

*Please note:* This patch is tagged with `api-minor` since it deprecates `PDFWorker.getWorkerSrc()` in favor of the shorter `PDFWorker.workerSrc`, with the fallback limited to `GENERIC` builds.
2021-08-07 10:43:39 +02:00
Brendan Dahl
3d18c76a53
Merge pull request #13881 from calixteman/bug_1723734
XFA - Elements under an area must be bound (bug 1723734)
2021-08-06 11:56:58 -07:00
Calixte Denizet
328383ea7a XFA - Elements under an area must be bound (bug 1723734)
- aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1723734.
2021-08-06 20:20:19 +02:00
calixteman
98e893b84f
Merge pull request #13880 from eltociear/patch-5
Fix typo in cff_parser_spec.js
2021-08-06 19:31:52 +02:00
Brendan Dahl
d7e1a419c2
Merge pull request #13873 from brendandahl/xfa-heading
XFA - Support aria heading and table structure. (bug 1723421) (bug 1723425)
2021-08-06 09:54:47 -07:00
Ikko Ashimine
23236f1b0b
Fix typo in cff_parser_spec.js
shoudn't -> shouldn't
2021-08-06 19:30:36 +09:00
Jonas Jenwald
df79b831f4 Fix the global variable definitions in test/resources/reftest-analyzer.js (issue 13862)
It shouldn't be necessary to assign these variables to the global scope (as far as I can tell), either explicitly with `window` or implicitly with `var`, and this way we don't need to disable the ESLint `no-undef` rule; fixes another small part of issue 13862.

*Please note:* I wasn't going to put additional work into this code after PR 13869, however these changes looked so simple that I figured trying to get rid of the few remaining "Code scanning alerts" wouldn't hurt.
However, this file would still very much benefit from additional clean-up and re-factoring work, since it's quite old and currently contains some dead code (commented out).
2021-08-06 11:45:55 +02:00
Jonas Jenwald
107efdb178 [Regression] Re-factor the *internal* renderInteractiveForms handling, since it's currently subtly wrong
The value of the `renderInteractiveForms` parameter, as passed to the `PDFPageProxy.render` method, will (potentially) affect the size/content of the operatorList that's returned from the worker (for documents with forms).
Given that operatorLists will generally, unless they contain huge images, be cached in the API, repeated `PDFPageProxy.render` calls that *only* change the `renderInteractiveForms` parameter can thus return an incorrect operatorList.

As far as I can tell, this *subtle* bug has existed ever since `renderInteractiveForms`-support was first added in PR 7633 (which is almost five years ago).
With the previous patch, fixing this is now really simple by "encoding" the `renderInteractiveForms` parameter in the *internal* renderingIntent handling.
2021-08-06 00:40:43 +02:00
Jonas Jenwald
47f94235ab [api-minor] Re-factor the *internal* renderingIntent, and change the default intent value in the PDFPageProxy.getAnnotations method
With the changes made in PR 13746 the *internal* renderingIntent handling became somewhat "messy", since we're now having to do string-matching in various spots in order to handle the "oplist"-intent correctly.
Hence this patch, which implements the idea from PR 13746 to convert the `intent`-strings, used in various API-methods, into an *internal* renderingIntent that's implemented using a bit-field instead. *Please note:* This part of the patch, in itself, does *not* change the public API (but see below).

This patch is tagged `api-minor` for the following reasons:
 1. It changes the *default* value for the `intent` parameter, in the `PDFPageProxy.getAnnotations` method, to "display" in order to be consistent across the API.
 2. In order to get *all* annotations, with the `PDFPageProxy.getAnnotations` method, you now need to explicitly set "any" as the `intent` parameter.
 3. The `PDFPageProxy.getOperatorList` method will now also support the new "any" intent, to allow accessing the operatorList of all annotations (limited to those types that have one).
 4. Finally, for consistency across the API, the `PDFPageProxy.render` method also support the new "any" intent (although I'm not sure how useful that'll be).

Points 1 and 2 above are the significant, and thus breaking, changes in *default* behaviour here. However, unfortunately I cannot see a good way to improve the overall API while also keeping `PDFPageProxy.getAnnotations` unchanged.
2021-08-06 00:39:42 +02:00
Brendan Dahl
a38d1122d8 XFA - Support aria heading and table structure. (bug 1723421) (bug 1723425)
https://bugzilla.mozilla.org/show_bug.cgi?id=1723421
https://bugzilla.mozilla.org/show_bug.cgi?id=1723425
2021-08-05 15:25:04 -07:00
Tim van der Meij
849bab973c
Merge pull request #13874 from Snuffleupagus/components-annotation-zoom-factor
Update the Annotation `--zoom-factor` CSS variable when `PDFPageView` is used standalone (PR 13868 follow-up)
2021-08-05 22:28:51 +02:00