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

19191 commits

Author SHA1 Message Date
Jonas Jenwald
06334c97ef Improve the loadingParams functionality in the API
- Move the definition of the `loadingParams` Object, to simplify the code.

 - Add a unit-test, since none existed and the viewer depends on this functionality.
2024-05-24 09:26:40 +02:00
Tim van der Meij
08bf96865d
Merge pull request #18154 from timvandermeij/integration-test-rect
Introduce a `getRect` utility function for the integration tests
2024-05-23 19:27:52 +02:00
Tim van der Meij
145d66090f
Introduce a getRect utility function for the integration tests
Over time the number of integration tests that get the rectangle for a
given selector has increased quite a bit, and the code to do so has
consequently become duplicated.

This commit refactors the integration tests to move the rectangle
fetching code to a single place, which reduces the code by over 400
lines and makes the individual tests simpler.
2024-05-23 18:40:03 +02:00
Tim van der Meij
0c562f0a98
Merge pull request #18153 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-05-23 17:35:03 +02:00
Tim van der Meij
af5d7908fe
Update translations to the most recent versions 2024-05-23 16:02:20 +02:00
Tim van der Meij
e40e95faf4
Update dependencies to the most recent versions 2024-05-23 16:02:18 +02:00
Tim van der Meij
1c3195b86f
Merge pull request #18152 from Snuffleupagus/TextLayerBuilder-shorter
Shorten the code in the `web/text_layer_builder.js` file
2024-05-23 14:48:00 +02:00
Jonas Jenwald
cb388c6658 Shorten the code in the web/text_layer_builder.js file
- Use `this` rather than explicitly spelling out the class-name in the static `#enableGlobalSelectionListener` method, since that leads to shorter code. Given that all the relevant static fields are *private* ESLint will catch any scope errors in the code.

 - Reduce a little bit of duplication when using the `#selectionChangeAbortController` signal.

 - Utilize early returns in the "selectionchange" event handler, since that reduces overall indentation which helps readability a tiny bit.
2024-05-23 13:53:51 +02:00
Tim van der Meij
b7b8e5ef78
Merge pull request #18145 from timvandermeij/merge-stream
Remove the `merge-stream` dependency in favor of the `ordered-read-streams` dependency
2024-05-22 16:48:42 +02:00
Tim van der Meij
723e5b2779
Remove the merge-stream dependency in favor of the ordered-read-streams dependency
The `merge-stream` dependency is no longer maintained and doesn't work
in combination with Gulp 5 anymore (for more information refer to
https://github.com/gulpjs/gulp/issues/2802#issuecomment-2094130656).

Fortunately the Gulp team maintains a drop-in replacement dependency
called `ordered-read-streams` with the same API as `merge-stream`.
Indeed, running all affected Gulp targets and comparing build artifacts
with `diff -r <old> <new>` confirms that no unexpected changes are made.

Fixes a part of #17922.
2024-05-22 15:14:36 +02:00
Tim van der Meij
821f3a1ef3
Merge pull request #18143 from Snuffleupagus/issue-18138
Improve /Page validation for linearized documents (issue 18138)
2024-05-22 13:27:49 +02:00
Jonas Jenwald
3afa9bfc42 Improve /Page validation for linearized documents (issue 18138)
The referenced PDF document contains corrupt linearization-data, that doesn't point to the *first* page as intended.
2024-05-22 12:04:02 +02:00
Jonas Jenwald
2a52fda11b
Merge pull request #17770 from Aditi-1400/fix-issue-16843
Add language attribute to canvas
2024-05-21 21:35:43 +02:00
Tim van der Meij
14942271d1
Merge pull request #17974 from timvandermeij/integration-tests-timeout-scripting
Remove most `waitForTimeout` usage from the scripting integration tests
2024-05-21 20:53:51 +02:00
Tim van der Meij
23de3fd549
Remove most waitForTimeout usage from the scripting integration tests
This commit replaces most `waitForTimeout` occurrences with calls to
`waitForFunction` or `waitForSandboxTrip`. Note that the occurrences in
the "must check that focus/blur callbacks aren't called" test remain
until we find a good way to ensure that nothing happened after the tab
switches (because currently we can't be sure that nothing happens since
there is nothing to await).
2024-05-21 18:36:05 +02:00
Tim van der Meij
2ad4601d04
Merge pull request #18129 from nicolo-ribaudo/test-css-only-zoom
Add test for drawing delay with CSS-only zoom
2024-05-21 18:35:05 +02:00
calixteman
5da2894278
Merge pull request #18136 from calixteman/ml_stamp
[Editor] Pass a buffer instead of a blob url to the ML api
2024-05-21 18:24:26 +02:00
calixteman
6860288df2
Merge pull request #17968 from calixteman/freetext_update_popup
[Editor] Update popup position and contents after a FreeText has been edited
2024-05-21 17:59:39 +02:00
Nicolò Ribaudo
53d866660a
Add test for drawing delay with CSS-only zoom
This commit adds a test for 0603d1ac18.
Before the fix the `pagerendered` events would be fired just 2-3
milliseconds after the call to `increaseScale`/`decreaseScale`.
2024-05-21 17:17:48 +02:00
Calixte Denizet
b20ddff300 [Editor] Pass a buffer instead of a blob url to the ML api 2024-05-21 17:07:03 +02:00
Calixte Denizet
2369e40d2e [Editor] Update popup position and contents after a FreeText has been edited 2024-05-21 16:54:10 +02:00
Aditi
9edca0a5ed Add lang attribute to canvas element
Fixes issue #16843.
In certain cases, the text layer was misaligned
due to a difference between the `lang` attribute
of the viewer and the canvas. This commit addresses
the problem by adding the `lang` attribute to the canvas.

The issue was caused because PDF.js uses serif/sans-serif
fonts to generate the text layer and relies on system fonts.
The difference in the `lang` attribute led to different fonts
being picked, causing the misalignment.
2024-05-21 19:41:24 +05:30
Jonas Jenwald
dce9c6d956
Merge pull request #18125 from Snuffleupagus/issue-18122
Support corrupt PDF documents that contain "endsteam" commands (issue 18122)
2024-05-21 16:09:01 +02:00
Tim van der Meij
661a62bb30
Merge pull request #18121 from calixteman/update_puppeteer_22_9_0
Update puppeteer to 22.9.0
2024-05-21 14:29:29 +02:00
Tim van der Meij
8753bd9b99
Merge pull request #18113 from timvandermeij/through2
Remove the `through2` dependency in favor of the built-in Node.js `stream.Transform`
2024-05-21 14:20:14 +02:00
Jonas Jenwald
57014d0d13 Support corrupt PDF documents that contain "endsteam" commands (issue 18122)
This patch also re-factors the findStreamLength-helper to avoid even more code duplication.
2024-05-21 13:38:17 +02:00
Jonas Jenwald
9ee7c07b83
Merge pull request #18104 from Snuffleupagus/TextLayer-class
[api-minor] Re-factor the basic textLayer-functionality
2024-05-21 12:28:28 +02:00
Jonas Jenwald
59637c1fa8
Merge pull request #18115 from Snuffleupagus/freeze-evaluatorOptions
Freeze `evaluatorOptions` in the src/core/pdf_manager.js file
2024-05-21 12:19:04 +02:00
Calixte Denizet
9dcaff230c Update puppeteer to 22.9.0 2024-05-20 22:01:59 +02:00
Jonas Jenwald
db7e68aea8
Merge pull request #18119 from Snuffleupagus/issue-18117
Support charCodes larger than 32-bit in `adjustMapping` (issue 18117)
2024-05-20 13:08:28 +02:00
Jonas Jenwald
440b4b6eeb Support charCodes larger than 32-bit in adjustMapping (issue 18117)
This also required changing the initial `charCodeToGlyphId`-data to an Object, which seems generally correct since it's consistent with existing code in the `src\core\{cff_font, type1_font}.js` files.
2024-05-20 12:13:55 +02:00
Jonas Jenwald
3cd6c6c0e6 Freeze evaluatorOptions in the src/core/pdf_manager.js file
Given that these options are passed from the API we don't want to accidentally modify them.
2024-05-18 15:16:12 +02:00
Tim van der Meij
c7739dae13
Remove the through2 dependency in favor of the built-in Node.js stream.Transform
The `through2` dependency got introduced over four years ago in #11325 to
replace the unmaintained `gulp-transform` dependency. However, sadly the
same holds for `through2` since the last release was also four years ago.

Fortunately the `through2` dependency can trivially be replaced with the
built-in Node.js `stream.Transform` API nowadays. In fact, the `through2`
dependency mentions themselves in their README already that they are "a
tiny wrapper around Node.js streams.Transform". The `stream.Transform`
API is available in all Node.js versions we support, and in Node.js 6
already the simplified constructor approach for `stream.Transform` got
introduced to simplify creating custom stream transformers; see
https://nodejs.org/docs/latest-v6.x/api/stream.html#stream_new_stream_transform_options.

This commit therefore replaces `through2` by switching to the
`stream.Transform` API directly so we don't need any wrappers anymore.
Note that for our case the only change we have to make is to enable
object mode, see https://nodejs.org/api/stream.html#object-mode, because
we pass in `VinylFile` objects instead of e.g. regular `Buffer` objects.

I have confirmed in two ways that this is indeed a drop-in replacement:

- Running the Gulp targets that call the `transform` function and
  diffing the resulting `build` folder before/after this patch, with
  `diff -r build-old/ build-new/`, to ensure that there are no
  unexpected changes in the output.
- Changing the Gulpfile to, instead of UTF-8, transform the files to
  ASCII, and diffing the resulting `build` folder to confirm that the
  transformation logic works and produces different results, such as:

```
diff build/lib/core/standard_fonts.js build-ascii/lib/core/standard_fonts.js
284c284
<   t["Trinité"] = true;
---
>   t["Trinit�"] = true;
```
2024-05-17 16:32:31 +02:00
Jonas Jenwald
15b5808eee [api-minor] Re-factor the basic textLayer-functionality
This is very old code, and predates e.g. the introduction of JavaScript classes, which creates unnecessarily unwieldy code in the viewer.
By introducing a new `TextLayer` class in the API, similar to how e.g. the `AnnotationLayer` looks, we're able to keep most parameters on the class-instance itself. This removes the need to manually track them in the viewer, and simplifies the call-sites.

This also removes the `numTextDivs` parameter from the "textlayerrendered" event, since that's only added to support default-viewer functionality that no longer exists.

Finally we try, as far as possible, to polyfill the old `renderTextLayer` and `updateTextLayer` functions since they are exposed in the library API.
For *simple* invocations of `renderTextLayer` the behaviour should thus be the same, with only a warning printed in the console.
2024-05-17 14:20:20 +02:00
Tim van der Meij
63b66b412c
Merge pull request #18109 from Snuffleupagus/textLayer-no-cleanup-on-pending
Don't invoke `cleanupTextLayer` when there are pending textLayers
2024-05-17 14:10:33 +02:00
Jonas Jenwald
d8e0fca609 Don't invoke cleanupTextLayer when there are pending textLayers
*Please note:* This doesn't really affect the viewer, but may affect the library API if multiple PDF documents are opened in parallel.

Since we clean-up "global" textLayer-data when destroying a PDF document, this means that other active PDFs could potentially break by invoking `cleanupTextLayer` unconditionally. Note that textLayer rendering is an asynchronous task, and we thus need to ensure those are all finished before running clean-up.
2024-05-17 08:52:10 +02:00
Tim van der Meij
ab9574fc62
Merge pull request #18107 from timvandermeij/needle
Remove the obsolete `needle` dependency
2024-05-16 20:31:51 +02:00
Tim van der Meij
ca056d79dd
Remove the obsolete needle dependency
The `needle` dependency originally got introduced in #12024, almost four
years ago, to be able to use pre-built binaries for the `canvas`
dependency on macOS. However, nowadays the `needle` dependency isn't
used by `canvas` anymore, or any other package we use for that matter,
as shown by the empty NPM dependency tree:

```
$ npm ls needle
pdf.js
└── needle@3.3.1
```

Investigation showed that the `canvas` package depends on the
`node-pre-gyp` package which in turn depended on `needle` (see
https://github.com/Automattic/node-canvas/issues/1110#issuecomment-411232630),
but in version 1.0.0 of `node-pre-gyp` from three years ago the `needle`
dependency got dropped in favor of `node-fetch` (see
a74f5e367c/CHANGELOG.md (L52)).
This explains why the NPM dependency tree is empty now and proves that
we can safely get rid of this dependency now.
2024-05-16 20:07:01 +02:00
Tim van der Meij
e8e9a3e29f
Merge pull request #18106 from timvandermeij/rimraf
Remove the `rimraf` dependency in favor of the built-in Node.js `fs.rmSync`
2024-05-16 19:19:42 +02:00
Tim van der Meij
fad14321a8
Remove the rimraf dependency in favor of the built-in Node.js fs.rmSync
In Node.js 14.14.0 the `fs.rmSync` function was added that removes files
and directories. The `recursive` option is used to remove directories
and their contents, making it a drop-in replacement for the `rimraf`
dependency we use.

Given that PDF.js now requires Node.js 18+ we can be sure that this
option is available, so we can safely remove `rimraf` and reduce the
number of project dependencies.

Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
2024-05-16 17:37:27 +02:00
Tim van der Meij
0603d1ac18
Merge pull request #18077 from Snuffleupagus/issue-18022
[api-minor] Respect the `drawingDelay` also when CSS-only zooming is used (issue 18022)
2024-05-16 14:19:40 +02:00
Tim van der Meij
128705c16e
Merge pull request #18103 from Snuffleupagus/pr-18089-followup
Actually disable `TextLayerRenderTask.prototype.#processItems` when `MAX_TEXT_DIVS_TO_RENDER` is reached (PR 18089 follow-up)
2024-05-16 14:17:09 +02:00
Jonas Jenwald
d5f3829f91 Actually disable TextLayerRenderTask.prototype.#processItems when MAX_TEXT_DIVS_TO_RENDER is reached (PR 18089 follow-up)
I broke this accidentally in PR 18089, sorry about that!
Note that since `#processItems` is private we can no longer just "replace" the method as was done in PR 18052.
2024-05-16 11:48:11 +02:00
Tim van der Meij
4db843617f
Merge pull request #18047 from Snuffleupagus/issue-18042
Avoid re-parsing global images that failed decoding (issue 18042, PR 17428 follow-up)
2024-05-15 15:40:18 +02:00
Tim van der Meij
b800268fca
Merge pull request #18094 from Snuffleupagus/rm-unnecessary-signal
Remove unnecessary `signal` parameter from `removeEventListener` calls
2024-05-15 13:34:41 +02:00
Tim van der Meij
66c2bf62c1
Merge pull request #18093 from timvandermeij/exception
Implement a unit test for the `BaseException` class
2024-05-15 13:33:25 +02:00
Jonas Jenwald
656963e72a Remove unnecessary signal parameter from removeEventListener calls
This parameter is not necessary, as outlined in https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#options
2024-05-15 09:09:50 +02:00
Tim van der Meij
6b237e3358
Implement a unit test for the BaseException class
The issue from #18003 hasn't been shown to be caused by PDF.js, but it
did surface that we don't have (direct) unit test coverage for the
`BaseException` class. This made it more difficult to prove that the
`stack` property was already available on exception instances, but more
importantly it caused the CI to be green even though the suggested
change would have caused the `stack` property to disappear.

To avoid future regressions, for e.g. similar changes or a rewrite from
a closure to a proper class, this commit introduces a dedicated unit
test for `BaseException` that asserts that our exception instances
indeed expose all expected properties.
2024-05-14 20:21:42 +02:00
Tim van der Meij
7e5e06b886
Merge pull request #18091 from Snuffleupagus/rm-_fetchDocument
Inline the `_fetchDocument` helper function in `getDocument`
2024-05-14 18:27:04 +02:00
Tim van der Meij
44b7cc517d
Merge pull request #18092 from timvandermeij/updates
Update dependencies and translations to the most  recent versions
2024-05-14 18:00:43 +02:00