Commit Graph

17379 Commits

Author SHA1 Message Date
Jonas Jenwald
9232264b8a Fix the JSDoc returns-type for two PageViewport-methods (issue 16134)
The affected methods have always returned Arrays, however the JSDoc did not accurately reflect that.
2023-03-09 15:57:16 +01:00
Jonas Jenwald
92296fa6a1 Include the document-id in the SVG-filter names (PR 16062 follow-up)
In the general PDF.js library multiple PDF documents may be opened on the same web-page, which is why we many years ago started using document-specific identifiers to prevent issues with global data such e.g. with fonts.
Hence we need to treat the identifiers generated by the `FilterFactory` in the same way, since the SVG-filters for two separate PDF documents may otherwise get identical ids.
2023-03-09 15:35:29 +01:00
Calixte Denizet
07b094729e Fix search in pdf a containing some UTF-32 characters (bug 1820909)
Some chars were supposed to have a length equals to 1 but UTF-32 chars
can be longuer.
2023-03-09 15:03:01 +01:00
Ben Wagner
5fad91a680 Better approximate gradient color stops
PDF gradients do not have color stops but an arbitrary PDF function of
the type f(t) -> color. CSS gradients are only based on color stops.
Most PDF gradient functions are produced from color stop oriented
gradients.

Take advantage of this by sampling the PDF function at a higher
frequency but not converting any samples which could be interpolated to
color stops. The sampling frequency is chosen to be the least common
multiple of as many values as practical to exactly re-create the common
case of the PDF function implementing equally spaced linearly
interpolated stops in RGB color space. This also allows for better
approximation of other smooth PDF functions (non-linear, or non-equally
spaced, or in different color space).

Fixes: #10572, #14165
2023-03-09 08:49:50 -05:00
Jonas Jenwald
c0671ac133 Slightly increase the maximum image sizes that we'll cache
The current value originated in PR 2317, and in the decade that have passed the amount of RAM available in (most) devices should have increased a fair bit.
Nowadays we also do a much better job of detecting repeated images at both the page- and document-level, which helps reduce overall memory-usage in many documents.

Finally the constant is also moved into the `src/shared/util.js` file, since it was implicitly used on both the main- and worker-thread previously.
2023-03-08 17:06:10 +01:00
Jonas Jenwald
15d9faba57 Slightly delay cleanup, after rendering, in documents with large images
Currently in PDF documents with large images we immediately cleanup once rendering has finished, in order to reduce memory-usage.
Normally that shouldn't be a big problem, however when e.g. repeated zooming happens in the viewer that could easily lead to a lot of wasted resources (and waiting).

Hence this patch, which introduces a new `PDFPageProxy` method that will slightly delay cleanup after rendering.
2023-03-08 17:06:09 +01:00
Jonas Jenwald
e7a7f02f4c Convert a couple of fields/methods into properly private ones in PDFPageProxy
These were always intended to be *private*, so let's use modern JS features to actually enforce that.
2023-03-08 17:06:09 +01:00
calixteman
a0ef5a4ae1
Merge pull request #16115 from calixteman/issue16114
Apply transfer filters to any graphic commands
2023-03-08 14:53:41 +01:00
calixteman
32e2f7c8e5
Merge pull request #16131 from calixteman/issue16049
Partially revert PR 15578
2023-03-08 12:57:18 +01:00
Jonas Jenwald
6839f15a32
Merge pull request #16128 from Snuffleupagus/issue-16127
Support (rare) Type3 fonts with Pattern resources (issue 16127)
2023-03-08 12:21:53 +01:00
Jonas Jenwald
e5427ab11b
Merge pull request #16122 from Snuffleupagus/rm-onUnsupportedFeature
[api-minor] Remove the deprecated `onUnsupportedFeature` functionality (PR 15758 follow-up)
2023-03-08 12:16:27 +01:00
Calixte Denizet
dabfbc623e Partially revert PR 15578
The dimensions still need to be fixed (from times to times they're in px)
but it doesn't have to be postponed anymore.
To test it: draw something and when resizing look at the dimensions of the div
in devtools, the units must be %.
2023-03-08 12:10:27 +01:00
calixteman
cc555a389b
Merge pull request #16117 from calixteman/workaround_bug1820511
Avoid to have a factor too close to 2 when downscaling image
2023-03-08 11:12:56 +01:00
Calixte Denizet
1617ee6c3f Avoid to have a factor too close to 2 when downscaling image
It's a workaround for bug 1820511: it only affects Firefox on Windows
using the D2D backend.
2023-03-08 11:05:46 +01:00
calixteman
39ff039b8a
Merge pull request #16125 from calixteman/firefox_max_area
[api-minor] Add an option to set the max canvas area
2023-03-08 10:56:03 +01:00
Calixte Denizet
e9474f1c84 [api-minor] Add an option to set the max canvas area 2023-03-08 10:37:06 +01:00
Jonas Jenwald
471aef5fc6 Support (rare) Type3 fonts with Pattern resources (issue 16127)
This simply extends the approach in PR 10727 to also cover Patterns, which shouldn't be a common occurrence in Type3 fonts (since this is the first issue we've seen).
2023-03-08 09:20:52 +01:00
Calixte Denizet
8304df2520 Apply transfer filters to any graphic commands 2023-03-07 22:17:19 +01:00
calixteman
e0d934ac9d
Merge pull request #16124 from calixteman/issue16119
Slightly modify the max width of a tracking space
2023-03-07 22:12:02 +01:00
Calixte Denizet
b8dda089e2 Slightly modify the max width of a tracking space 2023-03-07 19:38:49 +01:00
Jonas Jenwald
6d3506548d [api-minor] Update the minimum supported Node.js version to 16
This patch updates the minimum supported environments as follows:
 - Node.js 16, which was released on 2021-04-20; see https://en.wikipedia.org/wiki/Node.js#Releases

Note also that Node.js 14 will very soon reach EOL, and thus no longer receive any security updates.
2023-03-07 16:33:56 +01:00
calixteman
ec5288caa5
Merge pull request #16121 from calixteman/issue16120
Use appearance stream to render locked annotations (bug 1723568)
2023-03-07 15:43:50 +01:00
Calixte Denizet
8db77cc361 Use appearance stream to render locked annotations (bug 1723568) 2023-03-07 15:01:31 +01:00
Jonas Jenwald
076fdbf6df
Merge pull request #16118 from Snuffleupagus/revert-update-rimraf
Revert "Update `rimraf` to version 4"
2023-03-07 13:38:30 +01:00
Jonas Jenwald
2f3dcc2327 [api-minor] Remove the deprecated onUnsupportedFeature functionality (PR 15758 follow-up)
This was deprecated in PR 15758, which has now been included in three official PDF.js releases.
While PR 15880 did limit the bundle-size impact of this functionality on e.g. the Firefox PDF Viewer, it still leads to some unnecessary "bloat" that these changes remove.
Furthermore, with this being deprecated there'd also be no effort put into e.g. extending the `UNSUPPORTED_FEATURES` list when handling future error cases.
2023-03-07 10:18:43 +01:00
Jonas Jenwald
2f2f1e5088 Revert "Update rimraf to version 4"
This reverts commit 32357e3d17.
2023-03-06 19:57:00 +01:00
calixteman
e11371c75f
Merge pull request #16110 from calixteman/norotate
[Annotation] Don't rotate an annotation when it has the NoRotate flag
2023-03-06 19:17:44 +01:00
Calixte Denizet
3849063d36 [Annotation] Don't rotate an annotation when it has the NoRotate flag 2023-03-06 17:27:11 +01:00
calixteman
652a6df62b
Merge pull request #16077 from calixteman/large_image
Render large images even if they're larger than the canvas limits (bug 1720282)
2023-03-05 15:38:51 +01:00
Calixte Denizet
05b0c9d7e6 Render large images even if they're larger than the canvas limits (bug 1720282)
The idea is to encode large image in BMP format (which is very simple and doesn't
require to compute any checksums) and then use createImageBitmap with a BMP blob
(which doesn't suffer of the Canvas/ImageData limits).
From a performance point of view, it isn't crazy (generating a large blob + decoding
it on the main thread is really not ideal) but at least we've something to display
which is a way better than a blank page (and one can notice that most of the time is
spent in decoding the image from the pdf stream).
2023-03-05 14:07:07 +01:00
Jonas Jenwald
d7e4be9cdb
Merge pull request #16107 from mozilla/dependabot/npm_and_yarn/minimist-1.2.7
Bump minimist from 1.2.5 to 1.2.7
2023-03-04 10:10:37 +01:00
dependabot[bot]
5cc65d193f
Bump minimist from 1.2.5 to 1.2.7
Bumps [minimist](https://github.com/minimistjs/minimist) from 1.2.5 to 1.2.7.
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](https://github.com/minimistjs/minimist/compare/v1.2.5...v1.2.7)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-04 02:42:21 +00:00
Ben Wagner
158c836e26 Correct PostScript trigonometric operators
PDF 32000-1:2008 7.10.5.1 "Type 4 (PostScript Calculator) Functions"
defers to the PostScript Language Reference for the description of these
functions. The PostScript Language Reference, third edition chapter 8
"Operators" defines the `angle` type as a "number of degrees". Section
8.1 defines "angle `sin` real", "angle `cos` real", and "num den `atan`
angle". The documentation for `atan` further states that it will return
an angle in degrees between 0 and 360.

Handle these operators correctly in `PostScriptEvaluator.execute`.
Convert the inputs to `sin` and `cos` from degrees to radians for use
with `Math.sin` and `Math.cos`. Correctly pop two values from the stack
for `atan`, use `Math.atan2`, and convert from radians to (positive)
degrees.
2023-03-03 17:25:11 -05:00
Jonas Jenwald
4e52bcee44
Merge pull request #16103 from Snuffleupagus/rm-direct-PDFDataRangeTransport
[api-minor] Remove calling `getDocument` directly with a `PDFDataRangeTransport`-instance (PR 15943 follow-up)
2023-03-02 18:25:00 +01:00
Jonas Jenwald
ceec93c832
[api-minor] Remove calling getDocument directly with a PDFDataRangeTransport-instance (PR 15943 follow-up)
This was deprecated in PR 15943, which has now been included in two official PDF.js releases.
Given that `PDFDataRangeTransport` is somewhat unlikely to be used outside of the *built-in* Firefox PDF Viewer, it doesn't seem necessary to wait longer before removing this.

Also, removes the specific error-message for GENERIC builds to not unnecessarily "advertise" using non-objects when calling the `getDocument`-function.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
2023-03-02 15:12:01 +01:00
calixteman
d4216264e8
Merge pull request #16062 from calixteman/create_image_in_worker
[api-minor] Generate images in the worker instead of the main thread.
2023-03-02 13:34:50 +01:00
Calixte Denizet
fd03cd5493 [api-minor] Generate images in the worker instead of the main thread.
We introduced the use of OffscreenCanvas in #14754 and this patch aims
to use them for all kind of images.
It'll slightly improve performances (and maybe slightly decrease memory use).
Since an image can be rendered in using some transfer maps but because of
OffscreenCanvas we don't have the underlying pixels array the transfer maps
stuff is re-implemented in using the SVG filter feComponentTransfer.
2023-03-01 17:40:12 +01:00
Jonas Jenwald
9640add1f7
Merge pull request #16100 from Snuffleupagus/getDocument-canvasFactory
[api-minor] Move the `canvasFactory` option into `getDocument`
2023-03-01 10:34:11 +01:00
Jonas Jenwald
f42a2e8451
[api-minor] Move the canvasFactory option into getDocument
Rather than repeatedly initializing a `canvasFactory`-instance for every page, move it to the document-level instead.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
2023-03-01 09:07:16 +01:00
Jonas Jenwald
22c9970309
Merge pull request #16095 from Snuffleupagus/worker-isOffscreenCanvasSupported
Check `OffscreenCanvas` support once on the worker-thread
2023-02-28 08:25:50 +01:00
Jonas Jenwald
45c332110e
Check OffscreenCanvas support once on the worker-thread
Currently we repeat the `FeatureTest.isOffscreenCanvasSupported` checks all over the worker-thread code, and with upcoming changes this will become even "worse".

Hence this patch, which changes the *worker-thread* default value for the `isOffscreenCanvasSupported`-parameter to `false` and moves the feature-testing into the `BasePdfManager`-constructor.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
2023-02-27 12:27:28 +01:00
Tim van der Meij
2da2ac492e
Merge pull request #16093 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-02-26 13:22:23 +01:00
Tim van der Meij
580180a720
Bump versions in pdfjs.config 2023-02-26 13:15:43 +01:00
Jonas Jenwald
af64149885
Merge pull request #16086 from mozilla/Snuffleupagus-textLayer-OffscreenCanvas
Use `OffscreenCanvas` as intended for all code-paths in `src/display/text_layer.js` (PR 15722 follow-up)
2023-02-24 22:40:18 +01:00
Jonas Jenwald
5075d0495b
Use OffscreenCanvas as intended for all code-paths in src/display/text_layer.js (PR 15722 follow-up)
Currently some `getCtx` calls will have `isOffscreenCanvasSupported === undefined` set, meaning that `OffscreenCanvas` isn't being used as intended, since no `TextLayerRenderTask._isOffscreenCanvasSupported` property exists.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
2023-02-24 11:29:58 +01:00
calixteman
9c58d4f7f2
Merge pull request #16082 from calixteman/fix_class_in_path
[Acroform] Use the full path to find the node in the XFA datasets where to store the value
2023-02-23 13:38:54 +01:00
Calixte Denizet
3a21423386 [Acroform] Use the full path to find the node in the XFA datasets where to store the value
I noticed several 'Path not found' errors because of a field called #subform[2].
From the XFA specs, the hash is used for a class of elements in the template tree.
When we're looking for a node in the datasets tree, it doesn't make sense to search
for a class. Hence the path element starting with a hash are just skipped.
2023-02-23 12:09:39 +01:00
calixteman
e676c9388d
Merge pull request #16080 from calixteman/link_hcm
[a11y] Improve the visibility of link annotations in HCM
2023-02-22 20:31:51 +01:00
Calixte Denizet
a074525bfb [a11y] Improve the visibility of link annotations in HCM
In order to help to identify a link, we add a border around it with the LinkText color.
And backdrop colors are inverted when the mouse pointer hovers them, this way it should
help to identify the link where the pointer is.
2023-02-22 19:39:28 +01:00
Jonas Jenwald
3f33fbf8cf
Merge pull request #16079 from mozilla/Snuffleupagus-PDFObjects-bitmap
Move the `ImageBitmap` clean-up into the `PDFObjects` class
2023-02-22 13:51:12 +01:00