Commit Graph

15540 Commits

Author SHA1 Message Date
Jonas Jenwald
4df82ad31e Prefer instanceof Dict rather than calling isDict() with one argument
Unless you actually need to check that something is both a `Dict` and also of the *correct* type, using `instanceof Dict` directly should be a tiny bit more efficient since it avoids one function call and an unnecessary `undefined` check.

This patch uses ESLint to enforce this, since we obviously still want to keep the `isDict` helper function for where it makes sense.
2022-02-21 12:44:56 +01:00
Jonas Jenwald
67b658e8d5 Prefer instanceof Cmd rather than calling isCmd() with *one* argument
Unless you actually need to check that something is both a `Cmd` and also of the *correct* type, using `instanceof Cmd` directly should be a tiny bit more efficient since it avoids one function call and an unnecessary `undefined` check.

This patch uses ESLint to enforce this, since we obviously still want to keep the `isCmd` helper function for where it makes sense.
2022-02-21 12:44:51 +01:00
Jonas Jenwald
40edd235ea Remove old prefixed CSS rules used with text tests
According to MDN, both the `transform-origin` and `box-sizing` CSS rules are supported in their *unprefixed* versions in modern browsers:

 - https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing#browser_compatibility
2022-02-20 18:01:22 +01:00
Tim van der Meij
3635a9a333
Merge pull request #14585 from Snuffleupagus/PDFObjects-private
Improve the `PDFObjects` class
2022-02-20 14:53:58 +01:00
Tim van der Meij
dce10de083
Merge pull request #14584 from Snuffleupagus/update-packages
Update packages and translations
2022-02-20 14:46:25 +01:00
Jonas Jenwald
bad15894fc Improve the JSDocs for the PDFObjects class
Given that we expose `PDFObjects`-instances, via the `commonObjs` and `objs` properties, on the `PDFPageProxy`-instances this ought to help provide slightly better TypeScript definitions.
2022-02-20 13:02:14 +01:00
Jonas Jenwald
f4712bc0ad Simplify the data stored on PDFObjects-instances
The manually tracked `resolved`-property is no longer necessary, since the same information is now directly available on all `PromiseCapability`-instances.
Furthermore, since the `PDFObjects.resolve` method is not documented as accepting e.g. only Object-data, we probably shouldn't resolve the `PromiseCapability` with the `data` and instead only store it on the `PDFObjects`-instance.[1]

---
[1] While Objects are passed by reference in JavaScript, other primitives such as e.g. strings are passed by value and the current implementation *could* thus lead to increased memory usage. Given how we're using `PDFObjects` in the PDF.js code-base none of this should be an issue, but it still cannot hurt to change this.
2022-02-20 12:33:33 +01:00
Jonas Jenwald
beecde3229 Introduce (some) private properties/methods in the PDFObjects class
This ensures that the underlying data cannot be accessed directly, from the outside, since that's definately not intended here.
Note that we expose `PDFObjects`-instances, via the `commonObjs` and `objs` properties, on the `PDFPageProxy`-instances hence these changes really cannot hurt.
2022-02-20 12:23:30 +01:00
Jonas Jenwald
21f1d1ace2 Update l10n files 2022-02-20 10:10:21 +01:00
Jonas Jenwald
55b78bb240 Update npm packages 2022-02-20 10:08:23 +01:00
Jonas Jenwald
fbed707592
Merge pull request #14577 from Snuffleupagus/rm-isRef
Remove the `isRef` helper function
2022-02-19 15:47:01 +01:00
Jonas Jenwald
2cb2f633ac Remove the isRef helper function
This helper function is not really needed, since it's just a wrapper around a simple `instanceof` check, and it only adds unnecessary indirection in the code.
2022-02-19 15:33:42 +01:00
Tim van der Meij
df0aa1a9c4
Merge pull request #14575 from Snuffleupagus/rm-isStream
Remove the `isStream` helper function
2022-02-19 14:59:19 +01:00
Tim van der Meij
8e234a16d4
Merge pull request #14578 from Snuffleupagus/rm-backingStorePixelRatio
Remove the `backingStorePixelRatio`-part of the `getOutputScale` helper function
2022-02-19 14:54:30 +01:00
Tim van der Meij
65d679a3a6
Merge pull request #14580 from Snuffleupagus/PixelsPerInch-class
Change `PixelsPerInch` to a class with `static` properties (issue 14579)
2022-02-19 14:49:50 +01:00
Tim van der Meij
964601ba39
Merge pull request #14581 from Snuffleupagus/Driver-parseQueryString
Use the (viewer) `parseQueryString` helper function in the reference tests
2022-02-19 14:47:37 +01:00
Jonas Jenwald
dde4e43b4a Use the (viewer) parseQueryString helper function in the reference tests
Rather than re-implementing this functionality in the `Driver` class, we can simply re-use the existing `parseQueryString` helper function instead.
2022-02-19 09:41:04 +01:00
Jonas Jenwald
05efe3017b Change PixelsPerInch to a class with static properties (issue 14579)
*Please note:* I'm completely fine with this patch being rejected, and the issue instead closed as WONTFIX, since this is unfortunately a case where the TypeScript definitions dictate how we can/cannot write JavaScript code.

Apparently the TypeScript definitions generation converts the existing `PixelsPerInch` code into a `namespace` and simply ignores the getter; please see a7fc0d33a1/types/src/display/display_utils.d.ts (L223-L226)

Initially I tried tagging `PixelsPerInch` as en `@enum`, see https://jsdoc.app/tags-enum.html, however that unfortunately didn't help.
Hence the only good/simple solution, as far as I'm concerned, is to convert `PixelsPerInch` into a class with `static` properties. This patch results in the following diff, for the `gulp types` build target:
```diff
@@ -195,9 +195,10 @@
      */
     static toDateObject(input: string): Date | null;
 }
-export namespace PixelsPerInch {
-    const CSS: number;
-    const PDF: number;
+export class PixelsPerInch {
+    static CSS: number;
+    static PDF: number;
+    static PDF_TO_CSS_UNITS: number;
 }
 declare const RenderingCancelledException_base: any;
 export class RenderingCancelledException extends RenderingCancelledException_base {
```
2022-02-19 09:05:40 +01:00
Jonas Jenwald
530af48b8e
Merge pull request #14569 from brendandahl/smask-state
Fix canvas state getting out of sync from smasks. (bug 1755507)
2022-02-18 19:35:58 +01:00
Jonas Jenwald
36cb82e517 Convert the getOutputScale helper function into a OutputScale class
Given the previous patch in particular, this seems like an overall nicer format since it avoids duplicating the `scaled` getter in each instance.
2022-02-18 16:45:38 +01:00
Jonas Jenwald
0928d26d54 Replace the scaled property, in the getOutputScale return, with a getter
In some cases, in the `PDFPageView` implementation, we're modifying the `sx`/`sy` properties when CSS-only zooming is being used.
Currently this requires that you remember to *manually* update the `scaled` property to prevent issues, which doesn't feel all that nice and also seems error-prone. By replacing the `scaled` property with a getter, this is now handled automatically instead.
2022-02-18 13:10:42 +01:00
Jonas Jenwald
0159ec0a12 Remove the backingStorePixelRatio-part of the getOutputScale helper function
The `CanvasRenderingContext2D.backingStorePixelRatio` property was never standardized, and only Safari set (its prefixed version of) it to anything other than `1`.
Note that e.g. MDN doesn't contain any information about this property, and one of the few sources of information (at this point) is the following post: https://stackoverflow.com/questions/24332639/why-context2d-backingstorepixelratio-deprecated

Hence we can simplify the `getOutputScale` helper function, by removing some dead code, and now it no longer requires any parameters when called.
2022-02-18 13:03:48 +01:00
Brendan Dahl
7def6d12c8 Fix canvas state getting out of sync from smasks. (bug 1755507)
Soft masks can be enabled/disabled at anytime and at different
points in the save/restore stack. This can lead to
the amount of save/restores becoming unbalanced across the
two canvases. Instead of save/restoring on the temporary canvas
change it so we only track state on the main (suspended canvas).

I was also getting an out balance stack from patterns, so I've also
fixed that and added a warning that will at least show up on chrome.
It would be nice to add this so Firefox at some point too.

Fixes #11328, #14297 and bug 1755507
2022-02-17 17:38:32 -08:00
Jonas Jenwald
1a31855977 Remove the isStream helper function
At this point all the various Stream-classes extends an abstract base-class, hence this helper function is no longer necessary and only adds unnecessary indirection in the code.
2022-02-17 13:51:36 +01:00
Tim van der Meij
d9a3a24353
Merge pull request #14566 from Snuffleupagus/misc-viewer-cleanup
Miscellaneous small viewer clean-up
2022-02-16 20:33:30 +01:00
Jonas Jenwald
ff6d9c74cc
Merge pull request #14572 from Snuffleupagus/_collectJS-string-check
Add a missing string-check in the `_collectJS` helper function
2022-02-16 14:44:30 +01:00
Jonas Jenwald
fd319e94b3 Add a missing string-check in the _collectJS helper function
Unfortunately I don't have a test-case that breaks without this change, however the `stringToPDFString` helper function will fail if anything other than a string is passed to it.
The changes in this patch thus make this code more-or-less identical to that found in the `Catalog.{_collectJavaScript, parseDestDictionary}` methods.
2022-02-16 13:43:42 +01:00
Jonas Jenwald
996396a914 Change PasswordPrompt.close to an async method
This is consistent with the `open` method, and it actually *ever so slightly* reduces the size of the file.
2022-02-14 12:22:36 +01:00
Jonas Jenwald
2dececf445 Remove the typeof navigator-checks in the web/app_options.js file
Given that the `Navigator` interface has been available since "forever", please see https://developer.mozilla.org/en-US/docs/Web/API/Navigator#browser_compatibility, it's somewhat difficult to see why these checks are actually necessary since the viewer is only intended for usage in browsers.

Looking at the history of the code, this functionality was originally placed in the general `src/shared/compatibility.js` file which could thus run in e.g. worker-threads and Node.js environments (where the `Navigator` interface isn't available).
2022-02-14 12:22:36 +01:00
calixteman
d5f048abe0
Merge pull request #14563 from calixteman/search_eol
[Search] Some matches were incorrectly shifted because of some '-\n'
2022-02-14 10:30:45 +01:00
Calixte Denizet
18f4e560ae [Search] Some matches were incorrectly shifted because of some '-\n'
- it aims to fix #14562;
- 'X-\n' were not correctly positioned;
- when X is a diacritic (e.g. in "sä-\n", which is decomposed into "sa¨-\n") we must handle both things:
  - diacritics on the one hand;
  - "-\n" on the other hand.
2022-02-14 10:12:33 +01:00
calixteman
263c89581f
Merge pull request #14564 from calixteman/bug1755201
[api-minor] Don't add in the text content the chars which are out-of-page (bug 1755201)
2022-02-13 21:48:57 +01:00
Calixte Denizet
18e3a98c2b [api-minor] Don't add in the text content the chars which are out-of-page (bug 1755201)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1755201;
- if the glyph position is not within the view then skip it.
2022-02-13 21:07:11 +01:00
Tim van der Meij
78246719f8
Merge pull request #14559 from Snuffleupagus/revert-9505
Revert "Don't block origin-less blob:-URLs in hosted viewer"
2022-02-13 14:10:22 +01:00
Tim van der Meij
c37d785b2a
Merge pull request #14560 from Snuffleupagus/Node-ReadableStream-polyfill
[api-minor] Remove the, in `legacy` builds, bundled `ReadableStream` polyfill
2022-02-13 14:08:22 +01:00
Tim van der Meij
7ee531d918
Merge pull request #14558 from Snuffleupagus/getFilenameFromContentDispositionHeader-TextDecoder
Remove the UTF-8 fallback, when `TextDecoder` is missing, from the Content-Disposition parser
2022-02-13 14:02:50 +01:00
Tim van der Meij
99fde3cf86
Merge pull request #14557 from Snuffleupagus/issue-14555
Remove unnecessary `font-size` CSS rule from the `html` element (issue 14555, PR 3794 follow-up)
2022-02-13 14:01:02 +01:00
Jonas Jenwald
b89595fd20 [api-minor] Remove the, in legacy builds, bundled ReadableStream polyfill
According to the MDN compatibility data, see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#browser_compatibility, all browsers that we support have native `ReadableStream` implementations (since quite some time too).

Hence only Node.js is now lagging behind w.r.t. `ReadableStream` support, and its experimental implementation doesn't really help us given the life-span of the LTS releases (see https://en.wikipedia.org/wiki/Node.js#Releases).
It seems quite unfortunate to bundle a `ReadableStream` polyfill in the `legacy` builds when it's unnecessary in browsers, given its overall size, but fortunately we can avoid that by simply listing `web-streams-polyfill` as a dependency for the `pdfjs-dist` library.
2022-02-13 10:15:58 +01:00
Jonas Jenwald
911021002e Revert "Don't block origin-less blob:-URLs in hosted viewer"
This reverts commit a6aca3cabe, since no version of Internet Explorer is supported any more.
2022-02-12 11:32:10 +01:00
Jonas Jenwald
d642d34500 Remove the UTF-8 fallback, when TextDecoder is missing, from the Content-Disposition parser
Given that `TextDecoder` is now supported by all modern browsers/environments, please see https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder#browser_compatibility, there's no longer any good reason to keep a UTF-8 fallback in the Content-Disposition parser.
2022-02-12 10:30:25 +01:00
Jonas Jenwald
06190dbbb3 Remove unnecessary font-size CSS rule from the html element (issue 14555, PR 3794 follow-up)
According to https://github.com/mozilla/pdf.js/pull/3794#discussion_r6983639 this was intended to be *temporary*, and the B2G project itself was discontinued years ago.
2022-02-11 19:44:03 +01:00
Tim van der Meij
e9fd67a3f6
Merge pull request #14551 from Snuffleupagus/mv-createObjectURL
[api-minor] Stop exposing the `createObjectURL` helper function in the API
2022-02-11 19:40:25 +01:00
Jonas Jenwald
b87a243222 [api-minor] Stop exposing the createObjectURL helper function in the API
With recent changes, specifically PR 14515 *and* the previous patch, the `createObjectURL` helper function is now only used with the SVG back-end.
All other call-sites, throughout the code-base, are now using `URL.createObjectURL(...)` directly and it no longer seems necessary to keep exposing the helper function in the API.
Finally, the `createObjectURL` helper function is moved into the `src/display/svg.js` file to avoid unnecessarily duplicating this code on both the main- and worker-threads.
2022-02-10 12:01:35 +01:00
Jonas Jenwald
0daab88a48 Update two display_utils unit-tests to use native functionality rather than the createObjectURL helper function
Given that most of the code-base is already using native functionality, we can update these unit-tests similarily as well.
 - For the `blob:`-URL test, we simply use `URL.createObjectURL(...)` and `Blob` directly instead.
 - For the `data:`-URL test, we simply use `btoa` to do the Base64 encoding and then build the final URL-string.
2022-02-10 12:01:29 +01:00
Brendan Dahl
f8b2a99ddc
Merge pull request #14543 from Snuffleupagus/bug-1753983
Let `Lexer.getNumber` treat a single minus sign as zero (bug 1753983)
2022-02-09 14:06:35 -08:00
Tim van der Meij
d57f3a13d7
Merge pull request #14547 from Snuffleupagus/xfa_bug1720182-file
Update the file used with the `xfa_bug1720182` test-case
2022-02-09 19:45:18 +01:00
Tim van der Meij
d3d63cb471
Merge pull request #14548 from Snuffleupagus/bug-1754421
[api-minor] Ensure that the `PDFDocumentLoadingTask`-promise is rejected when cancelling the PasswordPrompt (bug 1754421)
2022-02-09 19:41:22 +01:00
Jonas Jenwald
1f0fb270b1 [api-minor] Ensure that the PDFDocumentLoadingTask-promise is rejected when cancelling the PasswordPrompt (bug 1754421)
This is essentially a *continuation* of PR 7926, where we added support for rejecting the current `PDFDocumentLoadingTask`-promise by throwing inside of the `onPassword`-callback.
Hence the naive way to address [bug 1754421](https://bugzilla.mozilla.org/show_bug.cgi?id=1754421) would be to simply throw in the `onPassword`-callback used in the default viewer. However it unfortunately turns out to not work, since the password input/validation is asynchronous, and we thus need another approach.

The simplest solution that I can come up with here, is thus to *extend* the `onPassword`-callback to also reject the current `PDFDocumentLoadingTask`-instance if an `Error` is explicitly passed as the input to the callback function. (This doesn't feel great, but I cannot see a better solution that isn't really complicated.)
2022-02-09 15:09:20 +01:00
Jonas Jenwald
188752e5f0 Update the test Driver to fail on duplicate files
While it's obviously fine to use the same PDF document in different reference-tests, note how we e.g. have both `eq` and `text` tests for one document, we should always avoid adding *duplicate* files in the `test/pdfs/` folder.
2022-02-08 16:59:18 +01:00
Jonas Jenwald
60efae96fd Update the file used with the xfa_bug1720182 test-case
The file used in this test-case is *identical* to, i.e. the md5 entry perfectly matches, the file used with the `xfa_bug1716380` test-case.
While it's obviously fine to use the same PDF document in different reference-tests, note how we e.g. have both `eq` and `text` tests for one document, we should always avoid adding *duplicate* files in the `test/pdfs/` folder.
2022-02-08 14:23:41 +01:00