1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 16:48:08 +02:00
Commit graph

6962 commits

Author SHA1 Message Date
Tim van der Meij
f44cba86d5
Don't get ICC color space files if required API options are missing
This commit improves validation of the API options for the ICC color
space logic. If `useWasm` is `true` but the corresponding `wasmUrl`
or `iccUrl` API options are not provided we can avoid requesting
files with `null` URLs which always results in a 404 response.
2025-03-16 16:29:42 +01:00
Jonas Jenwald
9e8d4e4d46 [api-minor] Attempt to support fetching the raw data of the PDF document from the PDFDocumentLoadingTask-instance (issue 15085)
The new API-functionality will allow a PDF document to be downloaded in the viewer e.g. while the PasswordPrompt is open, or in cases when document initialization failed.
Normally the raw data of the PDF document would be accessed via the `PDFDocumentProxy.prototype.getData` method, however in these cases the `PDFDocumentProxy`-instance isn't available.
2025-03-16 10:09:44 +01:00
Jonas Jenwald
8a24c1907a Replace a few simple regular expressions in the XFA-code with string parsing
- Add a couple of `limit` parameters in cases where those were "missing", for `String.prototype.split()` calls, to avoid unnecessary parsing.

 - Remove some "pointless" initial trimming of leading/trailing spaces, since that's already done at a later parsing step in many cases.
2025-03-15 17:25:26 +01:00
Jonas Jenwald
ec30f0788b Slightly shorten a couple of MeshStreamReader methods
By using object destructuring in the `readCoordinate` and `readComponents` methods we can ever so slightly shorten this code.
2025-03-14 12:57:41 +01:00
Jonas Jenwald
78b310afb1
Merge pull request #19650 from Snuffleupagus/shorten-crypto
Shorten the `src/core/crypto.js` file a little bit
2025-03-13 12:46:53 +01:00
Jonas Jenwald
0e15f709c4 Remove unnecessary else if when checking the encryptionKey in the CipherTransformFactory constructor
This can be simplified a tiny bit since we already throw `PasswordException` when no password is provided.
2025-03-13 11:58:13 +01:00
Jonas Jenwald
cc63ffa6bb Reduce duplication when checking the userPassword, in CipherTransformFactory.prototype.#prepareKeyData
Currently we duplicate the exact same code in both the `if`- and `else`-branches, which seems unnecessary, and we can also replace the manual loop.
2025-03-13 11:58:02 +01:00
calixteman
38cb01c629
Merge pull request #19648 from calixteman/bug1953290
[Editor] Fix the role of the different editors in order to make them interactive elements (bug 1953290)
2025-03-13 09:20:26 +01:00
Calixte Denizet
7fce3eac93 [Editor] Fix the role of the different editors in order to make them interactive elements (bug 1953290)
Having some interactive elements forces the screen readers to switch to form mode
and consequently they delegate the keyboard stuff to the browser.
This patch sets an aria label on each editor in order to have a better description than just
'application'.
2025-03-12 22:19:31 +01:00
Jonas Jenwald
319d239f41 Add an OutputScale static method to get the devicePixelRatio
Currently we lookup the `devicePixelRatio`, with fallback handling, in a number of spots in the code-base.
Rather than duplicating code we can instead add a new static method in the `OutputScale` class, since that one is now exposed in the API.
2025-03-12 21:07:06 +01:00
Jonas Jenwald
e4795f639c
Merge pull request #19644 from Snuffleupagus/crypto-PDFBase
Introduce a common base class for the `PDF17` and `PDF20` crypto classes
2025-03-12 21:05:39 +01:00
Jonas Jenwald
0cbb2b1d13
Merge pull request #19646 from Snuffleupagus/dont-cache-MIN_TOUCH_DISTANCE_TO_PINCH
Don't shadow the `TouchManager.prototype.MIN_TOUCH_DISTANCE_TO_PINCH` value
2025-03-12 21:02:02 +01:00
Jonas Jenwald
ee34c5c648 Let Lexer.prototype.getNumber treat more cases of a single minus sign as zero (bug 1953099)
This patch extends the approach of PR 14543, by also treating e.g. minus signs followed by '(' or '<' as zero.
Inside of a /Contents stream those characters will generally mean the start of one or more glyphs.
2025-03-12 17:50:13 +01:00
Jonas Jenwald
92adc7ea1b Don't shadow the TouchManager.prototype.MIN_TOUCH_DISTANCE_TO_PINCH value
The `devicePixelRatio` may change if the window resolution changes, which can happen e.g. if the viewer is moved to another monitor.
2025-03-12 14:53:20 +01:00
Jonas Jenwald
2ff6829e47 Introduce a common base class for the PDF17 and PDF20 crypto classes
With the exception of a different hashing function these classes are identical, and the base class thus help reduce code duplication.

This patch reduces the size of the `gulp mozcentral` build with 1344 bytes, which isn't a lot but still cannot hurt.
2025-03-12 12:25:55 +01:00
Calixte Denizet
4b4f85484e Always use the absolute value of the line thickness (issue 19633) 2025-03-11 14:03:23 +01:00
Calixte Denizet
b5a7b827b5 [Editor] Add an aria label to an added signature (bug 1952571) 2025-03-10 19:15:05 +01:00
calixteman
13474aca63
Merge pull request #19620 from calixteman/cmyk_icc
[api-minor] Use an icc profile for converting CMYK to RGB
2025-03-10 16:55:48 +01:00
Jonas Jenwald
4152eae3fb
Merge pull request #19635 from Snuffleupagus/thumbnails-maxCanvasPixels
Support the `maxCanvasPixels` option in the thumbnails code
2025-03-10 16:30:25 +01:00
Jonas Jenwald
0edfd29a3e Improve text-selection for Type3 fonts, using d0 operators, with empty /FontBBox-entries (issue 19624)
For Type3 glyphs with `d1` operators it's easy to compute a fallback bounding box, however for `d0` the situation is more difficult.
Given that we nowadays compute the min/max of basic path-rendering operators on the worker-thread, we can utilize that by parsing these Type3 operatorLists to guess a more suitable fallback bounding box.
2025-03-10 16:21:54 +01:00
Calixte Denizet
7280540901 [api-minor] Use an icc profile for converting CMYK to RGB 2025-03-10 14:18:20 +01:00
Jonas Jenwald
fc22d3afc7 Support the maxCanvasPixels option in the thumbnails code
This addresses an inconsistency in the viewer, since the thumbnails don't respect the `maxCanvasPixels` option.
Note that, as far as I know, this has not lead to any bugs since the thumbnails render with a fixed (and small) width, however it really cannot hurt to address this (especially after the introduction of the `maxCanvasDim` option).

To support this a new `OutputScale`-method was added, to avoid having to duplicate code in multiple files.
2025-03-10 14:12:07 +01:00
Jonas Jenwald
10a99ea0a7 Let SMask/Mask images fallback to the parent image dimensions (issue 19611)
One of the images have a corrupt SMask, where the /Height-entry is bogus; see the excerpt below (via https://brendandahl.github.io/pdf.js.utils/browser/).
```
SMask (stream) [id: 17, gen: 0]

    ColorSpace = /DeviceGray
    Height = /Length
    Subtype = /Image
    Filter = /FlateDecode
    Type = /XObject
    Width = 157
    Matte (array)
    BitsPerComponent = 8
    Length = 3893
    <view contents> download
```

Hence we enable SMask/Mask images to fallback to the parent image dimensions, and also add more validation of the width/height to get a better error message when that data is wrong.
2025-03-10 12:37:44 +01:00
Tim van der Meij
81baa16c8b
Merge pull request #19629 from Snuffleupagus/split-crypto
Re-factor the `src/core/crypto.js` file
2025-03-09 13:08:40 +01:00
Tim van der Meij
621258f85c
Merge pull request #19623 from Snuffleupagus/PDFFunctionFactory-rm-createFromArray
Remove the `PDFFunctionFactory.createFromArray` method
2025-03-09 12:58:55 +01:00
Jonas Jenwald
0a2c176027 Remove the unused or/shiftLeft methods from the Word64 class (PR 4938 follow-up)
These methods were introduced in *the first* commit of PR 4938, however they became unused in *the second* commit of that PR.
Hence it seems that we've been accidentally shipping, a small amount of, unused code for over a decade.
2025-03-08 17:33:16 +01:00
Jonas Jenwald
67065e43f5 Replace loops with TypedArray.prototype.set in the CipherTransformFactory class
Also, adds `TypedArray.prototype.fill` usage in one spot.
2025-03-08 16:17:45 +01:00
Jonas Jenwald
c65f1b0dae Move a couple of AESBaseCipher fields from the constructors
Thanks to modern JS class features we can, ever so slightly, shorten some class field definitions.
2025-03-08 16:06:30 +01:00
Jonas Jenwald
461488cb16 Initialize the defaultPasswordBytes, in CipherTransformFactory, lazily 2025-03-08 16:06:30 +01:00
Jonas Jenwald
139d27aa7d Simplify various calculate... methods a tiny bit
While initializing the `padded` Uint8Arrays we're manually assigning zeros to some entries, which is completely unnecessary since that's the default value for a TypedArray, and instead we can just increment the index.
2025-03-08 16:06:27 +01:00
Jonas Jenwald
facf34606f Move the calculateSHA384 and calculateSHA512 functions into their own file
This allows us to remove a closure, and we also change the code to initialize various constants lazily.
2025-03-08 15:56:22 +01:00
Jonas Jenwald
a1eac86037 Move the calculateSHA256 function into its own file
This allows us to remove a closure, and we also change the code to initialize various constants lazily.
2025-03-08 15:56:16 +01:00
Jonas Jenwald
3e8d01ad7c Move the calculateMD5 function into its own file
This allows us to remove a closure, and we also change the code to initialize various constants lazily.
2025-03-08 15:56:05 +01:00
Jonas Jenwald
1b5151f969 Remove pointless Math.min usage in the XFA parsing
When creating the `StyleMapping` for the "xfa-font-horizontal-scale" and "xfa-font-vertical-scale" properties there's currently pointless `Math.min` usage, since we're not actually comparing with anything.
2025-03-08 12:22:33 +01:00
Jonas Jenwald
bee0f53c65 Use the MathClamp helper function more (PR 19617 follow-up)
There's a few spots that I accidentally missed in PR 19617.
2025-03-08 12:19:56 +01:00
Jonas Jenwald
17d7943758 Remove the PDFFunctionFactory.createFromArray method
This combines the `PDFFunctionFactory.create` and `PDFFunctionFactory.createFromArray` methods, which helps simplify and shorten the code.
Additionally, to simplify the parameter handling we pass the `PDFFunctionFactory`-instance directly to the various `PDFFunction`-methods.
2025-03-07 12:28:14 +01:00
Jonas Jenwald
af89e77124
Merge pull request #19619 from Snuffleupagus/fix-#savedHasOwnCanvas
Fix the `#savedHasOwnCanvas` handling in the `StampAnnotation` class
2025-03-06 17:59:14 +01:00
calixteman
1abb7be11a
Merge pull request #19618 from calixteman/non_editable_stamp
[Editor] In edit mode, a non-editable stamp must be visible after the page is rendered
2025-03-06 16:23:55 +01:00
Jonas Jenwald
4f2cf38bfa
Merge pull request #19617 from Snuffleupagus/MathClamp
Introduce a helper function for clamping a value to a range
2025-03-06 15:48:14 +01:00
Calixte Denizet
f3454a738d [Editor] In edit mode, a non-editable stamp must be visible after the page is rendered 2025-03-06 15:37:27 +01:00
Jonas Jenwald
08fa4eba20 Fix the #savedHasOwnCanvas handling in the StampAnnotation class
This may not be possible to trigger in practice, however it seems that if `StampAnnotation.prototype.mustBeViewedWhenEditing` is called back-to-back with `isEditing === true` set then the second invocation could overwrite the `#savedHasOwnCanvas`-field and thus lose its initial state.
2025-03-06 15:17:52 +01:00
Jonas Jenwald
07bbbf75a5 Introduce a helper function for clamping a value to a range
Currently we have a number of spots in the code-base where we need to clamp a value to a [min, max] range. This is either implemented using `Math.min`/`Math.max` or with a local helper function, which leads to some unnecessary duplication.

Hence this patch adds and re-uses a single helper function for this, which we'll hopefully be able to remove in the future once https://github.com/tc39/proposal-math-clamp/ becomes generally available.
2025-03-06 14:05:26 +01:00
Jonas Jenwald
4ec5f08803 [Editor] Remove the unused opacityToHex helper function (PR 19093 follow-up)
The only call-site was removed in PR 19093, hence this is now dead code.
2025-03-05 23:10:56 +01:00
Jonas Jenwald
d8d7235876 Simplify the ColorSpaceUtils.singletons handling (PR 19564 follow-up)
With the changes in PR 19564 the actual `ColorSpace`-classes where separated from the various static "helper" methods.
Hence it seems that we can now simplify/shorten this old code to instead cache the "standard" ColorSpaces directly on the `ColorSpaceUtils`-class.
2025-03-05 15:02:05 +01:00
Jonas Jenwald
fbf1f2ba15 Remove ColorSpaceUtils.parseAsync and simplify the ColorSpace "API-surface"
This patch reduces the number of `ColorSpaceUtils` static-methods, and in particular the `parseAsync` method is removed and it's now instead possible to have `parse` optionally return a Promise.
This thus removes the need to manually check if a `ColorSpace`-instance is cached, note the changes in the `src/core/evaluator.js` file.
2025-03-05 12:43:58 +01:00
Calixte Denizet
971be48b60 Support using ICC profiles in using qcms (bug 860023) 2025-03-05 10:29:59 +01:00
Jonas Jenwald
ba640e5cdc Shorten various static ColorSpace method signatures
By passing around common parameters, i.e. everything that's not the ColorSpace-data, in an object we can shorten this code a little bit.
2025-03-03 11:08:05 +01:00
Jonas Jenwald
33dfc4dd5f Also cache "sub" ColorSpaces globally (PR 19583 follow-up)
Some ColorSpaces can reference other ColorSpaces, and since it's fairly common for many pages to use the same ColorSpaces (see e.g. `issue17061.pdf`) this can help reduce a lot of unnecessary re-parsing especially for e.g. `ICCBased` ColorSpaces.
2025-03-03 10:07:41 +01:00
Jonas Jenwald
7b5cd9cddd Use arrow functions with some Promise.then calls
A lot of this is fairly old code, which we can shorten slightly by using arrow functions instead of "regular" functions.
2025-03-02 19:57:38 +01:00
Tim van der Meij
146bc58f32
Merge pull request #19596 from Snuffleupagus/Array-methods-arrow-functions
Use arrow function with various Array methods
2025-03-02 16:09:09 +01:00