1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 00:58:07 +02:00
Commit graph

20185 commits

Author SHA1 Message Date
Jonas Jenwald
7450457525 [api-major] Change viewer component render-methods to take parameter objects
This is nicer than a bunch of somewhat arbitrarily ordered parameters, and makes any future changes easier.
2025-01-21 23:29:45 +01:00
Jonas Jenwald
79a976ce9d
Merge pull request #19337 from Snuffleupagus/dev-wasm
Support multiple wasm-files in the development viewer
2025-01-21 10:50:17 +01:00
Jonas Jenwald
23dc3ff49f
Merge pull request #19353 from Snuffleupagus/ESLint-import/no-restricted-paths
Enable the `import/no-restricted-paths` ESLint plugin rule for the viewer
2025-01-20 22:28:50 +01:00
Jonas Jenwald
850e605e36
Merge pull request #19356 from Snuffleupagus/bug-1942064-2
Replace the EXIF-block with dummy data to prevent JPEG images being rotated (bug 1942064)
2025-01-20 16:54:09 +01:00
Jonas Jenwald
c4ba3ac23f Replace the EXIF-block with dummy data to prevent JPEG images being rotated (bug 1942064)
The `ImageDecoder` will respect the EXIF orientation, which can lead to JPEG images being incorrectly rotated. To avoid this we replace the entire EXIF-block with dummy data, which works since it'll cause EXIF parsing to bail out early in Firefox; see https://searchfox.org/mozilla-central/rev/9a66d18cb35595c89f499a1011c9dd7e573fce77/image/decoders/EXIF.cpp#130-138
2025-01-20 16:50:22 +01:00
Jonas Jenwald
d91830c447 Enable the import/no-restricted-paths ESLint plugin rule for the viewer
Code in the `web/` folder cannot import directly from the `src/` folder, since that could result in most (or all) main-thread code being bundled into the viewer, and must rather be imported via the `pdfjs-lib` alias.

Let's use ESLint to help enforce this, please find additional details in https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md
2025-01-20 11:40:29 +01:00
Jonas Jenwald
01d542eee5
Merge pull request #19351 from timvandermeij/integration-tests-ink
Centralize the editor selector definitions in the ink editor integration tests
2025-01-20 10:23:08 +01:00
Jonas Jenwald
b950c51373
Merge pull request #19350 from timvandermeij/integration-tests-stamp
Centralize the editor selector definitions in the stamp editor integration tests
2025-01-20 10:21:00 +01:00
Tim van der Meij
bd67156ef5
Centralize the editor selector definitions in the ink editor integration tests
In most integration tests we already use the pattern of defining the
editor selector once and reusing it in the rest of the test, but it's
not fully consistent everywhere yet. This commit fixes that for the
ink editor integration tests, which has multiple advantages:

- it improves consistency between the various editor integration tests;
- it removes duplicate function calls and aligns variable definitions;
- it reduces the number of `getEditorSelector` calls that contained
  hardcoded IDs, which helps to isolate the tests and to simplify
  follow-up patches.
2025-01-19 19:46:50 +01:00
Tim van der Meij
0f95617b4c
Centralize the editor selector definitions in the stamp editor integration tests
In most integration tests we already use the pattern of defining the
editor selector once and reusing it in the rest of the test, but it's
not fully consistent everywhere yet. This commit fixes that for the
stamp editor integration tests, which has multiple advantages:

- it improves consistency between the various editor integration tests;
- it removes duplicate function calls and aligns variable definitions;
- it reduces the number of `getEditorSelector` calls and other helper
  function calls that contained hardcoded IDs (by updating them to take
  editor selectors as arguments instead of editor IDs), which helps to
  isolate the tests and to simplify follow-up patches.
2025-01-19 19:33:35 +01:00
Tim van der Meij
c7b35ecd78
Enable a disabled stamp editor integration test in Chrome
Puppeteer recently got updated to version 24.0.0+, so we're past version
23.9.1- where the integration test failed before and we can enable it
again now that it passes in Chrome.
2025-01-19 19:05:42 +01:00
Tim van der Meij
ac57939648
Merge pull request #19344 from timvandermeij/integration-tests-editor-helpers
Implement helper functions for (un)selecting an editor in the integration tests
2025-01-19 18:39:04 +01:00
Tim van der Meij
895edafc23
Implement a helper function for unselecting an editor in the integration tests
This has multiple advantages:

- it improves consistency between the various editor integration tests;
- it makes the code easier to read/understand;
- it reduces code duplication.
2025-01-19 12:26:17 +01:00
Tim van der Meij
c051dd78cf
Implement a helper function for selecting an editor in the integration tests
This has multiple advantages:

- it improves consistency between the various editor integration tests;
- it makes the code easier to read/understand;
- it reduces code duplication;
- it reduces the number of `getEditorSelector` calls that contained
  hardcoded IDs, which helps to isolate the tests and to simplify
  follow-up patches.
2025-01-19 12:26:17 +01:00
Tim van der Meij
5026af107f
Align variable names in the freetext editor integration tests
The `selectorEditor` name is used 57 times, but only in the freetext
editor integration tests file. The `editorSelector` name on the other
hand is used 241 times in all editor integration test files, so this
commit renames the former name to the latter name to achieve consistency
in variable names across all editor integration test files, which also
simplifies upcoming changes.
2025-01-18 20:35:25 +01:00
Tim van der Meij
50b7922f8c
Merge pull request #19342 from timvandermeij/updates
Update dependencies to the most recent versions
2025-01-18 20:34:11 +01:00
Tim van der Meij
615ed67174
Update dependencies to the most recent versions 2025-01-18 18:55:44 +01:00
Jonas Jenwald
54729a57b7
Merge pull request #19341 from Snuffleupagus/api-Default-Factory
Inline the default Factory-definitions in `getDocument`
2025-01-18 14:20:57 +01:00
Jonas Jenwald
db43f158dc Inline the default Factory-definitions in getDocument
- Most of the these are only used in the `src/display/api.js` file, and this leads to slightly shorter code.

 - A number of unit-tests need a `BaseCanvasFactory`-instance, however that one is available through the `PDFDocumentProxy`-instance nowadays.

 - For other unit-tests the remaining necessary default Factory-definitions can be moved into the `test/unit/test_utils.js` file.
2025-01-18 14:09:14 +01:00
Tim van der Meij
6d12d2924f
Merge pull request #19331 from Snuffleupagus/api-Factory-JSDoc
Simplify the JSDocs for the various `getDocument` Factory-parameters
2025-01-18 13:38:29 +01:00
Jonas Jenwald
3adec3724c
Merge pull request #19340 from calixteman/issue19336
Handle the case where openjpeg.wasm is missing
2025-01-18 09:36:14 +01:00
Jonas Jenwald
0053b36ee7 Support multiple wasm-files in the development viewer
This prepares for a future where we're using more than one wasm-file, originating in different `external/`-folders, by extending the existing `gulp.watch` usage.
The following diff illustrates how to add more entries:

```diff
diff --git a/gulpfile.mjs b/gulpfile.mjs
index 0e0a5a1ac..1502755be 100644
--- a/gulpfile.mjs
+++ b/gulpfile.mjs
@@ -655,6 +655,10 @@ function createWasmBundle() {
       base: "external/openjpeg",
       encoding: false,
     }),
+    gulp.src(["external/foobar/*.wasm"], {
+      base: "external/foobar",
+      encoding: false,
+    }),
   ]);
 }

@@ -2125,7 +2129,7 @@ gulp.task(
     },
     function watchWasm() {
       gulp.watch(
-        "external/openjpeg/*",
+        ["external/openjpeg/*", "external/foobar/*"],
         { ignoreInitial: false },
         gulp.series("dev-wasm")
       );
```
2025-01-18 09:35:11 +01:00
Calixte Denizet
0c14d6e2db Handle the case where openjpeg.wasm is missing
It fixes #19336.
2025-01-17 22:11:24 +01:00
Jonas Jenwald
45a32b7c58
Merge pull request #19335 from Snuffleupagus/test-rm-console-log-spam
Reduce console spam when running tests in Firefox
2025-01-17 11:29:23 +01:00
Jonas Jenwald
851a52faf3
Merge pull request #19333 from Snuffleupagus/src-core-fetchBinaryData
Handle JPX wasm fetch-response errors correctly (PR 19329 follow-up)
2025-01-17 11:29:12 +01:00
Jonas Jenwald
534bd3e4a8 Reduce console spam when running tests in Firefox
Rather than waiting for the upstream patch to reach the Firefox version we're using with Puppeteer, let's just set the same preference as done in https://phabricator.services.mozilla.com/D234320.
2025-01-17 10:58:46 +01:00
Jonas Jenwald
6038b5a992 Handle JPX wasm fetch-response errors correctly (PR 19329 follow-up)
Currently we're not checking that the response is actually OK before getting the data, which means that rather than throwing an error we can get an empty `ArrayBuffer`.

To avoid duplicating code we can move an existing helper into `src/core/core_utils.js` and re-use it when fetching the JPX wasm-file as well.
2025-01-17 10:20:16 +01:00
Jonas Jenwald
88735d0f14
Merge pull request #19332 from Snuffleupagus/version-5.0
Bump library version to `5.0`
2025-01-16 23:25:39 +01:00
Jonas Jenwald
12d114bccb
Merge pull request #19264 from Snuffleupagus/ResponseException
[api-major] Replace `MissingPDFException` and `UnexpectedResponseException` with one exception
2025-01-16 23:23:16 +01:00
Jonas Jenwald
7765af228d Bump library version to 5.0 2025-01-16 23:07:09 +01:00
Jonas Jenwald
1ddce76a8b Simplify the JSDocs for the various getDocument Factory-parameters
Given that we nowadays provide default Node.js versions of these Factory-parameters it no longer seems necessary to mention that environment specifically.
2025-01-16 23:01:36 +01:00
Jonas Jenwald
75cba72ca6 [api-major] Replace MissingPDFException and UnexpectedResponseException with one exception
These old exceptions have a fair amount of overlap given how/where they are being used, which is likely because they were introduced at different points in time, hence we can shorten and simplify the code by replacing them with a more general `ResponseException` instead.

Besides an error message, the new `ResponseException` instances also include:
 - A numeric `status` field containing the server response status, similar to the old `UnexpectedResponseException`.

 - A boolean `missing` field, to allow easily detecting the situations where `MissingPDFException` was previously thrown.
2025-01-16 22:51:05 +01:00
calixteman
7a57af12e1
Merge pull request #19329 from calixteman/bug1935076_1
[api-major] Add openjpeg.wasm to pdf.js (bug 1935076)
2025-01-16 22:32:46 +01:00
Calixte Denizet
94b4b54ef6 [api-major] Add openjpeg.wasm to pdf.js (bug 1935076)
In order to fix bug 1935076, we'll have to add a pure js fallback in case wasm is disabled
or simd isn't supported. Unfortunately, this fallback will take some space.

So, the main goal of this patch is to reduce the overall size (by ~93k).
As a side effect, it should make easier to use an other wasm file (which must export
_jp2_decode, _malloc and _free).
2025-01-16 21:09:50 +01:00
Jonas Jenwald
711bf2bd12
Merge pull request #19324 from nicolo-ribaudo/search-dash-date
Allow searching for number-number on two lines
2025-01-15 15:04:09 +01:00
Nicolò Ribaudo
8358ab63b3
Allow searching for number-number on two lines
When a dash separates two digits, it's very likely to not be a hyphen
inserted to split a word into two lines (e.g. "par\n-ser"), but rather
either a minus sign, a range, or a date. For example, in the tracemonkey
PDF there is `2008-02` (a date) split across two lines.

Preserving the dash, similarly to how we do for compound words, allows
searches for "2008-02" to find a match.
2025-01-15 14:23:04 +01:00
Jonas Jenwald
2533a08779
Merge pull request #19327 from Snuffleupagus/issue-19326
Access the number of components correctly in JPEG 2000 images with color space entries (issue 19326)
2025-01-15 11:17:24 +01:00
Jonas Jenwald
e5bc760316 Access the number of components correctly in JPEG 2000 images with color space entries (issue 19326)
This small typo appears to be a regression from PR 18204.
2025-01-15 10:16:06 +01:00
Jonas Jenwald
016de74229
Merge pull request #19320 from nicolo-ribaudo/stamp-double-click
Enable editor when double-clicking on stamp annotation
2025-01-14 12:02:30 +01:00
Nicolò Ribaudo
60dd8147c6
Enable editor when double-clicking on stamp annotation
In Firefox, double-clicking on a stamp annotation triggers text
selection (selecting the last text element in the dom before the
annotation): this triggers the logic to make annotations not interfere
with text selection, which in turns prevents the double click from
triggering the annotation editor.

This commit fixes the problem by making annotations non-selectable, so
that clicking on them does not trigger text selection. Freetext
annotations were already non-selectable, so this commit doesn't change
that. However, we need to explicitly mark text in popups as selectable.
2025-01-14 11:16:59 +01:00
Tim van der Meij
61995e9e37
Merge pull request #19321 from Snuffleupagus/issue-19319
Improve performance when reading very large TrueType "cmap" tables (issue 19319)
2025-01-13 20:21:14 +01:00
Tim van der Meij
0b1a840fa2
Merge pull request #19318 from timvandermeij/puppeteer-24
Upgrade Puppeteer to version 24.0.0
2025-01-13 20:18:56 +01:00
Jonas Jenwald
5e569cade5 Improve performance when reading very large TrueType "cmap" tables (issue 19319)
In the affected font the total number of mapping-entries is `1142348`, and no less than `997473` of them are duplicates.
Given that every duplicate causes a lot of Array elements to be moved this becomes extremely inefficient, which we can avoid by keeping track of seen `charCode`s and directly build the final mappings-Array instead.
2025-01-13 13:09:47 +01:00
Tim van der Meij
d7e6d95304
Upgrade Puppeteer to version 24.0.0
This is a major version bump, but the changelog at
https://github.com/puppeteer/puppeteer/releases/tag/puppeteer-core-v24.0.0
doesn't indicate any breaking changes that should impact us.
2025-01-12 19:48:05 +01:00
Tim van der Meij
e1b972aac3
Merge pull request #19317 from Snuffleupagus/FontRendererFactory-reuse-helpers
Re-use existing helper functions in `FontRendererFactory`
2025-01-12 15:20:43 +01:00
Tim van der Meij
db40155d33
Merge pull request #19313 from timvandermeij/updates
Update dependencies to the most recent versions
2025-01-12 15:14:56 +01:00
Jonas Jenwald
e0be2a02dc Re-use existing helper functions in FontRendererFactory
Currently we re-implement a number of helper functions specifically for this code, which seems completely unnecessary since there's already general purpose ones available in the `src/core/core_utils.js` file.
2025-01-12 13:01:54 +01:00
calixteman
b5218853b4
Merge pull request #19312 from calixteman/improve_touch
[Editor] Improve zooming with a pinch gesture while drawing
2025-01-10 18:30:55 +01:00
calixteman
3cd5521270
Merge pull request #19311 from calixteman/issue19239
[Editor] Don't try to use an non-existing canvas when rendering an in visible existing stamp editor
2025-01-10 16:32:22 +01:00
Calixte Denizet
8483ae0f88 [Editor] Improve zooming with a pinch gesture while drawing
It lets the user make a pinch gesture with a finger on page with a drawing
and the second finger on an other page.
On mobile, it's pretty easy to be in such a situation.
2025-01-10 16:24:58 +01:00