Commit Graph

15352 Commits

Author SHA1 Message Date
Tim van der Meij
2bb96a708c
Merge pull request #14598 from Snuffleupagus/rm-isBool
Re-factor the `Catalog.viewerPreferences` method and remove the `isBool` helper function
2022-02-23 20:36:56 +01:00
Tim van der Meij
409cbfc817
Merge pull request #14597 from Snuffleupagus/Dict-set-validate-key
Ensure that `Dict.set` only accepts string `key`s
2022-02-23 20:31:36 +01:00
Tim van der Meij
1672c3a731
Merge pull request #14588 from Snuffleupagus/rm-old-test-CSS
Remove old prefixed CSS rules used with `text` tests
2022-02-23 20:28:26 +01:00
Tim van der Meij
1b51e10c9c
Merge pull request #14595 from Snuffleupagus/structuredClone-comment-support
Update the support information for `structuredClone` (PR 14392 follow-up)
2022-02-23 20:27:35 +01:00
Jonas Jenwald
3704283f5b Remove the isBool helper function
The call-sites are replaced by direct `typeof`-checks instead, which removes unnecessary function calls.
2022-02-23 13:31:03 +01:00
Jonas Jenwald
82f1ee1755 Re-factor the Catalog.viewerPreferences method
This removes the `ViewerPreferencesValidators` structure, and thus (slightly) simplifies the code overall. With these changes we only have to iterate through, and validate, the actually available Dictionary entries.
2022-02-23 13:25:56 +01:00
Jonas Jenwald
a2f9031e9a Ensure that Dict.set only accepts string keys
Trying to use a non-string `key` in a `Dict` is not intended, and would basically be an implementation error. Hence we can add a non-PRODUCTION check to enforce this, complementing the existing `value` check added in PR 11672.
2022-02-22 16:35:20 +01:00
Jonas Jenwald
b2f6844ce3
Merge pull request #14596 from Snuffleupagus/rm-isNum
Remove the `isNum` helper function
2022-02-22 16:06:47 +01:00
Jonas Jenwald
48985bd221 Update the support information for structuredClone (PR 14392 follow-up)
When the `structuredClone` polyfill was added, the support information in Safari was unclear. Given that an actual version *number* is now available, see below, it seems like a good idea to update the comment accordingly.

https://developer.mozilla.org/en-US/docs/Web/API/structuredClone#browser_compatibility
2022-02-22 12:30:54 +01:00
Jonas Jenwald
05edd91bdb Remove the isNum helper function
The call-sites are replaced by direct `typeof`-checks instead, which removes unnecessary function calls. Note that in the `src/`-folder we already had more `typeof`-cases than `isNum`-calls.

These changes were *mostly* done using regular expression search-and-replace, with two exceptions:
 - In `Font._charToGlyph` we no longer unconditionally update the `width`, since that seems completely unnecessary.
 - In `PDFDocument.documentInfo`, when parsing custom entries, we now do the `typeof`-check once.
2022-02-22 11:55:34 +01:00
Jonas Jenwald
edd024c9e7
Merge pull request #14594 from Snuffleupagus/more-instanceof
Prefer `instanceof ...` rather than calling `isCmd`/`isDict`/`isName` with *one* argument
2022-02-21 20:59:34 +01:00
Jonas Jenwald
b282814e38 Prefer instanceof Name rather than calling isName() with one argument
Unless you actually need to check that something is both a `Name` and also of the *correct* type, using `instanceof Name` 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 `isName` helper function for where it makes sense.
2022-02-21 12:45:00 +01:00
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