Compare commits

...

2652 Commits

Author SHA1 Message Date
Tim van der Meij
4aca13e77a
Merge pull request #20469 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-11-29 16:00:32 +01:00
Tim van der Meij
0b051a7cad
Bump the stable version in pdfjs.config 2025-11-29 15:57:15 +01:00
Tim van der Meij
f44e5f0e63
Merge pull request #20462 from calixteman/improve_thumbnails
Slightly reduce the memory used by thumbnails
2025-11-29 15:36:46 +01:00
Calixte Denizet
423379e42f
Slightly reduce the memory used by thumbnails
In using a blob instead of a base64 string it's possible to reduce the memory.
And simplify a bit the thumbnails themselves.
2025-11-28 21:52:40 +01:00
Tim van der Meij
a965536485
Merge pull request #20468 from timvandermeij/trusted-publishing
Use OIDC trusted publishing in the GitHub Actions release workflow
2025-11-28 21:13:06 +01:00
Tim van der Meij
8eb747663a
Use OIDC trusted publishing in the GitHub Actions release workflow
This commit updates the release pipeline to use OIDC trusted publishing
now that we have configured it between GitHub Actions and NPM. This
solution allows us to remove the token variable (because there is no
longer a fixed token) and provenance flag (because provenance
attestations are generated by default with this approach); refer to
https://docs.npmjs.com/trusted-publishers for more information.
2025-11-28 21:01:13 +01:00
calixteman
ec5330f78c
Merge pull request #20465 from calixteman/update_char_to_nfkc
Fix the regex string used to find the chars to normalize with NFKC when searching
2025-11-28 16:59:23 +01:00
calixteman
925fc3d8f2
Merge pull request #20467 from calixteman/make_sidebar
Create a sidebar object
2025-11-28 16:27:44 +01:00
Calixte Denizet
45578aa8f5
Create a sidebar object
For now its use is limited to the comment sidebar but it'll be used for the new one
containing the thumbnails.
And make the sidebar more accessible with the keyboard or a screen reader.
2025-11-28 16:22:26 +01:00
Calixte Denizet
eee20cf138
Fix the regex string used to find the chars to normalize with NFKC when searching
ICU has been updated in Firefox (see https://bugzilla.mozilla.org/show_bug.cgi?id=2000225).
The char `0xA7F1` is now alphabetic and can be normalized as a "S".
2025-11-28 16:19:43 +01:00
Tim van der Meij
907cceb4ab
Merge pull request #20460 from calixteman/issue20452
[Editor] Allow to save an edited comment in using CTRL+Enter shortcut.
2025-11-27 21:37:07 +01:00
Tim van der Meij
40b52fa43a
Merge pull request #20458 from calixteman/fix_firstchild
Don't use firstChild/lastChild when getting elements (follow-up of #20447)
2025-11-27 21:34:56 +01:00
Tim van der Meij
08074cf024
Merge pull request #20450 from Mario34/update-dependencies
Include missing `cached-iterable` dev dependency in `package.json`
2025-11-27 21:16:21 +01:00
Tim van der Meij
956aa7efad
Merge pull request #20459 from mozilla/dependabot/github_actions/actions/checkout-6
Bump actions/checkout from 5 to 6
2025-11-27 21:07:51 +01:00
Calixte Denizet
b6fcb523c5
[Editor] Allow to save an edited comment in using CTRL+Enter shortcut. 2025-11-24 20:20:31 +01:00
dependabot[bot]
f6ad1a5610
Bump actions/checkout from 5 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-24 12:42:52 +00:00
Mario34
0bad4e938e Include missing cached-iterable dev dependency in package.json
This dependency got introduced during the move to Fluent for
localization (bug 1858715), but it wasn't added to `package.json`
at the time. This worked because other dependencies already
installed it, but we shouldn't rely on that, so this commit
explicitly includes it in `package.json` instead.

Fixes 66982a2a.
2025-11-24 09:24:20 +08:00
calixteman
029cae2ad4 Don't use firstChild/lastChild when getting elements (follow-up of #20447) 2025-11-22 21:10:32 +01:00
calixteman
ec71e4ed65
Merge pull request #20455 from calixteman/bug1998843
[XFA] Set default max value in occur tag to -1 (bug 1998843)
2025-11-22 20:59:04 +01:00
calixteman
d4b6464675
Merge pull request #20456 from calixteman/issue20225
When searching for a group of punctuation signs, only add extraspaces around the group
2025-11-22 15:25:25 +01:00
calixteman
b41959bde8
Merge pull request #20413 from sachiniyer/siyer/fix-annotation-editor-deletion
fix: deleteAnnotationElement takes a full editor object
2025-11-21 22:28:06 +01:00
Sachin Iyer
464dae11ac fix: deleteAnnotationElement takes a full editor object 2025-11-21 11:32:29 -08:00
Calixte Denizet
039b9e4df3 When searching for a group of punctuation signs, only add extraspaces around the group
It fixes #20225.

And only add the extra spaces where it's required depending on their position in the query string.
2025-11-21 18:59:37 +01:00
Calixte Denizet
516aea5562 [XFA] Set default max value in occur tag to -1 (bug 1998843) 2025-11-21 17:53:38 +01:00
calixteman
ddf3a989ca
Merge pull request #20427 from Aditi-1400/issue-20426
Add setter for some FontFaceObject properties
2025-11-20 20:49:30 +01:00
Aditi
7743d11594 Add setter for some FontFaceObject properties 2025-11-20 22:47:57 +05:30
Tim van der Meij
8f0c62990e
Merge pull request #20447 from calixteman/lint_html
Lint and format the HTML in using Prettier
2025-11-18 21:11:52 +01:00
Tim van der Meij
20393c4c57
Merge pull request #20449 from mozilla/dependabot/npm_and_yarn/js-yaml-3.14.2
Bump js-yaml from 3.14.1 to 3.14.2
2025-11-18 20:51:32 +01:00
dependabot[bot]
b392cbf3c4
Bump js-yaml from 3.14.1 to 3.14.2
Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 3.14.1 to 3.14.2.
- [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nodeca/js-yaml/compare/3.14.1...3.14.2)

---
updated-dependencies:
- dependency-name: js-yaml
  dependency-version: 3.14.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-18 19:46:50 +00:00
Tim van der Meij
1c4c16f18f
Merge pull request #20448 from mozilla/dependabot/npm_and_yarn/multi-12cb0b0c21
Bump glob
2025-11-18 20:45:28 +01:00
dependabot[bot]
447aab7fe6
Bump glob
Bumps  and [glob](https://github.com/isaacs/node-glob). These dependencies needed to be updated together.

Updates `glob` from 10.4.5 to 10.5.0
- [Changelog](https://github.com/isaacs/node-glob/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/node-glob/compare/v10.4.5...v10.5.0)

Updates `glob` from 11.0.3 to 11.1.0
- [Changelog](https://github.com/isaacs/node-glob/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/node-glob/compare/v10.4.5...v10.5.0)

---
updated-dependencies:
- dependency-name: glob
  dependency-version: 10.5.0
  dependency-type: indirect
- dependency-name: glob
  dependency-version: 11.1.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-18 17:43:29 +00:00
Calixte Denizet
b9368b576d Lint and format the HTML in using Prettier
The linter found some issues in viewer.html with </input> which isn't required
and a missing closing div in test/resources/reftest-analyzer.html.
The HTML can now be nicely formatted. In order to not break the build for
mozilla-central, the preprocessor has been fixed in order to take into account
the white spaces at the beginning of a comment line.
And finally, make .prettierrc (which is supposed to be either json or yaml)
itself lintable.
2025-11-18 17:22:50 +01:00
calixteman
264046736d
Merge pull request #20151 from maettuu/reg-test-pr-19184
Add regression test for PR 19184
2025-11-18 09:26:11 +01:00
calixteman
c6b61a34e6
Merge pull request #20436 from calixteman/merge_struct_trees
Merge the structure trees coming from different pdfs (bug 1997379)
2025-11-17 20:10:06 +01:00
calixteman
b20bd9061e
Merge pull request #20405 from calixteman/add_telemetry_tagged_pdf
Add telemetry for tagged pdfs (bug 1997134)
2025-11-17 20:09:40 +01:00
Calixte Denizet
e13a618df3 Merge the structure trees coming from different pdfs (bug 1997379) 2025-11-17 19:56:36 +01:00
Calixte Denizet
50c48cf11b Add telemetry for tagged pdfs (bug 1997134) 2025-11-17 19:47:16 +01:00
Tim van der Meij
603e3a8f3e
Merge pull request #20430 from timvandermeij/freetext-helper
Introduce a helper function to create a freetext editor in the integration tests
2025-11-16 14:50:17 +01:00
Tim van der Meij
f880f4b803
Merge pull request #20429 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-11-16 14:49:52 +01:00
calixteman
e7288dca8e
Merge pull request #20431 from calixteman/split_merge_p4
Add a wrapper for the new xref in order to be able to get some values from cloned dictionaries
2025-11-11 21:47:42 +01:00
Tim van der Meij
bc4d90711a
Merge pull request #20432 from calixteman/version
Version entry in the catalog has to be a name and not a string
2025-11-11 20:31:59 +01:00
Calixte Denizet
a98b0b1fb5 Version entry in the catalog has to be a name and not a string 2025-11-09 15:34:57 +01:00
Calixte Denizet
65881f0e21 Add a wrapper for the new xref in order to be able to get some values from cloned dictionaries 2025-11-09 15:28:43 +01:00
calixteman
3676ffde17
Merge pull request #20421 from calixteman/split_merge_p3
Update the named page destinations when some pdf are combined (bug 1997379)
2025-11-09 15:19:05 +01:00
Tim van der Meij
b5b821365e
Introduce a helper function to create a freetext editor in the integration tests
Doing so has a number of advantages:

- it removes code duplication, thereby improving readability;
- it removes hardcoded editor IDs, by using the `getNextEditorId` helper
  function that was previously introduced for the highlight editor
  integration tests, thereby improving readability and reusability;
- it removes potential for intermittent failures by not proceeding until
  the freetext editor is fully created and all assertions pass, which
  didn't happen consistently before because the code wasn't centralized.
2025-11-09 14:32:24 +01:00
Tim van der Meij
398ba0331c
Update translations to the most recent versions 2025-11-08 19:27:15 +01:00
Tim van der Meij
7fc23de26f
Update dependencies to the most recent versions 2025-11-08 19:26:17 +01:00
Calixte Denizet
37f4712f7e Update the named page destinations when some pdf are combined (bug 1997379)
and remove link annotations pointing on a deleted page.
2025-11-07 18:22:19 +01:00
calixteman
57334bd205
Merge pull request #20411 from calixteman/split_merge_p2
Update the page labels tree when a pdf is extracted (bug 1997379)
2025-11-07 17:21:38 +01:00
Calixte Denizet
ad97c5b816 Update the page labels tree when a pdf is extracted (bug 1997379) 2025-11-07 15:59:57 +01:00
calixteman
85ed401b82
Merge pull request #20409 from calixteman/split_merge_p1
Add the possibility to create a pdf from different ones (bug 1997379)
2025-11-07 15:05:52 +01:00
Calixte Denizet
bc87f4e8d6 Add the possibility to create a pdf from different ones (bug 1997379)
For now it's just possible to create a single pdf in selecting some pages in different pdf sources.
The merge is for now pretty basic (it's why it's still a WIP) none of these data are merged for now:
 - the struct trees
 - the page labels
 - the outlines
 - named destinations
For there are 2 new ref tests where some new pdfs are created: one with some extracted pages and an other
one (encrypted) which is just rewritten.
The ref images are generated from the original pdfs in selecting the page we want and the new images are
taken from the generated pdfs.
2025-11-07 14:57:48 +01:00
calixteman
2201777d0f
Merge pull request #20425 from calixteman/only_parese_parenttree_one_time
Create the number tree for the ParentTree only one time
2025-11-07 09:45:17 +01:00
Calixte Denizet
04db38558a Create the number tree for the ParentTree only one time 2025-11-05 17:49:55 +01:00
Tim van der Meij
0a2680bca6
Merge pull request #20414 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-11-02 13:14:45 +01:00
Tim van der Meij
1febf9e30f
Bump the stable version in pdfjs.config 2025-11-02 13:11:00 +01:00
calixteman
2cc809ade2
Merge pull request #20213 from lab-core/pointer-type
[Editor] A new CurrentPointers class to store current pointers used by the editor
2025-11-01 19:17:32 +01:00
Tim van der Meij
6e7a6eb52b
Merge pull request #20408 from calixteman/fix_mml_encoding
Don't set the MathML namespace for attributes in MathML tags (bug 1997343)
2025-11-01 14:58:15 +01:00
Tim van der Meij
c696648826
Merge pull request #20404 from mozilla/revert-20031-telemetry_signature_certificate
Revert "Add some telemetry in order to know what are the certificates used in pdfs (bug 1973573)"
2025-11-01 14:55:07 +01:00
Calixte Denizet
6db23139be Don't set the MathML namespace for attributes in MathML tags (bug 1997343)
And by default a XML file is UTF-8 encoded so correctly decode the embedded file.
2025-10-30 18:37:19 +01:00
calixteman
27bb5fb173
Merge pull request #20406 from gregtatum/text-extractor
Add text extractor as an external service
2025-10-30 17:23:18 +01:00
Greg Tatum
b7708da368 Address review feedback 2025-10-30 09:48:46 -05:00
calixteman
7fc5706e16
Merge pull request #20327 from edoardocavazza/collect-list-table-children
Collect all child nodes of lists and tables in StructTree
2025-10-29 21:09:52 +01:00
Greg Tatum
26360c3e63 Add text extractor for an external service 2025-10-29 13:15:51 -05:00
Edoardo Cavazza
a932a063ea Revert unwanted change 2025-10-29 17:34:34 +01:00
Edoardo Cavazza
17cdd9b1e7 Move tables test to specific struct tree spec file 2025-10-29 17:33:36 +01:00
Edoardo Cavazza
d04832a82f Add test case for empty cells 2025-10-29 17:31:49 +01:00
Edoardo Cavazza
4c22b99df3 Collect all child nodes of lists and tables 2025-10-29 17:30:46 +01:00
calixteman
de7179fd74
Merge pull request #20394 from CoelacanthusHex/feat/pt-astra-serif
Add the font PT Astra Serif as a possible substitution for Times New Roman
2025-10-29 16:30:34 +01:00
calixteman
aeceee1df3
Revert "Add some telemetry in order to know what are the certificates used in pdfs (bug 1973573)" 2025-10-29 15:41:34 +01:00
calixteman
4a660967bd
Merge pull request #20396 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-10-29 14:25:37 +01:00
Coelacanthus
6590063614
Add the font PT Astra Serif as a possible substitution for Times New Roman
Metric-compatible font with Times New Roman created by ParaType, based on
their serif font PT Serif, released under OFL-1.1 license.

https://www.paratype.com/fonts/pt/pt-astra-serif

Signed-off-by: Coelacanthus <uwu@coelacanthus.name>
2025-10-29 17:15:31 +08:00
Tim van der Meij
3d175f2f48
Merge pull request #20400 from mozilla/dependabot/github_actions/actions/upload-artifact-5
Bump actions/upload-artifact from 4 to 5
2025-10-28 19:57:39 +01:00
dependabot[bot]
deb74b9062
Bump actions/upload-artifact from 4 to 5
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 5.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-27 13:01:42 +00:00
Tim van der Meij
982e7ea531
Update translations to the most recent versions 2025-10-26 16:42:41 +01:00
Tim van der Meij
1f7d3974e1
Upgrade eslint-plugin-unicorn to version 62.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v62.0.0
doesn't indicate any breaking changes that should impact us.
2025-10-26 16:41:13 +01:00
Tim van der Meij
cbd2b3d426
Update dependencies to the most recent versions 2025-10-26 16:40:07 +01:00
calixteman
520363b350
Merge pull request #20384 from calixteman/bug1937438
Make MathML elements visible in the struct tree (bug 1937438)
2025-10-23 17:55:42 +02:00
Calixte Denizet
e5a62c8d06 Make MathML elements visible in the struct tree (bug 1937438)
It'll help to make math equations "visible" for screen readers.
MS Office has a specific way to add some MathML code to struc tree leaf
and this patch handles it.
2025-10-23 16:29:01 +02:00
calixteman
f6317ddbbb
Merge pull request #20389 from calixteman/bug1995579
[Editor] Make sure the left (resp. right) corner of the popup is visible when in LTR (resp. RTL) (bug 1995579)
2025-10-23 09:01:50 +02:00
calixteman
638861008f
Merge pull request #20388 from calixteman/bug1995705
[Editor] Avoid to have several Undo entries in the context menu (bug 1995705)
2025-10-23 09:01:19 +02:00
calixteman
1b5ecd36e4
Merge pull request #20387 from calixteman/bug1995721
[Editor] Fix the css of the link in the comment sidebar (bug 1995721)
2025-10-23 09:00:48 +02:00
calixteman
64f6fb9049
Merge pull request #20386 from calixteman/bug1995766
[Editor] Fix the css of the button to close the comment sidebar (bug 1995766)
2025-10-23 09:00:21 +02:00
Calixte Denizet
cb36dc28a7 [Editor] Make sure the left (resp. right) corner of the popup is visible when in LTR (resp. RTL) (bug 1995579) 2025-10-22 22:47:20 +02:00
Calixte Denizet
19cbdba434 [Editor] Avoid to have several Undo entries in the context menu (bug 1995705) 2025-10-22 19:45:52 +02:00
Calixte Denizet
ad9bcabee3 [Editor] Fix the css of the link in the comment sidebar (bug 1995721) 2025-10-22 16:18:37 +02:00
Calixte Denizet
abfa1495d5 [Editor] Fix the css of the button to close the comment sidebar (bug 1995766) 2025-10-22 16:05:26 +02:00
calixteman
1a8689b9be
Merge pull request #20340 from Aditi-1400/serialize-pattern-ab
Serialize pattern data into ArrayBuffer
2025-10-22 11:05:22 +02:00
legraina
a932804fb5
A new CurrentPointers class to store current pointers used by the editor
Move current pointer field of DrawingEditor to CurrentPointer class in tools.js: The pointer types fields have been moved to a CurrentPointer object in tools.js. This object is used by eraser.js and ink.js.
Only reset pointer type when user select a new mode: Clear the pointer type when changing mode, instead of at the end of the session. It seems more stable, as the method is not called this way when the user changes pages. Also, clear the pointer type when the mode is changed by an event (the user changes the editor type), otherwise, the same pointer type is kept (the document is changed for example)
2025-10-21 17:00:08 -04:00
Tim van der Meij
a6934b478f
Merge pull request #20381 from mozilla/dependabot/github_actions/actions/setup-node-6
Bump actions/setup-node from 5 to 6
2025-10-21 20:22:31 +02:00
dependabot[bot]
6268f930ca
Bump actions/setup-node from 5 to 6
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 5 to 6.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-20 12:57:45 +00:00
calixteman
9f397a632c
Merge pull request #20378 from timvandermeij/integration-tests-aboutstacks
Don't use the `aboutstacks.pdf` file in the integration tests
2025-10-19 20:40:10 +02:00
calixteman
a40df9a5be
Merge pull request #20380 from timvandermeij/integration-tests-tweak-viewer-scroll
Tweak the "scroll into view" viewer integration test
2025-10-19 20:37:30 +02:00
calixteman
205fe258f2
Merge pull request #20355 from calixteman/highlight_span
Add a highlightSpan function in order to simplify a bit the integration tests
2025-10-19 20:35:52 +02:00
Calixte Denizet
9205305dbb Add a highlightSpan function in order to simplify a bit the integration tests 2025-10-19 19:37:41 +02:00
Tim van der Meij
4fd3bad67f
Tweak the "scroll into view" viewer integration test
On GitHub Actions this test could fail with `Expected 1.3125 to be less
than 1` due to slight differences in the decimals of the `rect.y` value.
However, for this check we're only really interested in full pixels, so
this commit rounds the value up to the next integer to not be affected
by small decimal differences so the test passes on GitHub Actions too.
2025-10-19 17:33:11 +02:00
Tim van der Meij
9ab4de5c04
Don't use the aboutstacks.pdf file in the integration tests
For the integration tests we prefer non-linked test cases because those
PDF files are directly checked into the Git repository and thus don't
need a separate download step that linked test cases do.

However, for the freetext and ink integration tests we currently use
`aboutstacks.pdf` which is a linked test case. Fortunately we don't need
to use it because for most tests we don't actually use any properties of
it: we only create editors on top of the canvas, but for that any PDF
file works, so we can simply use the non-linked `empty.pdf` file instead.

The only exception is the "aria-owns" test that needs a line of text from
the PDF file, so we move that particular test to a dedicated `describe`
block and adapt it to use the non-linked `attachment.pdf` file that just
contains a single line of text that can be used for this purpose.

The changes combined make 12 more integration tests run out-of-the-box
after a Git clone, which also simplifies running on GitHub Actions.
2025-10-19 13:05:46 +02:00
Tim van der Meij
b87c999815
Merge pull request #20379 from calixteman/fix_after_20373
Fix stream use when getting the text (follow-up of #20373)
2025-10-19 13:04:13 +02:00
Calixte Denizet
199b3d04df Fix stream use when getting the text (follow-up of #20373) 2025-10-18 22:58:27 +02:00
calixteman
b0e8c39f31
Merge pull request #20373 from calixteman/get_original_stream
Use stream for whatever substrem in stream classes
2025-10-18 14:53:49 +02:00
Tim van der Meij
b2810513c9
Merge pull request #20377 from calixteman/fix_integration_test1
[Editor] Fix integration test after #20372
2025-10-18 13:43:25 +02:00
Calixte Denizet
05f368056d Use stream for whatever substrem in stream classes
and add a method in order to get the original stream.
When writing an existing stream it'll help to have the original one instead of the filtered one.
2025-10-17 22:26:05 +02:00
Tim van der Meij
bd0bf03a68
Merge pull request #20375 from calixteman/fix_color_copy_paste
[Editor] Make sure the color picker has the right color when pasting an editor
2025-10-17 21:05:44 +02:00
Calixte Denizet
c2535b32fe [Editor] Fix integration test after #20372 2025-10-17 20:44:02 +02:00
Tim van der Meij
bc9d34b45c
Merge pull request #20374 from calixteman/bug1995028
[Editor] FreeText annotations aren't supposed to have an attached popup so disable commenting for them (bug 1995028)
2025-10-17 20:40:53 +02:00
Calixte Denizet
97fec3ab81 [Editor] Make sure the color picker has the right color when pasting an editor 2025-10-17 19:37:05 +02:00
Calixte Denizet
18a7a82c29 [Editor] FreeText annotations aren't supposed to have an attached popup so disable commenting for them (bug 1995028) 2025-10-17 18:33:15 +02:00
calixteman
928a758811
Merge pull request #20372 from calixteman/bug1994958
[Editor] Fix the tooltip of the comment button when in the editor toolbar (bug 1994958)
2025-10-17 16:20:30 +02:00
Calixte Denizet
54ffd860ec [Editor] Fix the tooltip of the comment button when in the editor toolbar (bug 1994958) 2025-10-17 15:47:55 +02:00
Tim van der Meij
1c1becf60b
Merge pull request #20369 from calixteman/bug1994738
[Editor] Correctly focus the annotation once the comment has been removed in the annotation layer (bug 1994738)
2025-10-16 20:43:55 +02:00
Tim van der Meij
455e89a295
Merge pull request #20367 from calixteman/bin_format_font_path
Use a binary format for the glyph paths
2025-10-16 20:39:29 +02:00
Calixte Denizet
fd3f7528b6 [Editor] Correctly focus the annotation once the comment has been removed in the annotation layer (bug 1994738) 2025-10-16 16:12:36 +02:00
Calixte Denizet
bb2a1126e6 Use a binary format for the glyph paths
We used a SVG string which can be pass to the Path2D ctor but it's a bit slower than
building the path step by step.
Having numerical data instead of a string will help the font data serialization.
2025-10-16 15:52:51 +02:00
calixteman
745e42701f
Merge pull request #20361 from nicolo-ribaudo/reset-setTextMatrix
Reset `sameLineText` dependencies data on `setTextMatrix`
2025-10-16 09:00:46 +02:00
calixteman
238694891c
Merge pull request #20356 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-10-16 08:17:41 +02:00
calixteman
79a7396583
Merge pull request #20363 from timvandermeij/python-3.14
Use Python 3.14 in the GitHub workflows
2025-10-16 08:16:06 +02:00
Nicolò Ribaudo
d79651e797
Reset sameLineText dependencies data on setTextMatrix
The position of the text rendered by `showText` is affected
incrementally by the preceding `showText` operations "on the same line".
For this reason, we keep track of all of them (with their dependencies)
in `sameLineText`.

`sameLineText` can be reset whenever we explicitly position the text
somewhere else. We were previously only doing it for `moveText`, and
this patch updates the code to also do it on `setTextMatrix` (which
resets `this.current.x/y` in `CanvasGraphics` to 0).

The complexity of subsequent `sameLineText` operations dependency
tracking grows quadratically with the number of operations on the same
line, so this patch fixes the performance problem when there are whole
pages of text that only use `setTextMatrix` and not `moveText`.
2025-10-15 17:56:30 +02:00
Tim van der Meij
0528885029
Use Python 3.14 in the GitHub workflows
Python 3.14 is the current stable version, released on October 7th. The
dependencies we use also support Python 3.14 now, most importantly
`fonttools` for which the OS-specific builds have been published (see
the `cp314` wheels on https://pypi.org/project/fonttools/#files).
2025-10-14 21:48:21 +02:00
Tim van der Meij
6eef518883
Update translations to the most recent versions 2025-10-14 20:26:53 +02:00
Tim van der Meij
6bd5c7cdb3
Update dependencies to the most recent versions 2025-10-14 20:26:50 +02:00
Tim van der Meij
3eca60735b
Merge pull request #20358 from calixteman/intersector
Very slightly improve intersector performance
2025-10-14 20:25:40 +02:00
Tim van der Meij
30c04550c8
Merge pull request #20357 from mozilla/dependabot/github_actions/github/codeql-action-4
Bump github/codeql-action from 3 to 4
2025-10-14 20:21:13 +02:00
Calixte Denizet
aab521327b Very slightly improve intersector performance
It just avoid useless computations.
2025-10-13 14:55:44 +02:00
dependabot[bot]
a3b5fcfa9d
Bump github/codeql-action from 3 to 4
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3 to 4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-13 12:41:18 +00:00
Aditi
fa631806bf Serialize pattern data into ArrayBuffer
Follow up on https://github.com/mozilla/pdf.js/pull/20197,
This serializes pattern data into an ArrayBuffer which is
then transferred from the worker to the main thread.

It sets up the stage for us to eventually switch to a
SharedArrayBuffer in the future.
2025-10-11 01:58:07 +05:30
calixteman
30fdf16071
Merge pull request #20354 from Aditi-1400/use-enum
Use enums instead of string for mesh shading figure type
2025-10-10 18:49:50 +02:00
calixteman
0d8a300777
Merge pull request #20353 from calixteman/improve_intersector
[Annotation] Improve the performance of the code for getting glyphs which belongs to annotations bounding boxes (bug 1987914)
2025-10-10 13:31:03 +02:00
Calixte Denizet
c4d436764c [Annotation] Improve the performance of the code for getting glyphs which belongs to annotations bounding boxes (bug 1987914)
Instead of looking at every bbox, we use a grid (64x64) where each cell of the grid is associated with the bboxes
touching it.
In order to get the potential bboxes containing a point, we just have to compute the number of the cell containing
it and in using the associated described above, we can quickly know if the point is contained.
With the pdf in the mentioned bug, it's ~20 times faster.
2025-10-10 13:28:18 +02:00
calixteman
c8d8f9fbb4
Merge pull request #20352 from calixteman/improve_struct_tree_parser
Improve performance of the struct tree build (bug 1987914)
2025-10-10 13:27:11 +02:00
Aditi
e8d08c941c Use enums instead of string for mesh shading figure type 2025-10-10 04:21:03 +05:30
Tim van der Meij
0fedfc9ceb
Merge pull request #20351 from calixteman/avoid_null
[Editor] Avoid to have a null button in the DOM when there's no comment manager
2025-10-09 20:57:20 +02:00
calixteman
16630b61bd
Merge pull request #20350 from calixteman/refactor_annotation_layer_a11y
[Annotation] Use the annotations rect in order to fix the order in the DOM (bug 1987914)
2025-10-09 20:53:08 +02:00
Calixte Denizet
f5a6dd4164 [Annotation] Use the annotations rect in order to fix the order in the DOM (bug 1987914)
It's just a partial fix for bug 1987914 but the time spent to add the annotations in the DOM
is divided by 5.
2025-10-09 17:43:49 +02:00
Calixte Denizet
9797dc0eb4 Improve performance of the struct tree build (bug 1987914)
For the pdf in bug 1987914, the overall time spent in `addTopLevelNode` is dropping from ~6s to ~70ms.
2025-10-09 16:08:56 +02:00
Calixte Denizet
16d0077387 [Editor] Avoid to have a null button in the DOM when there's no comment manager 2025-10-09 09:25:43 +02:00
calixteman
8ba18075f2
Merge pull request #20344 from calixteman/bug1992770
[Editor] Make sure that annotation positions in the DOM respect the visual order (bug 1992770)
2025-10-08 16:55:01 +02:00
calixteman
152324fdbd
Merge pull request #20347 from calixteman/bug1990826
[Editor] Remove the role radio for the editing buttons (bug 1990826)
2025-10-08 15:15:51 +02:00
Calixte Denizet
41dea1e38b [Editor] Make sure that annotation positions in the DOM respect the visual order (bug 1992770) 2025-10-08 15:11:09 +02:00
Calixte Denizet
2d759a5f4b [Editor] Remove the role radio for the editing buttons (bug 1990826) 2025-10-08 14:45:28 +02:00
calixteman
d83cbb28a9
Merge pull request #20341 from calixteman/bug1992868
[Editor] Make sure all editors are focusable with the keyboard (bug 1992868)
2025-10-07 22:34:10 +02:00
calixteman
262741634f
Merge pull request #20343 from calixteman/bug1992832
[Editor] Make sure the editor is focused after the comment has been deleted (bug 1992832)
2025-10-07 22:33:04 +02:00
Calixte Denizet
76e0de6c08 [Editor] Make sure the editor is focused after the comment has been deleted (bug 1992832) 2025-10-07 21:31:09 +02:00
Calixte Denizet
5c28346abc [Editor] Make sure all editors are focusable with the keyboard (bug 1992868) 2025-10-07 21:15:26 +02:00
Tim van der Meij
1df2ee68b7
Merge pull request #20342 from calixteman/bug1992987
[Editor] Make sure that comment stuff is removed when an editor is deleted (bug 1992987)
2025-10-07 20:55:53 +02:00
Calixte Denizet
be987f2fbf [Editor] Make sure that comment stuff is removed when an editor is deleted (bug 1992987) 2025-10-07 19:09:48 +02:00
Tim van der Meij
f4104326f3
Merge pull request #20338 from calixteman/test_date_tz
Add a test for PR #20320
2025-10-05 20:24:02 +02:00
calixteman
7f92a6e2be
Merge pull request #20335 from timvandermeij/setDims
[Editor] Remove obsolete arguments for `setDims` calls in the highlight code
2025-10-05 19:43:07 +02:00
calixteman
66763b33a4
Merge pull request #20337 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-10-05 19:41:43 +02:00
Calixte Denizet
25ce14042f Add a test for PR #20320 2025-10-05 19:38:37 +02:00
Tim van der Meij
44c498549c
Merge pull request #20339 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-10-05 19:07:21 +02:00
Tim van der Meij
66bf335a6c
Bump the stable version in pdfjs.config 2025-10-05 19:04:33 +02:00
Tim van der Meij
b9d9523871
Update translations to the most recent versions 2025-10-05 14:41:45 +02:00
Tim van der Meij
4f50eacdfc
Update dependencies to the most recent versions 2025-10-05 14:41:05 +02:00
Tim van der Meij
68ed5be9ac
[Editor] Remove obsolete arguments for setDims calls in the highlight code
The `width` and `height` arguments for `setDims` have been removed in
PR #20285, but for two calls in the highlight code they remained. This
commit removes them as they are no longer used in the method itself.

Fixes 0722faa9.
2025-10-05 13:52:09 +02:00
calixteman
f56dc86014
Merge pull request #20333 from calixteman/issue20302
Fix incremental saving with hybrid references
2025-10-04 20:31:09 +02:00
Calixte Denizet
19ff148163 Fix incremental saving with hybrid references
This patch removes some previous fixes which are now likely fixed by #17636.

Fixes #20302.
2025-10-04 18:31:55 +02:00
Tim van der Meij
6c3036836f
Merge pull request #20301 from mozilla/dependabot/npm_and_yarn/tar-fs-3.1.1
Bump tar-fs from 3.1.0 to 3.1.1
2025-10-04 14:59:34 +02:00
Tim van der Meij
d27cd6a4a1
Merge pull request #20334 from calixteman/issue20319
Only apply word spacing when there is a 0x20 in the text chunk
2025-10-04 14:47:30 +02:00
Calixte Denizet
4d15bfec0d Only apply word spacing when there is a 0x20 in the text chunk
Fixes #20319.
2025-10-03 22:18:02 +02:00
calixteman
4e7db4f59c
Merge pull request #20332 from calixteman/bug1992385
[Editor] Slightly move the resizer in the sidebar comment in order to make it easier to use (bug 1992385)
2025-10-03 18:36:52 +02:00
Calixte Denizet
3ecefa5e0c [Editor] Slightly move the resizer in the sidebar comment in order to make it easier to use (bug 1992385)
And highlight the resizer when hovering it.
2025-10-03 17:07:42 +02:00
calixteman
e1de28c866
Merge pull request #20328 from calixteman/fix_dialog_position
[Editor] Make sure the comment dialog always have relative coordinates between 0% and 100%
2025-10-03 09:17:09 +02:00
calixteman
af542a84cc
Merge pull request #20329 from calixteman/fix_annotation_layer_driver
Fix the creation of the annotation layer in the ref tests
2025-10-02 22:04:10 +02:00
Calixte Denizet
17993a0c5d Fix the creation of the annotation layer in the ref tests 2025-10-02 20:27:29 +02:00
Calixte Denizet
2aef871d5d [Editor] Make sure the comment dialog always have relative coordinates between 0% and 100%
This way, when the window is resized, the dialog stay visible.
2025-10-02 18:55:55 +02:00
calixteman
3234912c86
Merge pull request #20224 from james-atticus/improve-serif-fallback-font-name-matching
Improve serif fallback font name matching
2025-10-01 19:58:13 +02:00
calixteman
9d917b2896
Merge pull request #20323 from calixteman/bug1991482
Increase the rendering quality of the detail view (bug 1991482)
2025-10-01 19:29:17 +02:00
Calixte Denizet
91e2f6c400 Increase the rendering quality of the detail view (bug 1991482)
But keep a lower quality when enableOptimizedPartialRendering is true because we need to compensate the time
used to compute the bboxes and since subsequent rendering are faster it's more acceptable to see
a lower quality image for few tenths of seconds.
2025-10-01 16:40:41 +02:00
calixteman
7fa50712c9
Merge pull request #20322 from calixteman/bug1990491
[Editor] Add the possibility to unselect a comment from the sidebar
2025-10-01 15:24:03 +02:00
Calixte Denizet
bb556dcb5c [Editor] Add the possibility to unselect a comment from the sidebar 2025-10-01 14:36:12 +02:00
calixteman
042e821bec
Merge pull request #20320 from calixteman/bug1991584
[Annotation] Fix some timezone issues when getting a date from the date picker (bug 1991584)
2025-10-01 00:41:17 -11:00
calixteman
cd66ecf3d2
Merge pull request #20318 from calixteman/fix_editorStats
[Editor] Avoid an error when getting the editors telemetry data
2025-10-01 00:40:35 -11:00
calixteman
d18289bccb
Merge pull request #20321 from calixteman/bug1989420
[Editor] Add a fake annotation (in the annotation layer) associated with an editor in order to be able to show the comment button (bug 1989420)
2025-10-01 00:40:13 -11:00
Calixte Denizet
12066af578 [Editor] Add a fake annotation (in the annotation layer) associated with an editor in order to be able to show the comment button (bug 1989420) 2025-10-01 09:08:57 +02:00
Calixte Denizet
7b9cde1daf [Annotation] Fix some timezone issues when getting a date from the date picker (bug 1991584) 2025-09-30 11:07:31 +02:00
Calixte Denizet
678aec9890 [Editor] Avoid an error when getting the editors telemetry data 2025-09-29 16:41:15 +02:00
calixteman
ec4f616d21
Merge pull request #20314 from calixteman/rm_useless_sidebar_css
[Editor] Remove useless sidebar css
2025-09-27 14:10:57 +02:00
Calixte Denizet
7041459fc0 [Editor] Remove useless sidebar css 2025-09-26 22:32:54 +02:00
calixteman
e3a5f61234
Merge pull request #20313 from calixteman/bug1991172
[Editor] Add some telemetry for the commenting feature (bug 1991172)
2025-09-26 21:07:01 +02:00
Calixte Denizet
02ddf277ab [Editor] Add some telemetry for the commenting feature (bug 1991172) 2025-09-26 21:04:09 +02:00
calixteman
f64ece2a97
Merge pull request #20312 from calixteman/bug1991029
[Annotation] In reading mode with new commment stuff enabled, use the comment popup for annotations without a popup but with some contents (bug 1991029)
2025-09-26 20:26:40 +02:00
Calixte Denizet
7fc7b79cd0 [Annotation] In reading mode with new commment stuff enabled, use the comment popup for annotations without a popup but with some contents (bug 1991029) 2025-09-26 18:24:55 +02:00
calixteman
91384738f8
Merge pull request #20311 from calixteman/fix_focus_comment_button
[Editor] Give the focus to the comment button after editing in reading mode
2025-09-26 18:24:32 +02:00
Calixte Denizet
f547e834e1 [Editor] Give the focus to the comment button after editing in reading mode 2025-09-26 17:18:37 +02:00
calixteman
d5fb95cda1
Merge pull request #20309 from calixteman/update_deps
Update dependencies
2025-09-26 14:02:50 +02:00
calixteman
28fb4f0f47
Merge pull request #20310 from calixteman/bug1990762
[Editor] Show the comments in the sidebar in the chronological order,newest to oldest (bug 1990762)
2025-09-26 11:09:27 +02:00
Calixte Denizet
f854770806 [Editor] Show the comments in the sidebar in the chronological order, newest to oldest (bug 1990762) 2025-09-26 10:10:43 +02:00
calixteman
101fa6201c
Merge pull request #20308 from calixteman/bug1990454
[Editor] Fix the URL for the 'Learn more' link in the comment sidebar (bug 1990454)
2025-09-26 09:25:00 +02:00
Calixte Denizet
893de3e754 Update dependencies 2025-09-26 09:23:17 +02:00
calixteman
7051fd0215
Merge pull request #20307 from calixteman/bug1990872
[Editor] Make sure the selected editor is correctly focused after switching editing mode (bug 1990872)
2025-09-26 09:17:48 +02:00
Calixte Denizet
5f832757bd [Editor] Fix the URL for the 'Learn more' link in the comment sidebar (bug 1990454) 2025-09-26 09:16:36 +02:00
Calixte Denizet
888df7c319 [Editor] Make sure the selected editor is correctly focused after switching editing mode (bug 1990872) 2025-09-25 22:42:32 +02:00
calixteman
a4f072f3df
Merge pull request #20304 from calixteman/bug1990820
[Editor] Move the focus to the comment button once editing is done (bug 1990820)
2025-09-25 21:07:30 +02:00
Calixte Denizet
442932f0b3 [Editor] Move the focus to the comment button once editing is done (bug 1990820) 2025-09-25 20:17:52 +02:00
calixteman
37c79c3837
Merge pull request #20305 from calixteman/bug1990813
[Editor] Add a title to the comment buttons (bug 1990813)
2025-09-25 20:16:57 +02:00
Calixte Denizet
90e56b706e [Editor] Add a title to the comment buttons (bug 1990813) 2025-09-25 18:47:49 +02:00
calixteman
007148e2c5
Merge pull request #20303 from calixteman/bug1990544
[Editor] Make the comment sidebar resizable (bug 1990544)
2025-09-25 16:27:24 +02:00
Calixte Denizet
a372294ea3 [Editor] Make the comment sidebar resizable (bug 1990544) 2025-09-25 15:29:41 +02:00
calixteman
8448d08345
Merge pull request #20300 from calixteman/bug1990499
[Editor] Fix the button labels in the comment dialog (bug 1990499)
2025-09-25 15:29:20 +02:00
dependabot[bot]
96ee833bf4
Bump tar-fs from 3.1.0 to 3.1.1
Bumps [tar-fs](https://github.com/mafintosh/tar-fs) from 3.1.0 to 3.1.1.
- [Commits](https://github.com/mafintosh/tar-fs/compare/v3.1.0...v3.1.1)

---
updated-dependencies:
- dependency-name: tar-fs
  dependency-version: 3.1.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-24 20:01:25 +00:00
calixteman
a8cf9a41d1
Merge pull request #20299 from calixteman/bug1990104
[Editor] Use some percent coordinates for the comment dialog (bug 1990104)
2025-09-24 18:45:16 +02:00
Calixte Denizet
7b67ed3454 [Editor] Fix the button labels in the comment dialog (bug 1990499) 2025-09-24 18:18:43 +02:00
Calixte Denizet
0427c1d93c [Editor] Use some percent coordinates for the comment dialog (bug 1990104) 2025-09-24 17:59:30 +02:00
calixteman
83b5e9efb0
Merge pull request #20298 from calixteman/bug1990082
[Editor] Avoid to use similar colors for background and foreground colors in HCM (bug 1990082)
2025-09-24 17:54:37 +02:00
Calixte Denizet
80c7aee347 [Editor] Avoid to use similar colors for background and foreground colors in HCM (bug 1990082) 2025-09-24 17:04:27 +02:00
calixteman
1ed99237a8
Merge pull request #20297 from calixteman/bug1990099
[Editor] Don't add scrollbars when it's useless in the comment sidebar (bug 1990099)
2025-09-24 17:02:32 +02:00
Calixte Denizet
3f1dbbcb77 [Editor] Don't add scrollbars when it's useless in the comment sidebar (bug 1990099) 2025-09-24 15:38:13 +02:00
calixteman
f5b5b6868a
Merge pull request #20295 from calixteman/comment_update_position
[Editor] Update the color and the position of the comment button in reading mode they've been modified
2025-09-24 14:28:48 +02:00
Calixte Denizet
0b40bf1743 [Editor] Update the color and the position of the comment button in reading mode they've been modified 2025-09-24 09:45:37 +02:00
calixteman
ae3c23e28a
Merge pull request #20291 from calixteman/bug1977269
[Editor] When in HCM, don't apply light/dark color in the comment buttons (bug 1977269)
2025-09-23 20:27:01 +02:00
calixteman
48c10d8938
Merge pull request #20285 from calixteman/editor_remove_useless_dim_stuff
[Editor] Remove useless computations when setting the dimensions of an editor
2025-09-23 20:26:12 +02:00
calixteman
225b07aa29
Merge pull request #20283 from calixteman/bug1989304
[Editor] Make sure the comment dialog is visible on the screen (bug 1989304)
2025-09-23 19:30:28 +02:00
Calixte Denizet
5d079c10b6 [Editor] When in HCM, don't apply light/dark color in the comment buttons (bug 1977269)
Add fix the color name to use in HCM.
2025-09-22 17:31:11 +02:00
calixteman
44affa76b9
Merge pull request #20197 from ryzokuken/sab-font-data
Serialize font data into an ArrayBuffer
2025-09-22 09:40:14 +02:00
calixteman
594fda13de
Merge pull request #20286 from calixteman/openjpeg_2.5.4
Update OpenJPEG to 2.5.4
2025-09-21 18:53:00 +02:00
Calixte Denizet
e9394d0f63 Update OpenJPEG to 2.5.4 2025-09-21 12:11:40 +02:00
Calixte Denizet
0722faa9ce [Editor] Remove useless computations when setting the dimensions of an editor
And remove an unused functions AnnotationEditor::setAspectRatio/fixDims.
2025-09-19 18:08:56 +02:00
Ujjwal Sharma
4bed7370f4 [WIP] Serialize font data into an ArrayBuffer
This PR serializes font data into an ArrayBuffer
that is then transfered from the worker to the
main thread. It's more efficient than the current
solution which clones the "export data" object
which includes the font data as a Uint8Array.

It prepares us to switch to a SharedArrayBuffer
in the future, which would allow us to share
the font data with multiple agents, which would be
crucial for the upcoming "renderer" worker.
2025-09-19 12:02:40 +05:30
Calixte Denizet
623d422ddb [Editor] Make sure the comment dialog is visible on the screen (bug 1989304) 2025-09-18 21:23:42 +02:00
Tim van der Meij
33e638c66f
Merge pull request #20282 from calixteman/fix_showing_invisible_editor
[Editor] Make sure to not add extra editors when showing again a destroyed page
2025-09-18 20:54:15 +02:00
Tim van der Meij
20f31d782b
Merge pull request #20281 from calixteman/comment_dialog_focus
[Editor] Fix the focus outline for the comment dialog buttons
2025-09-18 20:50:50 +02:00
Calixte Denizet
cbc5241b53 [Editor] Make sure to not add extra editors when showing again a destroyed page 2025-09-18 15:18:50 +02:00
Calixte Denizet
a1906f02d9 [Editor] Fix the focus outline for the comment dialog buttons
And add an aria label to the dialog.
2025-09-18 14:01:07 +02:00
James Fitzsimmons
ae8f8e4d34 Improve serif fallback font name matching 2025-09-18 14:15:41 +10:00
Tim van der Meij
05af4ff783
Merge pull request #20252 from sigmaSd/patch-1
Use `console.warn`/`console.info` where appropriate
2025-09-16 19:41:54 +02:00
calixteman
4eeabcb70b
Merge pull request #20279 from calixteman/unused_css
Avoid unused css variables
2025-09-16 13:45:04 +02:00
Calixte Denizet
d1f06fe70e Avoid unused css variables 2025-09-16 13:40:09 +02:00
Bedis Nbiba
b6165c02b9 use console.warn/info where appropriate
Change info to use console.info and warn function
to use console.warn, this not only makes sense semantically
but also in practice server side runtimes like deno
write console.log to stdout, and console.warn
to stderr (info goes to stdout, unfortunately?)
this is important because logging to stdout
can break some cli apps.
2025-09-15 22:37:08 +00:00
Tim van der Meij
d85fd12437
Merge pull request #20274 from calixteman/save_comment_reading_mode
[Annotation] Save the comment changes made in reading mode (bug 1987427)
2025-09-15 23:32:51 +02:00
Tim van der Meij
a68630eee4
Merge pull request #20278 from calixteman/fix_comment_popup_position
[Editor] Fix the position of the comment popup and its dialog
2025-09-15 23:23:10 +02:00
Calixte Denizet
764c2e639c [Editor] Fix the position of the comment popup and its dialog
Only fix the popup position if the user didn't change it.
And don't adjust the dialog position since it should have the same as the popup.
2025-09-15 21:26:36 +02:00
Calixte Denizet
5feb4674d6 [Annotation] Save the comment changes made in reading mode (bug 1987427) 2025-09-15 19:49:49 +02:00
calixteman
394fa2c184
Merge pull request #20250 from calixteman/new_popup_reading_mode
[Annotation] Use the new popup in reading mode (bug 1987426)
2025-09-15 18:00:14 +02:00
Calixte Denizet
38b86cb97a [Annotation] Use the new popup in reading mode (bug 1987426) 2025-09-15 16:58:22 +02:00
calixteman
3432c1933e
Merge pull request #20249 from calixteman/new_comment_popup_2
[Editor] Add a new popup for comments (bug 1987425)
2025-09-15 08:27:17 +02:00
calixteman
0982ff2911
Merge pull request #20272 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-09-15 08:25:35 +02:00
Calixte Denizet
b660b721f9 [Editor] Add a new popup for comments (bug 1987425)
And:
 - improve the editing dialog in removing menu;
 - position correctly the popup on the left/right depending on the direction value.
2025-09-15 08:24:26 +02:00
calixteman
adf9233f46
Merge pull request #20270 from calixteman/issue20232
Consider a ttf font with both Symbolic and Nonsymbolic flags set with a Differences array in the encoding dict as non-symbolic
2025-09-14 21:37:58 +02:00
Tim van der Meij
2f53e50074
Update translations to the most recent versions 2025-09-14 19:23:35 +02:00
Tim van der Meij
637599dc23
Upgrade eslint-plugin-unicorn to version 61.0.2
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v61.0.0
doesn't indicate any breaking changes that should impact us.
2025-09-14 19:23:34 +02:00
Tim van der Meij
a730cba414
Update dependencies to the most recent versions 2025-09-14 19:23:34 +02:00
Tim van der Meij
10bc635fc8
Merge pull request #20271 from timvandermeij/integration-tests-pending
Replace manual returns with `pending` in the integration tests
2025-09-14 19:17:41 +02:00
Calixte Denizet
b6d772d71d Consider a ttf font with both Symbolic and Nonsymbolic flags set with a Differences array in the encoding dict as non-symbolic
It fixes #20232.
2025-09-14 18:52:16 +02:00
Tim van der Meij
ffeaa9111a
Replace manual returns with pending in the integration tests
This allows Jasmine to track skipped tests and makes it easier to
discover them using e.g. `grep`.
2025-09-14 18:30:17 +02:00
Tim van der Meij
1cae8e2933
Merge pull request #20269 from calixteman/dichotomic_find_color
Use a dichotomy to find a color with a good contrast ratio
2025-09-14 18:15:52 +02:00
Tim van der Meij
e78c7d0cc2
Merge pull request #20256 from nicolo-ribaudo/bboxes-when-needed
Only record bboxes when needed
2025-09-14 16:22:46 +02:00
Calixte Denizet
634bef5fb4 Use a dichotomy to find a color with a good contrast ratio
It helps to reduce the number of iterations so it makes the algorithm
slightly faster in general.
2025-09-13 15:45:00 +02:00
calixteman
2138ec17cc
Merge pull request #20267 from nicolo-ribaudo/fix-jsdoc
Fix JSDoc description in src/display/api.js
2025-09-13 15:40:47 +02:00
Nicolò Ribaudo
5de14aa429
Only record bboxes when needed
Before this patch, when `enableOptimizedPartialRendering`
is enabled we would record the bounding boxes of the
various operations on the first render.

This patches change it to happen on the first render that we
know will also need a detail view, so that the performance
cost is not paid for the case when the detail view is not used.
2025-09-12 15:02:24 +02:00
Nicolò Ribaudo
42b4d97115
Fix JSDoc description in src/display/api.js 2025-09-12 15:01:41 +02:00
calixteman
beb5f5ca85
Merge pull request #20208 from nicolo-ribaudo/bboxes-typedarray
Store ops bboxes in a linear Uint8Array
2025-09-12 14:52:42 +02:00
calixteman
d77f89026f
Merge pull request #20240 from calixteman/fix_contrast
Make sure that a good constrast ratio is respected when darkening/lightening a color
2025-09-12 09:24:40 +02:00
calixteman
0e28b5c3c4
Merge pull request #20258 from calixteman/cleanup_before_editing_mode
[Editor] Cleanup the pages not being fully rendered before switching to editing mode
2025-09-11 23:03:08 +02:00
Tim van der Meij
e8cc25c0ae
Merge pull request #20259 from calixteman/no_throw_when_switching_editing_mode
[Editor] Don't throw when switching to editing mode before an annotation editor layer is rendered
2025-09-11 22:04:47 +02:00
Calixte Denizet
7f85c00ee6 Make sure that a good constrast ratio is respected when darkening/lightening a color 2025-09-11 21:29:28 +02:00
Tim van der Meij
557eb2c7e1
Merge pull request #20253 from calixteman/scroll_and_center
Add an option in scrollIntoView and goToXY in order to be able to center vertically or horizontally the point XY in the viewer container
2025-09-11 21:20:55 +02:00
Tim van der Meij
f049360689
Merge pull request #20255 from nicolo-ribaudo/low-res
Reduce background canvas resolution
2025-09-11 21:04:27 +02:00
Nicolò Ribaudo
4c7bbd0fef
Reduce background canvas resolution
The size of the canvas has significant impact on the rendering
performance. If we are going to render a high-res detail
view on top of the full-page canvas, we can further
reduce the full-page canvas resolution to improve
rendering time without affecting the resolution seen by
the user.

Users will se the lower resolution when quickly scrolling around the
page, but it will then be replaced with the high-res
detail view.
2025-09-10 16:52:57 +02:00
Calixte Denizet
593ceadc93 [Editor] Don't throw when switching to editing mode before an annotation editor layer is rendered
It can happen with a pdf having a large text layer.
Instead of waiting for the first rendered page to enable the buttons we wait for
a rendered annotation editor layer.
2025-09-10 11:04:47 +02:00
Calixte Denizet
0fc8986dc6 [Editor] Cleanup the pages not being fully rendered before switching to editing mode
In order to see the issue this patch is fixing:
 - open a pdf with some highlights and a comment on page 1, at page 7
 - open the comment sidebar
 - click on the comment on page 1

Opening at page 7 lets a not fully rendered page which means that when jumping to it
with the sidebar, we re-use what we've instead of redrawing it.
2025-09-10 10:23:29 +02:00
Calixte Denizet
e1bdc34b4a Add an option in scrollIntoView and goToXY in order to be able to center vertically or horizontally the point XY in the viewer container 2025-09-09 13:10:49 +02:00
Nicolò Ribaudo
e4ea2e0c79
Store ops bboxes in a linear Uint8Array
This PR changes the way we store bounding boxes so that they use less
memory and can be more easily shared across threads in the future.

Instead of storing the bounding box and list of dependencies for each
operation that renders _something_, we now only store the bounding box
of _every_ operation and no dependencies list. The bounding box of
each operation covers the bounding box of all the operations affected
by it that render something. For example, the bounding box of a
`setFont` operation will be the bounding box of all the `showText`
operations that use that font.

This affects the debugging experience in pdfBug, since now the bounding
box of an operation may be larger than what it renders itself. To help
with this, now when hovering on an operation we also highlight (in red)
all its dependents. We highlight with white stripes operations that do
not affect any part of the page (i.e. with an empty bbox).

To save memory, we now save bounding box x/y coordinates as uint8
rather than float64. This effectively gives us a 256x256 uniform grid
that covers the page, which is high enough resolution for the usecase.
2025-09-09 10:24:48 +02:00
calixteman
5b7f9ca8b9
Merge pull request #20247 from calixteman/wait_for_rendered_editors
[Editor] When clicking on a comment in the sidebar, wait for the annotation editor layer to be rendered
2025-09-09 09:26:45 +02:00
calixteman
d009c434f5
Merge pull request #20248 from calixteman/toolbar_button_position
[Editor] Make sure the comment button is at the right place when adding it in the toolbar
2025-09-08 23:06:02 +02:00
calixteman
b5113d9a74
Merge pull request #20239 from timvandermeij/integration-test-unskip-timezone
Unskip the `must check that date entered by the user is consistent` scripting integration test for Firefox
2025-09-08 22:35:18 +02:00
calixteman
17a27806c6
Merge pull request #20245 from calixteman/comment_richtext
[Editor] Add the dates and rich text if any to the editors in order to use them when displaying the popup
2025-09-08 22:23:03 +02:00
Tim van der Meij
3f0d39b024
Merge pull request #20244 from calixteman/fix_deleting_popup
[Editor] Fix saving a deleted popup
2025-09-08 21:23:47 +02:00
Tim van der Meij
512c30b1f6
Unskip the must check that date entered by the user is consistent scripting integration test for Firefox
Bug 1978027 has been fixed upstream 10 days ago, so this integration
test can be enabled for Firefox too now that it passed with recent
Nightly versions.
2025-09-08 20:48:24 +02:00
Tim van der Meij
8bd13f7f25
Merge pull request #20172 from timvandermeij/misc-test-improvements
Improve the integration test code
2025-09-08 20:44:29 +02:00
Tim van der Meij
5382c54803
Merge pull request #20243 from mozilla/dependabot/github_actions/actions/setup-node-5
Bump actions/setup-node from 4 to 5
2025-09-08 20:43:01 +02:00
Tim van der Meij
7e3417f862
Merge pull request #20242 from mozilla/dependabot/github_actions/actions/setup-python-6
Bump actions/setup-python from 5 to 6
2025-09-08 20:42:35 +02:00
Calixte Denizet
f5c913bc9e [Editor] Make sure the comment button is at the right place when adding it in the toolbar 2025-09-08 17:59:28 +02:00
Calixte Denizet
94d72e903f [Editor] Add the dates and rich text if any to the editors in order to use them when displaying the popup 2025-09-08 17:40:47 +02:00
Calixte Denizet
54351ee437 [Editor] When clicking on a comment in the sidebar, wait for the annotation editor layer to be rendered
and add a getter for the layer bounding rect.
2025-09-08 17:13:37 +02:00
Calixte Denizet
2d5794f79d [Editor] Fix saving a deleted popup 2025-09-08 15:36:41 +02:00
dependabot[bot]
f9be06a8c1
Bump actions/setup-node from 4 to 5
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 4 to 5.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-08 12:31:52 +00:00
dependabot[bot]
a5ef8ca828
Bump actions/setup-python from 5 to 6
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5 to 6.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-08 12:26:36 +00:00
calixteman
d946de904c
Merge pull request #20238 from timvandermeij/fix-freetext-permafail
Fix the rendering of XFA rich text in popup annotations
2025-09-07 20:59:36 +02:00
Tim van der Meij
f1f8ee47ff
Fix the rendering of XFA rich text in popup annotations
Before the introduction of the `renderRichText` helper function we
exclusively used `this.#html` for XFA rich text and exclusively used
`this.#contentsObj` for plain text. However, after the refactoring we
tried to access `this.#contentsObj.dir` in both cases, which fails for
XFA rich text because `this.#contentsObj` is `null` in that case.

This commit fixes the issue by using optional chaining to make sure we
don't try to access non-existent `this.#contentsObj` properties, which
makes the `must update an existing annotation and show the right popup`
freetext integration pass again.

Fixes #20237.
Fixes 35c90984.
2025-09-07 18:35:17 +02:00
Tim van der Meij
7f74fbf8fd
Fix block spacing inconsistencies in the integration test code
Most places have a newline before/after `before{Each,All}`,
`after{Each,All}` and `it` to visually separate the blocks for clarity,
but in a handful of places this wasn't done. This commit removes the
inconsistencies so that the test code is formatted consistently.
2025-09-07 14:39:52 +02:00
Tim van der Meij
cf5bffef2e
Use the getAnnotationSelector helper function more in the integration test code
The helper function was used in a number of places, but also a lot of
places contained the annotation selector string inline. This commit
makes sure that all places use `getAnnotationSelector` consistently to
make sure the annotation selector string is only defined in a single
place and to improve readability of the test code.
2025-09-07 14:39:52 +02:00
Tim van der Meij
c09ad5a2ce
Use the closePages helper function more in the integration test code
This test called `closeSinglePage` manually at the end of the test,
which is inconsistent with all other tests that call `closePages` in an
`afterEach` block. This commit fixes the difference for consistency.
2025-09-07 14:39:48 +02:00
calixteman
2a93ade197
Merge pull request #20231 from calixteman/xfa_render_richtext
Add a new function renderRichText to be used in the annotation layer
2025-09-05 08:36:28 +02:00
Calixte Denizet
35c909843b Add a new function renderRichText to be used in the annotation layer
and which will be used in order to make the contents of the new popup used for comments.
2025-09-04 22:27:31 +02:00
calixteman
7b87c220a5
Merge pull request #20233 from calixteman/dont_add_image_stamp_update
[Editor] Don't save the image when updating a stamp annotation
2025-09-04 22:19:36 +02:00
Tim van der Meij
84e32964ed
Merge pull request #20221 from calixteman/button_color_comment
[Editor] Use the color of the annotation for the background of the comment button
2025-09-04 21:27:07 +02:00
Calixte Denizet
2354ae4233 [Editor] Don't save the image when updating a stamp annotation
It adds some useless bytes in the file.
2025-09-04 18:54:13 +02:00
maettuu
2d8dfb0b62 Add regression test for Unicode mapping
Verifies that ToUnicodeMap correctly maps Extension B characters to their full Unicode code points using codePointAt

See PR https://github.com/mozilla/pdf.js/pull/19184
2025-09-04 17:17:34 +02:00
Calixte Denizet
ca280399c2 [Editor] Use the color of the annotation for the background of the comment button 2025-09-02 21:17:08 +02:00
Tim van der Meij
c386d9b87d
Merge pull request #20222 from calixteman/sidebar_scroll
[Editor] Make scrollable the area containing the comments in the sidebar
2025-09-01 20:28:35 +02:00
Calixte Denizet
dd4b475109 [Editor] Make scrollable the area containing the comments in the sidebar 2025-08-31 23:21:19 +02:00
calixteman
c8d49db624
Merge pull request #20217 from calixteman/comment_editor_sidebar
[Editor] Add editors with a comment in the sidebar
2025-08-31 21:48:52 +02:00
Calixte Denizet
2a459857ce [Editor] Add editors with a comment in the sidebar
and add a button close to the editor.
Clicking on the button will display a popup with the comment but it's for a next patch.
2025-08-31 19:59:16 +02:00
Tim van der Meij
9855d85fb5
Merge pull request #20220 from timvandermeij/editor-hint-bugfix
[Editor] Hide the comment sidebar on document change
2025-08-31 18:56:27 +02:00
Tim van der Meij
5a7c872618
[Editor] Hide the comment sidebar on document change
If the document changes the comment state from the old document should
be replaced with that of the new document. To do this the comment
manager is destroyed, but the corresponding comment sidebar wasn't
destroyed yet, which resulted in the comment state from the old document
still being visible for the new document.

This commit fixes the issue by hiding the comment sidebar if the comment
manager is destroyed. Note that hiding the comment sidebar effectively
destroys all its state, and we already set the annotation mode to "none"
on document change so we don't want to keep showing the comment sidebar
anyway.
2025-08-31 16:26:03 +02:00
calixteman
c96fa68c9d
Merge pull request #20204 from calixteman/add_changelightness
Add a function changeLightness in order to change the lightness of a RGB color
2025-08-30 21:40:31 +02:00
Calixte Denizet
0ec503e5ef Add a function changeLightness in order to change the lightness of a RGB color 2025-08-30 21:18:12 +02:00
Tim van der Meij
c2699a941e
Merge pull request #20216 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-08-30 20:01:51 +02:00
Tim van der Meij
cac052c0be
Update translations to the most recent versions 2025-08-30 18:39:19 +02:00
Tim van der Meij
4dcfc96703
Update dependencies to the most recent versions 2025-08-30 18:38:25 +02:00
Tim van der Meij
f110e57512
Merge pull request #20215 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-08-30 17:52:18 +02:00
Tim van der Meij
a5456033ce
Bump the stable version in pdfjs.config 2025-08-30 17:49:19 +02:00
calixteman
9e2e9e2096
Merge pull request #20210 from calixteman/comment_sidebar
[Editor] Add a sidebar allowing the user to navigate between the comments in a pdf (bug 1985567)
2025-08-30 14:19:04 +02:00
Tim van der Meij
a2d4b259c5
Merge pull request #20212 from calixteman/reset_mode
Reset editing mode when changing the pdf document
2025-08-29 20:45:21 +02:00
Calixte Denizet
25990e4287 [Editor] Add a sidebar allowing the user to navigate between the comments in a pdf (bug 1985567)
This implements what has been specified but it's still not done: we have to handle editing a comment
or an annotation containing one.
2025-08-29 16:00:06 +02:00
Calixte Denizet
3e01ee9bb7 Reset editing mode when changing the pdf document 2025-08-28 22:38:05 +02:00
Tim van der Meij
13ba311e5a
Merge pull request #20211 from calixteman/fix_css_unit
[Editor] Fix unit (for consistency) and remove few useless px
2025-08-28 20:37:18 +02:00
Tim van der Meij
53c37547f0
Merge pull request #20209 from calixteman/fix_comment_icon
[Editor] Fix the dimensions of the comment icon
2025-08-28 20:33:31 +02:00
Calixte Denizet
0a4817fb71 [Editor] Fix unit (for consistency) and remove few useless px 2025-08-28 16:09:58 +02:00
Calixte Denizet
1876013e4e [Editor] Fix the dimensions of the comment icon 2025-08-27 16:01:29 +02:00
calixteman
e37a58f978
Merge pull request #20200 from calixteman/remove_useless_css2
[Editor] Remove useless CSS and fix styling for the comment button
2025-08-26 22:10:11 +02:00
Calixte Denizet
e44e470eb2 [Editor] Remove useless CSS and fix styling for the comment button 2025-08-26 22:06:49 +02:00
Tim van der Meij
d8c01bf70d
Merge pull request #20196 from calixteman/xy_getter
[Editor] Add a method to get an editor rect in the pdf page coordinates
2025-08-26 20:27:06 +02:00
Calixte Denizet
1fc039e14f [Editor] Add a method to get an editor rect in the pdf page coordinates 2025-08-26 19:40:41 +02:00
Tim van der Meij
bde01f0998
Merge pull request #20195 from timvandermeij/fix-chrome-windows
Skip the curvature ink editor integration test for Chrome on Windows
2025-08-25 21:35:13 +02:00
Tim van der Meij
11d5d6d0ce
Skip the curvature ink editor integration test for Chrome on Windows
This test permafails for that particular OS/browser combination.

Fixes 18d3dc18.
2025-08-25 20:09:32 +02:00
calixteman
5a10376e4d
Merge pull request #20191 from calixteman/link_gotoxy
Add a method goToXY in PDFLinkService in order to scroll the document at a given location
2025-08-25 20:08:03 +02:00
calixteman
261c1f9e05
Merge pull request #20194 from calixteman/update_comment_icon
[Editor] Change the icon for inline comments
2025-08-25 20:07:37 +02:00
Calixte Denizet
5ed2dfbf26 [Editor] Change the icon for inline comments 2025-08-25 20:04:56 +02:00
Calixte Denizet
1678782680 Add a method goToXY in PDFLinkService in order to scroll the document at a given location
This function is required for the commenting feature: the user will be able to click
on a comment in the sidebar and the document will be scrolled accordingly.
2025-08-25 19:57:53 +02:00
Tim van der Meij
ab41f5095c
Merge pull request #20190 from timvandermeij/text-layer-permafail
Improve the selection check in the "doesn't jump when moving selection" integration test
2025-08-25 19:40:27 +02:00
calixteman
7a65c58b5e
Merge pull request #20170 from calixteman/bug1980958
Don't iterate over all empty slots in the xref entries (bug 1980958)
2025-08-25 15:46:20 +02:00
Calixte Denizet
af144be3ba Don't iterate over all empty slots in the xref entries (bug 1980958) 2025-08-25 14:02:08 +02:00
calixteman
5d4f0659bc
Merge pull request #20182 from calixteman/add_comment_button
[Editor] Add a button to the annotation having a popup in order to edit it
2025-08-25 13:18:37 +02:00
calixteman
307ea5d25d
Merge pull request #20187 from calixteman/update_puppeteer_24.17.0
Update puppeteer to 24.17.0
2025-08-25 13:09:44 +02:00
Calixte Denizet
0af61f5bf4 Update puppeteer to 24.17.0 2025-08-25 09:33:53 +02:00
Calixte Denizet
bd8c438428 [Editor] Add a button to the annotation having a popup in order to edit it 2025-08-24 21:36:19 +02:00
Tim van der Meij
4cc93af364
Improve the selection check in the "doesn't jump when moving selection" integration test
Locally, on Arch Linux, this integration test permafails:

```
1) Text layer Text selection using selection carets doesn't jump when moving selection
  Message:
    second selection:
        Expected '(frequently executed) bytecode sequences, records
        them, and compiles them to fast native code. We call such a s' to roughly match /frequently .* We call such a se/s.
  Stack:
        at <Jasmine>
        at UserContext.<anonymous> (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/test/integration/text_layer_spec.mjs:521:12)
  Message:
    third selection:
        Expected '(frequently executed) bytecode sequences, records
        them, and compiles them to fast native code. We call such a s' to roughly match /frequently .* We call such a se/s.
  Stack:
        at <Jasmine>
        at UserContext.<anonymous> (file:///home/timvandermeij/Documenten/Ontwikkeling/pdf.js/Code/test/integration/text_layer_spec.mjs:529:12
```

The exact selection can differ a bit per OS/browser. In this case the
last character was consistently not selected while on other platforms it
is, so this commit fixes the issue by relaxing the regex to not consider
the final character so that the test passes if the rest matches.
2025-08-24 20:46:20 +02:00
Tim van der Meij
649a03f817
Merge pull request #20189 from timvandermeij/null-signal
[Editor] Don't use a null signal for the comment button
2025-08-24 20:43:36 +02:00
Tim van der Meij
eec1bea1b4
[Editor] Don't use a null signal for the comment button
This removes the following error from the integration test logs:

```
JavaScript error: http://127.0.0.1:59283/build/generic/build/pdf.mjs, line 3879:
TypeError: EventTarget.addEventListener: 'signal' member of AddEventListenerOptions is not an object.
```

Fixes 636ff50.
Extends 63651885.
2025-08-24 20:01:10 +02:00
Tim van der Meij
535a042b01
Merge pull request #20188 from timvandermeij/chrome-webdriverbidi
Use WebDriver BiDi for Chrome
2025-08-24 19:59:31 +02:00
Tim van der Meij
18d3dc18e0
Use WebDriver BiDi for Chrome 2025-08-24 15:58:52 +02:00
calixteman
592d6c070a
Merge pull request #20179 from calixteman/add_rect_popup
[Editor] Add a Rect entry to a saved popup in order to avoid to have an invalid pdf
2025-08-24 12:01:31 +02:00
calixteman
78f63dd6db
Merge pull request #20180 from calixteman/mv_comment_button
[Editor] Move the comment button just before the delete one
2025-08-24 12:00:29 +02:00
calixteman
cfe08bd035
Merge pull request #20184 from calixteman/use_cached_annotations
Use the cached annotations when collecting them by types
2025-08-24 11:57:17 +02:00
Tim van der Meij
8be21711a4
Merge pull request #20183 from calixteman/resizer_top_editor
[Editor] Make sure the resizers are on top of the editor content
2025-08-23 21:27:35 +02:00
calixteman
4e089f210a
Merge pull request #20186 from calixteman/puppeteer_switch_nightly
Use Firefox nightly with puppeteer
2025-08-23 15:36:21 +02:00
Calixte Denizet
22c0e25eb5 Use Firefox nightly with puppeteer 2025-08-22 22:02:34 +02:00
calixteman
673f19bc2b
Merge pull request #19043 from nicolo-ribaudo/compute-bounding-boxes
Add logic to track rendering area of various PDF ops
2025-08-22 20:34:03 +02:00
Nicolò Ribaudo
6a22da9c2e
Add logic to track rendering area of various PDF ops
This commit is a first step towards #6419, and it can also help with
first compute which ops can affect what is visible in that part of
the page.

This commit adds logic to track operations with their respective
bounding boxes. Only operations that actually cause something to
be rendered have a bounding box and dependencies.

Consider the following example:
```
0. setFillRGBColor
1. beginText
2. showText "Hello"
3. endText
4. constructPath [...] -> eoFill
```
here we have three rendering operations: the showText op (2) and the
path (4). (2) depends on (0), (1) and (3), while (4) only depends on
(0). Both (2) and (4) have a bounding box.

This tracking happens when first rendering a PDF: we then use the
recorded information to optimize future partial renderings of a PDF, so
that we can skip operations that do not affected the PDF area on the
canvas.

All this logic only runs when the new `enableOptimizedPartialRendering`
preference, disabled by default, is enabled.

The bounding boxes and dependencies are also shown in the pdfBug
stepper. When hovering over a step now:
- it highlights the steps that they depend on
- it highlights on the PDF itself the bounding box
2025-08-22 18:26:59 +02:00
Calixte Denizet
ebc3411727 Use the cached annotations when collecting them by types 2025-08-21 18:04:00 +02:00
Calixte Denizet
0c6cf84274 [Editor] Make sure the resizers are on top of the editor content 2025-08-21 09:10:57 +02:00
Calixte Denizet
f8466c9ff8 [Editor] Add a Rect entry to a saved popup in order to avoid to have an invalid pdf 2025-08-20 17:56:50 +02:00
Calixte Denizet
f8ea63606c [Editor] Move the comment button just before the delete one 2025-08-20 17:18:38 +02:00
calixteman
e20ee99580
Merge pull request #20178 from calixteman/pinpoint_firefox
Use Firefox stable for the tests because bug 1983414
2025-08-20 17:04:08 +02:00
Calixte Denizet
2beb26ad14 Use Firefox stable for the tests because bug 1983414 2025-08-20 16:11:59 +02:00
calixteman
212547e865
Merge pull request #20169 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-08-19 10:41:27 +02:00
calixteman
65dd6b05a9
Merge pull request #20167 from calixteman/get_all_editable_annotations
[Editor] Add the ability to get all the editable annotations in a pdf document
2025-08-19 10:39:48 +02:00
Calixte Denizet
9e5ee1e5a7 [Editor] Add the ability to get all the editable annotations in a pdf document
We want to be able to show all the comments in a pdf even if the pages where they are
haven't been rendered.
And it'll help to fix the issue #18915.
2025-08-18 21:31:11 +02:00
Tim van der Meij
13de21841d
Update translations to the most recent versions 2025-08-17 16:32:29 +02:00
Tim van der Meij
d49fc494cd
Update dependencies to the most recent versions 2025-08-17 16:32:29 +02:00
Tim van der Meij
dd560ee453
Merge pull request #20171 from timvandermeij/firefox-test-prefs
Update Firefox preferences for testing
2025-08-17 16:31:16 +02:00
Tim van der Meij
844681a2fa
Disable AI/ML features using Firefox preferences for testing
We don't need AI/ML features in the tests, so this should reduce CPU
usage by not having the inference process running. Moreover, it prevents
the following lines from being logged in the test output:

```
JavaScript error: resource://gre/actors/MLEngineParent.sys.mjs, line 509: Error: Unable to get the ML engine from Remote Settings.
JavaScript error: resource://gre/actors/MLEngineParent.sys.mjs, line 1279: TypeError: can't access property "postMessage", this[#port] is null
```
2025-08-17 16:05:04 +02:00
Tim van der Meij
a05dc9c1c5
Remove obsolete Firefox preferences for testing
The following preferences don't have to be set manually anymore:

- `print.show_print_progress`
  - Why: removed
  - Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1770536
  - Commit: b522664310

- `gfx.offscreencanvas.enabled`
  - Why: removed
  - Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1914083
  - Commit: 7d2c688920

- `layout.css.round.enabled`
  - Why: removed
  - Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1874633
  - Commit: 97909653e7

- `dom.events.asyncClipboard.clipboardItem`
  - Why: enabled by default
  - Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1887845
  - Commit: de56ae88bf
2025-08-17 14:53:35 +02:00
Tim van der Meij
5adff6a2e2
Merge pull request #20126 from timvandermeij/fix-intermittents-chrome
Implement a delay for Chrome protocol calls in the integration tests, and skip the "must check that an existing highlight is ignored on hovering" integration test on Windows
2025-08-15 19:34:13 +02:00
Tim van der Meij
17dc9e9917
Skip the "must check that an existing highlight is ignored on hovering" integration test on Windows
This is a temporary measure to reduce noise until #20136 is fixed. Note
that this shouldn't be an issue in terms of coverage because we still
run the test on Linux.
2025-08-14 20:54:41 +02:00
Tim van der Meij
7294377cd9
Implement a delay for Chrome protocol calls in the integration tests
In Chrome protocol calls are faster than in Firefox and thus trigger in
quicker succession. This can cause intermittent failures because new
protocol calls can run before events triggered by the previous protocol
calls had a chance to be processed (essentially causing events to get
lost).

This commit fixes the issue by configuring Chrome with a protocol call
delay value that gives it a more similar execution speed as Firefox
(which also gives us more consistency between the two browser runs).

Note that this doesn't negatively impact the overall runtime of the
integration tests because Puppeteer already waits for a test to complete
in both browsers before continuing to the next one and Chrome
consistently was, and with this patch still slightly is, faster in
completing the tests.
2025-08-14 20:54:37 +02:00
Tim van der Meij
c6bd044438
Merge pull request #20164 from calixteman/editor_hide_deleted_annotation
[Editor] Correctly hide deleted annotations
2025-08-14 20:39:39 +02:00
Tim van der Meij
5951485b98
Merge pull request #20166 from calixteman/fix_signal_integration_test
[Editor] Avoid to use a null signal when setting listeners in the editor toolbar
2025-08-14 20:32:49 +02:00
Calixte Denizet
6365188535 [Editor] Avoid to use a null signal when setting listeners in the editor toolbar
It should fix the error:
```
JavaScript error: http://127.0.0.1:43303/build/generic/build/pdf.mjs, line 1445:
TypeError: EventTarget.addEventListener: 'signal' member of AddEventListenerOptions is not an object.
```

we've when running integration tests on the Linux bot.
2025-08-14 15:07:22 +02:00
Calixte Denizet
6a00174688 [Editor] Correctly hide deleted annotations 2025-08-13 22:41:19 +02:00
Tim van der Meij
7ea7a94ed5
Merge pull request #20160 from calixteman/issue20155
Check the setDash arguments
2025-08-12 20:48:44 +02:00
Tim van der Meij
32ea986c9b
Merge pull request #20161 from mozilla/dependabot/github_actions/actions/checkout-5
Bump actions/checkout from 4 to 5
2025-08-12 20:02:18 +02:00
dependabot[bot]
e38fb68724
Bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-11 17:13:51 +00:00
Tim van der Meij
1bada43a22
Merge pull request #20159 from calixteman/update_l10n_1
Update l10n files
2025-08-10 11:15:19 +02:00
Calixte Denizet
1d4ae786f4 Check the setDash arguments
It fixes #20155.
2025-08-09 22:34:44 +02:00
Calixte Denizet
02635814a2 Update l10n files 2025-08-08 14:46:17 +02:00
calixteman
41ca92b2ea
Merge pull request #20149 from k-nut/patch-1
Mark `canvasContext` as optional
2025-08-07 22:38:32 +02:00
Knut Hühne
760c8d632c
Mark canvasContext as optional
In #20016, the `canvasContext` property of `RenderParameters` was deprecated in favor of the new `canvas` property.

The JSDoc was updated to include the new parameter along with the old one.

I think the old one should be enclosed in `[]` to mark it as optional (and to allow usage from TypeScript with just the `canvas` parameter provided).

I also reordered the properties so that all required properties come first, follow by optional ones.
2025-08-06 12:38:30 +02:00
calixteman
fcf69d8536
Merge pull request #20093 from Aditi-1400/fix-horizontal-scroll
Make horizontal padding relative to device width
2025-08-06 11:44:55 +02:00
calixteman
d41f144716
Merge pull request #20148 from fnlctrl/icc-lazy-finalization-registry
Lazy initialize FinalizationRegistry used by IccColorSpace.#finalizer
2025-08-06 11:24:40 +02:00
宋铄运 (Alan Song)
3d9374e02e lazy initialize IccColorSpace.#finalizer 2025-08-05 22:29:32 +00:00
Aditi
9babc144a7 Make horizontal padding relative to device width
The fixed -400px horizontal offset used by
scrollIntoView led to horizontal scroll only moving
part-way right on narrow screens. The highlights near
the right-edge remained party or completely off
screen.

This centres the highlighted match on any viewport width while
clamping the left margin to 20-400px. On very narrow screens
the scrollbar now moves all the way to the right instead of
stopping midway.
2025-08-04 15:29:52 +05:30
Tim van der Meij
e9a483014d
Merge pull request #20142 from calixteman/bug1957680
Trigger a fake scrollend event in case it hasn't been triggered by the browser (bug 1957680)
2025-08-03 16:03:39 +02:00
Tim van der Meij
17527d84f8
Merge pull request #20138 from calixteman/bug1976597
[Editor] Highlight text on a selectionchange event which hasn't been triggered by the pointer or the keyboard (bug 1976597)
2025-08-03 15:29:07 +02:00
Calixte Denizet
287776483f Trigger a fake scrollend event in case it hasn't been triggered by the browser (bug 1957680)
This way, it should unblock zooming with ctrl+wheel after scrolling.
2025-08-01 19:06:26 +02:00
Calixte Denizet
a81e99168a [Editor] Highlight text on a selectionchange event which hasn't been triggered by the pointer or the keyboard (bug 1976597)
It's useful for users highlighting with NVDA.
They've to enable native selection and then selection some text.
In this case only a selectionchange is triggered once the selection is done.
2025-07-31 21:03:32 +02:00
calixteman
e5922f2e72
Merge pull request #20129 from calixteman/bug1978985
Disable printing when enablePermission is true and the pdf isn't allowed to be printed (bug 1978985)
2025-07-30 20:03:44 +02:00
Calixte Denizet
806f9c1cee Disable printing when enablePermission is true and the pdf isn't allowed to be printed (bug 1978985) 2025-07-30 19:29:01 +02:00
Tim van der Meij
e48563ab5d
Merge pull request #20134 from timvandermeij/fix-intermittent-scripting
Fix intermittent failure in the "must check that the computed value is correct" scripting integration test
2025-07-29 20:04:51 +02:00
Tim van der Meij
48c6253b32
Fix intermittent failure in the "must check that the computed value is correct" scripting integration test
Typing in the text field causes a sandbox event to trigger, which we
should await to avoid continuing to the next part of the test before
the sandbox event is fully processed.
2025-07-29 19:31:08 +02:00
calixteman
f16e0b6daa
Merge pull request #20132 from calixteman/fix_css_2
[Editor] Remove unused property
2025-07-29 12:01:49 +02:00
Calixte Denizet
38b410f7e5 [Editor] Remove unused property 2025-07-29 11:58:49 +02:00
calixteman
d9ffffd435
Merge pull request #20131 from calixteman/fix_css
[Editor] Remove useless css and use a defined but unused property
2025-07-29 10:03:51 +02:00
Calixte Denizet
fbdeb7bb6d [Editor] Remove useless css and use a defined but unused property 2025-07-29 09:33:38 +02:00
Tim van der Meij
aa4b9ffd4a
Merge pull request #20128 from calixteman/issue20127
Add comment-* images when building components
2025-07-28 20:15:18 +02:00
calixteman
2e974e8f30
Merge pull request #20109 from maettuu/reg-test-pr-19639
Add regression test for PR 19639
2025-07-28 18:53:24 +02:00
calixteman
995f070f23
Merge pull request #20119 from calixteman/comment_floating_button
[Editor] Add a floating button in order to highlight the text selection and add a comment (bug 1979381)
2025-07-28 18:20:34 +02:00
Calixte Denizet
3fb7cd40e7 [Editor] Add a floating button in order to highlight the text selection and add a comment (bug 1979381)
The callback called when clicking on the button is the same as the one trigged by clicking in the context menu (in m-c).
2025-07-28 15:32:23 +02:00
calixteman
366727d734
Merge pull request #20125 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-07-28 14:54:28 +02:00
Calixte Denizet
605c9be94f Add comment-* images when building components
It fixes #20127.
2025-07-28 14:30:03 +02:00
Tim van der Meij
7f5c517b49
Update translations to the most recent versions 2025-07-27 18:32:32 +02:00
Tim van der Meij
c19271f7c3
Upgrade eslint-plugin-unicorn to version 60.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v60.0.0
doesn't indicate any breaking changes that should impact us.

Note that this brings the vulnerability count back to zero because this
version addresses https://github.com/advisories/GHSA-xffm-g5w8-qvg7.
2025-07-27 18:32:32 +02:00
Tim van der Meij
7594f21adb
Update dependencies to the most recent versions
Note that we must include `eslint-config-prettier` explicitly because
it's now a required dependency and without it linting fails; please see
https://github.com/prettier/eslint-plugin-prettier?tab=readme-ov-file#installation.
2025-07-27 18:31:03 +02:00
Tim van der Meij
e4b146221b
Merge pull request #20124 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-07-27 17:55:59 +02:00
Tim van der Meij
8771175e5f
Bump the stable version in pdfjs.config 2025-07-27 17:52:46 +02:00
Tim van der Meij
295fb3ec4f
Merge pull request #20120 from calixteman/remove_actions_button
[Editor] Don't show the actions button in the comment popup when it's useless
2025-07-27 14:24:17 +02:00
Calixte Denizet
efc1654326 [Editor] Don't show the actions button in the comment popup when it's useless 2025-07-25 19:47:58 +02:00
calixteman
542514efbd
Merge pull request #20116 from calixteman/add_date_picker
Use a HTML date/time input when a field requires a date or a time.
2025-07-25 15:34:52 +02:00
Calixte Denizet
57ce4f8f43 Use a HTML date/time input when a field requires a date or a time.
The user will be able to enter a date in the format corresponding to their locale
and it'll be formatted in using the format provided by the pdf.
2025-07-24 22:01:45 +02:00
calixteman
aee4f2d33c
Merge pull request #20113 from calixteman/bug1978317
Fix the xref table with the values we've at the beginning of a xref stream (bug 1978317)
2025-07-23 09:36:29 +02:00
Calixte Denizet
78391ed85a Fix the xref table with the values we've at the beginning of a xref stream (bug 1978317) 2025-07-22 22:10:23 +02:00
maettuu
ac8757f36f Add regression test for negative LW normalization in gs operator
Ensure that negative “LW” entries in an ExtGState dictionary are converted to their absolute values when the “gs” operator is processed.

See PR https://github.com/mozilla/pdf.js/pull/19639
2025-07-20 16:03:46 +02:00
Tim van der Meij
bfc20250b2
Merge pull request #20107 from timvandermeij/updates
Update translations and dependencies to the most recent versions
2025-07-19 20:06:33 +02:00
Tim van der Meij
dcf161e2eb
Update translations to the most recent versions 2025-07-19 18:41:21 +02:00
Tim van der Meij
5d6023cb2a
Update dependencies to the most recent versions 2025-07-19 18:39:16 +02:00
Tim van der Meij
ed141970e6
Merge pull request #20099 from calixteman/bug1977259
[Editor] Fix the highlighting colors in HCM (bug 1977259)
2025-07-18 22:25:43 +02:00
Tim van der Meij
f3080a185b
Merge pull request #20106 from timvandermeij/fix-viewer-alert-intermittent
Fix intermittent failure in the viewer alert tests
2025-07-18 21:32:26 +02:00
Tim van der Meij
603fd2524a
Fix intermittent failure in the viewer alert tests
It takes some time for the viewer alert to be updated after the editor
is committed, but the current tests don't await that and proceed too
fast to the viewer alert string assertion. This commit fixes the issue
by waiting for the expected viewer alert string to appear instead.
2025-07-18 20:56:02 +02:00
Tim van der Meij
daf2cbbfe9
Merge pull request #20096 from calixteman/bug1708041
Make the link annotations correctly announced by screen readers (bug 1708041)
2025-07-18 20:33:30 +02:00
Calixte Denizet
f695e0ca62 Make the link annotations correctly announced by screen readers (bug 1708041)
And focus the targeted page when the user clicks on a link.
2025-07-18 20:15:31 +02:00
Calixte Denizet
c022a3294a [Editor] Fix the highlighting colors in HCM (bug 1977259)
Using the same color in HCM or non-HCM was inducing a too small contrast between
some bg/fg colors making the text a bit hard to read.
2025-07-18 20:11:28 +02:00
calixteman
bfc7fc4da9
Merge pull request #20101 from calixteman/issue20065
Use canvas context text primitives when the font file is missing
2025-07-18 20:03:22 +02:00
Calixte Denizet
8b17e5ecd8 Use canvas context text primitives when the font file is missing
It fixes #20065.

The only to get a path (from the path generator) is when the font is embedded.
So when we need a path (disableFontFace: true or when we want to use a pattern for stroking/filling), it's impossible
to fulfil.
2025-07-18 19:57:30 +02:00
Tim van der Meij
e4585c2452
Merge pull request #20104 from calixteman/fix_newpopup
[Editor] Only add a popup to an existing annotation if it exits
2025-07-18 19:34:03 +02:00
Calixte Denizet
6d7e0e7025 [Editor] Only add a popup to an existing annotation if it exits
It fixes the ink integration test "must update an existing annotation".
2025-07-18 17:31:53 +02:00
Tim van der Meij
23bd705cea
Merge pull request #20080 from calixteman/add_comment_1
[Editor] Add the possibility to add Popup annotations (bug 1976724)
2025-07-17 21:07:06 +02:00
calixteman
d2f8e60794
Merge pull request #20098 from calixteman/update_highlight_color
[Editor] Make possible to change the highlight color from the main panel
2025-07-17 21:06:29 +02:00
Calixte Denizet
5162209b27 [Editor] Make possible to change the highlight color from the main panel
It's consistent with the way to change colors for FreeText or Ink annotations.
2025-07-17 20:57:51 +02:00
Tim van der Meij
ef9292094c
Merge pull request #20103 from calixteman/avoid_undefined_id
Don't add an undefined id to the span for marked content
2025-07-17 20:36:16 +02:00
Calixte Denizet
86d58b637f Don't add an undefined id to the span for marked content
It fixes #20102.
2025-07-17 19:13:30 +02:00
Calixte Denizet
636ff503ff [Editor] Add the possibility to add Popup annotations (bug 1976724)
It's a first big step.
This patch contains a new modal dialog to let the user edit/update a Popup
2025-07-15 22:39:16 +02:00
Tim van der Meij
9f645fb9a6
Merge pull request #20095 from calixteman/issue20091
[Editor] Make sure that doorhangers are large enough to fit localized strings
2025-07-15 19:50:48 +02:00
Tim van der Meij
be10bb8c7b
Merge pull request #20094 from calixteman/use_rounded_color_swatch
[Editor] Use a round color swatch for the basic color picker
2025-07-15 19:48:07 +02:00
Calixte Denizet
ca4e219b7b [Editor] Make sure that doorhangers are large enough to fit localized strings
It fixes #20091.
2025-07-15 17:14:44 +02:00
Calixte Denizet
b2aba463a5 [Editor] Use a round color swatch for the basic color picker 2025-07-15 15:06:07 +02:00
calixteman
5600c0ac02
Merge pull request #20092 from calixteman/mv_a11y_alert
Avoid Firefox test failure
2025-07-15 10:53:32 +02:00
Calixte Denizet
6b5aee2923 Avoid Firefox test failure
It fixes test: accessible/tests/mochitest/elm/test_HTMLSpec.html
2025-07-15 10:50:38 +02:00
calixteman
4f2390a607
Merge pull request #20070 from calixteman/editor_toolbar_color
[Editor] Add a color picker in the toolbar of Ink and Freetext annotations
2025-07-14 23:55:51 +02:00
Calixte Denizet
dbd6f8cdd4 [Editor] Add a color picker in the toolbar of Ink and Freetext annotations 2025-07-14 23:00:01 +02:00
calixteman
ac2a0c5080
Merge pull request #20085 from calixteman/bug1975719
Handle the case where all the image data are in the alpha channel (bug 1975719)
2025-07-14 22:44:19 +02:00
calixteman
e0783cd075
Merge pull request #20086 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-07-13 19:47:11 +02:00
calixteman
9070a2786a
Merge pull request #20087 from timvandermeij/fix-intermittent-viewer
Fix the "must check that canvas perfectly fits the page whatever the zoom level" viewer integration test
2025-07-13 13:54:24 +02:00
Tim van der Meij
a0f8cbafcf
Fix the "must check that canvas perfectly fits the page whatever the zoom level" viewer integration test
In order to screenshot the page and assert that it's monochrome,
providing a regression test for #18694, the viewer background is
configured to match the page background because screenshotting the page
always captures a small part of the viewer background as well, and this
way we can easily go over all pixels and check that they are all equal.

However, in addition to configuring the viewer background the test also
hides the toolbar and removes the page border. Especially the latter
makes `scrollIntoView` fail in both Chrome and Firefox with recent
Puppeteer versions, for reasons which remain a bit unclear.

Fortunately both hiding the toolbar and removing the page border is not
actually necessary (anymore) for the test to work, so we can simply
remove those actions to fix the issue and reduce the amount of code. To
make sure that the test still covers the original issue correctly we've
reverted the changes from #18698 and then test still fails as expected.

Fixes #19811.
Fixes 68332ec2.
2025-07-12 21:49:33 +02:00
Tim van der Meij
3054942101
Update translations to the most recent versions 2025-07-12 20:21:07 +02:00
Tim van der Meij
7a129f8eae
Update dependencies to the most recent versions 2025-07-12 20:20:05 +02:00
Tim van der Meij
b7a0f01f40
Merge pull request #19976 from calixteman/write_popup
[Editor] Add the possibility to add a popup to an annotation when saving
2025-07-12 15:28:56 +02:00
Tim van der Meij
64b150f78f
Merge pull request #20077 from calixteman/remove_popup
[Editor] Remove a popup from the DOM when it's deleted
2025-07-12 15:25:49 +02:00
Calixte Denizet
6f8796d2c8 Handle the case where all the image data are in the alpha channel (bug 1975719)
and add an error message in case where there is no data in the image.
2025-07-11 22:34:37 +02:00
Calixte Denizet
b07914843b [Editor] Remove a popup from the DOM when it's deleted 2025-07-11 21:55:14 +02:00
Calixte Denizet
8fc51dc089 [Editor] Add the possibility to add a popup to an annotation when saving
When saving/printing, only update the properties which are provided and set
a default value only when there is no pre-existing one.
2025-07-11 21:42:21 +02:00
Tim van der Meij
e853a8f41a
Merge pull request #20081 from calixteman/signature_description
Add the l10n parameter when pasting a Signature annotation
2025-07-11 20:27:06 +02:00
Tim van der Meij
c296fb8f95
Merge pull request #20084 from calixteman/hcm_popup_trigger_area
In HCM, invert colors when hovering an annotation with a popup
2025-07-11 20:22:31 +02:00
Tim van der Meij
094253f2de
Merge pull request #20082 from calixteman/fix_firefox_printing
Use the canvas context from mozPrintCallback when printing a pdf from the Firefox viewer
2025-07-11 20:21:03 +02:00
Calixte Denizet
7091647039 In HCM, invert colors when hovering an annotation with a popup 2025-07-11 15:35:35 +02:00
Calixte Denizet
1c15ba7789 Use the canvas context from mozPrintCallback when printing a pdf from the Firefox viewer
The context is specific to the callback and cannot be created from the canvas itself.
2025-07-11 12:55:39 +02:00
Calixte Denizet
0f504d9a1a Add the l10n parameter when pasting a Signature annotation 2025-07-10 21:01:24 +02:00
calixteman
2e0f1ec515
Merge pull request #20076 from calixteman/revert_20047
Revert "Make horizontal padding relative to device width"
2025-07-09 18:09:26 +02:00
Calixte Denizet
e36f58ee4d Revert "Make horizontal padding relative to device width"
This reverts commit c138887c1f7613bce44b99d22b63e2d744b0fb40.
2025-07-09 17:38:49 +02:00
calixteman
2dadac8877
Merge pull request #20071 from ryzokuken/bump-version-5.4
Bump library version to `5.4`
2025-07-09 14:57:13 +02:00
Ujjwal Sharma
1d702d4d6d Bump library version to 5.4 2025-07-08 23:27:41 +02:00
calixteman
1b427a3af5
Merge pull request #20016 from ryzokuken/move-getcontext
[api-minor] Move getContext call to InternalRenderTask
2025-07-08 22:20:19 +02:00
calixteman
0e2b59e3d5
Merge pull request #20064 from calixteman/dict_api
Add few methods to the Dict class in order to simplify the code when writing an annotation
2025-07-08 22:16:57 +02:00
calixteman
481b74a1c2
Merge pull request #20063 from calixteman/issue20062
Fix the default appearance of a Polygon annotation when a fill color is provided
2025-07-08 22:10:52 +02:00
Calixte Denizet
63b37b4371 Add few methods to the Dict class in order to simplify the code when writing an annotation 2025-07-08 21:23:29 +02:00
Calixte Denizet
ecc7096a80 Fix the default appearance of a Polygon annotation when a fill color is provided
It fixes #20062.
2025-07-08 20:51:58 +02:00
Tim van der Meij
b999d5ce58
Merge pull request #20060 from noritaka1166/fix-typos
Fix typos across the codebase
2025-07-08 18:28:52 +02:00
calixteman
729f2bb148
Merge pull request #20058 from calixteman/use_creationdate_popup
Use the creation date in the popup when there is no modification date
2025-07-07 10:55:28 +02:00
Calixte Denizet
bb52a440ce Use the creation date in the popup when there is no modification date
Remove the h1 element in popup title because it caused a warning in Firefox and use a span instead.
2025-07-07 10:51:35 +02:00
Noritaka Kobayashi
fa568e826d
Fix typos across the codebase 2025-07-07 09:59:36 +09:00
Tim van der Meij
b3794c7148
Merge pull request #20061 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-07-06 20:45:30 +02:00
Tim van der Meij
be1f5fe009
Bump the stable version in pdfjs.config 2025-07-06 20:42:12 +02:00
Tim van der Meij
cbeef3233f
Merge pull request #20056 from calixteman/one_click
[Editor] Allow to change the editor mode when selecting the corresponding editor (bug 1975538)
2025-07-06 19:35:31 +02:00
Ujjwal Sharma
b1b728d47f [api-minor] Move getContext call to InternalRenderTask
This is a precursor to moving the call into a
worker thread to let us use `OffscreenCanvas`. The
current position wouldn't work since we make
transformations to the canvas object after the
getContext call, which isn't allowed for
OffscreenCanvas. Also it isn't allowed to clone or
`transferControlToOffscreen` the canvas after the
`getContext` call.
2025-07-04 00:53:51 +02:00
Calixte Denizet
6d2c6cfc9f [Editor] Allow to change the editor mode when selecting the corresponding editor (bug 1975538)
For example, selecting an ink editor just after having created a freetext will switch to ink mode.
2025-07-03 23:27:34 +02:00
calixteman
2d0ba7db08
Merge pull request #20043 from yyliu12/popup-rotation-fix
Make Popup annotations always have noRotate flag set as true
2025-07-03 17:27:40 +02:00
calixteman
ad31385792
Merge pull request #20055 from calixteman/bug1975264
[Editor] When an annotation is added, announce it if the user is using a screen reader (bug 1975264)
2025-07-03 17:23:56 +02:00
calixteman
54c0d56ccf
Merge pull request #20054 from calixteman/bug1974863
Don't focus the viewer at startup (bug 1974863)
2025-07-03 17:01:19 +02:00
Calixte Denizet
c22a425b04 [Editor] When an annotation is added, announce it if the user is using a screen reader (bug 1975264) 2025-07-03 16:53:01 +02:00
calixteman
fd87e668e0
Merge pull request #20047 from Aditi-1400/fix-horizontal-scroll
Make horizontal padding relative to device width
2025-07-03 16:52:15 +02:00
Yuyang Liu
d8ecfad8bd Make Popup annotations always have noRotate flag set as true
Necessary because when there is no Popup annotation created along
with a Text annotation, the Popup annotation created by pdf.js
does not receive the noRotate flag
2025-07-03 05:52:31 +09:00
Calixte Denizet
aaae516894 Don't focus the viewer at startup (bug 1974863)
It's useless and it causes screen readers to not always read the document title.
2025-07-02 17:34:23 +02:00
calixteman
426ee03488
Merge pull request #20041 from calixteman/bug1974436
Remove the shadow from the links (bug 1974436)
2025-07-01 12:59:17 +02:00
Tim van der Meij
8f2a4561b2
Merge pull request #20039 from calixteman/bug1974257
[Editor] In the signature modal, disable the save checkbox when the storage is full (bug 1974257)
2025-06-30 21:46:38 +02:00
Calixte Denizet
9acd16a0c7 [Editor] In the signature modal, disable the save checkbox when the storage is full (bug 1974257) 2025-06-30 21:42:28 +02:00
Calixte Denizet
fc9ba0cda3 Remove the shadow from the links (bug 1974436)
The shadow was taken into account when computing the bounding box of the section
containing the link and it was making the clip path wrong.
Since the shadow is almost invisible because of the opacity, the yellow color and the clip
we can remove it without causing any visual regressions (and as a side effect it'll avoid
to use resources to compute it when displayed).
2025-06-30 21:39:22 +02:00
Tim van der Meij
f4043b03e2
Merge pull request #20038 from calixteman/bug1974112
Don't remove a dash at the end of a line when guessing urls (bug 1974112)
2025-06-30 20:43:17 +02:00
Aditi
c138887c1f Make horizontal padding relative to device width
The fixed -400px horizontal offset used by
scrollIntoView led to horizontal scroll only moving
part-way right on narrow screens. The highlights near
the right-edge remained party or completely off
screen.

This centres the highlighted match on any viewport width while
clamping the left margin to 20-400px. On very narrow screens
the scrollbar now moves all the way to the right instead of
stopping midway.
2025-06-30 19:08:02 +05:30
Calixte Denizet
bb6b42177c Don't remove a dash at the end of a line when guessing urls (bug 1974112) 2025-06-26 18:55:59 +02:00
calixteman
85b67f19bc
Merge pull request #20031 from calixteman/telemetry_signature_certificate
Add some telemetry in order to know what are the certificates used in pdfs (bug 1973573)
2025-06-24 22:36:14 +02:00
Calixte Denizet
194e2ede4d Add some telemetry in order to know what are the certificates used in pdfs (bug 1973573) 2025-06-24 22:23:29 +02:00
calixteman
1ebc896b6f
Merge pull request #20019 from calixteman/bug1885505
Get the text under highlight/squiggly/underline/strikethrough annotations (bug 1885505)
2025-06-22 23:39:40 +02:00
Calixte Denizet
3bdc5d54fe Get the text under highlight/squiggly/underline/strikethrough annotations (bug 1885505)
and add an invisible element containing the text in the annotation layer to make
it readable by a screen reader.
2025-06-22 21:47:29 +02:00
Tim van der Meij
7d3b2a6d3f
Merge pull request #20028 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-06-22 18:38:23 +02:00
Tim van der Meij
08c0a6d6b1
Update translations to the most recent versions 2025-06-22 15:40:43 +02:00
Tim van der Meij
571a04bd23
Fix low-severity vulnerability in the brace-expansion dependency
This patch is automatically generated with `npm audit fix` and fixes
CVE-2025-5889.
2025-06-22 15:40:43 +02:00
Tim van der Meij
bd511747c8
Upgrade @types/node to version 24.0.3
This commit makes the type definitions compatible with Node 24 which was
released in May 2025.
2025-06-22 15:25:35 +02:00
Tim van der Meij
7f619c7605
Update dependencies to the most recent versions 2025-06-22 15:24:53 +02:00
Tim van der Meij
8fe9db0fb5
Merge pull request #20022 from calixteman/color_picker_a11y
[Editor] Fix the accessibility of the dropdown in the color picker
2025-06-22 14:23:20 +02:00
Tim van der Meij
ac399e77e8
Merge pull request #20023 from calixteman/edit_added_annotation
[Editor] When editing mode is disabled, allow to double click on a added annotation to edit it
2025-06-21 16:23:56 +02:00
Tim van der Meij
032f80e46a
Merge pull request #20027 from calixteman/issue20024
Allow to have an URL as file parameter when loading the viewer
2025-06-21 16:17:45 +02:00
Calixte Denizet
eafc040734 Allow to have an URL as file parameter when loading the viewer 2025-06-21 14:57:24 +02:00
calixteman
c7796c7f8d
Merge pull request #19993 from calixteman/editor_toolbar_simplification
Slightly simplify the way to create the editor toolbar
2025-06-20 21:59:01 +02:00
calixteman
e78575e593
Merge pull request #19986 from calixteman/dont_show_empty_popup
Only show popups when they've some contents to display
2025-06-20 13:48:30 +02:00
calixteman
84d1703897
Merge pull request #19992 from calixteman/hashtag_filename
Correctly handle files with a hash sign in their names (bug 1894166)
2025-06-20 12:52:31 +02:00
Calixte Denizet
b97cee2ab5 Correctly handle files with a hash sign in their names (bug 1894166)
It fixes #19990.
2025-06-20 09:21:41 +02:00
calixteman
e9527ce308
Merge pull request #20021 from calixteman/issue15490
[JS] Make the date parser less strict
2025-06-20 09:12:43 +02:00
Calixte Denizet
2541d96bf5 [JS] Make the date parser less strict
and display the expected date formt as a tooltip.
2025-06-20 08:57:07 +02:00
Calixte Denizet
2548405401 Slightly simplify the way to create the editor toolbar 2025-06-19 23:03:06 +02:00
Calixte Denizet
d0b0064643 [Editor] When editing mode is disabled, allow to double click on a added annotation to edit it
It's already possible but only when double clicking outside the the text layer.
This patach adds the possibility to click on the text layer.
2025-06-19 21:15:08 +02:00
Calixte Denizet
1f2e9e5c0f [Editor] Fix the accessibility of the dropdown in the color picker 2025-06-19 20:08:33 +02:00
Calixte Denizet
96216de410 Only show popups when they've some contents to display
Chrome, Edge and Acrobat do that.
2025-06-19 16:33:52 +02:00
calixteman
5653458b51
Merge pull request #20013 from calixteman/fix_annotation_tabindex
Make annotations focusable just after the text layer
2025-06-19 14:09:27 +02:00
calixteman
3baea2feff
Merge pull request #20003 from calixteman/bug1971299
Remove the possibility to go to the next page in using the ENTER key (bug 1971299)
2025-06-17 22:43:18 +02:00
calixteman
412500c9b9
Merge pull request #19996 from calixteman/bug1961423_bis
Fix a printing issue on Mac (bug 1961423)
2025-06-17 21:23:49 +02:00
calixteman
35b604b9f8
Merge pull request #20011 from calixteman/bug1971134
[Editor] Fix the text alignment in freetext annotations (bug 1971134)
2025-06-17 21:18:50 +02:00
calixteman
802808c47a
Merge pull request #20004 from calixteman/move_popup_dom
Move the popup annotation in the DOM just after the element triggering it
2025-06-16 23:11:23 +02:00
Calixte Denizet
0d995fa089 Make annotations focusable just after the text layer 2025-06-16 19:06:13 +02:00
Calixte Denizet
8d7246af98 [Editor] Fix the text alignment in freetext annotations (bug 1971134) 2025-06-16 15:11:32 +02:00
Calixte Denizet
27a81c506e Move the popup annotation in the DOM just after the element triggering it 2025-06-16 14:42:44 +02:00
Tim van der Meij
c796b93473
Merge pull request #20002 from nicolo-ribaudo/reftest-log-progress
Log test number and id in reftests
2025-06-15 19:36:11 +02:00
Calixte Denizet
07f94825c3 Remove the possibility to go to the next page in using the ENTER key (bug 1971299) 2025-06-10 14:58:18 +02:00
Nicolò Ribaudo
f789c132da
Log test number and id in reftests
The new output looks like
```
Harness thinks this browser is firefox
Fetching manifest "/test/test_manifest.json"... done
[1/1152] bug1755201:
  Skipping file "pdfs/bug1755201.pdf"
[2/1152] issue14864:
  Skipping file "pdfs/issue14864.pdf"
[3/1152] issue18503:
  Skipping file "pdfs/issue18503.pdf"
[4/1152] issue19835:
  Skipping file "pdfs/issue19835.pdf"
[5/1152] filled-background-range:
  Loading file "pdfs/filled-background.pdf"
    Loading page 1/3... Snapshotting... done
    Loading page 2/3... Snapshotting... done
    Loading page 3/3... Snapshotting... done
[6/1152] tracemonkey-eq:
  Loading file "pdfs/tracemonkey.pdf"
    Loading page 1/14... Snapshotting... done
    Loading page 2/14... Snapshotting... done
```

This gives an idea of how many tests are left while they are running
2025-06-09 18:48:06 +02:00
Tim van der Meij
250cc7d299
Merge pull request #20000 from timvandermeij/intermittent-find
Fix intermittent failure in the find integration tests
2025-06-08 22:11:15 +02:00
Tim van der Meij
7133259341
Merge pull request #19997 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-06-08 22:10:01 +02:00
Tim van der Meij
64a2d708f9
Fix intermittent failure in the find integration tests
After clicking the find button we need to wait for the input field to
appear before we try to type in it, but instead we were waiting for the
button to appear. However, the button is always present, so the current
`waitForSelector` call is basically a no-op, and this can cause the
integration tests to fail intermittently if we continue before the
input field is actually visible.

This appears to be due a typo first introduced in commit
d10da907dac86c103b787127110a59aed82c7aaa that has been copy/pasted.

This commit fixes the issue by waiting for the input field to be visible
before we continue typing in it.
2025-06-08 20:21:13 +02:00
Tim van der Meij
9edcfa26ca
Update translations to the most recent versions 2025-06-08 18:07:23 +02:00
Tim van der Meij
fda68a5a56
Upgrade yargs to version 18.0.0
This is a major version bump, but the changelog at
https://github.com/yargs/yargs/releases/tag/v18.0.0
doesn't indicate any breaking changes that should impact us.
2025-06-08 18:07:23 +02:00
Tim van der Meij
34ef9ece38
Upgrade svglint to version 4.1.0
This is a major version bump, but the changelog at
https://github.com/simple-icons/svglint/releases/tag/v4.0.0
doesn't indicate any breaking changes that should impact us.
2025-06-08 18:06:12 +02:00
Tim van der Meij
003cffe6cb
Update dependencies to the most recent versions 2025-06-08 18:02:45 +02:00
Calixte Denizet
14f0e88910 Fix a printing issue on Mac (bug 1961423)
On mac, the pdf backend used when printing is using the cid from the font,
so if a char has null cid then it's equivalent to .notdef and some viewers
don't display it.
2025-06-07 21:33:17 +02:00
calixteman
18d7aafc94
Merge pull request #19985 from calixteman/puppeteer_24.10.0
Update Puppeteer to version 24.10.0
2025-06-03 20:55:45 +02:00
Calixte Denizet
fd3a41c149 Update Puppeteer to version 24.10.0 2025-06-03 19:38:35 +02:00
Tim van der Meij
7e8587428d
Merge pull request #19981 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-06-01 20:30:28 +02:00
Tim van der Meij
8a0eb51f53
Bump the stable version in pdfjs.config 2025-06-01 20:26:12 +02:00
Tim van der Meij
47ad820d95
Merge pull request #19952 from timvandermeij/intermittent-viewer-origin
Fix intermittent failure in the "supports specifying a custom origin" viewer integration test
2025-06-01 20:10:31 +02:00
Tim van der Meij
f251e600d2
Fix intermittent failure in the "supports specifying a custom origin" viewer integration test
The problem in the original code is that `getTextAt` is called too
early and therefore returns unexpected text content. This can happen
because we call `increaseScale` and then wait for the page's text layer
to be visible, but it can take some time before the zoom actually
occurs/completes in the viewer and in the meantime the old (pre-zoom)
text layer may still be visible, causing us to continue too soon because
we don't validate that we're dealing with the post-zoom text layer.

This commit fixes the issue by simply waiting for the expected text to
show up at the given origin coordinates, which makes the test work
independent of viewer actions/timing.
2025-06-01 19:33:58 +02:00
calixteman
d63aabd662
Merge pull request #19969 from calixteman/editor_inconsistencies
[Editor] Change mode when double clicking on an editor
2025-05-28 18:00:26 +02:00
Calixte Denizet
47e69e93a3 [Editor] Change mode when double clicking on an editor
It was only possible to double click on a FreeText editor while being in ink mode (or any other).
2025-05-28 17:49:16 +02:00
calixteman
712d502561
Merge pull request #19975 from calixteman/fix_color_dialog_buttons
Fix the colors of disabled buttons in the dialogs
2025-05-28 16:14:28 +02:00
Calixte Denizet
de1a9e7055 Fix the colors of disabled buttons in the dialogs 2025-05-26 19:11:24 +02:00
Tim van der Meij
21ef454faf
Merge pull request #19962 from Snuffleupagus/api_utils
Move a few helper functions/classes out of the `src/display/api.js` file
2025-05-24 14:21:29 +02:00
Tim van der Meij
d90ec29b4d
Merge pull request #19964 from Snuffleupagus/core-catalog-private
Replace semi-private fields/methods with actual private ones in `src/core/catalog.js`
2025-05-24 14:16:06 +02:00
Jonas Jenwald
f11d8b0f67
Merge pull request #19972 from Snuffleupagus/issue-19971
Ignore empty paths when optimizing `constructPath` operations (issue 19971)
2025-05-23 18:34:07 +02:00
Jonas Jenwald
c5449a98e0 Ignore empty paths when optimizing constructPath operations (issue 19971)
Note how we're handling empty paths in [src/display/canvas.js](a8e05d82e2/src/display/canvas.js (L1423-L1428)), hence we need add similar code in the `QueueOptimizer` as well.
2025-05-23 13:59:05 +02:00
Jonas Jenwald
a8e05d82e2
Merge pull request #19961 from nicolo-ribaudo/debugger-contructPath-op
Show the op dispatched by constructPath in the debugger
2025-05-23 13:15:55 +02:00
Jonas Jenwald
d81174d7bc
Merge pull request #19956 from Snuffleupagus/versionInfoHeader
Improve how the PDF.js version/commit information is exposed in the *built* files
2025-05-22 15:24:02 +02:00
calixteman
875233b3c6
Merge pull request #19967 from mozilla/revert-19934-minify
Revert "Minify the js code when building for Firefox (bug 1965003)"
2025-05-22 14:22:49 +02:00
calixteman
32789073a9
Revert "Minify the js code when building for Firefox (bug 1965003)" 2025-05-22 14:08:31 +02:00
Jonas Jenwald
a90e46bdc9 Use nullish coalescing in the Catalog.prototype.numPages getter 2025-05-21 16:47:20 +02:00
Jonas Jenwald
0d2ab3c709 Replace semi-private fields/methods with actual private ones in src/core/catalog.js
Additionally, move a couple of "public" fields out of the class constructor and initialize them directly instead.
2025-05-21 12:10:07 +02:00
Jonas Jenwald
e91b480c09 Move the PDFObjects class to its own file
This isn't directly part of the official API, and having this class in its own file could help avoid future changes (e.g. issue 18148) affecting the size of the `src/display/api.js` file unnecessarily.
2025-05-20 13:47:36 +02:00
Jonas Jenwald
0105237af6 Move a few helper functions/classes out of the src/display/api.js file
Given that this file represents the official API, it's difficult to avoid it becoming fairly large as we add new functionality. However, it also contains a couple of smaller (and internal) helpers that we can move into a new utils-file.

Also, we inline the `DEFAULT_RANGE_CHUNK_SIZE` constant since it's only used *once* and its value has never been changed in over a decade.
2025-05-20 13:47:36 +02:00
Nicolò Ribaudo
0596f03d4e
Show the op dispatched by constructPath in the debugger
The `constructPath` op receives as arguments not only the
information to construct the path, but also the op to apply
the path to (such as "fill", or "stroke").

This commit updates the Stepper tool in the debugger to decode
that op, showing its name rather than just its numeric ID.
2025-05-19 19:33:14 +02:00
calixteman
fc68a9f3ee
Merge pull request #19958 from calixteman/rm_useless_subarray_flate_stream
Don't create a useless subarray when getting image data from a flate stream
2025-05-19 19:29:25 +02:00
Jonas Jenwald
e921533577
Merge pull request #19960 from Snuffleupagus/version-5.3
Bump library version to `5.3`
2025-05-19 18:00:47 +02:00
Jonas Jenwald
6c803e89e6 Bump library version to 5.3 2025-05-19 17:57:28 +02:00
calixteman
f148106cb1
Merge pull request #19957 from calixteman/rm_qcms_subarray
Remove all the useless subarrays when using qcms.
2025-05-19 17:33:52 +02:00
calixteman
72faeeab93
Merge pull request #19959 from calixteman/undefined_worker_port
Fix pdfjsPreloadedWorker when it's undefined
2025-05-19 17:29:18 +02:00
Jonas Jenwald
36b40d959b
Merge pull request #19955 from Snuffleupagus/issue-19954
Support Type3 fonts with an incomplete /FontDescriptor dictionary (issue 19954)
2025-05-19 17:26:46 +02:00
Calixte Denizet
69231e2dbd Fix pdfjsPreloadedWorker when it's undefined 2025-05-19 17:05:37 +02:00
Calixte Denizet
3ecbef516d Don't create a useless subarray when getting image data from a flate stream 2025-05-19 16:48:23 +02:00
Calixte Denizet
782e883a87 Remove all the useless subarrays when using qcms.
It reduces the memory use and the newly added function `getRgbHex` is 4 times faster.
2025-05-19 16:07:57 +02:00
calixteman
2b9f621087
Merge pull request #19953 from calixteman/rm_useless_arrays
[api-minor] Create the css color to use with the canvas in the worker
2025-05-19 16:02:08 +02:00
Jonas Jenwald
c02ea0c681 Simplify how we handle Type3 fonts without a /FontDescriptor dictionary
Part of this is very old code, which we can now simplify a little bit.
2025-05-19 15:26:11 +02:00
Jonas Jenwald
97a42486f5 Improve how the PDF.js version/commit information is exposed in the *built* files
To make it easier to tell which PDF.js version/commit that the *built* files correspond to, they have (since many years) included `pdfjsVersion` and `pdfjsBuild` constants with that information.

As currently implemented this has a few shortcomings:
 - It requires manually adding the code, with its preprocessor statements, in all relevant files.

 - It requires ESLint disable statements, since it's obviously unused code.

 - Being unused, this code is removed in the minified builds.

 - This information would be more appropriate as comments, however Babel discards all comments during building.

 - It would be helpful to have this information at the top of the *built* files, however it's being moved during building.

To address all of these issues, we'll instead utilize Webpack to insert the version/commit information as a comment placed just after the license header.
2025-05-19 15:01:05 +02:00
Calixte Denizet
5789afd3f8 Create the css color to use with the canvas in the worker
It slightly reduces the time spent to draw and the memory used.
2025-05-19 14:52:24 +02:00
Jonas Jenwald
5f5d9dfc28 Support Type3 fonts with an incomplete /FontDescriptor dictionary (issue 19954)
We have a fallback for the common case of Type3 fonts without a /FontDescriptor dictionary, however we also need to handle the case where it's present but lacking the required /FontName entry.
2025-05-19 12:56:14 +02:00
Tim van der Meij
60574fb7e3
Merge pull request #19950 from timvandermeij/intermittent-all-await
Fix missing `await` for asynchronous method calls in the integration tests
2025-05-18 19:12:48 +02:00
Tim van der Meij
393e799e49
Fix missing await for asynchronous method calls in the integration tests
The `Page.evaluate()` and `Mouse.click()` APIs in Puppeteer both return
a promise; see https://pptr.dev/api/puppeteer.page.evaluate and
https://pptr.dev/api/puppeteer.mouse.click, and should therefore be
awaited before proceeding in tests to make sure that the test's behavior
is deterministic and avoid intermittent failures.

The following command was used to find potential places to fix:
`grep -nEr "[^await|return] page\." test/integration/*`
2025-05-18 18:19:46 +02:00
Tim van der Meij
819671d42f
Merge pull request #19949 from timvandermeij/intermittent-stamp-undo
Fix intermittent failure in the stamp editor's undo-related integration tests
2025-05-18 15:17:41 +02:00
Tim van der Meij
6355dd7ded
Fix intermittent failure in the stamp editor's undo-related integration tests
The clipboard, used via the `copyImage` helper function, is a shared
resource, so access to it cannot happen concurrently because it could
result in tests overwriting each other's contents. Most tests using
the clipboard are therefore run sequentially, but only the stamp
editor's undo-related tests weren't, so this commit fixes the issue
by running those tests sequentially too.
2025-05-18 14:36:19 +02:00
Tim van der Meij
f6e4b1cf4a
Merge pull request #19945 from Snuffleupagus/NetworkStream-rm-Node-Error
Remove Node.js-specific checks when using the Fetch API
2025-05-18 12:05:13 +02:00
Tim van der Meij
30bba5f165
Merge pull request #19944 from Snuffleupagus/PDFDataRangeTransport-private-fields
Use private fields in the `PDFDataRangeTransport` class
2025-05-18 12:01:03 +02:00
Jonas Jenwald
a882195e9b Remove Node.js-specific checks when using the Fetch API
Given that Node.js has full support for the Fetch API since version 21, see the "History" data at https://nodejs.org/api/globals.html#fetch, it seems unnecessary for us to manually check for various globals before using it.

Since our primary development target is browsers in general, and Firefox in particular, being able to remove Node.js-specific compatibility code is always helpful.

Note that we still, for now, support Node.js version 20 and if the relevant globals are not available then Errors will instead be thrown from within the `PDFFetchStream` class.
2025-05-18 10:49:02 +02:00
Jonas Jenwald
99b23ea1f6 Use private fields in the PDFDataRangeTransport class 2025-05-18 10:16:46 +02:00
Jonas Jenwald
f72f240699
Merge pull request #19939 from Snuffleupagus/disableWorker-clear-workerPort
Ensure that the viewer clears the `workerPort` option when using "fake" workers
2025-05-18 08:38:48 +02:00
Tim van der Meij
23f269b353
Merge pull request #19942 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-05-17 20:41:48 +02:00
Tim van der Meij
91679ece4b
Merge pull request #19943 from Snuffleupagus/PDFWorker-create
Replace `PDFWorker.fromPort` with a generic `PDFWorker.create` method
2025-05-17 19:12:38 +02:00
Jonas Jenwald
fc697b3602 Utilize private fields and methods more in the PDFWorker class
This replaces, wherever possible, the old semi-private fields and methods with actually private ones.
2025-05-17 18:05:49 +02:00
Jonas Jenwald
ab672f0b77 Replace PDFWorker.fromPort with a generic PDFWorker.create method
This allows us to simply invoke `PDFWorker.create` unconditionally from the `getDocument` function, without having to manually check if a global `workerPort` is available first.
2025-05-17 16:13:41 +02:00
Tim van der Meij
1e4ba0b8bf
Update translations to the most recent versions 2025-05-17 15:58:38 +02:00
Tim van der Meij
d297e44f3f
Update dependencies to the most recent versions 2025-05-17 15:50:54 +02:00
Tim van der Meij
278fc064eb
Merge pull request #19917 from Snuffleupagus/unicorn-59-rule-updates
Add a couple of new `eslint-plugin-unicorn` rules
2025-05-17 13:55:52 +02:00
Jonas Jenwald
b81b9ce00d Add a couple of new eslint-plugin-unicorn rules
The recent `eslint-plugin-unicorn` update added, and replaced, a few rules that seem useful for us; please refer to https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v59.0.0

Note that none of the following rules required any code-changes:
 - Replace `no-array-push-push` with `prefer-single-call`, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-single-call.md

 - Add `no-unnecessary-slice-end`, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unnecessary-slice-end.md

 - Add `no-unnecessary-array-flat-depth`, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unnecessary-array-flat-depth.md

 - Add `no-unnecessary-array-splice-count`, see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unnecessary-array-splice-count.md
2025-05-17 13:49:11 +02:00
Tim van der Meij
b05351ceae
Merge pull request #19937 from studystill/master
chore: remove redundant word in comment
2025-05-17 13:34:39 +02:00
Tim van der Meij
57cbaae8e4
Merge pull request #19916 from Snuffleupagus/prefer-import-meta-properties
Enable the `unicorn/prefer-import-meta-properties` ESLint plugin rule
2025-05-17 13:33:48 +02:00
Jonas Jenwald
eef1e3e87f Ensure that the viewer clears the workerPort option when using "fake" workers
Without this "fake" workers may be ignored in the API, which isn't really what you want when manually providing the `disableWorker=true` hash parameter. (Note that this requires the `pdfBugEnabled` option/preference to be set as well.)

Also, after the changes in PR 19810 we can just load the "fake" worker directly in development mode and don't need to manually assign it to the global scope.
2025-05-17 11:41:33 +02:00
studystill
b585937340 chore: remove redundant word in comment
Signed-off-by: studystill <chenghuiyue@outlook.com>
2025-05-16 15:16:26 +08:00
Jonas Jenwald
13c9995455 Enable the unicorn/prefer-import-meta-properties ESLint plugin rule
Given that we require Node.js versions `>=20.16.0 || >=22.3.0` using this should be fine, based on the "History" data in https://nodejs.org/api/esm.html#importmetadirname respectively https://nodejs.org/api/esm.html#importmetafilename.

Please also see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-import-meta-properties.md
2025-05-16 07:47:08 +02:00
Jonas Jenwald
d97b65378f
Merge pull request #19933 from mozilla/dependabot/npm_and_yarn/undici-6.21.3
Bump undici from 6.21.1 to 6.21.3
2025-05-15 23:28:00 +02:00
calixteman
f4a3e47018
Merge pull request #19935 from calixteman/bug1966721
Use the worker created in the child actor (bug 1966721)
2025-05-15 21:21:06 +02:00
Calixte Denizet
f01b13d332 Use the worker created in the child actor (bug 1966721) 2025-05-15 21:17:44 +02:00
Jonas Jenwald
b3ccc55c1d
Merge pull request #19936 from Snuffleupagus/workerPort-firefox
Allow using the `workerPort` option in Firefox
2025-05-15 21:09:08 +02:00
calixteman
be463f0e0c
Merge pull request #19934 from calixteman/minify
Minify the js code when building for Firefox (bug 1965003)
2025-05-15 20:11:11 +02:00
Jonas Jenwald
e5e9d18289 Allow using the workerPort option in Firefox 2025-05-15 19:30:43 +02:00
Calixte Denizet
8129ccc9a7 Minify the js code when building for Firefox (bug 1965003)
It helps to improve the loading time in the worker by around 25% on Windows, Mac and Android.
2025-05-15 19:01:52 +02:00
dependabot[bot]
64c1e07f22
Bump undici from 6.21.1 to 6.21.3
Bumps [undici](https://github.com/nodejs/undici) from 6.21.1 to 6.21.3.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v6.21.1...v6.21.3)

---
updated-dependencies:
- dependency-name: undici
  dependency-version: 6.21.3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-15 15:23:50 +00:00
Jonas Jenwald
b070a502c3
Merge pull request #19929 from Snuffleupagus/bug-1966086
Prefer the /Metadata, when available, in the document properties dialog (bug 1966086)
2025-05-15 15:54:42 +02:00
Jonas Jenwald
ab89773e49 Prefer the /Metadata, when available, in the document properties dialog (bug 1966086) 2025-05-15 15:12:09 +02:00
Jonas Jenwald
d4d0081ac9
Merge pull request #19923 from nicolo-ribaudo/fix-new-url
Remove unused OpenJPEG wasm fallback logic
2025-05-14 08:11:37 +02:00
Marco Castelluccio
2ed959d75a
Merge pull request #19897 from Snuffleupagus/ci-Node-24
Run CI tests in Node.js version 24
2025-05-14 00:09:06 +02:00
calixteman
a4b5b7c4bb
Merge pull request #19925 from calixteman/bug1962819
[Editor] Keep aspect ratio when rescaling an image before being processed for a signature (bug 1962819)
2025-05-13 20:07:11 +02:00
Nicolò Ribaudo
aebe0cb67f
Remove unused OpenJPEG wasm fallback logic
Emscripten generates code that allows the caller to provide the Wasm
module (thorugh Module.instantiateWasm), with a fallback in case
.instantiateWasm is not provided. We always define instantiateWasm, so
we can hard-code the check and let our dead code elimination logic
remove the unused fallback.

This commit also improved the dead code elimination logic so that if
a function declaration becomes unused as a result of removing dead
code, the function itself is removed.
2025-05-13 19:38:17 +02:00
Calixte Denizet
d6605674dd [Editor] Keep aspect ratio when rescaling an image before being processed for a signature (bug 1962819) 2025-05-13 19:12:17 +02:00
calixteman
2bb8099831
Merge pull request #19924 from calixteman/update_qcms
Update qcms build
2025-05-13 17:49:54 +02:00
Calixte Denizet
09f0af5b83 Update qcms build
It's a follow-up of https://github.com/mozilla/pdf.js.qcms/pull/1.
2025-05-13 16:44:18 +02:00
Jonas Jenwald
5e3d26601e
Merge pull request #19922 from nicolo-ribaudo/vite-ignore-minified
Preserve webpack/vite ignore comments when minifying
2025-05-13 14:54:17 +02:00
Nicolò Ribaudo
ff432c39f9
Preserve webpack/vite ignore comments when minifying
They were removed in the minified build, but the code that made the comments necessary was still there (just minified). This commit updates the Terser config to preserve them.

The default value of Terser's `comments` option is [`/@preserve|@copyright|@lic|@cc_on|^\**!/i`](d528103b7c/lib/output.js (L178C12-L178C53)), however the only type of comment it was actually matching in our case is `@lic`, for the license header in minified files. Thus the new regexp is `/@lic|webpackIgnore|@vite-ignore/i`.
2025-05-13 12:52:29 +02:00
Jonas Jenwald
3f1ecc1ba9
Merge pull request #19915 from Snuffleupagus/OutputScale-capPixels
Reduce duplication when computing the maximum canvas pixels
2025-05-10 21:47:52 +02:00
Jonas Jenwald
d5c534fb83 Reduce duplication when computing the maximum canvas pixels
*This is something that occurred to me when reviewing the latest PDF.js update in mozilla-central.*

Currently we duplicate essentially the same code in both the `OutputScale.prototype.limitCanvas` and `PDFPageDetailView.prototype.update` methods, which seems unnecessary, and to avoid that we introduce a new `OutputScale.capPixels` method that is used to compute the maximum canvas pixels.
2025-05-10 20:12:38 +02:00
calixteman
ca05a0dbfc
Merge pull request #19911 from calixteman/issue19753
Decode appearance keys of checkboxes
2025-05-10 15:01:22 +02:00
Jonas Jenwald
5f4bfe1fb9
Merge pull request #19913 from Snuffleupagus/openAction-array-validate
Improve validation in the `Catalog.prototype.openAction` getter
2025-05-10 14:53:48 +02:00
Jonas Jenwald
f26f984fa0 Improve validation in the Catalog.prototype.openAction getter
When the /OpenAction data is an Array we're currently using it as-is which could theoretically cause problems in corrupt PDF documents, hence we ensure that a "raw" destination is actually valid. (This change is covered by existing unit-tests.)

*Note:* In the Dictionary case we're using the `Catalog.parseDestDictionary` method, which already handles all of the necessary validation.
2025-05-10 11:51:58 +02:00
Calixte Denizet
49a098cb5d Decode appearance keys of checkboxes 2025-05-09 21:46:17 +02:00
calixteman
293506ada7
Merge pull request #19903 from Snuffleupagus/shorten-fieldObjects-getter
Shorten the `PDFDocument.prototype.fieldObjects` getter slightly
2025-05-09 15:49:51 +02:00
calixteman
ff0d9b13a7
Merge pull request #19902 from Snuffleupagus/core-document-shorten
Shorten the code in the `src/core/document.js` file
2025-05-09 15:48:49 +02:00
calixteman
a806f00ea1
Merge pull request #19755 from calixteman/reduce_canvas_size
Add a pref in order to cap the canvas area to a factor of the window one (bug 1958015)
2025-05-09 15:47:42 +02:00
Calixte Denizet
1225c1e39a Add a pref in order to cap the canvas area to a factor of the window one (bug 1958015)
This way it helps to reduce the overall canvas dimensions and make the rendering faster.
The drawback is that when scrolling, the page can be blurry in waiting for the rendering.

The default value is 200% on desktop and will be 100% for GeckoView.
2025-05-09 13:57:16 +02:00
Jonas Jenwald
69595a2919
Merge pull request #19905 from Snuffleupagus/locales-update-repo
Update the Firefox repository used in `external/importL10n/locales.mjs`
2025-05-08 13:57:53 +02:00
Jonas Jenwald
360d287d55 Update l10n files 2025-05-08 13:52:58 +02:00
Jonas Jenwald
feea4007b5 Update the Firefox repository used in external/importL10n/locales.mjs
The https://github.com/mozilla/gecko-dev repository has been deprecated in favour of https://github.com/mozilla-firefox/firefox, hence we should tweak the l10n-update script accordingly.
2025-05-08 13:52:56 +02:00
Jonas Jenwald
1f7581b5c6 Shorten the PDFDocument.prototype.fieldObjects getter slightly
The effect is probably not even measurable, however this patch ever so slightly reduces the asynchronicity in the `fieldObjects` getter. These changes should be safe since:

 - We're inside of the `PDFDocument`-class and the `annotationGlobals`-getter, which will always return a (shadowed) Promise and won't throw `MissingDataException`s, can be accessed directly without going through the `BasePdfManager`-instance.

 - The `acroForm`-dictionary can be accessed through the `annotationGlobals`-data, removing the need to "manually" look it up and thus the need for using `Promise.all` here.

 - We can also lookup the /Fields-data, in the `acroForm`-dictionary, synchronously since the initial `formInfo.hasFields` check guarantees that it's available.
2025-05-07 17:47:09 +02:00
Jonas Jenwald
36fafbc05c Use object destructuring a bit more in the src/core/document.js file 2025-05-07 13:41:50 +02:00
Jonas Jenwald
92b065c87e Replace a number of semi-private fields with actual private ones in src/core/document.js
These are fields that can be moved out of their class constructors, and be initialized directly.
2025-05-07 13:41:44 +02:00
Jonas Jenwald
39803a9f25 Replace a number of semi-private methods with actual private ones in src/core/document.js
There's a few remaining cases that are used with either cached getters or `BasePdfManager.prototype.ensure`-methods, and those cannot be converted.
2025-05-07 13:41:36 +02:00
Jonas Jenwald
0ded85e9b3 Add a Page helper method to create a PartialEvaluator-instance
Currently we repeat the same identical code five times in the `Page`-class when creating a `PartialEvaluator`-instance, which given the number of parameters it needs seems like unnecessary duplication.
2025-05-07 13:41:29 +02:00
Jonas Jenwald
6f052312d6
Merge pull request #19895 from Snuffleupagus/ObjectLoader-improve
Unify method return values in the `ObjectLoader` class, and simplify how the `ObjectLoader` is used
2025-05-06 21:18:09 +02:00
Jonas Jenwald
384a09113c Run CI tests in Node.js version 24
Node.js version 24 was just released, see https://github.com/nodejs/release#release-schedule, hence we should run tests in that version in order to help catch any possible issues as soon as possible.
Also, since version 23 will reach EOL (end-of-life) in less than a month we stop running tests in that version.
2025-05-06 18:43:02 +02:00
Jonas Jenwald
62009ffa70 Simplify how the ObjectLoader is used
The `ObjectLoader.prototype.load` method has a fast-path, which avoids any lookup/parsing if the entire PDF document is already loaded.
However, we still need to create an `ObjectLoader`-instance which seems unnecessary in that case.

Hence we introduce a *static* `ObjectLoader.load` method, which will help avoid creating `ObjectLoader`-instances needlessly and also (slightly) shortens the call-sites.
To ensure that the new method will be used, we extend the `no-restricted-syntax` ESLint rule to "forbid" direct usage of `new ObjectLoader()`.
2025-05-06 15:49:59 +02:00
Jonas Jenwald
ef1ad675c2 Unify method return values in the ObjectLoader class
Given that all the methods are already asynchronous we can just use `await` more throughout this code, rather than having to explicitly return function-calls and `undefined`.
Note also how none of the `ObjectLoader.prototype.load` call-sites use the return value.
2025-05-06 15:43:00 +02:00
calixteman
04400c588f
Merge pull request #19893 from calixteman/issue19517
Downscale jpeg2000 images, if needed, while decoding them
2025-05-05 22:53:49 +02:00
Calixte Denizet
ac925f4f1b Downscale jpeg2000 images, if needed, while decoding them
It fixes #19517.
2025-05-05 22:39:59 +02:00
Tim van der Meij
06f44916c8
Merge pull request #19889 from Snuffleupagus/loadXfaResources
Slightly re-factor how we pre-load fonts and images in XFA documents
2025-05-04 14:28:11 +02:00
Jonas Jenwald
d9548b1c18 Slightly re-factor how we pre-load fonts and images in XFA documents
Rather than "manually" invoking the methods from the `src/core/worker.js` file we introduce a single `PDFDocument`-method that handles this for us, and make the current methods private.
Since this code is only invoked at most *once* per document, and only for XFA documents, we can use `BasePdfManager.prototype.ensureDoc` directly rather than needing a stand-alone method.
2025-05-04 13:44:33 +02:00
Jonas Jenwald
604153957a Reduce duplication when parsing fonts in loadXfaFonts
Currently we repeat virtually the same code when calling the `PartialEvaluator.prototype.handleSetFont` method, which we can avoid by introducing an inline helper function.
2025-05-04 13:42:17 +02:00
Jonas Jenwald
2979e23f3c Ensure that XFAFactory.prototype.isValid returns a boolean value
Considering the name of the method, and how it's actually being used, you'd expect it to return a boolean value.
Given how it's currently being used this inconsistency doesn't cause any issues, however we should still fix this.
2025-05-04 13:42:17 +02:00
Tim van der Meij
5ca57fbd4b
Merge pull request #19885 from Snuffleupagus/loadXfaImages-simplify
Simplify the `loadXfaImages` method and related code
2025-05-04 13:41:06 +02:00
Tim van der Meij
22cb3080ee
Merge pull request #19887 from Snuffleupagus/serializeXfaData-simplify
Simplify the `serializeXfaData` method and related code
2025-05-04 13:38:01 +02:00
Tim van der Meij
bd81d390c7
Merge pull request #19888 from Snuffleupagus/rm-BasePdfManager-catalog-getter
Remove the `BasePdfManager.prototype.catalog` getter
2025-05-04 13:33:16 +02:00
Jonas Jenwald
b3e16800f5 Remove the BasePdfManager.prototype.catalog getter
This is only invoked *once* and it can be trivially replaced by the `ensureCatalog`-method, since the code where it's used is already asynchronous.
2025-05-03 13:40:23 +02:00
Jonas Jenwald
b531720d9c Simplify the serializeXfaData method and related code
Rather than having a dedicated `BasePdfManager`-method for this one call-site we can instead change `PDFDocument.prototype.serializeXfaData` to a non-async method, that we invoke via `BasePdfManager.prototype.ensureDoc`.
2025-05-03 11:20:42 +02:00
Jonas Jenwald
122822a750 Simplify the loadXfaImages method and related code
Currently we create an intermediate `Dict` during parsing, however that seems unnecessary since (note especially the second point):
 - The `NameOrNumberTree.prototype.getAll` method will already resolve any references, as needed, during parsing.
 - The `Catalog.prototype.xfaImages` getter is invoked, via the `BasePdfManager`-instance, such that any `MissingDataException`s are already handled correctly.
2025-05-02 11:53:41 +02:00
calixteman
91bfe12f38
Merge pull request #19883 from gpanakkal/checkbutton-tostyle
Fix arguments in `toStyle` call in `CheckButton`
2025-05-01 22:08:03 +02:00
Gautam Panakkal
7bba3bd4ad Add missing this arg to toStyle in CheckButton.prototype.[$toHTML] 2025-05-01 10:19:28 -07:00
Jonas Jenwald
fc92e4059a
Merge pull request #19884 from Snuffleupagus/issue-19835-2
Allow to, optionally, keep Unicode escape sequences in  `stringToPDFString` (PR 17331 follow-up)
2025-05-01 11:39:13 +02:00
Jonas Jenwald
b629bafd1c Allow to, optionally, keep Unicode escape sequences in stringToPDFString (PR 17331 follow-up)
Currently *some* of the links[1] on page three of the `issue19835.pdf` test-case aren't clickable, since the destination (of the LinkAnnotation) becomes empty.
The reason is that these destinations include the character `\x1b`, which is interpreted as the start of a Unicode escape sequence specifying the language of the string; please refer to section [7.9.2.2 Text String Type](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G6.1957385) in the PDF specification.

Hence it seems that we need a way to optionally disable that behaviour, to avoid a "badly" formatted string from becoming empty (or truncated), at least for cases where we are:
 - Parsing named destinations[2] and URLs.
 - Handling "strings" that are actually /Name-instances.
 - Building a lookup Object/Map based on some PDF data-structure.

*NOTE:* The issue that prompted this patch is obviously related to destinations, however I've gone through the `src/core/` folder and updated various other `stringToPDFString` call-sites that (directly or indirectly) fit the categories listed above.

---
[1] Try clicking on anything on the line containing "Item 7A. Quantitative and Qualitative Disclosures About Market Risk 27".

[2] Unfortunately just skipping `stringToPDFString` in this case would cause other issues, such as the named destination becoming "unusable" in the viewer; see e.g. issues 14847 and 14864.
2025-04-30 20:51:10 +02:00
Jonas Jenwald
254431df1e Avoid extra lookup/parsing when all destinations are already available
Whenever we cannot find a destination we'll fallback to checking all destinations, to account for e.g. out-of-order NameTrees, and in those cases any subsequent destination-lookups can be made a tiny bit more efficient by immediately checking the already cached destinations.
2025-04-30 15:26:00 +02:00
calixteman
b8de9a372f
Merge pull request #19856 from calixteman/bug1936605
Don't update the visible canvas at 60 fps (bug 1936605)
2025-04-29 22:31:02 +02:00
Jonas Jenwald
0922aa9e9d
Merge pull request #19880 from Snuffleupagus/numberToString-assert-number
Assert that `numberToString` is called with a number (issue 19877)
2025-04-29 20:35:32 +02:00
calixteman
262a1f9895
Merge pull request #19881 from calixteman/bug1963407
Fix the bbox when saving a rotated text field (bug 1963407)
2025-04-29 20:33:53 +02:00
Jonas Jenwald
f5faf86180 Assert that numberToString is called with a number (issue 19877)
*NOTE:* Given that this is an *internal* function, used only in the worker-thread, it's not clear to me that this is an entirely "necessary" change.
2025-04-29 20:31:24 +02:00
Calixte Denizet
7a251b206e Fix the bbox when saving a rotated text field (bug 1963407) 2025-04-29 18:49:07 +02:00
Calixte Denizet
ecc56a61e6 Don't update the visible canvas at 60 fps (bug 1936605)
Instead, we update the visible canvas every 500ms.
With large canvas, updating at 60fps lead to a lot gfx transactions and it can take a lot of time.
For example, with wuppertal_2012.pdf on Windows, displaying it at 150% takes around 14 min !!! without
this patch when it takes only around 14 sec with. Even at 30% it helps to improve the performance
by around 20%.
2025-04-29 18:35:21 +02:00
Jonas Jenwald
c1a398d932
Merge pull request #19876 from Snuffleupagus/Node-polyfill-navigator
Add a basic `navigator` polyfill for older Node.js versions
2025-04-29 10:04:19 +02:00
calixteman
2e10ff6dd4
Merge pull request #19855 from 1Jesper1/hotfix/useractivation-response
Add useractivation check for response function
2025-04-28 13:14:51 +02:00
Jonas Jenwald
3d4e8bb17e Add a basic navigator polyfill for older Node.js versions
Modern Node.js versions now include a `navigator` implementation, with a few basic properties, that's actually enough for the PDF.js use-cases; please see https://nodejs.org/api/globals.html#navigator
Unfortunately we still support Node.js version `20`, hence we add a basic polyfill since that allows simplifying the code slightly.
2025-04-28 13:07:12 +02:00
Tim van der Meij
b47b248e15
Merge pull request #19875 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-04-27 14:53:05 +02:00
Tim van der Meij
6d0e8d752d
Bump the stable version in pdfjs.config 2025-04-27 14:49:27 +02:00
Tim van der Meij
4f7761353c
Merge pull request #19873 from timvandermeij/fix-editor-undo-bar-intermittents
Fix the "must work properly when selecting undo by keyboard" integration test
2025-04-27 14:15:34 +02:00
Tim van der Meij
967e34046a
Fix the "must work properly when selecting undo by keyboard" integration test
This integration test fails intermittently because the undo button can
only be activated if focus can be put on it, and that in turn can only
happen if it's visible. The test tried to make sure that the undo bar
is visible, but checking for the absence of the `hidden` attribute is
unfortunately not enough to assert visibility according to Puppeteer
documentation [1]. Moreover, the undo button wasn't checked at all.

To fix the issue we let Puppeteer do the visibility detection for the
undo bar by providing the `visible: true` option to `waitForSelector`
[2]. This is consistent with the other tests that already do this, and
also with the existing code that detects if the undo bar is hidden
(which uses the `hidden: true` option of `waitForSelector`). Moreover,
we wait for the undo button to be present before putting focus on it.

For consistency, and to avoid intermittent failures elsewhere, we mirror
this solution to the other undo bar/button tests of the various editors.

[1] https://pptr.dev/api/puppeteer.elementhandle.isvisible
[2] https://pptr.dev/api/puppeteer.waitforselectoroptions
2025-04-27 14:00:50 +02:00
Tim van der Meij
9e1f93e5eb
Merge pull request #19874 from Snuffleupagus/issue-19871
Always render the Annotation- and XFA-layers with light `color-scheme` (issue 19871)
2025-04-27 11:54:08 +02:00
Jonas Jenwald
0852c42c15 Always render the Annotation- and XFA-layers with light color-scheme (issue 19871)
The intention with PR 19819 was to change how colours are specified for the viewer UI, however it wasn't intended to affect elements in the Annotation- and XFA-layers.
Hence we enforce the light `color-scheme` for these layers, and also make sure to provide a default `color` for PopupAnnotations.
2025-04-26 20:44:07 +02:00
Tim van der Meij
48b7d9f424
Merge pull request #19869 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-04-26 18:01:22 +02:00
Tim van der Meij
b8dd236ae6
Update translations to the most recent versions 2025-04-26 15:52:12 +02:00
Tim van der Meij
cbf61712f9
Update dependencies to the most recent versions 2025-04-26 15:51:20 +02:00
Tim van der Meij
a40bf37184
Merge pull request #19866 from Snuffleupagus/updateUrlHash
Avoid (most) string parsing when removing/replacing the hash property of a URL
2025-04-26 12:21:38 +02:00
Jonas Jenwald
c2d88540b4
Merge pull request #19868 from Snuffleupagus/MathClamp-4
Use the `MathClamp` helper function more in the `web/` folder (PR 19617 follow-up)
2025-04-26 12:07:30 +02:00
Tim van der Meij
6891602e7f
Merge pull request #19858 from luckymore/master
Tweak the Node.js version listed in "engines", to ensure that process.getBuiltinModule is available
2025-04-26 11:45:27 +02:00
Tim van der Meij
2fc325e4f8
Merge pull request #19814 from loganrosen/beginner-bug-readme
Fix beginner bugs link in README
2025-04-26 11:29:41 +02:00
Jonas Jenwald
af3d13c22d Use the MathClamp helper function more in the web/ folder (PR 19617 follow-up)
There's one more spot that I missed in PR 19617.
2025-04-26 11:09:52 +02:00
Jonas Jenwald
abc9522886 Avoid (most) string parsing when removing/replacing the hash property of a URL 2025-04-25 23:13:05 +02:00
calixteman
efc5c3c231
Merge pull request #19862 from calixteman/bug1961423
Fix 'print to pdf' on Mac with a cid font (bug 1961423)
2025-04-25 15:11:55 +02:00
Jonas Jenwald
312c85bfd6
Merge pull request #19815 from Snuffleupagus/getMergedResources-size
Ensure that "local" /Contents stream-dict /Resources aren't empty (PR 19803 follow-up)
2025-04-25 10:46:04 +02:00
Jonas Jenwald
1a5c9e90dd
Merge pull request #19861 from Snuffleupagus/debugger-fix-light-dark-fallout
Fix the debugger CSS when using the dark theme (PR 19819 follow-up)
2025-04-25 10:44:55 +02:00
Jesper
8af06a4c60 Add useractivation check for response function 2025-04-24 22:40:28 +02:00
Calixte Denizet
785991a97c Fix 'print to pdf' on Mac with a cid font (bug 1961423) 2025-04-24 20:19:12 +02:00
Jonas Jenwald
6b76bdac3a Fix the debugger CSS when using the dark theme (PR 19819 follow-up)
Perhaps we should update the debugger CSS to properly account for the light/dark theme, however since that's not UI that end-users ever see we simply force using the light theme for now.
2025-04-24 17:34:29 +02:00
calixteman
91175dc67d
Merge pull request #19854 from calixteman/fix_find_in_tests
Fix errors when running the integration tests
2025-04-24 11:27:03 +02:00
zhangningning
940b4657fc Tweak the Node.js version listed in "engines", to ensure that process.getBuiltinModule is available 2025-04-24 15:04:15 +08:00
Calixte Denizet
8630822a63 Fix errors when running the integration tests
JavaScript error: http://127.0.0.1:42301/build/generic/web/viewer.mjs, line 5822: TypeError: this[#state] is null
JavaScript error: http://127.0.0.1:42301/build/generic/web/viewer.mjs, line 6001: TypeError: can't access property "getPage", this._pdfDocument is null
2025-04-23 23:04:24 +02:00
Jonas Jenwald
de2a44a558
Merge pull request #19849 from Snuffleupagus/issue-19848
Ensure that the /Form XObject /Resources-entry is actually a dictionary (issue 19848)
2025-04-23 16:48:06 +02:00
Jonas Jenwald
01c1c6e60f
Merge pull request #19819 from Snuffleupagus/CSS-light-dark
Use the `light-dark` CSS function in the viewer (issue 17780)
2025-04-23 16:30:03 +02:00
calixteman
627a935baf
Merge pull request #19853 from calixteman/issue19850
Disable userActivation before executing a setTimeout/setInterval callback
2025-04-23 16:11:59 +02:00
Jonas Jenwald
ae1cbc6a9e Use the light-dark CSS function in the viewer (issue 17780)
This removes the need for (most) separate `@media (prefers-color-scheme: dark)` blocks when defining colors values, and also provides a simple way of forcing use of either the light or dark theme.

Please refer to https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark and https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme

*NOTE:* To support this in older browsers, we utilize a [PostCSS plugin](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-light-dark-function).
2025-04-23 15:31:39 +02:00
Calixte Denizet
05a45346a5 Disable userActivation before executing a setTimeout/setInterval callback
Fixes issue #19850.
2025-04-23 15:25:12 +02:00
Jonas Jenwald
64007e777e Ensure that the /Form XObject /Resources-entry is actually a dictionary (issue 19848) 2025-04-23 10:19:20 +02:00
Jonas Jenwald
63e6566597
Merge pull request #19816 from Snuffleupagus/bug-1957401
Add a "supportsPrinting" viewer-option (bug 1957401)
2025-04-22 15:25:20 +02:00
Jonas Jenwald
213d51d7e9
Merge pull request #19823 from Snuffleupagus/rm-duplicate-secondaryToolbar-mask-image
Remove duplicate secondaryToolbar button `mask-image` definitions (PR 18385 follow-up)
2025-04-22 15:14:47 +02:00
Jonas Jenwald
c8ed291cf9
Merge pull request #19836 from Snuffleupagus/issue-19835
Always fallback to checking all destinations, when lookup fails (issue 19835)
2025-04-22 15:14:05 +02:00
Jonas Jenwald
c63c51e016
Merge pull request #19841 from Snuffleupagus/issue-19840
Fix printing of XFA documents, by calling `XfaLayerBuilder.prototype.render` correctly (issue 19840)
2025-04-22 15:12:46 +02:00
Jonas Jenwald
b4626a77a2 Fix printing of XFA documents, by calling XfaLayerBuilder.prototype.render correctly (issue 19840)
When changing the format of various `render`-methods in PR 19365 I forgot to update the code used to print XFA documents, sorry about that.
2025-04-22 09:15:52 +02:00
Jonas Jenwald
adc9eb5a5a Always fallback to checking all destinations, when lookup fails (issue 19835)
In the referenced PDF document the keys, in the /Dests dictionary, need to account for PDFDocEncoding.
To improve destination handling in general we'll now unconditionally fallback to always checking all destinations.
2025-04-20 14:53:10 +02:00
calixteman
d8d3e0abf5
Merge pull request #19829 from calixteman/info_icon
Replace the info icon in the undo bar by the right one (bug 1960523)
2025-04-18 14:16:56 +02:00
Calixte Denizet
75e9f2a0e8 Replace the info icon in the undo bar by the right one (bug 1960523) 2025-04-18 14:13:02 +02:00
Jonas Jenwald
87a143dbbc
Merge pull request #19828 from Snuffleupagus/worker-check-Object-prototype
Check that the `Object.prototype` hasn't been incorrectly extended (PR 11582 follow-up)
2025-04-18 13:59:07 +02:00
Jonas Jenwald
91ba147317 Check that the Object.prototype hasn't been incorrectly extended (PR 11582 follow-up)
This complements, and extends, the existing check of the `Array.prototype` in the worker-thread.
To simplify the implementation we'll now abort immediately, rather than collecting all "bad" properties.
2025-04-18 12:19:29 +02:00
calixteman
4b1875c8c0
Merge pull request #19825 from calixteman/bug1961107
Avoid to create any subarrays when optimizing 'save, transform, constructPath, restore' (bug 1961107)
2025-04-17 19:42:28 +02:00
Calixte Denizet
d7cbda6cb5 Avoid to create any subarrays when optimizing 'save, transform, constructPath, restore' (bug 1961107)
Removing those `subarray`calls helps to improve performance by a factor 6 on Linux and by a factor of 3
on Windows 11.
2025-04-17 19:14:01 +02:00
Jonas Jenwald
f1e20cd668
Merge pull request #19824 from Snuffleupagus/getStructTree-catch-errors
Improve error handling when parsing page-structTrees
2025-04-17 15:21:55 +02:00
Jonas Jenwald
bf553f22da Ensure that the /P-entry is actually a dictionary in StructTreePage.prototype.addNode
This may fix issue 19822, but without a test-case it's simply impossible to know for sure.
2025-04-17 14:01:53 +02:00
Jonas Jenwald
76f23ce3b5 Catch, and ignore, errors during Page.prototype.getStructTree
This way any errors thrown during parsing of the page-structTree will not be forwarded to the viewer.
2025-04-17 13:57:30 +02:00
Jonas Jenwald
8e7060158e Remove duplicate secondaryToolbar button mask-image definitions (PR 18385 follow-up)
It appears that all secondaryToolbar buttons currently have their `mask-image` definitions duplicated, which leads to larger than necessary CSS files.
2025-04-17 10:51:51 +02:00
Jonas Jenwald
97fe7d6a19 Add a "supportsPrinting" viewer-option (bug 1957401)
This will allow us to respect the `print.enabled` Firefox preference, by extending [this method](https://searchfox.org/mozilla-central/rev/56117379696ea0cffb94cd09c14cd022a8c5e4e8/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs#426-453), which will hide the toolbar and secondaryToolbar print-buttons.
2025-04-15 12:43:11 +02:00
Jonas Jenwald
245d9ba925 Ensure that "local" /Contents stream-dict /Resources aren't empty (PR 19803 follow-up)
This is a small, and quite possibly pointless, optimization which ensures that any "local" /Resources aren't empty, to avoid needlessly trying to load and merge dictionaries.
2025-04-14 09:58:15 +02:00
Logan Rosen
ba7c34ff56 Fix beginner bugs link in README 2025-04-13 18:57:56 -04:00
Tim van der Meij
2f7d163dfd
Merge pull request #19812 from timvandermeij/disable-permafail
Remove debug code from the integration tests, and skip the "must check that canvas perfectly fits the page whatever the zoom level" integration test in Chrome
2025-04-13 20:53:58 +02:00
Tim van der Meij
923753a66b
Skip the "must check that canvas perfectly fits the page whatever the zoom level" integration test in Chrome
This is a temporary measure to reduce noise until #19811 is fixed. Note
that this shouldn't be an issue in terms of coverage because we still
run the test in Firefox.
2025-04-13 19:32:39 +02:00
Tim van der Meij
efe4a3455a
Remove debug code from the integration tests
Doing so simplifies the code a bit, and such code is generally not
checked in because it can easily be added locally if needed.
2025-04-13 19:19:13 +02:00
Tim van der Meij
35f85c55bd
Merge pull request #19810 from Snuffleupagus/issue-19808
Update Webpack to version `5.99.5` (issue 19808)
2025-04-13 18:43:19 +02:00
Tim van der Meij
574e4f4ec1
Merge pull request #19809 from timvandermeij/integration-tests-isolate-all-and-random
Run the integration tests in a random order
2025-04-13 18:37:08 +02:00
Jonas Jenwald
6b961c424f Update Webpack to version 5.99.5 (issue 19808)
In Webpack version `5.99.0` the way that `export` statements are handled was changed slightly, with much less boilerplate code being generated, which unfortunately breaks our `tweakWebpackOutput` function that's used to expose the exported properties globally and that e.g. the viewer depends upon.

Given that we were depending on formatting that should most likely be viewed as nothing more than an internal implementation detail in Webpack, we instead work-around this by manually defining the structures that were previously generated.
Obviously this will lead to a tiny bit more manual work in the future, however we don't change the API-surface often enough that it should be a big issue *and* the relevant unit-tests are updated such that it shouldn't be possible to break this.

*NOTE:* In the future we might want to consider no longer using global properties like this, and instead rely only on proper `export`s throughout the code-base.
However changing this would likely be non-trivial (given edge-cases), and it'd be an `api-major` change, so let's just do the minimal amount of work to unblock Webpack updates for now.
2025-04-13 16:48:19 +02:00
Tim van der Meij
938430be5b
Remove workaround from the "must convert input to uppercase" scripting integration test
It's no longer necessary after commit 1c73e52 that caused the document
to be closed properly between tests, and this therefore partly reverts
commit 973b67f.
2025-04-13 15:57:54 +02:00
Tim van der Meij
5f46791887
Run the integration tests in a random order
This commit configures Jasmine to no longer run the tests in a fixed
order, which combined with the previous isolation commits avoids being
able to accidentally introduce dependencies between integration tests.
2025-04-13 15:46:03 +02:00
Tim van der Meij
75b321b000
Isolate the viewer integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:24:15 +02:00
Tim van der Meij
965949c259
Isolate the text layer integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:24:15 +02:00
Tim van der Meij
6308f5eb51
Isolate the text field integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:24:15 +02:00
Tim van der Meij
7c8262ccc9
Isolate the stamp editor integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:24:15 +02:00
Tim van der Meij
44243761a5
Isolate the highlight editor integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:20:27 +02:00
Tim van der Meij
5011d96a62
Isolate the freetext editor integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:20:23 +02:00
Tim van der Meij
f043760b54
Isolate the find integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:20:18 +02:00
Tim van der Meij
179859f54a
Isolate the copy/paste integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:20:14 +02:00
Tim van der Meij
0e9e4ec64f
Isolate the caret browsing integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:20:08 +02:00
Tim van der Meij
a60f9bc612
Isolate the autolinker integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:20:03 +02:00
Tim van der Meij
e1cbba4ded
Isolate the annotation integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:19:59 +02:00
Tim van der Meij
193bebd78a
Isolate the accessibility integration tests
To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
2025-04-13 15:18:19 +02:00
Tim van der Meij
c071f44883
Merge pull request #19807 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-04-13 11:24:15 +02:00
Tim van der Meij
d5dce6bc42
Update translations to the most recent versions 2025-04-12 19:38:22 +02:00
Tim van der Meij
b61d52c6da
Update dependencies to the most recent versions 2025-04-12 19:38:22 +02:00
Tim van der Meij
e06b32c831
Merge pull request #19806 from Snuffleupagus/more-logical-assign
Add more logical assignment in the `src/` folder
2025-04-12 18:51:28 +02:00
Jonas Jenwald
834423b51d Add more logical assignment in the src/ folder
This patch uses nullish coalescing assignment in cases where it's immediately obvious from surrounding code that doing so is safe, and logical OR assignment elsewhere (mostly the changes in XFA code).
2025-04-12 17:28:33 +02:00
Tim van der Meij
5da507f279
Merge pull request #19805 from Snuffleupagus/_xfaStreams-Map
Change `PDFDocument.prototype._xfaStreams` to return a `Map`
2025-04-12 14:00:09 +02:00
Tim van der Meij
5f3e8806fe
Merge pull request #19789 from Snuffleupagus/generic-SignatureStorage-save
Simplify `Object.fromEntries` usage a tiny bit in the `web/generic_signature_storage.js` file
2025-04-12 13:37:40 +02:00
Tim van der Meij
f482232493
Merge pull request #19790 from Snuffleupagus/test-getAnnotationStorage-rm-entries
Simplify the `getAnnotationStorage` integration-test helper function
2025-04-12 13:36:20 +02:00
Jonas Jenwald
1c80412f61 Change PDFDocument.prototype._xfaStreams to return a Map
Using a `Map` rather than an `Object` is a nicer, since it has better support for both iteration and checking if a key exists.
We also change the initial values to be `null`, rather than empty strings, and reduce duplication when creating the `Map`.

*Please note:* Since this is worker-thread code, these changes are "invisible" at the API-level.
2025-04-12 12:47:22 +02:00
Jonas Jenwald
9c6e2e6df0
Merge pull request #19803 from Snuffleupagus/issue-19800
Catch circular references in /Form XObjects (issue 19800)
2025-04-11 17:03:42 +02:00
Jonas Jenwald
1048508dd1 Catch circular references in /Form XObjects (issue 19800)
For simplicity we will abort /Form XObject parsing *immediately* when encountering a circular reference, rather than letting it continue up until some limit (as e.g. PDFium appears to do), which should be fine since there are never any guarantees if/how *corrupt* PDF documents will render.
2025-04-11 16:54:22 +02:00
Jonas Jenwald
7a94fafd30 Prefer /Resources from the /Contents stream-dict, if available
In rare cases /Resources are also found in the /Contents stream-dict, in addition to in the /Page dict, hence we need to prefer those when available; see `issue18894.pdf`.
2025-04-11 16:54:22 +02:00
Jonas Jenwald
53c5a53668
Merge pull request #19804 from Snuffleupagus/issue-19802
Use `adjustWidths` unconditionally for all embedded fonts (issue 19802)
2025-04-11 16:53:20 +02:00
Jonas Jenwald
835a456767 Use adjustWidths unconditionally for all embedded fonts (issue 19802)
Previously we'd only do this for Type1/CFF fonts, see e.g. PR 6736, since the font-program may update the /FontMatrix.
However, it seems that we should do this unconditionally to account for fonts with non-default /FontMatrix-entries in the font-dictionary (which seem to be pretty rare).
2025-04-11 15:01:35 +02:00
calixteman
539a81c7a3
Merge pull request #19797 from calixteman/issue19793
[Editor] Commit the current drawing before switching the current mode
2025-04-10 21:34:51 +02:00
calixteman
1d8af5fe68
Merge pull request #19799 from calixteman/bug1959774
[Editor] Fix the border line of the thickness slider in the signature modal while in HCM (bug 1959774)
2025-04-10 21:32:19 +02:00
Calixte Denizet
61df54c689 [Editor] Commit the current drawing before switching the current mode
It fixes #19793.
2025-04-10 21:31:24 +02:00
Calixte Denizet
88d58f393b [Editor] Fix the border line of the thickness slider in the signature modal while in HCM (bug 1959774) 2025-04-10 19:55:22 +02:00
Jonas Jenwald
220a28933c
Merge pull request #19791 from Snuffleupagus/IndexedCS-round-clamp
Handle non-integer and out-of-range values correctly in Indexed color spaces
2025-04-09 16:29:23 +02:00
Jonas Jenwald
fbc4f4b12a Handle non-integer and out-of-range values correctly in Indexed color spaces
In PDF version 2.0 the handling of Indexed color spaces was clarified as follows:
> The index value should be an integer in the range 0 to hival. If the value is a real number, it shall be rounded to the nearest integer (0.5 values shall be rounded up); if it is outside the range 0 to hival, it shall be adjusted to the nearest value within that range.

Please refer to https://github.com/pdf-association/pdf-differences/tree/main/IndexedColor
2025-04-09 15:31:49 +02:00
Jonas Jenwald
60bf9b133a Simplify the getAnnotationStorage integration-test helper function
As can be seen [at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries#parameters) the `Object.fromEntries` method accepts a `Map` directly, hence using the `Map.prototype.entries` method is superfluous here.
2025-04-09 13:42:22 +02:00
Jonas Jenwald
1d1e6e7b92 Simplify Object.fromEntries usage a tiny bit in the web/generic_signature_storage.js file
As can be seen [at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries#parameters) the `Object.fromEntries` method accepts a `Map` directly, hence using the `Map.prototype.entries` method is superfluous here.
2025-04-09 12:06:40 +02:00
Jonas Jenwald
22657e2b6e
Merge pull request #19778 from Snuffleupagus/replace-getAll
[api-minor] Replace various `getAll` methods with iterators
2025-04-08 17:26:24 +02:00
Jonas Jenwald
12c7c7b0af
Merge pull request #19773 from Snuffleupagus/inline-PDFImage-createRawMask
Inline `PDFImage.createRawMask` in the `PDFImage.createMask` method
2025-04-08 17:19:09 +02:00
Jonas Jenwald
19486952c2
Merge pull request #19781 from Snuffleupagus/mv-IDENTITY_MATRIX
Move the `IDENTITY_MATRIX` constant into `src/core/core_utils.js` (PR 19772 follow-up)
2025-04-08 17:16:31 +02:00
Jonas Jenwald
0e50125a6c
Merge pull request #19788 from Snuffleupagus/no-array-reduce
Enable the `no-array-reduce` ESLint plugin rule
2025-04-08 17:09:44 +02:00
Jonas Jenwald
38d01250f4 Enable the no-array-reduce ESLint plugin rule
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-reduce.md

Note that this still allows "simple" usage of `Array.prototype.reduce`, however most of those cases will be possible to replace with `Math.sumPrecise` once that becomes generally available (currently not supported in Node.js or QuickJS).
2025-04-08 12:21:20 +02:00
Jonas Jenwald
dc3e24a76a Inline PDFImage.createRawMask in the PDFImage.createMask method
After the introduction of `OffscreenCanvas` support we now have *two separate* mask-methods in the `PDFImage` class, and the reason that they were not combined is likely that we need the "raw" bytes when parsing Type3-glyph image masks.
However, that case is easy to support simply by disabling `OffscreenCanvas` usage when parsing Type3-glyphs and that way we're able to reduce some code duplication.

Another slightly strange property of the `PDFImage.createMask` method is that it needs various image-dictionary parameters *manually* provided, which is probably because this is very old code.
That feels slightly unwieldy, and we instead change the method to pass in the image-stream directly and do the necessary data-lookup internally.

A side-effect of this re-factoring is that we now support using the custom `isSingleOpaquePixel` operator in Type3-glyphs, which shouldn't hurt even though it seems extremely unlikely for that to ever happen in Type3-glyphs.
2025-04-08 12:01:50 +02:00
Jonas Jenwald
85e6f3c92b
Merge pull request #19785 from nicolo-ribaudo/chrome-selection-fix
[chrome] Fix text selection with `.markedContent`
2025-04-08 11:57:32 +02:00
Jonas Jenwald
115ea6afa3
Merge pull request #19786 from nicolo-ribaudo/linting-export
Lint against `export [some declaration]`
2025-04-08 11:07:07 +02:00
Nicolò Ribaudo
f654fb1b83
Lint against export [some declaration]
This disallowd the following types of `export` declaration:
- `export class A {}`/`export function A() {}`
- `export default class A {}`/`export default function A() {}`
- `export let A`/`export const A`/`export var A`

While allowing
- `export { A }`
- `export default A`
2025-04-07 17:51:17 +02:00
Nicolò Ribaudo
da5b681b16
[chrome] Fix text selection with .markedContent
The current text layer approach based on absolutely positioned
`<span>` elements by default causes flickering with text selection,
and we have browser-specific workarounds to solve that.

In Chrome, the workaround involves moving the `.endOfContent` element to
right after the last element that contains some selected content. This
works well in simple PDFs, but breaks when we have `span.markedContent`
elements. Given a text layer structure like the following, rendered
as four consecutive lines:
```html
<span class="markedContent">
  <br>
  <span>development enter the construction phase (estimated at around</span>
</span>
<span class="markedContent">
  <br>
  <span>300 MEUR).</span>
</span>
<span class="markedContent">
  <br>
  <span>Kreate's EBITA increased to 2.8 MEUR (Q4'23: 2.7 MEUR) and the</span>
</span>
<span class="markedContent">
  <br>
  <span>margin rose to 3.7% (Q4'23: 3.4%). However, profitability was</span>
</span>
```
when starting to select from inside the first line and dragging down
to the empty space after the second line, Chrome will anchor the
selection at the beginning of either the `<br>` or the `<span>` inside
the last `.markedContent`, depending on whether the selection is in
"per-character mode" (i.e. click and drag) or "per-word mode" (i.e.
double click and drag). This causes us to insert the `.endOfContent`
element in the wrong place (one element too far), which causes one
more line to be selected, which triggers another `"selecctionchange"`
event, which causes us to move `.endOfContent` again, and so on, looping
until when the whole page is selected.

This commit fixes the issue by making sure that when the end of the
selection range points to the _begining_ of an element, we walk back
the dom finding the first non-empty element, and attatch `.endOfContent`
to the end of that.
2025-04-07 17:36:40 +02:00
Jonas Jenwald
d882d0869c Move the IDENTITY_MATRIX constant into src/core/core_utils.js (PR 19772 follow-up)
After the changes in PR 19772 the `IDENTITY_MATRIX` constant is now only used on the worker-thread, which leads to Webpack marking the code as unused in the *built* `pdf.mjs` file; see https://phabricator.services.mozilla.com/D244533#change-8oITAexCvrlQ
2025-04-07 11:40:18 +02:00
Jonas Jenwald
2c593b06e4 [api-minor] Replace various getAll methods with iterators
These `getAll` methods are not used anywhere within the PDF.js code-base, outside of tests, and were mostly added (speculatively) for third-party users.
To still allow access to the same data we instead introduce iterators on these classes, which (slightly) shortens the code and allows us to remove the `objectFromMap` helper function.

A summary of the changes in this patch:
 - Replace the `getAll` methods with iterators in the following classes: `AnnotationStorage`, `Metadata`, and `OptionalContentGroup`.

 - Change, and also re-name, `AnnotationStorage.prototype.setAll` into a test-only method since it's not used elsewhere.

 - Remove the `Metadata.prototype.has` method, since it's only used in tests and can be trivially replaced by calling `Metadata.prototype.get` and checking if the returned value is `null`.
2025-04-06 21:43:16 +02:00
Tim van der Meij
72feb4c256
Merge pull request #19775 from Snuffleupagus/AFSimple_Calculate-MIN-MAX-destructuring
Use Array-destructuring when computing MIN/MAX in `AFSimple_Calculate`
2025-04-06 18:32:37 +02:00
Tim van der Meij
36ece9af8d
Merge pull request #19777 from Snuffleupagus/Node-engines-20.16.0
Tweak the Node.js version listed in "engines", to ensure that `process.getBuiltinModule` is available
2025-04-06 18:25:26 +02:00
Tim van der Meij
082485f094
Merge pull request #19776 from Snuffleupagus/rm-reduce-unit-tests
Remove `Array.prototype.reduce` usage from the unit-tests
2025-04-06 18:24:29 +02:00
Jonas Jenwald
18617eb792 Tweak the Node.js version listed in "engines", to ensure that process.getBuiltinModule is available
In order to use the PDF.js library in Node.js environments the `process.getBuiltinModule` functionality must be available, which was released in [version `20.16.0`](https://nodejs.org/en/blog/release/v20.16.0), however we've seen repeated issues filed by users on older `20.x` versions.
2025-04-06 14:32:36 +02:00
Jonas Jenwald
ec5b5184d3 Remove Array.prototype.reduce usage from the unit-tests
Using `Array.prototype.reduce` often leads to less readable code, and in these cases we can replace it with other Array-methods instead.
2025-04-06 12:12:37 +02:00
Jonas Jenwald
0845552ff9 Use Array-destructuring when computing MIN/MAX in AFSimple_Calculate
This appears to work fine with QuickJS, as evident by the added unit-test, and allows us to remove more `Array.prototype.reduce` usage.
2025-04-06 11:44:08 +02:00
calixteman
6cc37c8415
Merge pull request #19772 from calixteman/settextmatrix
Avoid to create an array when setting the text matrix
2025-04-05 21:59:30 +02:00
Calixte Denizet
4c63905a18 Avoid to create an array when setting the text matrix 2025-04-05 20:45:26 +02:00
Jonas Jenwald
9217d253aa
Merge pull request #19771 from Snuffleupagus/canvas-shorter-CanvasExtraState
Change how (most) fields are initialized in the `CanvasExtraState` class
2025-04-05 18:46:24 +02:00
Jonas Jenwald
7cfb1be650
Merge pull request #19758 from Snuffleupagus/OperatorList-setOptions
Initialize the `isOffscreenCanvasSupported` option, in the `OperatorList` class, once per document
2025-04-05 18:45:55 +02:00
Jonas Jenwald
a70f42339e
Merge pull request #19756 from Snuffleupagus/canvas-unconditional-ctx-filter
Use `ctx.filter` unconditionally in the `src/display/canvas.js` file
2025-04-05 18:45:19 +02:00
Jonas Jenwald
010b6ad886 Change how (most) fields are initialized in the CanvasExtraState class
The majority of the class fields don't depend on any parameters, hence we can re-factor and shorten by this using modern JavaScript features.
2025-04-05 15:03:06 +02:00
Jonas Jenwald
624d8a418e Remove "unnecessary" inline function names in the src/display/canvas.js file
This is ever so slightly shorter, which cannot hurt.
2025-04-05 14:59:04 +02:00
calixteman
7eef7dfc78
Merge pull request #19763 from calixteman/simplify_updaterect
Replace UpdateRectMinMax by getAxialAlignedBoundingBox
2025-04-04 21:33:05 +02:00
Jonas Jenwald
a6934a4dd5
Merge pull request #19768 from Snuffleupagus/writer-infoMap
Pass the /Info-strings as a `Map` to the `src/core/writer.js` code
2025-04-04 20:53:55 +02:00
Calixte Denizet
e7a951547d Replace UpdateRectMinMax by getAxialAlignedBoundingBox
and don't use array destructuring because it induces a memory and perf penalties.
2025-04-04 19:57:55 +02:00
Jonas Jenwald
dad6febc39 Pass the /Info-strings as a Map to the src/core/writer.js code
We want to iterate through the data in the `computeMD5` function, and `Map`s have "nicer" support for that than generic objects.
(Somewhat recently `Map` performance was improved in Firefox, however this also isn't really performance sensitive code.)
2025-04-04 13:36:13 +02:00
Jonas Jenwald
0bde69c7bf
Merge pull request #19767 from Snuffleupagus/issue-19761
Attempt to get bundlers to leave Emscripten Compiler generated `URL`s alone (issue 19761)
2025-04-04 12:30:15 +02:00
Jonas Jenwald
20e06c4bb5 Attempt to get bundlers to leave Emscripten Compiler generated URLs alone (issue 19761)
Note that we load all wasm-files manually, however the Emscripten Compiler (emcc) unfortunately generates `URL`s for fallback wasm-file loading.
In the PDF.js build-scripts we work-around that by using suitable Webpack-options, however that apparently doesn't work when third-party users re-bundle our code and we thus try to work-around this by adding "ignore comments" to these `URL`s (similar to how we handle `import`-statements).
2025-04-04 11:45:54 +02:00
Jonas Jenwald
bd06061e85
Merge pull request #19766 from Snuffleupagus/version-5.2
Bump library version to `5.2`
2025-04-04 08:58:16 +02:00
Jonas Jenwald
bd418de6b0 Bump library version to 5.2 2025-04-04 08:54:06 +02:00
Jonas Jenwald
16c876569f
Merge pull request #19760 from Snuffleupagus/OperatorList-transfers-bitmap
Also transfer `ImageBitmap`s for image masks and inline images
2025-04-03 20:10:27 +02:00
Jonas Jenwald
8c5fb7979f Also transfer ImageBitmaps for image masks and inline images
Currently we're only transferring TypedArrays, however there's no reason (as far as I can tell) to not also transfer `ImageBitmap`s in these cases.
2025-04-03 18:50:39 +02:00
calixteman
ff2d95a9b6
Merge pull request #19752 from calixteman/simplify_updateRectMinMax
Simplify updateRectMinMax in order to use slightly less memory
2025-04-03 18:25:30 +02:00
Calixte Denizet
41bed561f0 Simplify updateRectMinMax in order to use slightly less memory 2025-04-03 17:06:58 +02:00
Jonas Jenwald
4a6c47489e Initialize the isOffscreenCanvasSupported option, in the OperatorList class, once per document
Currently we're setting this option for each small inline image, which seems unnecessary since it should suffice to do that once per document.
2025-04-03 14:00:07 +02:00
Jonas Jenwald
0c78b46184 Use ctx.filter unconditionally in the src/display/canvas.js file
It seems that the `@napi-rs/canvas` dependency has *basic* canvas-filter support, whereas the "old" `canvas` dependency didn't, hence we no longer need the Node.js-specific checks in the `src/display/canvas.js` file.

Note that I've successfully tested the [`pdf2png` example](https://github.com/mozilla/pdf.js/tree/master/examples/node/pdf2png) with this patch applied and things appear to work as before.
2025-04-03 12:30:29 +02:00
Jonas Jenwald
a45f961a1c
Merge pull request #19751 from Snuffleupagus/applyTransform-in-place
Change `Util.applyTransform` to use the point-argument as an in/out parameter
2025-04-02 20:47:21 +02:00
calixteman
b7437376f1
Merge pull request #19732 from calixteman/rm_useless_beginpath
Remove few useless beginPaths
2025-04-02 13:46:05 +02:00
Jonas Jenwald
4262603b06 Re-name the Util.applyTransformToBezierInPlace method
Given that all `Util.apply...` methods are now using in/out parameters, we can slightly shorten the name of this one.
2025-04-01 23:03:50 +02:00
Jonas Jenwald
c852e877d8 Change Util.applyInverseTransform to use the point-argument as an in/out parameter
This will help reduce the total number of Array allocations, which cannot hurt.
2025-04-01 23:03:44 +02:00
Jonas Jenwald
fa643bb22f Change Util.applyTransform to use the point-argument as an in/out parameter
This will help reduce the total number of Array allocations, which cannot hurt, and also allows us to remove the `Util.applyTransformInPlace` method.
2025-04-01 23:03:36 +02:00
Jonas Jenwald
e5fbf52405
Merge pull request #19736 from Snuffleupagus/compileType3Glyph-worker
[api-minor] Move Type3-glyph compilation to the worker-thread
2025-04-01 19:40:30 +02:00
Jonas Jenwald
b33522a208
Merge pull request #19746 from Snuffleupagus/evaluator-img-cache-tweaks
Reduce some code duplication when handling globally cached images
2025-04-01 19:15:10 +02:00
calixteman
25693dc0ee
Merge pull request #19712 from calixteman/optimize_save_construct
Optimize save-transform-constructPath-restore
2025-04-01 18:20:59 +02:00
Calixte Denizet
a35443ff45 Remove few useless beginPaths.
The ctx current path is no more changed since we use some Path2D when we want to fill/stroke them.
It makes calling ctx.beginPath useless.
2025-04-01 16:02:38 +02:00
Jonas Jenwald
9cd5a9658a [api-minor] Move Type3-glyph compilation to the worker-thread
After PR 19731 the format of compiled Type3-glyphs is now simple enough that the compilation can be moved to the worker-thread, without introducing any significant additional complexity.
This allows us to, ever so slightly, simplify the implementation in `src/display/canvas.js` since the Type3 operatorLists will now directly include standard path-rendering operators (using the format introduced in PR 19689).

As part of these changes we also stop caching Type3 image masks since: we've not come across any cases where that actually helps, they're usually fairly small, and it simplifies the code.

Note that one "negative" change introduced in this patch is that we'll now compile Type3-glyphs *eagerly*, whereas previously we'd only do that lazily upon their first use.
However, this doesn't seem to impact performance in any noticeable way since the compilation is fast enough (way below 1 ms/glyph in my testing) and Type3-fonts are also limited to just 256 glyphs. Also, many (or most?) Type3-fonts don't even use image masks and are thus not affected by these changes.
2025-04-01 09:09:00 +02:00
calixteman
a4950c0b71
Merge pull request #19721 from calixteman/simplif_singular_decomposition
Simplify singularValueDecompose2dScale in order to make it using less memory
2025-03-31 12:53:17 +02:00
Jonas Jenwald
213830f44f Use, and re-name, the addLocallyCachedImageOps helper for global images too
This avoids having to "manually" set the image operators for globally cached images.
2025-03-31 10:57:04 +02:00
Jonas Jenwald
e0e59eaf01 Define the global cache-data once in buildPaintImageXObject
Currently we duplicate the same identical code three times, which seems both unnecessary and error prone.
2025-03-31 10:29:29 +02:00
Calixte Denizet
6e9fbd9420 Simplify singularValueDecompose2dScale in order to make it using less memory
In using the Firefox profiler (with JS allocations tracking) and wuppertal.pdf, I noticed
we were using a bit too much memory for a function which is supposed to just compute 2 numbers.
The memory used by itself isn't so important but having a too much objects lead to waste some time
to gc them.

So this patch aims to simplify it a bit.
2025-03-31 10:28:01 +02:00
Jonas Jenwald
e8b4ed2fde
Merge pull request #19743 from timvandermeij/integration-tests-freetext-isolate-part-3
Isolate the "basic operations" freetext editor integration tests
2025-03-31 09:27:26 +02:00
Tim van der Meij
ed08a6a988
Isolate the "basic operations" freetext editor integration tests
This commit reduces the number of freetext editor integration test suite
failures, in full isolation, from 5 to 0 by fixing the following issues
in the "basic operations" block:

- Most tests relied on the first test to enable freetext editing mode.
  For isolation we now do it explicitly in all tests.
- Most tests relied on the other tests having created editors. For
  isolation we now create the editors explicitly in the tests themselves.
- Most tests relied on previous tests for the editor numbering. For
  isolation we change the editor numbering to the one after initial
  document load. Since we can't have state (editors) from a previous
  test anymore we can remove various `clearAll` calls as well.
2025-03-30 18:52:19 +02:00
Tim van der Meij
f32254dbd4
Merge pull request #19742 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-03-30 18:04:07 +02:00
Tim van der Meij
040e9c7be4
Update translations to the most recent versions 2025-03-30 15:46:00 +02:00
Tim van der Meij
bb8fb74b72
Upgrade eslint-plugin-unicorn to version 58.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v58.0.0
doesn't indicate any breaking changes that should impact us.
2025-03-30 15:44:51 +02:00
Tim van der Meij
a6db2d9f47
Update dependencies to the most recent versions 2025-03-30 15:43:55 +02:00
Tim van der Meij
221956d8ba
Merge pull request #19741 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-03-30 15:33:32 +02:00
Tim van der Meij
7a1ff7f36c
Bump the stable version in pdfjs.config 2025-03-30 15:30:08 +02:00
Tim van der Meij
45cbe8bb0d
Merge pull request #19735 from Snuffleupagus/Type3WordSpacing
Apply char/word-spacing correctly for missing Type3-glyphs
2025-03-30 12:07:54 +02:00
Tim van der Meij
1ccc82beff
Merge pull request #19733 from Snuffleupagus/import-vite-ignore
[api-minor] Attempt to improve support for using the PDF.js builds with Vite
2025-03-30 11:58:20 +02:00
Tim van der Meij
97bf09b795
Merge pull request #19739 from Snuffleupagus/buildPaintImageXObject-fn-OPS
Reduce duplication when specifying the fn-operations in `buildPaintImageXObject`
2025-03-30 11:55:53 +02:00
Tim van der Meij
cb818ce0d3
Merge pull request #19720 from Snuffleupagus/_initializeViewerComponents-shorten
Shorten the `PDFViewerApplication._initializeViewerComponents` method
2025-03-30 11:52:19 +02:00
Tim van der Meij
9d237b9f96
Merge pull request #19737 from Snuffleupagus/TilingPattern-color-param
Simplify handling of the color-parameter in `TilingPattern` (PR 4824 follow-up)
2025-03-30 11:49:11 +02:00
Tim van der Meij
9e58bac43c
Merge pull request #19740 from Snuffleupagus/integration-test-properly-spelling
Spell "properly" in viewer integration-test names
2025-03-30 11:48:12 +02:00
Jonas Jenwald
5b7b94c078 Spell "properly" in viewer integration-test names 2025-03-29 16:35:22 +01:00
Jonas Jenwald
8e3a3387e0 Reduce duplication when specifying the fn-operations in buildPaintImageXObject
Currently we explicitly specify the fn-`OPS` both when adding entries to the operatorList and to the image-caches, and by using a temporary variable we can reduce a bit of duplication (similar to the existing args-handling).
2025-03-29 15:56:46 +01:00
Jonas Jenwald
09118670ca Simplify handling of the color-parameter in TilingPattern (PR 4824 follow-up)
The color-parameter is already available through `IR` (i.e. the internal representation), and after the changes in PR 4824 (which landed in 2014) we no longer need any special handling for it.
2025-03-29 13:02:13 +01:00
Jonas Jenwald
667645798f Apply char/word-spacing correctly for missing Type3-glyphs
In the included PDF document the Type3-font doesn't contain any glyph definition for "space", despite that character being referenced in the /Contents stream.
While missing Type3-glyphs obviously cannot be rendered, we still need to update the current canvas position such that any char/word-spacing is correctly applied.

The test-case was found at https://github.com/pdf-association/pdf-differences/tree/main/Type3WordSpacing
2025-03-29 00:12:08 +01:00
calixteman
dfa553dc11
Merge pull request #19734 from calixteman/bug1952563
[Editor] Add a border to the undo button in the snackbar in order to make a contrast (bug 1952563)
2025-03-28 22:03:22 +01:00
Calixte Denizet
bb2ef20420 [Editor] Add a border to the undo button in the snackbar in order to make a contrast (bug 1952563) 2025-03-28 21:42:57 +01:00
Jonas Jenwald
8bcc3664c9 [api-minor] Attempt to improve support for using the PDF.js builds with Vite
Similar to Webpack there's apparently other bundlers that will not leave `import`-calls alone unless magic comments are used.
Hence we extend the builder to also append `/* @vite-ignore */` comments to `import`-calls, in order to attempt to improve support for using the PDF.js builds together with Vite.

This patch also renames `__non_webpack_import__` to `__raw_import__` since the functionality is no longer bundler-specific.

***PLEASE NOTE:*** This patch is provided as-is, and it does *not* mean that the PDF.js project can/will provide official support for Vite.
2025-03-28 16:34:00 +01:00
Jonas Jenwald
34136d7775
Merge pull request #19731 from Snuffleupagus/Type3-Path2D-pre-transform
Pre-apply the transform when building the `Path2D` objects for Type3-fonts
2025-03-28 16:29:18 +01:00
Jonas Jenwald
f577271908 Simplify the compileType3Glyph function to just return the Path2D objects
Originally this function would "manually" invoke the rendering commands for Type3-glyphs, however that was changed some time ago:
 - Initial `Path2D` support was added in PR 14858, but the old code kept for Node.js compatibility.
 - Since PR 15951 we've been using a `Path2D` polyfill in Node.js environments.

Hence, after the previous commit, we can further simplify this function by *directly* returning/using the `Path2D` object when rendering Type3-glyphs; see also https://github.com/mozilla/pdf.js/pull/19731#discussion_r2018712695
While this won't improve performance significantly, when compared to the introduction of `Path2D`, it definately cannot hurt.
2025-03-28 15:20:43 +01:00
Jonas Jenwald
852b7e407a Pre-apply the transform when building the Path2D objects for Type3-fonts
Rather than updating the transform every time that we're painting a Type3-glyph, we can instead just compute the "final" coordinates during building of the `Path2D` objects.
2025-03-28 13:28:25 +01:00
calixteman
31ec357282
Merge pull request #19730 from calixteman/update_fluent
Update @fluent/dom to 0.10.1
2025-03-28 11:13:53 +01:00
Calixte Denizet
6ff1626cf3 Update @fluent/dom to 0.10.1 2025-03-28 09:39:02 +01:00
calixteman
3da8901f26
Merge pull request #19728 from calixteman/bug1956513
[Editor] Set an aria-description for an added signature (bug 1956513)
2025-03-27 21:31:02 +01:00
Jonas Jenwald
f23087ca7e
Merge pull request #19726 from Snuffleupagus/_setDefaultAppearance-bbox
Use `Util.rectBoundingBox` more in the annotation code (PR 19713 follow-up)
2025-03-27 21:30:01 +01:00
Calixte Denizet
7d8c64b2ff [Editor] Set an aria-description for an added signature (bug 1956513)
NVDA behaves differently depending if the user is hovering or focusing an added signature.
An aria-description is read in both cases while an aria-label is not.
2025-03-27 18:14:06 +01:00
Jonas Jenwald
29788eb0b8 Use Util.rectBoundingBox more in the annotation code (PR 19713 follow-up)
By changing the return format of the various `pointsCallback` functions we can use the `Util.rectBoundingBox` helper in the `MarkupAnnotation.prototype._setDefaultAppearance` method as well, thus shortening the code slightly.
2025-03-27 13:46:36 +01:00
calixteman
2da54ffb59
Merge pull request #19725 from calixteman/bug1956114
[Editor] in the signature UI, disable the description input if there is no signature (bug 1956114)
2025-03-27 13:36:32 +01:00
Calixte Denizet
62df96894d [Editor] in the signature UI, disable the description input if there is no signature (bug 1956114) 2025-03-26 23:02:13 +01:00
calixteman
828398f60f
Merge pull request #19722 from calixteman/bug1956110
[Editor] Fix the border color of a tab panel in HCM (bug 1956110)
2025-03-26 18:54:19 +01:00
Calixte Denizet
5c3c003931 [Editor] Fix the border color of a tab panel in HCM (bug 1956110)
And fix the color of the signature itself when its a drawing or if it comes
from an image.
2025-03-26 14:56:24 +01:00
Jonas Jenwald
c6b9338f6f
Merge pull request #19719 from Snuffleupagus/structTree-xref
Pass the `XRef`-instance explicitly to the `StructTreeRoot` class, and simplify the `StructElementNode.prototype.role` getter
2025-03-25 19:41:20 +01:00
Jonas Jenwald
74ab29544e
Merge pull request #19701 from Snuffleupagus/enableAutoLinking-true
[api-minor] Enable `enableAutoLinking` by default
2025-03-25 18:18:08 +01:00
Jonas Jenwald
22107145df
Merge pull request #19691 from Snuffleupagus/xfa-template-rm-reduce
Remove `Array.prototype.reduce` usage from the `src/core/xfa/template.js` file
2025-03-25 18:17:12 +01:00
Jonas Jenwald
532406427b Simplify the StructElementNode.prototype.role getter a tiny bit
Given that the `roleMap` only contains `Name`-strings, the lookup can be simplified thanks to modern JavaScript features.
2025-03-25 18:04:56 +01:00
Jonas Jenwald
3c93d63731 Pass the XRef-instance explicitly to the StructTreeRoot class
This avoids the current situation where we're accessing it through various dictionaries, since that's a somewhat brittle solution given that in the general case a `Dict`-instance may not have the `xref`-field set (see e.g. the empty-Dict).
2025-03-25 18:04:51 +01:00
calixteman
d4c7aaa9d3
Merge pull request #19702 from calixteman/issue19694
In the struct tree a kid can be a reference to an MCID entry (issue #19694)
2025-03-25 18:02:46 +01:00
Calixte Denizet
6146e5fee7 Optimize save-transform-constructPath-restore
The 4 operations can be replaced with just one in applying the transform to the points coordinates.
2025-03-25 15:31:45 +01:00
Calixte Denizet
dee80cb082 In the struct tree a kid can be a reference to an MCID entry (issue #19694) 2025-03-25 15:01:52 +01:00
Jonas Jenwald
8f7d6f4118 Shorten the PDFViewerApplication._initializeViewerComponents method
By tweaking a few local variable names we can shorten various viewer-component initialization code, and we can also reduce some duplication when assigning components to the `PDFViewerApplication`-scope.
2025-03-25 12:51:40 +01:00
calixteman
a8c77633a1
Merge pull request #19717 from calixteman/issue16287
Don't overwrite the global alpha when switching to smask mode (bug 1764587)
2025-03-25 10:08:36 +01:00
Calixte Denizet
1d0227af62 Don't overwrite the global alpha when switching to smask mode
It fixes #issue16287.
2025-03-24 21:35:09 +01:00
calixteman
b57da32d70
Merge pull request #19716 from calixteman/issue16742
Take into account the group bbox
2025-03-24 16:57:34 +01:00
Jonas Jenwald
9456b88f6b Remove Array.prototype.reduce usage from the src/core/xfa/template.js file
Using `Array.prototype.reduce` often leads to less readable code, and in these cases we can replace that with other Array-methods instead.
2025-03-24 16:40:41 +01:00
Jonas Jenwald
fceaab8864
Merge pull request #19713 from Snuffleupagus/Util-minMax-methods
Add new bounding-box helpers in `Util` to reduce code duplication
2025-03-24 16:39:05 +01:00
Jonas Jenwald
d8d4f2a850
Merge pull request #19714 from Snuffleupagus/MathClamp-3
Use the `MathClamp` helper function even more (PR 19617 follow-up)
2025-03-24 16:35:07 +01:00
Calixte Denizet
a3c31904f1 Take into account the group bbox
It fixes #16742.
2025-03-24 15:07:31 +01:00
calixteman
bcba053a5e
Merge pull request #19715 from calixteman/issue18529
Take into account the path and the line width when consuming a stroked path
2025-03-24 14:41:29 +01:00
Jonas Jenwald
b85f0903ca Add new bounding-box helpers in Util to reduce code duplication
Currently we have a `Util`-helper for computing the bounding-box of a Bézier curve, however for simple points and rectangles we repeat virtually identical code in many spots throughout the code-base.

 - Introduce new `Util.pointBoundingBox` and `Util.rectBoundingBox` helpers.

 - Remove the "fallback" from `Util.bezierBoundingBox` and only support passing in a `minMax`-array, since there's only a single call-site using the other format and it could be easily updated.
2025-03-23 19:20:02 +01:00
Calixte Denizet
2369e2d84f Take into account the path and the line width when consuming a stroked path 2025-03-23 18:08:06 +01:00
Jonas Jenwald
4547e582ff Use the MathClamp helper function even more (PR 19617 follow-up)
There's a few more spots that I accidentally missed in PR 19617.
2025-03-23 17:11:06 +01:00
Tim van der Meij
19b4adac03
Merge pull request #19711 from timvandermeij/integration-tests-freetext-isolate-part-2
Isolate the "create editor with keyboard" freetext editor integration tests
2025-03-23 15:06:39 +01:00
calixteman
7c5695f5c6
Merge pull request #19708 from calixteman/fix_save_smask_mode
Fix save/restore while in smask mode
2025-03-23 14:45:09 +01:00
Tim van der Meij
d01913e62e
Isolate the "create editor with keyboard" freetext editor integration tests
This commit reduces the number of freetext editor integration test suite
failures, in full isolation, from 6 to 5 by fixing the following issues
in the "create editor with keyboard" block:

- The second test relied on the first test to enable freetext editing
  mode and put focus on the page (annotation layer). For isolation we
  now do that explicitly in the second test.
- The second test relied on the first test for the editor numbering. For
  isolation we change the editor numbering to the one after initial
  document load.

Moreover, the test names have been updated to clarify with scenario is
being tested, which came up during comparison of the changes against
commit ea5eafa to make sure that we are still testing the originally
intended scenarios (confirmed by disabling the relevant code from the
commit per scenario and noticing the corresponding test failing).
2025-03-23 14:28:03 +01:00
Tim van der Meij
94b2c86251
Merge pull request #19704 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-03-23 13:43:28 +01:00
Jonas Jenwald
c7c08bbd07
Merge pull request #19710 from Snuffleupagus/Math-sumPrecise
Introduce `Math.sumPrecise` usage in the code-base
2025-03-23 13:34:28 +01:00
Jonas Jenwald
e73224ded7 Introduce Math.sumPrecise usage in the code-base
This is a new JavaScript feature that makes it easy to compute the sum of list of values; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise

This allows us to remove most cases of `Array.prototype.reduce`, which helps improve readability since that (in my opinion) often isn't the most intuitive code.
2025-03-23 13:03:56 +01:00
Tim van der Meij
7352d1d683
Update translations to the most recent versions 2025-03-23 12:46:06 +01:00
Tim van der Meij
4522c6c071
Update dependencies to the most recent versions 2025-03-23 12:46:02 +01:00
Tim van der Meij
80d4d7058f
Merge pull request #19706 from timvandermeij/integration-tests-freetext-isolate-part-1
Isolate the "move editor with arrows" freetext editor integration tests
2025-03-23 12:01:30 +01:00
Calixte Denizet
c275c72977 Fix save/restore while in smask mode
The rendering bug with issue17779.pdf is due to the fact that we call save on the suspended ctx
but not on the the current ctx. So each time we've something like save/transform/restore then
the transform not "removed" when restoring.
So this patch just apply the save/restore operations to ctx which are mirrored on the suspended one.
2025-03-22 23:26:51 +01:00
calixteman
d009e4b3a7
Merge pull request #19689 from calixteman/use_path2d
[api-minor] Use a Path2D when doing a path operation in the canvas (bug 1946953)
2025-03-22 21:46:27 +01:00
Tim van der Meij
440d519326
Isolate the "move editor with arrows" freetext editor integration tests
This commit reduces the number of freetext editor integration test suite
failures, in full isolation, from 8 to 6 by fixing the following issues
in the "move editor with arrows" block:

- The second and third test relied on the first test to enable freetext
  editing mode. For isolation we now do it explicitly in both tests.
- The second test relied on the first test having created an editor. For
  isolation we now create the editor explicitly in the second test.
- The third test relied on the previous tests for the editor numbering.
  For isolation we change the editor numbering to the one after initial
  document load. Since we can't have state (editors) from a previous
  test anymore we can remove the `clearAll` call as well.
2025-03-22 20:46:21 +01:00
Tim van der Meij
72212a892b
Merge pull request #19705 from timvandermeij/integration-tests-scripting-isolate
Isolate the scripting integration tests
2025-03-22 20:38:50 +01:00
Calixte Denizet
be1f5671bb [api-minor] Use a Path2D when doing a path operation in the canvas (bug 1946953)
With this patch, all the paths components are collected in the worker until a path
operation is met (i.e., stroke, fill, ...).
Then in the canvas a Path2D is created and will replace the path data transfered from the worker,
this way when rescaling, the Path2D can be reused.
In term of performances, using Path2D is very slightly improving speed when scaling the canvas.
2025-03-22 20:35:24 +01:00
Tim van der Meij
1c73e526e0
Isolate the scripting integration tests
To avoid being able to introduce dependencies between tests, and to
bring existing dependencies to the surface, this commit makes sure that
we close the document between tests so that we can't accidentally rely
on state set by a previous test. This prevents multiple tests from
failing if one of them fails and makes debugging easier by being able to
run each test on their own independent of other tests.

This commit, combined with the previous ones, is enough to make the
scripting integration test suite pass consistently if random mode in
Jasmine is enabled, proving that the tests are fully isolated now.
2025-03-22 18:31:23 +01:00
Tim van der Meij
0f3692a621
Remove the dependency between the order-dependent scripting integration tests
The integration tests are order-dependent because they rely on input
field state set by a previous test. This commit fixes the issue by
updating the values to match the initial state of the document, which
makes sure that we don't build upon values from previous tests while
still testing the intended logic in the individual tests like before.
2025-03-22 18:31:23 +01:00
Tim van der Meij
334d681359
Refactor the order-dependent scripting integration tests
By checking for the expected value directly we can shorten the code, and
it simplifies removing the dependencies between the tests in the next
commit (by having fewer places to change). Note that this follows the
same pattern as PRs #19192, #19001 and #18399 and also helps to remove
any further possibilities for intermittent failures.
2025-03-22 18:31:10 +01:00
Tim van der Meij
11e89b74d9
Merge pull request #19696 from Snuffleupagus/issue-19695
Extend `getSupplementalGlyphMapForCalibri` with Pound-sign (issue 19695)
2025-03-22 13:21:07 +01:00
Tim van der Meij
9023395550
Merge pull request #19681 from Snuffleupagus/AbortSignal-any-basic-polyfill
[api-minor] Add a basic `AbortSignal.any` polyfill in PDF.js `legacy` builds
2025-03-22 13:20:18 +01:00
Tim van der Meij
7f70835830
Merge pull request #19703 from Snuffleupagus/bidi-rm-setValues
Replace the `setValues` function with `Array.prototype.fill()` in the `src/core/bidi.js` file
2025-03-22 13:13:42 +01:00
Jonas Jenwald
fe19d9666f Replace the setValues function with Array.prototype.fill() in the src/core/bidi.js file
This code is originally from 2012, see PR 1218, and the Array-method wasn't available until Firefox 31 (released on 2014-07-22).
2025-03-21 23:00:38 +01:00
Jonas Jenwald
abcddb51e0 [api-minor] Enable enableAutoLinking by default
It's already enabled by default in Firefox, and since there's no open issues regarding auto-linking I suppose that we can attempt to enable it unconditionally.
2025-03-21 11:49:03 +01:00
Jonas Jenwald
8f4c0169a0
Merge pull request #19692 from Snuffleupagus/writer-improve
Improve the implementation in `src/core/writer.js` a little bit
2025-03-20 21:43:21 +01:00
Jonas Jenwald
50eb97afb3 Improve the implementation in src/core/writer.js a little bit
- Let the `writeString` helper function return the new offset, to avoid having to recompute that in multiple spots.

 - In the `computeMD5` helper function we can create the `md5Buffer` via Array-destructuring, rather than using a manual loop.
2025-03-20 21:13:34 +01:00
Jonas Jenwald
f90732e4c3 Extend getSupplementalGlyphMapForCalibri with Pound-sign (issue 19695) 2025-03-20 20:12:24 +01:00
Jonas Jenwald
a229914b46
Merge pull request #19693 from Snuffleupagus/writer-fix-md5
Fix the MD5 computation in the `src/core/writer.js` file
2025-03-20 16:30:57 +01:00
Jonas Jenwald
e6c869c127 Fix the MD5 computation in the src/core/writer.js file
Currently the MD5 computation doesn't actually work (at all?), since we're invoking the `calculateMD5` function without providing all of the necessary parameters and the PDF-data thus isn't taken into account.

Fixing this caused unit-tests to fail, which isn't that surprising since the current date/time is used in the MD5 computation, and we thus utilize Jasmine to work-around that.
2025-03-20 14:41:25 +01:00
calixteman
cd4a30341f
Merge pull request #19685 from calixteman/issue19424
[Editor] Take into account the parent rotation when switch to edit mode (issue #19424)
2025-03-19 15:15:25 +01:00
Calixte Denizet
276c8f3518 [Editor] Take into account the parent rotation when switch to edit mode (issue #19424) 2025-03-19 14:26:55 +01:00
Jonas Jenwald
1a39e2dac1
Merge pull request #19684 from Snuffleupagus/issue-19683
Improve `addSignatureDescription`/`editSignatureDescription` handling (issue 19683)
2025-03-19 13:43:54 +01:00
Jonas Jenwald
79058c92e3 Improve addSignatureDescription/editSignatureDescription handling (issue 19683)
- Point the `addSignatureDescription` respectively `editSignatureDescription` labels to their actual `input`-elements (this way clicking the label will actually focus the input).

 - Add the event listener to the `addSignatureDescription`-input, rather than its `span`-element (this is consistent with the `editSignatureDescription` case).

 - Correctly check if the `addSignatureDescription`-input is empty, since we're accidentally comparing with its `span`-element.

 - Remove unbalanced, and likely accidentally added, `</span>` tags.
2025-03-19 11:38:56 +01:00
Jonas Jenwald
028e4f7ea8 [api-minor] Add a basic AbortSignal.any polyfill in PDF.js legacy builds
This is an admittedly very basic polyfill, to allow us to remove a bunch of inline feature testing, that I've thrown together based on reading https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static and related MDN articles.

Compared to PR 19218 it's obviously much more "primitive", however the implementation is simple and it doesn't suffer from any licensing issues (since I wrote the code myself).
2025-03-18 10:54:49 +01:00
Jonas Jenwald
00e3a4d87a
Merge pull request #19674 from Snuffleupagus/core-document-more-async
Introduce more `async` code in the `src/core/document.js` file
2025-03-17 21:40:16 +01:00
Jonas Jenwald
6243afa85e
Merge pull request #19675 from Snuffleupagus/IccColorSpace-fetchSync
Introduce a `fetchSync` helper function for the `IccColorSpace` classes
2025-03-17 20:22:00 +01:00
Jonas Jenwald
2f1497c9c4
Merge pull request #19677 from Snuffleupagus/issue-19676
For JPEG images with CMYK-data, ensure that the alpha-component is set correctly when WebAssembly is disabled (issue 19676)
2025-03-17 20:17:00 +01:00
Jonas Jenwald
afb14bdc0b For JPEG images with CMYK-data, ensure that the alpha-component is set correctly when WebAssembly is disabled (issue 19676) 2025-03-17 16:15:32 +01:00
Jonas Jenwald
1fb6edc713 Introduce a fetchSync helper function for the IccColorSpace classes
This reduces code duplication a tiny bit, which shouldn't hurt.
2025-03-17 14:58:53 +01:00
Jonas Jenwald
e37236e9af
Merge pull request #19673 from Snuffleupagus/rm-ftl-comment
Remove documentation for unused l10n variable (PR 18492 follow-up)
2025-03-17 14:28:12 +01:00
Jonas Jenwald
d00482380a Introduce more async code in the src/core/document.js file 2025-03-17 13:20:51 +01:00
Jonas Jenwald
e5e0856f99 Remove documentation for unused l10n variable (PR 18492 follow-up)
Looking at PR 18492 it doesn't seem that the `$percent` variable, for the `pdfjs-editor-new-alt-text-ai-model-downloading-progress` l10n-string, was ever used.
2025-03-17 12:20:30 +01:00
Tim van der Meij
92d7b6d09f
Merge pull request #19671 from timvandermeij/integration-tests-signature-intermittent
Fix the "Signature Editor Basic operations must check copy and paste" integration test
2025-03-16 21:35:25 +01:00
Tim van der Meij
2a4f970e00
Fix the "Signature Editor Basic operations must check copy and paste" integration test
This integration test fails intermittently because of concurrent
clipboard access due to running the test in parallel in both browsers.
It can be reproduced by introducing `await waitForTimeout(1000)` between
the copy and paste operations.

This commit fixes the issue by running the test sequentially instead,
mirroring the change from commit 0e94f2bd.
2025-03-16 20:35:36 +01:00
Tim van der Meij
e738566900
Merge pull request #19669 from timvandermeij/icc-colorspace-404
Don't get ICC color space files if required API options are missing
2025-03-16 18:45:21 +01:00
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
4c5ad92584
Merge pull request #19667 from Snuffleupagus/version-5.1
Bump library version to `5.1`
2025-03-16 13:51:35 +01:00
Jonas Jenwald
e3e2396230 Bump library version to 5.1 2025-03-16 13:47:18 +01:00
Tim van der Meij
d86045eacb
Merge pull request #19632 from Snuffleupagus/issue-15085
[api-minor] Attempt to support fetching the raw data of the PDF document from the `PDFDocumentLoadingTask`-instance (issue 15085)
2025-03-16 12:32:20 +01:00
Tim van der Meij
f8c2a949b7
Merge pull request #19665 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-03-16 11:31:08 +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
Tim van der Meij
33af8b5c2c
Update translations to the most recent versions 2025-03-15 20:42:08 +01:00
Tim van der Meij
85818f404f
Upgrade babel-loader to version 10.0.0
This is a major version bump, but the changelog at
https://github.com/babel/babel-loader/releases/tag/v10.0.0
doesn't indicate any breaking changes that should impact us.
2025-03-15 20:42:08 +01:00
Tim van der Meij
cfe6cc6a7e
Upgrade @metalsmith/layouts to version 3.0.0
This is a major version bump, and the changelog at
https://github.com/metalsmith/layouts/releases/tag/v3.0.0
indicates a breaking change that impacts us, namely that we need to
explicitly define the pattern and transformer that we wish to use.
2025-03-15 20:42:08 +01:00
Tim van der Meij
ef7e0ddae4
Update dependencies to the most recent versions 2025-03-15 20:42:08 +01:00
Jonas Jenwald
d1d88cc09e
Merge pull request #19662 from Snuffleupagus/xfa-rm-regex
Replace a few simple regular expressions in the XFA-code with string parsing
2025-03-15 19:44:30 +01:00
Tim van der Meij
2d1833b566
Merge pull request #19663 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-03-15 19:19:22 +01:00
Tim van der Meij
a1bcd789b9
Bump the stable version in pdfjs.config 2025-03-15 19:15:34 +01:00
Tim van der Meij
23972e1946
Merge pull request #19661 from Snuffleupagus/thumbnails-inline-finishRenderTask
Inline the `PDFThumbnailView.prototype.#finishRenderTask`  helper method
2025-03-15 18:46:26 +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
6548c9f1f6 Inline the PDFThumbnailView.prototype.#finishRenderTask helper method
Given that the `draw` method is already asynchronous we can easily inline this old helper method, which shortens the code and improves consistency in the code-base (note the `BasePDFPageView`-implementation).
2025-03-15 14:19:16 +01:00
Jonas Jenwald
7ee061bcf1 Add a helper function, in web/pdf_thumbnail_view.js, for "zeroing" a canvas
This removes a tiny bit of code duplication.
2025-03-15 13:24:52 +01:00
Jonas Jenwald
b7eef925ac Shorten the PDFThumbnailView.prototype.#getReducedImageDims method (PR 19635 follow-up)
This method is slightly more verbose than necessary, hence we can shorten the code a little bit.
2025-03-15 13:19:34 +01:00
Tim van der Meij
4b2683ecb6
Merge pull request #19656 from Snuffleupagus/shorten-MeshStreamReader
Slightly shorten a couple of `MeshStreamReader` methods
2025-03-14 19:50:36 +01:00
Jonas Jenwald
9967ab4aa8
Merge pull request #19657 from Snuffleupagus/GenericL10n-rm-regex
Replace the regular expression in `GenericL10n.#getPaths` with simple string parsing
2025-03-14 16:21:54 +01:00
Jonas Jenwald
9180e27f15 Replace the regular expression in GenericL10n.#getPaths with simple string parsing 2025-03-14 15:54:14 +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
calixteman
2294a510b0
Merge pull request #19653 from calixteman/rm_strings_html
Remove all the translatable strings from the html
2025-03-13 21:24:34 +01:00
Calixte Denizet
88c3ed9a80 Remove all the translatable strings from the html 2025-03-13 18:38:29 +01:00
calixteman
8791b24742
Merge pull request #19652 from calixteman/rm_useless_css_var
[Editor] Remove useless css variable
2025-03-13 16:48:50 +01:00
Calixte Denizet
7c706b6525 [Editor] Remove useless css variable 2025-03-13 16:40:30 +01:00
calixteman
dc61e36bf4
Merge pull request #19651 from calixteman/fix_ftl
[Editor] Fix variable name in the ftl file
2025-03-13 16:36:38 +01:00
Calixte Denizet
56f58bde9a [Editor] Fix variable name in the ftl file
and add a linting rule to avoid such an error in the future.
2025-03-13 16:26:16 +01:00
calixteman
d5c185b90a
Merge pull request #19649 from calixteman/bug1953298
[Editor] Fix the title of saved signature button (bug 1953298)
2025-03-13 13:50:43 +01:00
Calixte Denizet
da105f71f6 [Editor] Fix the title of saved signature button (bug 1953298) 2025-03-13 13:07:45 +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
ef01ceda1b Change a couple of "password" ref-tests to "eq" tests
Currrently these are just "load" tests, and by also testing rendering we get slightly better test-coverage for the `src/core/crypto.js` file.
2025-03-13 11:58:13 +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
a8ad7d6485
Merge pull request #19645 from Snuffleupagus/OutputScale-pixelRatio
Add an `OutputScale` static method to get the `devicePixelRatio`
2025-03-12 21:22:16 +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
643c44b631
Merge pull request #19643 from Snuffleupagus/l10n-update
Update l10n files
2025-03-12 21:02:24 +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
bec6287b0a
Merge pull request #19647 from Snuffleupagus/bug-1953099
Let `Lexer.prototype.getNumber` treat more cases of a single minus sign as zero (bug 1953099)
2025-03-12 19:34:07 +01:00
calixteman
7bc7416111
Merge pull request #19642 from calixteman/bug1953003
[Editor] Fix the style of the buttons in dialog (bug 1953003)
2025-03-12 19:24:53 +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
Jonas Jenwald
4ebcc996d0 Update l10n files
Given the recently added l10n-strings, let's do yet another update before the upcoming release to avoid needlessly "broken" translations.
2025-03-12 09:58:52 +01:00
Calixte Denizet
216e17afc5 [Editor] Fix the style of the buttons in dialog (bug 1953003)
This patch fixes:
 - the style of the primary/secondary buttons in the dialog which weren't fully compliant to the last specs.
 - the style of the input field in HCM (wrong background)
 - the color of the link in the image tab.
2025-03-11 20:03:23 +01:00
Jonas Jenwald
d74619847d
Merge pull request #19640 from Snuffleupagus/secondaryToolbar-fix-close
Don't close the `secondaryToolbar` when clicking inside it (PR 18385 follow-up)
2025-03-11 19:42:36 +01:00
Jonas Jenwald
221eba29b9 Don't close the secondaryToolbar when clicking inside it (PR 18385 follow-up)
When the DOM structure of the viewer was updated in PR 18385 it caused the `secondaryToolbar` to accidentally start closing when clicking inside of it, since the `secondaryToolbar` now reside *under* the `toolbar` in the DOM.

**Steps to reproduce:**
 - Open the viewer.
 - Open the `secondaryToolbar`.
 - Try to change document rotation at least *twice*.

**Expected behaviour:**
 The document rotation can be changed an arbitrary number of times.

**Actual results:**
 The `secondaryToolbar` closes after changing rotation just once.
2025-03-11 19:26:23 +01:00
calixteman
391e84c34b
Merge pull request #19639 from calixteman/issue19633
Always use the absolute value of the line thickness (issue 19633)
2025-03-11 14:35:33 +01:00
Calixte Denizet
4b4f85484e Always use the absolute value of the line thickness (issue 19633) 2025-03-11 14:03:23 +01:00
calixteman
d008452e80
Merge pull request #19637 from calixteman/bug1952571
[Editor] Add an aria label to an added signature (bug 1952571)
2025-03-10 20:44:42 +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
febf59ce75
Merge pull request #19636 from calixteman/bug1952558
[Editor] Make sure the save checkbox isn't focusable when saving is disabled (bug 1952558)
2025-03-10 18:46:40 +01:00
Calixte Denizet
69a2e5137d [Editor] Make sure the save checkbox isn't focusable when saving is disabled (bug 1952558)
And fix the the width of the warning message when the limit of signatures has been reached:
in french the string is longer than the dialog's one.
2025-03-10 18:08:42 +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
26b5c8f821
Merge pull request #19625 from Snuffleupagus/issue-19624
Improve text-selection for Type3 fonts, using `d0` operators, with empty /FontBBox-entries (issue 19624)
2025-03-10 16:26:04 +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
Jonas Jenwald
b9e8844541
Merge pull request #19613 from Snuffleupagus/issue-19611
Let SMask/Mask images fallback to the parent image dimensions (issue 19611)
2025-03-10 16:12:48 +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
Jonas Jenwald
1bc98dfbd9
Merge pull request #19621 from Snuffleupagus/bug-1943094-thumbs
Limit the maximum thumbnail canvas width/height, similar to pages (PR 19604 follow-up)
2025-03-10 11:32:08 +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
Tim van der Meij
66af403f10
Merge pull request #19628 from Snuffleupagus/MathClamp-2
Use the `MathClamp` helper function more (PR 19617 follow-up)
2025-03-09 12:49:53 +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
cef4fcf025
Merge pull request #19622 from nicolo-ribaudo/zoom-detail-view-constant-redraw
Do not constantly render the detail canvas on zoom (bug 1952496)
2025-03-07 13:56:13 +01:00
Nicolò Ribaudo
a1dc46aa9d
Do not constantly render the detail canvas on zoom
When zooming, we should skip rendering the detail canvas until the
zoom is done, similarly to how normal page rendering is delayed.
To do so is enough to skip details view while zooming, since the
main view rendering that already happens after the delay will also
trigger rendering of the detail views.
2025-03-07 12:38:52 +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
eef15a30cd Limit the maximum thumbnail canvas width/height, similar to pages (PR 19604 follow-up)
The changes in PR 19604 weren't enough for thumbnail canvases in some cases, see e.g. https://web.archive.org/web/20231204152348if_/https://user.informatik.uni-bremen.de/cabo/rfc9000.pdf#pagemode=thumbs
2025-03-06 23:00:20 +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
Jonas Jenwald
d646b2b270
Merge pull request #19610 from Snuffleupagus/rm-opacityToHex
[Editor] Remove the unused `opacityToHex` helper function (PR 19093 follow-up)
2025-03-06 15:42:38 +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
dea35aed4a
Merge pull request #19608 from Snuffleupagus/l10n-update
Update l10n files
2025-03-05 15:25:55 +01:00
Jonas Jenwald
c2fa55420c
Merge pull request #19607 from Snuffleupagus/ColorSpaceUtils-rm-singletons
Simplify the `ColorSpaceUtils.singletons` handling (PR 19564 follow-up)
2025-03-05 15:25:19 +01:00
Jonas Jenwald
de47041e77 Update l10n files
Given the recently added l10n-strings, let's do another update before the upcoming release to avoid needlessly "broken" translations.
2025-03-05 15:08:39 +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
fedfdf9d10
Merge pull request #19599 from Snuffleupagus/ColorSpace-rm-parseAsync
Remove `ColorSpaceUtils.parseAsync` and simplify the ColorSpace "API-surface"
2025-03-05 13:11:45 +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
calixteman
19bc5dcb0e
Merge pull request #19564 from calixteman/qcms_icc
[api-minor] Support using ICC profiles in using qcms (bug 860023)
2025-03-05 10:34:23 +01:00
Calixte Denizet
971be48b60 Support using ICC profiles in using qcms (bug 860023) 2025-03-05 10:29:59 +01:00
calixteman
4693b7ad2f
Merge pull request #19585 from calixteman/update_openjpeg2
Use the latest emsdk version to compile openjpeg decoder
2025-03-05 10:07:11 +01:00
Calixte Denizet
559ff28db3 Use the latest emsdk version to compile openjpeg decoder 2025-03-04 18:41:20 +01:00
Jonas Jenwald
ab8ebc9b77
Merge pull request #19604 from Snuffleupagus/bug-1943094
[api-minor] Limit the maximum canvas width/height, in addition to its total area (bug 1943094)
2025-03-04 17:53:31 +01:00
Jonas Jenwald
9f9de4508c [api-minor] Limit the maximum canvas width/height, in addition to its total area (bug 1943094)
Browsers not only limit the maximum total canvas area, but additionally also limit their maximum width/height which affects PDF documents with e.g. very tall and narrow pages.
To address this we add a new `maxCanvasDim` viewer-option, which in Firefox will use a browser preference, such that both the total canvas area and the width/height will affect when CSS-zooming is used.
2025-03-04 15:23:45 +01:00
Jonas Jenwald
5e6cfbe163
Merge pull request #19598 from Snuffleupagus/ColorSpace#subParse
Also cache "sub" ColorSpaces globally (PR 19583 follow-up)
2025-03-03 17:30:14 +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
Tim van der Meij
0c1ac54f48
Merge pull request #19597 from Snuffleupagus/then-arrow-functions
Use arrow functions with some `Promise.then` calls
2025-03-02 22:14:53 +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
Jonas Jenwald
3cd1b10433
Merge pull request #19576 from nicolo-ribaudo/fix-linkannotation
Fix autolinking with highlighted search results
2025-03-02 19:51:15 +01:00
Nicolò Ribaudo
b47d81536c
Fix autolinking with highlighted search results
The current logic assumes that all spans in the text layer contain
only one text node, and thus that the position information
returned by `highlighter._convertMatches` can be directly used
on the element's only child.

This is not true in case of highlighted search results: they will be
injected in the DOM as `<span>` elements, causing the `<span>`s
in the text layer to have more than one child.

This patch fixes the problem by properly converting the (span, offset)
pair in a (textNode, offset) pair that points to the right text node.
2025-03-02 17:09:58 +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
Tim van der Meij
be6ef64a2c
Merge pull request #19577 from Snuffleupagus/isValidExplicitDest-reuse
Re-use the `isValidExplicitDest` helper function in the worker/viewer
2025-03-02 15:50:54 +01:00
Tim van der Meij
e8bbb60869
Merge pull request #19582 from dhdaines/consume_response
Be sure to consume responses in case of error in downloading test files (issue 19580)
2025-03-02 15:48:26 +01:00
Tim van der Meij
1aee9d5c61
Merge pull request #19581 from Snuffleupagus/issue-19579
Write string-data into the `.error`-file created for broken test-manifest links (issue 19579)
2025-03-02 15:39:11 +01:00
Tim van der Meij
dfa6370161
Merge pull request #19589 from Snuffleupagus/RunLengthStream-fill
Replace a loop with `TypedArray.prototype.fill()` in the `RunLengthStream` class
2025-03-02 15:36:49 +01:00
Tim van der Meij
27c82ab8cc
Merge pull request #19568 from Snuffleupagus/FakeMLManager-no-bundle
Don't bundle the `FakeMLManager` class in regular builds
2025-03-02 15:30:03 +01:00
Tim van der Meij
93759f34f4
Merge pull request #19571 from yjoer/master
Add the missing return type for `PDFWorker.fromPort()`
2025-03-02 15:27:10 +01:00
Jonas Jenwald
2e62f426fe Use arrow function with various Array methods
A lot of this is quite old code, which we can shorten slightly by using arrow functions instead of "regular" functions.
2025-03-02 15:19:04 +01:00
Jonas Jenwald
a3d259a681 Replace a loop with TypedArray.prototype.fill() in the RunLengthStream class
This is a tiny bit shorter, which cannot hurt.
2025-03-02 13:10:34 +01:00
Jonas Jenwald
7081a1f112
Merge pull request #19578 from nicolo-ribaudo/flaky-test
Try reducing flakiness of CSS-only zoom test
2025-03-02 10:28:11 +01:00
Nicolò Ribaudo
de9b041b5e
Fix flakiness of CSS-only zoom test
Update the test to wait for the `pagerendered`` event of a specific
page (1), so that the `pagerendered`` event of other pages from a
previously running render doesn't resolve the `waitForPageRendered`
promise.
2025-03-01 19:10:28 +01:00
Jonas Jenwald
89ccc3a526
Merge pull request #19583 from Snuffleupagus/GlobalColorSpaceCache
Add a `GlobalColorSpaceCache` to reduce unnecessary re-parsing
2025-03-01 14:24:49 +01:00
Jonas Jenwald
4be79748c9 Add a GlobalColorSpaceCache to reduce unnecessary re-parsing
This complements the existing `LocalColorSpaceCache`, which is unique to each `getOperatorList`-invocation since it also caches by `Name`, which should help reduce unnecessary re-parsing especially for e.g. `ICCBased` ColorSpaces once we properly support those.
2025-03-01 14:21:05 +01:00
David Huggins-Daines
962f972aea Be sure to consume responses in case of error in downloading test files (issue 19580)
As mentioned in https://nodejs.org/docs/latest-v20.x/api/http.html#httpgeturl-options-callback
if a request results in an error, you still need to consume the data, or call
`response.resume()`, or your code will hang waiting for the request to close.
2025-03-01 07:53:56 -05:00
Jonas Jenwald
165d90fe26 Re-use the isValidExplicitDest helper function in the worker/viewer
Currently we re-implement the same helper function twice, which in hindsight seems like the wrong decision since that way it's quite easy for the implementations to accidentally diverge.
The reason for doing it this way was because the code in the worker-thread is able to check for `Ref`- and `Name`-instances directly, which obviously isn't possible in the viewer but can be solved by passing validation-functions to the helper.
2025-03-01 12:08:56 +01:00
calixteman
5f4d923618
Merge pull request #19584 from calixteman/update_openjpeg1
Fix the build of the openjpeg decoder in order to use an optimized build of the openjpeg library (bug 1951128)
2025-02-28 22:55:46 +01:00
calixteman
84a5e90a43
Merge pull request #19544 from hecerinc/hecerinc/viewerCssFF
Reenable viewerCssTheme option for Firefox
2025-02-28 21:27:20 +01:00
Calixte Denizet
c565810a3d Fix the build of the openjpeg decoder in order to use an optimized build of the openjpeg library (bug 1951128) 2025-02-28 21:25:51 +01:00
Jonas Jenwald
d1b2476c14 Write string-data into the .error-file created for broken test-manifest links (issue 19579)
This appears to have broken in PR 17431, since prior to that the `downloadFile` function returned a string (via a callback) on failure and now we're instead rejecting with an Error.
2025-02-28 17:05:15 +01:00
Jonas Jenwald
6e1cfa20d1
Merge pull request #19574 from Snuffleupagus/autolinking-xfa-disable
Don't attempt to use auto-linking in XFA documents (PR 19110 follow-up)
2025-02-28 16:30:45 +01:00
Jonas Jenwald
7273db2e35 Don't attempt to use auto-linking in XFA documents (PR 19110 follow-up)
Auto-linking requires a normal textLayer which XFA documents obviously don't have, and currently XFA documents cause "pointless" error messages to be logged in the console.
2025-02-28 14:47:48 +01:00
Yeoh Joer
2221ccf160 Add the missing return type for PDFWorker.fromPort() 2025-02-28 02:49:44 +08:00
Jonas Jenwald
b5ac96da19 Don't bundle the FakeMLManager class in regular builds
Given that this functionality is only used in the development viewer and in TESTING builds, there's no reason to include this in the regular builds.
2025-02-27 12:59:58 +01:00
Jonas Jenwald
50c573d16d
Merge pull request #19563 from Snuffleupagus/loadType3Data-once
Invoke `TranslatedFont.prototype.loadType3Data` only *once* per font
2025-02-27 11:20:26 +01:00
Jonas Jenwald
56a683bc3b
Merge pull request #19562 from Snuffleupagus/issue-19550
Extend `getGlyphMapForStandardFonts` with some Cyrillic entries (issue 19550)
2025-02-27 11:17:42 +01:00
Jonas Jenwald
4a48a7ec0f
Merge pull request #19557 from Snuffleupagus/PDFViewer-cleanupTimeouts
Abort various timeouts, in `PDFViewer`, when closing the document (PR 19128 follow-up)
2025-02-27 11:17:02 +01:00
Jonas Jenwald
21829f4157
Merge pull request #19556 from Snuffleupagus/_initializeViewerComponents-more-local-vars
Use more local variables in `PDFViewerApplication._initializeViewerComponents`
2025-02-27 11:16:04 +01:00
Jonas Jenwald
4e76a78341
Merge pull request #19549 from Snuffleupagus/fewer-EXPORT_DATA_PROPERTIES-2
[api-minor] Stop exporting, by default, a few additional Font properties (PR 11777 follow-up)
2025-02-27 11:15:27 +01:00
calixteman
a4fea2dafd
Merge pull request #19565 from calixteman/signature_fix_telemetry
[Editor] Fix the telemetry for the signature stuff
2025-02-27 10:10:13 +01:00
Calixte Denizet
bbf9bfc3c2 [Editor] Fix the telemetry for the signature stuff 2025-02-27 09:34:31 +01:00
Jonas Jenwald
bdfa96878d Invoke TranslatedFont.prototype.loadType3Data only *once* per font
Currently we're first loading the font, and then for Type3 fonts we're invoking `loadType3Data` every time that the font is encountered.
That seems completely unnecessary, and it's probably connected to the age of this code, since the `loadType3Data`-method will only run once anyway (note the caching).
2025-02-26 15:17:11 +01:00
Jonas Jenwald
da17c7b82f
Merge pull request #19548 from Snuffleupagus/Font-exportData-disableFontFace-fontExtraProperties
Send `disableFontFace` and `fontExtraProperties` as part of the exported font-data
2025-02-26 11:25:29 +01:00
Jonas Jenwald
59cb9a064e Extend getGlyphMapForStandardFonts with some Cyrillic entries (issue 19550) 2025-02-26 10:16:06 +01:00
Jonas Jenwald
0e0872288e
Merge pull request #19558 from Snuffleupagus/RenderingCancelledException-null-#renderError
Reset `#renderError` on `RenderingCancelledException` (PR 19128 follow-up)
2025-02-26 09:43:39 +01:00
Hector Rincon
4069c3a422 Reenable viewerCssTheme option for Firefox
The `viewerCssTheme` was removed in #17222  and subsequently reenabled in #17293,
but only for Chromium and generic builds. This commit reenables the
function using the new method introduced in #17293.
2025-02-25 22:00:32 -08:00
Jonas Jenwald
d50d3b0b0e Reset #renderError on RenderingCancelledException (PR 19128 follow-up)
This restores the behaviour that existed prior to PR 19128, see e.g. 8727a04ae5/web/pdf_page_view.js (L908-L911), since `RenderingCancelledException` should still overwrite any previously seen Error.
2025-02-25 16:46:01 +01:00
Jonas Jenwald
71ad9fd0b7 Abort various timeouts, in PDFViewer, when closing the document (PR 19128 follow-up)
Looking at recent integration-test logs there's occasionally warnings about trying to invoke `PDFViewer.prototype.update` too late, which probably started with PR 19128 (see log excerpt below).
Given that we already had another timeout before that PR the problem was pre-existing, but it seems to trigger more easily now.

```
JavaScript warning: http://127.0.0.1:42333/build/generic/web/viewer.mjs, line 12668: Script terminated by timeout at:
update@http://127.0.0.1:42333/build/generic/web/viewer.mjs:12668:9
@http://127.0.0.1:42333/build/generic/web/viewer.mjs:12373:12
setTimeout handler*_scrollUpdate@http://127.0.0.1:42333/build/generic/web/viewer.mjs:12371:29
viewAreaElementScrolled@http://127.0.0.1:42333/build/generic/web/viewer.mjs:154:15
FrameRequestCallback*debounceScroll@http://127.0.0.1:42333/build/generic/web/viewer.mjs:140:18
EventListener.handleEvent*watchScroll@http://127.0.0.1:42333/build/generic/web/viewer.mjs:165:19
PDFViewer@http://127.0.0.1:42333/build/generic/web/viewer.mjs:11777:19
_initializeViewerComponents@http://127.0.0.1:42333/build/generic/web/viewer.mjs:15081:23
initialize@http://127.0.0.1:42333/build/generic/web/viewer.mjs:14931:16
async*run@http://127.0.0.1:42333/build/generic/web/viewer.mjs:15227:16
webViewerLoad@http://127.0.0.1:42333/build/generic/web/viewer.mjs:17078:24
@http://127.0.0.1:42333/build/generic/web/viewer.mjs:17082:3
```
2025-02-25 13:11:51 +01:00
Jonas Jenwald
cec32c6177 Use more local variables in PDFViewerApplication._initializeViewerComponents
This, ever so slightly, shortens the code which can never hurt.
2025-02-25 12:33:13 +01:00
Jonas Jenwald
aa70b28365
Merge pull request #19555 from rossj/master
Pad rev 4 encryption keys to be >= 16 bytes (issue 19484)
2025-02-25 10:03:56 +01:00
calixteman
e999f77959
Merge pull request #19554 from calixteman/signature_telemetry
[Editor] Add some telemetry for the signature editor (bug 1945827)
2025-02-24 22:53:49 +01:00
Ross Johnson
4f25d7f6cd Fix decryption of R=4, V=4 files with < 16-byte keys by 0-padding - undocumented but matches Acrobat behavior (issue #19484) 2025-02-24 15:36:37 -06:00
Calixte Denizet
9e672ff05e [Editor] Add some telemetry for the signature editor (bug 1945827) 2025-02-24 21:10:04 +01:00
calixteman
fef706233d
Merge pull request #19551 from Snuffleupagus/loadSystemFont-fix-assert
Fix the `assert` in `FontLoader.prototype.loadSystemFont`
2025-02-24 16:49:03 +01:00
calixteman
12d2f1b04a
Merge pull request #19552 from calixteman/add_generated_header_openjpeg
Add a comment 'THIS FILE IS GENERATED - DO NOT EDIT' in openjpeg files generated with emscripten
2025-02-24 16:17:48 +01:00
Jonas Jenwald
2966171a2b Fix the assert in FontLoader.prototype.loadSystemFont
Currently this `assert` isn't actually doing what it's supposed to, since the `FontLoader`-class doesn't have a `disableFontFace`-field.
The `FontFaceObject`-class on the other hand has such a field, hence we update the method-signature to be able to check the intended thing.
2025-02-24 16:09:07 +01:00
calixteman
f9aa8e1d15
Merge pull request #19539 from calixteman/paste_signature
[Editor] Shift the signature editor when pasted
2025-02-24 16:07:50 +01:00
Calixte Denizet
c099245daa Add a comment 'THIS FILE IS GENERATED - DO NOT EDIT' in openjpeg files generated with emscripten 2025-02-24 16:05:19 +01:00
Jonas Jenwald
132ccf04db [api-minor] Stop exporting, by default, a few additional Font properties (PR 11777 follow-up)
None of the "composite", "subtype", or "type" properties are normally used on the main-thread and/or in the API, hence there's no need to include them in the exported font-data by default.
Given that these properties may still be useful when debugging, and that `debugger.mjs` actually relies on the "type" property, they will instead only be sent to the main-thread when the `fontExtraProperties` API-option is used.
2025-02-24 12:27:51 +01:00
Jonas Jenwald
c4784832ac
Merge pull request #19545 from hecerinc/hecerinc/issueLinkFix
Fix the link for issue5939.pdf
2025-02-24 10:08:15 +01:00
Jonas Jenwald
d428db63c3 Improve the "FontFallback" handling on the worker-thread
Remove the `Catalog.prototype.fontFallback` method, and move its code into `PDFDocument.prototype.fontFallback` instead, to reduce the indirection a little bit.
Pass the `evaluatorOptions` directly to the `TranslatedFont.prototype.fallback` method, since nothing else in the `TranslatedFont`-class needs it now.
2025-02-24 09:34:58 +01:00
Jonas Jenwald
839e23f5c2 Send disableFontFace and fontExtraProperties as part of the exported font-data
These options are needed in the `FontFaceObject` class, and indirectly in `FontLoader` as well, which means that we currently need to pass them around manually in the API.
Given that the options are (obviously) available on the worker-thread, it's very easy to just provide them when creating `Font`-instances and then send them as part of the exported font-data. This way we're able to simplify the code (primarily on the main-thread), and note that `Font`-instances even had a `disableFontFace`-field already (but it wasn't properly initialized).
2025-02-24 09:34:48 +01:00
Hector Rincon
c19e70f6d9 Fix the link for issue5939.pdf
Web archive no longer has the revision for the saved PDF referenced in
that test case, so this updates that link to a more recent revision to
enable the tests to run on a clean clone.
2025-02-23 15:15:11 -08:00
Jonas Jenwald
ed64faa88c
Merge pull request #19543 from timvandermeij/integration-tests-helpers
Refactor the editor integration test helper functions
2025-02-23 22:56:38 +01:00
Calixte Denizet
cc3d6ab539 [Editor] Shift the signature editor when pasted
The idea is to avoid to have the pasted editor hidding the copied one:
the user could think that nothing happened.
So the top-left corner of the pasted one is moved to the bottom-right corner of the copied one.
2025-02-23 21:35:01 +01:00
Tim van der Meij
acc5a2153a
Introduce a generic clearEditors helper function
This replaces the various copies of this logic with a single helper that
we template for each editor type, similar to what we already do for the
`switchToEditor` helper.
2025-02-23 20:49:04 +01:00
Tim van der Meij
f155b69c07
Introduce a generic selectEditors helper function
This replaces the various copies of this logic with a single helper that
we template for each editor type, similar to what we already do for the
`switchToEditor` helper.
2025-02-23 20:48:24 +01:00
Tim van der Meij
060ef0e15e
Deduplicate the waitForPointerUp helper function in the highlight editor integration tests
The helper function is available in `test_utils.mjs` since commit
3fe55ba, so we can remove the local copy by importing it.
2025-02-23 20:48:17 +01:00
Tim van der Meij
07629e105c
Deduplicate the getXY helper function in the highlight editor integration tests
The helper function is available in `test_utils.mjs` since commit
301f1bb, so by exporting it there it can be reused.
2025-02-23 20:48:17 +01:00
Tim van der Meij
4f3dbcf24d
Remove the waitForEditorMovedInDOM helper function export
It's no longer used outside of `test_utils.mjs` since commit 301f1bb.
2025-02-23 20:48:17 +01:00
Tim van der Meij
fcf94e8c38
Merge pull request #19542 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-02-23 20:47:10 +01:00
Tim van der Meij
33c53dfaa9
Update translations to the most recent versions 2025-02-23 19:31:20 +01:00
Tim van der Meij
cd6c5b009f
Upgrade globals to version 16.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/globals/releases/tag/v16.0.0
doesn't indicate any breaking changes that should impact us.
2025-02-23 19:31:20 +01:00
Tim van der Meij
8b0f1641ee
Upgrade eslint-plugin-unicorn to version 57.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v57.0.0
doesn't indicate any breaking changes that should impact us.

However, we do replace the deprecated `no-instanceof-array` rule with
the new `no-instanceof-builtins` rule. Note that the changelog calls
this rule `no-instanceof-builtin-object`, but it got renamed in
https://github.com/sindresorhus/eslint-plugin-unicorn/pull/2537.
2025-02-23 19:28:28 +01:00
Tim van der Meij
08ba910ef0
Update dependencies to the most recent versions 2025-02-23 18:21:50 +01:00
calixteman
878d206c79
Merge pull request #19538 from calixteman/move_draw
[Editor] Fix the position in the page of a drawing after it has been moved with the keyboard
2025-02-22 15:55:26 +01:00
Calixte Denizet
301f1bbf2b [Editor] Fix the position in the page of a drawing after it has been moved with the keyboard
When a drawing was moved with arrow keys and then printed or saved, the drawing wasn't moved finally.
So the fix is just about calling onTranslated once the translation is done.
2025-02-22 15:19:14 +01:00
Jonas Jenwald
a648e1e769
Merge pull request #19537 from Snuffleupagus/api-useWasm
[api-minor] Re-factor how the `useWorkerFetch` option is used internally
2025-02-22 14:16:31 +01:00
Tim van der Meij
23d7398371
Merge pull request #19531 from stof/patch-1
Disable the loading of node types in the type tests
2025-02-22 13:47:44 +01:00
Jonas Jenwald
637e95985a Simplify JpxImage.setOptions a little bit
After PR 19392 we're only invoking this method *once* per document, hence the early-return branch shouldn't be necessary any more.
2025-02-22 13:38:10 +01:00
Jonas Jenwald
641e2f506e [api-minor] Re-factor how the useWorkerFetch option is used internally
With the recently added OpenJPEG no-wasm fallback we need to send the `wasmUrl` option to the worker-thread *regardless* of the value of the `useWorkerFetch` option, since the fallback won't work if we don't have a URL to `import` it from.
For consistency the code is re-factored to always send the factory-urls to the worker-thread, and simply check the `useWorkerFetch` option there instead.

Also, as a follow-up to PR 19525, introduce a new `useWasm` option that can be used in e.g. browser-tests to forcibly disable WebAssembly usage.
2025-02-22 09:56:53 +01:00
Jonas Jenwald
6d3bb47655
Merge pull request #19525 from calixteman/bug1935076_part2
Provide a js fallback when the wasm version of openjpeg is failing to load (bug 1935076)
2025-02-22 09:34:40 +01:00
calixteman
c2e616dfc9
Merge pull request #19534 from calixteman/signature_description_test
[Editor] Add a test for copy & paste a signature editor
2025-02-21 23:01:31 +01:00
Jonas Jenwald
553ec7babc
Merge pull request #19128 from nicolo-ribaudo/draw-page-portion
[api-minor] Render high-res partial page views when falling back to CSS zoom (bug 1492303)
2025-02-21 22:24:41 +01:00
calixteman
b4e26dc425
Merge pull request #19533 from Xiphoseer/type3-text-rise
Consider textRise when showing Type3 font glyphs (issue 19532)
2025-02-21 22:10:58 +01:00
Calixte Denizet
814d2bbe6d [Editor] Add a test for copy & paste a signature editor
This patch fixes an issue when pasting: an exception was thrown when pasting.
And while writing the test and comparing the paths in the svg, I found a difference
which is fixed thanks to call to the right constructor (to take into account the inheritance)
in inkdraw.js
2025-02-21 21:43:19 +01:00
Xiphoseer
24aa39eb14 Consider textRise when showing type3 font glyphs
Add test case for issue 19532
2025-02-21 21:31:04 +01:00
Calixte Denizet
36e4f5c222 Provide a js fallback when the wasm version of openjpeg is failing to load (bug 1935076) 2025-02-21 19:03:47 +01:00
Nicolò Ribaudo
dc5d6aad8a
Avoid degrading scroll performance due to the detail view
When scrolling quickly, the constant re-rendering of the detail view
significantly affects rendering performance, causing Firefox to
not render even the _background canvas_, which is just a static canvas
not being re-drawn by JavaScript.

This commit changes the viewer to only render the detail view while
scrolling if its rendering hasn't just been cancelled. This means that:
- when the user is scrolling slowly, we have enough time to render the
  detail view before that we need to change its area, so the user always
  sees the full screen as high resolution.
- when the user is scrolling quickly, as soon as we have to cancel a
  rendering we just give up, and the user will see the lower resolution
  canvas. When then the user stops scrolling, we render the detail view
  for the new visible area.
2025-02-21 10:00:57 -08:00
Nicolò Ribaudo
458b2ee402
[api-minor] Render high-res partial page views when falling back to CSS zoom (bug 1492303)
When rendering big PDF pages at high zoom levels, we currently fall back
to CSS zoom to avoid rendering canvases with too many pixels. This
causes zoomed in PDF to look blurry, and the text to be potentially
unreadable.

This commit adds support for rendering _part_ of a page (called
`PDFPageDetailView` in the code), so that we can render portion of a
page in a smaller canvas without hiting the maximun canvas size limit.

Specifically, we render an area of that page that is slightly larger
than the area that is visible on the screen (100% larger in each
direction, unless we have to limit it due to the maximum canvas size).
As the user scrolls around the page, we re-render a new area centered
around what is currently visible.
2025-02-21 10:00:55 -08:00
Nicolò Ribaudo
06257f782e
Extract PDFPageViewBase class out of PDFPageView
This base class contains the generic logic for:
- Creating a canvas and showing when appropriate
- Rendering in the canvas
- Keeping track of the rendering state
2025-02-21 09:48:31 -08:00
Christophe Coevoet
93a5fa5b88
Disable the loading of node types in the type tests
Those type tests are performing type checking on a project using DOM APIs, intended to reflect the usage in a non-node project.
Not loading the node types in that project ensures that the library type declarations don't force a dependency on the node types.
2025-02-21 14:10:35 +01:00
Jonas Jenwald
e3ea92603d
Merge pull request #19493 from Snuffleupagus/URL-parse
Introduce some `URL.parse()` usage in the code-base
2025-02-21 10:40:32 +01:00
calixteman
34ef74cf0e
Merge pull request #19518 from Snuffleupagus/JpegStream-EXIF-replace
Move the EXIF-block replacement into `JpegStream` (PR 19356 follow-up)
2025-02-20 23:11:43 +01:00
calixteman
c64d3d7cc0
Merge pull request #19524 from calixteman/fix_doorhanger_color
[Editor] Fix the color of the labels in the editing doorhangers
2025-02-20 22:45:51 +01:00
Calixte Denizet
cd94c19f9a [Editor] Fix the color of the labels in the editing doorhangers
The fix in #19522 wasn't correct.
This one should be better.
2025-02-20 19:31:57 +01:00
calixteman
6713c239e3
Merge pull request #19523 from calixteman/signature_menu_outline
[Editor] Fix the outline of a focused button in the doorhanger while navigating with the keyboard
2025-02-20 19:23:54 +01:00
Calixte Denizet
8be6d744cd [Editor] Fix the outline of a focused button in the doorhanger while navigating with the keyboard
It's a follow-up of #19507.
Without this patch the outline is partially hidden.
2025-02-20 18:33:19 +01:00
calixteman
b1d579d4ab
Merge pull request #19522 from calixteman/bug1949417
[Editor] Make the editing toolbar buttons text visible when hovered in HCM with Desert theme (bug 1949417)
2025-02-20 15:45:20 +01:00
Calixte Denizet
b7e65b854b [Editor] Make the editing toolbar buttons text visible when hovered in HCM with Desert theme (bug 1949417) 2025-02-20 15:01:52 +01:00
calixteman
c52b5bac6c
Merge pull request #19516 from calixteman/bug1949201
[Editor] Remove the error panel when the user click on an other tab (bug 1949201)
2025-02-20 14:07:07 +01:00
Calixte Denizet
12ba81718c [Editor] Remove the error panel when the user click on an other tab (bug 1949201) 2025-02-20 14:03:59 +01:00
Jonas Jenwald
d5ce35f744 Move the EXIF-block replacement into JpegStream (PR 19356 follow-up)
Currently we modify the EXIF-block in place, which may end up "breaking" the JPEG-data of the original PDF document since e.g. saving it from the viewer no longer contains the real EXIF-block.
Hence the EXIF-block replacement is moved into the `JpegStream` class, such that we can copy the data before doing the replacement.
2025-02-20 12:41:39 +01:00
Jonas Jenwald
d10cea5dd0
Merge pull request #19470 from ryzokuken/fix-autolinking-edge-cases
Fix autolinking errors
2025-02-19 14:43:14 +01:00
Ujjwal Sharma
38ab358fb1 Fix autolinking error due to redundant annotations on zooming
Fix an issue where redundant links were being added to the annotation
layer on zooming on the page with the links.
2025-02-19 13:18:31 +01:00
Ujjwal Sharma
70e2873430 Fix autolinking errors due to regex and email validation
Fix some edge cases in the autolinking logic with the regex as well as
validating email domains and add unit tests for them.

Fixes: https://github.com/mozilla/pdf.js/issues/19462
2025-02-19 13:18:31 +01:00
Jonas Jenwald
63b397f49d
Merge pull request #19513 from Snuffleupagus/issue-19510
Don't cache free/missing XRef entries (issue 19510)
2025-02-18 21:23:01 +01:00
Jonas Jenwald
db7cf40a30 Don't cache free/missing XRef entries (issue 19510)
During the XRef stream parsing we're attempting to lookup an entry that hasn't yet been found, since parsing is currently running, and given that we'd also cache free/missing XRef entries we'd then return an incorrect value during normal PDF parsing.

The simplest solution here is to just not cache free/missing XRef entries, since a properly generated PDF document shouldn't be trying to access objects it doesn't contain.
Furthermore, the amount of "extra" parsing now needed for such XRef entries shouldn't be significant enough to be an issue.
2025-02-18 18:04:00 +01:00
calixteman
5bc3cb839b
Merge pull request #19512 from calixteman/signature_test2
[Editor] Add two integration tests for the signature feature
2025-02-18 18:03:00 +01:00
Jonas Jenwald
426c730e11
Merge pull request #19504 from Snuffleupagus/eslint-fix-arrow-body-style
Fix all outstanding ESLint `arrow-body-style` warnings
2025-02-18 17:52:36 +01:00
Calixte Denizet
3fe55baa5e [Editor] Add two integration tests for the signature feature
- one test about adding a drawn signature
- an other one about adding a signature extracted from an image.
2025-02-18 15:24:03 +01:00
calixteman
a857ca3261
Merge pull request #19511 from calixteman/editor_dnd_image
[Editor] Wait for switching to stamp mode before adding a new editor when dnd'ing an image
2025-02-18 13:16:30 +01:00
Calixte Denizet
9984afe6a6 [Editor] Wait for switching to stamp mode before adding a new editor when dnd'ing an image
When dnd'ing an image with the FreeText mode enabled, the image wasn't correctly added.
2025-02-18 10:53:34 +01:00
calixteman
203452c170
Merge pull request #19508 from calixteman/issue19505
[JS] Skip throwing actions
2025-02-17 22:57:14 +01:00
calixteman
d0107566ba
Merge pull request #19506 from calixteman/bug1948741
[Editor] Scale the signature editor when it's too large (bug 1948741)
2025-02-17 21:59:46 +01:00
Calixte Denizet
8f9232202f [JS] Skip throwing actions
It fixes #19505.

We were invaliding throwing actions (in setting event.rc to false) and all the event process was stopped.
Now we're just dumping the exception in the console: the action is skipped and event.rc is not set
else the input fields aren't updated wit KeyStroke actions.
2025-02-17 21:58:20 +01:00
calixteman
a0bdd67bc3
Merge pull request #19507 from calixteman/bug1948771
[Editor] Add a scrollbar to the signature doorhanger when it's overflowing (bug 1948771)
2025-02-17 21:31:01 +01:00
Calixte Denizet
cde7d83319 [Editor] Add a scrollbar to the signature doorhanger when it's overflowing (bug 1948771) 2025-02-17 21:09:56 +01:00
Calixte Denizet
3fc6b1321f [Editor] Scale the signature editor when it's too large (bug 1948741) 2025-02-17 20:20:26 +01:00
Jonas Jenwald
36979e9eb2 Fix all outstanding ESLint arrow-body-style warnings
Currently this rule is disabled in a number of spots across the code-base, and unless absolutely necessary we probably shouldn't disable linting, so let's just update the code to fix all the outstanding cases.
2025-02-17 15:45:44 +01:00
Jonas Jenwald
affce70a09
Merge pull request #19503 from Snuffleupagus/web-rm-some-eslint-disable
Remove a few `eslint-disable` statements in the `web/` folder
2025-02-17 15:21:57 +01:00
calixteman
2df0f925b9
Merge pull request #19500 from calixteman/test_signature1
[Editor] Add two integration tests for the signature UI
2025-02-17 14:48:07 +01:00
Calixte Denizet
b8993cfcc8 [Editor] Add two integration tests for the signature UI 2025-02-17 13:58:54 +01:00
Jonas Jenwald
a2d15ceb84 Remove a few eslint-disable statements in the web/ folder
These cases could be easily re-written to avoid having to disable ESLint rules.
2025-02-17 13:40:09 +01:00
Tim van der Meij
33c97570f5
Merge pull request #19499 from Snuffleupagus/useWorkerFetch-ensure-boolean
Ensure that the `useWorkerFetch` fallback value is always a boolean
2025-02-16 14:50:29 +01:00
Jonas Jenwald
06e4580f8b Ensure that the useWorkerFetch fallback value is always a boolean
If either of the factory-urls are missing or invalid, the fallback value would currently become `useWorkerFetch === null`.
While that is obviously a falsy value, which means that the code still works as intended, we should ensure that this is consistent.
2025-02-16 14:04:30 +01:00
Jonas Jenwald
c2e33307b1 Introduce some URL.parse() usage in the code-base
This (fairly new) static method allows parsing URLs without having to wrap `new URL(...)` calls within `try...catch` blocks, thus simplifying the code; see https://developer.mozilla.org/en-US/docs/Web/API/URL/parse_static

For older browsers/environments the functionality will be polyfilled, but *only* in `legacy` builds, via `core-js`; see https://github.com/zloirock/core-js?tab=readme-ov-file#url-and-urlsearchparams

*Please note:* This is currently limited to the `src/`- and `web/`-folders, such that we don't break development/testing, since the functionality is not available in all Node.js versions that we support; see https://developer.mozilla.org/en-US/docs/Web/API/URL/parse_static#browser_compatibility
2025-02-15 19:10:36 +01:00
Jonas Jenwald
3f15e0c469
Merge pull request #19495 from Snuffleupagus/issue-19494
Check more of the stream when looking for commands after inline image (issue 19494)
2025-02-15 17:05:59 +01:00
Jonas Jenwald
8dec353c7a
Merge pull request #19496 from Snuffleupagus/shorter-#buildObjectKey
Shorten the `CipherTransformFactory.prototype.#buildObjectKey` method
2025-02-15 17:03:35 +01:00
Jonas Jenwald
65df1d336f Check more of the stream when looking for commands after inline image (issue 19494)
Currently we only check `followingBytes`, which turns out to be too short to find e.g. valid transform (cm) commands with decimal arguments.
2025-02-15 15:14:47 +01:00
Jonas Jenwald
a722ca4de5 Shorten the CipherTransformFactory.prototype.#buildObjectKey method
- Use `TypedArray.prototype.set()` rather than a manual loop when building the `key`.

 - Use an existing local variable to avoid re-computing the length of the `encryptionKey`.
2025-02-15 13:00:42 +01:00
calixteman
92ff26e4ff
Merge pull request #19427 from calixteman/bug1946181
Add some unicode mapping for ligatures when writing the cmap table in the font (bug 1946181)
2025-02-14 17:46:07 +01:00
Jonas Jenwald
144e5fe196
Merge pull request #19476 from Snuffleupagus/issue-19474
Search for destinations in both /Names and /Dests dictionaries (issue 19474)
2025-02-14 16:05:36 +01:00
Jonas Jenwald
33cba30bdb Search for destinations in both /Names and /Dests dictionaries (issue 19474)
Currently we only use either one of them, preferring the NameTree when it's available.
2025-02-14 15:49:05 +01:00
Jonas Jenwald
c69282a64f
Merge pull request #19487 from Snuffleupagus/OverlayManager-closeIfActive
Add a new `closeIfActive` method in the `OverlayManager` class
2025-02-14 15:46:13 +01:00
Jonas Jenwald
96f5dcbd91 Add a new closeIfActive method in the OverlayManager class
It's now pretty common that we only want to close a `dialog` *if* it's currently active, to avoid throwing errors, and this new method provides a shorter and more convenient way to achieve that.
2025-02-14 15:43:00 +01:00
calixteman
6258a77bd7
Merge pull request #19486 from calixteman/signature_edit_desc
[Editor] Add the possibility to change a signature description (bug 1948116)
2025-02-14 15:41:45 +01:00
Jonas Jenwald
6ad56135c9
Merge pull request #19481 from Snuffleupagus/GenericL10n-fetch-bundles-parallel
[GenericL10n] Fetch the language bundles in parallel to reduce load time
2025-02-14 15:33:29 +01:00
Jonas Jenwald
c81a404138
Merge pull request #19475 from Snuffleupagus/injectLinkAnnotations-method-event
Move the auto-link handling into its own `PDFPageView` helper-method, and dispatch a "linkannotationsadded" event
2025-02-14 14:05:06 +01:00
Calixte Denizet
1d82b2ce94 [Editor] Add the possibility to change a signature description (bug 1948116) 2025-02-14 14:00:45 +01:00
Jonas Jenwald
a877493826
Merge pull request #19485 from Snuffleupagus/SignatureManager-Array-from-shorten
Slightly shorten an `Array.from` usage in the `SignatureManager` class
2025-02-14 10:44:37 +01:00
Jonas Jenwald
7dbf8c8e4b Slightly shorten an Array.from usage in the SignatureManager class
This should be equivalent to the old code, and besides being ever so slightly shorter I'm also finding it a little bit easier to read at a glance.
2025-02-13 20:04:02 +01:00
calixteman
74a7576c2c
Merge pull request #19478 from calixteman/signature_init
[Editor] Populate the 'Add signature' menu with the saved signatures (bug 1947828)
2025-02-13 16:46:01 +01:00
Calixte Denizet
68451fe17e [Editor] Populate the 'Add signature' menu with the saved signatures (bug 1947828) 2025-02-13 15:59:57 +01:00
Jonas Jenwald
8d8e25c89d [GenericL10n] Fetch the language bundles in parallel to reduce load time
For non `en-US` locales this will, ever so slightly, shorten the time it takes to load and parse the language bundles.
2025-02-13 11:53:45 +01:00
Jonas Jenwald
8727a04ae5 Move the auto-link handling into its own PDFPageView helper-method, and dispatch a "linkannotationsadded" event
This is similar to a lot of existing functionality for various layers, and the new event might be helpful in e.g. the integration-tests.
2025-02-12 14:57:44 +01:00
Jonas Jenwald
d6f63d0e4b
Merge pull request #19469 from Snuffleupagus/bug-1947248
[api-major] Apply the `userUnit` using CSS, to fix the text/annotation layers (bug 1947248)
2025-02-11 23:13:46 +01:00
calixteman
5b13ea14c2
Merge pull request #19472 from calixteman/update_button_hover_color
Fix the color of the background button when hovering it
2025-02-11 22:42:51 +01:00
Calixte Denizet
6950a312aa Fix the color of the background button when hovering it 2025-02-11 20:15:17 +01:00
Jonas Jenwald
e2d2263788
Merge pull request #19464 from Snuffleupagus/autolinking-catch
Catch and ignore any errors during auto-linking parsing (PR 19110 follow-up)
2025-02-11 20:06:33 +01:00
Jonas Jenwald
bd05b255fa [api-major] Apply the userUnit using CSS, to fix the text/annotation layers (bug 1947248)
Rather than modifying the "raw" dimensions of the page, we'll instead apply the `userUnit` as an *additional* scale-factor via CSS.

*Please note:* It's not clear to me if this solution is fully correct either, or if there's other problems with it, but it at least *appears* to work.

---

With these changes, the following CSS variables are now assumed to be available/set as necessary: `--total-scale-factor`, `--scale-factor`, `--user-unit`, `--scale-round-x`, and `--scale-round-y`.
2025-02-11 14:36:06 +01:00
calixteman
e3cca6d513
Merge pull request #19425 from calixteman/signature_save
[Editor] Add the possibility to compress/decompress the signature data in  order to store them in the logins storage in Firefox (bug 1946171)
2025-02-10 19:20:32 +01:00
Calixte Denizet
6b95095e14 Add the possibility to compress/decompress the signature data in order to store them in the logins storage in Firefox (bug 1946171) 2025-02-10 19:09:51 +01:00
Jonas Jenwald
29fbed384a
Merge pull request #19461 from Snuffleupagus/autolinking-lazy-borderStyle
Create the `borderStyle` of inferred links lazily (PR 19110 follow-up)
2025-02-10 16:32:12 +01:00
Jonas Jenwald
357ff4afde Catch and ignore any errors during auto-linking parsing (PR 19110 follow-up)
While investigating a bug, that I've not yet had time to fully investigate and report, I found that if there's ever an error thrown from the `Autolinker` class it'll prevent the annotationEditorLayer from rendering *and* the renderTask itself will be treated as having failed.
2025-02-10 16:28:02 +01:00
Jonas Jenwald
de1c2146b8
Merge pull request #19458 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-02-10 12:47:56 +01:00
Jonas Jenwald
fba5f3c237 Create the borderStyle of inferred links lazily (PR 19110 follow-up)
Given that most inferred links will overlap existing LinkAnnotations, creating a lot of unused `borderStyle` objects seem unnecessary.
Hence we can move that into the `AnnotationLayer.prototype.addLinkAnnotations` method instead, which also allows us to slightly reduce the API-surface.
2025-02-10 11:53:22 +01:00
Jonas Jenwald
e608daed9f
Merge pull request #19460 from Snuffleupagus/autolinking-check-annotationLayer
Check that the annotationLayer is still active before injecting inferred links (PR 19110 follow-up)
2025-02-10 10:08:47 +01:00
Jonas Jenwald
81e99da440 Check that the annotationLayer is still active before injecting inferred links (PR 19110 follow-up)
This issue is quite difficult to trigger reliably, however it's possible for rendering to have been aborted and thus for the annotationLayer to have been removed once we're invoking `injectLinkAnnotations`. In that case, an Error is thrown[1].

The way that I'm able to *intermittently* trigger this is by:
 - Loading http://localhost:8888/web/viewer.html?file=/test/pdfs/pdf.pdf#disableHistory=true
 - Enable "Wrapped Srolling" mode.
 - Quickly zoom out, to the minimum zoom level.

---
[1]
```
renderView: TypeError: can't access property "injectLinkAnnotations", this.annotationLayer is null
    resultPromise http://localhost:8888/web/pdf_page_view.js:1116
    draw http://localhost:8888/web/pdf_page_view.js:1099
    renderView http://localhost:8888/web/pdf_rendering_queue.js:196
    forceRendering http://localhost:8888/web/pdf_viewer.js:1849
    promise callback*forceRendering http://localhost:8888/web/pdf_viewer.js:1848
    renderHighestPriority http://localhost:8888/web/pdf_rendering_queue.js:79
    renderView http://localhost:8888/web/pdf_rendering_queue.js:198
    renderView http://localhost:8888/web/pdf_rendering_queue.js:197
    forceRendering http://localhost:8888/web/pdf_viewer.js:1849
    promise callback*forceRendering http://localhost:8888/web/pdf_viewer.js:1848
    renderHighestPriority http://localhost:8888/web/pdf_rendering_queue.js:79
    renderView http://localhost:8888/web/pdf_rendering_queue.js:198
    renderView http://localhost:8888/web/pdf_rendering_queue.js:197
    forceRendering http://localhost:8888/web/pdf_viewer.js:1849
    promise callback*forceRendering http://localhost:8888/web/pdf_viewer.js:1848
    renderHighestPriority http://localhost:8888/web/pdf_rendering_queue.js:79
    renderView http://localhost:8888/web/pdf_rendering_queue.js:198
    renderView http://localhost:8888/web/pdf_rendering_queue.js:197
    forceRendering http://localhost:8888/web/pdf_viewer.js:1849
    promise callback*forceRendering http://localhost:8888/web/pdf_viewer.js:1848
    renderHighestPriority http://localhost:8888/web/pdf_rendering_queue.js:79
    renderView http://localhost:8888/web/pdf_rendering_queue.js:198
    renderView http://localhost:8888/web/pdf_rendering_queue.js:197
    forceRendering http://localhost:8888/web/pdf_viewer.js:1849
    promise callback*forceRendering http://localhost:8888/web/pdf_viewer.js:1848
    renderHighestPriority http://localhost:8888/web/pdf_rendering_queue.js:79
    update http://localhost:8888/web/pdf_viewer.js:1677
    onScaleChanging http://localhost:8888/web/app.js:2550
    dispatch http://localhost:8888/web/event_utils.js:115
    #setScaleUpdatePages http://localhost:8888/web/pdf_viewer.js:1363
    #setScale http://localhost:8888/web/pdf_viewer.js:1389
    updateScale http://localhost:8888/web/pdf_viewer.js:2263
    updateZoom http://localhost:8888/web/app.js:814
    zoomOut http://localhost:8888/web/app.js:827
    onKeyDown http://localhost:8888/web/app.js:2780
    bindWindowEvents http://localhost:8888/web/app.js:2097
    initialize http://localhost:8888/web/app.js:262
    run http://localhost:8888/web/app.js:704
    webViewerLoad http://localhost:8888/web/viewer.js:294
    <anonymous> http://localhost:8888/web/viewer.js:305
pdf_rendering_queue.js:204:21
```
2025-02-10 09:19:04 +01:00
Jonas Jenwald
86ae2ca01c
Merge pull request #19449 from Snuffleupagus/autolinking-URL-fuzzy-match
Ignore the URLs when checking if inferred links overlap existing LinkAnnotations (PR 19110 follow-up)
2025-02-09 22:51:37 +01:00
Jonas Jenwald
37ef0b4a86 Ignore the URLs when checking if inferred links overlap existing LinkAnnotations (PR 19110 follow-up)
*Note:* For the issue mentioned on Matrix it'll obviously still make sense to improve the regular expression to detect more URL edge-cases.

However it occurred to me that even once that particular case is fixed there'll always be a risk that inferred links could overlap, and effectively block, the actual LinkAnnotations.
Hence this patch removes the URL comparison to ensure that overlapping inferred links will always be ignored.
2025-02-09 22:06:58 +01:00
Tim van der Meij
58a60b8959
Update translations to the most recent versions 2025-02-09 18:59:00 +01:00
Tim van der Meij
d2a07dcac6
Update dependencies to the most recent versions
Moreover, fix the linting issues (using `npx gulp lint --fix`) that are
found by the new versions of the linting tools.
2025-02-09 18:58:26 +01:00
Tim van der Meij
d88035525c
Merge pull request #19457 from timvandermeij/integration-tests-ink-isolate
Isolate the ink editor integration tests
2025-02-09 18:10:29 +01:00
Jonas Jenwald
b4a6b1ba0b
Merge pull request #19456 from Snuffleupagus/more-TypedArray-fill
Replace a couple of loops with `TypedArray.prototype.fill()`
2025-02-09 17:45:17 +01:00
calixteman
6862e84daa
Merge pull request #19437 from calixteman/signature_save_print1
[Editor] Add the ability to print and save some newly added signatures (bug 1946795)
2025-02-09 17:13:01 +01:00
Tim van der Meij
6d9ff34611
Isolate the ink editor integration tests
To avoid being able to introduce dependencies between tests, and to
bring existing dependencies to the surface, this commit makes sure that
we close the document between tests so that we can't accidentally rely
on state set by a previous test. This prevents multiple tests from
failing if one of them fails and makes debugging easier by being able to
run each test on their own independent of other tests.

This commit, combined with the previous one, is enough to make the ink
editor integration test suite pass consistently if random mode in
Jasmine is enabled, proving that the tests are fully isolated now.
2025-02-09 16:46:58 +01:00
Tim van der Meij
ced1268ec3
Remove the dependency between two ink editor integration tests
The second test of the basic operations block for the ink editor
depends on the first test to work. This becomes visible if we only run
the second test, using `fit`, which always fails with:

`ProtocolError: Waiting for selector '.annotationEditorLayer' failed:
Runtime.callFunctionOn timed out. Increase the 'protocolTimeout' setting
in launch/connect calls for a higher timeout if needed.`

The problem is that the second test doesn't enable the ink editor and
relies on the first test having done that already (because we don't
close the document between tests yet). This commit fixes the issue by
unconditionally enabling the ink editor in the second test to remove the
dependency between the two tests so they both pass in isolation.
2025-02-09 16:46:58 +01:00
Jonas Jenwald
294fa3e4e6 Replace a couple of loops with TypedArray.prototype.fill()
When you want to initialize a TypedArray with a non-zero value for all elements the `fill`-method is simpler than manually looping through it.
2025-02-09 16:24:45 +01:00
Tim van der Meij
c1035e4356
Merge pull request #19454 from Snuffleupagus/Chrome-110
[api-minor] Update the minimum supported Google Chrome version to 110
2025-02-09 15:59:50 +01:00
Jonas Jenwald
ad1c79e6af [api-minor] Update the minimum supported Google Chrome version to 110
This patch updates the minimum supported browsers as follows:
 - Google Chrome 110, which was released on 2023-02-07; see https://chromereleases.googleblog.com/2023/02/stable-channel-update-for-desktop.html

Note that nowadays we usually try, where feasible and possible, to support browsers that are about two years old. By limiting support to only "recent" browsers we reduce the risk of holding back improvements of the *built-in* Firefox PDF Viewer, and also (significantly) reduce the maintenance/support burden for the PDF.js contributors.

*Please note:* As always, the minimum supported browser version assumes that a `legacy`-build of the PDF.js library is being used; see https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
2025-02-09 13:33:55 +01:00
Tim van der Meij
8ba8e75d6c
Merge pull request #19446 from Snuffleupagus/shorten-MeshStreamReader-readBits
Shorten the `MeshStreamReader.prototype.readBits` method a little bit
2025-02-09 12:57:53 +01:00
Tim van der Meij
739324d77e
Merge pull request #19447 from Snuffleupagus/fix-integrationtest-inferred_link_
Check for the correct link-id prefix in "must not add links when unnecessary" integration-test (PR 19110 follow-up)
2025-02-09 12:55:10 +01:00
Tim van der Meij
1921aefccf
Merge pull request #19450 from Snuffleupagus/crypto-CipherTransform-iv-getRandomValues
Use `crypto.getRandomValues` unconditionally in the `src/core/crypto.js` file
2025-02-09 12:53:27 +01:00
Jonas Jenwald
7919f4e84f Use crypto.getRandomValues unconditionally in the src/core/crypto.js file
This functionality is now available in all browsers/environments that we support, please see https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#browser_compatibility
2025-02-09 11:42:17 +01:00
Jonas Jenwald
6eec20afc0 Check for the correct link-id prefix in "must not add links when unnecessary" integration-test (PR 19110 follow-up)
Currently this test-case would never fail, even if the actual implementation was broken, since it checks for a link-id prefix that we're not using.
2025-02-08 15:42:31 +01:00
Jonas Jenwald
36522d85cc Shorten the MeshStreamReader.prototype.readBits method a little bit
- Use a `BaseStream`-instance method to directly get the int32 value.

 - Use local variables more.
2025-02-08 11:17:35 +01:00
Jonas Jenwald
72339dc561
Merge pull request #19399 from Snuffleupagus/TextLayer-#getAscent-simplify
[api-minor] Simplify the `TextLayer.#getAscent` fallback (PR 12896 follow-up)
2025-02-08 00:01:40 +01:00
Calixte Denizet
24417a1a0b [Editor] Add the ability to print and save some newly added signatures (bug 1946795) 2025-02-07 23:07:27 +01:00
Tim van der Meij
b43efdd545
Merge pull request #19436 from Snuffleupagus/api-FetchBinaryData
Combine the main-thread message handlers for CMap-, StandardFontData-, and Wasm-files
2025-02-07 21:13:58 +01:00
Tim van der Meij
01148d35bc
Merge pull request #19423 from Snuffleupagus/annotation-more-getPdfColorArray
Use the `getPdfColorArray` helper more in the `src/core/annotation.js` file
2025-02-07 21:05:52 +01:00
Tim van der Meij
5b7bc27c46
Merge pull request #19419 from Snuffleupagus/blank_issues_enabled-false
Disable the "Blank issue" alternative when using the GitHub "New issue"-button
2025-02-07 20:52:26 +01:00
Jonas Jenwald
88e5da1e37 Combine the main-thread message handlers for CMap-, StandardFontData-, and Wasm-files
Currently we have three separate and virtually identical message handlers for this data, which can easily be combined into a single message handler instead.
2025-02-07 14:33:15 +01:00
calixteman
651d712109
Merge pull request #19433 from calixteman/signature_icon
[Editor] Add an icon for the signature tool and move it before the highlight one
2025-02-06 21:59:27 +01:00
Jonas Jenwald
7d9cfbf597
Merge pull request #19432 from Snuffleupagus/isSyncFontLoadingSupported-FeatureTest
Use the `FeatureTest` helper in the `src/display/font_loader.js` file
2025-02-06 21:36:28 +01:00
Calixte Denizet
5ee7307bf5 [Editor] Add an icon for the signature tool and move it before the highlight one 2025-02-06 20:58:59 +01:00
Jonas Jenwald
33f3506842 Use the FeatureTest helper in the src/display/font_loader.js file 2025-02-06 20:45:18 +01:00
Jonas Jenwald
41a918b0fe
Merge pull request #19430 from Snuffleupagus/Fluent-PLATFORM
[GENERIC viewer] Add Fluent `PLATFORM` function (PR 19414 follow-up)
2025-02-06 20:07:07 +01:00
calixteman
16155fd801
Merge pull request #19431 from Snuffleupagus/var--save-warning-color
Fix `--save-warning-color` CSS variable typo (PR 19414 follow-up)
2025-02-06 19:09:20 +01:00
Jonas Jenwald
314928ffd7 Fix --save-warning-color CSS variable typo (PR 19414 follow-up) 2025-02-06 19:06:04 +01:00
Jonas Jenwald
d5d3d8b3f7 [GENERIC viewer] Add Fluent PLATFORM function (PR 19414 follow-up)
This patch extends the `FeatureTest.platform` getter to provide the necessary information, and uses that one to implement a Fluent `PLATFORM` function based on: https://searchfox.org/mozilla-central/rev/d1fbe983fb7720f0a4aca0e748817af11c1a374e/intl/l10n/rust/fluent-ffi/src/bundle.rs#81-98
2025-02-06 18:59:35 +01:00
calixteman
f1152f5caf
Merge pull request #19429 from calixteman/autolinking_firefox
Enable autolinking in Firefox (bug 1019475)
2025-02-06 17:47:55 +01:00
Calixte Denizet
76c06c5996 Enable autolinking in Firefox (bug 1019475) 2025-02-06 17:02:54 +01:00
calixteman
2d773cb773
Merge pull request #19110 from ryzokuken/autolink-demo
Enable automatic URL linking (bug 1019475)
2025-02-06 16:53:48 +01:00
calixteman
08663f715b
Merge pull request #19414 from calixteman/signature_dialog2
[Editor] Add a new dialog for the signature editor (bug 1945574)
2025-02-06 16:20:01 +01:00
Calixte Denizet
185ec1faf6 Add some unicode mapping for ligatures when writing the cmap table in the font (bug 1946181) 2025-02-06 10:51:15 +01:00
Calixte Denizet
fa25ab9c13 [Editor] Add a new dialog for the signature editor (bug 1945574) 2025-02-05 23:00:38 +01:00
Ujjwal Sharma
61ba1ea48c Enable automatic URL linking
Automatically detect links in the text content of a file and automatically
generate link annotations at the appropriate locations to achieve
automatic link detection and hyperlinking.
2025-02-05 16:56:54 +01:00
Jonas Jenwald
925071ab46 Use the getPdfColorArray helper more in the src/core/annotation.js file
While the file-size reduction is obviously tiny, it should never hurt to remove code duplication.
2025-02-05 11:37:32 +01:00
Jonas Jenwald
0b118efc26 Disable the "Blank issue" alternative when using the GitHub "New issue"-button
With recent changed made to the GitHub issues-UI the "Blank issue" alternative is now showing up quite prominently, which can easily negate the point of our bug/feature templates and lead to incomplete issues being filed.
2025-02-04 15:19:04 +01:00
Jonas Jenwald
90a5c37cb0
Merge pull request #19416 from Snuffleupagus/getFactoryUrlProp
[api-minor] Add more validation for the `cMapUrl`, `standardFontDataUrl`, and `wasmUrl` parameters
2025-02-04 12:48:21 +01:00
Jonas Jenwald
212388a980
Merge pull request #19415 from Snuffleupagus/dist-wasm
Bundle wasm-files in `pdfjs-dist` (PR 19329 follow-up)
2025-02-04 11:41:00 +01:00
Jonas Jenwald
696c6c626b Include the OpenJPEG license files
This is consistent with the handling of CMaps and StandardFontData.
2025-02-04 10:39:38 +01:00
Jonas Jenwald
fa3358baf9 [api-minor] Add more validation for the cMapUrl, standardFontDataUrl, and wasmUrl parameters
Given that we now have a few different factory-url parameters, we introduce a helper function for parsing them.

*Please note:* These parameters have always been documented as requiring a trailing slash[1], which we can now easily enforce during the `getDocument`-call.

---
[1] I recall that we've occasionally seen issues because users miss that detail, and the new Error should hopefully be more easily actionable than one thrown during rendering/parsing.
2025-02-04 10:27:31 +01:00
Jonas Jenwald
de79996574 Bundle wasm-files in pdfjs-dist (PR 19329 follow-up) 2025-02-04 10:22:26 +01:00
Tim van der Meij
d1f62509e5
Merge pull request #19410 from timvandermeij/integration-tests-freetext
Centralize the editor selector definitions in the freetext editor integration tests
2025-02-02 19:41:13 +01:00
Tim van der Meij
9a6511127a
Put waitForSelector options on a single line in the editor integration tests
This pattern was already followed quite consistently outside of the
freetext editor integration tests, so this commit aligns the remaining
places for consistency. This also helps to make the tests more compact
and to reduce the number of changes in follow-up changes.
2025-02-02 17:20:14 +01:00
Tim van der Meij
e95a26dc1d
Centralize the editor selector definitions in the freetext 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
freetext 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-02-02 17:18:14 +01:00
Tim van der Meij
bdbd9a317f
Merge pull request #19408 from Snuffleupagus/rm-popup-color-mix-fallback
Remove the `color-mix` fallback used with PopupAnnotations
2025-02-02 14:22:08 +01:00
Tim van der Meij
944602a7d5
Merge pull request #19405 from timvandermeij/integration-tests-highlight
Centralize the editor selector definitions in the highlight editor integration tests
2025-02-02 14:19:23 +01:00
Tim van der Meij
f9d3f699a7
Merge pull request #19404 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-02-02 14:19:06 +01:00
Jonas Jenwald
9752d88241
Merge pull request #19407 from hamirmahal/master
Replace uninformative README badge (issue 19406)
2025-02-02 11:31:49 +01:00
Jonas Jenwald
9f62a88c38 Remove the color-mix fallback used with PopupAnnotations
This CSS feature is now available in *most* browsers that we support, with old Chromium-based browsers being the only exception; please see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-mix#browser_compatibility

From this data we see that the feature in question has been supported since Chrome 111, which was released on 2023-03-01 (i.e. almost two years ago).

Please note that we've never guaranteed that all features and functionality will be available in the oldest supported browsers.
Furthermore, even with the `color-mix` fallback removed PopupAnnotations will still function just as before but may render with the default color (defined in the CSS-file) rather than the one specified in the PDF document.
2025-02-02 10:41:35 +01:00
Hamir Mahal
d8b6f1138f
Replace uninformative README badge (issue 19406) 2025-02-01 15:32:09 -08:00
Tim van der Meij
8babcded5d
Centralize the editor selector definitions in the highlight 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
highlight 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-02-01 19:23:42 +01:00
Tim van der Meij
0326814a1e
Update translations to the most recent versions 2025-02-01 18:37:01 +01:00
Tim van der Meij
c0957986b7
Update dependencies to the most recent versions 2025-02-01 18:35:56 +01:00
Tim van der Meij
de191d2a12
Merge pull request #19402 from Snuffleupagus/AnnotationElement-width-height-getters
Add width/height getters in the `AnnotationElement` class
2025-02-01 16:17:59 +01:00
Jonas Jenwald
2fd1344ece Add width/height getters in the AnnotationElement class
This is similar to PR 19397, but for the main-thread code, and helps to slightly shorten the code.
2025-02-01 13:20:15 +01:00
Jonas Jenwald
c8be02f2a7 [api-minor] Simplify the TextLayer.#getAscent fallback (PR 12896 follow-up)
At the time of PR 12896 the `fontBoundingBox{Ascent, Descent}` properties were not yet available by default in Fírefox, however that's no longer the case since Firefox 116; please see https://bugzilla.mozilla.org/show_bug.cgi?id=1801198.

Hence this patch which replaces the "full" fallback with a warning and uses the `ascent`/`descent` values from the fonts in the PDF document (as we did previously). Obviously the TextLayer won't look as good in that case, but it's a simpler and shorter solution.
2025-02-01 10:11:57 +01:00
Tim van der Meij
b48717a99e
Merge pull request #19397 from Snuffleupagus/Annotation-width-height-getters
Add width/height getters in the `Annotation` class
2025-01-31 16:14:02 +01:00
calixteman
938add1bb0
Merge pull request #19396 from calixteman/update_signature_draw
[Editor] Add some functions in order to extract contours from text and to generate a drawing from a drawn signature
2025-01-31 15:44:00 +01:00
Calixte Denizet
20992e87f5 [Editor] Add some functions in order to extract contours from text and to generate a drawing from a drawn signature 2025-01-31 14:59:58 +01:00
Jonas Jenwald
6f2966628c Add width/height getters in the Annotation class
Currently we're manually computing the width/height of the /Rect-entry in a number of spots throughout the worker-thread Annotation code, which these new getters help avoid.
2025-01-31 13:21:53 +01:00
calixteman
58c8f069f7
Merge pull request #19395 from calixteman/fix_overlay_manager
Avoid to remove the active overlay when a cancelled dialog (like the file picker) was called from a dialog
2025-01-30 16:51:26 +01:00
calixteman
ec7270c546
Merge pull request #19394 from calixteman/mv_supported_img_types
Move the array containing the supported image mime types in display_utils
2025-01-30 16:48:13 +01:00
Calixte Denizet
eca1e6c52e Avoid to remove the active overlay when a cancelled dialog (like the file picker) was called from a dialog 2025-01-30 16:13:48 +01:00
Calixte Denizet
2c737bc420 Move the array containing the supported image mime types in display_utils
and make it available for the viewer (it'll be used in the signature UI).
2025-01-30 15:35:17 +01:00
Jonas Jenwald
31deee26b9
Merge pull request #19393 from Snuffleupagus/fewer-hasFieldFlag
Use fewer `hasFieldFlag` calls in the `src/core/annotation.js` file
2025-01-30 15:10:14 +01:00
Jonas Jenwald
d1a0f3e495
Merge pull request #19392 from Snuffleupagus/image-options-init-once
Initialize the image-options, on the worker-thread, once per document
2025-01-30 15:06:25 +01:00
Jonas Jenwald
9e227de3c5 Use fewer hasFieldFlag calls in the src/core/annotation.js file
We lookup a number of field-flags multiple times, which seems unnecessary.
2025-01-30 13:38:57 +01:00
Jonas Jenwald
db53320da8 Initialize the image-options, on the worker-thread, once per document
Currently we're initializing the image-options for every page, which seems unnecessary since it should suffice to do that once per document.

Also, changes the `BasePdfManager` constructor to improve readability/documentation a little bit.
2025-01-30 11:52:15 +01:00
calixteman
42c2b7b657
Merge pull request #19339 from calixteman/signature_tools
[Editor] (WIP) Add a new tool in order to add an handwritten signature to a pdf (bug 1942343)
2025-01-30 10:54:56 +01:00
Calixte Denizet
2f828c7bf4 [Editor] (WIP) Add a new tool in order to add an handwritten signature to a pdf (bug 1942343)
This patch is adding some code in order to extract a drawing as curves from an image.
The algorithm is basically the following:
 - reduce the dimensions
 - make it gray
 - apply a bilateral filter in order to add some blurryness while keeping the edges
 - compute the histogram
 - guess what's the background color which should contain a large majority of the pixels
 - make a binary image
 - extract the contours in using the Suzuki algorithm
 - apply the Douglas-Peucker algorithm in order to reduce the number of points

The algorithm is improvable but it should work pretty well if there's a clear difference between
the background and the drawing.
In a v2 we could use a ML model in order to improve the extraction.

There's few changes related to the UI in order to make the tool usable, but they're very basic
for the moment.
2025-01-29 21:52:14 +01:00
Jonas Jenwald
9bc4331485
Merge pull request #19390 from Snuffleupagus/issue-19389
Support the password field-flag in TextWidgetAnnotation (issue 19389)
2025-01-29 14:41:19 +01:00
Jonas Jenwald
6f2706fad6 Support the password field-flag in TextWidgetAnnotation (issue 19389) 2025-01-29 12:40:09 +01:00
Jonas Jenwald
786ac2fe01
Merge pull request #19388 from Snuffleupagus/readInt16
Introduce a `readInt16` helper function in the `src/core/core_utils.js` file
2025-01-29 11:42:59 +01:00
Jonas Jenwald
237a17ad56 Introduce a readInt16 helper function in the src/core/core_utils.js file
Rather than manually repeating code needed to get an int16, we can move and re-use an existing helper function instead.
2025-01-29 10:14:23 +01:00
Jonas Jenwald
b0b9552216
Merge pull request #19384 from Snuffleupagus/isNumberArray-fix-BigInt-check
Handle *empty* BigInt64Array/BigUint64Array in the `isNumberArray` helper
2025-01-28 10:05:01 +01:00
Jonas Jenwald
6281a89778 Handle *empty* BigInt64Array/BigUint64Array in the isNumberArray helper
The current checks would accidentally allow *empty* BigInt64Array/BigUint64Array, which we can fix by instead checking directly for those types.
This should be fine since those types are available in all environments that we support, see:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array#browser_compatibility
2025-01-27 12:57:47 +01:00
Tim van der Meij
4f1078dc63
Merge pull request #19368 from Snuffleupagus/rm-delayed-cleanup
[api-minor] Simplify clean-up of page resources after rendering
2025-01-26 16:54:43 +01:00
Tim van der Meij
09a0a0f06f
Merge pull request #19358 from Snuffleupagus/Node-enable-web_pdfjsLib
Enable the "checks that the viewer re-exports the expected API functionality" unit-test in Node.js
2025-01-26 16:45:51 +01:00
Tim van der Meij
329c3d1d71
Merge pull request #19381 from Snuffleupagus/rm-isInEditingMode
Remove unused `isInEditingMode` method (PR 19311 follow-up)
2025-01-26 16:44:21 +01:00
Tim van der Meij
3cfc41e54d
Merge pull request #19382 from mozilla/dependabot/npm_and_yarn/undici-6.21.1
Bump undici from 6.19.8 to 6.21.1
2025-01-26 16:43:11 +01:00
dependabot[bot]
85a6c1ea6b
Bump undici from 6.19.8 to 6.21.1
Bumps [undici](https://github.com/nodejs/undici) from 6.19.8 to 6.21.1.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v6.19.8...v6.21.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-26 15:37:40 +00:00
Jonas Jenwald
b02274e5d6 Remove unused isInEditingMode method (PR 19311 follow-up)
This method was added in PR 19311, however it's not actually used anywhere in the code-base.
2025-01-25 13:17:25 +01:00
calixteman
38800715cd
Merge pull request #19373 from Hydraulicus/fix-drawing-beyond-page
[Editor] Add validation for the target element of curve endpoints
2025-01-23 23:54:37 +01:00
Jonas Jenwald
4a513bb52e
Merge pull request #19365 from Snuffleupagus/viewer-component-render-option-objects
[api-major] Change viewer component `render`-methods to take parameter objects
2025-01-23 22:36:28 +01:00
calixteman
f798bade4e
Merge pull request #19338 from avdoseferovic/fix/ink-editor-jumping
[Editor] Don't scroll when drawing (issue 17327)
2025-01-23 22:07:29 +01:00
hydraulicus
104e1c3f90 [Editor] Add validation for the target element of curve endpoints
This patch fixes a bug that caused incorrect curve shapes when an endpoint lies beyond the page boundaries. It adds a check for the endpoint's position, and if it is outside the page, the point is excluded from the shape's coordinates.
2025-01-23 22:05:33 +02:00
Jonas Jenwald
30fa7c3d84
Merge pull request #19372 from Snuffleupagus/mainHighlightColorPicker-toolbar-init
[GENERIC viewer] Re-initialize the viewer-toolbar `ColorPicker` for each PDF document
2025-01-23 18:08:02 +01:00
Jonas Jenwald
342b5e20b4 [GENERIC viewer] Re-initialize the viewer-toolbar ColorPicker for each PDF document
Steps to reproduce this in `master`:
 1. Open https://mozilla.github.io/pdf.js/web/viewer.html
 2. Use the "Open"-button (in the secondaryToolbar), or drag-and-drop, to load another PDF document.
 3. Enable the highlight-editor.
 4. Try to pick a new colour.

Note how it's no longer possible to change the default highlight-colour.
The reason for this is that we're only initializing the viewer-toolbar `ColorPicker` *once*, which doesn't work since every PDF document gets its own `AnnotationEditorUIManager`-instance. To address this we simply need to re-initialize the viewer-toolbar `ColorPicker`, and note that this patch won't affect the Firefox PDF Viewer.
2025-01-23 16:53:31 +01:00
Jonas Jenwald
2132552d71
Merge pull request #19371 from Snuffleupagus/issue-19369
[Editor] Ensure that `highlightSelection` waits until we've fully updated the editing-mode (issue 19369)
2025-01-23 14:39:35 +01:00
Jonas Jenwald
3b4758a400 [Editor] Ensure that highlightSelection waits until we've fully updated the editing-mode (issue 19369)
With the changes in PR 18843 the `AnnotationEditorUIManager.prototype.updateMode` method is now asynchronous, which we need to take into account when dispatching the "annotationeditormodechanged" event.
2025-01-23 13:46:39 +01:00
Jonas Jenwald
9241e1be8c [api-minor] Simplify clean-up of page resources after rendering
After PR 2317, which landed in 2012, we'd immediately clean-up after rendering for pages with large image resources. This had the effect that re-rendering, e.g. after zooming, would force us to re-parse the entire page which could easily lead to bad performance.
In PR 16108, which landed in 2023, we tried to lessen the impact of that by slightly delaying clean-up however that's obviously not a perfect solution (and it increased the complexity of the relevant code).

Furthermore, the condition for this "immediate" clean-up seems a bit arbitrary to me since a page could easily contain a large number of smaller images whose total size vastly exceeds the threshold.

Hence this patch, which suggests that we remove the conditional and delayed clean-up after rendering. Compared to the situation back in 2012, a number of things have improved since:
 - We have *multiple* caches for repeated image-resources on the worker-thread[1], which helps reduce overall memory usage and improves performance.
 - We downsize huge images on the worker-thread, which means that the images we're using on the main-thread cannot be arbitrarily large.
 - The amount of available RAM on devices should be a lot higher, since more than a decade has passed.

A future improvement here, for more resource constrained environments, could be to instead clean-up when actually needed using e.g. `WeakRef`s (see issue 18148).

---
[1] More specifically:
 - `LocalImageCache`, which caches image-data by /Name and /Ref on the `PartialEvaluator.prototype.getOperatorList` level.
 - `RegionalImageCache`, which caches image-data by /Ref on the `PartialEvaluator`-instance (i.e. at the page) level.
 - `GlobalImageCache`, which caches image-data by /Ref globally at the document level.
2025-01-22 12:19:44 +01:00
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
calixteman
877f69886c
Merge pull request #19361 from calixteman/issue19360
Correctly render the glyph outline when it has a stroke pattern
2025-01-21 16:41:26 +01:00
Calixte Denizet
1ccf6ed976 Correctly render the glyph outline when it has a stroke pattern
It fixes #19360.

Each glyph in the test case has a fill and a stroke pattern, so the current transform used
to scale the glyph outline must be the same.
In setting the stroke color to green, I noticed that the last outline contains some non-closed
subpaths, so when generating the glyph outline, every time we 'moveTo', we close the previous
subpath.
2025-01-21 15:30:16 +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
0790d94674 Enable the "checks that the viewer re-exports the expected API functionality" unit-test in Node.js
By also running `gulp generic-legacy` before the Node.js unit-tests, we can enable one more test-case in Node.js environments.
2025-01-20 22:10:36 +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
avdoseferovic
78f612ffef fix: don't scroll when drawing [#17327] 2025-01-18 09:12:03 +00: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
Calixte Denizet
06f72d5662 [Editor] Don't try to use an non-existing canvas when rendering an invisible existing stamp editor
It fixes #19239.

When the canvas isn't existing the editor has no image: it's fine because the editor is invisible.
Once it's made visible, the canvas is set when the annotation layer has been rendered.
2025-01-10 16:05:59 +01:00
Tim van der Meij
45d2e808fd
Update dependencies to the most recent versions 2025-01-09 22:48:00 +01:00
calixteman
f1166f480f
Merge pull request #19309 from calixteman/make_unique_id_draw_layer
[Editor] Set a unique id for each element in the draw layer
2025-01-08 21:56:52 +01:00
Calixte Denizet
586f45b7b8 [Editor] Set a unique id for each element in the draw layer
It avoids any conflict with existing elements when an elment is moved from a page
to an other.
2025-01-08 20:44:15 +01:00
Jonas Jenwald
573e5f54f1
Merge pull request #19305 from Snuffleupagus/issue-18816
Access the bbox/background data correctly in the `MeshShadingPattern` class (issue 18816)
2025-01-08 16:57:14 +01:00
Jonas Jenwald
916fff0e42 Access the bbox/background data correctly in the MeshShadingPattern class (issue 18816)
This appears to have regressed in PR 13808, since it removed the `matrix`-entry from array returned by the `MeshShading.prototype.getIR` method *without* also updating the indexes in the `MeshShadingPattern` constructor.
2025-01-08 15:57:56 +01:00
Jonas Jenwald
115af68f10
Merge pull request #19307 from Snuffleupagus/rm-fuzz-test
Remove the fuzz tests (issue 19297)
2025-01-08 15:57:31 +01:00
Jonas Jenwald
c32d49117c Remove the fuzz tests (issue 19297)
Reasons for removal:

 - These tests never generated any warnings from OSS-Fuzz, in over a year.

 - An error thrown during image decoding will lead to a broken/missing image, not a security problem.

 - These tests rely on the Jazzer.js library, which has a number of problems: It now causes failures in Node.js v23 in the CI tests, it's no longer being maintained upstream, and it lacks support for some (fairly common) CPU architectures.
2025-01-08 15:54:11 +01:00
calixteman
dfbd1d5db6
Merge pull request #19300 from calixteman/remove_useless_css
Remove unused CSS variables
2025-01-07 14:16:03 +01:00
Calixte Denizet
1608e36de6 Remove unused CSS variables 2025-01-07 10:29:23 +01:00
calixteman
e5ad7ef863
Merge pull request #19295 from calixteman/update_moz_toggle.css
Update the toggle-button css after the changes in m-c (bug 1940085)
2025-01-06 19:00:55 +01:00
Calixte Denizet
6db49bedbe Update the toggle-button css after the changes in m-c (bug 1940085) 2025-01-06 18:34:08 +01:00
calixteman
af5beeb861
Merge pull request #19280 from calixteman/issue19274
Let be more tolerant with predefined phone number format
2025-01-06 17:24:05 +01:00
Calixte Denizet
3dd8752283 Let be more tolerant with predefined phone number format
The long US phone number format should be '(999) 999-9999' but the parenthesis
can be omitted or the space replaced with a dash, ...
2025-01-06 15:24:19 +01:00
Tim van der Meij
3001264801
Merge pull request #19291 from timvandermeij/integration-tests-extract-freetext-commit
Implement a commit helper function for the freetext integration tests
2025-01-05 13:20:12 +01:00
Tim van der Meij
26b0d4f749
Merge pull request #19290 from timvandermeij/integration-tests-use-waitforunselectededitor
Use the `waitForUnselectedEditor` integration test helper function more
2025-01-05 13:19:11 +01:00
Tim van der Meij
e57f2c53a4
Implement a commit helper function for the freetext integration tests
The ink editor integration tests already use a helper function for
committing the editor, so this commit mirrors the approach to the
freetext editor 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 (220 lines of code removed);
- it reduces the number of `getEditorSelector` calls (32 calls removed)
  that contained hardcoded IDs, which helps to isolate the tests and to
  simplify follow-up patches.
2025-01-04 20:22:19 +01:00
Tim van der Meij
5126210fff
Use the waitForUnselectedEditor integration test helper function more
This commit applies the `waitForUnselectedEditor` helper function to the
remaining places, that most likely predate the introduction of the
helper function, to deduplicate the code and to have a unified way of
checking if a given editor is unselected.
2025-01-04 20:15:45 +01:00
Tim van der Meij
4d4e1befeb
Merge pull request #19289 from Snuffleupagus/issue-19281
Skip LinkAnnotations when collecting field objects (issue 19281)
2025-01-04 13:32:18 +01:00
Tim van der Meij
3e822399d8
Merge pull request #19278 from Snuffleupagus/more-Dict-iteration
Use `Dict` iteration more (PR 19051 follow-up)
2025-01-04 13:22:51 +01:00
Tim van der Meij
7f5f4d0e66
Merge pull request #19277 from timvandermeij/integration-tests-remove-getselectededitors
Remove the `getSelectedEditors` integration test helper function
2025-01-04 13:21:45 +01:00
Jonas Jenwald
6f062abb76 Skip LinkAnnotations when collecting field objects (issue 19281)
The `/Root/AcroForm/Fields` array contains a "ridiculous" number of LinkAnnotations, which obviously makes no sense since those are not form fields.
To improve performance we'll thus ignore those when collecting the field objects.
2025-01-04 11:54:45 +01:00
Jonas Jenwald
74c1795c9f Use Dict iteration more (PR 19051 follow-up)
There's a few cases where we're looping through the result of `Dict.prototype.getKeys` and then manually look-up the values, which after PR 19051 can be replaced with direct iteration instead.
2025-01-02 15:09:19 +01:00
Tim van der Meij
9d09c56014
Remove the getSelectedEditors integration test helper function
The `getSelectedEditors` function is largely a copy of the `getEditors`
function, with three small differences:

1. `getEditors` allows getting any kind of editor whereas
   `getSelectedEditors` is harcoded to only getting selected editors.
2. `getEditors` returns editor selectors (strings) whereas
   `getSelectedEditors` returns editor IDs (integers).
3. `getSelectedEditors` returns a sorted array of editor IDs whereas
   `getEditors` does not ensure that the array is sorted.

This commit makes the `getEditors` function a drop-in replacement for
the `getSelectedEditors` function to deduplicate the code and to have a
unified way of getting editors.

Note that we don't actually use the contents of the returned array
(only its length), so we can safely change `getEditors` to return a
sorted array of integer editor IDs instead. Sorting the array makes the
return value deterministic, which is a nice property for test stability,
and integer IDs are also easier to handle in test assertions. Note that
the corresponding selector strings can also easily be obtained from the
integer IDs using the `getEditorSelector` function if needed.
2025-01-01 15:58:09 +01:00
Tim van der Meij
5905eb1253
Merge pull request #19276 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-01-01 14:45:30 +01:00
Tim van der Meij
9bd03e81dc
Bump the stable version in pdfjs.config 2025-01-01 14:42:42 +01:00
Jonas Jenwald
f9bea397f8
Merge pull request #19273 from Snuffleupagus/NetworkManager-request-methods
Remove the `requestRange`/`requestFull` methods from the `NetworkManager` class
2024-12-31 16:26:13 +01:00
Jonas Jenwald
01240fda89 Remove the requestRange/requestFull methods from the NetworkManager class
Originally the code in this file was used in both the GENERIC and MOZCENTRAL builds, however that's no longer the case.
Hence we can now directly call `NetworkManager.prototype.request` and remove these old "helper" methods that only had a single call-site each.
2024-12-31 15:57:26 +01:00
Jonas Jenwald
f19b0a1804
Merge pull request #19271 from Snuffleupagus/l10n-update
Update l10n files
2024-12-31 15:42:36 +01:00
Jonas Jenwald
93ce29f136 Update l10n files
Let's ensure that the l10n files are up-to-date before the next release.
2024-12-31 13:51:43 +01:00
Jonas Jenwald
61c3ed47c1
Merge pull request #19269 from Snuffleupagus/image-hasMask
For images that include SMask/Mask entries, ignore an SMask defined in the current graphics state (bug 986450)
2024-12-31 09:07:46 +01:00
Jonas Jenwald
20d5332009 For images that include SMask/Mask entries, ignore an SMask defined in the current graphics state
From section [11.6.4.3 Mask Shape and Opacity](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G10.4848628) in the PDF specification:
 - An image XObject may contain its own *soft-mask image* in the form of a subsidiary image XObject in the `SMask` entry of the image dictionary (see "Image Dictionaries"). This mask, if present, shall override any explicit or colour key mask specified by the image dictionary's `Mask` entry. Either form of mask in the image dictionary shall override the current soft mask in the graphics state.
2024-12-30 14:25:07 +01:00
Tim van der Meij
8a50d2d302
Merge pull request #19259 from Snuffleupagus/more-wrapReason
Reduce duplication when handling "DocException" and "PasswordRequest" messages
2024-12-29 15:47:11 +01:00
Tim van der Meij
91d801728d
Merge pull request #19262 from Snuffleupagus/CompiledFont-assert-fontMatrix
Assert that the `fontMatrix` is always valid in `compileGlyph`
2024-12-29 15:41:04 +01:00
Tim van der Meij
5b94c865e7
Merge pull request #19263 from Snuffleupagus/Type2Compiled-fix-glyphNameMap
Remove the unused `glyphNameMap` parameter from `Type2Compiled`
2024-12-29 15:39:58 +01:00
Tim van der Meij
b4abfec3ac
Merge pull request #19260 from Snuffleupagus/src-core-simplify-ifs
Shorten some `if`-statements in the `src/core/` folder
2024-12-29 15:38:47 +01:00
Tim van der Meij
0c87fce16e
Merge pull request #19258 from Snuffleupagus/pr-15390-followup
Remove mention of Bower from the README (PR 15390 follow-up)
2024-12-29 15:34:13 +01:00
Jonas Jenwald
aba6369638 Remove the unused glyphNameMap parameter from Type2Compiled
As part of the changes in PR 4259, which landed over ten years ago, the `glyphNameMap` property on `Font`-instances was removed.
The reason that this didn't cause any bugs is that we always fallback on `getGlyphsUnicode`, and when using that data we also rely on `StandardEncoding`, hence we should just remove the unused parameter from the `Type2Compiled` constructor.
2024-12-27 14:31:39 +01:00
Jonas Jenwald
2ae5aa08cc Assert that the fontMatrix is always valid in compileGlyph
While [bug 1893645](https://bugzilla.mozilla.org/show_bug.cgi?id=1893645) was fixed some time ago now, it still shouldn't hurt to also assert that the `fontMatrix` is always valid when invoking the `compileGlyph` method.
2024-12-27 11:41:49 +01:00
Jonas Jenwald
3a797317c8 Shorten some if-statements in the src/core/ folder
Thanks to modern JavaScript there's some existing code that can be shortened slightly.
2024-12-26 18:37:25 +01:00
Jonas Jenwald
6bde49a606 Reduce duplication when handling "DocException" and "PasswordRequest" messages
Rather than having to manually implement the exception-handling for the "DocException" message, we can instead re-use (and slightly extend) the existing `wrapReason` function since that one already does what we need.

Furthermore, we can also simplify handling of the "PasswordRequest" message a little bit and again re-use the `wrapReason` function.

Finally, the patch makes the following smaller changes:
 - Avoid needlessly re-creating exceptions in the `wrapReason` function.
 - Use a slightly shorter parameter name in the `wrapReason` function.
 - Remove the unused entries in the `CallbackKind`/`StreamKind` enumerations.
2024-12-26 12:55:49 +01:00
Jonas Jenwald
c58f69dda4 Remove mention of Bower from the README (PR 15390 follow-up) 2024-12-26 11:34:36 +01:00
Tim van der Meij
4547f230ba
Merge pull request #19254 from timvandermeij/refactor-tests
Improve the test folder structure
2024-12-22 20:22:20 +01:00
Tim van der Meij
cdce9c2bee
Update the page title/favicon of the test runner HTML files
This commit makes sure that the font tests are no longer reported as
being unit tests and that the PDF.js logo is shown in the browser tab to
make PDF.js-specific resources/tabs more easily identifyable during e.g.
development.
2024-12-22 14:08:56 +01:00
Tim van der Meij
22ad864cc7
Move the reporter file to the test root folder
The reporter is used in both the unit and the font tests, so this commit
moves it to the test root folder to more clearly indicate that this is a
shared resource and so the font tests don't have to reach into the unit
tests folder to import it (which improves separation).
2024-12-22 14:08:56 +01:00
Tim van der Meij
a43fc32bf3
Move the integration tests boot file to the integration tests folder
This file is specific to the integration tests, so this commit moves it
to bundle the integration test logic a bit better and to match the
unit/font tests in terms of folder structure for consistency.
2024-12-22 14:08:55 +01:00
Tim van der Meij
94f425d2cc
Merge pull request #19246 from Snuffleupagus/add-missing-startWorkerTask
Add missing `startWorkerTask` calls in the "SaveDocument" handler
2024-12-21 18:20:33 +01:00
Jonas Jenwald
ec1a05c104 Add missing startWorkerTask calls in the "SaveDocument" handler
Without these calls we'll not actually wait for saving to complete when document destruction runs; compare with other `WorkerTask`-usage in this file.
While I cannot imagine that this has caused any problems for library users, the code is however not technically correct as-is.
2024-12-21 14:22:18 +01:00
Jonas Jenwald
dd5618ebed
Merge pull request #19243 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-12-20 14:22:51 +01:00
Tim van der Meij
d34ac535f0
Update translations to the most recent versions 2024-12-19 21:17:35 +01:00
Tim van der Meij
af0ffd29fa
Fix vulnerability in the nanoid dependency
This patch is generated with `npm audit fix` and fixes GHSA-mwcw-c2x4-8c55.
2024-12-19 21:14:29 +01:00
Tim van der Meij
d70ede4751
Update dependencies to the most recent versions 2024-12-19 21:13:00 +01:00
Tim van der Meij
7d0fe45443
Merge pull request #19232 from nicolo-ribaudo/scroll-to-search-result
Fix left offset when scrolling to search result
2024-12-19 20:52:46 +01:00
Tim van der Meij
7bd168811c
Merge pull request #19237 from Snuffleupagus/pr-19114-followup-2
Disable the `handle reading ranges with missing/invalid "Content-Range" header` unit-test in Google Chrome (PR 19114 follow-up)
2024-12-19 19:19:20 +01:00
calixteman
2df5d8f3ef
Merge pull request #19238 from calixteman/bug1938087
Take the absolute value of the font size when the annotation contents is in xhtml (bug 1938087)
2024-12-18 17:34:06 +01:00
Jonas Jenwald
0b487774d5
Merge pull request #19236 from Snuffleupagus/issue-19234
Add basic support for non-embedded HelveticaLTStd-Bold fonts (issue 19234)
2024-12-18 17:28:41 +01:00
Calixte Denizet
723ee9bc8c Take the absolute value of the font size when the annotation contents is in xhtml (bug 1938087) 2024-12-18 17:00:45 +01:00
Jonas Jenwald
760c4a0297 Disable the handle reading ranges with missing/invalid "Content-Range" header unit-test in Google Chrome (PR 19114 follow-up)
Note that PR 19212 tried to change the test-server to fix the intermittent failure in Google Chrome, however that unfortunately caused *other* unit-tests to start failing.
As long as this unit-test still runs successfully in Mozilla Firefox that should be enough, and it doesn't seem like a good use of our time to hunt down a bug that only happens in Google Chrome.
2024-12-18 10:15:33 +01:00
Jonas Jenwald
189183aa1a Add basic support for non-embedded HelveticaLTStd-Bold fonts (issue 19234) 2024-12-18 09:39:22 +01:00
Nicolò Ribaudo
4e2aabc5cd
Fix left offset when scrolling to search result
When computing the left offset of the highlighted text, we cannot use
.offsetLeft because the text might have been scaled through CSS, and it
needs to be taken into account.

Use `.getClientRects()`/`.getBoundingClientRect()` instead, which will
return measurements scaled appropriately.
2024-12-16 16:04:13 +01:00
Tim van der Meij
8985d80aef
Merge pull request #19226 from Snuffleupagus/pr-19216-followup
Disable touch-zooming, in the viewer, if `AbortSignal.any` is unsupported (PR 19216 follow-up)
2024-12-15 19:15:32 +01:00
Jonas Jenwald
29c3b7bec5 Disable touch-zooming, in the viewer, if AbortSignal.any is unsupported (PR 19216 follow-up)
This way loading of the *entire* viewer won't break in older browsers that lack `AbortSignal.any` support; see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static#browser_compatibility
2024-12-15 18:13:38 +01:00
Jonas Jenwald
b781b55ea0
Merge pull request #19225 from Snuffleupagus/version-4.10
Bump library version to `4.10`
2024-12-15 16:34:52 +01:00
Jonas Jenwald
780692b226 Bump library version to 4.10 2024-12-15 16:30:31 +01:00
Tim van der Meij
ac81de6ab4
Merge pull request #19224 from Snuffleupagus/pr-18776-followup
[api-minor] Remove deprecated `getDocument` options (PR 18776 follow-up)
2024-12-15 15:52:34 +01:00
Tim van der Meij
322616988e
Merge pull request #19214 from Snuffleupagus/issue-19205
Don't remove trailing regular spaces from the "raw" response headers (issue 19205)
2024-12-15 15:51:20 +01:00
Jonas Jenwald
490e740365 [api-minor] Remove deprecated getDocument options (PR 18776 follow-up) 2024-12-15 14:13:44 +01:00
calixteman
a8c35a9e0c
Merge pull request #19219 from calixteman/pinch_editor
[Editor] Add the ability to resize an editor in using a pinch gesture
2024-12-14 21:50:51 +01:00
Calixte Denizet
4ed7f7f1ee [Editor] Add the ability to resize an editor in using a pinch gesture 2024-12-14 19:39:51 +01:00
calixteman
8fa4398266
Merge pull request #19216 from calixteman/extract_pinch
Move the pinch stuff in its own file in order to use for editors
2024-12-12 10:15:05 +01:00
Calixte Denizet
e0b63ecd03 Move the pinch stuff in its own file in order to use for editors 2024-12-11 23:20:01 +01:00
calixteman
a9c5bb25b8
Merge pull request #19215 from calixteman/issue18911
[Editor] Avoid to focus an existing editor when enabling the layer
2024-12-11 22:18:17 +01:00
Calixte Denizet
d61b882888 [Editor] Avoid to focus an existing editor when enabling the layer
It fixes #18911.
2024-12-11 15:06:56 +01:00
Jonas Jenwald
08e54053ff Don't remove trailing regular spaces from the "raw" response headers (issue 19205)
This bug only seems to reproduce in Google Chrome, since browsers apparently sort response headers differently.
When the issue occurs the "raw" response headers string looks like this:
```
content-length: 525404\r\ncontent-type: \r\n
```
and since we trim *any* leading/trailing white-space characters the "content-type" header isn't detected correctly, which thus leads to `new Headers(...)` throwing.

Hence we'll keep regular spaces at the end of the "raw" response headers string, while still removing all other kinds of trailing white-space characters.

*Note:* The response headers parsing was based on https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#examples
2024-12-11 12:16:31 +01:00
calixteman
fbac4ab5f3
Merge pull request #19209 from calixteman/draw_touch_screen
[Editor] Improve drawing on a touch screen.
2024-12-10 22:40:13 +01:00
Calixte Denizet
89f61b4262 [Editor] Improve drawing on a touch screen.
- it's now possible to start a drawing with a pen and use fingers to zoom
  or scroll without interacting with the current drawing;
- it's now possible to draw with a finger and them zoom with two fingers.
2024-12-10 21:54:29 +01:00
calixteman
4d228818a9
Merge pull request #19210 from calixteman/puppeteer_23.10.3
Update Puppeteer to version 23.10.3
2024-12-10 21:10:21 +01:00
Calixte Denizet
b7ab5ee018 Update Puppeteer to version 23.10.3 2024-12-10 19:59:54 +01:00
calixteman
6e33f23757
Merge pull request #19208 from calixteman/puppeteer_23.10.2
Update Puppeteer to version 23.10.2
2024-12-10 19:56:16 +01:00
Calixte Denizet
73701ad873 Update Puppeteer to version 23.10.2 2024-12-10 19:55:55 +01:00
calixteman
b35999d837
Merge pull request #19198 from calixteman/fix_intermittent_itest_chrome
Fix intermittent failures when moving a freetext annotation in integration tests
2024-12-10 16:56:58 +01:00
Calixte Denizet
74a377f72f Fix intermittent failures when moving a freetext annotation in integration tests
When an editor is moved with the keyboard or in dragging it, it is moved in the DOM in order
to make screen readers happy. But this move is slightly postponed thanks to a setTimeout(..., 0).
The failures were very likely due to the fact that intermittently the DOM move was done in
the middle of the next key sequence which was making the move on screen failing.
2024-12-10 16:14:26 +01:00
calixteman
aa589b9068
Merge pull request #19206 from nicolo-ribaudo/canvas-prepend
Simplify logic to insert canvas as first element
2024-12-10 14:59:18 +01:00
Nicolò Ribaudo
62db66dd46
Simplify logic to insert canvas as first element
Instead of conditionally checking if the `.cavnasWrapper` already
has a child element and then inserting the `canvas` before it, we can
use `.prepend` which always injects the new element as the first
child.
2024-12-10 12:00:09 +01:00
calixteman
44421d36f6
Merge pull request #19201 from calixteman/fix_resize_stamp
[Editor] When resizing a stamp annotation, the opposite corner must stay fixed
2024-12-10 11:00:01 +01:00
calixteman
f9ae9b06e8
Merge pull request #19204 from calixteman/set_canvas_as_first_child
Make sure the canvas is always the first child of its wrapper
2024-12-09 21:28:21 +01:00
Calixte Denizet
3402b727ee Make sure the canvas is always the first child of its wrapper
While drawing, in zooming fast enough, it's possible, intermittently, to have the canvas
after the svg which makes the svg invisible.
So this patch makes sure to have the canvas at the right position.
2024-12-09 19:55:37 +01:00
calixteman
898be9ef5e
Merge pull request #19202 from calixteman/avoid_to_lose_focus
[Editor] Don't commit the current drawing while zooming
2024-12-09 19:00:26 +01:00
calixteman
438c641da2
Merge pull request #19203 from calixteman/update_openjpeg_2.5.3
Update OpenJPEG to 2.5.3
2024-12-09 18:59:26 +01:00
Jonas Jenwald
39bfc92b8e
Merge pull request #19200 from Snuffleupagus/delete-raw-path
Remove the raw path-strings after creating the actual `Path2D` glyph-objects
2024-12-09 18:46:34 +01:00
Calixte Denizet
19ea64c6d7 Update OpenJPEG to 2.5.3 2024-12-09 18:02:18 +01:00
Calixte Denizet
166a529ddd [Editor] Don't commit the current drawing while zooming 2024-12-09 17:25:36 +01:00
Calixte Denizet
99f3e6b4ec [Editor] When resizing a stamp annotation, the opposite corner must stay fixed
It was due the resize observer which is removed thanks to this patch.
In order to reuse the dragAndDrop function in test, this patch slighty refactors it
in order to make it easier to use.
2024-12-09 16:07:43 +01:00
Jonas Jenwald
6153b15231 Remove the raw path-strings after creating the actual Path2D glyph-objects
The `Path2D` glyph-objects are cached on the `FontFaceObject`-instance, so we can save a little bit of memory by removing the raw path-strings once they're no longer needed.
2024-12-09 15:09:18 +01:00
calixteman
99eefb7b71
Merge pull request #19189 from calixteman/improve_font_drawer
Improve perfs of the font renderer
2024-12-09 14:15:15 +01:00
Jonas Jenwald
5dc2d257ad
Merge pull request #19196 from Snuffleupagus/issue-19176
Take the `userUnit` into account in the `PageViewport` class (issue 19176)
2024-12-09 13:38:31 +01:00
Calixte Denizet
2b05924504 Improve perfs of the font renderer
Some SVG paths are generated from the font and used in the main thread
to render the glyphs.
2024-12-08 17:12:10 +01:00
calixteman
6177bb5aa8
Merge pull request #19197 from calixteman/test_disableFontFace
Add a ref test for setting disableFontFace to true
2024-12-08 16:17:42 +01:00
Calixte Denizet
f6662d3f7c Add a ref test for setting disableFontFace to true 2024-12-08 16:06:25 +01:00
Jonas Jenwald
c6e3fc4fe6 Take the userUnit into account in the PageViewport class (issue 19176) 2024-12-08 15:51:04 +01:00
Tim van der Meij
35573cb8e8
Merge pull request #19192 from timvandermeij/scripting-intermittent
Fix intermittent issues in the `issue14307.pdf` integration tests
2024-12-08 14:59:24 +01:00
Tim van der Meij
e74080915d
Fix intermittent issues in the issue14307.pdf integration tests
The `must check input for US zip format` integration test fails pretty
consistently in Puppeteer 23.4.0+ with `Expected '12341' to equal
'12345'`. This is reproducible with the `pdf.sandbox.external.js` hack
from https://github.com/mozilla/pdf.js/issues/18396#issuecomment-2211273743.
Investigation uncovered two issues at play here:

1. We do two `clearInput` calls, but don't await processing of the two
   sandbox events that are triggered by that action. The three tests that
   use `issue14307.pdf` are in different `describe` blocks and therefore
   reload the PDF file, so we can simply remove those calls because the
   inputs are already empty by default.

2. We don't await processing of the sandbox events that occur after
   switching to another text field. This causes the expectation failure
   because the typing actions will happen too soon and interfere with
   the sandbox event processing. We solve the issue by explicitly
   awaiting the sandbox roundtrip.

Moreover, similar to PR #19001 and #18399 we remove any remaining room
for intermittent issues by directly checking for the expected value,
which also results in shorter code.
2024-12-07 19:28:26 +01:00
Tim van der Meij
3f1d07a35e
Merge pull request #19191 from Snuffleupagus/Node-legacy-warn
Print more warnings about potential problems in Node.js environments
2024-12-07 14:54:57 +01:00
Tim van der Meij
67076b6220
Merge pull request #19190 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-12-07 14:52:40 +01:00
Jonas Jenwald
c60a6d1ebd Print more warnings about potential problems in Node.js environments
- Warn if the "regular" PDF.js build is used in Node.js environments, since that won't load any of the relevant polyfills.

 - Warn if the `require` function cannot be accessed, since currently we're just "swallowing" any errors.
2024-12-07 14:08:09 +01:00
Tim van der Meij
2738d1e4f6
Update translations to the most recent versions 2024-12-07 13:44:57 +01:00
Tim van der Meij
129fc66f65
Upgrade eslint-plugin-perfectionist to version 4.2.0
This requires two changes on our side:

- The order of exports in `web/viewer{-geckoview}.js` changes slightly
  because `eslint-plugin-perfectionist` aligned the sorting order with
  the `eslint-plugin-sort-exports` plugin we used before. This restores
  the change from commit 347f155.
- The `eslint-plugin-import` plugin contains a bug that causes the new
  version of `eslint-plugin-perfectionist` to be reported as unresolved.
  This issue is tracked upstream, and since the plugin works fine we
  can simply extend the ignore list we already have to avoid this error
  until the upstream bug is fixed.
2024-12-07 13:44:48 +01:00
Tim van der Meij
7d1ca73acc
Update dependencies to the most recent versions 2024-12-07 13:22:44 +01:00
Jonas Jenwald
b870c5d2ad
Merge pull request #19185 from Snuffleupagus/issue-19175
Support toggling the `PDFFindBar` options with the `Enter` key (issue 19175)
2024-12-06 23:32:58 +01:00
calixteman
23c42f891b
Merge pull request #19184 from calixteman/issue19182
Get the first codepoint instead of the first char when using the toUnicode map
2024-12-06 18:31:30 +01:00
Calixte Denizet
6fe6b6d6b7 Get the first codepoint instead of the first char when using the toUnicode map
It fixes #19182.
2024-12-06 18:25:13 +01:00
Jonas Jenwald
49326f71c2 Support toggling the PDFFindBar options with the Enter key (issue 19175)
These DOM elements are `input type="checkbox"` and (natively) only support being toggled with the `Space` key, however we can extend an existing event-listener to "manually" support the `Enter` key as well.
2024-12-06 17:53:28 +01:00
Jonas Jenwald
c198e0b446
Merge pull request #19148 from nicolo-ribaudo/error-preserve-trace
Do not stringify errors when logging them
2024-12-06 17:11:33 +01:00
Nicolò Ribaudo
202b26487f
Do not stringify errors when logging them
Converting errors to string drops their stack trace, making it more
difficult to debug their actual reason. We can instead pass the error
objects as-is to console.warn/error, so that Firefox/Chrome devtools
will show both the stack trace of the console.warn/error call, and the
original stack trace of the error.

This commit also enables the `unicorn/no-console-spaces` ESLint rule,
which avoids accidental extra spaces when passing multiple parameters to
`console.*` methods.
2024-12-06 14:47:22 +01:00
Jonas Jenwald
60eba287d4
Merge pull request #19114 from Snuffleupagus/issue-19075
Ensure that a missing/invalid "Content-Range" header is handled in `PDFNetworkStream` (issue 19075)
2024-12-06 12:31:18 +01:00
Jonas Jenwald
eff8ede33e Make the onError callback required in NetworkManager
This helps ensure that loading errors are always handled correctly, and note that both `PDFNetworkStreamFullRequestReader` and `PDFNetworkStreamRangeRequestReader` already provided such a callback.
2024-12-06 12:09:36 +01:00
Jonas Jenwald
2661d0623b Ensure that a missing/invalid "Content-Range" header is handled in PDFNetworkStream (issue 19075)
In the event that the "Content-Range" header is missing/invalid, loading will now be aborted rather than hanging indefinitely.
2024-12-06 12:09:34 +01:00
calixteman
e04b62ba2d
Merge pull request #19164 from calixteman/issue18622
When zooming replace the css-zoomed canvas by the new one only when rendering is finished
2024-12-06 11:44:32 +01:00
Calixte Denizet
f3038406b1 When zooming replace the css-zoomed canvas by the new one only when rendering is finished
It fixes #18622.

It avoids to recreate a canvasWrapper element in order minimize the DOM operations.
2024-12-05 23:15:04 +01:00
Tim van der Meij
ef6ecee34c
Merge pull request #19178 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-12-05 22:30:35 +01:00
Tim van der Meij
34390ca53a
Bump the stable version in pdfjs.config 2024-12-05 22:25:31 +01:00
Tim van der Meij
a4eb8407c1
Merge pull request #19149 from Snuffleupagus/issue-19145
Prevent Webpack from resolving `import.meta.url` statements during building (issue 19145)
2024-12-05 21:38:26 +01:00
Tim van der Meij
f0a8a799a7
Merge pull request #19177 from calixteman/issue19171
Avoid to display an alert or a confirm dialog if the message is empty
2024-12-05 21:36:54 +01:00
Calixte Denizet
d1db8d6294 Avoid to display an alert or a confirm dialog if the message is empty
It fixes #19171.
2024-12-05 21:04:07 +01:00
calixteman
f180de41f3
Merge pull request #19174 from calixteman/ink_update_width
[Editor] Correctly update the current drawing when zooming
2024-12-05 16:06:34 +01:00
Jonas Jenwald
28d801e081
Merge pull request #19172 from Snuffleupagus/toggleButton-hover
Ensure that the `.toggleButton`, as used in the findbar, always have visible hover/focus state (issue 19165)
2024-12-05 15:24:46 +01:00
Calixte Denizet
dfa0e79553 [Editor] Correctly update the current drawing when zooming
We were trying to update the drawing on the current page but if the drawing is an another
page then it wasn't updated.
2024-12-05 14:22:02 +01:00
calixteman
9cbc5baafd
Merge pull request #19163 from calixteman/fix_new_ink_itest
Correctly wait for the editor mode when double clicking on an annotation in integration tests
2024-12-05 13:38:12 +01:00
Jonas Jenwald
61e2eceff6 Ensure that the .toggleButton, as used in the findbar, always have visible hover/focus state (issue 19165)
Similar to the regular toolbarButtons that can be toggled, this ensure that it's always possible to tell when the findbar "buttons" are hovered/focused.
2024-12-05 13:07:57 +01:00
Jonas Jenwald
2ad8f6155c
Merge pull request #19161 from Snuffleupagus/Promise-try
Introduce `Promise.try()` usage in the code-base
2024-12-05 10:48:29 +01:00
Calixte Denizet
3ac55501e9 Correctly wait for the editor mode when double clicking on an annotation in integration tests 2024-12-04 18:42:49 +01:00
Jonas Jenwald
ef0331877d Introduce Promise.try() usage in the code-base
This simplifies the creation of Promises in some cases; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/try
2024-12-04 10:31:42 +01:00
calixteman
11ce57ac22
Merge pull request #19160 from calixteman/fix_css_message_bar
Fix unused css variables (follow-up of #18900)
2024-12-04 09:45:17 +01:00
Calixte Denizet
1cd3eb75d5 Fix unused css variables (follow-up of #18900) 2024-12-04 09:15:01 +01:00
calixteman
9a4b7c2612
Merge pull request #19155 from calixteman/bug1929311
[Editor] Corrrectly get the words from the alt-text when reporting the telemetry (bug 1929311)
2024-12-03 19:27:15 +01:00
Calixte Denizet
e161826a44 [Editor] Corrrectly get the words from the alt-text when reporting the telemetry (bug 1929311) 2024-12-03 19:02:58 +01:00
calixteman
a5ce71247b
Merge pull request #18900 from ryzokuken/popup-undo-annotation
Annotation deletion popup (bug 1899731)
2024-12-03 16:53:48 +01:00
Aditi
41bf874461 Add tests for annotation delete popup 2024-12-03 11:03:15 +01:00
Ujjwal Sharma
dd82d78a2d Pop open a message when user deletes an annotation
When a user deletes any number of annotations, they are notified of the action
by a popup message with an undo button. Besides that, this change reuses the
existing messageBar CSS class from the new alt-text dialog as much as possible.
2024-12-03 11:03:15 +01:00
Ujjwal Sharma
962eb6206a Break messageBar class out
Move .messageBar out of .dialog into its own standalone class in order
to reuse as much of it for the upcoming feature for an undo message for
annotations.
2024-12-02 23:01:22 +01:00
Jonas Jenwald
f8d11a3a3a
Merge pull request #19074 from Rob--W/issue-12744-test
Add test cases for redirected responses
2024-12-02 19:06:55 +01:00
calixteman
8a2bdb1a05
Merge pull request #19151 from calixteman/edit_inks
[Editor] Make ink annotation editable
2024-12-02 18:30:40 +01:00
Rob Wu
f97b4b9a66 Add test cases for redirected responses
Regression tests for issue #12744 and PR #19028
2024-12-02 17:57:49 +01:00
Rob Wu
28b0220bc2 Replace createTemporaryNodeServer with TestPdfsServer
Some tests rely on the presence of a server that serves PDF files.
When tests are run from a web browser, the test files and PDF files are
served by the same server (WebServer), but in Node.js that server is not
around.

Currently, the tests that depend on it start a minimal Node.js server
that re-implements part of the functionality from WebServer.

To avoid code duplication when tests depend on more complex behaviors,
this patch replaces createTemporaryNodeServer with the existing
WebServer, wrapped in a new test utility that has the same interface in
Node.js and non-Node.js environments (=TestPdfsServer).

This patch has been tested by running the refactored tests in the
following three configurations:

1. From the browser:
   - http://localhost:8888/test/unit/unit_test.html?spec=api
   - http://localhost:8888/test/unit/unit_test.html?spec=fetch_stream

2. Run specific tests directly with jasmine without legacy bundling:
   `JASMINE_CONFIG_PATH=test/unit/clitests.json ./node_modules/.bin/jasmine --filter='^api|^fetch_stream'`

3. `gulp unittestcli`
2024-12-02 17:57:49 +01:00
Calixte Denizet
7e02c77250 [Editor] Make ink annotation editable 2024-12-02 17:15:33 +01:00
calixteman
97c7a8eb7a
Merge pull request #19144 from calixteman/no_focus_if_invisible
[Editor] Don't focus a newly added drawing if it isn't visible on screen
2024-12-02 14:02:01 +01:00
calixteman
36b1ba8eca
Merge pull request #19142 from calixteman/rotated_ink
Fix the clickable area for rotated ink annotations
2024-12-02 14:01:26 +01:00
Jonas Jenwald
a2b889bb9a Prevent Webpack from resolving import.meta.url statements during building (issue 19145)
This fixes a Node.js-specific regression from PR 18959.
2024-12-02 13:38:22 +01:00
Calixte Denizet
673c93e832 [Editor] Don't focus a newly added drawing if it isn't visible on screen 2024-12-02 11:06:13 +01:00
Calixte Denizet
1460a8128a Fix the clickable area for rotated ink annotations 2024-12-02 09:48:22 +01:00
Tim van der Meij
d448953166
Merge pull request #19139 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-12-01 20:07:54 +01:00
Tim van der Meij
33da75fb36
Bump the stable version in pdfjs.config 2024-12-01 20:04:54 +01:00
Jonas Jenwald
867aaf01fa
Merge pull request #19117 from Snuffleupagus/bot-forceNoChrome
Disable the browser-tests in Google Chrome on the bots
2024-12-01 18:28:03 +01:00
Tim van der Meij
2bbf9b432c
Merge pull request #19099 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-12-01 14:54:07 +01:00
Tim van der Meij
eb51dbf296
Update translations to the most recent versions 2024-12-01 14:49:03 +01:00
Tim van der Meij
7784f868fc
Update dependencies to the most recent versions 2024-12-01 14:49:03 +01:00
Tim van der Meij
c40a0a6478
Merge pull request #19137 from Snuffleupagus/PDFDocumentProperties-move-getPage
Move the `getPage` call in `PDFDocumentProperties` class
2024-12-01 14:44:43 +01:00
Tim van der Meij
9f90bc9114
Merge pull request #19136 from Snuffleupagus/WorkerMessageHandler-this
Shorten the `WorkerMessageHandler` class a little bit
2024-12-01 14:40:38 +01:00
Tim van der Meij
1bc6b767c2
Merge pull request #19135 from Snuffleupagus/api-more-optional-chaining
Use even more optional chaining in the `src/display/api.js` file
2024-12-01 14:36:58 +01:00
Jonas Jenwald
e5f744da04 Move the getPage call in PDFDocumentProperties class
This allows us to remove an ESLint disable-statement for `arrow-body-style`, without affecting readability of the code, and fetching the metadata and the page in parallel should be a *tiny* bit more efficient as well.
2024-12-01 12:25:16 +01:00
Jonas Jenwald
ede589dd6e Shorten the WorkerMessageHandler class a little bit
- Use `this` in all scopes where that's possible, to avoid having to spell out `WorkerMessageHandler` everywhere.

 - Inline the `isMessagePort` helper function, since there's only a single call-site.

 - Use a static initialization block to move more code into the `WorkerMessageHandler` class itself.
2024-11-30 14:07:16 +01:00
Jonas Jenwald
4b0900fdfa Use even more optional chaining in the src/display/api.js file
This slightly shortens the code, in various `destroy`-methods, which cannot hurt.
Also, use pre-processor checks to simplify `PDFDocumentLoadingTask.destroy` in the Firefox PDF Viewer since the `PDFWorker.fromPort`-method isn't used there.
2024-11-30 12:06:27 +01:00
calixteman
8f08ca2150
Merge pull request #19131 from calixteman/bug1934157
Build date consistently (in term of tz) when executing some embedded JS (bug 1934157)
2024-11-29 21:44:10 +01:00
calixteman
a09ea8d29a
Merge pull request #19124 from calixteman/simplify_pinching
Simplify the code to zoom in using a pinch gesture
2024-11-29 20:47:59 +01:00
Calixte Denizet
2a337082c0 Build date consistently (in term of tz) when executing some embedded JS (bug 1934157)
The date was create in UTC+0 and then amended in using set-Month/Date which take into account
the user timezone.
With this patch we build all the date in the user timezone.
2024-11-29 19:50:21 +01:00
calixteman
9ecc613c08
Merge pull request #19066 from jarklee/issue19056
Fix #serializeBoxes function not output correct quadPoints values for deserialize (issue19056)
2024-11-29 18:31:28 +01:00
Calixte Denizet
a300b19525 Simplify the code to zoom in using a pinch gesture 2024-11-29 18:29:18 +01:00
calixteman
ffce4c74b5
Merge pull request #19129 from calixteman/issue19126
[Editor] Allow to abort the current drawing
2024-11-29 17:31:28 +01:00
Calixte Denizet
4acc086292 [Editor] Allow to abort the current drawing
It fixes #19126.
2024-11-29 16:22:49 +01:00
calixteman
308ca2a16f
Merge pull request #19123 from calixteman/improve_search_perf
Very slightly improve the performance when searching in a pdf
2024-11-28 17:44:14 +01:00
Calixte Denizet
94d53d5b45 Very slightly improve the performance when searching in a pdf
It helps to slightly decrease memory use in reducing the number of created arrays.
In searching for "a" in pdf.pdf, the time spent in getOriginalIndex is decreased by
around 30%.
2024-11-28 17:37:19 +01:00
Jonas Jenwald
65f20b0392
Merge pull request #19121 from Snuffleupagus/more-stopEvent
Use the `stopEvent` helper function everywhere possible
2024-11-28 17:21:34 +01:00
calixteman
c784a24d45
Merge pull request #19122 from calixteman/issue19120
Correctly compute the mapping between text and normalized text when it contains a compound word on two lines
2024-11-28 17:13:09 +01:00
calixteman
ee0df62bc8
Merge pull request #19093 from calixteman/refactor_ink
[Editor] Add a new base class to allow to add a drawing in the SVG layer.
2024-11-28 16:54:21 +01:00
Calixte Denizet
aa9503e51f Correctly compute the mapping between text and normalized text when it contains a compound word on two lines
It fixes #19120.

The original text doesn't contain the cr so we must take that into account.
2024-11-28 15:56:04 +01:00
Calixte Denizet
cee65fcd4e [Editor] Add a new base class to allow to add a drawing in the SVG layer.
This patch makes a clear separation between the way to draw and the editing stuff.
It adds a class DrawEditor which should be extended in order to create new drawing tools.
As an example, the ink tool has been rewritten in order to use it.
2024-11-28 15:23:03 +01:00
Jonas Jenwald
e1760aab8d Use the stopEvent helper function everywhere possible 2024-11-28 13:25:56 +01:00
calixteman
22babd722f
Merge pull request #19109 from calixteman/click_when_dragging
[Editor] Disallow to have multiple pointers while dragging an editor
2024-11-27 20:26:45 +01:00
Calixte Denizet
e695d04ca2 [Editor] Disallow to have multiple pointers while dragging an editor
It'll let the user dragging with two fingers.
2024-11-27 19:41:13 +01:00
Jonas Jenwald
fd31e728f7 Disable the browser-tests in Google Chrome on the bots
Given that `browsertest` repeatedly timeout in Google Chrome, and considering that Firefox is the primary development target, we stop running them on the bots to avoid having to repeatedly deal with this.

Note that we already disabled these tests *on Windows* almost three years ago, because of stability issues; see PR 14392.
2024-11-27 17:59:51 +01:00
calixteman
052b001f0e
Merge pull request #19111 from calixteman/fix_highlight_test_with_kb
Fix the highlight integration test when highlighting with the keyboard
2024-11-27 16:10:38 +01:00
Calixte Denizet
5d77a64e1f Fix the highlight integration test when highlighting with the keyboard
These tests were failing with Puppeteer 23.9.0.
2024-11-27 15:38:33 +01:00
Jarklee
2200f0523c Fix #serializeBoxes bug inconsistent with deserialize function for highlight editor.
Add test for quadPoints order while serializing.
2024-11-27 14:19:31 +07:00
calixteman
079eb24621
Merge pull request #19100 from Rob--W/test-trailing-whitespace-fixup
Drop trailing whitespace from test/unit/api_spec.js
2024-11-25 09:32:02 +01:00
Rob Wu
131d4650a5 Drop trailing whitespace from test/unit/api_spec.js
test/unit/api_spec.js is the only JS file in the tree with trailing
whitespace. Because `trim_trailing_whitespace = true` in .editorconfig,
any editor supporting EditorConfig would trim whitespace when the file
is changed, which results in test failures.

This commit fixes the issue by trimming the trailing whitespace and
adjusting the test expectations.
2024-11-24 23:37:16 +01:00
Tim van der Meij
725ae4998c
Fix the type definition of the fingerprints getter in src/display/api.js
The `Array` type takes one parameter that describes the possible types
of the inner  elements. This parameter may exist of pipes to indicate
multiple possible types. However, the current type definition provides
multiple parameters; this is incorrect syntax, and TypeScript 5.7+ now
fails on this due to stricter syntax validation.

This commit fixes the issue by changing the type definition to the
proper syntax, which together with the accompanying comment about the
contents of the fingerprints array should document it sufficiently.
2024-11-24 21:53:45 +01:00
Tim van der Meij
d45a61b579
Merge pull request #19091 from Snuffleupagus/getPdfManager-async
Convert the `getPdfManager` function to be asynchronous
2024-11-24 15:36:29 +01:00
Tim van der Meij
8ae5b4e442
Merge pull request #19096 from Rob--W/test-server-hardening
Fix path traversal issue in createTemporaryNodeServer
2024-11-24 15:30:22 +01:00
calixteman
9017e80d5a
Merge pull request #19095 from calixteman/issue17190
Rescale the image data when they're really too large
2024-11-24 14:30:37 +01:00
Jonas Jenwald
f911635b58
Merge pull request #19028 from Snuffleupagus/issue-12744
Ensure that the response-origin of range requests match the full request (issue 12744)
2024-11-24 10:37:07 +01:00
Jonas Jenwald
6a015588b9 Ensure that the response-origin of range requests match the full request (issue 12744)
The following cases are excluded in the patch:
 - The Firefox PDF Viewer, since it has been fixed on the platform side already; please see https://bugzilla.mozilla.org/show_bug.cgi?id=1683940

 - The `PDFNodeStream`-implementation, used in Node.js environments, since after recent changes that code only supports `file://`-URLs.

Also updates the `PDFNetworkStreamFullRequestReader.read`-method to await the headers before returning any data, similar to the implementation in `src/display/fetch_stream.js`.

*Note:* The relevant unit-tests are updated to await the `headersReady` Promise before dispatching range requests, since that's consistent with the actual usage in the `src/`-folder.
2024-11-24 10:08:29 +01:00
Calixte Denizet
1ef670411a Rescale the image data when they're really too large
It fixes #17190.
2024-11-23 22:42:30 +01:00
Rob Wu
17da8ee8fa Fix path traversal issue in createTemporaryNodeServer
The test-only createTemporaryNodeServer helper featured a path traversal
vulnerability. This enables attackers with network access to the device
to read arbitrary files while unit tests are running that activate this
test server.

This patch fixes the issue by validation of paths.

To test this vulnerability before the patch:

1. Run the test-only server:

```
node -e 'console.log(require("./test/unit/test_utils.js").createTemporaryNodeServer().port)
```

2. From another terminal, send the following request (modify the port to
   the port reported in the previous step):

```
curl --path-as-is http://localhost:45755/../../package.json
```

Before the patch, the second step would traverse the directory, and
return results from the root of the PDF.js repository, instead of files
within test/pdfs/.

With the patch, the server refuses the request with HTTP status 400.
2024-11-23 21:32:24 +01:00
Jonas Jenwald
8ec399d7e1 Convert the getPdfManager function to be asynchronous
This is fairly old code, and by making the function `async` we can handle initialization errors "automatically" without the need for try-catch statements.
2024-11-22 17:49:43 +01:00
calixteman
1f6cc85134
Merge pull request #19088 from calixteman/no_movementXY
[Editor] Avoid to use event.movementX/Y when resizing an editor
2024-11-22 16:59:54 +01:00
Calixte Denizet
c08b5b2a94 [Editor] Avoid to use event.movementX/Y when resizing an editor
Those propertie can have some non-expected values so use screenX/Y instead.
2024-11-22 14:55:53 +01:00
calixteman
086cb6630e
Merge pull request #19087 from calixteman/no_scroll_when_dragging
[Editor] Avoid to scroll when dragging an editor on a touch screen
2024-11-22 09:53:49 +01:00
calixteman
5133e6b666
Merge pull request #19085 from calixteman/simplify_drawer
[Editor] Simplify the draw layer code
2024-11-22 09:16:48 +01:00
Calixte Denizet
aef150d38a [Editor] Avoid to scroll when dragging an editor on a touch screen 2024-11-21 22:54:07 +01:00
calixteman
5b600e8f84
Merge pull request #19086 from calixteman/issue19083
Use the V entry as an option when no options in a choice widget
2024-11-21 18:40:04 +01:00
Calixte Denizet
3c343acbb6 [Editor] Simplify the draw layer code
and tweak a bit the highlight one (e.g. it's useless to have 64 bits floating point numbers
when 32 bits ones are enough).

It's a required step for the refactoring of the ink tool (in order to use the draw layer).
It avoids to call several functions acting on the same SVG element.
2024-11-21 17:50:35 +01:00
Calixte Denizet
b0b0de98e7 Use the V entry as an option when no options in a choice widget
It fixes #19083.

It isn't really a fix but more a workaround (we should correctly implement the
choice widget as a mix of text input+select).
2024-11-21 17:27:34 +01:00
Jonas Jenwald
445b7ece61
Merge pull request #19084 from Snuffleupagus/getUuid-shorten
Simplify the `getUuid` helper function
2024-11-21 15:17:14 +01:00
Jonas Jenwald
c290a12ce1 Simplify the getUuid helper function
We can remove most feature testing from this helper function, with the exception of `randomUUID` since that's only available in "secure contexts", and also remove the fallback code-path.
Note that this code was only added for Node.js compatibility, and it's no longer necessary now that the minimum support version is `20`; see also https://developer.mozilla.org/en-US/docs/Web/API/Crypto#browser_compatibility

Finally, this patch also adds a basic unit-test for the helper function.
2024-11-21 13:11:10 +01:00
Tim van der Meij
07765e993e
Merge pull request #19069 from calixteman/stamp_test
Fix 'must load a SVG, delete it and undo' integration test
2024-11-19 20:42:12 +01:00
Tim van der Meij
c31ccc6847
Merge pull request #19071 from Snuffleupagus/no-single-promise-in-promise-methods
Enable the `unicorn/no-single-promise-in-promise-methods` ESLint plugin rule
2024-11-19 20:33:33 +01:00
Tim van der Meij
e8fbb602c5
Merge pull request #19064 from timvandermeij/fix-intermittent
Fix the "must check that an infinite loop is not triggered" integration test
2024-11-19 20:31:49 +01:00
Jonas Jenwald
b38b12d48a Enable the unicorn/no-single-promise-in-promise-methods ESLint plugin rule
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-single-promise-in-promise-methods.md
2024-11-19 11:39:02 +01:00
Calixte Denizet
eefaca07c3 Fix 'must load a SVG, delete it and undo' integration test
We wait for the canvas before trying to serialize the annotation in order to make sure the image has been loaded.
2024-11-18 21:25:59 +01:00
Jonas Jenwald
f4061190fa
Merge pull request #19068 from nicolo-ribaudo/json-imports
Use JSON imports instead of PDFJSDev.json
2024-11-18 16:37:37 +01:00
Nicolò Ribaudo
a8592d86a9
Use JSON imports instead of PDFJSDev.json
JSON imports are now supported by all tools used in PDF.js' build
process. The `chromecom.js` file is bundled by webpack and
import attributes are thus removed, so browser compatibility for this
new syntax is not relevant.
2024-11-18 16:21:12 +01:00
calixteman
658a0a16c1
Merge pull request #18669 from calixteman/stylint_update
Update svglint to 3.1.0
2024-11-18 15:11:57 +01:00
Calixte Denizet
1c5d93cf2d Update svglint to 3.1.0
The new release contains:
 - https://github.com/simple-icons/svglint/pull/110
 - https://github.com/simple-icons/svglint/pull/111

which allow us to slightly simplify our code.
2024-11-18 15:00:07 +01:00
Tim van der Meij
973b67f047
Fix the "must check that an infinite loop is not triggered" integration test
This integration test fails intermittently, locally at least in Chrome
with Puppeteer 23.4.0+, with the following errors:

```
In chrome: Expected '123Hello' to equal 'Hello123'.
In chrome: Expected '123Hello' to equal '123'.
```

This happens because the test before it left queued sandbox events
behind. We don't close the document between tests, so those get run
when we click the textbox in this test and that interferes with our
selection/typing actions. This commit fixes the issue by flushing the
queued sandbox events in the first test, which makes sure that state
no longer leaks through to the next test and thus improves isolation.

Morever, similar to commit 3adf8b6 we use safer assertions to avoid
further intermittent failures, and we replace the `page.$eval` call
with a simpler Home button push like we already do in e.g. the test
helpers. This combined makes the code shorter and simpler.
2024-11-17 21:23:04 +01:00
Tim van der Meij
3219d4905d
Merge pull request #19061 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-11-17 19:59:15 +01:00
Tim van der Meij
21137963b2
Merge pull request #19062 from timvandermeij/gitpod
Remove obsolete Gitpod files
2024-11-17 19:57:53 +01:00
Tim van der Meij
e18cf97733
Update translations to the most recent versions 2024-11-17 19:55:28 +01:00
Tim van der Meij
50d79736f5
Update dependencies to the most recent versions 2024-11-17 19:55:28 +01:00
Tim van der Meij
093485d491
Remove obsolete Gitpod files
In PR #11300 Gitpod support got introduced, but we re-evaluated that
decision in #11732. In PR #11800 the support was partially reverted,
but the actual Gitpod files were kept to not outright break potential
workflows because at the time we were not sure if, and if so how often,
Gitpod was actually used for contributing to PDF.js.

However, in addition to the concerns mentioned in #11732 after five
years we haven't seen any contributions that clearly originated from
Gitpod, and the files have not been updated after e.g. PR #11807 and
PR #17913 because it's not a workflow that we maintain or are able
to test (nor have we seen Gitpod community contributions for this).

This commit therefore removes the remaining Gitpod files to reduce
maintainance burden for PDF.js. Note that users of Gitpod can still
contribute to PDF.js via the platform; we just don't provide/manage
workspace files from this repository anymore.
2024-11-17 19:52:48 +01:00
calixteman
8a8b69f456
Merge pull request #19054 from calixteman/issue18630
When saving some annotations with the same name, set the value in the parent
2024-11-17 18:00:48 +01:00
Tim van der Meij
e2bbcb544a
Merge pull request #19045 from Snuffleupagus/api-rm-isChrome
[api-minor] Disable `ImageDecoder` usage by default in Chromium browsers
2024-11-17 16:32:48 +01:00
Tim van der Meij
fc0484904e
Merge pull request #19059 from Snuffleupagus/DOMFilterFactory-rm-_hcmCache
Improve clean-up of `#_hcmCache`-data in `DOMFilterFactory.prototype.destroy`
2024-11-17 16:31:37 +01:00
Calixte Denizet
2da586527f When saving some annotations with the same name, set the value in the parent
It fixes #18630.
2024-11-17 15:55:20 +01:00
Jonas Jenwald
4c57ec4da7 Improve clean-up of #_hcmCache-data in DOMFilterFactory.prototype.destroy
- Use optional chaining when clearing various data-structures, since that's slightly shorter.

 - Ensure that checking for the existence of `#_hcmCache`-data won't cause it to be initialized. (Note how `this.#hcmCache` is actually a getter.)

 - Actually reset the `#_hcmCache`-data when that's appropriate, e.g. when closing the PDF document.
2024-11-17 15:31:42 +01:00
Jonas Jenwald
bc91985941
Merge pull request #19051 from Snuffleupagus/Dict-Map
Convert the `Dict`-implementation to use a `Map` internally
2024-11-17 12:59:02 +01:00
Jonas Jenwald
823e700b3b
Merge pull request #19057 from Snuffleupagus/extendCMap-avoid-lookup
Avoid redundant CMap-value lookup in `extendCMap` (PR 5101 follow-up)
2024-11-17 12:49:20 +01:00
Tim van der Meij
15a5e47e64
Merge pull request #19042 from Snuffleupagus/eslint-no-console
Enable the ESLint `no-console` rule in parts of the code-base
2024-11-17 12:45:50 +01:00
Jonas Jenwald
2c0cc48d1b Replace the forEach method in Dict with "proper" iteration support 2024-11-17 12:45:32 +01:00
Jonas Jenwald
691be77f65 Convert the Dict-implementation to use a Map internally
With all the recent work happening under https://bugzilla.mozilla.org/show_bug.cgi?id=1851662, the performance of `Map` is already good enough that I believe that we should now be able to utilize it in the `Dict`-class without problem.

This patch was tested in Firefox Nightly, specifically build https://hg.mozilla.org/mozilla-central/rev/6c508a387477e3b72db913a9e1761e9a433d06a2, with the following manifest file:
```
[
  {
    "id": "tracemonkey-eq",
    "file": "pdfs/tracemonkey.pdf",
    "md5": "9a192d8b1a7dc652a19835f6f08098bd",
    "rounds": 100,
    "type": "eq"
  },
  {
    "id": "issue2618",
    "file": "pdfs/issue2618.pdf",
    "md5": "2c554a99a52288ca1a44a422eeafb8fb",
    "rounds": 100,
    "type": "eq"
  }
]
```
which gave the following results, indicating no significant regression, when comparing this patch against the `master` branch:
 - Overall
   ```
   -- Grouped By browser, pdf, stat --
   browser | pdf            | stat         | Count | Baseline(ms) | Current(ms) | +/- |    %  | Result(P<.05)
   ------- | -------------- | ------------ | ----- | ------------ | ----------- | --- | ----- | -------------
   firefox | issue2618      | Overall      |   100 |          678 |         678 |   0 |  0.04 |
   firefox | issue2618      | Page Request |   100 |            1 |           1 |   0 | -3.88 |
   firefox | issue2618      | Rendering    |   100 |          677 |         677 |   0 |  0.05 |
   firefox | tracemonkey-eq | Overall      |  1400 |           35 |          36 |   0 |  0.96 |
   firefox | tracemonkey-eq | Page Request |  1400 |            1 |           1 |   0 | -8.08 |
   firefox | tracemonkey-eq | Rendering    |  1400 |           34 |          35 |   0 |  1.26 |
   ```

 - Page-specific
   ```
   -- Grouped By browser, pdf, page, stat --
   browser | pdf            | page | stat         | Count | Baseline(ms) | Current(ms) | +/- |     %  | Result(P<.05)
   ------- | -------------- | ---- | ------------ | ----- | ------------ | ----------- | --- | ------ | -------------
   firefox | issue2618      | 0    | Overall      |   100 |          678 |         678 |   0 |   0.04 |
   firefox | issue2618      | 0    | Page Request |   100 |            1 |           1 |   0 |  -3.88 |
   firefox | issue2618      | 0    | Rendering    |   100 |          677 |         677 |   0 |   0.05 |
   firefox | tracemonkey-eq | 0    | Overall      |   100 |           23 |          24 |   0 |   1.24 |
   firefox | tracemonkey-eq | 0    | Page Request |   100 |            1 |           1 |   0 |  19.77 |
   firefox | tracemonkey-eq | 0    | Rendering    |   100 |           23 |          23 |   0 |   0.40 |
   firefox | tracemonkey-eq | 1    | Overall      |   100 |           32 |          32 |  -1 |  -1.89 |
   firefox | tracemonkey-eq | 1    | Page Request |   100 |            1 |           1 |   0 | -28.13 |
   firefox | tracemonkey-eq | 1    | Rendering    |   100 |           31 |          31 |   0 |  -0.77 |
   firefox | tracemonkey-eq | 2    | Overall      |   100 |           17 |          18 |   1 |   4.60 |
   firefox | tracemonkey-eq | 2    | Page Request |   100 |            1 |           1 |   0 |  23.53 |        slower
   firefox | tracemonkey-eq | 2    | Rendering    |   100 |           17 |          17 |   1 |   3.71 |
   firefox | tracemonkey-eq | 3    | Overall      |   100 |           23 |          24 |   0 |   1.71 |
   firefox | tracemonkey-eq | 3    | Page Request |   100 |            1 |           1 |   0 |   7.79 |
   firefox | tracemonkey-eq | 3    | Rendering    |   100 |           23 |          23 |   0 |   1.55 |
   firefox | tracemonkey-eq | 4    | Overall      |   100 |           31 |          31 |   1 |   2.49 |
   firefox | tracemonkey-eq | 4    | Page Request |   100 |            1 |           1 |   0 |  48.96 |
   firefox | tracemonkey-eq | 4    | Rendering    |   100 |           30 |          30 |   0 |   1.05 |
   firefox | tracemonkey-eq | 5    | Overall      |   100 |           31 |          30 |  -1 |  -2.42 |
   firefox | tracemonkey-eq | 5    | Page Request |   100 |            2 |           1 |  -1 | -49.33 |
   firefox | tracemonkey-eq | 5    | Rendering    |   100 |           29 |          29 |   0 |  -0.03 |
   firefox | tracemonkey-eq | 6    | Overall      |   100 |           27 |          27 |   0 |   1.81 |
   firefox | tracemonkey-eq | 6    | Page Request |   100 |            1 |           1 |   0 |   4.94 |
   firefox | tracemonkey-eq | 6    | Rendering    |   100 |           26 |          27 |   0 |   1.68 |
   firefox | tracemonkey-eq | 7    | Overall      |   100 |           26 |          26 |   1 |   3.13 |
   firefox | tracemonkey-eq | 7    | Page Request |   100 |            1 |           1 |   0 |   6.98 |
   firefox | tracemonkey-eq | 7    | Rendering    |   100 |           25 |          25 |   1 |   2.92 |
   firefox | tracemonkey-eq | 8    | Overall      |   100 |           25 |          26 |   1 |   5.16 |
   firefox | tracemonkey-eq | 8    | Page Request |   100 |            1 |           1 |  -1 | -41.84 |
   firefox | tracemonkey-eq | 8    | Rendering    |   100 |           23 |          25 |   2 |   8.19 |
   firefox | tracemonkey-eq | 9    | Overall      |   100 |           33 |          33 |   0 |   0.03 |
   firefox | tracemonkey-eq | 9    | Page Request |   100 |            1 |           1 |   0 |   0.79 |
   firefox | tracemonkey-eq | 9    | Rendering    |   100 |           32 |          32 |   0 |  -0.10 |
   firefox | tracemonkey-eq | 10   | Overall      |   100 |          144 |         144 |   1 |   0.52 |
   firefox | tracemonkey-eq | 10   | Page Request |   100 |            2 |           1 |  -1 | -43.52 |
   firefox | tracemonkey-eq | 10   | Rendering    |   100 |          141 |         143 |   2 |   1.18 |
   firefox | tracemonkey-eq | 11   | Overall      |   100 |           24 |          25 |   1 |   2.51 |
   firefox | tracemonkey-eq | 11   | Page Request |   100 |            1 |           1 |   0 |  -4.71 |
   firefox | tracemonkey-eq | 11   | Rendering    |   100 |           23 |          24 |   1 |   2.78 |
   firefox | tracemonkey-eq | 12   | Overall      |   100 |           40 |          39 |  -1 |  -1.67 |
   firefox | tracemonkey-eq | 12   | Page Request |   100 |            1 |           1 |   0 |  14.71 |
   firefox | tracemonkey-eq | 12   | Rendering    |   100 |           39 |          38 |  -1 |  -1.98 |
   firefox | tracemonkey-eq | 13   | Overall      |   100 |           19 |          20 |   1 |   3.09 |
   firefox | tracemonkey-eq | 13   | Page Request |   100 |            1 |           1 |   0 |  24.79 |
   firefox | tracemonkey-eq | 13   | Rendering    |   100 |           18 |          19 |   0 |   1.70 |
   ```
2024-11-17 12:44:06 +01:00
Jonas Jenwald
729e3190eb Fix a couple of bugs affecting benchmarking
- Ensure that `pdfjsTestingUtils` is available when running benchmarking, since that shouldn't be done in TESTING-mode.

 - Exclude the `test/stats/results/` folder from linting, since it'll contain *generated* JSON-files.
2024-11-17 12:44:06 +01:00
Tim van der Meij
a719c3c067
Merge pull request #19050 from Snuffleupagus/evaluator-no-var
Enable the ESLint `no-var` rule in the `src/core/evaluator.js` file
2024-11-17 12:23:49 +01:00
Tim van der Meij
cab98b8ca9
Merge pull request #19052 from Snuffleupagus/pr-19029
Remove the `extensions/chromium/.eslintrc` file (PR 19029 follow-up)
2024-11-17 12:21:33 +01:00
Jonas Jenwald
8783dd0178 Avoid redundant CMap-value lookup in extendCMap (PR 5101 follow-up)
When iterating through `useCMap` the value is already available, without having to manually invoke the `lookup`-method.
While this will likely not affect performance in any noticeable way, it's nonetheless unnecessary to lookup an already available value twice.
2024-11-17 11:57:45 +01:00
Jonas Jenwald
6f3f3be7a3 Remove the extensions/chromium/.eslintrc file (PR 19029 follow-up)
This file became unused in PR 19029, but we apparently forgot to remove it.
2024-11-16 14:48:44 +01:00
Jonas Jenwald
c082169cae Enable the ESLint no-var rule in the src/core/evaluator.js file
This was previously attempted in PR 13371, but had to be reverted because of issues related to SystemJS (which has since been removed).

Also, while unrelated, shortens an existing conditional assignment.
2024-11-15 12:36:51 +01:00
Jonas Jenwald
af3c1f2a0d Enable the ESLint no-console rule in parts of the code-base
The purpose of these changes is to make it more difficult to accidentally include logging statements, used during development and debugging, when submitting patches for review.

For (almost) all code residing in the `src/` folder we should use our existing helper functions to ensure that all logging can be controlled via the `verbosity` API-option.

For the `test/unit/` respectively `test/integration/` folders we shouldn't need any "normal" logging, but it should be OK to print the *occasional* warning/error message.

Please find additional details about the ESLint rule at https://eslint.org/docs/latest/rules/no-console
2024-11-14 12:41:39 +01:00
Jonas Jenwald
471284f51b [api-minor] Disable ImageDecoder usage by default in Chromium browsers
Given that there are multiple issues with `ImageDecoder` in Chromium browsers, affecting both BMP and JPEG images, for now we (by default) disable that functionality there to avoid problems.

This also means that we can remove the previously added, and separate, `isChrome` API-option.
2024-11-14 12:05:15 +01:00
Jonas Jenwald
9bf9bbda0b
Merge pull request #19031 from Snuffleupagus/api-isImageDecoderSupported
[api-minor] Add a `getDocument` option to disable `ImageDecoder` usage
2024-11-13 09:19:05 +01:00
Tim van der Meij
f197c9faec
Merge pull request #19033 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-11-12 21:43:00 +01:00
Tim van der Meij
172e1bf2c2
Merge pull request #19035 from timvandermeij/python3.13
Use Python 3.13 in the GitHub workflows
2024-11-12 21:42:15 +01:00
Tim van der Meij
913738644a
Use Python 3.13 in the GitHub workflows
Python 3.13 is the current version and was released over a month ago
(see https://devguide.python.org/versions). The dependencies we use now
support Python 3.13, most importantly `fonttools` which uses OS-specific
builds and for which compatibility got introduced in
https://github.com/fonttools/fonttools/pull/3656 and the corresponding
`cp313` wheels for all distributions are published on
https://pypi.org/project/fonttools/#files.

Moreover, we fix forgotten `npx` usage in the font tests README which
was encountered while testing this patch.
2024-11-12 20:59:01 +01:00
Tim van der Meij
cfbbf61dd9
Update translations to the most recent versions 2024-11-12 20:36:16 +01:00
Tim van der Meij
499fab998e
Upgrade eslint to version 9
This is unblocked now that all dependencies have been updated and the
flat configuration format (compatible with ESLint 8 and 9) was
introduced first. The following deprecation warnings during `npm
install` are resolved by this upgrade:

```
npm warn deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
npm warn deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
npm warn deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
```

Note that according to https://eslint.org/version-support ESLint 8 is
officially EOL now, and ESLint 9 has been released for over seven
months and is the only officially supported version.

Fixes #17928.
2024-11-12 20:35:50 +01:00
Tim van der Meij
cdb32dae45
Update dependencies to the most recent versions 2024-11-12 20:22:27 +01:00
Tim van der Meij
6676492920
Merge pull request #19021 from Snuffleupagus/PartialEvaluator-#fetchData
Add a `PartialEvaluator` helper for fetching CMap and Standard Font data
2024-11-12 19:56:39 +01:00
Jonas Jenwald
65eedfb0fc [api-minor] Add a getDocument option to disable ImageDecoder usage
This allows end-users to forcibly disable `ImageDecoder` usage, even if the browser appears to support it (similar to the pre-existing option for `OffscreenCanvas`).
2024-11-12 17:12:42 +01:00
Jonas Jenwald
fe5967c84e
Merge pull request #19029 from nicolo-ribaudo/eslint-flat-config
Migrate to ESLint flat config
2024-11-12 16:22:54 +01:00
Nicolò Ribaudo
9e6ff979db
Migrate to ESLint flat config
Flat config is the new config system used by ESLint 9.
To make the migration easier, they also added
flat config support to ESLint 8.

This commit migrates the various ESLint configs in the repository to use
the new system, **without** upgrading to ESLint 9 yet.
2024-11-12 16:15:17 +01:00
calixteman
13a231cd3b
Merge pull request #19026 from calixteman/refactor_newrefs_saving
Simplify saving added/modified annotations.
2024-11-12 13:52:20 +01:00
Calixte Denizet
4bf7787084 Simplify saving added/modified annotations.
Having this map to collect the different changes will allow to know if some objects have already been modified.
2024-11-12 10:59:38 +01:00
calixteman
7a962031e9
Merge pull request #19024 from calixteman/disable_test_chrome
Disable ref test 'issue18896' for Chrome because it takes too much time
2024-11-11 19:11:30 +01:00
Calixte Denizet
92b7374aad Disable ref test 'issue18896' for Chrome because it takes too much time 2024-11-11 18:55:56 +01:00
calixteman
2ad8782428
Merge pull request #19023 from calixteman/issue19022
Apply gradient when stroking text
2024-11-11 17:15:50 +01:00
Calixte Denizet
79e1f155ac Apply gradient when stroking text
It fixes #19022.

I noticed that the glyph contours weren't correct (for T and x) and
because we forgot to close the contour.
2024-11-11 15:53:07 +01:00
Jonas Jenwald
16e86878d2 Add a PartialEvaluator helper for fetching CMap and Standard Font data
This avoids a little bit of code duplication, which cannot hurt.
2024-11-11 11:57:28 +01:00
Jonas Jenwald
5524216c23
Merge pull request #19015 from Snuffleupagus/@napi-rs/canvas
[api-minor] Replace the `canvas` package with `@napi-rs/canvas`
2024-11-10 19:45:01 +01:00
Tim van der Meij
b9c17efe35
Merge pull request #19019 from Snuffleupagus/userUnit-shorten
Shorten the `Page.prototype.userUnit` getter slightly
2024-11-10 18:31:00 +01:00
calixteman
34e4c4f9b6
Merge pull request #19018 from calixteman/issue19008
Set the padding of the buttons in the toolbars to zero
2024-11-10 17:05:55 +01:00
Jonas Jenwald
0b864ee7d5 Shorten the Page.prototype.userUnit getter slightly 2024-11-10 16:30:07 +01:00
Calixte Denizet
ca3b777b89 Set the padding of the buttons in the toolbars to zero
It fixes #19008.
In Firefox on mac, the default padding is set to 4px and with Firefox for iOS, it's set to 13px.
The padding is useless for such buttons.
2024-11-09 22:30:50 +01:00
Jonas Jenwald
9b62f2e7d1 Polyfill ImageData in Node.js environments
Given that `ImageData` has been supported for many years in all browsers, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/ImageData#browser_compatibility), we have a `typeof` check that's only necessary in Node.js environments.
Since the `@napi-rs/canvas` package provides that functionality, we can thus add an `ImageData` polyfill which allows us to ever so slightly simplify the code.
2024-11-09 18:51:32 +01:00
Jonas Jenwald
86f943ca03 [api-minor] Replace the canvas package with @napi-rs/canvas
The `@napi-rs/canvas` package has fewer dependencies, which should *hopefully* make installing and using it easier for `pdfjs-dist` end-users. (Over the years we've seen, repeatedly, that `canvas` can be difficult to install successfully.)
Furthermore, this package includes more functionality (such as `Path2D`) which reduces the overall number of dependencies in the PDF.js project.

One point to note is that `@napi-rs/canvas` is a fair bit newer than `canvas`, and has a lot fewer users, however looking at the commit history it does seem to be actively maintained.

Note that I've successfully tested the [Node.js examples](https://github.com/mozilla/pdf.js/tree/master/examples/node), in particular the `pdf2png` one, with this patch applied and things appear to work fine.

Please see:
 - https://www.npmjs.com/package/@napi-rs/canvas
 - https://github.com/Brooooooklyn/canvas
2024-11-09 18:51:29 +01:00
Jonas Jenwald
bff6738966
Merge pull request #19012 from Snuffleupagus/pr-18819
Fix Typo:XFATemplate class Para Styling paddingight => paddingRight
2024-11-06 12:12:45 +01:00
Pascal Maximilian Bremer
6d7157a875 Fix Typo:XFATemplate class Para Styling paddingight => paddingRight 2024-11-06 12:04:55 +01:00
calixteman
f520d2375b
Merge pull request #19011 from calixteman/roman
Simplify toRomanNumerals function
2024-11-06 09:23:20 +01:00
Jonas Jenwald
b666c4f7be
Merge pull request #19002 from Snuffleupagus/version-4.9
Bump library version to `4.9`
2024-11-06 09:12:07 +01:00
Jonas Jenwald
1a56b35af7
Merge pull request #19003 from Snuffleupagus/api-unittest-image-helpers
Add helper functions to load image blob/bitmap data in `test/unit/api_spec.js`
2024-11-06 09:11:28 +01:00
Calixte Denizet
d59f9648a9 Simplify toRomanNumerals function 2024-11-05 22:35:35 +01:00
Jonas Jenwald
fdfcfbc351
Merge pull request #19005 from Snuffleupagus/core_utils-shorten
Shorten a few helper functions in `src/core/core_utils.js`
2024-11-05 21:46:44 +01:00
Jonas Jenwald
c78eebbace
Merge pull request #19007 from Snuffleupagus/issue-18986
Try to improve handling of missing trailer dictionaries in `XRef.indexObjects` (issue 18986)
2024-11-05 21:45:27 +01:00
Jonas Jenwald
cbb02eb655
Merge pull request #19010 from CyberAndrii/18957-fix-error-on-empty-response-headers
Fix error on empty response headers
2024-11-05 21:22:29 +01:00
Andrii Vitiv
824a619a2a
Fix error on empty response headers
Fixes https://github.com/mozilla/pdf.js/issues/18957

https://github.com/mozilla/pdf.js/pull/18682 introduced a regression that causes the following error:

```
Uncaught TypeError: Failed to construct 'Headers': Invalid name
    at PDFNetworkStreamFullRequestReader._onHeadersReceived (pdf.mjs:10214:29)
    at NetworkManager.onStateChange (pdf.mjs:10103:22)
```

The mentioned PR replaced a call to `getResponseHeader()` with `getAllResponseHeaders()` without handling cases where it may return null or an empty string. Quote from the [docs](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#return_value):

> Returns:
>
>A string representing all of the response's headers (except those whose field name is Set-Cookie) separated by CRLF, or null if no response has been received. If a network error happened, an empty string is returned.

Run the following code and observe the error in the console. Note that the URL is intentionally set to an invalid value to simulate network error

```js
<script src="//mozilla.github.io/pdf.js/build/pdf.mjs" type="module"></script>

<script type="module">
  var url = 'blob:';

  pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.mjs';

  var loadingTask = pdfjsLib.getDocument(url);
  loadingTask.promise
    .then((pdf) => console.log('PDF loaded'))
    .catch((reason) => console.error(reason));

</script>
```
2024-11-05 21:52:50 +02:00
Jonas Jenwald
e92a929a58 Try to improve handling of missing trailer dictionaries in XRef.indexObjects (issue 18986)
The problem with the referenced PDF document has nothing to do with invalid dates, as the issue seems to suggest, but rather with the fact that it has neither an XRef table nor a trailer dictionary.
Given that crucial parts of the internal document structure is missing, you might argue that it's not really a PDF document.

In an attempt to support this kind of corruption, we'll simply iterate through all (previously found) XRef entries and pick one that *might* be a valid /Root dictionary.
There's obviously no guarantee that this works, and it might not be fast in larger PDF documents, but at least it cannot be any worse than *immediately* throwing `InvalidPDFException` as we previously did here.

*Please note:* I'm totally fine with this patch being rejected, since it's somewhat questionable if we should actually attempt to support "PDF documents" with this level of corruption.
2024-11-05 18:19:26 +01:00
Jonas Jenwald
2c90eee5a8 Shorten a few helper functions in src/core/core_utils.js
In a few cases we can ever so slightly shorten the code without negatively impacting the readability.
2024-11-05 13:58:00 +01:00
Jonas Jenwald
f2fb3b95ce Add helper functions to load image blob/bitmap data in test/unit/api_spec.js
This avoids repeating the same code multiple times, and as part of the changes we'll also utilize existing PDF.js helpers more.
2024-11-04 14:09:34 +01:00
Jonas Jenwald
e4a5bd9555 Bump library version to 4.9 2024-11-04 10:37:35 +01:00
Jonas Jenwald
cefd1ebcd2
Merge pull request #18959 from Snuffleupagus/Node-20
[api-minor] Update the minimum supported Node.js version to 20, and only support the Fetch API for "remote" PDF documents in Node.js
2024-11-04 10:29:55 +01:00
Jonas Jenwald
9269fb9be2 Remove the BaseFullReader and BaseRangeReader classes in the src/display/node_stream.js file
After the previous patch these base-classes are only extended once each and they can thus be combined with the final classes.
2024-11-03 16:18:12 +01:00
Jonas Jenwald
cbf0ca71bf [api-minor] Only support the Fetch API for "remote" PDF documents in Node.js environments
The Fetch API has been supported since Node.js version 18, see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#browser_compatibility
2024-11-03 16:18:10 +01:00
Jonas Jenwald
c7407230c1 [api-minor] Load Node.js packages/polyfills with process.getBuiltinModule
This allows *synchronous* loading of Node.js modules and (indirectly) packages, thus simplifying the code a fair bit.
2024-11-03 16:13:58 +01:00
Jonas Jenwald
4f01cdef18 [api-minor] Update the minimum supported Node.js version to 20
This patch updates the minimum supported environments as follows:
 - Node.js 20, which was released on 2023-04-18 and has now entered the "Maintenance"-phase; see https://github.com/nodejs/release#release-schedule

Furthermore, note also that Node.js 18 will fairly soon reach EOL.
2024-11-03 16:13:55 +01:00
Tim van der Meij
35673d3e6e
Merge pull request #19001 from timvandermeij/integration-test-scripting-uppercase
Fix the "must convert input to uppercase" scripting integration test
2024-11-03 15:47:45 +01:00
Tim van der Meij
3adf8b6be0
Fix the "must convert input to uppercase" scripting integration test
This integration test fails intermittently because we're not
(correctly) awaiting the sandbox actions. The `27R` field in
`issue14862.pdf` triggers sandbox events for every typing action, but
for the backspace and "a" character typing actions we weren't awaiting
the sandbox trip at all, and for other places we weren't awaiting it
fully (causing some characters to be missed in the assertion).

This commit fixes the issues by using the appropriate helper functions,
similar to what we did in PR #18399. Not only is this shorter in terms
of code, but it also fixed the near-permafail for this test with newer
versions of Puppeteer.
2024-11-03 15:08:55 +01:00
Tim van der Meij
20fbb4d661
Merge pull request #19000 from timvandermeij/types-node
Install and use the most recent Node types for the types tests
2024-11-03 14:41:06 +01:00
Tim van der Meij
ccfaf20ee2
Install and use the most recent Node types for the types tests
The types tests run in Node.js and therefore use Node types for e.g.
builtins. However, we didn't explicitly indicate this in
`tsconfig.json` (see [1] for more information and [2] for the PR where
we found this). Moreover, we didn't explicitly install the most recent
version of `@types/node` which implicitly made us fall back to version
14.14.45 (because that was installed as a dependency of other modules)
whereas much newer versions are available and we need those after
changes in Node.js (see [3] for more information and [4] for the PR
where we found this).

This commit fixes both issues by explicitly installing and using the
most recent Node.js types, which should also avoid future issues with
the types tests.

[1] https://github.com/TypeStrong/ts-node/issues/1012
[2] https://github.com/mozilla/pdf.js/pull/18237
[3] https://stackoverflow.com/questions/78790943/in-typescript-5-6-buffer-is-not-assignable-to-arraybufferview-or-uint8arr
[4] https://github.com/mozilla/pdf.js/pull/18959
2024-11-03 13:40:55 +01:00
Tim van der Meij
c1bcb46b3b
Merge pull request #18999 from Snuffleupagus/toBase64Util-unittest
Use the `toBase64Util` helper function in the unit-tests
2024-11-03 13:04:13 +01:00
Jonas Jenwald
f78a8f3c54 Use the toBase64Util helper function in the unit-tests 2024-11-03 11:25:19 +01:00
Tim van der Meij
5f77b907eb
Merge pull request #18997 from Snuffleupagus/Node-enable-Blob-unittest
Enable the 'gets PDF filename from query string appended to "blob:" URL' unit-test in Node.js
2024-11-03 11:11:36 +01:00
Tim van der Meij
7ae21ece4a
Merge pull request #18998 from Snuffleupagus/Node-enable-XFA-alt-unittest
Enable the "should have an alt attribute from toolTip" unit-test in Node.js
2024-11-03 11:10:54 +01:00
Tim van der Meij
3755d680e4
Merge pull request #18995 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-11-03 11:09:15 +01:00
Jonas Jenwald
faf9e32ecb Enable the "should have an alt attribute from toolTip" unit-test in Node.js
Despite the pending-message mentioning "Image", this appears to be another case where the code actually depends on [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#browser_compatibility); note cf3ca8b5bc/src/core/xfa/template.js (L3453)
2024-11-03 00:15:44 +01:00
Jonas Jenwald
15fbee158c Enable the 'gets PDF filename from query string appended to "blob:" URL' unit-test in Node.js
The necessary functionality has been supported in Node.js for quite some time now, please see:
 - https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static#browser_compatibility
2024-11-02 23:53:03 +01:00
Tim van der Meij
3854ab5efd
Update translations to the most recent versions 2024-11-02 20:21:59 +01:00
Tim van der Meij
3cd906829e
Update dependencies to the most recent versions 2024-11-02 20:20:58 +01:00
Tim van der Meij
cf3ca8b5bc
Merge pull request #18994 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-11-02 19:59:41 +01:00
Tim van der Meij
627a588336
Bump the stable version in pdfjs.config 2024-11-02 19:56:10 +01:00
Tim van der Meij
3634dab10c
Merge pull request #18988 from Snuffleupagus/split-dom-factory
Move the various DOM-factories into their own files
2024-11-02 19:06:47 +01:00
Tim van der Meij
e930f3030c
Merge pull request #18992 from Snuffleupagus/getPdfManager-inline-flushChunks
Inline the `flushChunks` helper function, used in `getPdfManager` on the worker-thread
2024-11-02 18:58:29 +01:00
Jonas Jenwald
e5485108ec
Merge pull request #18990 from Snuffleupagus/ensure-structTree-serializable
Ensure that serializing of StructTree-data cannot fail during loading
2024-11-02 15:17:10 +01:00
Jonas Jenwald
aa4839ed0f
Merge pull request #18993 from Snuffleupagus/stringToUTF16HexString-hexNumbers
Use the `hexNumbers` structure in the `stringToUTF16HexString` helper
2024-11-02 15:15:47 +01:00
Jonas Jenwald
2145a7b9ca Use the hexNumbers structure in the stringToUTF16HexString helper
We can re-use the `hexNumbers` structure here, since that allows us to directly lookup the hexadecimal values and shortens the code.
2024-11-02 15:00:32 +01:00
Jonas Jenwald
196f7d7df1 Inline the flushChunks helper function, used in getPdfManager on the worker-thread
- This helper function has only a single call-site, and the function is fairly short.

 - It'll only be invoked if range requests are *disabled*, or if the entire PDF manages to load *before* the headers are resolved (which is very unlikely).
   Hence, by default, this helper function is not invoked.

 - By inlining the code we're able to utilize the existing error-handling at the call-site, rather than having to duplicate it, which further reduces the size of this code.

Finally, while slightly unrelated, this patch also adds optional chaining in one spot in the file (PR 16424 follow-up).
2024-11-02 11:06:30 +01:00
Jonas Jenwald
b26dc19392 Ensure that serializing of StructTree-data cannot fail during loading
I discovered that doing skip-cache re-reloading of https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf would *intermittently* cause (some of) the AnnotationLayers to break with errors printed in the console (see below).

In hindsight this bug is really obvious, however it took me quite some time to find it, since the `StructTreePage.prototype.serializable` getter will lookup various data and all of those cases can fail during loading when streaming and/or range requests are being used.

Finally, to prevent any future errors, ensure that the viewer won't break in these sort of situations.

```
Uncaught (in promise)
Object { message: "Missing data [19098296, 19098297)", name: "UnknownErrorException", details: "MissingDataException: Missing data [19098296, 19098297)", stack: "BaseExceptionClosure@resource://pdf.js/build/pdf.mjs:453:29\n@resource://pdf.js/build/pdf.mjs:456:2\n" }
viewer.mjs:8801:55

\#renderAnnotationLayer: "UnknownErrorException: Missing data [17552729, 17552730)". viewer.mjs:8737:15

Uncaught (in promise)
Object { message: "Missing data [17552729, 17552730)", name: "UnknownErrorException", details: "MissingDataException: Missing data [17552729, 17552730)", stack: "BaseExceptionClosure@resource://pdf.js/build/pdf.mjs:453:29\n@resource://pdf.js/build/pdf.mjs:456:2\n" }
viewer.mjs:8801:55
```
2024-11-01 17:43:59 +01:00
Jonas Jenwald
4e12906061 Move the various DOM-factories into their own files
- Over time the number and size of these factories have increased, especially the `DOMFilterFactory` class, and this split should thus aid readability/maintainability of the code.

 - By introducing a couple of new import maps we can avoid bundling the `DOMCMapReaderFactory`/`DOMStandardFontDataFactory` classes in the Firefox PDF Viewer, since they are dead code there given that worker-thread fetching is always being used.

 - This patch has been successfully tested, by running `$ ./mach test toolkit/components/pdfjs/`, in a local Firefox artifact-build.

*Note:* This patch reduces the size of the `gulp mozcentral` output by `1.3` kilo-bytes, which isn't a lot but still cannot hurt.
2024-11-01 13:31:28 +01:00
Tim van der Meij
06f3b2d0a6
Merge pull request #18983 from Snuffleupagus/api-FetchBuiltInCMap-FetchStandardFontData-async
Change the "FetchBuiltInCMap"/"FetchStandardFontData" message-handlers to be asynchronous
2024-10-31 20:30:11 +01:00
Jonas Jenwald
3ed438aef5
Merge pull request #18979 from Snuffleupagus/L10n-#elements-lazy-init
Don't initialize `L10n.#elements` eagerly since it's unused in MOZCENTRAL builds
2024-10-31 11:03:24 +01:00
Jonas Jenwald
7572382c7a Change the "FetchBuiltInCMap"/"FetchStandardFontData" message-handlers to be asynchronous
This way we can directly throw Errors, rather than having to "manually" return rejected Promises, which is ever so slightly shorter.

Also, since `useWorkerFetch` is always true in MOZCENTRAL builds these message-handlers should not be invoked there.
2024-10-31 09:29:11 +01:00
Jonas Jenwald
cdd4b052f9 Don't initialize L10n.#elements eagerly since it's unused in MOZCENTRAL builds
It's not necessary to manually start translation in the Firefox PDF Viewer, and doing so would even cause problems there (see issue 17142).
2024-10-30 15:20:44 +01:00
Jonas Jenwald
f013c39b9f
Merge pull request #18978 from Snuffleupagus/toHexUtil-simplify
Re-factor the `toHexUtil` helper (PR 17862 follow-up)
2024-10-29 17:10:36 +01:00
calixteman
f142fb8c28
Merge pull request #18972 from calixteman/refactor_highlight
[Editor] Refactor the free highlight stuff in order to be able to use the code for more general drawing
2024-10-29 17:09:03 +01:00
Jonas Jenwald
db1238aae3 Re-factor the toHexUtil helper (PR 17862 follow-up)
We can re-use the `hexNumbers` structure, since that allows us to directly lookup the hexadecimal values and shortens the code.
2024-10-29 16:35:44 +01:00
Jonas Jenwald
9870099e90
Merge pull request #18977 from Snuffleupagus/api-ReaderHeadersReady-simplify
Simplify the "ReaderHeadersReady" message-handler in the API
2024-10-29 15:46:31 +01:00
Calixte Denizet
5a9607b2ad [Editor] Refactor the free highlight stuff in order to be able to use the code for more general drawing
One goal is to make the code for drawing with the Ink tool similar to the one to free highlighting:
it doesn't really make sense to have so different ways to do almost the same thing.

When the zoom level is high, it'll avoid to create a too big canvas covering all the page which consume
more memory, makes the drawing very slow and the overall user xp pretty bad.

A second goal is to be able to easily implement more drawing tools where we would just have to implement
how to draw from the pointer coordinates.
2024-10-29 15:41:08 +01:00
Jonas Jenwald
25cf4add05
Merge pull request #17862 from Snuffleupagus/fingerprints-toHex
Improve the implementation of the `PDFDocument.fingerprints`-getter
2024-10-29 15:34:02 +01:00
Jonas Jenwald
afb4813d1c Simplify the "ReaderHeadersReady" message-handler in the API
We can convert the handler to an `async` function, which removes the need to create a temporary Promise here.
Given the age of this code it shouldn't hurt to simplify it a little bit.
2024-10-29 14:59:39 +01:00
Jonas Jenwald
8f47d06d07 Add helper functions to allow using new Uint8Array methods
This allows using the new methods in browsers that support them, e.g. Firefox 133+, while still providing fallbacks where necessary; see https://github.com/tc39/proposal-arraybuffer-base64

*Please note:* These are not actual polyfills, but only implements what we need in the PDF.js code-base. Eventually this patch should be reverted, once support is generally available.
2024-10-29 10:22:35 +01:00
Jonas Jenwald
bfc645bab1 Introduce some Uint8Array.fromBase64 and Uint8Array.prototype.toBase64 usage in the main code-base
See https://github.com/tc39/proposal-arraybuffer-base64
2024-10-29 10:22:35 +01:00
Jonas Jenwald
f9fc477080 Improve the implementation of the PDFDocument.fingerprints-getter
- Add explicit `length` validation of the /ID entries. Given the `EMPTY_FINGERPRINT` constant we're already *implicitly* assuming a particular length.

 - Move the constants into the `fingerprints`-getter, since they're not used anywhere else.

 - Replace the `hexString` helper function with the standard `Uint8Array.prototype.toHex` method; see https://github.com/tc39/proposal-arraybuffer-base64
2024-10-29 10:22:35 +01:00
Jonas Jenwald
3a85479c67
Merge pull request #18974 from Snuffleupagus/issue-18973
Allow `StreamsSequenceStream` to skip sub-streams that are not actual Streams (issue 18973)
2024-10-29 10:21:35 +01:00
Jonas Jenwald
48a18585f2 Allow StreamsSequenceStream to skip sub-streams that are not actual Streams (issue 18973)
This extends PR 13796 to also handle the case where sub-streams contain invalid data, i.e. anything that isn't a Stream, however please note that in these cases there's no guarantee that we'll render the page "correctly".

Note that Adobe Reader, i.e. the PDF reference implementation, cannot render the last page of the referenced PDF document.
2024-10-29 09:36:08 +01:00
Jonas Jenwald
93961e2802
Merge pull request #18971 from Snuffleupagus/AltText-fluent
[Editor] Utilize Fluent "better" when localizing the AltText
2024-10-28 20:53:06 +01:00
Jonas Jenwald
ee812b5df2 [Editor] Utilize Fluent "better" when localizing the AltText
Currently we manually localize and update the DOM-elements of the AltText-button, and it seems nicer to utilize Fluent "properly" for that task.
This can be achieved by introducing an explicit `span`-element on the AltText-button (similar to e.g. the regular toolbar-buttons), and adding a few more l10n-strings, since that allows just setting the `data-l10n-id`-attribute on all the relevant DOM-elements.

Finally, note how we no longer need to localize any strings eagerly when initializing the various editors.
2024-10-28 17:19:02 +01:00
calixteman
9108848743
Merge pull request #18918 from calixteman/bmp_decoder
Use a BMP decoder when resizing an image
2024-10-28 16:30:20 +01:00
Calixte Denizet
b649b6f8dd Use a BMP decoder when resizing an image
The image decoding won't block the main thread any more.
For now, it isn't enabled for Chrome because issue6741.pdf leads to a crash.
2024-10-28 14:09:52 +01:00
calixteman
07a1d30fad
Merge pull request #18968 from calixteman/bug1903588
[Editor] Split the long words when showing the alt-text tooltip (bug 1903588)
2024-10-28 14:07:48 +01:00
Calixte Denizet
8fbb9e2f16 [Editor] Split the long words when showing the alt-text tooltip (bug 1903588) 2024-10-28 11:08:30 +01:00
calixteman
2bee3af0ee
Merge pull request #18967 from calixteman/bug1910431
Make util.scand a bit more flexible with dates which don't match the given format (bug 1910431)
2024-10-28 09:36:34 +01:00
Calixte Denizet
230d7f9229 Make util.scand a bit more flexible with dates which don't match the given format (bug 1910431) 2024-10-27 19:19:06 +01:00
Tim van der Meij
5418060bbc
Merge pull request #18951 from Snuffleupagus/CMap-isCompressed
[api-minor] Remove the `CMapCompressionType` enumeration
2024-10-27 14:42:00 +01:00
Tim van der Meij
b5805caacd
Merge pull request #18965 from Snuffleupagus/_goodSquareLength-static
Re-factor the `ImageResizer._goodSquareLength` definition
2024-10-27 14:38:43 +01:00
Jonas Jenwald
8a2b95418a Re-factor the ImageResizer._goodSquareLength definition
Move the `ImageResizer._goodSquareLength` definition into the class itself, since the current position shouldn't be necessary, and also convert it into an actually private field.
2024-10-27 11:03:04 +01:00
calixteman
0d42e56cab
Merge pull request #18960 from calixteman/issue18956
Always fill the mask with the backdrop color
2024-10-26 15:16:06 +02:00
Calixte Denizet
d114f71feb Always fill the mask with the backdrop color
It fixes #18956.

In the patch #18029, for performance reasons and because I thought it was useless, I deliberately chose to not fill the mask
with the backdrop color when it's full black: it was a bad idea.
So in this patch we always add the backdrop color to the mask.
2024-10-26 14:14:51 +02:00
Jonas Jenwald
b048420d21 [api-minor] Remove the CMapCompressionType enumeration
After the binary CMap format had been added there were also some ideas about *maybe* providing other formats, see [here](https://github.com/mozilla/pdf.js/pull/8064#issuecomment-279730182), however that was over seven years ago and we still only use binary CMaps.
Hence it now seems reasonable to simplify the relevant code by removing `CMapCompressionType` and instead just use a boolean to indicate the type of the built-in CMaps.
2024-10-24 11:08:16 +02:00
Jonas Jenwald
50c291eb33 Unconditionally cache built-in CMaps on the worker-thread
Given that we've not shipped, nor used, anything except binary CMaps for years let's just cache them unconditionally (since that's a tiny bit less code).
2024-10-24 10:15:09 +02:00
calixteman
bde36f28be
Merge pull request #18947 from calixteman/add_comment_ftl
Add a comment in l10n file for the non-standard attribute default-content
2024-10-23 15:16:18 +02:00
Calixte Denizet
c0c527266d Add a comment in l10n file for the non-standard attribute default-content 2024-10-23 15:12:52 +02:00
calixteman
1ad09779f1
Merge pull request #18910 from calixteman/image_decoder1
Use ImageDecoder in order to decode jpeg images (bug 1901223)
2024-10-23 13:54:07 +02:00
Calixte Denizet
b6c4f0b69e Use ImageDecoder in order to decode jpeg images (bug 1901223) 2024-10-23 10:42:01 +02:00
Tim van der Meij
1e07b87bb6
Merge pull request #18933 from Snuffleupagus/base-factory-fetchData
Change the `BaseCMapReaderFactory` fetch-helper to return a `Uint8Array`
2024-10-22 20:03:50 +02:00
Tim van der Meij
54a77d24eb
Merge pull request #18940 from Snuffleupagus/bug-report-PDF-placeholder
Try to discourage "unrelated" information under `Attach (recommended) or Link to PDF file` in the bug report template (PR 18535 follow-up)
2024-10-22 19:53:33 +02:00
Jonas Jenwald
49c3dc9c5f
Merge pull request #18942 from Snuffleupagus/issue-18941
Fallback to a standard font if a font-file entry doesn't contain a Stream (issue 18941)
2024-10-22 18:18:44 +02:00
Jonas Jenwald
236c8d862e Re-factor how we handle missing, corrupt, or empty font-file entries
This improves the fixes for e.g. issue 9462 and 18941 slightly and allows better fallback behaviour for non-standard fonts.
2024-10-22 17:07:12 +02:00
Jonas Jenwald
63b34114b1 Fallback to a standard font if a font-file entry doesn't contain a Stream (issue 18941)
The PDF document is clearly corrupt, since it has /FontFile2 entries that are Dictionaries which obviously isn't correct.
While there's obviously no guarantee that things will look perfect this way, actually rendering the text at all should be an improvement in general.
2024-10-22 11:51:28 +02:00
Jonas Jenwald
a809461738 Try to discourage "unrelated" information under Attach (recommended) or Link to PDF file in the bug report template (PR 18535 follow-up)
Unfortunately it turns out to be somewhat common for users to provide a bunch of "unrelated" information in this field, or even stating their entire problem there, rather than placing it under the appropriate headings further down in the template.
2024-10-22 09:23:32 +02:00
Jonas Jenwald
6c3336f04f Re-factor the DefaultFileReaderFactory unit-test helper
We can re-use the existing helpers from `src/display/` rather than re-implementing the functionality here.
2024-10-21 13:20:31 +02:00
Jonas Jenwald
df696063b9 Change the BaseCMapReaderFactory fetch-helper to return a Uint8Array
This moves more functionality into the base-class, rather than having to duplicate that in the extending classes.
For consistency, also updates the `BaseStandardFontDataFactory` and introduces more `async`/`await` in various relevant code.
2024-10-21 13:20:18 +02:00
Jonas Jenwald
d37e4b08e4
Merge pull request #18930 from Snuffleupagus/rm-duplicate-print-download-mask-image
Remove `mask-image` duplication for the print/download buttons
2024-10-21 08:31:16 +02:00
Jonas Jenwald
65b38f24ff Remove mask-image duplication for the print/download buttons
With the recent re-factoring of the viewer CSS rules we now have some duplication of the `mask-image` definitions for the print/download buttons in the secondaryToolbar; note 17419de157/web/viewer.css (L1204-L1210)
2024-10-20 21:15:09 +02:00
Tim van der Meij
17419de157
Merge pull request #18923 from timvandermeij/integration-test-text-layer
Fix the "Text selection using mouse doesn't jump when hovering on an empty area in a single page" integration test
2024-10-20 19:49:49 +02:00
Tim van der Meij
24b8393bfe
Fix the "Text selection using mouse doesn't jump when hovering on an empty area in a single page" integration test
The `getSpanRectFromText` helper function returns the location as float
values. This could be desirable in cases where the exact values matter
(for example during comparisons), but in the text layer tests we don't
need this precision. Moreover, the Puppeteer `page.mouse.move` API
apparently doesn't work correctly if float values are given as input.

Note that this test only failed because it couldn't move to the initial
selection position; any subsequent moves actually worked because the
`moveInSteps` helper function already rounded all values correctly.

This commit fixes the issue by consistently rounding all values that we
pass to Puppeteer's `page.mouse.move` API.
2024-10-20 19:42:40 +02:00
Tim van der Meij
b94ab46be5
Merge pull request #18929 from timvandermeij/eslint-perfectionist
Replace `eslint-plugin-sort-exports` by `eslint-plugin-perfectionist`
2024-10-20 19:41:37 +02:00
Jonas Jenwald
9c6f85f1f2
Merge pull request #18920 from Snuffleupagus/FreeText-l10n-default-content
Simplify localization of the "default-content" in FreeText editors
2024-10-20 19:31:34 +02:00
Tim van der Meij
347f155ebc
Replace eslint-plugin-sort-exports by eslint-plugin-perfectionist
The `eslint-plugin-sort-exports` plugin doesn't support ESLint 9 or has
published plans to do so. The `eslint-plugin-perfectionist` does support
ESLint 9 [1], seems more actively maintained [2, 3] and contains other
rules that could be interesting later on [4]. Note that both plugins
behave the same, except for two cases which are updated here.

[1] https://github.com/azat-io/eslint-plugin-perfectionist/issues/154
[2] https://github.com/azat-io/eslint-plugin-perfectionist/commits/main
[3] https://www.npmjs.com/package/eslint-plugin-perfectionist?activeTab=versions
[4] https://perfectionist.dev/rules
2024-10-20 18:50:35 +02:00
Jonas Jenwald
2ef3fd2a81 Simplify localization of the "default-content" in FreeText editors
By using "data-l10n-attrs" it's possible to instruct Fluent to localize *custom* attributes, which means that we don't need to manually translate/update the "default-content" in FreeText editors.
2024-10-20 18:46:44 +02:00
Tim van der Meij
f9659f4635
Merge pull request #18921 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-10-20 16:35:14 +02:00
Tim van der Meij
ccfb8a20c2
Update translations to the most recent versions 2024-10-20 15:59:03 +02:00
Tim van der Meij
b4651390bb
Update dependencies to the most recent versions 2024-10-20 15:58:59 +02:00
Tim van der Meij
29b2f26131
Merge pull request #18927 from timvandermeij/eslint-plugin-cleanup
Remove the `eslint-plugin-{fetch-options,html}` and `eslint-config-prettier` dependencies
2024-10-20 15:56:04 +02:00
Tim van der Meij
6def1c8453
Remove the eslint-config-prettier dependency
The `eslint-plugin-prettier` dependency already installs this dependency
by default nowadays, so we don't have to specify it ourselves anymore.
2024-10-20 15:38:22 +02:00
Tim van der Meij
760dd24ea0
Remove the eslint-plugin-{fetch-options,html} dependencies
The plugins have originally been introduced in commit d63da81 for the
`eslint-plugin-mozilla` dependency, but the `eslint-plugin-mozilla`
plugin got removed in commit be93d53 and we also don't use the plugins
ourselves in e.g. our `.eslintrc` files (as evidenced by `npx gulp lint`
not failing while it does fail if we remove any of the other plugins).
2024-10-20 15:38:22 +02:00
Tim van der Meij
df77401821
Merge pull request #18925 from Snuffleupagus/ci-test-Node-23
Run CI tests in Node.js version 23
2024-10-20 14:03:20 +02:00
Jonas Jenwald
6604adb5ff Run CI tests in Node.js version 23
Node.js version 23 was recently released, see https://github.com/nodejs/release#release-schedule, hence it cannot hurt to start testing in that environment.
2024-10-20 13:50:48 +02:00
Jonas Jenwald
521f5b8cdc
Merge pull request #18924 from Snuffleupagus/version-4.8
Bump library version to `4.8`
2024-10-20 12:52:16 +02:00
Jonas Jenwald
4165910fd9 Bump library version to 4.8 2024-10-20 12:49:06 +02:00
Jonas Jenwald
2a4630f89a
Merge pull request #18922 from Snuffleupagus/node-canvas-3
[api-minor] Update the `canvas` package to version 3
2024-10-20 12:42:59 +02:00
Jonas Jenwald
54e00b0104 Catch errors when invoking applyPath2DToCanvasRenderingContext
This way we allow the rest of the packages to be loaded successfully, such that e.g. the Node.js unit-tests work correctly.

Note that this occurred after updating the `node-canvas` package to version `3.0.0-rc2`, however it's not immediately clear to me if it's a problem there or in the `path2d` package; see also nilzona/path2d-polyfill/issues/84.
2024-10-20 12:39:10 +02:00
Jonas Jenwald
6ae13fac9b [api-minor] Update the canvas package to version 3
This allows us to run the Node.js unit-tests in version 22, which is good since it'll very soon become the active LTS release; see https://github.com/nodejs/release#release-schedule.
2024-10-20 12:39:08 +02:00
Tim van der Meij
025c0875b0
Merge pull request #18919 from Snuffleupagus/GrabToPan-AbortSignal
Remove event listeners with `AbortSignal` in the `GrabToPan` class
2024-10-19 13:08:10 +02:00
Jonas Jenwald
c3bbeb51e3 Remove event listeners with AbortSignal in the GrabToPan class 2024-10-19 12:01:43 +02:00
Jonas Jenwald
c88d3a31cf
Merge pull request #18888 from Snuffleupagus/MessageHandler-AbortSignal
Re-factor the `MessageHandler`-class event handler function
2024-10-18 17:27:14 +02:00
calixteman
762667b2df
Merge pull request #18916 from calixteman/bug1922766
When changing a property on a radio button then change it for the siblings (bug 1922766)
2024-10-17 20:21:00 +02:00
Calixte Denizet
86d1272d1b When changing a property on a radio button then change it for the siblings (bug 1922766) 2024-10-17 18:27:12 +02:00
Jonas Jenwald
788eabc76a Re-factor the MessageHandler-class event handler function
- Change the "message" event handler function to a private method.

 - Remove the "message" event listener with an `AbortSignal`.

 - Extend the `LoopbackPort`-class with `AbortSignal` support.
2024-10-16 10:16:27 +02:00
Jonas Jenwald
689ffda9df
Merge pull request #18902 from Snuffleupagus/pdkids-rm-linked-test
Add the `pdkids` PDF document to the repository
2024-10-15 22:15:09 +02:00
Tim van der Meij
96bced7f5b
Merge pull request #18884 from hubgit/patch-1
Handle null parentElement for selection anchor
2024-10-15 20:55:23 +02:00
Tim van der Meij
ec79316379
Merge pull request #18905 from Snuffleupagus/optionalContentConfig-determine-groups
Reduce duplication when collecting optional content groups
2024-10-15 20:46:23 +02:00
Tim van der Meij
e8149b3982
Merge pull request #18898 from Snuffleupagus/PDFViewerApplication-bindEvents-opts
Create fewer Objects in `PDFViewerApplication.bindEvents`
2024-10-15 20:34:45 +02:00
Tim van der Meij
54606e9b7b
Merge pull request #18893 from Snuffleupagus/PDFViewerApplication-rm-removeEventListener-opts
Remove unnecessary options from `removeEventListener` in the `web/app.js` file
2024-10-15 20:26:19 +02:00
Jonas Jenwald
805f962181 Reduce duplication when collecting optional content groups
After PR 18825 we can easily "compute" the optional content groups, and can thus avoid tracking them manually.
2024-10-15 13:20:30 +02:00
Jonas Jenwald
424f81c4db
Merge pull request #18825 from agrahn/rbgroups
implementing optional content radiobutton groups
2024-10-15 13:11:19 +02:00
Alexander Grahn
441efe456e Optional Content (OC) radiobutton (RB) groups implemented. Resolves #18823.
The code parses the /RBGroups entry in the OC configuration dict and adds the property `rbGroups' to instances of the OptionalContentGroup class. rbGroups takes an array of Sets, where each Set instance represents an RB group the OptionalContentGroup instance is a member of. Such a Set instance contains all OCG ids within the corresponding RB group. RB groups an OCG is associated with are processed when its visibility is set to true, as required by the PDF spec.
2024-10-15 11:34:45 +02:00
Jonas Jenwald
fb3c7b6d8f Add the pdkids PDF document to the repository
Given that the sub-title of that document is "Public domain texts for young people." and that the images have clear sources at the end of the document, it should (hopefully) be OK to add it to the repository rather than relying on a linked test-case.
2024-10-15 10:55:17 +02:00
calixteman
c10d0935c4
Merge pull request #18899 from calixteman/issue18896
Some jpx images can have a mask
2024-10-14 21:56:36 +02:00
Calixte Denizet
8b7b39f5d6 Some jpx images can have a mask
It fixes #18896.
2024-10-14 21:50:32 +02:00
Jonas Jenwald
4d7f29d736 Create fewer Objects in PDFViewerApplication.bindEvents
Given that all listeners need the same options we can create and re-use a single options-Objects for all of them.
2024-10-14 11:48:41 +02:00
calixteman
e1f9fa4ea5
Merge pull request #18895 from calixteman/issue18894
Fallback on gray colorspace when there are no colorspace and no name in the scn/SCN arguments
2024-10-13 17:56:52 +02:00
Calixte Denizet
e7ab8cd8c1 Fallback on gray colorspace when there are no colorspace and no name in the scn/SCN arguments
It fixes #18894.
2024-10-13 16:02:07 +02:00
Jonas Jenwald
4ae6132d07 Remove unnecessary options from removeEventListener in the web/app.js file
Only the `capture` parameter matters when removing an event listener, see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#matching_event_listeners_for_removal
2024-10-13 11:39:36 +02:00
calixteman
1c0c070847
Merge pull request #18890 from calixteman/clamp_indexedcs_hival
Clamp the hival parameter of Indexed color space to the range [0; 255]
2024-10-12 23:53:59 +02:00
calixteman
e28dd8e824
Merge pull request #18889 from calixteman/rm_useless_aria_has_popup
Don't add attribute 'aria-haspopup' when no popup is rendered for an annotation
2024-10-12 23:52:15 +02:00
Calixte Denizet
4dea773c5b Clamp the hival parameter of Indexed color space to the range [0; 255]
Since this value is used to allocate an array, it makes sense to avoid to use too much memory.
From the specs, this value must be in the range [0; 255] (see section 8.6.6.3).
This patch removes the unused property 'highVal'.
2024-10-12 23:50:58 +02:00
Calixte Denizet
7c43cb2dae Don't add attribute 'aria-haspopup' when no popup is rendered for an annotation
and for ink annotations, create the popup after the loop in order to avoid useless
elements creation.
2024-10-12 20:51:40 +02:00
Tim van der Meij
c3af34271e
Merge pull request #18881 from Snuffleupagus/AltTextManager-rm-events-AbortSignal
Remove event listeners with `AbortSignal` in the `AltTextManager` class
2024-10-11 19:37:00 +02:00
Tim van der Meij
02b33b970b
Merge pull request #18885 from Snuffleupagus/PDFDateString-regex
Move the regular expression caching into the `PDFDateString` class
2024-10-11 19:32:13 +02:00
calixteman
4a0c508689
Merge pull request #18833 from calixteman/gulp_testfilter
Add an option to gulp makeref/browsertest to only run tests with specific ids
2024-10-11 15:54:21 +02:00
Jonas Jenwald
8afc542ae2 Move the regular expression caching into the PDFDateString class
This code is old enough that it pre-dates availability of private class fields, hence why this wasn't done originally.
2024-10-11 15:34:58 +02:00
Alf Eaton
e97e9c93d6
Handle null parentElement for selection anchor 2024-10-11 13:58:06 +01:00
Jonas Jenwald
6f307e90a3 Remove event listeners with AbortSignal in the AltTextManager class 2024-10-11 12:05:36 +02:00
Calixte Denizet
6dd7726022 Add an option to gulp makeref/browsertest to only run tests with specific ids
It can be used like this: `gulp makeref -t tracemonkey-eq` or `gulp browsertest --testfilter tracemonkey-text`.
2024-10-10 21:58:16 +02:00
calixteman
c6d01caf65
Merge pull request #18860 from calixteman/issue18775
Fix failing integration test on Windows with Chrome
2024-10-10 21:46:36 +02:00
Calixte Denizet
edc2cd1968 Fix failing integration test on Windows with Chrome
It fixes #18775.
2024-10-10 21:27:55 +02:00
Tim van der Meij
0543e9e49c
Merge pull request #18874 from Snuffleupagus/ColorPicker-AbortSignal-any
[Editor] Remove `ColorPicker` event listeners with `AbortSignal.any()` (PR 18586 follow-up)
2024-10-10 19:55:19 +02:00
calixteman
a77bf87c50
Merge pull request #18879 from calixteman/highlight_hover
Don't add the grey outline when hovering a selected highlight
2024-10-10 15:28:59 +02:00
calixteman
5f522d1c60
Merge pull request #18878 from calixteman/issue18876
Avoid exceptions in the console with ill-formed flate streams
2024-10-10 14:25:35 +02:00
Calixte Denizet
fa7df01568 Don't add the grey outline when hovering a selected highlight
When playing with a pen, I noticed that sometimes a free highlight has still its
gray outline when an other one is drawn: for any reason the pointerleave event isn't
triggered.
2024-10-10 14:12:50 +02:00
Calixte Denizet
f2f56b6464 Avoid exceptions in the console with ill-formed flate streams
It fixes #18876.
2024-10-10 12:07:30 +02:00
Jonas Jenwald
14537d1412 [Editor] Remove ColorPicker event listeners with AbortSignal.any() (PR 18586 follow-up)
Also, removes another "unnecessary" bound-method.
2024-10-09 10:58:35 +02:00
Tim van der Meij
233ac1773d
Merge pull request #18873 from Snuffleupagus/visibilitychange-AbortSignal-any
Remove the temporary "visibilitychange" listener, in `PDFViewer`, with `AbortSignal.any()`
2024-10-08 20:41:43 +02:00
Tim van der Meij
1269c6a4f9
Merge pull request #18871 from Snuffleupagus/PDFDocument-more-ensure
Improve the promise-caching in the `PDFDocument.fieldObjects` getter
2024-10-08 20:11:46 +02:00
Tim van der Meij
b15dd55c3a
Merge pull request #18862 from timvandermeij/integration-scripting-delays
Fix typing logic in the scripting integration tests
2024-10-08 19:59:13 +02:00
Jonas Jenwald
31b0a496fd Remove the temporary "visibilitychange" listener, in PDFViewer, with AbortSignal.any()
This is similar to a lot of other code, where we've been replacing explicit `removeEventListener`-calls.
Given the somewhat limited availability of `AbortSignal.any()`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static#browser_compatibility), this event listener will no longer be immediately removed in older browsers (however that should be fine).
2024-10-08 15:38:31 +02:00
Jonas Jenwald
662bd022ce Reduce duplication in the PDFDocument.calculationOrderIds getter 2024-10-08 12:24:09 +02:00
Jonas Jenwald
e3b5ed2e40 Improve the promise-caching in the PDFDocument.fieldObjects getter
After PR 18845 we're accessing this getter more, hence it seems like a good idea to ensure that the initial `formInfo` access is covered as well.
While unlikely to be a problem in practice, at least theoretically that data may not be available and the code in `fieldObjects` could thus currently be *unintentionally* invoked more than once.
2024-10-08 12:15:04 +02:00
Tim van der Meij
1d4376c2e2
Fix typing logic in the scripting integration tests
The default `page.type()` API from Puppeteer works for text fields that
only dispatch a sandbox event on e.g. focus loss (i.e. after all
characters have been inserted), and for those we can also use the
default typing delay from Puppeteer instead of defining our own value.

However, it doesn't work correctly for text fields where every character
insertion dispatches a sandbox event. This is because processing the
sandbox event takes some time and Puppeteer must wait for that before it
can (safely) insert the next character. This commit therefore introduces
a helper function to type a given value correctly in such text fields.

Not only does this fix intermittent failures if our delay was too low
for sandbox processing to complete, but it also speeds up the tests by
eliminating our delays in places where they were (much) higher than
necessary. In total the runtime of the scripting integration test suite
goes from 137 seconds before this patch to 100 seconds after this patch.
2024-10-06 21:13:46 +02:00
Tim van der Meij
81cf42df47
Merge pull request #18858 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-10-06 13:49:12 +02:00
Tim van der Meij
32caffb438
Bump the stable version in pdfjs.config 2024-10-06 13:46:35 +02:00
Tim van der Meij
8b73b828b6
Merge pull request #18844 from calixteman/bug1922063
Use Calibri and Lucida Console, when it's possible, in place of sans-serif and monospaced (bug 1922063)
2024-10-06 12:52:58 +02:00
Tim van der Meij
7eee86e078
Merge pull request #18855 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-10-06 12:46:41 +02:00
Tim van der Meij
e6a413d201
Update translations to the most recent versions 2024-10-06 12:43:07 +02:00
Tim van der Meij
dcc46ceafa
Upgrade eslint-plugin-unicorn to version 56.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v56.0.0
doesn't indicate any breaking changes that should impact us.
2024-10-06 12:43:07 +02:00
Tim van der Meij
78bf5287d1
Update dependencies to the most recent versions
Note that the new version of `eslint-plugin-import` contains support
for ESLint 9.

Moreover, the new version of Babel removed the leading space for import
comments (see https://github.com/babel/babel/pull/16780), so we update
the corresponding test expectation to match this.

Fixes a part of #17928.
2024-10-06 12:43:07 +02:00
Calixte Denizet
a45e4a391a Use Calibri and Lucida Console, when it's possible, in place of sans-serif and monospaced (bug 1922063)
A recent change in Firefox induced too much difference between the text widths computed in using a Canvas
and the ones computed by the text layout engine when rendering the text layer. Consequently, the
text selection can be bad on Windows with some fonts like Arial or Consolas.
This patch is a workaround to try to use in first place some fonts which don't have the problem.
2024-10-05 20:45:25 +02:00
calixteman
5a25c477b7
Merge pull request #18853 from calixteman/issue18036
Keep the empty lines in the text fields
2024-10-05 17:44:21 +02:00
Calixte Denizet
3194f3de8b Keep the empty lines in the text fields
It fixes #18036.
2024-10-05 16:19:41 +02:00
Tim van der Meij
9e69735914
Merge pull request #18854 from sylvestre/patch-1
Add more authors
2024-10-05 13:00:42 +02:00
Sylvestre Ledru
64ca2eeb83
Add more authors 2024-10-04 22:38:31 +02:00
Jonas Jenwald
6aef332bcd
Merge pull request #18852 from Snuffleupagus/bug-1922618
Change how we handle l10n-args for dates in the DocumentProperties dialog (bug 1922618)
2024-10-04 20:21:07 +02:00
calixteman
ac563b90b3
Merge pull request #18845 from calixteman/issue15096
Fix missing annotation parent in using the one from the Fields entry
2024-10-04 20:16:05 +02:00
Calixte Denizet
3103deaa44 Fix missing annotation parent in using the one from the Fields entry
Fixes #15096.
2024-10-04 20:00:19 +02:00
calixteman
7c1883a839
Merge pull request #18851 from calixteman/issue18849
[Editor] Avoid an exception when undoing the deletion of a pre-existing annotation
2024-10-04 19:54:18 +02:00
Jonas Jenwald
c681ff25d8 Change how we handle l10n-args for dates in the DocumentProperties dialog (bug 1922618)
Strangely enough the code works just fine as-is in the GENERIC viewer, so there must be some difference between the Firefox built-in Fluent implementation and the Fluent.js one.

It seems that we can work-around the problem by handling this l10n-arg the same way that we handle dates in the AnnotationLayer, and testing this with the Firefox Devtools it seems that it should work.
2024-10-04 19:50:05 +02:00
Calixte Denizet
b6e60d033a [Editor] Avoid an exception when undoing the deletion of a pre-existing annotation
It fixes #18849.

When such an annotation is deleted, we make sure that there are some data
to restore.
The version of this patch was making undoing a svg deletion buggy, so it's fixed now and
an integration test has been added for this case.
2024-10-04 18:24:58 +02:00
calixteman
e5b6144bfa
Merge pull request #18846 from flodolo/undo_number
Fluent: remove NUMBER() function from variant selector
2024-10-04 08:03:10 +02:00
calixteman
e9c81a6e54
Merge pull request #18834 from calixteman/edit_stamp1
[Editor] Make stamp annotations editable (bug 1921291)
2024-10-04 07:53:27 +02:00
Francesco Lodolo
58d31479d7
Fluent: remove NUMBER() function from variant selector 2024-10-04 07:14:45 +02:00
Calixte Denizet
8410252eb8 [Editor] Make stamp annotations editable (bug 1921291) 2024-10-03 21:54:08 +02:00
Jonas Jenwald
ebbd019d7d
Merge pull request #18842 from Snuffleupagus/annotationEditorMode-AbortSignal-any
Remove the `PDFViewer.annotationEditorMode` setter event listeners with `AbortSignal.any()`
2024-10-03 19:38:49 +02:00
calixteman
85586c5859
Merge pull request #18843 from calixteman/editor_async_deser
[Editor] Make the editor deserialization async
2024-10-03 19:37:49 +02:00
Calixte Denizet
7bd3e5ccec [Editor] Make the editor deserialization async 2024-10-03 18:34:22 +02:00
Jonas Jenwald
b7ae92c11c Remove the PDFViewer.annotationEditorMode setter event listeners with AbortSignal.any() 2024-10-03 15:57:46 +02:00
calixteman
4fb3adfc0f
Merge pull request #18837 from calixteman/bug1838602
[GV] Increase the height (48px) of the toolbar in order to fit the a11y recommendations (bug 1838602)
2024-10-03 11:29:54 +02:00
Calixte Denizet
0ce6f8b482 [GV] Increase the height (48px) of the toolbar in order to fit the a11y recommendations (bug 1838602)
and reorganize the toolbar css to use nested styles.
2024-10-02 19:17:40 +02:00
calixteman
567df42149
Merge pull request #18805 from calixteman/update_stamp
[Editor] Add the possibility to save an updated stamp annotation (bug 1921291)
2024-10-02 13:16:35 +02:00
Calixte Denizet
c9050be863 [Editor] Add the possibility to save an updated stamp annotation (bug 1921291) 2024-10-02 11:45:16 +02:00
Jonas Jenwald
e25832c43f
Merge pull request #18831 from Snuffleupagus/toolbar-container
Fix `toolbarViewer`/`toolbarContainer` regressions (PR 18385, 18786 follow-up)
2024-10-02 09:37:12 +02:00
calixteman
0308b8075f
Merge pull request #18824 from calixteman/issue18072
Write the display flags in F entry when saving an annotation (issue 18072)
2024-10-02 09:13:06 +02:00
Jonas Jenwald
07e8afb247 Always set AppOptions.eventBus, regardless of build, to make local testing easier 2024-10-01 19:43:19 +02:00
Jonas Jenwald
7c9d177826 Update the CaretBrowsingMode toolbar-height if the toolbarDensity preference changes (PR 18786 follow-up)
Otherwise the isVisible-calculations may not work correctly.
2024-10-01 19:43:16 +02:00
calixteman
3cdc3258d9
Merge pull request #18830 from calixteman/menu_nvda
Make the secondary menu button usable with the keyboard when NVDA is enabled
2024-10-01 17:27:56 +02:00
Calixte Denizet
2481a4bab9 Write the display flags in F entry when saving an annotation (issue 18072) 2024-10-01 17:26:39 +02:00
Jonas Jenwald
f2a132f826 Use the "correct" toolbar container element in getViewerConfiguration (PR 18385 follow-up)
With the changes made in PR 18385 the `toolbarViewer` element is now shorter than before, since the padding is applied on its `toolbarContainer` parent-element instead.
This causes two separate regressions:
 - Clicking at the very top/bottom of the toolbar no longer closes the secondaryToolbar like previously.
 - The `CaretBrowsingMode`-constructor no longer computes the toolbar-height correctly.

Given how/where the `container`-property is being used these changes *should* thus be safe.
2024-10-01 17:17:40 +02:00
Calixte Denizet
392c17efa0 Make the secondary menu button usable with the keyboard when NVDA is enabled
It's a temporary workaround until bug 1921984 is fixed.
2024-10-01 16:57:39 +02:00
Jonas Jenwald
35a9a6a7b3
Merge pull request #18829 from Snuffleupagus/PDFLayerViewer-update-UI
Re-factor how `PDFLayerViewer` decides if the UI needs to updated on "optionalcontentconfigchanged" events
2024-10-01 15:17:00 +02:00
Jonas Jenwald
655ef12b14 Re-factor how PDFLayerViewer decides if the UI needs to updated on "optionalcontentconfigchanged" events
The current implementation won't work correctly in some cases, e.g. if RBGroups are present, which means that it's possible for the UI to get out-of-sync with the actual optionalContent-state.

To avoid querying the DOM unnecessarily we cache the last known UI-state and compare with the actual optionalContent-state, which thus replaces the previously used hash-comparison.
2024-10-01 13:25:22 +02:00
Jonas Jenwald
783facb312
Merge pull request #18822 from Snuffleupagus/Chrome-103
[api-minor] Update the minimum supported Google Chrome version to 103
2024-10-01 10:12:57 +02:00
Jonas Jenwald
1267e28255 [api-minor] Update the minimum supported Google Chrome version to 103
This patch updates the minimum supported browsers as follows:
 - Google Chrome 103[1], which was released on 2022-06-21; see https://chromereleases.googleblog.com/2022/06/stable-channel-update-for-desktop_21.html

Note that nowadays we usually try, where feasible and possible, to support browsers that are about two years old. By limiting support to only "recent" browsers we reduce the risk of holding back improvements of the *built-in* Firefox PDF Viewer, and also (significantly) reduce the maintenance/support burden for the PDF.js contributors.

*Please note:* As always, the minimum supported browser version assumes that a `legacy`-build of the PDF.js library is being used; see https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support

---

[1] This is consistent with the minimum supported version in the recently updated Google Chrome addon.
2024-09-29 13:11:02 +02:00
Jonas Jenwald
a7e1bf64c4
Merge pull request #18812 from Snuffleupagus/pr-15522-followup
Ensure that the CursorTools-buttons are disabled e.g. during editing (PR 15522 follow-up)
2024-09-28 19:20:56 +02:00
Jonas Jenwald
b1df164a26 Ensure that the CursorTools-buttons are disabled e.g. during editing (PR 15522 follow-up)
We disable any non-default CursorTool in PresentationMode and during Editing, since they don't make sense there and to prevent problems such as e.g. [bug 1792422](https://bugzilla.mozilla.org/show_bug.cgi?id=1792422).
Hence it seems like a good idea to *also* disable the relevant SecondaryToolbar-buttons, to avoid the user being surprised that the CursorTools-buttons do nothing if clicked.
2024-09-28 12:29:51 +02:00
calixteman
642b9a5ae6
Merge pull request #18793 from calixteman/bug1911980
[Editor] Avoid to have a selected stamp annotation on top of the secondary toolbar (bug 1911980)
2024-09-26 20:16:13 +02:00
calixteman
c46ac3f73f
Merge pull request #18800 from calixteman/popup_deletion
[Editor] When deleting an annotation with popup, then delete the popup too
2024-09-26 18:04:24 +02:00
Calixte Denizet
0382dd0e25 [Editor] When deleting an annotation with popup, then delete the popup too 2024-09-26 17:52:25 +02:00
Calixte Denizet
ec01af6b38 [Editor] Avoid to have a selected stamp annotation on top of the secondary toolbar (bug 1911980) 2024-09-26 17:48:02 +02:00
Jonas Jenwald
7063be9860
Merge pull request #18802 from Snuffleupagus/issue-18801
Add basic support for non-embedded GillSansMT fonts (issue 18801)
2024-09-26 17:42:57 +02:00
Jonas Jenwald
7db9941e0f Add basic support for non-embedded GillSansMT fonts (issue 18801)
Given the following excerpt from the [Wikipedia article](https://en.wikipedia.org/wiki/Gill_Sans), mapping this to Helvetica should hopefully be fine:

> It has been described as "the British Helvetica" because of its lasting popularity in British design.
2024-09-26 16:42:54 +02:00
Jonas Jenwald
6daaa2fef7
Merge pull request #18799 from Snuffleupagus/rm-more-getCanvas-trackTransform
Remove `trackTransform` arguments from `CachedCanvases.getCanvas`-calls (PR 15281 follow-up)
2024-09-26 16:28:27 +02:00
Jonas Jenwald
fa2d7fc178 Remove trackTransform arguments from CachedCanvases.getCanvas-calls (PR 15281 follow-up)
This became unused in PR 15281, however that patch clearly missed some occurrences; sorry about that!
2024-09-26 15:21:44 +02:00
Jonas Jenwald
3902a148e2
Merge pull request #18785 from Snuffleupagus/transportFactory-init
Slightly re-factor the `transportFactory` initialization in `getDocument`
2024-09-26 15:03:22 +02:00
calixteman
2ff8035981
Merge pull request #18798 from calixteman/pattern_negative_bbox
Fix the rendering of tiling pattern when the steps are lower than the tile dimensions (bug 1837738)
2024-09-26 14:25:14 +02:00
Calixte Denizet
6d88f9f154 Fix the rendering of tiling pattern when the steps are lower than the tile dimensions (bug 1837738)
It fixes #16038.

The idea is to create a pattern having the steps for dimensions and then draw
the base tile and the different overlapping parts on it.
2024-09-26 14:20:48 +02:00
Jonas Jenwald
a989244570 Slightly re-factor the transportFactory initialization in getDocument
Given that the `WorkerTransport`-constructor will access all possible factory-instances, let's ensure that the `transportFactory`-object always has a consistent shape regardless of other options.

Also, since `useWorkerFetch` is always true in MOZCENTRAL builds we never need to create `CMapReaderFactory`/`StandardFontDataFactory`-instances there.
2024-09-26 12:16:05 +02:00
Jonas Jenwald
a1283785e5
Merge pull request #18796 from Snuffleupagus/unify-toolbarContainer
Unify separate `#toolbarContainer`-blocks in the CSS (PR 18385 follow-up)
2024-09-26 12:09:37 +02:00
Jonas Jenwald
17008ddf21
Merge pull request #18795 from Snuffleupagus/rm-splitToolbarButton
Remove the unused `splitToolbarButton` CSS class (PR 18385 follow-up)
2024-09-26 12:09:03 +02:00
Jonas Jenwald
f765b5ab35 Unify separate #toolbarContainer-blocks in the CSS (PR 18385 follow-up) 2024-09-26 11:08:55 +02:00
Jonas Jenwald
135ee03847 Remove the unused splitToolbarButton CSS class (PR 18385 follow-up) 2024-09-26 11:01:18 +02:00
Marco Castelluccio
9735a840ad
Merge pull request #18791 from sylvestre/patch-1
Add Calixte to the list of authors
2024-09-25 18:18:31 +02:00
calixteman
4ab381f52e
Merge pull request #18786 from calixteman/update_toolbar_height
Increase the size of the toolbar depending on the uidensity (bug 1171799)
2024-09-25 15:48:54 +02:00
calixteman
45758104a4
Merge pull request #18790 from calixteman/bug1917734
Correctly compute the font size when printing a text field with an auto font size (bug 1917734)
2024-09-25 14:58:33 +02:00
Sylvestre Ledru
5c407a2d23
Add Calixte to the list of authors 2024-09-25 14:48:01 +02:00
Calixte Denizet
e23159c41b Increase the size of the toolbar depending on the uidensity (bug 1171799) 2024-09-25 14:27:17 +02:00
Calixte Denizet
fc1564f476 Correctly compute the font size when printing a text field with an auto font size (bug 1917734) 2024-09-25 14:05:54 +02:00
calixteman
529906c74f
Merge pull request #18784 from calixteman/rm_useless_css
Remove duplicated --toolbar-height definition in the css
2024-09-24 12:44:34 +02:00
Calixte Denizet
50517b8fba Remove duplicated --toolbar-height definition in the css 2024-09-24 12:31:43 +02:00
calixteman
cc63941b64
Merge pull request #18783 from calixteman/rm_useless_css
Remove useless css variable --editor-toolbar-base-offset
2024-09-24 10:08:02 +02:00
Calixte Denizet
e9b10ae8b2 Remove useless css variable --editor-toolbar-base-offset 2024-09-24 09:58:17 +02:00
Jonas Jenwald
45fef4c6d7
Merge pull request #18781 from timvandermeij/typescript
Update `typescript` to version 5.6.2
2024-09-24 09:38:47 +02:00
calixteman
313ab9a464
Merge pull request #18385 from calixteman/remove_tabindex
Refactor the toolbar html & css to improve its overall accessibility (bug 1171799, bug 1855695)
2024-09-24 09:04:36 +02:00
Calixte Denizet
6f40ed729b Refactor the toolbar html & css to improve its overall accessibility (bug 1171799, bug 1855695)
The first goal of this patch was to remove the tabindex because it helps
to improve overall a11y. That led to move some html elements associated
with the buttons which helped to position these elements relatively to their
buttons.
Consequently it was easy to change the toolbar height (configurable in Firefox
with the pref browser.uidensity): it's the second goal of this patch.
For a11y reasons we want to be able to change the height of the toolbar to make
the buttons larger.
2024-09-23 22:43:44 +02:00
calixteman
c90ce5da20
Merge pull request #18779 from calixteman/bug1920515
[Editor] Don't show the ml toggle button when the ml is disabled (bug 1920515)
2024-09-23 22:12:25 +02:00
Tim van der Meij
c8af3f14d3
Update typescript to version 5.6.2
This is unblocked because in commit bb302dd the default value for the
constructor got removed, which apparently confused TypeScript before.

Fixes #18770.
2024-09-23 20:34:35 +02:00
Calixte Denizet
d35a20a8c1 [Editor] Don't show the ml toggle button when the ml is disabled (bug 1920515) 2024-09-23 19:46:32 +02:00
Jonas Jenwald
b65b7747b6
Merge pull request #18777 from Snuffleupagus/version-4.7
Bump library version to `4.7`
2024-09-23 14:46:12 +02:00
Jonas Jenwald
be60ca66e1 Bump library version to 4.7 2024-09-23 14:40:09 +02:00
Jonas Jenwald
bbef99fe82
Merge pull request #18776 from Snuffleupagus/api-CanvasFactory-FilterFactory
[api-minor] Pass `CanvasFactory`/`FilterFactory`, rather than instances, to `getDocument`
2024-09-23 14:36:32 +02:00
Jonas Jenwald
6aa02ed7f6
Merge pull request #18771 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-09-23 11:53:54 +02:00
Jonas Jenwald
bb302dd993 [api-minor] Pass CanvasFactory/FilterFactory, rather than instances, to getDocument
This unifies the various factory-options, since it's consistent with `CMapReaderFactory`/`StandardFontDataFactory`, and ensures that any needed parameters will always be consistently provided when creating `CanvasFactory`/`FilterFactory`-instances.

As shown in the modified example this may simplify some custom implementations, since we now provide the ability to access the `CanvasFactory`-instance used with a particular `getDocument`-invocation.
2024-09-23 11:26:30 +02:00
Tim van der Meij
ed100f2ef2
Update translations to the most recent versions 2024-09-22 20:27:10 +02:00
Tim van der Meij
3753387e9d
Update dependencies to the most recent versions 2024-09-22 20:27:10 +02:00
Tim van der Meij
ddd7b63406
Merge pull request #18772 from Snuffleupagus/Node-unit-test-fs-promise
Use `fs/promises` in the Node.js unit-tests (PR 17714 follow-up)
2024-09-22 20:21:37 +02:00
Jonas Jenwald
1a1dfe60bf Add more optional chaining in the test/ directory 2024-09-22 13:00:57 +02:00
Jonas Jenwald
0a621ba73a Use fs/promises in the Node.js unit-tests (PR 17714 follow-up)
This is available in all Node.js versions that we currently support, and using it allows us to remove callback-functions; please see https://nodejs.org/docs/latest-v18.x/api/fs.html#promises-api
2024-09-22 12:57:23 +02:00
Jonas Jenwald
ea2172e754
Merge pull request #18766 from Snuffleupagus/issue-18765
Ignore non-existing /Shading resources during parsing (issue 18765)
2024-09-21 21:11:53 +02:00
Jonas Jenwald
67af371e58 Ignore non-existing /Shading resources during parsing (issue 18765) 2024-09-19 21:55:02 +02:00
Jonas Jenwald
96cdff4a73
Merge pull request #18763 from Snuffleupagus/readme-update-issue-link
Link to the new issue templates from the README (PR 18308 follow-up)
2024-09-19 16:31:48 +02:00
Jonas Jenwald
9e001f8513 Link to the new issue templates from the README (PR 18308 follow-up) 2024-09-19 16:14:39 +02:00
calixteman
6222359c5f
Merge pull request #18761 from calixteman/fix_separator_color
Fix the rendering of the different separators we've in the UI
2024-09-19 15:37:17 +02:00
Calixte Denizet
b29278efb8 Fix the rendering of the different separators we've in the UI
Currently, the css for a separator is something like { height: 1px; background-color: ... }.
But its rendering depends on its position on the screen.
So instead of setting the height to 1px, we just set something like { border-top: 1px solid ...; },
this way the final rendering is exactly the same for all the separators.
2024-09-19 15:24:01 +02:00
calixteman
652e3e0d76
Merge pull request #18760 from calixteman/bug1919513
Read a signed integer when using PUSHW in sanitizing a font (bug 1919513)
2024-09-19 13:33:50 +02:00
Calixte Denizet
78dd35483c Read a signed integer when using PUSHW in sanitizing a font (bug 1919513) 2024-09-18 22:09:17 +02:00
calixteman
19151feb5f
Merge pull request #18757 from calixteman/rename_toolbar_buttons
Rename the toolbar buttons in order to free their current names
2024-09-17 21:20:38 +02:00
Calixte Denizet
ee89bd1c39 Rename the toolbar buttons in order to free their current names
which can then be used for their future parent container.
This patch aims to simplify a bit the patch in #18385.
2024-09-17 20:34:38 +02:00
Tim van der Meij
a58cd6851e
Merge pull request #18756 from Snuffleupagus/api-NetworkStream
Simplify the code that picks the appropriate NetworkStream-implementation
2024-09-17 19:19:19 +02:00
Jonas Jenwald
f77a29d675 Simplify the code that picks the appropriate NetworkStream-implementation
This code is quite old and has been moved/re-factored a few times over the years, however we can simplify this even further since we don't actually need a function to determine what NetworkStream-implementation to use.
2024-09-17 12:23:43 +02:00
calixteman
f68310b7b1
Merge pull request #18749 from calixteman/issue18626
[Editor] Take into account the device pixel ratio when drawing an added image
2024-09-16 15:01:38 +02:00
Calixte Denizet
46fac8b2c1 [Editor] Take into account the device pixel ratio when drawing an added image
Fixes #18626.
2024-09-16 14:48:26 +02:00
Tim van der Meij
014ce7c1db
Merge pull request #18728 from Rob--W/crx-mv3-fallback-detect-fixup
[CRX] Fix feature detect of DNR responseHeaders option
2024-09-15 15:43:23 +02:00
Tim van der Meij
bf5c987fee
Merge pull request #18748 from Rob--W/crx-mv3-enable-wasm
[CRX] Enable WebAssembly in Chrome extension
2024-09-15 15:42:38 +02:00
Rob Wu
3170bf3f69 [CRX] Enable WebAssembly in Chrome extension
After the removal of 'unsafe-eval' CSP in #18651, WebAssembly fails to
load, resulting in issues such as seen in #18457.

Manifest Version 3 does not allow 'unsafe-eval', does accept the more
specific 'wasm-unsafe-eval' as of Chrome 103. Note that manifest.json
already sets minimum_chrome_version to 103.

This patch also adds `object-src 'self'` because it was required until
Chrome 110. As of Chrome 111, the default is `object-src 'self'` and
`object-src` is no longer required. We could drop `object-src` in the
future, but for now we need to include it to support Chrome 103 - 110.
2024-09-15 12:58:38 +02:00
Jonas Jenwald
c72fb9b733
Merge pull request #18742 from Snuffleupagus/pageColorsBackground-unloaded-pages
Use the "pageColorsBackground" option as background-color for non-loaded pages (issue 18680)
2024-09-12 22:38:52 +02:00
Jonas Jenwald
d86f94a3db Use the "pageColorsBackground" option as background-color for non-loaded pages (issue 18680)
This should prevent non-loaded pages from flashing white in e.g. high contrast mode (HCM).
2024-09-12 21:15:15 +02:00
calixteman
b915a9c3a5
Merge pull request #18741 from flodolo/fluent_number
Fluent: use explicit NUMBER() in plural variants
2024-09-12 17:03:17 +02:00
calixteman
4275424456
Merge pull request #18740 from calixteman/bug1897909
[Editor] Avoid an extra new line when serializing a FreeText annotation (bug 1897909)
2024-09-12 17:00:38 +02:00
Francesco Lodolo
6e1b4d63e7
Fluent: use explicit NUMBER() in plural variants 2024-09-12 16:53:18 +02:00
Calixte Denizet
85e8bac45d [Editor] Avoid an extra new line when serializing a FreeText annotation (bug 1897909)
The extra new line is added because of using shift+enter to add a new line
in the text editor.
2024-09-12 15:35:19 +02:00
Jonas Jenwald
1ab9ab67ee
Merge pull request #18738 from mozilla/dependabot/npm_and_yarn/dset-3.1.4
Bump dset from 3.1.3 to 3.1.4
2024-09-12 10:35:14 +02:00
dependabot[bot]
edd1dfb699
Bump dset from 3.1.3 to 3.1.4
Bumps [dset](https://github.com/lukeed/dset) from 3.1.3 to 3.1.4.
- [Release notes](https://github.com/lukeed/dset/releases)
- [Commits](https://github.com/lukeed/dset/compare/v3.1.3...v3.1.4)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-11 23:53:47 +00:00
calixteman
cb20d1b169
Merge pull request #18737 from calixteman/bug1918115
[JS] Correctly format floating numbers when they're close to an integer (bug 1918115)
2024-09-11 18:03:59 +02:00
Calixte Denizet
ca95264e8b [JS] Correctly format floating numbers when they're close to an integer (bug 1918115) 2024-09-11 17:19:34 +02:00
Jonas Jenwald
c52e8485a7
Merge pull request #18731 from Snuffleupagus/TextLayer-ensureCtxFont
Ensure that textLayers can be rendered in parallel, without interfering with each other
2024-09-11 16:29:53 +02:00
Jonas Jenwald
5b3d3c7dd9 Ensure that textLayers can be rendered in parallel, without interfering with each other
Note that the textContent is returned in "chunks" from the API, through the use of `ReadableStream`s, and on the main-thread we're (normally) using just one temporary canvas in order to measure the size of the textLayer `span`s; see the [`#layout`](5b4c2fe1a8/src/display/text_layer.js (L396-L428)) method.

*Order of events, for parallel textLayer rendering:*
 1. Call [`render`](5b4c2fe1a8/src/display/text_layer.js (L155-L177)) of the textLayer for page A.
 2. Immediately call `render` of the textLayer for page B.
 3. The first text-chunk for pageA arrives, and it's parsed/layout which means updating the cached [fontSize/fontFamily](5b4c2fe1a8/src/display/text_layer.js (L409-L413)) for the textLayer of page A.
 4. The first text-chunk for pageB arrives, which means updating the cached fontSize/fontFamily *for the textLayer of page B* since this data is unique to each `TextLayer`-instance.
 5. The second text-chunk for pageA arrives, and we don't update the canvas-font since the cached fontSize/fontFamily still apply from step 3 above.

Where this potentially breaks down is between the last steps, since we're using just one temporary canvas for all measurements but have *individual* fontSize/fontFamily caches for each textLayer.
Hence it's possible that the canvas-font has actually changed, despite the cached values suggesting otherwise, and to address this we instead cache the fontSize/fontFamily globally through a new (static) helper method.

*Note:* Includes a basic unit-test, using dummy text-content, which fails on `master` and passes with this patch.

Finally, pun intended, ensure that temporary textLayer-data is cleared *before* the `render`-promise resolves to avoid any intermittent problems in the unit-tests.
2024-09-11 15:28:51 +02:00
calixteman
870394d22b
Merge pull request #18730 from calixteman/issue18693
Consider foo-\nBar as a compound word
2024-09-11 15:15:16 +02:00
Calixte Denizet
06f9d8002d Consider foo-\nBar as a compound word
Fixes #18693.
2024-09-11 15:01:54 +02:00
calixteman
0ac7f294cd
Merge pull request #18726 from calixteman/issue18058
Consume any pending path before drawing an annotation
2024-09-10 19:00:58 +02:00
Calixte Denizet
518b776e43 Consume any pending path before drawing an annotation
Fixes #18058.
2024-09-10 16:44:30 +02:00
Rob Wu
a91ba11185 [CRX] Fix feature detect of DNR responseHeaders option
Fix regression from #18711. `urlFilter` is a key of `condition`, not of
the `rule`. Consequently, the feature detection method failed to detect
the availability of the feature in Chrome 128+.
2024-09-10 16:05:11 +02:00
Jonas Jenwald
66ed4b9e25
Merge pull request #18724 from Snuffleupagus/highlight-rm-l10nPromise
Remove ununsed static `HighlightEditor._l10nPromise` field
2024-09-10 15:59:25 +02:00
Jonas Jenwald
2883a9460e Remove ununsed static HighlightEditor._l10nPromise field 2024-09-10 10:00:41 +02:00
calixteman
5b4c2fe1a8
Merge pull request #18716 from calixteman/stamp_auto_resize
[Editor] Avoid to have a stamp editor resizing itself
2024-09-09 22:13:49 +02:00
calixteman
f98e6040cd
Merge pull request #18719 from calixteman/bug1917543
[Editor] Avoid to have the ML disclaimer when the ML engine isn't ready (bug 1917543)
2024-09-09 22:12:46 +02:00
calixteman
95cd848e3b
Merge pull request #18718 from calixteman/bug1916714
[JS] Let AFSpecial_KeystrokeEx match a format without 'decoration' (bug 1916714)
2024-09-09 21:50:46 +02:00
Calixte Denizet
6e4b7ee3f8 [Editor] Avoid to have the ML disclaimer when the ML engine isn't ready (bug 1917543) 2024-09-09 21:47:18 +02:00
Calixte Denizet
3f23bcbecc [Editor] Avoid to have a stamp editor resizing itself
Fixes #18715.
2024-09-09 21:31:55 +02:00
Tim van der Meij
5f39b592c5
Merge pull request #18708 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-09-09 21:23:16 +02:00
Calixte Denizet
bae32b4fd2 [JS] Let AFSpecial_KeystrokeEx match a format without 'decoration' (bug 1916714)
It'll let the user enter 1234567 instead of 123-4567 for example.
It works like this in other pdf viewers.
2024-09-09 20:29:14 +02:00
Tim van der Meij
8e5f06d77d
Merge pull request #18711 from Rob--W/crx-mv3-fallback-detect
[CRX] Detect availability of DNR responseHeaders before use
2024-09-09 20:00:44 +02:00
Tim van der Meij
2f2d74ba5c
Update translations to the most recent versions 2024-09-09 19:51:21 +02:00
Tim van der Meij
ae13b4a015
Update dependencies to the most recent versions 2024-09-09 19:51:21 +02:00
Rob Wu
9705169371 [CRX] Detect availability of DNR responseHeaders before use
Critical fix for old but recent Chrome versions; all requests are
otherwise redirected to the viewer.
2024-09-09 14:41:00 +02:00
Tim van der Meij
a1b45d6e69
Merge pull request #18681 from Rob--W/crx-mv3-migration
[CRX] Migrate Chrome extension to Manifest Version 3
2024-09-08 18:10:43 +02:00
Rob Wu
4bf7be6427 [CRX] Bump minimum_chrome_version from 88 to 103
The minimum required version is Chrome 103 because wildcard support for
web_accessible_resources[].extension_id was introduced in 103, in
c9caeb1a08

A way to broaden compatibility is to drop that key. By doing so, the
minimum required Chrome version is then 96, because of the
chrome.storage.session API (and declarativeNetRequestWithHostAccess).

Since gulpfile.js already defines "Chrome >= 98" and there is no real
point in expanding support to older versions, I'm just setting the
minimum version to 103.
2024-09-08 16:35:14 +02:00
Rob Wu
b3a0ad09ad [CRX] Add work-around for Chrome crash 2024-09-08 16:35:14 +02:00
Rob Wu
4327502bf3 [CRX] Add fallback PDF detection for Chrome 127- 2024-09-08 16:35:14 +02:00
Rob Wu
3fe256cd0d [CRX] Set manifest_version to 3
- Replace DOM-based pdfHandler.html (background page) with background.js
  (extension service worker).

- Adjust logic of background scripts to account for the fact that the
  scripts can execute repeatedly during a browser session. Primarily,
  register relevant extension event handlers at the top level and use
  in-memory storage.session API to keep track of initialization state.

- Extension URL router: replace blocking webRequest with the service
  worker-specific "fetch" event.

- PDF detection: replace blocking webRequest with declarativeNetRequest.
  This requires Chrome 128+. The next commit will add a fallback for
  earlier Chrome versions.
2024-09-08 16:35:13 +02:00
Rob Wu
7017d8246b [CRX] Replace localStorage in telemetry logic
In MV3, the background script is a service worker. localStorage is not
supported in service workers. Switch to storage.local instead.

Data migration is not implemented because it is not needed due to the
privacy-friendly design of the telemetry: In practice the data is reset
about every 4 weeks, when the major version of Chrome is updated.
2024-09-08 16:35:13 +02:00
Rob Wu
bc4890d4d4 [CRX] Remove restoretab.js logic
restoretab.js was added in https://github.com/mozilla/pdf.js/pull/6233
with the purpose of restoring lost tabs when Chrome closes all extension
tabs when it reloads the extension. This forced reload can happen when
the user toggles the "Allow access to file URLs" option.

This logic does not work any more, and since the use of localStorage is
a blocker in migrating to MV3, this patch just drops the logic.
2024-09-08 16:35:13 +02:00
Rob Wu
23bc46d51a [CRX] Replace deprecated extension.getURL with runtime.getURL 2024-09-08 16:35:13 +02:00
Rob Wu
b23829fc60 [CRX] Drop chrome_style from manifest.json
MV3 does not support chrome_style in options_ui. Remove it and replace
it with the minimal amount of styles that still has some spacing around
the individual settings for readability.
2024-09-08 16:35:13 +02:00
Rob Wu
bd3d993180 [CRX] Use DNR instead of webRequest in preserve-referer
webRequestBlocking is unavailable in MV3. Non-blocking webRequest can
still be used to detect the Referer, but we have to use
declarativeNetRequest to change the Referer header as needed.
2024-09-08 16:35:13 +02:00
Tim van der Meij
578549487f
Merge pull request #18707 from Snuffleupagus/pr-18596-followup
Prevent `.visibleMediumView` from overriding already hidden elements (issue 18704, PR 18596 follow-up)
2024-09-08 12:00:44 +02:00
Tim van der Meij
c159cb1335
Merge pull request #18682 from Snuffleupagus/responseHeaders
Use response-`Headers` in the different `IPDFStream` implementations
2024-09-08 11:49:50 +02:00
Jonas Jenwald
b681ea6fd9 Prevent .visibleMediumView from overriding already hidden elements (issue 18704, PR 18596 follow-up)
*Please note:* As a general rule we probably don't need to fix things affecting *custom* implementations of the default viewer, but in this case a "targeted" fix seem possible that shouldn't (famous last words) break anything else.

Ensure that the `.visibleMediumView` class, which is used when the viewer becomes narrow, cannot override the `display`-value for DOM elements that are being *explicitly* hidden either through the associated attribute or class.
2024-09-08 10:47:18 +02:00
Jonas Jenwald
5d0c82cf05
Merge pull request #18706 from Snuffleupagus/AltText-full-l10n-ids
Use "full" localization ids in the `AltText` class (PR 18674 follow-up)
2024-09-07 23:20:09 +02:00
Jonas Jenwald
727454600b
Merge pull request #18705 from Snuffleupagus/ColorPicker-full-l10n-ids
Use "full" localization ids in the `ColorPicker` class (PR 18674 follow-up)
2024-09-07 23:19:28 +02:00
calixteman
5369a24c9c
Merge pull request #18698 from calixteman/issue18694
Avoid to have a white line around the canvas
2024-09-07 22:22:21 +02:00
Calixte Denizet
68332ec236 Avoid to have a white line around the canvas
The canvas must have the same dims as the page in order to avoid to see the page
background.
2024-09-07 20:12:29 +02:00
Jonas Jenwald
0ffd99acc5 Use "full" localization ids in the AltText class (PR 18674 follow-up)
Apparently I missed these in PR 18674.
2024-09-07 16:38:21 +02:00
Jonas Jenwald
931090328d Use "full" localization ids in the ColorPicker class (PR 18674 follow-up)
Apparently I missed these in PR 18674.
2024-09-07 15:53:01 +02:00
Jonas Jenwald
2a01931e4a Use the _headersCapability name in PDFNetworkStreamFullRequestReader
This improves consistency in the code-base since the implementations with the Fetch API respectively Node.js uses that name.
2024-09-07 12:36:34 +02:00
Jonas Jenwald
840cc5e0d4 Use response-Headers in the different IPDFStream implementations
Given that the `Headers` functionality is now available in all browsers/environments that we support, [see MDN](https://developer.mozilla.org/en-US/docs/Web/API/Headers#browser_compatibility), we can utilize "proper" `Headers` in the helper functions that are used to parse the response.
2024-09-07 12:34:53 +02:00
calixteman
77c7ec6927
Merge pull request #18692 from calixteman/bug1708040
Make tagged images visible for screen readers (bug 1708040)
2024-09-05 18:50:22 +02:00
Calixte Denizet
ddba096191 Make tagged images visible for screen readers (bug 1708040)
The idea is to insert a span in the text layer with an aria-role set to img
and use the bounding box provided by the attribute field in the tag dict in
order to have non-null dimensions for the image to make it "visible".
2024-09-05 17:59:42 +02:00
calixteman
4b906ad0a8
Merge pull request #18697 from calixteman/issue18696
[Editor] Avoid to throw when an highlight annotation is resetted
2024-09-05 16:15:23 +02:00
Calixte Denizet
350e3e7b1c [Editor] Avoid to throw when an highlight annotation is resetted 2024-09-05 15:31:49 +02:00
calixteman
e3fd62d726
Merge pull request #18690 from calixteman/print_test_afterprint
In the autoprint integration test, resolve the promise on 'afterprint' event
2024-09-04 15:44:05 +02:00
calixteman
4fb045b9eb
Merge pull request #18689 from Snuffleupagus/StructTreeLayerBuilder-render-caching
Improve the `StructTreeLayerBuilder.render` method
2024-09-04 14:07:18 +02:00
Calixte Denizet
5d622ada04 In the autoprint integration test, resolve the promise on 'afterprint' event 2024-09-04 13:49:02 +02:00
calixteman
1cdaaadf2d
Merge pull request #18670 from calixteman/bug1911764
[Editor] Remove the disclaimer when the user is editing the alt-text in the new alt-text modal (bug 1911764)
2024-09-04 13:41:18 +02:00
Jonas Jenwald
4b8628637a Improve the StructTreeLayerBuilder.render method
In hindsight it occurred to me that there's a couple of smaller issues with this method after it's made asynchronous (in PR 18658).

 - If the `render`-method is invoked back-to-back the existing caching doesn't guarantee that re-parsing won't occur, which we can address by introducing a new (private) promise.

 - If there's any errors fetching and/or parsing the structTree-data, we'd attempt to parse it again on re-rendering despite that being pointless.
2024-09-04 11:53:51 +02:00
Calixte Denizet
4aea51b5bf [Editor] Remove the disclaimer when the user is editing the alt-text in the new alt-text modal (bug 1911764) 2024-09-04 10:00:35 +02:00
calixteman
d3698223a8
Merge pull request #18658 from calixteman/bug1912001
[Editor] Make the stamp annotations alt text readable by either VO or NVDA (bug 1912001)
2024-09-03 21:47:21 +02:00
Tim van der Meij
082ad955f0
Merge pull request #18673 from Snuffleupagus/use-Headers
Use `Headers` consistently in the different `IPDFStream` implementations
2024-09-03 20:26:35 +02:00
Tim van der Meij
da99f5d6cd
Merge pull request #18679 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-09-03 20:14:37 +02:00
calixteman
a61f4b0303
Merge pull request #18427 from calixteman/edit_highlight
[Editor] Make highlight annotations editable (bug 1883884)
2024-09-03 17:56:37 +02:00
calixteman
5d8d9ef6f9
Merge pull request #18664 from calixteman/bug1911994
[Editor] Make the focused stamp annotation more clear from a screen reader point of view (bug 1911994)
2024-09-03 17:04:21 +02:00
Calixte Denizet
deedbd1c4f [Editor] Make the stamp annotations alt text readable by either VO or NVDA (bug 1912001) 2024-09-03 16:57:41 +02:00
Calixte Denizet
843fde3b13 [Editor] Make the focused stamp annotation more clear from a screen reader point of view (bug 1911994)
It has been tested with Voice Over (mac) and with NVDA (windows).

When an added stamp annotation is focused, the screen reader will announce
that it's a figure containing a graphic with the added alt-text.
2024-09-03 16:38:21 +02:00
Calixte Denizet
a62ceedb69 [Editor] Make highlight annotations editable (bug 1883884)
The goal of this patch is to be able to edit existing highlight annotations.
2024-09-03 15:27:55 +02:00
Jonas Jenwald
d3a94f17cb Use Headers consistently in the different IPDFStream implementations
The `Headers` functionality is now available in all browsers/environments that we support, which allows us to consolidate and simplify how the `httpHeaders` API-option is handled; see https://developer.mozilla.org/en-US/docs/Web/API/Headers#browser_compatibility

Also, simplifies the old `NetworkManager`-constructor a little bit.
2024-09-02 11:56:24 +02:00
Tim van der Meij
8084ae2054
Update translations to the most recent versions 2024-09-01 19:59:22 +02:00
Tim van der Meij
ec7d0f6860
Update dependencies to the most recent versions 2024-09-01 19:58:26 +02:00
Tim van der Meij
0676ea19cf
Merge pull request #18678 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-09-01 19:40:17 +02:00
Tim van der Meij
4220116c1a
Bump the stable version in pdfjs.config 2024-09-01 19:36:48 +02:00
Tim van der Meij
9b541910ff
Merge pull request #18675 from calixteman/nofirefox
Add an option (i.e. --noFirefox) to only use Chrome when running tests
2024-09-01 15:44:00 +02:00
Tim van der Meij
bde7a84e09
Merge pull request #18672 from Snuffleupagus/PDFPageView-AnnotationEditorLayerBuilder-shorter-init
Shorten the code that inits `AnnotationEditorLayerBuilder` in the `web/pdf_page_view.js` file
2024-09-01 15:30:20 +02:00
Tim van der Meij
4a132229c6
Merge pull request #18665 from Snuffleupagus/PDFNodeStream-createRequest
Add a helper function for http/https requests in `src/display/node_stream.js`
2024-09-01 15:27:48 +02:00
Jonas Jenwald
2a68aa62f2
Merge pull request #18674 from Snuffleupagus/full-l10n-ids
Use "full" localization ids throughout the code-base
2024-09-01 10:11:21 +02:00
Calixte Denizet
1b0bfcae3e Add an option (i.e. --noFirefox) to only use Chrome when running tests 2024-08-31 22:29:24 +02:00
Jonas Jenwald
ff762179a6
Merge pull request #18671 from Snuffleupagus/update-l10n
Update l10n files
2024-08-31 21:36:51 +02:00
Jonas Jenwald
b01df28810 Use "full" localization ids throughout the code-base
It was recently brought to my attention that using partial or generated localization ids is bad for maintainability, hence this patch goes through the code-base and replaces any such occurrences.
2024-08-31 18:31:31 +02:00
Jonas Jenwald
044f1c9e07 Shorten the code that inits AnnotationEditorLayerBuilder in the web/pdf_page_view.js file
This code can now utilize logical OR assignment, which is ever so slightly shorter.
2024-08-31 11:58:43 +02:00
Jonas Jenwald
bcc511119e Update l10n files
Given the recent l10n-id changes, let's do one more update before the next release to avoid "broken" translations.
2024-08-31 11:17:38 +02:00
calixteman
7494dbccf4
Merge pull request #18666 from calixteman/update_loading_icon_alt_text
[Editor] Update the loading icon when wait for ML to take into account prefered-reduced-motion setting
2024-08-30 18:38:21 +02:00
Calixte Denizet
36c5d192c7 [Editor] Update the loading icon when wait for ML to take into account prefered-reduced-motion setting
* The icon has been updated in https://bugzilla.mozilla.org/show_bug.cgi?id=1908920;
 * Add a linter to check that a svg element doesn't have fill="context-fill" attribute.
2024-08-30 15:48:51 +02:00
Jonas Jenwald
a94e8ba9e8 Add a helper function for http/https requests in src/display/node_stream.js
Currently we repeat virtually the same http/https request code in two different classes in this file, which seems unnecessary and it leads to more code.
2024-08-29 22:52:26 +02:00
Tim van der Meij
f6216df889
Merge pull request #18663 from Snuffleupagus/PDFDocumentProperties-full-l10n-ids
Use "full" localization ids in the `PDFDocumentProperties` class
2024-08-29 20:58:15 +02:00
Tim van der Meij
5d94047dad
Merge pull request #18657 from nicolo-ribaudo/url
Use the URL global instead of the deprecated url.parse
2024-08-29 20:50:43 +02:00
Jonas Jenwald
39ac3ef1a6 Move the metric-locale check into PDFDocumentProperties.#parsePageSize
With the introduction of Fluent the `getLanguage`-method became synchronous, hence it no longer seems necessary to do the metric-locale check eagerly in the constructor and it can instead be "delayed" until actually needed.
2024-08-29 20:26:11 +02:00
Jonas Jenwald
a6e54160cc Use "full" localization ids in the PDFDocumentProperties class
It was recently brought to my attention that using partial or generated localization ids is bad for maintainability, which means that PR 18636 wasn't the correct thing to do.
However, just reverting that one doesn't really fix the problems which is why this patch updates *every* l10n-id in the `PDFDocumentProperties` class (but doesn't touch any `viewer.ftl`-files). Obviously this leads to more verbose code, but that cannot really be helped.
2024-08-29 20:26:11 +02:00
Tim van der Meij
044e761214
Merge pull request #18655 from Snuffleupagus/PDFDocumentProperties-updateUI-rm-param
Simplify the `PDFDocumentProperties.#updateUI` method
2024-08-29 20:23:04 +02:00
Tim van der Meij
ce656238e3
Merge pull request #18651 from Rob--W/crx-mv3-prep-drop-manifest
[CRX] Remove obsolete manifest features
2024-08-29 20:18:19 +02:00
Tim van der Meij
ea090fec02
Merge pull request #18590 from timvandermeij/puppeteer-23
Upgrade Puppeteer to version 23.1.1
2024-08-29 20:14:19 +02:00
Jonas Jenwald
a5d0e410c7 Simplify the PDFDocumentProperties.#updateUI method
We can remove the `reset`-parameter, since it's redundant, given that it's only used after `PDFDocumentProperties.#reset` has been invoked which means that `this.#fieldData === null` which is equivalent to resetting.
Also, we don't need to have two separate loops in order to update the UI in this method.

Finally, inline the `DEFAULT_FIELD_CONTENT` constant now that it's only used once.
2024-08-29 12:48:11 +02:00
calixteman
a41cd38387
Merge pull request #18661 from calixteman/bug1915434
[Editor] Fix few telemetry issues with the new alt text flow (bug 1915434)
2024-08-28 22:18:21 +02:00
Calixte Denizet
1658b0af55 [Editor] Fix few telemetry issues with the new alt text flow (bug 1915434) 2024-08-28 18:54:15 +02:00
Nicolò Ribaudo
229ad1bb2c
Use the URL global instead of the deprecated url.parse
The Node.js url.parse API (https://nodejs.org/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost)
is deprecated because it's prone to security issues (to the point that Node.js doesn't even publish CVEs for it anymore).

The official reccomendation is to instead use the global URL constructor, available both in Node.js and in browsers.
Node.js filesystem APIs accept URL objects as parameter, so this also avoids a few URL->filepath conversions.
2024-08-27 18:19:25 +02:00
Jonas Jenwald
ab052db5b3
Merge pull request #18654 from Snuffleupagus/editor-l10n-disclaimer-str
[Editor] Define the "pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer" string once
2024-08-27 15:35:50 +02:00
Jonas Jenwald
d70f5a1952 [Editor] Define the "pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer" string once
This l10n-string is being re-defined once for every editor, i.e. currently four times, which seems unnecessary.
To avoid having to check if this l10n-string exists first, we can utilize rest parameters to move it into the `AnnotationEditor._l10nPromise` Map-definition instead.
2024-08-27 14:59:24 +02:00
Jonas Jenwald
e9a319be2c
Merge pull request #18649 from Snuffleupagus/resizers-fluent
[Editor] Utilize Fluent "better" when localizing the resizer DOM-elements
2024-08-27 14:58:59 +02:00
Jonas Jenwald
ac75a05cd4 [Editor] Utilize Fluent "better" when localizing the resizer DOM-elements
Currently we manually localize and update the DOM-elements of the editor-resizers, and it seems nicer to utilize Fluent for that task.
This can be achieved by updating the l10n-strings to directly target the `aria-label` and then just setting the `data-l10n-id` on the DOM-elements.
2024-08-26 21:32:02 +02:00
calixteman
b58c24ab09
Merge pull request #18650 from calixteman/bug1914480
[Editor] Add a missing parameter in the telemetry for the new alt text flow (bug 1914480)
2024-08-26 15:33:41 +02:00
Rob Wu
1d545382a3 [CRX] Remove obsolete extension API calls
These work arounds are no longer relevant to the latest Chrome versions.
2024-08-25 22:03:38 +02:00
Rob Wu
683b511f20 [CRX] Remove obsolete manifest features
In preparation for migrating the Chrome extension to Manifest Version 3,
this patch removes parts of the manifest that are obsolete and/or
unsupported in MV3.

Remove ftp mentions: ftp was dropped from 6 years ago, in Chrome 59.

Remove file_browser_handlers: does not work on Chrome OS according to
https://github.com/mozilla/pdf.js/issues/14161 . MV3 replacement needs
a different manifest key and logic, which will be added later.

Remove content_security_policy: MV3 does not support unsafe-eval CSP,
and PDF.js does not require it. This may result in a mild performance
degradation in PDFs that contain PostScript.

Remove page_action logic: When this logic was originally introduced,
Chrome showed page action buttons in the address bar, which enabled
the extension to display the button on specific PDF viewer tabs only.
In Chrome 49 (2016), pageActions were dropped from the address bar and
put in an UI area that is hidden by default. The user can pin the button
to be unconditionally visible on the toolbar, which is distracting.
Because the UX is no longer serving the original needs, this patch
removes page_action from the manifest.
2024-08-25 20:34:03 +02:00
Calixte Denizet
e8763a08ab [Editor] Add a missing parameter in the telemetry for the new alt text flow (bug 1914480) 2024-08-25 17:33:42 +02:00
Tim van der Meij
54eead78ab
Upgrade Puppeteer to version 23.1.1
This major version contains three breaking changes that impact us:

- The `product` option has been renamed to the more suitable `browser`.
- The `page.screenshot()` API returns a `Uint8Array` instead of a
  `Buffer`, but since `pngjs` requires a `Buffer` object we need to do
  the conversion using `Buffer.from()` before passing data to `pngjs`.
- The browser configuration should be set using a configuration file
  instead of environment variables. Note that as a bonus this allows us
  to remove the `cross-env` dependency since that was only used to set
  the Puppeteer environment variable equally for all operating systems.

For more information about the changes between the old and new Puppeteer
versions refer to https://github.com/puppeteer/puppeteer/releases.
2024-08-25 12:49:20 +02:00
Tim van der Meij
cd99be0aa5
Merge pull request #18638 from Snuffleupagus/PDFDocumentProperties-l10n-functions
Utilize Fluent to format numbers and dates in `PDFDocumentProperties`/`AnnotationLayer`
2024-08-25 12:44:15 +02:00
Tim van der Meij
de365b69fa
Merge pull request #18648 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-08-25 12:39:52 +02:00
Jonas Jenwald
6ce9f97943 Utilize Fluent to format dates in the AnnotationLayer
The `AnnotationLayer` may not display correctly formatted data in PopupAnnotations, especially in the GENERIC viewer, since it's using native methods[1] that depend on the *browser* locale instead of the viewer locale as intended.
With Fluent we're able to improve things since it's got built-in support for formatting dates. Not only does this simplify the JavaScript code slightly, but it also gives the localizer more fine-grained control of the desired output.

Please find additional information here:
 - https://projectfluent.org/fluent/guide/builtins.html
 - https://projectfluent.org/fluent/guide/functions.html

---

[1] `toLocaleDateString`, and `toLocaleTimeString`.
2024-08-25 12:11:02 +02:00
Jonas Jenwald
d96558836e Utilize Fluent to format numbers and dates in PDFDocumentProperties
The `PDFDocumentProperties` dialog may not display correctly formatted data, especially in the GENERIC viewer, since it's using native methods[1] that depend on the *browser* locale instead of the viewer locale as intended.
At the time when this dialog was introduced that was probably all we could easily do, but with Fluent we're able to improve things since it's got built-in support for formatting numbers and dates. Not only does this simplify the JavaScript code, but it also gives the localizer more fine-grained control of the desired output.

Please find additional information here:
 - https://projectfluent.org/fluent/guide/builtins.html
 - https://projectfluent.org/fluent/guide/functions.html

---

[1] `toLocaleString`, `toLocaleDateString`, and `toLocaleTimeString`.
2024-08-25 12:11:02 +02:00
Tim van der Meij
bf778b04a8
Update translations to the most recent versions 2024-08-25 11:40:42 +02:00
Tim van der Meij
c26aac013e
Fix vulnerability in the micromatch dependency
This patch is generated automatically using `npm audit fix` and fixes
CVE-2024-4067 (see https://github.com/advisories/GHSA-952p-6rrq-rcjv),
bringing the vulnerability count back to zero.
2024-08-25 11:39:06 +02:00
Tim van der Meij
5d31fda876
Update dependencies to the most recent versions 2024-08-25 11:38:00 +02:00
Tim van der Meij
037c181af6
Merge pull request #18644 from Snuffleupagus/PDFPrintService-unconditional-toBlob
Use `HTMLCanvasElement.toBlob()` unconditionally in `PDFPrintService`
2024-08-23 20:37:46 +02:00
Tim van der Meij
f11baea3e3
Merge pull request #18643 from Snuffleupagus/l10n-translateOnce
Introduce a `L10n`-method to translate an element once, and use that in `PDFLayerViewer`
2024-08-23 20:36:01 +02:00
Tim van der Meij
f025cecace
Merge pull request #18636 from Snuffleupagus/PDFDocumentProperties-#getL10nStr
Introduce a helper method for fetching l10n-data in `PDFDocumentProperties`
2024-08-23 20:13:19 +02:00
Tim van der Meij
5f7637b9ea
Merge pull request #18635 from calixteman/avoid_print_dialog
Don't show the print dialog when printing in some integration tests
2024-08-23 20:08:04 +02:00
Jonas Jenwald
6a1b1ae6a4 Revoke the blob-URLs used during printing in PDFPrintService 2024-08-23 18:39:28 +02:00
Jonas Jenwald
502a429e3e Use HTMLCanvasElement.toBlob() unconditionally in PDFPrintService
The fallback is very old code, and according to the MDN compatibility data `HTMLCanvasElement.toBlob()` should be available in all browsers that we support now: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#browser_compatibility
2024-08-23 18:29:42 +02:00
Jonas Jenwald
584fef5823
Merge pull request #18646 from Snuffleupagus/issue-18645
Support an odd number of digits in hexadecimal strings (issue 18645)
2024-08-23 18:24:19 +02:00
Jonas Jenwald
8728f7f134 Support an odd number of digits in hexadecimal strings (issue 18645)
See https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G6.1840792
2024-08-23 16:31:43 +02:00
Jonas Jenwald
fabbe544ab Introduce a L10n-method to translate an element once, and use that in PDFLayerViewer
Currently we *manually* fetch the "pdfjs-additional-layers" string and update the DOM-element, which was needed since we want to avoid triggering a bunch of otherwise unnecessary translation when appending the entire layer-tree to the DOM.
By introducing a new helper method in the `L10n`-class we can avoid this, and instead use a "data-l10n-id" attribute on the element (as most other viewer code does nowadays).
2024-08-23 12:31:55 +02:00
Jonas Jenwald
2c34b64415 Introduce a helper method for fetching l10n-data in PDFDocumentProperties
Given the length of the l10n-strings we can slightly reduce verbosity, and thus overall code-size, by introducing a helper method for fetching l10n-data.

While testing this I stumbled upon an issue in the `L10n`-class, where an optional chaining operator was placed incorrectly since the underlying method always return an Array; see 48e2a62ed4/fluent-dom/src/localization.js (L38-L77)
2024-08-21 15:07:46 +02:00
Jonas Jenwald
908f453384
Merge pull request #18627 from richard-smith-preservica/rcs/send-page-dict-requests-in-parallel
Send fetch requests for all page dict lookups in parallel
2024-08-21 13:58:03 +02:00
Richard Smith (smir)
a67b9aec6c Send fetch requests for all page dict lookups in parallel
- When adding page dict candidates to the lookup tree, also initiate fetching them from xref, so if they are not yet loaded at all, the XHR will be sent
 - Only at the top level - assume that if there is a /Pages tree, it is sensibly structured and the number of requests won't be too bad
- We can then await on the cached Promise without making the requests pipeline
- This has a significant performance improvement for load-on-demand (i.e. with auto-fetch turned off) when a PDF has a large number of pages in the top level /Pages collection, and those pages are spread through a file, so every candidate needs to be fetched separately
 - PDFs with many pages where each page is a big image and all the pages are at the top level are quite a common output for digitisation programmes
- I would have liked to do something like "if it's the top level collection and page count = number of kids, then just fetch that page without traversing the tree" but unfortunately I agree with comments on #8088 that there is no good general solution to allow for /Pages nodes with empty /Kids arrays
2024-08-21 11:08:14 +01:00
Calixte Denizet
b0c239a200 Don't show the print dialog when printing in some integration tests 2024-08-20 22:24:08 +01:00
Tim van der Meij
e0fc1a341a
Merge pull request #18628 from Snuffleupagus/issue-18208
Use standard glyph mapping for non-embedded and non-composite Calibri fonts (issue 18208)
2024-08-19 20:26:56 +02:00
Jonas Jenwald
6dd31183be Use standard glyph mapping for non-embedded and non-composite Calibri fonts (issue 18208)
Given that we handle non-embedded Calibri fonts as "mapped to standard font", we really ought to be able to use the same glyph mapping as for an actual standard font.
Note that this actually improves consistency in the code, given how we already handle such fonts if they happen to be of the `CIDFontType2` type; see b47c7eca83/src/core/fonts.js (L1186-L1190)
2024-08-19 19:10:35 +02:00
Tim van der Meij
88ea60dcde
Merge pull request #18624 from timvandermeij/intermittent-scripting-siblings
Fix the "must check that a value is correctly updated on a field and its siblings" scripting integration test
2024-08-19 19:04:34 +02:00
Tim van der Meij
79dce534f5
Merge pull request #18623 from timvandermeij/uimanager-test
[Editor] Move setting `window.uiManager` back to the test code
2024-08-19 19:04:11 +02:00
Tim van der Meij
5cc77d3ebd
Fix the "must check that a value is correctly updated on a field and its siblings" scripting integration test
This integration test fails intermittently because we cache the initial
total value to be able to compare it to the new total value at the end
of the test to check that it's different before doing the assertions.
However, this doesn't work as expected because the second `clearInput`
call triggers an intermediate total value calculation because it clicks
on another input field and that triggers a sandbox event.

This results in the `waitForFunction` calls always resolving immediately
and since we don't use other means of waiting until the calculation is
done (using e.g. `waitForSandboxTrip`) we basically rely on the time
between the final click and the assertions to be enough for the sandbox
to do its work. If it's is not done in that time, we do the assertions
with older values and that makes the test fail.

This commit fixes the issue by simply waiting for the total value to be
what we expect it to be. This requires less code, is more consistent
with the other integration tests and removes the possibility of doing
assertions against older values.
2024-08-18 19:24:51 +02:00
Tim van der Meij
db06011032
[Editor] Move setting window.uiManager back to the test code
In PR #18574 setting `window.uiManager` was moved into the `src` folder
to avoid intermittent integration test failures because at the time we
lacked a way to register event listeners early (before PDF.js loads).
However, in PR #18617 this functionality got introduced, so we can now
use the new way of setting up the event bus in the tests to move this
back to the `test` folder again and to reduce the amount of test-only
code in the main codebase as discussed in PR #18574.

Partially reverts e037c5711d3d2413669e9b6c275986adf24a295b.
2024-08-18 15:45:42 +02:00
Tim van der Meij
b47c7eca83
Merge pull request #18617 from calixteman/early_event_handler
Set the event handlers in the integration tests before any event is triggered
2024-08-18 15:10:23 +02:00
Calixte Denizet
5e4948062c Set the event handlers in the integration tests before any event is triggered
The function evaluateOnNewDocument in Puppeteer allow us to execute some js before the pdf.js one
is loaded.
It allows us to stub some setters before there are used and then set some event handlers very soon.
2024-08-18 09:57:43 +01:00
Tim van der Meij
f7d3add994
Merge pull request #18615 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-08-16 19:02:39 +02:00
Tim van der Meij
0aada51568
Update translations to the most recent versions 2024-08-15 19:52:03 +02:00
Tim van der Meij
f6c2860195
Fix the repository URLs in the importl10n script
We introduced quite a few new strings recently, but during the last few
rounds of updates we didn't see new translations updates becoming
available. I only just now recalled the announcement that Mozilla is
moving from Mercurial to Git, and indeed the Mercurial page at
https://hg.mozilla.org/l10n-central hasn't been updated since July
anymore and that's were we used to pull our translations from.

This commit fixes the issue by changing the URLs to the Mozilla Git
repositories hosted on GitHub instead.
2024-08-15 19:51:48 +02:00
Tim van der Meij
44f7e3c002
Fix vulnerability in the axios dependency
This patch is generated automatically using `npm audit fix` and fixes
CVE-2024-39338 (see https://github.com/advisories/GHSA-8hc4-vh64-cxmj),
bringing the vulnerability count back to zero.
2024-08-15 19:37:05 +02:00
Tim van der Meij
140dd3c99f
Update dependencies to the most recent versions 2024-08-15 19:34:02 +02:00
Tim van der Meij
d8d9cff715
Merge pull request #18612 from Snuffleupagus/_parseHashParams-shorten
Shorten the `PDFViewerApplication._parseHashParams` method
2024-08-15 18:39:35 +02:00
Tim van der Meij
73bae55c5d
Merge pull request #18613 from calixteman/enable_tests
Enable disabled integration tests for Firefox
2024-08-15 18:35:10 +02:00
Calixte Denizet
75e52360ad Enable disabled integration tests for Firefox 2024-08-15 13:11:31 +01:00
Jonas Jenwald
ee7441d5bc Shorten the PDFViewerApplication._parseHashParams method
The way that the debugging hash-parameter parsing is implemented leads to a lot of boilerplate code in this method, since *most* of the cases are very similar.[1]
With just a few exceptions most of the options can be handled automatically, by defining an appropriate checker for each option.

---

[1] With the recent introduction of TESTING-only options the size of this method increased a fair bit.
2024-08-15 13:50:35 +02:00
calixteman
b60261e39a
Merge pull request #18611 from calixteman/fix_telemetry
Fix the telemetry for the new alt-text flow
2024-08-15 12:46:55 +01:00
Jonas Jenwald
17f387b460
Merge pull request #18610 from Snuffleupagus/bug-report-version-description
Link to official releases and the demo viewer in the bug report template
2024-08-15 13:31:05 +02:00
Calixte Denizet
9bd00859d3 Fix the telemetry for the new alt-text flow 2024-08-15 11:29:00 +01:00
Jonas Jenwald
4caa309fda Link to official releases and the demo viewer in the bug report template
Hopefully this might lead to *more* users actually testing the latest version before reporting a bug.
2024-08-15 09:25:21 +02:00
Tim van der Meij
8446d3ac03
Merge pull request #18605 from Snuffleupagus/issue-18196
Handle the "switchannotationeditorparams" event in the editor-code (issue 18196)
2024-08-13 19:42:20 +02:00
Jonas Jenwald
9e0c6ef476 Handle the "switchannotationeditorparams" event in the editor-code (issue 18196)
The problem seems to be caused by the browser trying to "restore" editing input-elements, in the various toolbars, to their previous values when the tab is re-opened.

Hence the simplest solution appears to be to move the event handling into the editor-code, which is also less code overall, since the listener thus won't be registered early enough for the problem to appear.
2024-08-13 15:29:55 +02:00
Jonas Jenwald
82735537bf Use the local eventBus in the AnnotationEditorUIManager constructor
This shortens the code ever so slightly, which cannot hurt.
2024-08-13 14:51:16 +02:00
Jonas Jenwald
038e482760
Merge pull request #18601 from timvandermeij/css-cleanup
Improve the viewer CSS after nesting the findbar and secondary toolbar rules
2024-08-13 12:37:17 +02:00
Jonas Jenwald
14f6cbe2b2
Merge pull request #18604 from Snuffleupagus/version-4.6
Bump library version to `4.6`
2024-08-13 12:30:27 +02:00
Jonas Jenwald
af03894764 Bump library version to 4.6 2024-08-13 12:20:52 +02:00
Jonas Jenwald
a999b346d0
Merge pull request #18549 from nicolo-ribaudo/custom-find-matcher-subclass
[api-minor] Allow specifying custom match logic in PDFFindController
2024-08-13 12:17:27 +02:00
Nicolò Ribaudo
f051597e23
Allow specifying custom match logic in PDFFindController
This patch allows embedders of PDF.js to provide custom match
logic for seaching in PDFs. This is done by subclassing the
PDFFindController class and overriding the `match` method.

`match` is called once per PDF page, receives as parameters the
search query, the page contents, and the page index, and returns
an array of { index, length } objects representing the search
results.
2024-08-13 10:45:57 +02:00
Jonas Jenwald
17b24639b9
Merge pull request #18594 from Snuffleupagus/rm-enableHighlightEditor-pref
Remove the `enableHighlightEditor` preference
2024-08-13 08:14:09 +02:00
Tim van der Meij
9fd23d8082
Generalize the CSS rules for labeled toolbar buttons
This commit fixes a regression from #18596 where the "Add image" button
styles broke because it's a labeled toolbar button but the labeled
toolbar button CSS rules were only scoped to the secondary toolbar.
However, nowadays labeled toolbar buttons are also used in e.g. the
editor parameters toolbar, and this highlighted that we didn't clearly
encode the concept of labeled toolbar buttons in the CSS so far.

This patch extracts the CSS rules for labeled toolbar buttons that were
previously limited to the secondary toolbar into a dedicated generic
class that can be applied on top of any unlabeled toolbar button to
convert it to a labeled toolbar button, regardless of its position in
the DOM. This also makes the distinction clearer in the HTML, and the
new CSS scope for the toolbar buttons lays the foundation for combining
the other toolbar buttons rules in there later on.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-12 20:27:33 +02:00
Tim van der Meij
68bda90777
Improve grouping of the secondary toolbar button CSS rules
Using the `:is(a)` selector we can move the previously separate rules
into the main `.toolbarButton` override rules.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-12 20:08:29 +02:00
Tim van der Meij
2a982e71ed
Merge the duplicate .editorParamsToolbar CSS blocks
Now that we have dedicated CSS scopes for the findbar and the secondary
toolbar we have ended up with two CSS blocks with identical selectors,
so now we can combine them for simplicity and to remove some rules in
the first block that were always overridden by the second block.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-12 20:04:36 +02:00
Tim van der Meij
d0fbfe10c5
Merge pull request #18598 from Snuffleupagus/base-class-init-TESTING-check
Limit base-class initialization checks to development and TESTING modes
2024-08-12 19:06:21 +02:00
Tim van der Meij
9103cf00c0
Merge pull request #18597 from timvandermeij/css-secondary-toolbar-part-3
Group and scope the secondary toolbar rules using CSS nesting
2024-08-12 19:03:04 +02:00
Jonas Jenwald
aebb8534f3 Limit base-class initialization checks to development and TESTING modes
We have a number of base-classes that are only intended to be extended, but never to be used directly. To help enforce this during development these base-class constructors will check for direct usage, however that code is obviously not needed in the actual builds.

*Note:* This patch reduces the size of the `gulp mozcentral` output by `~2.7` kilo-bytes, which isn't a lot but still cannot hurt.
2024-08-12 12:26:35 +02:00
Tim van der Meij
5193adf1fd
Group and scope the secondary toolbar rules using CSS nesting
The secondary toolbar CSS rules predate the general availability of CSS
nesting, which makes them more difficult to understand and change
safely. The primary issues are that the rules are spread over the
`viewer.css` file, they share blocks with other elements and the scope
of the rules is sometimes bigger than necessary.

This refactoring groups all remaining secondary toolbar rules together,
scoped to the top-level `#secondaryToolbar` element, for improved
overview and isolation. Note that this patch only intends to move the
existing rules around and not change any behavior.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-11 18:27:04 +02:00
Tim van der Meij
aa2337f934
Merge pull request #18596 from timvandermeij/css-secondary-toolbar-part-2
Remove the `secondaryToolbarButton` CSS class
2024-08-11 18:25:29 +02:00
Tim van der Meij
2a22424c95
Remove the secondaryToolbarButton CSS class
Secondary toolbar buttons are toolbar buttons with some extra rules,
mainly to make them wider and have visible labels. However, this
similarity is currently not clearly reflected in the implementation
because the secondary toolbar buttons use a different CSS class,
`secondaryToolbarButton`, compared to the other toolbar buttons that
use the `toolbarButton` CSS class. This also causes some duplication
in the rules and requires extra care to keep the common bits for the
`secondaryToolbarButton` class in sync with the `toolbarButton` class.

Fortunately, now that we have a dedicated CSS scope for the secondary
toolbar, we can simplify this by giving all secondary toolbar buttons
the `toolbarButton` class and explicitly listing the required overrides
in the `#secondaryToolbar` scope instead. Doing so removes most of the
special-casing for secondary toolbar buttons while explicitly listing
the differences in a single place for a better overview. It also lays
the foundation for making all toolbar buttons respect the
`browser.uidensity` Firefox preference later by reducing differences.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-11 17:48:25 +02:00
Tim van der Meij
efe00cf68c
Merge pull request #18595 from timvandermeij/css-secondary-toolbar-part-1
Group and scope the secondary toolbar button container/icon rules using CSS nesting
2024-08-11 16:14:59 +02:00
Tim van der Meij
97b761dfbf
Group and scope the secondary toolbar button container/icon rules using CSS nesting
The secondary toolbar CSS rules predate the general availability of CSS
nesting, which makes them more difficult to understand and change
safely. The primary issues are that the rules are spread over the
`viewer.css` file, they share blocks with other elements and the scope
of the rules is sometimes bigger than necessary.

This refactoring groups all CSS rules for the secondary toolbar button
container/icons together, scoped to the top-level `#secondaryToolbar`
element, for improved overview and isolation. Note that this patch only
intends to move the existing rules around and not change any behavior.
Moreover, this patch does not move the rules for the secondary toolbar
itself and the secondary toolbar buttons; those will be part of a
follow-up patch and will be easier once this is in place first.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-11 13:52:23 +02:00
calixteman
e44e4db529
Merge pull request #18589 from calixteman/new_alt_text_telemetry
[Editor] Add the telemetry for the new alt text (bug 1912500)
2024-08-10 18:49:41 +02:00
Calixte Denizet
00305184b5 [Editor] Add the telemetry for the new alt text (bug 1912500) 2024-08-10 18:29:03 +02:00
Tim van der Meij
6e4b347e1b
Merge pull request #18593 from Snuffleupagus/PDFSidebar-AbortController
Remove the sidebar resizing event listeners with an `AbortController`
2024-08-10 18:28:38 +02:00
Tim van der Meij
ec48602379
Merge pull request #18592 from Snuffleupagus/firefoxcom-AbortSignal-any
[Firefox] Remove the "loadaiengineprogress" listener with `AbortSignal.any()`
2024-08-10 18:21:18 +02:00
Tim van der Meij
4367fc1bc0
Merge pull request #18581 from calixteman/new_alt_text_test_1
[Editor] Add a first test to test the new alt text flow
2024-08-10 18:14:12 +02:00
Jonas Jenwald
b9f5e78e15 Remove the enableHighlightEditor preference
This was enabled by default in Firefox 126, see [bug 1867513](https://bugzilla.mozilla.org/show_bug.cgi?id=1867513), so hopefully we should be able to remove the option/preference now.
2024-08-10 16:00:31 +02:00
Calixte Denizet
debcb2267e [Editor] Add a first test to test the new alt text flow 2024-08-10 14:59:35 +02:00
Jonas Jenwald
be685a293c Remove the sidebar resizing event listeners with an AbortController 2024-08-10 12:24:59 +02:00
Jonas Jenwald
7619171265 Stop sidebar resizing on "blur" events
Because of an old oversight (by me) we don't stop sidebar resizing when the browser window loses focus, which seems generally wrong and can also lead to duplicate mouse-related event listeners being registered.
2024-08-10 12:24:54 +02:00
Jonas Jenwald
984debaa9f Use a few local variables in PDFSidebar.#addEventListeners
This, ever so slightly, shortens the code for a couple of repeatedly accessed class fields.
2024-08-10 12:06:45 +02:00
Jonas Jenwald
723c76929c [Firefox] Remove the "loadaiengineprogress" listener with AbortSignal.any() 2024-08-10 11:16:42 +02:00
calixteman
b6b99a7b75
Merge pull request #18588 from mozilla/revert-18580-alt_text_pass_buffer
Revert "[Editor] Pass a buffer instead of a typed array when passing image data to the model"
2024-08-09 17:53:16 +02:00
calixteman
31727ccb4d
Revert "[Editor] Pass a buffer instead of a typed array when passing image data to the model" 2024-08-09 17:49:47 +02:00
Tim van der Meij
daabc7abea
Merge pull request #18587 from Snuffleupagus/PDFViewer-check-AbortSignal-any
Check that `AbortSignal.any()` is supported in `PDFViewer` too (PR 18586 follow-up)
2024-08-09 17:35:25 +02:00
Jonas Jenwald
da9cfe7781 Check that AbortSignal.any() is supported in PDFViewer too (PR 18586 follow-up)
Without this patch the viewer may break on load, since the check added in PR 18586 only applies to the toolbar.
2024-08-09 16:48:44 +02:00
Jonas Jenwald
b7198d316f
Merge pull request #18586 from Snuffleupagus/editor-AbortSignal-any
[Editor] Remove event listeners with `AbortSignal.any()`
2024-08-09 16:20:49 +02:00
calixteman
36dc666d04
Merge pull request #18584 from calixteman/preview_background
[Editor] Change the background color of the image preview in the new alt text dialog
2024-08-09 12:36:15 +02:00
Jonas Jenwald
c0bf3d3c94 [Editor] Remove event listeners with AbortSignal.any()
There's a fair number of event listeners in the editor-code that we're currently removing "manually", by keeping references to their event handler functions.
This was necessary since we have a "global" `AbortController` that applies to all event listeners used in the editor-code, however it's now possible to combine multiple `AbortSignal`s; please see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static

Since this functionality is [fairly new](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static#browser_compatibility) the viewer will check that `AbortSignal.any()` is available before enabling the editing-functionality.
(It should hopefully be fairly straightforward, famous last words, for users to implement a polyfill to allow editing in older browsers.)

Finally, this patch also adds checks and test-only asserts to ensure that we don't add duplicate event listeners in various editor-code.
2024-08-09 11:24:34 +02:00
Calixte Denizet
bad214fc71 [Editor] Change the background color of the image preview in the new alt text dialog 2024-08-08 21:13:58 +02:00
Tim van der Meij
4569e88778
Merge pull request #18568 from timvandermeij/css-findbar
Group and scope the findbar rules using CSS nesting
2024-08-08 20:27:14 +02:00
Tim van der Meij
fb049b0a05
Merge pull request #18583 from timvandermeij/eslint-plugin-mozilla
Remove the `eslint-plugin-mozilla` dependency
2024-08-08 20:26:52 +02:00
Tim van der Meij
be93d530de
Remove the eslint-plugin-mozilla dependency
We only used two rules from the plugin which can both easily be replaced
nowadays:

- `mozilla/avoid-removeChild` is equal to the already active
  `unicorn/prefer-dom-node-remove` rule; please see [1] and [2].
- `mozilla/import-globals` is mostly obsolete nowadays ever since we
  removed the Firefox extension code from this repository and we
  eliminated most globals usage. The three remaining occurrences can be
  replaced with explicit `/* globals */` comments that we already use
  elsewhere, which overall is also more consistent.

[1] https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/rules/avoid-removeChild.html
[2] https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-remove.md
2024-08-08 19:51:20 +02:00
Tim van der Meij
1fcdcedee1
Group and scope the findbar rules using CSS nesting
The findbar CSS rules predate the general availability of CSS nesting,
which makes them more difficult to understand and change safely. The
primary issues are that the findbar rules are spread all over the
`viewer.css` file, they share blocks with non-findbar elements and the
scope of the rules is sometimes bigger than necessary.

This refactoring groups all findbar-related CSS rules together, scoped
to the top-level `#findbar` element, for improved overview and
isolation. Note that this patch only intends to move the existing rules
around and not change any behavior yet, but it does lay the foundation
for e.g. making the findbar respect the `browser.uidensity` preference
in Firefox in follow-up work.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-08-08 19:19:32 +02:00
Tim van der Meij
cd3d188f99
Merge pull request #18571 from timvandermeij/linting
Enable the `unicorn/{prefer-includes,throw-new-error}` linting rules
2024-08-08 19:18:26 +02:00
Tim van der Meij
318433b2d8
Enable the unicorn/throw-new-error linting rule
For more information refer to
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/throw-new-error.md.

This didn't require any changes because we already do this correctly,
but it ensures that new code remains consistent and explicit.
2024-08-08 19:03:07 +02:00
Tim van der Meij
ad95df2214
Enable the unicorn/prefer-includes linting rule
For more information refer to
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-includes.md.

Fortunately this only required one change because we already use
`.includes()` everywhere else. Note that that is mostly due to the
`mozilla/use-includes-instead-of-indexOf` rule which we replace with
this new rule now because it's more complete.
2024-08-08 19:01:35 +02:00
calixteman
40aa593b1f
Merge pull request #18580 from calixteman/alt_text_pass_buffer
[Editor] Pass a buffer instead of a typed array when passing image data to the model
2024-08-08 14:48:27 +02:00
Calixte Denizet
d2e8e742eb [Editor] Pass a buffer instead of a typed array when passing image data to the model 2024-08-08 14:43:36 +02:00
calixteman
999403f5ef
Merge pull request #18579 from calixteman/cancel_ai_requests_2
Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
2024-08-07 23:26:37 +02:00
Calixte Denizet
1d51c3e711 Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
The user can change a setting in a tab and it must have an effect in the current viewer.
2024-08-07 23:21:38 +02:00
calixteman
e099840100
Merge pull request #18578 from mozilla/revert-18573-cancel_ai_requests
Revert "[Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)"
2024-08-07 23:14:11 +02:00
calixteman
6c005eabb3
Revert "[Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)" 2024-08-07 23:11:31 +02:00
calixteman
fef2853263
Merge pull request #18573 from calixteman/cancel_ai_requests
[Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
2024-08-07 23:11:04 +02:00
Calixte Denizet
92ade5495b [Editor] Dispatch changes in prefs enableAltTextModelDownload and enableGuessAltText to the viewer (bug 1912024)
The user can change a setting in a tab and it must have an effect in the current viewer.
2024-08-07 22:45:08 +02:00
calixteman
5709b1300d
Merge pull request #18575 from calixteman/ai_disclaimer_icon_position
[Editor] Move the AI icon on the top of its parent div
2024-08-07 19:22:29 +02:00
calixteman
3cad8d1c27
Merge pull request #18574 from calixteman/add_window_uimanager_test
[Editor] Add the uiManager to the window object when testing
2024-08-07 19:17:24 +02:00
Calixte Denizet
f487ed3004 [Editor] Move the AI icon on the top of its parent div
And fix the line-height for all the dialog (which is "normal" in the specs).
Because of the wrong line-height, the icon was slightly misplaced.
2024-08-07 18:50:59 +02:00
Calixte Denizet
e037c5711d [Editor] Add the uiManager to the window object when testing 2024-08-07 18:06:14 +02:00
Tim van der Meij
341a0b6d47
Merge pull request #18566 from calixteman/issue18561
Don't stop calculating field values when a Calculate callback throws
2024-08-06 17:59:15 +02:00
Tim van der Meij
af012c7872
Merge pull request #18567 from timvandermeij/integration-test-otherpages
Remove obsolete `otherPages` variable from the scripting integration tests
2024-08-06 17:23:36 +02:00
calixteman
18284815e7
Merge pull request #18570 from calixteman/new_alt_text_string_change
[Editor] Update the disclaimer string in the new alt-text dialog (bug 1911738)
2024-08-06 14:09:11 +02:00
Calixte Denizet
fc602c65c0 [Editor] Update the disclaimer string in the new alt-text dialog (bug 1911738)
And tweak the css in order to take into account that disclaimer can be on two (or more lines).
2024-08-06 10:17:18 +02:00
Calixte Denizet
ad12f33999 Don't stop calculating field values when a Calculate callback throws
It fixes #18561.
2024-08-05 20:36:04 +02:00
Tim van der Meij
b7b0735192
Remove obsolete otherPages variable from the scripting integration tests
It looks like this has accidentally been copy/pasted from the
`Textfields and focus` block, which is the only one in which a test
actually uses it. We can therefore safely remove it from all other
blocks where no test uses it.
2024-08-05 19:23:39 +02:00
Tim van der Meij
9ac05e797c
Merge pull request #18560 from Snuffleupagus/editor-bind-event-handlers
Define a few editor event handler functions inline
2024-08-05 18:34:36 +02:00
Tim van der Meij
7c896578c2
Merge pull request #18555 from timvandermeij/waitforevent
Use the `waitForEvent` helper function in the text layer integration tests
2024-08-05 18:23:56 +02:00
Tim van der Meij
9844ce01b3
Merge pull request #18554 from timvandermeij/updates
Update dependencies to the most recent versions
2024-08-05 18:19:11 +02:00
Jonas Jenwald
d32b294a60
Merge pull request #18562 from nicolo-ribaudo/babel-static-block
Update the Babel plugin to remove empty static blocks
2024-08-05 16:19:25 +02:00
Nicolò Ribaudo
995f5a29aa
Update the Babel plugin to remove empty static blocks
This commit updates the Babel plugin to:
- apply the same flattening logic that we already
  have for blocks, to flatten blocks nested inside
  class static blocks
- remove class static blocks when, after flattening
  all the blocks they contain, they are empty.

Before this commit, the transform output was the
same as the input.
2024-08-05 15:14:05 +02:00
Jonas Jenwald
0eac5e9d6f Define a few editor event handler functions inline
Given that we're removing event listeners with `AbortSignal` it's no longer necessary to keep a reference to a few of the event handler functions in order to remove them.
Hence we can simply inline the relevant `bind`-calls instead, which reduces the code-size a tiny bit.
2024-08-05 12:27:53 +02:00
Tim van der Meij
356d54175b
Use the waitForEvent helper function in the text layer integration tests
The `waitForClick` helper function is functionality-wise mostly a
reduced copy of the more generic `waitForEvent` helper function that
we use for other integration tests, so we can safely replace it to
reduce the amount of code.

Moreover, the `waitForClick` code is prone to intermittent failures
given recent assertion failures we have seen on the bots (one of them
is linked in #18396) while `waitForEvent` has recently been fixed to
avoid intermittent failures, so usiong it should also get rid of the
flakiness for these integration tests.
2024-08-04 20:14:43 +02:00
Tim van der Meij
f7d2145782
Upgrade postcss-nesting to version 13.0.0
This is a major version bump, but the changelog at
https://github.com/csstools/postcss-plugins/blob/main/plugins/postcss-nesting/CHANGELOG.md
doesn't indicate any breaking changes that should impact us.
2024-08-04 19:24:43 +02:00
Tim van der Meij
1dfdb59f0b
Upgrade postcss-dir-pseudo-class to version 9.0.0
This is a major version bump, but the changelog at
https://github.com/csstools/postcss-plugins/blob/main/plugins/postcss-dir-pseudo-class/CHANGELOG.md
doesn't indicate any breaking changes that should impact us.
2024-08-04 19:23:10 +02:00
Tim van der Meij
762b16c08a
Update dependencies to the most recent versions 2024-08-04 19:20:36 +02:00
calixteman
c60c0d1c6d
Merge pull request #18552 from calixteman/issue18536
Empty fields are 0 when using AFSimple_Calculate
2024-08-03 15:10:22 +02:00
Calixte Denizet
4b7f9a8d87 Empty fields are 0 when using AFSimple_Calculate
It fixes #18536 and #18532.
2024-08-02 21:51:27 +02:00
Jonas Jenwald
829c9f553d
Merge pull request #18551 from Snuffleupagus/rm-viewer-download-options
Stop sending the unused `options` parameter to various download-methods in the viewer
2024-08-02 21:10:10 +02:00
Jonas Jenwald
ecbd660609 Stop sending the unused options parameter to various download-methods in the viewer
The `options` handling, for the download-methods, was originally added in PR 16391 and became obsolete in PR 17771.

This fixes failures, in mozilla-central tests, which appeared after landing PR 18527.
2024-08-02 20:46:13 +02:00
calixteman
a372bf8f4d
Merge pull request #18541 from calixteman/use_ml_but_no_dialog
[Editor] Guess alt text even when showing the dialog is disabled
2024-08-02 18:02:53 +02:00
Tim van der Meij
7ac87dd6f8
Merge pull request #18544 from Snuffleupagus/app-bind-listeners
Improve the larger event listeners in the `web/app.js` file
2024-08-02 17:56:19 +02:00
Calixte Denizet
d2c519e57a Guess alt text even when showing the dialog is disabled 2024-08-02 17:40:10 +02:00
calixteman
c8ba7b02b0
Merge pull request #18546 from calixteman/load_model_switch_stamp
[Editor] Load the model when the user switch to the stamp editing mode
2024-08-02 17:21:26 +02:00
Calixte Denizet
a81b071d2d [Editor] Load the model when the user switch to the stamp editing mode 2024-08-02 17:14:09 +02:00
Jonas Jenwald
aae223f79b Replace onScrollModeChanged and onSpreadModeChanged with one function
Given that these event handlers are virtually identical, obviously with the exception of the name-parameter, let's reduce a little bit of code duplication.
2024-08-02 16:16:25 +02:00
Jonas Jenwald
22ec252193 Improve the larger event listeners in the web/app.js file
- Shorten the names of the event listeners.

 - Use `bind` to pass in the `PDFViewerApplication`-scope to the event handlers.
   This makes the event handler code (a lot) less verbose, and this change is possible now that we're removing event listeners with `AbortSignal`.

 - Move the GENERIC-only event listeners into the same pre-processor block.

*Note:* This patch reduces the size of the `gulp mozcentral` output by `~4.3` kilo-bytes, which isn't a lot but still cannot hurt.
2024-08-02 16:16:25 +02:00
Tim van der Meij
b80e552760
Merge pull request #18527 from Snuffleupagus/app-inline-short-listeners
Inline single-line event handlers in the `web/app.js` file
2024-08-02 16:08:45 +02:00
Tim van der Meij
5e052af3f6
Merge pull request #18542 from Snuffleupagus/bug-report-browser-description
Link to the list of supported browsers in the bug report template
2024-08-02 15:55:26 +02:00
Tim van der Meij
0d44e71b95
Merge pull request #18547 from calixteman/fix_hcm_button_colors
Fix the color of the buttons in a dialog in HCM
2024-08-02 15:53:58 +02:00
Calixte Denizet
f32d19de18 Fix the color of the buttons in a dialog in HCM 2024-08-02 15:38:55 +02:00
calixteman
08821a3e5d
Merge pull request #18543 from calixteman/disable_create_alttext_button
[Editor] Avoid to have the create alt-text button without a click listener
2024-08-02 15:06:05 +02:00
Jonas Jenwald
464d534961
Merge pull request #18540 from calixteman/no_ml_settings
[Editor] Don't create the image settings dialog if new alt-text is disabled
2024-08-02 12:14:12 +02:00
Calixte Denizet
271bd4d079 [Editor] Avoid to have the create alt-text button without a click listener
The toggle button hasn't a click listener after we deleted and downloaded the model.
2024-08-02 11:05:58 +02:00
Calixte Denizet
974911f24f [Editor] Don't create the image settings dialog if new alt-text is disabled 2024-08-02 10:41:34 +02:00
Jonas Jenwald
adb6548d38 Link to the list of supported browsers in the bug report template
Given that users fairly often report issues with unsupported browsers/environments it cannot hurt to provide a link to the relevant section in the FAQ.
2024-08-02 10:40:50 +02:00
calixteman
4422e6fb3b
Merge pull request #18538 from calixteman/fix_new_alt_text_l10n
[Editor] Fix l10n issues
2024-08-02 10:39:08 +02:00
Calixte Denizet
63d0fa5733 [Editor] Fix l10n issues
Remove the strings containing only a variable.
2024-08-02 10:36:18 +02:00
calixteman
a7768a30b8
Merge pull request #18539 from calixteman/use_css_var
[Editor] Use the color defined for the message bar foreground
2024-08-02 10:32:54 +02:00
Calixte Denizet
1a8bcdb2ba [Editor] Use the color defined for the message bar foreground 2024-08-02 09:35:21 +02:00
Jonas Jenwald
89f3a26c2f Inline single-line event handlers in the web/app.js file
We have a fair number of (effectively) single-line event handlers in the  `web/app.js` file, which leads to unnecessarily verbose code. These can, without affecting readability too much, be replaced either by:
 - Using `bind` for the simplest cases.
 - Using arrow-functions for the remaining ones.

Note that this is possible since we started removing event listeners with `AbortSignal`, which means that we no longer need to keep a reference to the event handler functions to be able to remove them.

Given that the old event handler functions use fairly long function names, and the way that they access `PDFViewerApplication` (given their scope), they impact the overall code-size unnecessarily.
*Note:* This patch reduces the size of the `gulp mozcentral` output by `~3.7` kilo-bytes, which isn't a lot but still cannot hurt.
2024-08-01 22:02:55 +02:00
calixteman
501da85222
Merge pull request #18537 from calixteman/image_settings
[Editor] Add a new dialog for alt-text settings (bug 1909604)
2024-08-01 21:55:41 +02:00
Calixte Denizet
32d09276f0 [Editor] Add a new dialog for alt-text settings (bug 1909604)
This patch adds a new entry in the secondary menu in order to open a dialog to let the user:
 - disables the alt-text generation thanks to a ML model;
 - deletes the alt-text model downloaded in Firefox;
 - disabled the new alt-text flow.
2024-08-01 21:34:50 +02:00
Tim van der Meij
d562e0525d
Merge pull request #18523 from Snuffleupagus/Toolbar-more-bindListeners
Move all event listeners into `Toolbar.prototype.#bindListeners`
2024-08-01 20:41:32 +02:00
Tim van der Meij
e6bb1f324b
Merge pull request #18535 from Snuffleupagus/bug-report-PDF-description
Further emphasize the importance of `Attach (recommended) or Link to PDF file` in the bug report template
2024-08-01 20:07:59 +02:00
Tim van der Meij
0269cf5b4d
Merge pull request #18518 from timvandermeij/viewer-toolbar-height
Introduce a CSS variable for the toolbar height (bug 1171799)
2024-08-01 20:06:43 +02:00
Tim van der Meij
ec0f0f3d9b
Merge pull request #18517 from timvandermeij/viewer-button-types
Give all HTML button elements a type
2024-08-01 20:06:23 +02:00
Jonas Jenwald
12c3f251a1 Further emphasize the importance of Attach (recommended) or Link to PDF file in the bug report template
Unfortunately it turns out (perhaps unsurprisingly) that even the new bug report template isn't stopping users from leaving out the single most important part, i.e. `Attach (recommended) or Link to PDF file`, despite it now being marked as a required field.
2024-08-01 12:01:39 +02:00
calixteman
63371eaed8
Merge pull request #18526 from calixteman/bug1907958
[Editor] Allow Float32Array for quadpoints in annotations (bug 1907958)
2024-07-31 17:34:19 +02:00
Calixte Denizet
5f95d9b1ba [Editor] Allow Float32Array for quadpoints in annotations (bug 1907958)
Added annotations could have some quadpoints (highlight, ink).
The isNumberArray check was returning false and consequently the annotation wasn't
printable.
The tests didn't catch this issue because the quadpoints were passed as Array.
So driver.js has been updated in order to pass them as Float32Array in order
to be in a situation similar to the real life one.
2024-07-31 16:23:01 +02:00
Jonas Jenwald
7c3aa9445c Move all event listeners into Toolbar.prototype.#bindListeners
Over time a couple of event listeners have been placed in the constructor, despite there being an existing helper method for that purpose. To improve the code organization, let's move these to the intended method instead.
2024-07-31 09:49:25 +02:00
Tim van der Meij
e3838c1c70
Introduce a CSS variable for the toolbar height (bug 1171799)
This refactoring lays the foundation for making the toolbar height
configurable in Firefox via the `browser.uidensity` preference. For
this to work correctly the toolbar height must be defined in a single
place that can easily be updated dynamically, hence this patch which
moves it to a CSS variable in such a way that the rest of the UI adapts
correctly if the value is changed.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-07-30 21:22:49 +02:00
calixteman
f6b356eff7
Merge pull request #18516 from calixteman/add_bg_for_alpha
[Editor] Add a checkerboard behind the image preview in the new alt-text dialog in order to see its potential transparency
2024-07-30 18:53:24 +02:00
Tim van der Meij
f1f58bbe67
Give all HTML button elements a type
The HTML button elements we use are all regular buttons that don't
submit form data to a server. According to
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#notes
those buttons should all have their type set to `button` explicitly, but
we only do that a handful of them. This commit fixes the issue by
consistently giving all our buttons the `button` type.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-07-30 18:49:18 +02:00
Calixte Denizet
16a66383bb [Editor] Add a checkerboard behind the image preview in the new alt-text dialog in order to see its potential transparency 2024-07-30 17:54:54 +02:00
calixteman
8f45374881
Merge pull request #18492 from calixteman/new_stamp_dialog
[Editor] Implement the new alt text flow (bug 1909604)
2024-07-30 10:25:02 +02:00
Tim van der Meij
7199c967e6
Merge pull request #18510 from timvandermeij/findbar-button
Improve how the findbar's toggle button is referenced in the viewer code
2024-07-29 20:33:04 +02:00
Tim van der Meij
f430a6bfd4
Improve how the findbar's toggle button is referenced in the viewer code
The sidebar and secondary toolbar both have a reference to their toggle
buttons in their own sections in `getViewerConfiguration`, so it makes
sense for the findbar to do the same.

While we actually have a findbar-specific reference to the toggle
button, I noticed that we don't use it consistently because the toolbar
also has a reference to the exact same toggle button and we use both in
the code. This is probably for historical reasons: the docstring in the
toolbar file indicates that the `viewFind` element is an input to the
component, but that option is never actually used in the code itself.

This commit fixes the issue by removing the toolbar-specific reference,
since it's not actually used (anymore) in the toolbar code, so that we
consistently use the findbar-specific reference everywhere.
2024-07-29 19:55:32 +02:00
Tim van der Meij
45e42cc6e4
Merge pull request #18509 from timvandermeij/globals
Remove the `globals` dependency
2024-07-29 19:16:38 +02:00
Tim van der Meij
7e3d56a308
Remove the globals dependency
This dependency got introduced in PR #10293, almost six years ago now,
because `eslint-plugin-mozilla` didn't work without it but also didn't
require it as a dependency itself.

However, nowadays `eslint-plugin-mozilla` works just fine without it,
and other dependencies that need it correctly require it themselves.
This can be seen using `npm ls globals`:

```
$ npm ls globals
pdf.js
├─┬ @babel/core@7.24.9
│ └─┬ @babel/traverse@7.25.0
│   └── globals@11.12.0
├─┬ @babel/preset-env@7.25.0
│ └─┬ @babel/plugin-transform-classes@7.25.0
│   └── globals@11.12.0
├─┬ eslint-plugin-unicorn@55.0.0
│ └── globals@15.8.0 deduped
├─┬ eslint@8.57.0
│ ├─┬ @eslint/eslintrc@2.1.4
│ │ └── globals@13.24.0
│ └── globals@13.24.0
└── globals@15.8.0
```

Further proof that `eslint-plugin-mozilla` (no longer) uses `globals` is
from a source code search in
https://searchfox.org/mozilla-central/search?q=globals&path=&case=false&regexp=false.
The only results for `eslint-plugin-mozilla` refer to a file named
`globals.js`, but the `globals` NPM package is not actually imported
anywhere.

Given this we should be able to safely get rid of this explicit
dependency on our end now.
2024-07-29 18:16:28 +02:00
Tim van der Meij
300e806efe
Merge pull request #18507 from Snuffleupagus/rm-PDFWorkerUtil
Remove `PDFWorkerUtil` and move its contents into `PDFWorker` instead
2024-07-29 17:45:51 +02:00
Calixte Denizet
ed22d934e5 Implement the new alt text flow (bug 1909604)
For the Firefox pdf viewer, we want to use AI to guess an alt-text when adding an image to a pdf.
For now the telemtry stuff is not implemented and will come soon.
In order to test it locally:
 - set enableAltText, enableFakeMLManager and enableUpdatedAddImage to true.
or in Firefox:
 - set browser.ml.enable, pdfjs.enableAltText and pdfjs.enableUpdatedAddImage to true.
2024-07-29 14:31:47 +02:00
Jonas Jenwald
c4fdb28573 Remove PDFWorkerUtil and move its contents into PDFWorker instead
This is possible thanks to features, i.e. private fields and in particular static initialization blocks, that didn't exist back when we started using classes in the code-base.
2024-07-29 11:22:43 +02:00
Tim van der Meij
582866ee50
Merge pull request #18506 from timvandermeij/updates
Update dependencies to the most recent versions
2024-07-28 19:56:54 +02:00
Tim van der Meij
100fafa9fb
Disable the WebDriver BiDi protocol for Chrome
This should avoid the timeouts and OOM issues we have on the Linux bot,
which started since PR #18473.
2024-07-28 17:37:11 +02:00
Tim van der Meij
b4f368c180
Upgrade eslint-plugin-unicorn to version 55.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v55.0.0
doesn't indicate any breaking changes that should impact us.
2024-07-28 17:26:49 +02:00
Tim van der Meij
69d3186745
Update dependencies to the most recent versions 2024-07-28 17:26:45 +02:00
Tim van der Meij
2eea0c8cf3
Merge pull request #18505 from Snuffleupagus/ci-rm-Node-21
Stop testing in Node.js 21 since it's reached end-of-life
2024-07-28 13:33:11 +02:00
Jonas Jenwald
70bc136ea6 Stop testing in Node.js 21 since it's reached end-of-life
According to https://github.com/nodejs/release?tab=readme-ov-file#end-of-life-releases Node.js 21 stopped being supported on 2024-06-01, which is almost two months ago now, hence it seems pointless to keep testing in that environment.
2024-07-28 13:15:43 +02:00
Tim van der Meij
0ef1132563
Merge pull request #18504 from Snuffleupagus/issue-18503
Ignore non-dictionary nodes when parsing StructTree data (issue 18503)
2024-07-28 13:06:08 +02:00
Jonas Jenwald
c4cd405a8f Ignore non-dictionary nodes when parsing StructTree data (issue 18503) 2024-07-28 12:08:44 +02:00
Tim van der Meij
6f9fc70926
Merge pull request #18481 from nicolo-ribaudo/fix-selection-with-links
Disable link annotations during text selection
2024-07-28 12:08:38 +02:00
Tim van der Meij
d3384c0e3c
Merge pull request #18501 from Snuffleupagus/AppOptions-init
Initialize all user-options upfront in AppOptions
2024-07-28 11:09:11 +02:00
Tim van der Meij
0ed4521ad5
Merge pull request #18502 from Snuffleupagus/base_factory-shorter-errors
Shorten the errors mentioning API parameters in `BaseCMapReaderFactory` and `BaseStandardFontDataFactory`
2024-07-27 20:48:39 +02:00
Jonas Jenwald
d116ab1a22 Shorten the errors mentioning API parameters in BaseCMapReaderFactory and BaseStandardFontDataFactory
The current error-messages also mention internal parameters, which an end-user obviously don't have to care about. So, let's try to avoid confusion here by only including the API parameters.
2024-07-27 16:54:54 +02:00
Jonas Jenwald
935d9047fc Initialize all user-options upfront in AppOptions
- Initialize all user-options upfront, to allow getting the options without having to check if they exist first. (This is easier to implement after PR 18475 landed.)

 - Move the user-options into a private field in `AppOptions`. (This code is old enough to pre-date general availability of that class feature.)

 - Move code/methods limited to GENERIC-builds into `AppOptions`.
2024-07-27 14:16:09 +02:00
Tim van der Meij
8378c40f4c
Merge pull request #18500 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-07-27 14:10:16 +02:00
Tim van der Meij
33d1506c50
Bump the stable version in pdfjs.config 2024-07-27 14:06:52 +02:00
Jonas Jenwald
3a21f03b07
Merge pull request #18495 from Snuffleupagus/AppOptions-setAll-EVENT_DISPATCH
Consistently dispatch events, if needed, when setting AppOptions
2024-07-27 10:55:58 +02:00
Jonas Jenwald
58c7b5b635 Consistently dispatch events, if needed, when setting AppOptions
Currently we'll only dispatch events, for the options that support it, when updating preferences. Since this could potentially lead to inconsistent behaviour, let's avoid any future surprises by *always* dispatching events regardless of how the relevant option is being changed.

Obviously we should then also dispatch events in `AppOptions.set`, and to avoid adding even more duplicated code this method is changed into a wrapper for `AppOptions.setAll`.
While this is technically a tiny bit less efficient I don't think it matters in practice, since outside of development- and debug-mode `AppOptions.set` is barely used.
2024-07-27 10:10:38 +02:00
calixteman
2efa3e460c
Merge pull request #18493 from calixteman/fix_utf16_alt_text
[Editor] Correctly save a non-ascii alt text
2024-07-24 19:59:22 +02:00
Calixte Denizet
c3065629ca [Editor] Correctly save a non-ascii alt text 2024-07-24 19:13:45 +02:00
Tim van der Meij
cb737512de
Merge pull request #18486 from Snuffleupagus/AppOptions-replace-locale
Replace the GENERIC-only "locale" with "localeProperties" in AppOptions
2024-07-23 15:50:29 +02:00
Tim van der Meij
1c65ad3adc
Merge pull request #18483 from timvandermeij/streamqueue
Remove the `streamqueue` dependency
2024-07-23 15:46:51 +02:00
Nicolò Ribaudo
64a0e59662
Disable link annotations during text selection
When selecting text, hovering over an element
causes all the text between (according the the dom
order) the current selection and that element to
be selected.

This means that when, while selecting, the cursor
moves over a link, all the text in the page gets
selected. Setting `user-select: none` on the link
annotations would improve the situation, but it
still makes it impossible to extend the selection
within a link without using Shift+arrows keys on
the keyboard.

This commit fixes the problem by setting
`pointer-events: none` on the `<section>`s in the
annotation layer while selecting some text. This
way, they are ignored for hit-testing and do not
affect selection.

It is still impossible to _start_ a selection
inside a link, as the link text is covered by the
link annotation.

Fixes #18266
2024-07-23 10:42:34 +02:00
calixteman
33493301b3
Merge pull request #18484 from calixteman/bug1909310
Add a pref to know if the alt-text must be automatically generated (bug 1909310)
2024-07-23 10:02:03 +02:00
Jonas Jenwald
7ebfad6d92 Replace the GENERIC-only "locale" with "localeProperties" in AppOptions
Since "localeProperties" is needed in Firefox, let's remove a tiny bit of option duplication by using it in the GENERIC builds as well.
For convenience, the old debug-only "locale" hash-parameter is kept intact.
2024-07-23 09:51:32 +02:00
Calixte Denizet
042183b89b Add a pref to know if the alt-text must be automatically generated (bug 1909310) 2024-07-22 23:10:25 +02:00
Tim van der Meij
1b9981cd92
Remove the streamqueue dependency
The `streamqueue` dependency is only used for the test targets in the
Gulpfile to make sure that the test types are run in series. This is
done by modelling the test processes as readable streams and then having
`streamqueue` combine them into a single readable stream for Gulp that
processes the inner readable streams in series (in contrast to the
`ordered-read-streams` dependency which is very similar but processes
the inner streams in parallel).

However, modelling the test processes as readable streams is a bit odd
because we're not actually streaming any data as one might expect.
Instead, we only use them to signal test process completion/abortion.

Fortunately nowadays, with modern Gulp versions, we don't need readable
streams and `streamqueue` anymore because we can achieve the same result
with simple asynchronous functions that can be passed to e.g.
`gulp.series()` calls. Note that we already do this in various places,
and overall it should be a better fit for test process invocations.
2024-07-22 20:27:31 +02:00
Tim van der Meij
5184a38e3d
Merge pull request #18480 from Snuffleupagus/AppOptions-optional-type
Add better support for AppOptions with multiple types (PR 18465 follow-up)
2024-07-22 18:10:29 +02:00
Jonas Jenwald
b3ea789286 Add better support for AppOptions with multiple types (PR 18465 follow-up)
For options with varying types, see `useSystemFonts`, we're not sufficiently validating the type when setting a new value. This means that for an option that uses `OptionKind.UNDEF_ALLOWED` we'd allow *any* value, which is obviously not the intention.

Hence we instead introduce a new and *optional* `type`-field that allows specifying exactly which types are valid when multiple ones are supported.

*Note:* This obviously didn't occur to me until after PR 18465 landed, sorry about that!
2024-07-22 17:58:21 +02:00
Tim van der Meij
deaac2839e
Merge pull request #18476 from Snuffleupagus/viewer-mv-docBaseUrl
Re-factor how the "docBaseUrl" API-option is set in the viewer
2024-07-22 17:29:18 +02:00
calixteman
91655aae7f
Merge pull request #18467 from calixteman/issue18466
Use a transparent color when setting fill/stroke colors in a pattern context but with no colorspace
2024-07-22 12:23:57 +02:00
Calixte Denizet
482994cc04 Use a transparent color when setting fill/stroke colors in a pattern context but with no colorspace 2024-07-22 09:56:10 +02:00
Jonas Jenwald
12e083f60d Re-factor how the "docBaseUrl" API-option is set in the viewer
This option is old enough that it predates e.g. the introduction of AppOptions, so it probably cannot hurt to re-factor this a little bit now.

 - In development-mode we can just set this directly in AppOptions.

 - In the extension-builds we still need to set it dynamically, however by moving this code we get the benefit of being able to avoid storing a data-URL in that case; note how [the API ignores those anyway](98e772727e/src/display/api.js (L256-L262)).
2024-07-21 22:07:52 +02:00
Tim van der Meij
98e772727e
Merge pull request #18475 from Snuffleupagus/rm-AppOptions-remove
Remove the unused `AppOptions.remove` method
2024-07-21 21:28:52 +02:00
calixteman
422b3e4a4a
Merge pull request #18468 from calixteman/dont_throw_with_invalid_cs
Fallback on DeviceGray when a colorspace cannot be parsed
2024-07-21 20:53:46 +02:00
calixteman
998bc07375
Merge pull request #18472 from calixteman/bug1908939
Add the possibility to delete a model (bug 1908939)
2024-07-21 20:53:08 +02:00
Jonas Jenwald
d9ff29a46b Remove the unused AppOptions.remove method
This method has *never* been used anywhere in the code-base, so I really don't know why I added it originally.
2024-07-21 19:26:15 +02:00
Calixte Denizet
71bae38afb Fallback on DeviceGray when a colorspace cannot be parsed 2024-07-21 17:56:31 +02:00
Tim van der Meij
0c34efbef9
Merge pull request #18465 from Snuffleupagus/issue-18210
Disable system fonts on Android (issue 18210)
2024-07-21 17:53:49 +02:00
Calixte Denizet
b759470ed5 Add the possibility to delete a model (bug 1908939) 2024-07-21 17:09:41 +02:00
calixteman
d0b580e79f
Merge pull request #18471 from calixteman/bug1909097
Add a pref containing the url for the sumo page about alt text (bug 1909097)
2024-07-21 17:07:29 +02:00
Calixte Denizet
5860c7bcc9 Add a pref containing the url for the sumo page about alt text (bug 1909097) 2024-07-21 16:55:26 +02:00
Jonas Jenwald
80d6bf6319 Disable system fonts on Android (issue 18210)
To avoid introducing any inline "hacks" in the viewer-code this meant adding `useSystemFonts` to the AppOptions, which thus required some new functionality since the default value should be `undefined` given how the option is handled in the API; note [this code](ed83d7c5e1/src/display/api.js (L298-L301)).

Finally, also moves the definition of the development-mode `window.isGECKOVIEW` property to the HTML file such that it's guaranteed to be set regardless of how and when it's accessed.
2024-07-21 15:28:16 +02:00
Jonas Jenwald
45ce3a057f Use shorter local variable names in a few AppOptions methods
Besides being slightly shorter, this should help reduce the risk of confusion given the very similar global Object/Map names.
2024-07-21 15:27:43 +02:00
Tim van der Meij
ebb3d27125
Merge pull request #18469 from Snuffleupagus/AppOptions-Maps
Introduce some `Map`-usage in the AppOptions
2024-07-21 14:47:29 +02:00
Tim van der Meij
9f62c0f139
Merge pull request #18470 from Snuffleupagus/move-Preferences-init
Move the `Preferences` initialization as early as possible
2024-07-21 14:40:07 +02:00
Jonas Jenwald
f8aa15aae9 Move the Preferences initialization as early as possible
Given that the entire default viewer initialization depends on the preferences being available, try to do this as early as possible.
2024-07-21 13:42:31 +02:00
Jonas Jenwald
26989fdf24 Add basic validation of the AppOptions BROWSER-kind 2024-07-21 09:32:36 +02:00
Jonas Jenwald
7bd920691f Change the userOptions, used with AppOptions, to a Map
This is needed for upcoming changes, and simplifies both checking if an entry exists and iteration of the entries.
2024-07-21 09:27:23 +02:00
Jonas Jenwald
57ee035573 Change the compatibilityParams, used with AppOptions, to a Map
This is needed for upcoming changes, and simplifies both checking if an entry exists and iteration of the entries.
2024-07-21 09:27:05 +02:00
Tim van der Meij
e92a6a14ff
Merge pull request #18450 from Snuffleupagus/AppOptions-set-validation
Add more validation when setting `AppOptions` (PR 18413 follow-up)
2024-07-20 19:11:54 +02:00
Tim van der Meij
7a8aceef20
Merge pull request #18463 from Snuffleupagus/app-rm-downloadComplete
Re-factor the code to remove all uses of `PDFViewerApplication.downloadComplete`
2024-07-20 18:11:32 +02:00
Tim van der Meij
9db1ae4da5
Merge pull request #18464 from Snuffleupagus/setTitleUsingUrl-url-fallback
Reduce a tiny bit of duplication in `PDFViewerApplication.setTitleUsingUrl`
2024-07-20 18:04:47 +02:00
Jonas Jenwald
482d6211aa Reduce a tiny bit of duplication in PDFViewerApplication.setTitleUsingUrl
Rather than repeating code, we can always fallback to the raw URL instead.
2024-07-20 10:19:45 +02:00
Jonas Jenwald
64a4f0dc7e Avoid downloading the document twice in PDFViewerApplication.download
The old implementation in `PDFViewerApplication.download` means that if the `getDocument`-call hasn't yet downloaded the *entire* PDF document it will be re-downloaded. This seems generally undesirable since:
 - In some (probably rare) cases a URL may not be valid an arbitrary number of times, which means that the download may fail.
 - It will lead to wasted resources, since we'll end up fetching the same PDF document *twice* in that case (once via the `getDocument`-call and once to allow the user to save it).

Hence this patch suggests that we change this very old code to instead always call the `PDFDocumentProxy.getData` method, since that'll trigger immediate downloading of the remaining document via the existing `getDocument`-call.

Finally, the patch removes the `PDFViewerApplication.downloadComplete` property since it's now unused.
2024-07-20 09:57:33 +02:00
Jonas Jenwald
006242489d Stop using downloadComplete in PDFViewerApplication.progress
This was only necessary to prevent (unlikely) visual glitches when `disableAutoFetch = true` is being used.
However, it turns out that we can move this functionality into the `ProgressBar` class instead by checking if the entire PDF document has loaded. This works since the API is always reporting 100% loading progress regardless of how the document was loaded; see [this code](ed83d7c5e1/src/display/api.js (L2735-L2740)).
2024-07-20 09:27:43 +02:00
Jonas Jenwald
216d3a9faf Add more validation when setting AppOptions (PR 18413 follow-up)
After the changes in PR 18413 we're now relying even more on `AppOptions` and it thus seems like a good idea to ensure that no invalid values can be added.
Hence the `AppOptions.{set, setAll}` methods will now *unconditionally* validate that the type of the values agree with the default-options.
2024-07-20 08:53:55 +02:00
calixteman
ed83d7c5e1
Merge pull request #18461 from calixteman/bug1908938
Load the image-to-text model when opening the pdf viewer in Firefox (bug 1908938)
2024-07-19 23:08:50 +02:00
Calixte Denizet
b71fa727e1 Load the image-to-text model when opening the pdf viewer in Firefox (bug 1908938) 2024-07-19 21:57:46 +02:00
calixteman
5b0e15ab18
Merge pull request #18454 from calixteman/setpref_event
[Editor] Allow to change a preference from the editor UI manager
2024-07-18 15:54:45 +02:00
Calixte Denizet
5946d20dc9 [Editor] Allow to change a preference from the editor UI manager
We want to be able to update a global pref (i.e. enableAltText) in using a toggle button in the new alt-text dialog.
2024-07-18 15:12:39 +02:00
Jonas Jenwald
5be66580e6
Merge pull request #18448 from Snuffleupagus/AppOptions-more-browser-params
Include additional data when fetching browser preferences in the PDF Viewer (bug 1908401)
2024-07-18 14:19:50 +02:00
Jonas Jenwald
31f247fe43
Merge pull request #18453 from Snuffleupagus/issue-18408
Allow /XYZ destinations without zoom parameter (issue 18408)
2024-07-18 13:32:51 +02:00
Jonas Jenwald
d24a61c648 Allow /XYZ destinations without zoom parameter (issue 18408)
According to the PDF specification these destinations should have a zoom parameter, which may however be `null`, but it shouldn't be omitted; please see https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G11.2095870

Hence we try to work-around bad PDF generators by making the zoom parameter optional when validating explicit destinations in both the worker and the viewer.
2024-07-18 13:29:32 +02:00
calixteman
e1f64a5b3e
Merge pull request #18449 from calixteman/bug1908483
Add the possibility to change some pdfjs preferences from the viewer (bug 1908483)
2024-07-18 10:19:50 +02:00
Calixte Denizet
6cc32b699f Add the possibility to change some pdfjs preferences from the viewer (bug 1908483) 2024-07-18 09:52:10 +02:00
Jonas Jenwald
99f34f4c2e Include additional data when fetching browser preferences in the PDF Viewer (bug 1908401)
To avoid having to request and await various browser data early during the PDF Viewer initialization, we can include that data in the existing preference fetching instead. With other planned changes to the PDF Viewer, the current situation would only become worse over time.

*Note:* Technically this data aren't preference-values, however we're already including other non-prefs in this list (e.g. `isInAutomation`) and doing it this way simplifies the overall implementation.
2024-07-17 16:57:55 +02:00
calixteman
15b71b82ed
Merge pull request #18445 from calixteman/issue18444
Remove active smask when restoring the initial canvas state
2024-07-17 15:36:04 +02:00
Calixte Denizet
37db3a7143 Remove active smask when restoring the initial canvas state
Fixes #18444.
2024-07-17 14:20:50 +02:00
Jonas Jenwald
86eb5ba700
Merge pull request #18441 from Snuffleupagus/api-rm-Outliner
[api-minor] Remove `Outliner` from the official API
2024-07-16 14:32:07 +02:00
calixteman
e190cebf92
Merge pull request #18440 from calixteman/fix_add_highlight
[Editor] When in non-editing mode, add a new editor only once the editing mode has switched
2024-07-16 13:50:40 +02:00
Jonas Jenwald
8a979c2d0e [api-minor] Remove Outliner from the official API
As far as I can tell `Outliner` is only exposed in the API because we need to access it when running some of the reference-tests, but is otherwise not used.
Hence this seems like something that should be kept *internal* and thus only exposed in TESTING-builds.
2024-07-16 13:08:26 +02:00
Calixte Denizet
6dd75c0e62 [Editor] When in non-editing mode, add a new editor only once the editing mode has switched
Switching to an editing mode can be asynchronous (e.g. if an editable annotation exists on a
visible page), so we must add a new editor only when the page rendering is done.
2024-07-15 21:04:52 +02:00
Jonas Jenwald
f9e3b6bcc4
Merge pull request #18430 from Snuffleupagus/pr-18417-followup
Fix `DOMFilterFactory.#createUrl` in MOZCENTRAL builds (18417 PR follow-up)
2024-07-15 15:05:35 +02:00
Jonas Jenwald
4c45948bc4 Fix DOMFilterFactory.#createUrl in MOZCENTRAL builds (18417 PR follow-up)
Somehow I managed to mess up the URL creation relevant to e.g. MOZCENTRAL builds, which is breaking the pending PDF.js update in mozilla-central; sorry about that!

To avoid future issues, we'll now always check if absolute filter-URLs are necessary regardless of the build-target.
2024-07-15 14:10:59 +02:00
calixteman
87e74a753b
Merge pull request #18429 from calixteman/bug1907207
[Editor] Add an option to use the new 'add an image' flow (bug 1907207)
2024-07-15 13:58:08 +02:00
Tim van der Meij
5059187fff
Merge pull request #18434 from timvandermeij/pdfjs-dist
Remove obsolete `pdfjs-dist` code from the Gulpfile
2024-07-13 20:28:30 +02:00
Tim van der Meij
08967a5cd3
Merge pull request #18433 from timvandermeij/contile
Disable network connections to Contile for the tests
2024-07-13 20:28:07 +02:00
Tim van der Meij
1c5c5da12e
Remove obsolete pdfjs-dist code from the Gulpfile
The Git logic for pushing to the `pdfjs-dist` repository was already
removed in PR #18350, but it was forgotten to also remove the logic to
create a Git repository in the first place. This commit fixes the open
action for that from
https://github.com/mozilla/pdf.js/pull/18358#discussion_r1661367441.

Moreover, we implement the suggestion from
https://github.com/mozilla/pdf.js/pull/18358#discussion_r1661364026
about moving the Git URL to a separate variable for consistency and we
update the homepage URL to the HTTPS scheme to avoid an HTTP -> HTTPS
redirect and enforce TLS-encrypted connections.
2024-07-13 19:49:28 +02:00
Tim van der Meij
aea409d8cb
Disable network connections to Contile for the tests
In PR #18356 the new tab page logic was disabled to prevent Firefox
from logging failed network connections to Contile, the Mozilla Tiles
service that is used for the new tab page [1]. However, recently this
log reappeared locally and on the bots:

```
console.warn: TopSitesFeed: Failed to fetch data from Contile server:
NetworkError when attempting to fetch resource.
```

It looks like Contile communication is also triggered from other places
in Firefox such as the URL bar [2], so this commit fixes the issue by
disabling network connections to Contile [3] altogether regardless of
their origin within Firefox. Note that we don't revert the change from
PR #18356 because as noted in [4] it can't hurt to keep that disabled
too to avoid overhead for a feature we don't use in the tests.

[1] https://github.com/mozilla-services/contile
[2] 196ef8360e/browser/components/urlbar/UrlbarProviderTopSites.sys.mjs (L38)
[3] 196ef8360e/browser/components/newtab/lib/TopSitesFeed.sys.mjs (L111)
[4] https://github.com/mozilla/pdf.js/pull/18356#issuecomment-2200354730
2024-07-13 18:29:32 +02:00
Tim van der Meij
07c58aa23a
Merge pull request #18432 from timvandermeij/updates
Update dependencies to the most recent versions and update the JS/CSS files for the new Prettier/Stylelint versions
2024-07-13 17:35:05 +02:00
Tim van der Meij
c77b97daff
Update the JS/CSS files for the new Prettier/Stylelint versions 2024-07-13 16:29:47 +02:00
Tim van der Meij
49eba2f892
Update dependencies to the most recent versions 2024-07-13 16:06:32 +02:00
Calixte Denizet
dfccc8ffd9 [Editor] Add an option to use the new 'add an image' flow (bug 1907207)
UX team designed in a new flow we'll implement soon and we want to be able to
make an experiment to be able to compare current flow vs the new one.
2024-07-12 16:28:48 +02:00
calixteman
2d254375a8
Merge pull request #18424 from calixteman/avoid_hovering_when_selecting
[Editor] Disable existing highlights when drawing a new one (bug 1879035)
2024-07-12 09:22:18 +02:00
Calixte Denizet
4e7c30da9a [Editor] Disable existing highlights when drawing a new one (bug 1879035)
When the mouse was hovering an existing highlight, all the text in the page
was selected.
So when the user is selecting some text or drawing a free highlight, the mouse
is disabled for the existing editors.
2024-07-11 21:34:28 +02:00
calixteman
df5bc544df
Merge pull request #18425 from calixteman/bug1879104
[Editor] Make editor toolbars usable whatever their z-index (bug 1879104)
2024-07-11 19:03:03 +02:00
Calixte Denizet
9a64749dbe [Editor] Make editor toolbars usable whatever their z-index (bug 1879104)
Because of editor z-index, the toolbar belonging to an highlight created
before a second adjacent one, can be overlapped by this new one.
So when the user select an editor we just show it on front of all the other
ones to make sure that it can be used normally.
2024-07-11 18:00:42 +02:00
Jonas Jenwald
acc70ce0b7
Merge pull request #18423 from Snuffleupagus/rm-setZoomDisabledTimeout
Remove the remaining `zoomDisabledTimeout` usage (issue 17727)
2024-07-11 13:41:57 +02:00
Jonas Jenwald
8082c2daf1
Merge pull request #18417 from Snuffleupagus/DOMFilterFactory-baseUrl
Create absolute filter-URLs when needed in `DOMFilterFactory` (issue 18406)
2024-07-11 12:25:16 +02:00
Jonas Jenwald
6b47ddd4d5 Remove the remaining zoomDisabledTimeout usage (issue 17727)
With https://bugzilla.mozilla.org/show_bug.cgi?id=1882168 now marked as fixed by the landing of https://bugzilla.mozilla.org/show_bug.cgi?id=1902017 we should *hopefully* be able to remove this work-around.
2024-07-11 12:17:41 +02:00
Jonas Jenwald
50a5a15088 Create absolute filter-URLs when needed in DOMFilterFactory (issue 18406)
This functionality is purposely limited to development mode and GENERIC builds, since it's unnecessary in e.g. the *built-in* Firefox PDF Viewer, and will only be used when a `<base>`-element is actually present.

*Please note:* We also have tests in mozilla-central that will *indirectly* ensure that relative filter-URLs work as intended in the Firefox PDF Viewer, see https://searchfox.org/mozilla-central/source/toolkit/components/pdfjs/test/browser_pdfjs_filters.js

---

To test that the issue is fixed, the following code can be used:

```html
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <base href=".">
  <title>base href (issue 18406)</title>
</head>
<body>

<ul>
  <li>Place this code in a file, named `base_href.html`, in the root of the PDF.js repository</li>
  <li>Run <pre>npx gulp dist-install</pre></li>
  <li>Run <pre>npx gulp server</pre></li>
  <li>Open <a href="http://localhost:8888/base_href.html">http://localhost:8888/base_href.html</a> in a browser</li>
  <li>Compare rendering with <a href="http://localhost:8888/web/viewer.html?file=/test/pdfs/issue16287.pdf">http://localhost:8888/web/viewer.html?file=/test/pdfs/issue16287.pdf</a></li>
</ul>

<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>

<script src="/node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>

<script id="script" type="module">
  //
  // If absolute URL from the remote server is provided, configure the CORS
  // header on that server.
  //
  const url = '/test/pdfs/issue16287.pdf';

  //
  // The workerSrc property shall be specified.
  //
  pdfjsLib.GlobalWorkerOptions.workerSrc =
    '/node_modules/pdfjs-dist/build/pdf.worker.mjs';

  //
  // Asynchronous download PDF
  //
  const loadingTask = pdfjsLib.getDocument(url);
  const pdf = await loadingTask.promise;
  //
  // Fetch the first page
  //
  const page = await pdf.getPage(1);
  const scale = 1.5;
  const viewport = page.getViewport({ scale });
  // Support HiDPI-screens.
  const outputScale = window.devicePixelRatio || 1;

  //
  // Prepare canvas using PDF page dimensions
  //
  const canvas = document.getElementById("the-canvas");
  const context = canvas.getContext("2d");

  canvas.width = Math.floor(viewport.width * outputScale);
  canvas.height = Math.floor(viewport.height * outputScale);
  canvas.style.width = Math.floor(viewport.width) + "px";
  canvas.style.height = Math.floor(viewport.height) + "px";

  const transform = outputScale !== 1
    ? [outputScale, 0, 0, outputScale, 0, 0]
    : null;

  //
  // Render PDF page into canvas context
  //
  const renderContext = {
    canvasContext: context,
    transform,
    viewport,
  };
  page.render(renderContext);
</script>

</body>
</html>
```
2024-07-11 11:30:45 +02:00
calixteman
9b1b5ff7e7
Merge pull request #18419 from calixteman/reuse_old_dict_when_updating
[Editor] Update the freetext annotation dictionary instead of creating a new one when updating an existing freetext
2024-07-11 11:24:15 +02:00
Jonas Jenwald
e8d35c25ee
Merge pull request #18412 from Snuffleupagus/issue-18059
Also update the width/unicode data when replacing missing glyphs in non-embedded Type1 fonts (issue 18059)
2024-07-11 10:52:17 +02:00
Jonas Jenwald
b56e4209a9
Merge pull request #18421 from Snuffleupagus/bug-1907000
Allow e.g. /FitH destinations without additional parameter (bug 1907000)
2024-07-11 10:51:44 +02:00
Calixte Denizet
6711123f68 [Editor] Update the freetext annotation dictionary instead of creating a new one when updating an existing freetext 2024-07-11 10:44:21 +02:00
Jonas Jenwald
403d023617 Allow e.g. /FitH destinations without additional parameter (bug 1907000)
According to the PDF specification these destinations should have a coordinate parameter, which may however be `null`, but it shouldn't be omitted; please see https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G11.2095870

Hence we try to work-around bad PDF generators by making the coordinate parameter optional when validating explicit destinations in both the worker and the viewer.
2024-07-11 10:36:44 +02:00
Tim van der Meij
cf58113e8c
Merge pull request #18416 from razh/ensureMinimumFontSize-body-flex
Fix `ensureMinFontSizeComputed` calculation if `<body>` is a flex container
2024-07-10 16:17:26 +02:00
razh
665fff020e Fix ensureMinFontSizeComputed calculation if <body> is a flex container
Given:

```css
html,
body {
  height: 100%;
}

body {
  display: flex;
}
```

The `<div>` appended to the `<body>` will take up the full height of the
viewport due to the implicit `align-items: stretch` of flex containers.

This results in an incorrect computed `minFontSize` value.
2024-07-10 08:41:09 -04:00
calixteman
b1bf8b4979
Merge pull request #18418 from calixteman/wait_for_rendering
[Editor] Wait for 'pagerendered' to switch to editing mode
2024-07-10 12:18:21 +02:00
Calixte Denizet
d27efb43cd [Editor] Wait for 'pagerendered' to switch to editing mode
The focus can potentially be stolen when the DOM is modified when adding
a new canvas element for the page being redrawn.
2024-07-10 11:29:42 +02:00
Tim van der Meij
7ffea2f02a
Merge pull request #18413 from Snuffleupagus/BasePreferences-AppOptions-wrapper
Re-factor `BasePreferences` to essentially be a wrapper around `AppOptions`
2024-07-09 23:09:09 +02:00
Jonas Jenwald
d9f0ec0b87 Re-factor BasePreferences to essentially be a wrapper around AppOptions
In the MOZCENTRAL build the `BasePreferences` class is almost unused, since it's only being used to initialize and update the `AppOptions` which means that theoretically we could move the relevant code there.
However for the other build targets (e.g. GENERIC and CHROME) we still need to keep the `BasePreferences` class, although we can re-factor things to move the necessary validation inside of `AppOptions` and thus simplify the code and reduce duplication.

The patch also moves the event dispatching, for changed preference values, into `AppOptions` instead.
2024-07-09 22:49:59 +02:00
Jonas Jenwald
56653e5770 Also update the width/unicode data when replacing missing glyphs in non-embedded Type1 fonts (issue 18059)
*Please note:* This causes a little bit of movement in the `issue2770` test-case, however this matches the rendering in both Adobe Reader and PDFium.
2024-07-09 09:41:01 +02:00
Jonas Jenwald
f9d63201eb Revert "Remove the unused Font.prototype.spaceWidth getter (PR 13424 follow-up)"
This reverts commit 4aee67227e3c5b28f1bb4d8fa6b2ad882bc23b5a.
2024-07-09 09:28:10 +02:00
Jonas Jenwald
7ffa9a283d Extend test-coverage for non-embedded Type1 fonts where .notdef glyphs are replaced with spaces 2024-07-09 09:12:09 +02:00
Tim van der Meij
1bdd6920ff
Merge pull request #17962 from calixteman/chrome_bidi
Use BiDi protocol for Chrome tests
2024-07-07 22:07:29 +02:00
Calixte Denizet
5bfe759574 Use BiDi protocol for Chrome tests 2024-07-07 17:12:00 +02:00
calixteman
2a125bd0f0
Merge pull request #18405 from timvandermeij/intermittent-waitforscripting
Introduce a `waitForScripting` helper function and use it in all scripting integration tests
2024-07-07 14:13:32 +02:00
Tim van der Meij
b540b6333f
Introduce a waitForScripting helper function and use it in all scripting integration tests
Code inspection uncovered that quite a few integration tests don't wait
for scripting to be ready before proceeding, which is a source of
intermittent failures, especially on slower machines where e.g. creating
the sandbox takes longer.

This commit fixes the issues by introducing a `waitForScripting` helper
function and calling it consistently in all scripting integration tests.
2024-07-06 19:29:45 +02:00
Jonas Jenwald
5ee61690f3
Merge pull request #18390 from alexcat3/fix-issue-18099
Handle toUnicode cMaps that omit leading zeros in hex encoded UTF-16 (issue 18099)
2024-07-06 18:57:07 +02:00
Tim van der Meij
145951df88
Merge pull request #18404 from timvandermeij/fix-unit-intermittent
Fix the "caches image resources at the document/page level as expected (issue 11878)" unit test
2024-07-06 17:32:55 +02:00
alexcat3
1c364422a6 Handle toUnicode cmaps that omit leading zeros in hex encoded UTF-16 (issue 18099)
Add unit test to check compatability with such cmaps

In the PDF in issue 18099. the toUnicode cmap had a line to map the glyph char codes from 00 to 7F to the corresponding code points. The syntax to map a range of char codes to a range of unicode code points is
<start_char_code> <end_char_code> <start_unicode_codepoint>
As the unicode code points are supposed to be given in UTF-16 BE, the PDF's line SHOULD have probably read
<00> <7F> <0000>
Instead it omitted two leading zeros from the UTF-16 like this
<00> <7F> <00>
This confused PDF.js into mapping these character codes to the UTF-16 characters with the corresponding HIGH bytes (01 became \u0100, 02 became \u0200, et cetera), which ended up turning latin text in the PDF into chinese when it was copied
I'm not sure if the PDF spec actually allows PDFs to do this, but since there's at least one PDF in the wild that does and other PDF readers read it correctly, PDF.js should probably support this
2024-07-06 11:29:21 -04:00
Tim van der Meij
2a44203d96
Fix the "caches image resources at the document/page level as expected (issue 11878)" unit test
This unit test fails occasionally (albeit much less than before thanks
to PR #17663), so we change the parsing time check's divisor to prevent
it from happening again. If the last page's rendering time is less than
or equal to 50% of the first page's rendering time that should be enough
proof that no worker thread re-parsing occurred while also providing a
wide enough range to avoid intermittents.

Note that the assertion is now equal to the one we already have in the
"caches image resources at the document/page level, with main-thread
copying of complex images (issue 11518)" unit test which seems to work
reliably so far.
2024-07-06 16:30:07 +02:00
Tim van der Meij
bb3e3164e6
Merge pull request #18402 from Snuffleupagus/updatedPreference-move-listener
Move the "updatedPreference" event listener registration
2024-07-06 15:54:14 +02:00
Tim van der Meij
fe692435d3
Merge pull request #18401 from timvandermeij/test-orphaned-browsers
Fix orphaned browser processes due to uncaught exceptions in the tests
2024-07-06 15:43:26 +02:00
Jonas Jenwald
9e352a8bad Move the "updatedPreference" event listener registration
This patch fixes a situation that'll probably never happen, but nonetheless seems like something that we should address.
Currently the "updatedPreference" listener isn't registered *until after* the preferences have been read and initialized, which leaves a very short window of time where a preference change could theoretically be skipped.
2024-07-06 15:28:03 +02:00
Tim van der Meij
3afe2d3048
Fix orphaned browser processes due to uncaught exceptions in the tests
If uncaught exceptions occur in the tests (which happened in #17962 and
can be triggered manually by throwing an error in `integration-boot.js`)
the teardown logic of the tests doesn't get to run and thus spawned
browser processes are not closed properly. Given that `test.mjs` is the
only process that has a reference to them they will become orphaned and
keep running if `test.mjs` exits without explicitly closing them.

This commit fixes the issue by always closing the browsers if uncaught
exceptions occur, and we make sure to log them for debugging purposes.
2024-07-06 15:07:54 +02:00
calixteman
db9115625b
Merge pull request #18398 from calixteman/bug1905923
[Editor] Change the enableML pref for enableAltText (bug 1905923)
2024-07-05 22:51:15 +02:00
Tim van der Meij
7a5f5616f4
Merge pull request #18399 from timvandermeij/intermittent-charlimit
Fix the "must check that charLimit is correctly set" scripting integration test
2024-07-05 21:58:04 +02:00
calixteman
9f001058c3
Merge pull request #18397 from calixteman/toolbar_density
Allow to change the toolbar height when changing the pref toolbar.density in Firefox (bug 1171799)
2024-07-05 21:50:10 +02:00
Tim van der Meij
70b44251ed
Fix the "must check that charLimit is correctly set" scripting integration test
This integration test fails intermittently because we're not (correctly)
awaiting the character limit increase sandbox action.

For the first increase an attempt was made to handle this, but it doesn't
work correctly because the text in the field is `abcdefghijklmnopq` and
it's not be truncated until the sandbox action is completed, so because
we didn't await that we would could pass the `value !== "abcdefgh"` check
because `abcdefghijklmnopq !== abcdefgh` is true. For the second increase
we didn't have a check in place.

This commit fixes the issues by using the `waitForSandboxTrip` and
`waitForSelector` helper functions to make sure that we can only proceed
if the sandbox action is completed and the DOM element is updated.
2024-07-05 21:15:44 +02:00
Calixte Denizet
0fba6e570e [Editor] Change the enableML pref for enableAltText (bug 1905923)
We want to use this pref to make a Nimbus experiment in the next weeks.
2024-07-05 21:01:12 +02:00
Calixte Denizet
0910f17a58 Allow to change the toolbar height when changing the pref toolbar.density in Firefox (bug 1171799)
It's a first step to just dispatch the pref change to the toolbar.
The second one, to effectively use it, will come after PR #18385 is merged.
2024-07-05 18:59:29 +02:00
calixteman
e777ae2258
Merge pull request #18380 from calixteman/avoid_dbl_ml_queries
[Editor] Avoid to query ML engine several times for the same image
2024-07-05 17:44:31 +02:00
Tim van der Meij
ccb141e211
Merge pull request #18393 from Snuffleupagus/mustBeViewedWhenEditing-params
Check the relevant parameters inside of the `mustBeViewedWhenEditing` method
2024-07-05 15:33:45 +02:00
Tim van der Meij
cf9dfbc084
Merge pull request #18394 from Snuffleupagus/rm-annotation-getOperatorList-renderForms
Remove the `renderForms` parameter from the Annotation `getOperatorList` methods
2024-07-05 15:30:52 +02:00
Calixte Denizet
5274bab9f3 [Editor] Avoid to query ML engine several times for the same image 2024-07-05 13:43:11 +02:00
Jonas Jenwald
38528d1116 Remove the renderForms parameter from the Annotation getOperatorList methods
The `renderForms` parameter pre-dates the introduction of the general `intent` parameter, which means that we're now effectively passing the same state twice to these `getOperatorList` methods.
2024-07-05 12:25:18 +02:00
Jonas Jenwald
5f744904ac Check the relevant parameters inside of the mustBeViewedWhenEditing method
Similar to the `mustBeViewed` method, we can check the relevant parameters within the `mustBeViewedWhenEditing` method itself since that (in my opinion) slightly helps readability of the code in the `src/core/document.js` file.
2024-07-05 11:38:55 +02:00
Tim van der Meij
9065ee465b
Merge pull request #18387 from Snuffleupagus/RenderingIntentFlag-IS_EDITING
Move the internal API/Worker `isEditing`-state into `RenderingIntentFlag`
2024-07-04 23:42:44 +02:00
Jonas Jenwald
a4ffc1066c Move the internal API/Worker isEditing-state into RenderingIntentFlag
In *hindsight* this seems like a better idea, since it avoids the need to manually pass `isEditing` around as a boolean value.
Note that `RenderingIntentFlag` is *internal* functionality, not exposed in the official API, which means that it can be extended and modified as necessary.
2024-07-04 23:34:30 +02:00
calixteman
8c5b0191cf
Merge pull request #18389 from calixteman/remove_pref_stamp
[Editor] Remove the option enableStamp
2024-07-04 23:06:42 +02:00
Calixte Denizet
74cbfbd09f [Editor] Remove the option enableStamp 2024-07-04 22:01:35 +02:00
Tim van der Meij
790470c1aa
Merge pull request #18383 from calixteman/fix_print_test
Fix the integration tests related to printing
2024-07-04 11:34:06 +02:00
Tim van der Meij
03a0500dcf
Merge pull request #18374 from calixteman/test_editor_visible
Make sure the editor is visible before getting its rect
2024-07-04 11:14:27 +02:00
Calixte Denizet
53ddfd139f Fix the integration tests related to printing 2024-07-04 11:12:31 +02:00
Tim van der Meij
944f3acecd
Merge pull request #18367 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-07-04 11:12:25 +02:00
Jonas Jenwald
396231b90c
Merge pull request #15209 from Snuffleupagus/createDefaultPrefsFile
[Firefox] Generate a PDF.js default-prefs file that can be used directly in mozilla-central (bug 1905864)
2024-07-04 11:06:48 +02:00
calixteman
617f513806
Merge pull request #18369 from calixteman/bug1905623
Use vertical variant of a char when it's in a missing vertical font (bug 1905623)
2024-07-04 09:45:43 +02:00
Calixte Denizet
fd6d0be50f Make sure the editor is visible before getting its rect 2024-07-03 09:57:12 +02:00
Calixte Denizet
832fc93aa4 Use vertical variant of a char when it's in a missing vertical font (bug 1905623) 2024-07-03 09:46:54 +02:00
Tim van der Meij
4e8a015a78
Update translations to the most recent versions 2024-07-02 18:29:19 +02:00
Tim van der Meij
bb54e7e64c
Update dependencies to the most recent versions 2024-07-02 18:20:49 +02:00
Tim van der Meij
ccad2f889a
Merge pull request #18349 from Snuffleupagus/rm-renderTextLayer
[api-minor] Remove the deprecated `renderTextLayer` and `updateTextLayer` functions (PR 18104 follow-up)
2024-07-02 17:23:54 +02:00
calixteman
59620d3748
Merge pull request #18366 from calixteman/clean_switch_annot
[Editor] Make sure everything is cleaned up when we switch to annotation editor mode
2024-07-02 17:13:57 +02:00
Calixte Denizet
68175323f1 [Editor] Make sure everything is cleaned up when we switch to annotation editor mode 2024-07-02 16:54:19 +02:00
calixteman
4f1d4c6bd0
Merge pull request #18365 from calixteman/bump_4.5
Bump library version to 4.5
2024-07-02 15:50:36 +02:00
calixteman
c154b1da23
Update pdfjs.config
Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>
2024-07-02 15:46:05 +02:00
Calixte Denizet
2060944bda Bump library version to 4.5 2024-07-02 15:08:43 +02:00
calixteman
bdcc4a0feb
Merge pull request #18134 from calixteman/hide_annotations
[api-minor][Editor] When switching to editing mode, redraw pages containing editable annotations (bug 1883884)
2024-07-02 15:05:42 +02:00
Jonas Jenwald
033623c8d6 Update the year in the license_header files 2024-07-02 14:34:59 +02:00
Jonas Jenwald
ecb39a75ed [Firefox] Generate a PDF.js default-prefs file that can be used directly in mozilla-central (bug 1905864) 2024-07-02 14:12:23 +02:00
Calixte Denizet
64635f3b35 [api-minor][Editor] When switching to editing mode, redraw pages containing editable annotations
Right now, editable annotations are using their own canvas when they're drawn, but
it induces several issues:
 - if the annotation has to be composed with the page then the canvas must be correctly
   composed with its parent. That means we should move the canvas under canvasWrapper
   and we should extract composing info from the drawing instructions...
   Currently it's the case with highlight annotations.
 - we use some extra memory for those canvas even if the user will never edit them, which
   the case for example when opening a pdf in Fenix.

So with this patch, all the editable annotations are drawn on the canvas. When the
user switches to editing mode, then the pages with some editable annotations are redrawn but
without them: they'll be replaced by their counterpart in the annotation editor layer.
2024-07-02 14:11:40 +02:00
calixteman
75129fd61a
Merge pull request #18361 from calixteman/issue18360.pdf
[Editor] Take into account the page translation when computing the quadpoints when saving an highlight
2024-07-02 11:21:06 +02:00
Calixte Denizet
576aaf7cc1 [Editor] Take into account the page translation when computing the quadpoints when saving an highlight
It fixes #18360.
2024-07-02 10:12:26 +02:00
Tim van der Meij
c280c520ee
Merge pull request #18359 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-07-01 20:14:50 +02:00
Tim van der Meij
2f4d5d25a8
Bump the stable version in pdfjs.config 2024-07-01 20:10:35 +02:00
Tim van der Meij
19fbc89985
Merge pull request #18358 from timvandermeij/npm-url
Fix the repository URL in the `package.json` file for `pdfjs-dist`
2024-07-01 19:55:07 +02:00
Tim van der Meij
bf5dd7ea10
Fix the repository URL in the package.json file for pdfjs-dist
For provenance, enabled in PR #18352, to work the repository URL in
`package.json` is required to match the repository URL of the GitHub
Actions invocation. This should fix the following error we encountered
publishing a new release today:

```
npm error 422 Unprocessable Entity - PUT https://registry.npmjs.org/pdfjs-dist - Error verifying sigstore provenance bundle: Failed to validate repository information: package.json: "repository.url" is "git+https://github.com/mozilla/pdfjs-dist.git", expected to match "https://github.com/mozilla/pdf.js" from provenance
```
2024-07-01 19:32:03 +02:00
Tim van der Meij
7114796430
Merge pull request #18352 from wojtekmaj/provenance
Generate provenance statements on npm publish
2024-07-01 17:42:16 +02:00
Tim van der Meij
067ec20092
Merge pull request #18356 from calixteman/no_newtabpage
Disable new tab page stuff in Firefox when running tests
2024-07-01 16:47:39 +02:00
Calixte Denizet
efb45a705e Disable new tab page stuff in Firefox when running tests
It should help to have such a garbage in the logs:
```
console.warn: TopSitesFeed: Failed to fetch data from Contile server: NetworkError when attempting to fetch resource.
JavaScript error: , line 0: TypeError: NetworkError when attempting to fetch resource.
```
2024-07-01 16:20:07 +02:00
Wojciech Maj
aaa65bf3fc
Generate provenance statements on npm publish
This PR adds [Provenance statements](https://docs.npmjs.com/generating-provenance-statements) on `npm publish`, increasing supply-chain security.
2024-07-01 15:37:25 +02:00
Tim van der Meij
8556a26390
Merge pull request #18353 from wojtekmaj/npm-ci
Use `npm ci`, not `npm install`, on CI
2024-07-01 15:25:02 +02:00
Wojciech Maj
6b449d8884
Use npm ci, not npm install, on CI
This PR switches from `npm install` to `npm ci` on CI. This enables some additional checks to ensure repo integrity when using CI/CD.

Read more: https://docs.npmjs.com/cli/v10/commands/npm-ci
2024-07-01 13:46:23 +02:00
calixteman
b5d554e1b4
Merge pull request #18350 from timvandermeij/github-actions-release
Introduce a GitHub Actions workflow for publishing a release and fix `npm publish` warnings about the `package.json` format
2024-07-01 10:02:41 +02:00
Tim van der Meij
dddb74d5e4
Fix npm publish warnings about the package.json format
This commit removes the following warnings from the `npm publish` output:

```
npm warn publish npm auto-corrected some errors in your package.json when publishing.  Please run "npm pkg fix" to address these errors.
npm warn publish errors corrected:
npm warn publish Removed invalid "scripts"
npm warn publish "repository.url" was normalized to "git+https://github.com/mozilla/pdfjs-dist.git"
```

For the "scripts" section it turns out that if the package doesn't have
any scripts it's expected to explicitly set it to an empty object; refer
to https://github.com/npm/cli/issues/6918 and
https://github.com/denoland/dnt/pull/414.
2024-06-30 16:03:52 +02:00
Tim van der Meij
a5f2b9faeb
Introduce a GitHub Actions workflow for publishing a release
This commit migrates this functionality away from the bots. Note that
the NPM token must be configured as a repository secret before this
workflow can execute.

The following resources are relevant for this patch:

- Publishing packages to the NPM registry:
  https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry
- Creating secrets for a repository:
  https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository
2024-06-30 16:03:52 +02:00
Jonas Jenwald
f3d177e3e4 [api-minor] Remove the deprecated renderTextLayer and updateTextLayer functions (PR 18104 follow-up) 2024-06-30 15:16:00 +02:00
Tim van der Meij
40b0c848ee
Merge pull request #18346 from Snuffleupagus/webserver-dev-note
Add a comment about `test/webserver.mjs` being development-only code
2024-06-30 13:45:30 +02:00
Jonas Jenwald
046e281e20 Add a comment about test/webserver.mjs being development-only code 2024-06-29 12:05:28 +02:00
calixteman
fb3a4e4f5c
Merge pull request #18345 from calixteman/issue18305
Take into account PageOpen and PageClose actions which are present in some fields
2024-06-28 22:43:23 +02:00
Calixte Denizet
dacf8bb0d1 Take into account PageOpen and PageClose actions which are present in some fields 2024-06-28 22:21:03 +02:00
calixteman
8709202021
Merge pull request #18341 from calixteman/issue17779_not_in_talos
Ignore test issue17779.pdf in talos because it times out
2024-06-28 18:58:08 +02:00
Calixte Denizet
4d91ae3cde Ignore test issue17779.pdf in talos because it times out 2024-06-28 17:38:58 +02:00
calixteman
a609bd89b3
Merge pull request #18338 from calixteman/fix_stamp_test
Fix intermittent failures with freetext and stamp tests
2024-06-27 20:03:04 +02:00
calixteman
abdc3fa7cf
Merge pull request #18339 from calixteman/add_port_option
Add a port option to gulp server
2024-06-27 20:01:46 +02:00
Tim van der Meij
53aca5fab1
Merge pull request #18336 from Snuffleupagus/InternalRenderTask-cancel-cancelAnimationFrame
Cancel the `requestAnimationFrame` in the API when cancelling rendering
2024-06-27 19:40:16 +02:00
Calixte Denizet
f006aa36d1 Add a port option to gulp server 2024-06-27 18:57:00 +02:00
Calixte Denizet
0e94f2bd00 Fix intermittent failures with freetext and stamp tests
They're potentially due to some concurrent access to the system clipboard.
So this patch makes them sequential.
2024-06-27 18:23:41 +02:00
Jonas Jenwald
a4f1a9a41b Cancel the requestAnimationFrame in the API when cancelling rendering
Errors related to this `requestAnimationFrame` show up intermittently when running the integration-tests on the bots, however I've been unable to reproduce it locally.
Hence I cannot guarantee that it's enough to fix the timing issues, however this should be generally safe since the `requestAnimationFrame` invokes the `_next`-method and the first thing that one does is check that rendering hasn't been cancelled.
2024-06-26 17:26:02 +02:00
Tim van der Meij
af16aa62ad
Merge pull request #18335 from Snuffleupagus/watchScroll-cancelAnimationFrame
Cancel the `requestAnimationFrame` in the `watchScroll` helper (PR 18193 follow-up)
2024-06-26 16:57:02 +02:00
Jonas Jenwald
4dad1e34b9 Cancel the requestAnimationFrame in the watchScroll helper (PR 18193 follow-up)
While the event listener is removed during testing, the `requestAnimationFrame` isn't cancelled and that occasionally shows up when the integration-tests are run on the bots.
2024-06-26 16:31:07 +02:00
Tim van der Meij
6d579081c4
Merge pull request #18331 from timvandermeij/integration-test-copy-pasting
Refactor the copy/paste logic in the integration tests and fix a race condition involving the `waitForEvent` integration test helper function
2024-06-26 16:20:57 +02:00
Tim van der Meij
7128b95d29
Fix a race condition involving the waitForEvent integration test helper function
Debugging #17931 uncovered a race condition in the way we use the
`waitForEvent` function. Currently the following happens:

1. We call `waitForEvent`, which starts execution of the function body
   and immediately returns a promise.
2. We do the action that triggers the event.
3. We await the promise, which resolves if the event is triggered or
   the timeout is reached.

The problem is in step 1: function body execution has started, but not
necessarily completed. Given that we don't await the promise, we
immediately trigger step 2 and it's not unlikely that the event we
trigger arrives before the event listener is actually registered in the
function body of `waitForEvent` (which is slower because it needs to be
evaluated in the page context and there is some other logic before the
actual `addEventListener` call).

This commit fixes the issue by passing the action to `waitForEvent` as
a callback so `waitForEvent` itself can call it once it's safe to do so.
This should make sure that we always register the event listener before
triggering the event, and because we shouldn't miss events anymore we
can also remove the retry logic for pasting.
2024-06-26 15:25:33 +02:00
Tim van der Meij
55ba4aa66a
Refactor the copy/paste logic in the integration tests
The integration tests are currently not consistent in how they do
copy/pasting: some tests use the `kbCopy`/`kbPaste` functions with
waiting for the event inline, some have their own helper function to
combine those actions and some even call `kbCopy`/`kbPaste` without
waiting for the event at all (which can cause intermittent failures).

This commit fixes the issues by providing a set of four helper functions
that all tests use and that abstract e.g. waiting for the event away
from the caller. This makes the invididual tests simpler and consistent,
reduces code duplication and fixes possible intermittent failures
due to not waiting for events to trigger.
2024-06-26 14:48:42 +02:00
calixteman
2fbd61944b
Merge pull request #18332 from calixteman/bug1904585
Add the possibility to dispatch some pdf.js events at the chrome level (bug 1904585)
2024-06-25 21:15:15 +02:00
Calixte Denizet
35474f8ef4 Add the possibility to dispatch some pdf.js events at the chrome level (bug 1904585) 2024-06-25 21:03:34 +02:00
Jonas Jenwald
7f586182ba
Merge pull request #18333 from Snuffleupagus/l10n-destroy-rm-requestAnimationFrame
Remove the `requestAnimationFrame` work-around in `L10n.prototype.destroy` (PR 18313 follow-up)
2024-06-25 18:34:42 +02:00
Jonas Jenwald
f676ce5760 Remove the requestAnimationFrame work-around in L10n.prototype.destroy (PR 18313 follow-up)
With `@fluent/dom 0.10.0` just published this work-around is no longer necessary.
2024-06-25 17:23:57 +02:00
Tim van der Meij
11cb3a8e11
Merge pull request #18283 from nicolo-ribaudo/ignore-browser-min-font-size
Override the minimum font size when rendering the text layer
2024-06-25 15:57:15 +02:00
Nicolò Ribaudo
5b29e935e1
Overrride the minimum font size when rendering the text layer
Browsers have an accessibility option that allows user to enforce
a minimum font size for all text rendered in the page, regardless
of what the font-size CSS property says. For example, it can be
found in Firefox under `font.minimum-size.x-western`.

When rendering the <span>s in the text layer, this causes the
text layer to not be aligned anymore with the underlying canvas.
While normally accessibility features should not be worked around,
in this case it is *not* improving accessibility:
- the text is transparent, so making it bigger doesn't make it more
  readable
- the selection UX for users with that accessibility option enabled
  is worse than for other users (it's basically unusable).

While there is tecnically no way to ignore that minimum font size,
this commit does it by multiplying all the `font-size`s in the text
layer by minFontSize, and then scaling all the `<span>`s down by
1/minFontSize.
2024-06-25 14:58:08 +02:00
Tim van der Meij
5885874953
Merge pull request #18326 from timvandermeij/integration-test-pastefromclipboard
Use `waitForEvent` in the `pasteFromClipboard` integration test helper function
2024-06-25 13:48:53 +02:00
Tim van der Meij
f974b75d69
Use waitForEvent in the pasteFromClipboard integration test helper function
This code contains the same bug that the previous commit fixed in
`waitForEvent`, namely that we don't clear the timeout if the event
is triggered. By using the now fixed `waitForEvent` function we not
only deduplicate this code but we also fix this issue so that no
incorrect timeout logs show up anymore.
2024-06-25 13:46:08 +02:00
Tim van der Meij
4b95d689de
Merge pull request #18325 from timvandermeij/integration-test-timeouts
Fix the timeout logic in the `waitForEvent` integration test helper function
2024-06-25 13:44:20 +02:00
calixteman
4899b2ea07
Merge pull request #18324 from calixteman/bug1539074_1
Fix the computation of unitsPerEm when the fontMatrix has some negative coefficients
2024-06-25 11:12:32 +02:00
Tim van der Meij
51dcd6a1ba
Fix the timeout logic in the waitForEvent integration test helper function
Debugging #17931, by printing all parts of the event lifecycle including
timestamps, uncovered that some events for which a timeout was logged
actually did get triggered correctly in the browser. Going over the code
and discovering https://stackoverflow.com/questions/47107465/puppeteer-how-to-listen-to-object-events#comment117661238_65534026
showed what went wrong: if the event we wait for is triggered then
`Promise.race` resolves, but that doesn't automatically cancel the
timeout. The tests didn't fail on this because `Promise.race` resolved
correctly, but slightly later once the timeout was reached we would see
spurious log lines about timeouts for the already-triggered events.

This commit fixes the issue by canceling the timeout if the event we're
waiting for has triggered.
2024-06-24 18:22:24 +02:00
Calixte Denizet
42bb2b0737 Fix the computation of unitsPerEm when the fontMatrix has some negative coefficients
It's a follow-up of #18253.
2024-06-24 16:40:07 +02:00
Tim van der Meij
e16707d6e2
Merge pull request #18323 from timvandermeij/security-followup
Improve the security policy
2024-06-24 16:08:31 +02:00
Tim van der Meij
4033913acc
Improve the security policy
This commit fixes two issues that have been found after commit 2beae7a
landed, namely:

- The security checkbox image is not rendering at
  https://github.com/mozilla/pdf.js/security/policy because the
  `SECURITY.md` file is apparently served differently there (because it
  does work as expected at
  https://github.com/mozilla/pdf.js/blob/master/.github/SECURITY.md),
  which causes the relative link not to work. We switch to an absolute
  link to fix the issue.
- If a security policy is defined it turns out that GitHub automatically
  adds a row to the "New issue" page; see
  https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository
  where it states "When someone creates an issue in your repository, they
  will see a link to your project's security policy". Since we now have
  two rows at https://github.com/mozilla/pdf.js/issues/new/choose about
  the security policy, we remove our own version in favor of the
  standard GitHub-provided one.
2024-06-24 15:54:06 +02:00
Tim van der Meij
8123719709
Merge pull request #18311 from timvandermeij/security-policy
Include a security policy for PDF.js
2024-06-24 15:27:58 +02:00
Tim van der Meij
8923f9a4af
Merge pull request #18321 from timvandermeij/integration-test-ignored-errors
Don't ignore errors in the Jasmine suite start/end stages
2024-06-24 15:24:40 +02:00
Tim van der Meij
2beae7aad6
Include a security policy for PDF.js
This makes sure that security researchers can find the required
information for reporting security vulnerabilities in a standardized
manner across GitHub repositories. Please refer to
https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository
for more information.
2024-06-23 21:35:33 +02:00
Tim van der Meij
2f3bf6f07e
Don't ignore errors in the Jasmine suite start/end stages
Currently errors in `afterAll` are logged, but don't fail the tests.
This could cause new errors during test teardown to go by unnoticed.

Moreover, the integration test use a different reporting mechanism which
also handled errors differently (this is extra reason to do #12730).

This patch fixes the issues by consistently handling errors in
`suiteStarted` and `suiteDone` in both reporting mechanisms.

Fixes #18319.
2024-06-23 20:59:48 +02:00
Tim van der Meij
6784124a74
Merge pull request #18320 from timvandermeij/integration-test-tabs
Fix the "copy/paste from a tab to an other" stamp editor integration test
2024-06-23 20:56:59 +02:00
Tim van der Meij
287fd6afd4
Fix the "copy/paste from a tab to an other" stamp editor integration test
This integration test contains three issues:

- The `page.bringToFront()` call is not awaited, even though it returns
  a promise (see https://pptr.dev/api/puppeteer.page.bringtofront). Note
  that in other tests we do this correctly already.
- The `page.waitForSelector()` call at the end is unnecessary because
  that exact condition is already checked at the end of the
  `waitForImage` function we call just before this line; see
  https://github.com/mozilla/pdf.js/blob/master/test/integration/stamp_editor_spec.mjs#L74.
- The pages should be closed in reversed order; please refer to the
  description in #18318 for more details.

Fixes #18318.
2024-06-23 19:08:58 +02:00
Tim van der Meij
b4393a7e79
Merge pull request #18317 from timvandermeij/integration-test-separate-browser-cleanup
Close the page in the text layer caret selection integration test
2024-06-23 16:13:00 +02:00
Tim van der Meij
7057142c7a
Merge pull request #18316 from timvandermeij/integration-test-addons-xpi
Disable system addon updates for Firefox in testing mode
2024-06-23 16:12:07 +02:00
Tim van der Meij
f4053c2b3e
Close the page in the text layer caret selection integration test
This integration test is currently the only one that spawns a separate
browser instance. However, while it closes the browser once it's done,
it doesn't close the page (and therefore doesn't call the `testingClose`
method) like the other integration tests do.

This commit fixes this difference by closing the page before closing the
browser, thereby ensuring all regular cleanup logic gets called and we
avoid (intermittent) shutdown tracebacks in the logs. This allows
upcoming integration tests that spawn a separate browser instance to
reuse this pattern to cleanly end the test.

Given that we integrate the `closeSinglePage` code from #17962 for this
patch, @calixteman is credited as the co-author.

Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
2024-06-23 12:46:18 +02:00
Tim van der Meij
327738d02a
Disable system addon updates for Firefox in testing mode
This commit fixes the following log line that currently shows up for
every type of tests that involve a browser:

`System addon update list error SyntaxError: XMLHttpRequest.open:
'http://%(server)s/dummy-system-addons.xml' is not a valid URL.`

If Firefox is in testing mode, the system addons update URL is
configured to a dummy URL so that it can't actually update (see for
example the same value in Marionette at
https://searchfox.org/mozilla-central/source/testing/marionette/client/marionette_driver/geckoinstance.py#109),
but this doesn't stop Firefox from trying to update, and when it does
it logs this line because the URL is obviously invalid.

Hence this patch which disables system addon updates altogether so
Firefox doesn't attempt to use the dummy URL anymore. The browser
updates are all managed by Puppeteer, and regular updates have already
been disabled too (see
6937a76f0a/packages/browsers/src/browser-data/firefox.ts (L302-L303)).
2024-06-23 11:58:55 +02:00
Tim van der Meij
c18a987f4e
Merge pull request #18313 from Snuffleupagus/l10n-destroy
Try to shutdown Fluent "more" when closing the viewer during testing
2024-06-22 19:45:24 +02:00
Tim van der Meij
658b5fab5d
Merge pull request #18312 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-06-22 19:32:25 +02:00
Jonas Jenwald
6492587066 Try to shutdown Fluent "more" when closing the viewer during testing
Even with PR 18280 fixed, we still *occasionally* see l10n-related errors when closing the integration-tests on the bots.
2024-06-22 16:40:12 +02:00
Tim van der Meij
a89c700607
Update translations to the most recent versions 2024-06-21 17:11:30 +02:00
Tim van der Meij
3b9208b8b6
Update dependencies to the most recent versions 2024-06-21 17:09:21 +02:00
Tim van der Meij
f9ff613e56
Merge pull request #18303 from bootleq/findbar-state-entire-word
Expose entireWord in updateFindControlState
2024-06-21 16:13:54 +02:00
Tim van der Meij
ba0e732e32
Merge pull request #18308 from nicolo-ribaudo/patch-1
Use the new formatted issue templates
2024-06-21 16:00:59 +02:00
Nicolò Ribaudo
1480e6778b
Use the new formatted issue templates 2024-06-21 15:42:31 +02:00
bootleq
890c567eca Expose entireWord in updateFindControlState
Allow apps with supportsIntegratedFind to better monitor the find state.

A recognized use case is the Firefox findbar, its "not found" sound must
consider `entireWord` and only make noise when it is off.

See related implementation in
https://hg.mozilla.org/mozilla-central/rev/16b902cbcf26

This change can help if we have to move the implementation from cpp to jsm.
2024-06-21 13:12:59 +08:00
calixteman
a081dd25eb
Merge pull request #18306 from calixteman/bug1903731
Always use DW if it's a number for the font default width (bug 1903731)
2024-06-20 16:52:29 +02:00
Tim van der Meij
1cf19e907d
Merge pull request #18302 from Snuffleupagus/testingClose-findbar-close
Close `PDFFindBar` when closing the viewer during testing
2024-06-20 15:55:36 +02:00
calixteman
d09aed87d0
Merge pull request #18296 from calixteman/bug1903589
[Editor] Correctly set the accessibility data when copying & pasting a stamp with an alt text (bug 1903589)
2024-06-20 15:35:22 +02:00
Calixte Denizet
8c9a665728 Always use DW if it's a number for the font default width (bug 1903731) 2024-06-20 15:33:34 +02:00
Jonas Jenwald
e76242d4ea
Merge pull request #18304 from Snuffleupagus/issue-18298
Don't throw if there's not enough data to get the header in `FlateStream` (issue 18298)
2024-06-20 13:53:26 +02:00
Calixte Denizet
67f9756fce [Editor] Correctly set the accessibility data when copying & pasting a stamp with an alt text (bug 1903589) 2024-06-20 13:52:58 +02:00
calixteman
9afd3a5b2f
Merge pull request #18301 from calixteman/no_signal
[Editor] Don't create an observer for the stamp annotation after the viewer has been closed
2024-06-20 13:42:54 +02:00
Jonas Jenwald
3fae2d71f6 Don't throw if there's not enough data to get the header in FlateStream (issue 18298)
Following in the footsteps of PR 17340.
2024-06-20 13:03:17 +02:00
Jonas Jenwald
02c03154b3 Close PDFFindBar when closing the viewer during testing
By closing `PDFFindBar` we also disconnect the `ResizeObserver`, since we've seen at least one case where that's running during shutdown: http://54.193.163.58:8877/91c40554d1b07c0/output.txt
2024-06-20 11:51:21 +02:00
Calixte Denizet
7d7ae34e34 [Editor] Don't create an observer for the stamp annotation after the viewer has been closed 2024-06-20 10:52:28 +02:00
Tim van der Meij
3e1d779859
Merge pull request #18218 from nicolo-ribaudo/test-maxCanvasPixels
Respect `maxCanvasPixels` when computing canvas dimensions
2024-06-19 16:47:09 +02:00
Jonas Jenwald
94cbe9ec23
Merge pull request #18289 from Snuffleupagus/app-testingClose
Add a new helper, in the viewer, to close everything during testing
2024-06-19 16:22:12 +02:00
Nicolò Ribaudo
de23bb9b82
Respect maxCanvasPixels when computing canvas dimensions
Ensure that we never round the canvas dimensions above `maxCanvasPixels`
by rounding them to the preceeding multiple of the display ratio rather
than the succeeding one.
2024-06-19 15:23:16 +02:00
Nicolò Ribaudo
12692d2e39
Add test for CSS-only zoom above maxCanvasPixels
This commit introduces a test to ensure that:
- When zooming below the maxCanvasPixels limit, the canvas is rendered
  with the correct size (the two sides are multiplied by the zoom factor).
- When zooming above the maxCanvasPixels limit, the canvas size is capped.
2024-06-19 15:22:53 +02:00
Tim van der Meij
b7d194f3c9
Merge pull request #18292 from Snuffleupagus/tweakWebpackOutput-improve-regex
Update the regular expression in `tweakWebpackOutput` to support minified-legacy builds (issue 18290)
2024-06-19 14:26:20 +02:00
Tim van der Meij
764e67e861
Merge pull request #18278 from timvandermeij/updates
Update dependencies to the most recent versions and upgrade `eslint-plugin-unicorn` to version 54.0.0
2024-06-19 14:01:49 +02:00
Jonas Jenwald
c771ac81cd Add a new helper, in the viewer, to close everything during testing
This has two advantages, as far as I'm concerned:
 - The tests don't need to manually invoke multiple functions to properly clean-up, which reduces the risk of missing something.
 - By collecting all the relevant clean-up in one method, rather than spreading it out, we get a much better overview of exactly what is being reset.
2024-06-19 13:48:08 +02:00
calixteman
c53f71a7d2
Merge pull request #18284 from calixteman/editor_signal
[Editor] Remove the various listeners when destroying the editor manager
2024-06-19 12:36:38 +02:00
Jonas Jenwald
df058edf22 Update the regular expression in tweakWebpackOutput to support minified-legacy builds (issue 18290) 2024-06-19 12:21:10 +02:00
Calixte Denizet
390afcb685 [Editor] Remove the various listeners when destroying the editor manager 2024-06-19 10:33:52 +02:00
calixteman
9dbe4c246b
Merge pull request #18286 from calixteman/call_sandbox
Avoid to call a function in the js sandbox when it has been destroyed
2024-06-18 22:53:16 +02:00
Calixte Denizet
4bdbf4bb3d Avoid to call a function in the js sandbox when it has been destroyed 2024-06-18 22:30:21 +02:00
Tim van der Meij
58dd289971
Upgrade eslint-plugin-unicorn to version 54.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v54.0.0
doesn't indicate any breaking changes that should impact us.
2024-06-18 21:49:38 +02:00
Tim van der Meij
c77dbe0496
Update dependencies to the most recent versions 2024-06-18 21:49:34 +02:00
Tim van der Meij
4b5d5a557c
Merge pull request #18280 from calixteman/issue18279
Pause l10n (i.e. disconnect the mutation observer in fluent) when closing the viewer
2024-06-18 21:47:06 +02:00
Calixte Denizet
34389d4e47 Pause l10n (i.e. disconnect the mutation observer in fluent) when closing the viewer 2024-06-18 21:08:47 +02:00
Tim van der Meij
0d8828f93d
Merge pull request #18282 from Snuffleupagus/issue-18274
Don't save modified documents, when running tests, upon closing the viewer (issue 18274)
2024-06-18 20:55:27 +02:00
Jonas Jenwald
9e811b97b1 Don't save modified documents, when running tests, upon closing the viewer (issue 18274) 2024-06-18 20:05:11 +02:00
Tim van der Meij
c521351338
Merge pull request #18260 from calixteman/dumpio
Enable dumpio when running the tests in order to have some useful debug data
2024-06-18 19:39:59 +02:00
Tim van der Meij
2f462a8afe
Merge pull request #18277 from calixteman/issue18276
[Editor] Fix intermittent failure in integration test when highlighting with the keyboard
2024-06-18 19:34:59 +02:00
calixteman
45762c2f0e
Merge pull request #18275 from calixteman/fix_stamp_css_odd_spread
[Editor] Set the canvas in the stamp editor at the right position in odd spread mode
2024-06-18 18:51:25 +02:00
Calixte Denizet
acf8600a3d [Editor] Set the canvas in the stamp editor at the right position in odd spread mode 2024-06-18 18:44:29 +02:00
Calixte Denizet
4cc77f1470 [Editor] Fix intermittent failure in integration test when highlighting with the keyboard 2024-06-18 18:29:25 +02:00
Jonas Jenwald
701325896a
Merge pull request #18273 from Snuffleupagus/addLocallyCachedImageOps
Add a helper function for handling locally cached image data (PR 18269 follow-up)
2024-06-18 18:11:19 +02:00
Calixte Denizet
3c02dc6d1d Enable dumpio when running the tests in order to have some useful debug data 2024-06-18 18:03:26 +02:00
Jonas Jenwald
604e8977e9 Add a helper function for handling locally cached image data (PR 18269 follow-up)
This avoids having to duplicate the same exact code multiple times.
2024-06-18 17:20:40 +02:00
calixteman
4c041586fb
Merge pull request #18271 from calixteman/clean_before_closing
Clean up before closing the tab in integration tests
2024-06-18 16:55:53 +02:00
Tim van der Meij
4c82438e61
Merge pull request #18269 from Snuffleupagus/issue-18259
Ensure that dependencies are added to the operatorList for locally cached images (issue 18259)
2024-06-18 15:07:07 +02:00
Tim van der Meij
c07dd17162
Merge pull request #18270 from Snuffleupagus/issue-18264
Only use the l10n fallback bundle when normal ftl-file fetching failed (issue 18264)
2024-06-18 14:53:45 +02:00
Calixte Denizet
43be717ce3 Clean up before closing the tab in integration tests 2024-06-18 14:23:19 +02:00
Jonas Jenwald
22ca7d52d3 Ensure that dependencies are added to the operatorList for locally cached images (issue 18259) 2024-06-18 12:25:53 +02:00
Jonas Jenwald
0981716bfa Only use the l10n fallback bundle when normal ftl-file fetching failed (issue 18264) 2024-06-18 11:54:49 +02:00
calixteman
06800cd966
Merge pull request #18255 from calixteman/disable_hwa_only_for_mc
Only disable HWA in m-c build and for local dev
2024-06-16 21:47:34 +02:00
Tim van der Meij
56c396556f
Merge pull request #18257 from calixteman/update_openjpeg_1
Update jpx decoder
2024-06-16 20:44:26 +02:00
Tim van der Meij
ff44c3be1f
Merge pull request #18258 from timvandermeij/release-reproducible
Implement reproducibility for the release builds
2024-06-16 20:39:38 +02:00
Tim van der Meij
44e0fae9d1
Implement reproducibility for the release builds
The release builds are currently not reproducible because ZIP files
record the modification date of files generated during the build
process, meaning that two builds from identical source code, made
at different times, result in different output.

This is undesirable because it makes detecting differences in the output
harder, for instance recently during the Gulp 5 efforts, because the
modification date differences are irrelevant and could obscure actually
important differences in the output during e.g. code changes. Moreover,
reprodicibility of build artifacts has become increasingly important;
please refer to the Reproducible Builds initiative at
https://reproducible-builds.org (note the "Why does it matter?" section
specifically) and https://reproducible-builds.org/docs/timestamps which
further explains the problem of timestamps in build artifacts.

This commit fixes the issue by configuring the ZIP file creation to use
the (fixed) date of the last Git commit for which the release is being
made. With this the build is fully reproducible so that identical source
code builds result in bit-by-bit identical output artifacts.

To improve readability we convert the compression method to take a
parameter object and use template strings where useful.
2024-06-16 20:32:55 +02:00
Calixte Denizet
7255b75ee9 Update jpx decoder
The decoder has been updated to reduce the number of copies after
having decoded an image:
b4ba3b3090
2024-06-16 19:05:26 +02:00
Jonas Jenwald
7b0c0347d0
Merge pull request #18254 from Snuffleupagus/force-save
Ensure that saving, in the viewer, works for partially loaded documents
2024-06-16 17:26:26 +02:00
Tim van der Meij
ee94391794
Merge pull request #18256 from timvandermeij/jsdoc-reproducible
Implement reproducibility for the JSDoc builds
2024-06-16 16:08:56 +02:00
Tim van der Meij
9d0002555d
Implement reproducibility for the JSDoc builds
The JSDoc builds are currently not reproducible because a timestamp is
included in the output, meaning that two builds from identical source
code, made at different times, result in different output.

This is undesirable because it makes diffing the output difficult, for
instance recently during the Gulp 5 efforts, because the timestamp
differences are irrelevant and could obscure actually important
differences in the output during e.g. code changes. Moreover,
reprodicibility of build artifacts has become increasingly important;
please refer to the Reproducible Builds initiative at
https://reproducible-builds.org (note the "Why does it matter?" section
specifically) and https://reproducible-builds.org/docs/timestamps which
further explains the problem of timestamps in build artifacts.

This commit fixes the issue by configuring JSDoc to not include the
timestamps in the output. It's not relevant for end users and without it
the build is fully reproducible so that identical source code builds
result in bit-by-bit identical output artifacts.

Note that this option sadly can only be set via a configuration file,
and not via the command line parameters like we used to have, so for
consistency we also move the other options into the configuration file
so they are all in one place and the Gulpfile becomes a bit simpler.
2024-06-16 15:10:34 +02:00
calixteman
f8acd33527
Merge pull request #18253 from calixteman/bug1539074
Compute correctly the unitsPerEm value from the fontMatrix when converting a font (bug 1539074)
2024-06-16 12:17:10 +02:00
Calixte Denizet
52a06e64f6 Only disable HWA in m-c build and for local dev
This way, we keep pdf.js working as before except for Firefox.
2024-06-16 12:14:33 +02:00
Jonas Jenwald
f4912db2ae Remove the _ensureDownloadComplete helper method in web/app.js
After the previous commit this method has only a single call-site, hence we can inline the needed part of that check directly in `PDFViewerApplication.download` instead.
2024-06-15 18:00:18 +02:00
Jonas Jenwald
7c5e9cf8be Ensure that saving, in the viewer, works for partially loaded documents
Currently saving a modified PDF document may fail *intermittently*, if it's triggered before the entire document has been downloaded.
When saving was originally added we only supported forms, and such PDF documents are usually small/simple enough for this issue to be difficult to trigger. However, with editing-support now available as well it's possible to modify much larger documents and this issue thus becomes easier to trigger.

One way to reproduce this issue *consistently* is to:
 - Open http://localhost:8888/web/viewer.html?file=/test/pdfs/pdf.pdf#disableHistory=true&disableStream=true&disableAutoFetch=true
 - Add an annotation on the first page, it doesn't matter what kind.
 - Save the document.
 - Open the resulting document, and notice that with the `master` branch the annotation is missing.
2024-06-15 17:58:58 +02:00
Calixte Denizet
d1452206d9 Compute correctly the unitsPerEm value from the fontMatrix when converting a font (bug 1539074) 2024-06-15 17:51:34 +02:00
Tim van der Meij
2effc96021
Merge pull request #18250 from Snuffleupagus/api-misc-fixes
Improve some old code in the `src/display/api.js` file
2024-06-15 15:46:44 +02:00
Tim van der Meij
ebb2db7be1
Merge pull request #18251 from timvandermeij/docs-api-inline
Include the generated API documentation directly on the API page
2024-06-15 15:34:27 +02:00
Tim van der Meij
e30dda5261
Include the generated API documentation directly on the API page
This should make the API documentation slightly quicker to access for
users by removing an extra click. Moreover, it makes the API
documentation blend in with the rest of the website/theme (one of the
points in #6526).

Fixes #18249.
2024-06-15 15:13:01 +02:00
Jonas Jenwald
f3f88eecb4 Use an AbortController to remove the temporary "error" handler for the worker 2024-06-15 14:35:32 +02:00
Jonas Jenwald
2d0e08f1c8 Introduce a helper method for resolving the PDFWorker promise
This avoids having to repeat the same code multiple times, since besides resolving the promise we also need to send the "configure" message to the worker-thread.
2024-06-15 14:35:30 +02:00
Jonas Jenwald
8d4456172b Reduce duplication when handling the "test" message from the worker
The feature-testing on the worker-thread has been simplified in previous pull requests, which means that we can simplify this main-thread handler as well.
2024-06-15 14:35:28 +02:00
Jonas Jenwald
0a36b667e4 Use an early return in PDFWorker.prototype._initialize when workers are disabled
This helps reduce overall indentation in the method, thus leading to slightly less code.
Also, remove an old comment referring to Chrome 15 since that's no longer relevant now.
2024-06-15 14:35:12 +02:00
Jonas Jenwald
d6612b3427 Remove some now redundant validation in getDocument
Given that we now check/validate all options properly this old code can be simplified.
2024-06-15 14:35:10 +02:00
Tim van der Meij
831a526c10
Merge pull request #18248 from timvandermeij/metalsmith
Replace Wintersmith with Metalsmith
2024-06-15 12:19:35 +02:00
Tim van der Meij
ce7cdf4670
Replace Wintersmith with Metalsmith
Wintersmith is no longer maintained given that the most recent version
is from six years ago, and all vulnerabilities that NPM reports
originate from Wintersmith's dependencies. Metalsmith, and its plugins,
on the other hand have recently had releases and don't have known
vulnerabilities. In fact, the number of reported vulnerabilities by NPM
even goes down to zero with this patch applied.

This commit therefore replaces Wintersmith with Metalsmith by providing
a transparent drop-in replacement, in a way that requires the least
amount of changes to the code and the generated output.

Note that this patch does update our versions of jQuery, Bootstrap and
the Highlight.js theme because the previous versions were very outdated
and didn't work correctly with Metalsmith. Moreover, those old versions
contained vulnerabilities that are hereby fixed.

Fixes #18198.
2024-06-14 20:37:13 +02:00
Tim van der Meij
7279ce6bad
Merge pull request #18247 from timvandermeij/readme
Don't recommend installing `gulp-cli` globally in the README and on the website
2024-06-14 20:26:12 +02:00
Tim van der Meij
0348559ef8
Don't recommend installing gulp-cli globally in the README and on the website
It's recommended to always install dependencies locally in the project
folder because global dependencies can easily conflict with other
projects and, because they are not managed by the project, diverge from
versions defined in e.g. `package.json`. Previously we installed
`gulp-cli` globally because at the time we lacked a convenient mechanism
to use Gulp otherwise, but nowadays NPM provides the `npx` command for
that purpose and recommends using it over global installations (see
https://docs.npmjs.com/downloading-and-installing-packages-globally
and PR #17489 that provided the ground work for using it).

This commit therefore updates our README and website to no longer recommend
installing `gulp-cli` globally but instead installing it locally from the
already existing entries in `package.json` like all other dependencies
we use. Not only does this remove the special-casing for `gulp-cli`
which simplifies the installation procedure, it also ensures that the
version ranges provided in `package.json` are respected.

This change is similar to the change in commit 92de2b7.

Fixes #18232.
Fixes 98ef8a1.
2024-06-14 18:41:44 +02:00
Tim van der Meij
aa68b8b4b3
Merge pull request #18234 from calixteman/improve_date_parsing
Improve date parsing in the js sandbox
2024-06-14 18:25:36 +02:00
Tim van der Meij
f9693b4d16
Merge pull request #18244 from Snuffleupagus/CSS-copyAll
Improve how the wait-cursor is toggled when copying all text
2024-06-14 18:23:03 +02:00
Tim van der Meij
f00152bf92
Merge pull request #18246 from calixteman/fix_js_error
Fix an query with an empty selector in integration tests
2024-06-14 18:20:44 +02:00
Calixte Denizet
c14c3cfc9f Improve date parsing in the js sandbox
If for example dd:mm is failing we just try with d:m which is equivalent
to the regex /d{1,2}:m{1,2}/. This way it allows the user to forget the
0 for the first days/months.
2024-06-14 17:21:50 +02:00
Calixte Denizet
6d1f7e806e Fix an query with an empty selector in integration tests
In looking the logs from Chrome bidi tests I noticed a js syntax error
which is fixed thanks to this patch.
2024-06-14 16:43:41 +02:00
calixteman
e3caa3c6ee
Merge pull request #18243 from calixteman/disable_ui_when_saving
Display a wait cursor when saving
2024-06-14 10:48:18 +02:00
Jonas Jenwald
97686c410c Improve how the wait-cursor is toggled when copying all text
- Use a CSS rule to display the wait-cursor during copying. Since copying may take a little while in long documents, there's a theoretical risk that something else could change the cursor in the meantime and just resetting to the saved-cursor could thus be incorrect.

 - Remove the `interruptCopyCondition` listener with an AbortController, since that's slightly shorter code.
2024-06-14 10:06:27 +02:00
Calixte Denizet
5ae936eb87 Display a wait cursor when saving
When the document is a bit long to save (for example in modifying a large document)
we must have something indicating that pdf.js is doing something.
2024-06-13 22:54:52 +02:00
Tim van der Meij
47791a4c80
Merge pull request #18236 from Snuffleupagus/rm-downloadUrl
Remove the `DownloadManager.downloadUrl` method
2024-06-13 15:44:42 +02:00
calixteman
f8ffc5baeb
Merge pull request #18238 from calixteman/disable_gpu
Add an option to enable/disable hardware acceleration (bug 1902012)
2024-06-12 19:27:07 +02:00
Calixte Denizet
ff6180a4c9 Add an option to enable/disable hardware acceleration (bug 1902012) 2024-06-12 18:41:07 +02:00
Jonas Jenwald
42999e5bef Remove the DownloadManager.downloadUrl method
This method has only a single call-site in the viewer, since it's used as a fallback, and the functionality can be moved into the `DownloadManager.download` method instead.
2024-06-12 13:27:45 +02:00
calixteman
341ff40e74
Merge pull request #18231 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-06-11 16:44:02 +02:00
Tim van der Meij
e0a01328f3
Update translations to the most recent versions 2024-06-11 15:13:06 +02:00
Tim van der Meij
8273dcaa81
Fix vulnerabilities in dependency versions
This patch is generated automatically using `npm audit fix`.
2024-06-11 15:11:07 +02:00
Tim van der Meij
866b948226
Update dependencies to the most recent versions 2024-06-11 15:10:22 +02:00
calixteman
361b54ec13
Merge pull request #18228 from calixteman/bug1899804
Don't display annotations with a PMD (barcode stuff) entry (bug 1899804)
2024-06-10 21:47:34 +02:00
Calixte Denizet
e3faa40f0f Don't display annotations with a PMD (barcode stuff) entry (bug 1899804)
There's no specification for that (even if it's possible to have an idea from
the xfa specs) so we just want to hide them in order to avoid to display something
wrong.
2024-06-10 21:01:37 +02:00
calixteman
bb73d2a922
Merge pull request #18219 from calixteman/jpx_fix_big_image
Update our OpenJPEG decoder in order to fix a malloc failure due to big image (bug 1901253)
2024-06-08 14:22:18 +02:00
Calixte Denizet
61398066b9 Update our OpenJPEG decoder in order to fix a malloc failure due to big image (bug 1901253)
It has been fixed in:
5ef68089b5
2024-06-07 17:38:35 +02:00
calixteman
c770e94e36
Merge pull request #18214 from calixteman/bug1900907
[Editor] Support dragging & dropping images on a pdf (bug 1900907)
2024-06-07 15:40:14 +02:00
Calixte Denizet
412e03e576 [Editor] Support dragging & dropping images on a pdf (bug 1900907) 2024-06-07 14:26:01 +02:00
Tim van der Meij
b557fba118
Merge pull request #18217 from Snuffleupagus/inline-finishRendering
Inline the `#finishRendering` helper in `TextLayerBuilder.prototype.render`
2024-06-07 14:16:07 +02:00
Tim van der Meij
593ce96834
Merge pull request #18216 from Snuffleupagus/download-data
Change `DownloadManager.download` to use Uint8Array-data
2024-06-07 14:14:48 +02:00
Jonas Jenwald
f7cbd7d16b Inline the #finishRendering helper in TextLayerBuilder.prototype.render
This helper method is simpler/shorter than it originally was[1] and with recent refactoring so is the `render`-method, hence we can just inline this code now.

---
[1] It used to e.g. dispatch the "textlayerrendered" event.
2024-06-07 13:32:28 +02:00
Jonas Jenwald
66e189c9aa Change DownloadManager.download to use Uint8Array-data
Part of this code is really old and pre-dates general availability of things such as `Blob` and `URL.createObjectURL`. To avoid having to duplicate the Blob-creation in the viewer, we can move this into `DownloadManager.download` instead.

Also, remove a couple of unnecessary `await` statements since the methods in question are synchronous.
2024-06-07 13:23:02 +02:00
calixteman
6a71f692bf
Merge pull request #18205 from calixteman/openjpeg_bsd2
Change openjpeg.js license from Apache 2 to BSD 2-clause
2024-06-04 21:27:35 +02:00
Calixte Denizet
e7749443a7 Change openjpeg.js license from Apache 2 to BSD 2-clause 2024-06-04 21:22:48 +02:00
calixteman
21e622769b
Merge pull request #18204 from calixteman/issue16782
Fix decoding of JPX images having an alpha channel
2024-06-03 21:21:52 +02:00
Calixte Denizet
196affd8e0 Fix decoding of JPX images having an alpha channel
When an image has a non-zero SMaskInData it means that the image
has an alpha channel.
With JPX images, the colorspace isn't required (by spec) so when we
don't have it, the JPX decoder will handle the conversion in RGBA
format.
2024-06-03 20:08:11 +02:00
calixteman
5c51d56223
Merge pull request #18167 from calixteman/decompress_image
Decompress when it's possible images in using DecompressionStream
2024-06-02 16:08:19 +02:00
Calixte Denizet
9654ad570a Decompress when it's possible images in using DecompressionStream
Getting images is already asynchronous, so we can use this opportunity
to use DecompressStream (which is async too) to decompress images.
2024-06-02 14:00:05 +02:00
Tim van der Meij
53dfb5a6ba
Merge pull request #18197 from timvandermeij/gulp-5
Upgrade `gulp` to version 5.0.0
2024-06-01 16:16:31 +02:00
calixteman
309d940c3a
Merge pull request #18189 from calixteman/bug1895050
Switch to page-scrolling mode when the pdf has more than 10000 pages (bug 1895050)
2024-05-31 16:03:31 +02:00
Calixte Denizet
018649f13b Switch to page-scrolling mode when the pdf has more than 10000 pages (bug 1895050) 2024-05-31 15:35:26 +02:00
Tim van der Meij
d25b52702a
Upgrade gulp to version 5.0.0
This is a major version bump, and the changelog at
https://github.com/gulpjs/gulp/releases/tag/v5.0.0 indicates one
breaking change that impacts us, namely that streams are now by default
interpreted/transformed to UTF-8 encoding. This breaks `gulp.src` calls
that work on binary files such as images or CMaps, but is fortunately
easy to fix for us by disabling re-encoding for all `gulp.src` calls
(see https://github.com/gulpjs/gulp/issues/2764#issuecomment-2063415792
for more information). This restores the previous behavior of copying
the files as-is without Gulp performing any transformations to it, which
is what we want because Gulp is only used for bundling and we make sure
that the source files have the right encoding.
2024-05-31 14:59:11 +02:00
calixteman
4d9c25a41a
Merge pull request #18193 from calixteman/rm_observer
Disconnect the resize observer and remove scroll listener when unbinding window events
2024-05-30 22:51:05 +02:00
Calixte Denizet
4430b6b703 Disconnect the resize observer and remove scroll listener when unbinding window events 2024-05-30 22:09:52 +02:00
Tim van der Meij
ea34e5ccf6
Merge pull request #18192 from calixteman/bump_4.4
Bump library version to 4.4
2024-05-30 19:05:56 +02:00
Calixte Denizet
648a2d8057 Bump library version to 4.4 2024-05-30 18:56:13 +02:00
calixteman
fdb3617e0f
Merge pull request #18163 from calixteman/simplify_list_points
[api-minor] Simplify how the list of points are structured
2024-05-30 18:25:50 +02:00
Tim van der Meij
0ac4b34c66
Merge pull request #18183 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-05-30 15:46:07 +02:00
Calixte Denizet
6fa98ac99f [api-minor] Simplify how the list of points are structured
Instead of sending to the main thread an array of Objects for a list of points (or quadpoints),
we'll send just a basic float buffer.
It should slightly improve performances (especially when cloning the data) and use slightly less memory.
2024-05-30 15:36:15 +02:00
Tim van der Meij
ea0d2126ea
Update translations to the most recent versions 2024-05-28 19:25:46 +02:00
Tim van der Meij
85c79422cf
Update dependencies to the most recent versions 2024-05-28 19:24:24 +02:00
Tim van der Meij
24e12d515d
Merge pull request #18182 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-05-28 18:48:09 +02:00
Tim van der Meij
fcea7e7b4b
Bump the stable version in pdfjs.config 2024-05-28 18:44:56 +02:00
Jonas Jenwald
0cec644372
Merge pull request #18179 from nicolo-ribaudo/zooming-utilities
[api-minor] Simplify API to implement zoom in custom viewers
2024-05-28 16:39:06 +02:00
Tim van der Meij
027ada81a7
Merge pull request #18170 from Snuffleupagus/TextLayerBuilder-rm-setTextContentSource
[api-minor] Remove the `setTextContentSource` method in `TextLayerBuilder` (PR 18104 follow-up)
2024-05-28 16:38:52 +02:00
Nicolò Ribaudo
b7933d8750
Add origin parameter to updateScale
This parameter allows defining which point should remain
fixed while scaling the document. It can be used, for example,
to implement "zoom around the cursor" or "zoom around
pinch center".

The logic was previously implemented in `web/app.js`, but
moving it to the viewer scaling utilities themselves makes it
easier to implement similar zooming functionalities in
other embedders.
2024-05-28 16:19:47 +02:00
Tim van der Meij
ee545930ea
Merge pull request #18171 from Snuffleupagus/move-pendingTextLayers
Don't register a pending `TextLayer` until `render` is invoked (PR 18104 follow-up)
2024-05-28 15:37:51 +02:00
Nicolò Ribaudo
161c7045f6
Unify increaseScale/decreaseScale logic as updateScale
`updateScale` receives a `drawingDelay`, a `scaleFactor` and/or a number of `steps`.
If `scaleFactor` is a positive number different from `1` the current scale is multiplied by
that number. Otherwise, if `steps` if a positive integer the current scale is multiplied by
`DEFAULT_SCALE_DELTA` `steps` times. Finally, if `steps` is a negative integer, the
current scale is divided by `DEFAULT_SCALE_DELTA` `abs(steps)` times.
2024-05-28 14:02:39 +02:00
Tim van der Meij
aac738c805
Merge pull request #18169 from Snuffleupagus/worker-shorter-code
Slightly shorten some worker-thread code
2024-05-28 13:36:05 +02:00
Tim van der Meij
401a1d4a34
Merge pull request #18161 from Snuffleupagus/types-ES2022
Target ES2022 when building the TypeScript definitions (issue 17932)
2024-05-28 13:28:22 +02:00
calixteman
95a7de9f98
Merge pull request #18174 from calixteman/make_dialog_css
Move the dialog css stuff in its own file
2024-05-28 11:26:49 +02:00
Calixte Denizet
697255d7cc Move the dialog css stuff in its own file
In order to share common parts between different dialogs, this patch
aims to slightly refactor the css in making it more generic.
This way it'll simplify adding a new dialog (we want to add a new one when
leaving an unsaved document).
2024-05-27 22:25:18 +02:00
calixteman
4bdc75f18d
Merge pull request #18165 from calixteman/integrationtest_switch_foo
Simplify the integration test in adding a function to turn on/off an editing tool
2024-05-27 12:00:25 +02:00
Calixte Denizet
b6b02ccff6 Simplify the integration test in adding a function to turn on/off an editing tool 2024-05-27 11:33:52 +02:00
Jonas Jenwald
f2e7eee00e Don't register a pending TextLayer until render is invoked (PR 18104 follow-up)
After the re-factoring in PR 18104 there's now a *theoretical* risk that a pending `TextLayer` is never removed, which we can avoid by not registering it until `render` is invoked.
Note that this doesn't affect the viewer or tests, but if a third-party user calls `new TextLayer(...)` without a following call of either the `render`- or `cancel`-method we'd block global clean-up without this patch.
2024-05-26 18:38:40 +02:00
Jonas Jenwald
303e793264 Introduce a helper method, in PDFPageView, for dispatching "...layerrendered" events
Currently we repeat virtually the same, with the exception of the name, event dispatching code four times for the different viewer layers.
2024-05-26 12:44:06 +02:00
Jonas Jenwald
db86f8132e [api-minor] Remove the setTextContentSource method in TextLayerBuilder (PR 18104 follow-up)
The `setTextContentSource` functionality is very old code, and was introduced years ago together with streaming of textContent.
By moving the `streamTextContent`-call into the `TextLayerBuilder` class we collect more functionality in one place and slightly reduce the amount of code needed.
2024-05-26 12:43:59 +02:00
Jonas Jenwald
27436d52b2 Reduce indentation when parsing new annotations in getOperatorList
This code has, over the years, become more complex and less indentation generally helps readability.
2024-05-25 12:00:44 +02:00
Jonas Jenwald
ce52ce063e Change parsingType3Font to a getter (PR 14448 follow-up)
We can easily "compute" `parsingType3Font` from the `type3FontRefs`-value, and thus avoid having to separately track two related properties.
2024-05-25 10:46:12 +02:00
Jonas Jenwald
c349ac3a5d Skip the temporary variable when calling #findStreamLength (PR 18125 follow-up) 2024-05-25 10:38:32 +02:00
Jonas Jenwald
17e09e5478
Merge pull request #18159 from Snuffleupagus/loadingParams-test
Improve the `loadingParams` functionality in the API
2024-05-24 23:21:24 +02:00
Jonas Jenwald
6460e9ebcf
Merge pull request #18160 from Snuffleupagus/file-layout-overview
Update the "File Layout Overview" docs
2024-05-24 22:31:30 +02:00
Jonas Jenwald
b78480a375
Merge pull request #18166 from Snuffleupagus/bug-1898802
Prevent XRef errors from breaking font loading (bug 1898802)
2024-05-24 22:29:21 +02:00
Jonas Jenwald
cfcb700ecc Prevent XRef errors from breaking font loading (bug 1898802)
Note that the referenced file is trivially corrupt, since it contains *two* PDF documents placed in the same file which doesn't make sense (and isn't how a PDF document should be updated).
However it's still a good idea to ensure that `loadFont` is able to handle errors when resolving References, since that allows us to invoke the existing fallback font handling.
2024-05-24 21:37:35 +02:00
Jonas Jenwald
78deb798e3 Target ES2022 when building the TypeScript definitions (issue 17932)
This should avoid the latest JS features appearing in the TypeScript definitions, and given the currently supported browsers/environments (in PDF.js) we shouldn't need to target an even older ES-version.
2024-05-24 12:14:58 +02:00
Jonas Jenwald
03601f99d8 Update the "File Layout Overview" docs
Apparently we forgot to update this in the version 4 release, so better late than never I suppose.
 - Use `.mjs` extensions where appropriate.
 - Remove mention of the `debugger`-functionality, since that's not really relevant to users.
 - Unify the whitespace handling to use spaces consistently.
2024-05-24 11:42:06 +02:00
calixteman
18a7bd60f7
Merge pull request #18156 from calixteman/bug1882613
[GeckoView] Don't use the system fonts (bug 1882613)
2024-05-24 09:56:38 +02:00
Calixte Denizet
adb2bb5af8 [GeckoView] Don't use the system fonts (bug 1882613)
On Android there's almost no chance we find a substitution font so
just use one of the font embedded in pdf.js.
2024-05-24 09:30:22 +02:00
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 0603d1ac1843bc4098d74382beda6cc511350ccd.
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
Jonas Jenwald
6b171540b7 Initialize the networkStream synchronously in getDocument
This is fairly old code, and at some point the need for this to be asynchronous disappeared.
2024-05-14 17:04:25 +02:00
Jonas Jenwald
cbb8748a22 Inline the _fetchDocument helper function in getDocument
This function has been modified a number of times over the years, and at this point it's small/simple enough that we can just inline the code instead.
2024-05-14 16:29:41 +02:00
Tim van der Meij
b0dbacd0e1
Update translations to the most recent versions 2024-05-14 16:26:34 +02:00
Tim van der Meij
d7f2bc044a
Upgrade eslint-plugin-unicorn to version 53.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v53.0.0
doesn't indicate any breaking changes that should impact us.

Most notably it contains support for ESLint 9, which brings us a step
closer towards #17928.
2024-05-14 16:23:36 +02:00
Tim van der Meij
161b942d41
Update dependencies to the most recent versions
The Puppeteer update should in particular be helpful for us because it
contains improved WebDriver BiDi compatibility, a newer Chrome version
(both might help for #17962) and an official deprecation of CDP for
Firefox. Note that the latter doesn't require changes on our end because
we already use WebDriver BiDi unconditionally for Firefox since commit
4db0174. The full release notes can be found at
https://github.com/puppeteer/puppeteer/releases/tag/puppeteer-core-v22.8.0.
2024-05-14 16:22:06 +02:00
Tim van der Meij
33f3228e00
Merge pull request #18087 from calixteman/update_openjpeg
Update openjpeg build (bug 1896577)
2024-05-14 16:05:52 +02:00
Tim van der Meij
c6d7ae2076
Merge pull request #18089 from Snuffleupagus/textLayer-private
Improve the `TextLayerRenderTask` implementation
2024-05-14 16:03:05 +02:00
Tim van der Meij
40f9371bf8
Merge pull request #17923 from nicolo-ribaudo/fix-text-selection
Fix flickering on text selection
2024-05-14 15:58:20 +02:00
Tim van der Meij
ac7b86d341
Merge pull request #18080 from calixteman/bug1895909
[Editor] Fix the CSS properties of the canvas when it's used in a stampEditor (bug 1895909)
2024-05-14 15:33:53 +02:00
Nicolò Ribaudo
6f2e4d0d94
Fix flickering on text selection
When seleciting on a touch screen device, whenever the finger moves to a
blank area (so over `div.textLayer` directly rather than on a `<span>`),
the selection jumps to include all the text between the beginning of the
.textLayer and the selection side that is not being moved.

The existing selection flickering fix when using the mouse cannot be
trivially re-used on mobile, because when modifying a selection on
a touchscreen device Firefox will not emit any pointer event (and
Chrome will emit them inconsistently). Instead, we have to listen to the
'selectionchange' event.

The fix is different in Firefox and Chrome:
- on Firefox, we have to make sure that, when modifying the selection,
  hovering on blank areas will hover on the .endOfContent element
  rather than on the .textLayer element. This is done by adjusting the
  z-indexes so that .endOfContent is above .textLayer.
- on Chrome, hovering on blank areas needs to trigger hovering on an
  element that is either immediately after (or immediately before,
  depending on which side of the selection the user is moving) the
  currently selected text. This is done by moving the .endOfContent
  element around between the correct `<span>`s in the text layer.

The new anti-flickering code is also used when selecting using a mouse:
the improvement in Firefox is only observable on multi-page selection,
while in Chrome it also affects selection within a single page.

After this commit, the `z-index`es inside .textLayer are as follows:
- .endOfContent has `z-index: 0`
- everything else has `z-index: 1`
  - except for .markedContent, which have `z-index: 0`
    and their contents have `z-index: 1`.

`.textLayer` has an explicit `z-index: 0` to introduce a new stacking context,
so that its contents are not drawn on top of `.annotationLayer`.
2024-05-14 14:31:12 +02:00
Jonas Jenwald
036fd11ad7 Improve the TextLayerRenderTask implementation
- Change all possible semi-private methods into properly private ones. Note that this code is old enough to predate standard classes.

 - Move the `appendText` helper function into `TextLayerRenderTask`, as a private method, to avoid having to manually pass in the scope.

 - Simplify `#layoutText` by directly passing in all necessary data. This is possible after the changes PR 18052.
2024-05-14 14:10:17 +02:00
Jonas Jenwald
c5f92437f7 Avoid re-parsing global images that failed decoding (issue 18042, PR 17428 follow-up)
For images that failed to decode once we want to avoid a pointless round-trip to the main-thread, which could otherwise happen for globally cached images.
2024-05-14 13:58:36 +02:00
Jonas Jenwald
bb9bb34721
Merge pull request #17941 from Snuffleupagus/getTextContent-lang
[api-minor] Include the document /Lang attribute in the textContent-data
2024-05-14 13:57:46 +02:00
Jonas Jenwald
36a496b409
Merge pull request #18060 from nicolo-ribaudo/babel-plugin-class
Update the Babel plugin to remove empty class constructors
2024-05-14 13:14:54 +02:00
Jonas Jenwald
6d523c316c [api-minor] Include the document /Lang attribute in the textContent-data
- These changes will allow a simpler way of implementing PR 17770.

 - The /Lang attribute is fetched lazily, with the first `getTextContent` invocation. Given the existing worker-thread caching, this will thus only need to be done *once* per PDF document (and most PDFs don't included this data).

 - This makes the /Lang attribute *directly available* in the `textLayer`, which has the following advantages:
    - We don't need to block, and thus delay, overall viewer initialization on fetching it (nor pass it around throughout the viewer).

    - Third-party users of the `textLayer` will automatically benefit from this, once we start actually using the /Lang attribute in PR 17770.
      *Please note:* This also, importantly, means that the `text` reference-tests will then cover this code (which wouldn't otherwise have been the case).
2024-05-14 12:44:41 +02:00
Jonas Jenwald
c0b5d93ef4
Merge pull request #18052 from Snuffleupagus/textLayer-only-ReadableStream
Restore broken functionality and simplify the implementation in `src/display/text_layer.js`
2024-05-14 12:30:27 +02:00
Jonas Jenwald
298d72133e
Merge pull request #18051 from Snuffleupagus/NodePackages
[api-minor] Re-factor how Node.js packages/polyfills are  loaded (issue 17245)
2024-05-14 11:43:57 +02:00
Calixte Denizet
699e8aa3e4 Update openjpeg build (bug 1896577)
It just contains fixes for:
 - bug 1896577
 - https://github.com/mozilla/pdf.js.openjpeg/issues/1
2024-05-14 10:11:58 +02:00
Jonas Jenwald
761abc7cc3
Merge pull request #18066 from Snuffleupagus/rm-FontFaceObject-ignoreErrors
Remove the `ignoreErrors` option from the `FontFaceObject` class
2024-05-14 09:49:08 +02:00
Tim van der Meij
0347e59b99
Merge pull request #18061 from Snuffleupagus/api-report-Stats
Slightly re-factor how the viewer initializes debug-only functionality
2024-05-13 19:38:59 +02:00
Calixte Denizet
093bdfd971 [Editor] Fix the CSS properties of the canvas when it's used in a stampEditor (bug 1895909)
And move the page canvas properties under canvasWrapper in order to avoid future regressions.
2024-05-13 16:58:19 +02:00
Tim van der Meij
df23679bc6
Merge pull request #18079 from mozilla/revert-18019-safari-zoom-fix
Revert "Fix rendering problem when zooming on Safari" for causing bug 1895909
2024-05-13 16:45:03 +02:00
Jonas Jenwald
75a1955fd0
Revert "Fix rendering problem when zooming on Safari" 2024-05-13 16:14:38 +02:00
Jonas Jenwald
1a3ea15950 [api-minor] Respect the drawingDelay also when CSS-only zooming is used (issue 18022)
If a user manually calls `PDFPageView.prototype.update()` with a `drawingDelay`-option then it'll always be necessary to re-call the method *without* a delay afterwards, regardless of the `maxCanvasPixels`-value (e.g. even when CSS-only zooming is used).
2024-05-13 15:24:48 +02:00
Tim van der Meij
d9cff1af04
Merge pull request #18069 from Snuffleupagus/rm-spaceWidth
Remove the unused `Font.prototype.spaceWidth` getter (PR 13424 follow-up)
2024-05-13 15:18:44 +02:00
Tim van der Meij
1c25e951a4
Merge pull request #18055 from Snuffleupagus/PDFViewer-signal
Remove event listeners with `signal` in web/pdf_viewer.js
2024-05-13 15:16:01 +02:00
Nicolò Ribaudo
46626ac64a
Update the Babel plugin to remove empty class constructors
This only happens when it's safe to do so. The exceptions are:
- when the class extends another subclass: removing the constructor would remove the error about the missing super() call
- when there are default parameters, that could have side effects
- when there are destructured prameters, that could have side effects
2024-05-13 11:51:43 +02:00
Jonas Jenwald
4aee67227e Remove the unused Font.prototype.spaceWidth getter (PR 13424 follow-up)
This getter became unused in PR 13424, well over two years ago, and apparently none of us noticed that.
2024-05-11 11:50:51 +02:00
Jonas Jenwald
5f6f1686b5 Remove the ignoreErrors option from the FontFaceObject class
- The `stopAtErrors` API option, which is the inverse of the "internal" `ignoreErrors` option, is explicitly documented as applying to *parsing* (i.e. the worker-thread) while the `FontFaceObject` class is used during rendering (i.e. the main-thread); see b6765403a1/src/display/api.js (L164-L167)

 - A glyph that fails in the `FontRendererFactory`, on the worker-thread, will already cause (overall) parsing to stop when `ignoreErrors === false` hence checking the option on the main-thread as well seems redundant; see b6765403a1/src/core/evaluator.js (L4527-L4533)

 - Removing this option simplifies the code, and slightly reduces the number of options that we need to handle in the main-thread code.
2024-05-11 10:18:23 +02:00
Jonas Jenwald
5e50479ac6 Use more object destructuring in the "commonobj" handler in the API 2024-05-11 09:44:10 +02:00
Jonas Jenwald
5fbc5ba16a Move the loadPDFBug function into PDFViewerApplication._parseHashParams
Given that this is a debug-only function we don't need to define it "globally" in the `web/app.js` file.
2024-05-11 09:42:05 +02:00
Jonas Jenwald
ba8c620e4b Inline the loadFakeWorker function at its only call-site in web/app.js
Given that this is a debug-only, and fairly short, function we can just inline the code.
2024-05-11 09:42:05 +02:00
Jonas Jenwald
4a8d742592 Move the reporting of page Stats into the API
This avoids having to add a couple of event listeners in the viewer, when debugging is enabled, and is consistent with the existing handling of `FontInspector` and `StepperManager` in the API.
2024-05-11 09:42:05 +02:00
Nicolò Ribaudo
83d878d34c
Rename builder esprima fixtures to babel
f724ae98a1c0859885083448e2cbc3f3d4c31cf1 changed the build
script to use Babel, so this commit updates the file names accordingly
2024-05-09 15:17:30 +02:00
Jonas Jenwald
469738c1ce Remove event listeners with signal in web/pdf_viewer.js 2024-05-08 16:07:43 +02:00
Jonas Jenwald
9418ed19e7 [api-minor] Remove the, now unused, pdfjsLibPromise global
This global was only introduced to work-around problems caused by the GENERIC PDF.js build using top level await. Since that was removed in the previous commit, this global is now dead code.
2024-05-07 18:21:56 +02:00
Jonas Jenwald
8d86e18a32 Restore the MAX_TEXT_DIVS_TO_RENDER limit in the textLayer
This limit is currently completely non-functional, since the check happens *after* the entire textLayer has been parsed and appended to the DOM. It seems that this has been *accidentally* broken ever since the introduction of `ReadableStream` support.
The reason that this hasn't caused noticeable textLayer-related performance issues in practice is probably because we nowadays manage to coalesce the textLayer into fewer overall DOM elements, whereas years ago many PDF documents ended up with one DOM element *per* glyph.

By moving this check, and thus restoring the functionality, we're also able to remove the `render` helper function and simplify the code.
2024-05-07 13:04:00 +02:00
Jonas Jenwald
30840e411e Ensure that the textLayer styleCache is always cleared, even on failure
By also moving it to the `TextLayerRenderTask`-instance, we can avoid a bit of manual parameter passing.
2024-05-07 13:04:00 +02:00
Jonas Jenwald
049848ba00 Unify the ReadableStream and TextContent code-paths in src/display/text_layer.js
The only reason that this code still accepts `TextContent` is for backward-compatibility purposes, so we can simplify the implementation by always using a `ReadableStream` internally.
2024-05-07 13:03:57 +02:00
Jonas Jenwald
2643570364 [api-minor] Re-factor how Node.js packages/polyfills are loaded (issue 17245)
*Please note:* This removes top level await from the GENERIC builds of the PDF.js library.

Despite top level await being supported in all modern browsers/environments, note [the MDN compatibility data](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#browser_compatibility), it seems that many frameworks and build-tools unfortunately have trouble with it.
Hence, in order to reduce the influx of support requests regarding top level await it thus seems that we'll have to try and fix this.

Given that top level await is only needed for Node.js environments, to load packages/polyfills, we re-factor things to limit the asynchronicity to that environment.
The "best" solution, with the least likelihood of causing future problems, would probably be to await the load of Node.js packages/polyfills e.g. at the top of the `getDocument`-function. Unfortunately that doesn't work though, since that's a *synchronous* function that we cannot change without breaking "the world".

Hence we instead await the load of Node.js packages/polyfills together with the `PDFWorker` initialization, since that's the *first point* of asynchronicity during initialization/loading of a PDF document. The reason that this works is that the Node.js packages/polyfills are only needed during fetching of the PDF document respectively during rendering, neither of which can happen *until* the worker has been initialized.
Hopefully this won't cause any future problems, since looking at the history of the PDF.js project I don't believe that we've (thus far) ever needed a Node.js dependency at an earlier point.
This new pattern for accessing Node.js packages/polyfills will also require some care during development *and* importantly reviewing, to ensure that no new top level await is added in the main code-base.
2024-05-06 23:20:03 +02:00
Jonas Jenwald
b6765403a1
Merge pull request #18026 from Snuffleupagus/validate-more-getArray
Validate even more dictionary properties
2024-05-06 22:09:42 +02:00
Tim van der Meij
14e87469db
Merge pull request #18041 from timvandermeij/integration-tests-timeout-freetext
Remove most `waitForTimeout` usage from the freetext editor integration tests
2024-05-06 20:00:03 +02:00
calixteman
30d0e3a0ba
Merge pull request #18044 from calixteman/bug1894849
Avoid to aria-hide the structure tree (bug 1894849)
2024-05-06 19:56:59 +02:00
Tim van der Meij
bb743389aa
Use waitForSelector instead of waitForFunction for focus checks
This commit replaces `waitForFunction` calls that use
`document.activeElement` to wait for an element to get focus by simpler
`waitForSelector` expressions that use the `:focus` selector. Note that
we already use this in other tests, so this improves consistency too.
2024-05-06 19:35:37 +02:00
Tim van der Meij
5c5c107ec5
Remove most waitForTimeout usage from the freetext editor integration tests
This commit replaces a `waitForTimeout` occurrence with an equivalent
`waitForSelector` expression, and removes two other `waitForTimeout`
occurrences that are obsolete because we already wait for an observable
event to trigger or class change to happen.

Note that the other `waitForTimeout` occurrences in this file are either
part of #17931 or remain until we find a good way to ensure that nothing
happened (because currently there is nothing we can await there).
2024-05-06 19:35:37 +02:00
Tim van der Meij
d79aaee62a
Merge pull request #18009 from nicolo-ribaudo/pin-node-21
Pin GitHub actions to Node.js 21
2024-05-06 14:47:56 +02:00
Jonas Jenwald
9b41bfc374 Introduce helper functions for parsing /Matrix and /BBox arrays 2024-05-03 22:37:50 +02:00
Jonas Jenwald
52f7ff155d Validate even more dictionary properties
This checks primarily Arrays, but also some other properties, that we'll end up sending (sometimes indirectly) to the main-thread.
2024-05-03 22:37:14 +02:00
Calixte Denizet
7742c3eb63 Avoid to aria-hide the structure tree (bug 1894849)
If one ancestor of the structure tree has the attribute aria-hidden
then it's invisible for screen readers.
2024-05-03 14:39:43 +02:00
Jonas Jenwald
1b811ac113
Merge pull request #18034 from Snuffleupagus/FileSpec-filename-stripPath
[api-minor] Improve the `FileSpec` implementation
2024-05-03 09:03:17 +02:00
Jonas Jenwald
a790f2df5d [api-minor] Remove the unused onlyStripPath option from the getFilenameFromUrl helper function 2024-05-03 08:29:41 +02:00
Jonas Jenwald
c419c8333b
Merge pull request #18037 from Snuffleupagus/validate-more-widths
Add even more validation of width-data (PR 18017 follow-up)
2024-05-02 14:41:02 +02:00
Tim van der Meij
2f7a4d555a
Merge pull request #18033 from Snuffleupagus/version-4.3
Bump library version to `4.3`
2024-05-02 14:38:54 +02:00
Jonas Jenwald
6c05f8b381 Add even more validation of width-data (PR 18017 follow-up)
I missed this case in PR 18017, sorry about that.
2024-05-02 11:24:15 +02:00
calixteman
33732ff2cb
Merge pull request #18035 from calixteman/rm_max_group_size
Remove the limit used to decided if a group canvas must be upscaled or not
2024-05-01 20:14:28 +02:00
Jonas Jenwald
2b69fb76ac [api-minor] Improve the FileSpec implementation
- Check that the `filename` is actually a string, before parsing it further.
 - Use proper "shadowing" in the `filename` getter.
 - Add a bit more validation of the data in `pickPlatformItem`.
 - Last, but not least, return both the original `filename` and the (path stripped) variant needed in the display-layer and viewer.
2024-05-01 18:02:05 +02:00
Calixte Denizet
5c771628de Remove the limit used to decided if a group canvas must be upscaled or not
It fixes issues #14982 and #14724.
The main problem of upscaling a canvas is that it can induces some pixelation
(see issue #14724). So this patch is just removing the limit and as a side
effect it fixes issue #14982.
As far as I can tell, in looking different profiles (especially some memory profile)
in using the Firefox profiler, I don't see any noticeable difference in term of
memory use.
2024-05-01 18:01:54 +02:00
Jonas Jenwald
16dbf5dcfd
Merge pull request #18031 from Snuffleupagus/issue-18030
[api-minor] Expose the /Desc-attribute of file attachments in the viewer (issue 18030)
2024-05-01 17:53:22 +02:00
Jonas Jenwald
3ff93ede07 Bump library version to 4.3 2024-05-01 17:00:14 +02:00
calixteman
96ce111e0c
Merge pull request #18029 from calixteman/simplify_smask
[api-minor] Remove the use of (get/put)ImageData when drawing SMasks (bug 1874013)
2024-05-01 16:12:43 +02:00
Calixte Denizet
82989e6790 [api-minor] Remove the use of (get/put)ImageData when drawing SMasks (bug 1874013)
and implement then in using some SVG filters and composition.
Composing in using destination-in in order to multiply RGB components by
the alpha from the mask isn't perfect: it'd be a way better to natively have
alpha masks support, it induces some small rounding errors and consequently
computed RGB are approximatively correct.
In term of performance, it's a real improvement, for example, the pdf in
issue #17779 is now rendered in few seconds.
There are still some room for improvement, but overall it should be a way
better.
2024-05-01 15:40:44 +02:00
Jonas Jenwald
bf4e36d1b5 [api-minor] Expose the /Desc-attribute of file attachments in the viewer (issue 18030)
In the viewer this will be displayed in the `title` of the hyperlink, which is probably the best we can do here given how the viewer is implemented.
2024-05-01 09:02:11 +02:00
Tim van der Meij
77e2182b8e
Merge pull request #18019 from Aditi-1400/safari-zoom-fix
Fix rendering problem when zooming on Safari
2024-04-30 14:50:46 +02:00
Tim van der Meij
716ac7eae8
Merge pull request #18024 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-04-30 13:58:36 +02:00
Tim van der Meij
9dcb2b3844
Update translations to the most recent versions 2024-04-29 19:57:19 +02:00
Tim van der Meij
9872de1415
Upgrade postcss-discard-comments to version 7.0.0
This is a major version bump, but the changelog at
https://github.com/cssnano/cssnano/releases/tag/cssnano%407.0.0
doesn't indicate any breaking changes that should impact us.
2024-04-29 19:55:38 +02:00
Tim van der Meij
89f41e527d
Update dependencies to the most recent versions 2024-04-29 19:52:37 +02:00
Tim van der Meij
1241758605
Merge pull request #18023 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-04-29 19:33:55 +02:00
Tim van der Meij
a6271e47b2
Bump the stable version in pdfjs.config 2024-04-29 19:30:03 +02:00
Tim van der Meij
49b388101a
Merge pull request #18001 from Snuffleupagus/api-pageRefCache
[api-minor] Move the page reference/number caching into the API
2024-04-29 19:10:06 +02:00
Jonas Jenwald
150964dd6d Remove unnecessary check from PDFLinkService.goToDestination (PR 17984 follow-up)
After the changes in PR 17984 this code can no longer be reached, since the destination is now validated on the worker-thread.
2024-04-29 18:54:09 +02:00
Jonas Jenwald
f6cd03955b [api-minor] Move the page reference/number caching into the API
Rather than having to handle this *manually* throughout the viewer, this functionality can instead be moved into the API which simplifies the code slightly.
2024-04-29 18:54:06 +02:00
Jonas Jenwald
fa69d9a3bc Inline the helper method in PDFLinkService.goToDestination
We no longer need the helper method to *potentially* call itself once data is available, and can instead take full advantage of async/await by inlining the code.
2024-04-29 18:52:12 +02:00
Tim van der Meij
3052e99f65
Merge pull request #18013 from Snuffleupagus/SimpleLinkService-extends-PDFLinkService
Re-factor `SimpleLinkService` to extend `PDFLinkService`
2024-04-29 18:41:53 +02:00
Jonas Jenwald
2b2ade7883
Merge pull request #18018 from Snuffleupagus/CompiledFont-tweak-caching
Reduce code-duplication when caching data in `CompiledFont.getPathJs`
2024-04-29 17:39:35 +02:00
Jonas Jenwald
627fe2d826
Merge pull request #18017 from Snuffleupagus/validate-widths
Add more validation of width-data
2024-04-29 14:17:23 +02:00
Aditi
04580168a2 Fix rendering problem when zooming on Safari 2024-04-29 17:32:06 +05:30
Jonas Jenwald
85ff8f34e2 Reduce code-duplication when caching data in CompiledFont.getPathJs 2024-04-29 13:18:31 +02:00
Jonas Jenwald
d411a072a4 Add more validation of width-data
The current `PartialEvaluator.extractWidths` implementation only contains *partial* validation of the width-data.
2024-04-29 10:51:16 +02:00
Jonas Jenwald
234067e745
Merge pull request #18014 from Snuffleupagus/validate-font-properties
Validate additional font-dictionary properties
2024-04-29 10:01:48 +02:00
Jonas Jenwald
08eb0566f7 Validate additional font-dictionary properties 2024-04-29 08:21:28 +02:00
calixteman
85e64b5c16
Merge pull request #18015 from calixteman/rm_eval_font_loader
Simplify the way to pass the glyph drawing instructions from the worker to the main thread
2024-04-28 23:27:47 +02:00
Jonas Jenwald
8c3d571939 Re-factor SimpleLinkService to extend PDFLinkService
Rather than having to maintain a dummy `IPDFLinkService` implementation, we can simply let it extend the primary `PDFLinkService` class instead.
Note how *some* methods already checked for an active PDF document, and those checks only needed to be used consistently throughout `PDFLinkService` in order for this to work.
2024-04-28 10:18:41 +02:00
Calixte Denizet
551e63901c Simplify the way to pass the glyph drawing instructions from the worker to the main thread
and remove the use of eval in the font loader.
2024-04-27 21:28:31 +02:00
Nicolò Ribaudo
e561a4af3c
Pin GitHub actions to Node.js 21
Node.js 22 was just released, and it seems like it's not compatible
with the `canvas` package. This commit pins the version on GitHub
actions to Node.js 21 as a temporary workaround.

This commit should be reverted once
https://github.com/Automattic/node-canvas/issues/2377
is fixed.
2024-04-26 19:23:16 +02:00
calixteman
90d4b9c2c0
Merge pull request #17868 from calixteman/interpolate_flag
Always enable smoothing when rendering downscaled image
2024-04-24 20:16:01 +02:00
Calixte Denizet
b511878ba7 Always enable smoothing when rendering downscaled image
and rely on the Interpolate flag only when the image is upscaled.
Fixes #16273.
2024-04-24 18:33:21 +02:00
calixteman
d1f494d68c
Merge pull request #17986 from calixteman/fix_struct_tree
Allow to insert several annotations under the same parent in the structure tree
2024-04-24 18:32:00 +02:00
Tim van der Meij
885dd72433
Merge pull request #17984 from Snuffleupagus/issue-17981
Validate explicit destinations on the worker-thread to prevent `DataCloneError` (issue 17981)
2024-04-24 16:25:02 +02:00
Calixte Denizet
45fa867577 Allow to insert several annotations under the same parent in the structure tree
While testing stamp insertion with the added pdf, I noticed that the tags using a MCID
weren't considered when trying to attach an annotation to it.
2024-04-24 16:23:05 +02:00
Tim van der Meij
7d1eabe2bd
Merge pull request #17969 from timvandermeij/integration-tests-timeout-annotations
Remove all `waitForTimeout` usage from the annotation integration tests
2024-04-24 16:14:54 +02:00
calixteman
dafc4f66c2
Merge pull request #17999 from calixteman/issue17998
Set correctly the change property for the event triggered when a choice list is changed
2024-04-24 16:07:28 +02:00
Tim van der Meij
10641d5af0
Remove all waitForTimeout usage from the annotation integration tests
This commit replaces all `waitForTimeout` occurrences with the
appropriate `waitForFunction` calls. Note that in some places they were
already present, so in those cases we could simply remove the
`waitForTimeout` call altogether.
2024-04-24 16:05:37 +02:00
Calixte Denizet
55808238e4 Set correctly the change property for the event triggered when a choice list is changed
It fixes #17998.
2024-04-24 14:48:22 +02:00
Tim van der Meij
bda98b91cb
Merge pull request #17967 from Snuffleupagus/eventBus-signal
Add `signal`-support in the `EventBus`, and utilize it in the viewer (PR 17964 follow-up)
2024-04-23 15:55:59 +02:00
Jonas Jenwald
7206d0a237 Validate explicit destinations on the worker-thread to prevent DataCloneError (issue 17981)
*Note:* This borrows a helper function from the viewer, however the code cannot be directly shared since the worker-thread has access to various primitives.
2024-04-22 22:51:35 +02:00
Tim van der Meij
522af265a7
Merge pull request #17977 from Snuffleupagus/parseImageProperties-TypedArray
Update `JpxImage.parseImageProperties` to support TypedArray data in IMAGE_DECODERS builds
2024-04-22 18:31:31 +02:00
Jonas Jenwald
9e80c6d228
Merge pull request #17978 from Snuffleupagus/pr-17428-followup
Extend the globally cached image main-thread copying to "complex" images as well (PR 17428 follow-up)
2024-04-22 16:46:23 +02:00
calixteman
f6b0413506
Merge pull request #17985 from calixteman/openjpeg_warn
Use the pdf.js warn when using jpx decoder
2024-04-22 16:06:13 +02:00
Calixte Denizet
55f943c4fa Use the pdf.js warn when using jpx decoder
Fixes #17980.
2024-04-22 16:02:45 +02:00
Tim van der Meij
335d8394cd
Merge pull request #17979 from Snuffleupagus/image-errors-shorter-msg
[api-minor] Remove the image-related error message prefixes
2024-04-22 15:35:10 +02:00
calixteman
c22e64cd05
Merge pull request #17983 from calixteman/openjpeg_simd
Improve jpx decoding by around 20% in enabling simd support when compiling OpenJPEG
2024-04-22 15:33:02 +02:00
Tim van der Meij
22c27f8520
Merge pull request #17972 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-04-22 15:32:10 +02:00
calixteman
9d891883b7
Merge pull request #17970 from calixteman/delete_from_xref
Correctly update the xref table when an annotation is deleted
2024-04-22 15:22:01 +02:00
calixteman
0867a1f9bc
Merge pull request #17973 from calixteman/no_contextmenu_resize
[Editor] Don't show the context menu when resizing
2024-04-22 15:13:26 +02:00
Calixte Denizet
c730a50540 Improve jpx decoding by around 20% in enabling simd support when compiling OpenJPEG 2024-04-22 13:08:47 +02:00
Jonas Jenwald
32b885c5ef Remove event listeners with signal in web/annotation_layer_builder.js and web/text_highlighter.js 2024-04-21 09:41:21 +02:00
Jonas Jenwald
912b57b95d [api-minor] Remove the image-related error message prefixes
Other custom errors, based on `BaseException`, do not use such a format.
2024-04-20 12:51:45 +02:00
Jonas Jenwald
2831caef13 Remove event listeners with signal in web/pdf_scripting_manager.js 2024-04-20 12:00:58 +02:00
Jonas Jenwald
bf785f2180 Remove event listeners with signal in web/pdf_history.js 2024-04-20 12:00:58 +02:00
Jonas Jenwald
702ee7b1e1 Add signal-support in the EventBus, and utilize it in the viewer (PR 17964 follow-up)
This mimics the `signal` option that's available for `addEventListener`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal).
2024-04-20 12:00:58 +02:00
Jonas Jenwald
91898e5923 Extend the globally cached image main-thread copying to "complex" images as well (PR 17428 follow-up)
In PR 17428 this functionality was limited to "larger" images, to not affect performance negatively. However it turns out that it's also beneficial to consider more "complex" images, regardless of their size, that contain /SMask or /Mask data; see issue 11518.
2024-04-20 11:10:09 +02:00
Jonas Jenwald
8970786d5b Update JpxImage.parseImageProperties to support TypedArray data in IMAGE_DECODERS builds
Given that the `decode` method only returns the actual image-data, a user would now need to invoke `parseImageProperties` to obtain e.g. the width and height.
This method only accepts `BaseStream`-instances, which are (obviously) not exposed, hence we extend it in IMAGE_DECODERS builds to wrap TypedArray data into the expected format.
2024-04-20 09:38:52 +02:00
Calixte Denizet
c57a0f38e9 [Editor] Don't show the context menu when resizing 2024-04-19 15:22:46 +02:00
Tim van der Meij
7affc7efa1
Update translations to the most recent versions 2024-04-19 14:57:04 +02:00
Tim van der Meij
0fdecb353d
Update dependencies to the most recent versions 2024-04-19 14:56:57 +02:00
Calixte Denizet
901d995a7e Correctly update the xref table when an annotation is deleted 2024-04-18 21:27:39 +02:00
Tim van der Meij
5ad42c13ad
Merge pull request #17964 from Snuffleupagus/addEventListener-signal
Remove *some* event listeners with `signal` in the viewer
2024-04-18 19:13:32 +02:00
Jonas Jenwald
ff2e0c8afd Skip the scroll/scrollend workaround in the Firefox PDF Viewer (PR 17724 follow-up)
Given that [bug 1881974](https://bugzilla.mozilla.org/show_bug.cgi?id=1881974) has been fixed in Firefox 126, the workaround should no longer be necessary in the *built-in* Firefox PDF Viewer.
2024-04-18 18:41:21 +02:00
Jonas Jenwald
46a29ff41b Remove event listeners with signal in web/app.js
By using the `signal` option when invoking `addEventListener`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal), we're able to remove an arbitrary number of event listeners with (effectively) a single line of code.
Besides getting rid of a bunch of `removeEventListener`-calls, which means shorter code, we no longer need to manually keep track of event-handling functions.
2024-04-18 18:41:21 +02:00
Jonas Jenwald
0788c4d918 Remove event listeners with signal in web/pdf_presentation_mode.js
By using the `signal` option when invoking `addEventListener`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal), we're able to remove an arbitrary number of event listeners with (effectively) a single line of code.
Besides getting rid of a bunch of `removeEventListener`-calls, which means shorter code, we no longer need to manually keep track of event-handling functions.
2024-04-18 18:41:18 +02:00
Tim van der Meij
aaa55d2b38
Merge pull request #17966 from timvandermeij/waitForTimeout
Remove `waitForTimeout` usage from the helper functions
2024-04-18 17:51:34 +02:00
Tim van der Meij
c2e9a6264c
Remove waitForTimeout usage from the dragAndDropAnnotation helper function
The timeout was introduced in commit 402e3fe with equal timeouts around
the helper function call. In commit 55e5af2 the timeouts around the
helper function call have been removed, and it looks like the helper
function itself was not updated purely due to an oversight.

The operations here should not require any timeouts because the promises
only resolve once the action is completed, which also explains why
removing the timeouts surrounding the helper function calls went without
any problems. It should therefore be safe to remove this timeout too.
2024-04-18 16:04:26 +02:00
Tim van der Meij
3f51da147c
Remove waitForTimeout usage from the clearInput helper function
We should wait until the input field's value is actually empty instead
of waiting for a fixed time (which could lead to intermittent failures).
2024-04-18 15:31:49 +02:00
calixteman
4866686749
Merge pull request #17914 from calixteman/freetext_edit
[Editor] Provide an element to render in the annotation layer after a freetext has been edited (bug 1890535)
2024-04-18 14:33:12 +02:00
Calixte Denizet
71ea8499f0 [Editor] Provide an element to render in the annotation layer after a freetext has been edited (bug 1890535) 2024-04-18 13:29:41 +02:00
Tim van der Meij
7290faf840
Merge pull request #17956 from calixteman/jpx_exceptions
[JPX] Throw an exception with the error messages returned by openjpeg
2024-04-16 20:48:23 +02:00
Tim van der Meij
921fae556e
Merge pull request #17951 from timvandermeij/fix-jpx-decoder
Fix `JpxImage` API issues (PR 17946 follow-up)
2024-04-16 19:09:46 +02:00
Calixte Denizet
ebcae3014c [JPX] Throw an exception with the error messages returned by openjpeg 2024-04-16 19:02:24 +02:00
Tim van der Meij
c08b09d3b9
Fix JpxImage API issues (PR 17946 follow-up)
This commit changes the `JpxImage.decode` method signature to define the
`ignoreColorSpace` argument as optional with a default value. Note that
we already set this default value in the `getBytes` method of the
`src/core/decode_stream.js` file since this option only seems useful for
certain special cases and therefore shouldn't be mandatory to provide.

Moreover, the JPX fuzzer is changed to use the new `JpxImage` API.
2024-04-16 18:02:47 +02:00
Tim van der Meij
801a0975f2
Merge pull request #17954 from calixteman/openjpeg_web
Build the openjpeg-based decoder in a web environment in order to avoid issues when used in node
2024-04-16 18:01:05 +02:00
Calixte Denizet
0149a8fc84 Build the openjpeg-based decoder in a web environment in order to avoid issues when used in node 2024-04-16 16:55:38 +02:00
Tim van der Meij
e7c45a001f
Merge pull request #17949 from Snuffleupagus/version-4.2
Bump library version to `4.2`
2024-04-16 14:07:34 +02:00
calixteman
12c4119cbd
Merge pull request #17946 from calixteman/openjpeg
[api-minor] Add a jpx decoder based on OpenJPEG 2.5.2
2024-04-16 13:41:58 +02:00
Calixte Denizet
2e83cfbbc1 [api-minor] Add a jpx decoder based on OpenJPEG 2.5.2
The decoder is compiled in WASM:
https://github.com/mozilla/pdf.js.openjpeg

Fixes #17289, #17061, #16485, #13051, #6365, #4648, #12213.
2024-04-16 12:54:36 +02:00
Jonas Jenwald
c6c60313f0 Bump library version to 4.2 2024-04-16 10:47:42 +02:00
Tim van der Meij
7bd7c6ca5a
Merge pull request #17947 from timvandermeij/scripting-intermittent
Fix the "must check that a field has the correct value when a choice is changed" scripting integration test
2024-04-15 16:19:58 +02:00
Tim van der Meij
0e612fbb7d
Fix the "must check that a field has the correct value when a choice is changed" scripting integration test
We should not wait for an arbitrary amount of time, which can easily
cause intermittent failures, but wait for a value change instead. Note
that this patch mirrors the approach we already use in other scripting
integration tests that also check for a value change; see e.g. the
"must check that a field has the correct formatted value" test.
2024-04-15 15:56:39 +02:00
Tim van der Meij
00af2e7b7a
Merge pull request #17942 from Snuffleupagus/Safari-16
[api-minor] Update the minimum supported Safari version to 16.4
2024-04-15 15:02:51 +02:00
Tim van der Meij
1008a53362
Merge pull request #17938 from timvandermeij/rimraf-test
Remove the `rimraf` dependency in favor of the built-in Node.js `fs.rmSync` in the test folder
2024-04-15 14:21:56 +02:00
Tim van der Meij
60f02ea5fe
Merge pull request #17940 from timvandermeij/scripting-test
Fix the "must check that invisible fields are made visible" scripting integration test
2024-04-15 14:20:34 +02:00
Jonas Jenwald
a41bb40fbb [api-minor] Update the minimum supported Safari version to 16.4
This patch updates the minimum supported browsers as follows:
 - Safari 16.4, which was released on 2023-03-27; see https://developer.apple.com/documentation/safari-release-notes/safari-16_4-release-notes

Nowadays we usually we try, where feasible and possible, to support browsers/environments that are about two years old. The reasons for limiting support to a slightly more recent Safari version include:
 - Safari has always been slower, compared to other browsers, at implementing e.g. new JavaScript features.
 - Trying to provide support for Safari is often difficult, and over the years we have seen *a lot* of bugs that are specific to Safari.
 - Safari is, and has been for many years, only listed as "mostly" supported in the FAQ.
 - This allows us to remove feature-testing, only relevant to Safari, from the main code-base.

By limiting support to only "recent" browsers we reduce the risk of holding back improvements of the built-in Firefox PDF Viewer, and also (significantly) reduce the maintenance/support burden for the PDF.js core contributors.

*Please note:* As always, the minimum supported browser version assumes that a `legacy`-build of the PDF.js library is being used; see https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
2024-04-15 12:44:37 +02:00
Tim van der Meij
2e9bd496ce
Fix the "must check that invisible fields are made visible" scripting integration test
We should not wait for an arbitrary amount of time, which can easily
cause intermittent failures, but wait for a property value change
instead. Note that this patch mirrors the approach we already use in
other scripting integration tests that also check for a visibility
change; see e.g. the "must show a text field and then make in invisible
when content is removed" test.
2024-04-14 18:53:09 +02:00
Tim van der Meij
a562c41e12
Remove the rimraf dependency in favor of the built-in Node.js fs.rmSync in the test folder
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 in the test folder.

This commit also gets rid of the indirection via the `removeDirSync`
test helper function by simply calling `fs.rmSync` directly.

Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
2024-04-14 16:41:59 +02:00
Tim van der Meij
e08de772ff
Merge pull request #17879 from ex37/master
Improve type definitions for the viewer
2024-04-14 16:35:02 +02:00
Tim van der Meij
14947ad0ad
Merge pull request #17935 from timvandermeij/mkdirp
Remove the `mkdirp` dependency in favor of the built-in Node.js `fs.mkdirSync`
2024-04-14 16:34:13 +02:00
Eduard Ghazanchyan
da43a53a68 Improve type definitions for the viewer
This commit improves compatibility of the viewer code with TypeScript by including missing type imports/definitions and correcting existing ones
2024-04-12 17:12:04 +04:00
Tim van der Meij
13afff48f8
Remove the mkdirp dependency in favor of the built-in Node.js fs.mkdirSync
In Node.js 10.12.0 the `recursive` option was added to `fs.mkdirSync`.
This option allows us to create a directory and all its parent
directories if they do not exist, making it a drop-in replacement for
the `mkdirp` 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 `mkdirp` and reduce the
number of project dependencies.

Co-authored-by: Wojciech Maj <kontakt@wojtekmaj.pl>
2024-04-12 15:06:48 +02:00
Tim van der Meij
2e94511330
Merge pull request #17934 from calixteman/warn_invalid_name
Warn when a non-embedded font has an invalid name
2024-04-12 14:15:02 +02:00
Calixte Denizet
acc56491c9 Warn when a non-embedded font has an invalid name
It can be helpful to find out some heuristics when trying
to find a substitution font.
2024-04-12 13:59:18 +02:00
Tim van der Meij
e005e6ecdd
Merge pull request #17933 from Snuffleupagus/pr-17464-followup
Fix resetting of cursor-tools when closing the document (PR 17464 follow-up)
2024-04-12 13:32:52 +02:00
Tim van der Meij
2d885e2862
Merge pull request #17930 from calixteman/issue17929
Remove the tag for missing font subset when trying to find a substitution
2024-04-12 13:27:32 +02:00
Jonas Jenwald
60832fee27 Fix resetting of cursor-tools when closing the document (PR 17464 follow-up)
With the removal of the "secondarytoolbarreset" event in PR 17464 resetting of cursor-tools state accidentally broke.
2024-04-12 13:16:44 +02:00
Tim van der Meij
f0ad4f00ce
Merge pull request #17927 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-04-12 13:12:56 +02:00
Tim van der Meij
355432fc71
Merge pull request #17925 from timvandermeij/web-history-private-methods
Convert the history code to use proper private methods
2024-04-12 13:12:30 +02:00
Calixte Denizet
52ea2333b3 Remove the tag for missing font subset when trying to find a substitution
Fixes #17929.
2024-04-11 20:34:28 +02:00
Tim van der Meij
ac7bd17cf8
Update translations to the most recent versions 2024-04-11 19:48:32 +02:00
Tim van der Meij
5db84e7930
Fix vulnerabilities in dependency versions
This patch is generated automatically using `npm audit fix`.
2024-04-11 19:48:31 +02:00
Tim van der Meij
b379b0e999
Upgrade eslint-plugin-unicorn to version 52.0.0
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v52.0.0
doesn't indicate any breaking changes that should impact us.
2024-04-11 19:48:31 +02:00
Tim van der Meij
28962da91b
Update dependencies to the most recent versions 2024-04-11 19:48:31 +02:00
Tim van der Meij
a45aec6393
Convert the history code to use proper private methods
This allows us to get rid of the `@private` JSDoc comments, which were
used to convey intent back when proper private methods could not be used
yet in JavaScript. This improves code readability/maintenance and enables
better usage validation by tooling such as ESlint.
2024-04-11 15:17:30 +02:00
Tim van der Meij
e78ce74b5f
Merge pull request #17924 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2024-04-11 14:52:11 +02:00
Tim van der Meij
09a8b981f2
Bump the stable version in pdfjs.config 2024-04-11 14:47:17 +02:00
758 changed files with 95991 additions and 46553 deletions

View File

@ -1,12 +0,0 @@
build/
l10n/
docs/
node_modules/
external/bcmaps/
external/builder/fixtures/
external/builder/fixtures_esprima/
external/quickjs/
test/tmp/
test/pdfs/
web/locale/
*~/

267
.eslintrc
View File

@ -1,267 +0,0 @@
{
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module",
},
"plugins": [
"import",
"json",
"mozilla",
"no-unsanitized",
"sort-exports",
"unicorn",
],
"extends": [
"plugin:json/recommended",
"plugin:prettier/recommended"
],
"env": {
"browser": true,
"es2022": true,
"worker": true,
},
"globals": {
"PDFJSDev": "readonly",
"__non_webpack_import__": "readonly",
},
"rules": {
// Plugins
"import/export": "error",
"import/exports-last": "error",
"import/extensions": ["error", "always", { "ignorePackages": true, }],
"import/first": "error",
"import/named": "error",
"import/no-cycle": "error",
"import/no-empty-named-blocks": "error",
"import/no-commonjs": "error",
"import/no-mutable-exports": "error",
"import/no-self-import": "error",
"import/no-unresolved": ["error", {
"ignore": ["display", "pdfjs", "pdfjs-lib", "pdfjs-web", "web", "fluent-bundle", "fluent-dom"],
}],
"mozilla/avoid-removeChild": "error",
"mozilla/use-includes-instead-of-indexOf": "error",
"no-unsanitized/method": "error",
"no-unsanitized/property": "error",
"sort-exports/sort-exports": ["error", {
"ignoreCase": true,
}],
"unicorn/no-abusive-eslint-disable": "error",
"unicorn/no-array-push-push": "error",
"unicorn/no-instanceof-array": "error",
"unicorn/no-invalid-remove-event-listener": "error",
"unicorn/no-new-buffer": "error",
"unicorn/no-typeof-undefined": ["error", {
"checkGlobalVariables": false,
}],
"unicorn/no-useless-promise-resolve-reject": "error",
"unicorn/no-useless-spread": "error",
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-flat": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-array-index-of": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-at": "error",
"unicorn/prefer-date-now": "error",
"unicorn/prefer-dom-node-append": "error",
"unicorn/prefer-dom-node-remove": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-modern-dom-apis": "error",
"unicorn/prefer-modern-math-apis": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/prefer-optional-catch-binding": "error",
"unicorn/prefer-regexp-test": "error",
"unicorn/prefer-string-replace-all": "error",
"unicorn/prefer-string-starts-ends-with": "error",
"unicorn/prefer-ternary": ["error", "only-single-line"],
// Possible errors
"for-direction": "error",
"getter-return": "error",
"no-async-promise-executor": "error",
"no-cond-assign": ["error", "except-parens"],
"no-constant-condition": ["error", { "checkLoops": false, }],
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-else-if": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": ["error", { "allowEmptyCatch": true, }],
"no-empty-character-class": "error",
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
"no-func-assign": "error",
"no-inner-declarations": ["error", "functions"],
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-loss-of-precision": "error",
"no-obj-calls": "error",
"no-promise-executor-return": "error",
"no-regex-spaces": "error",
"no-setter-return": "error",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"no-unsafe-optional-chaining": ["error", { "disallowArithmeticOperators": true }],
"no-unused-private-class-members": "error",
"use-isnan": ["error", { "enforceForIndexOf": true, }],
"valid-typeof": ["error", { "requireStringLiterals": true, }],
// Best Practices
"accessor-pairs": ["error", {
"setWithoutGet": true,
"enforceForClassMembers": true,
}],
"consistent-return": "error",
"curly": ["error", "all"],
"default-case-last": "error",
"dot-notation": "error",
"eqeqeq": ["error", "always"],
"grouped-accessor-pairs": ["error", "getBeforeSet"],
"no-alert": "error",
"no-caller": "error",
"no-else-return": "error",
"no-empty-pattern": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-fallthrough": "error",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-implied-eval": "error",
"no-iterator": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-multi-str": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-symbol": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-octal": "error",
"no-redeclare": "error",
"no-return-await": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"no-throw-literal": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-useless-call": "error",
"no-useless-catch": "error",
"no-useless-concat": "error",
"no-useless-escape": "error",
"no-useless-return": "error",
"prefer-promise-reject-errors": "error",
"prefer-spread": "error",
"wrap-iife": ["error", "any"],
"yoda": ["error", "never", {
"exceptRange": true,
}],
// Strict Mode
"strict": ["off", "global"],
// Variables
"no-delete-var": "error",
"no-label-var": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-undef-init": "error",
"no-undef": ["error", { "typeof": true, }],
"no-unused-vars": ["error", {
"vars": "all",
"args": "none",
}],
"no-use-before-define": ["error", {
"functions": false,
"classes": false,
"variables": false,
}],
// Stylistic Issues
"lines-between-class-members": ["error", "always"],
"max-len": ["error", {
"code": 1000,
"comments": 80,
"ignoreUrls": true
}],
"new-cap": ["error", { "newIsCap": true, "capIsNew": false, }],
"no-array-constructor": "error",
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0, "maxBOF": 1, }],
"no-nested-ternary": "error",
"no-new-object": "error",
"no-restricted-syntax": ["error",
{
"selector": "BinaryExpression[operator='instanceof'][right.name='Object']",
"message": "Use `typeof` rather than `instanceof Object`.",
},
{
"selector": "CallExpression[callee.name='assert'][arguments.length!=2]",
"message": "`assert()` must always be invoked with two arguments.",
},
{
"selector": "CallExpression[callee.name='isCmd'][arguments.length<2]",
"message": "Use `instanceof Cmd` rather than `isCmd()` with one argument.",
},
{
"selector": "CallExpression[callee.name='isDict'][arguments.length<2]",
"message": "Use `instanceof Dict` rather than `isDict()` with one argument.",
},
{
"selector": "CallExpression[callee.name='isName'][arguments.length<2]",
"message": "Use `instanceof Name` rather than `isName()` with one argument.",
},
{
"selector": "NewExpression[callee.name='Cmd']",
"message": "Use `Cmd.get()` rather than `new Cmd()`.",
},
{
"selector": "NewExpression[callee.name='Name']",
"message": "Use `Name.get()` rather than `new Name()`.",
},
{
"selector": "NewExpression[callee.name='Ref']",
"message": "Use `Ref.get()` rather than `new Ref()`.",
},
],
"no-unneeded-ternary": "error",
"operator-assignment": "error",
"prefer-exponentiation-operator": "error",
"spaced-comment": ["error", "always", {
"block": {
"balanced": true,
}
}],
// ECMAScript 6
"arrow-body-style": ["error", "as-needed"],
"constructor-super": "error",
"no-class-assign": "error",
"no-const-assign": "error",
"no-dupe-class-members": "error",
"no-duplicate-imports": "error",
"no-this-before-super": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-var": "error",
"object-shorthand": ["error", "always", {
"avoidQuotes": true,
}],
"prefer-const": "error",
"require-yield": "error",
"sort-imports": ["error", {
"ignoreCase": true,
}],
"template-curly-spacing": ["error", "never"],
},
}

View File

@ -1,17 +0,0 @@
Attach (recommended) or Link to PDF file here:
Configuration:
- Web browser and its version:
- Operating system and its version:
- PDF.js version:
- Is a browser extension:
Steps to reproduce the problem:
1.
2.
What is the expected behavior? (add screenshot)
What went wrong? (add screenshot)
Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):

81
.github/ISSUE_TEMPLATE/bug.yml vendored Normal file
View File

@ -0,0 +1,81 @@
name: Bug Report
description: Report a bug in PDF.js
title: "[Bug]: "
body:
- type: textarea
attributes:
label: Attach (recommended) or Link to PDF file
description: Without this information the issue may be closed without comment
placeholder: Please place only the PDF file in this field
validations:
required: true
- type: markdown
attributes: { value: "---" }
- type: input
attributes:
label: Web browser and its version
description: Please ensure that it's supported, refer to [the FAQ](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support)
validations:
required: true
- type: input
attributes:
label: Operating system and its version
validations:
required: true
- type: input
attributes:
label: PDF.js version
description: Please find official releases [here](https://github.com/mozilla/pdf.js/releases)
validations:
required: true
- type: dropdown
attributes:
label: Is the bug present in the latest PDF.js version?
description: Please check the [online demo](https://github.com/mozilla/pdf.js#online-demo)
options: ["Yes", "No"]
default: 0
validations:
required: true
- type: dropdown
attributes:
label: Is a browser extension
options: ["Yes", "No"]
default: 1
validations:
required: true
- type: markdown
attributes: { value: "---" }
- type: textarea
attributes:
label: Steps to reproduce the problem
placeholder: "1.\n2."
validations:
required: true
- type: textarea
attributes:
label: What is the expected behavior?
description: Also add a screenshot
validations:
required: true
- type: textarea
attributes:
label: What went wrong?
description: Also add a screenshot
validations:
required: true
- type: input
attributes:
label: Link to a viewer
description: Needed if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension
- type: textarea
attributes:
label: Additional context
description: Do you have anything to add that doesn't fit in the issue template?

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Need help?
url: https://github.com/mozilla/pdf.js/discussions
about: If you need help on how to use PDF.js, please open a discussion where other community members can reply

23
.github/ISSUE_TEMPLATE/feature.yml vendored Normal file
View File

@ -0,0 +1,23 @@
name: Feature request
description: Propose a new feature or enhancement for PDF.js
title: "[Feature]: "
body:
- type: dropdown
attributes:
label: Is the feature relevant to the Firefox PDF Viewer?
options: ["Yes", "No"]
default: 1
validations:
required: true
- type: textarea
attributes:
label: Feature description
description: What new feature would you like PDF.js to have? Why would it be useful? What are the current workarounds?
validations:
required: true
- type: textarea
attributes:
label: Other PDF viewers
description: Do other PDF viewers implement similar functionality? Add descriptions, links, and/or screenshots.

13
.github/SECURITY.md vendored Normal file
View File

@ -0,0 +1,13 @@
# Security policy
Mozilla takes the security of our software seriously. If you believe you have found a security vulnerability in PDF.js, please report it to us as described below.
## Reporting security vulnerabilities
**Please don't report security vulnerabilities through public GitHub issues.**
Instead, please report security vulnerabilities in [Bugzilla](https://bugzilla.mozilla.org/enter_bug.cgi?product=Firefox&component=PDF%20Viewer&groups=firefox-core-security) and make sure that the checkbox in the "Security" section is checked so the required access controls are automatically configured:
![Security checkbox](https://github.com/mozilla/pdf.js/blob/master/.github/security.png)
The Mozilla security team will process the bug as described in [Mozilla's security bugs policy](https://www.mozilla.org/en-US/about/governance/policies/security-group/bugs).

View File

@ -25,3 +25,5 @@ CO01:
exclusions: exclusions:
files: [] files: []
messages: [] messages: []
VC:
disabled: false

BIN
.github/security.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -11,21 +11,21 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node-version: [18, lts/*, latest] node-version: [20, 22, 24]
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4 uses: actions/setup-node@v6
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Run external tests - name: Run external tests
run: npx gulp externaltest run: npx gulp externaltest

View File

@ -18,18 +18,18 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v3 uses: github/codeql-action/init@v4
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
queries: security-and-quality queries: security-and-quality
- name: Autobuild CodeQL - name: Autobuild CodeQL
uses: github/codeql-action/autobuild@v3 uses: github/codeql-action/autobuild@v4
- name: Perform CodeQL analysis - name: Perform CodeQL analysis
uses: github/codeql-action/analyze@v3 uses: github/codeql-action/analyze@v4

View File

@ -25,12 +25,12 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v6
- name: Use Python 3.12 - name: Use Python 3.14
uses: actions/setup-python@v5 uses: actions/setup-python@v6
with: with:
python-version: '3.12' python-version: '3.14'
cache: 'pip' cache: 'pip'
- name: Install Fluent dependencies - name: Install Fluent dependencies

View File

@ -36,22 +36,22 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4 uses: actions/setup-node@v6
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Use Python 3.12 - name: Use Python 3.14
uses: actions/setup-python@v5 uses: actions/setup-python@v6
with: with:
python-version: '3.12' python-version: '3.14'
cache: 'pip' cache: 'pip'
- name: Install Fonttools - name: Install Fonttools

View File

@ -15,17 +15,17 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4 uses: actions/setup-node@v6
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Run lint - name: Run lint
run: npx gulp lint run: npx gulp lint

37
.github/workflows/publish_release.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: Publish release
on:
release:
types: [published]
permissions:
contents: read
id-token: write
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [lts/*]
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Build the `pdfjs-dist` library
run: npx gulp dist
- name: Publish the `pdfjs-dist` library to NPM
run: npm publish ./build/dist

View File

@ -17,17 +17,17 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4 uses: actions/setup-node@v6
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Build the website - name: Build the website
run: npx gulp web run: npx gulp web
@ -49,7 +49,7 @@ jobs:
INPUT_PATH: build/gh-pages INPUT_PATH: build/gh-pages
- name: Upload the website - name: Upload the website
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v5
with: with:
name: github-pages name: github-pages
path: ${{ runner.temp }}/website.tar path: ${{ runner.temp }}/website.tar

View File

@ -15,17 +15,17 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4 uses: actions/setup-node@v6
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- name: Install dependencies - name: Install dependencies
run: npm install run: npm ci
- name: Run types tests - name: Run types tests
run: npx gulp typestest run: npx gulp typestest

7
.gitpod.Dockerfile vendored
View File

@ -1,7 +0,0 @@
FROM gitpod/workspace-full-vnc
USER gitpod
RUN sudo apt-get update && \
sudo apt-get install -yq firefox && \
sudo rm -rf /var/lib/apt/lists/*

View File

@ -1,13 +0,0 @@
image:
file: .gitpod.Dockerfile
tasks:
- command: |
gp await-port 8888 && gp preview $(gp url 8888)/web/viewer.html && echo '[{"name": "Firefox","path": "/usr/bin/firefox"}]' | jq '.' > test/resources/browser_manifests/browser_manifest.json
- init: npm install -g gulp-cli && npm install
command: gulp server
ports:
- port: 8888
onOpen: ignore
- port: 6080
onOpen: ignore

View File

@ -4,8 +4,11 @@ docs/
node_modules/ node_modules/
external/bcmaps/ external/bcmaps/
external/builder/fixtures/ external/builder/fixtures/
external/builder/fixtures_esprima/ external/builder/fixtures_babel/
external/openjpeg/
external/qcms/
external/quickjs/ external/quickjs/
test/stats/results/
test/tmp/ test/tmp/
test/pdfs/ test/pdfs/
web/locale/ web/locale/

View File

@ -9,10 +9,17 @@
"overrides": [ "overrides": [
{ {
files: ["tsconfig.json"], "files": ["tsconfig.json", ".prettierrc"],
options: { "options": {
parser: "json", "parser": "json"
}, }
}, },
{
"files": ["**/*.html"],
"options": {
"parser": "html",
"printWidth": 160
}
}
] ]
} }

9
.puppeteerrc Normal file
View File

@ -0,0 +1,9 @@
{
"chrome": {
"skipDownload": false
},
"firefox": {
"skipDownload": false,
"version": "nightly"
}
}

View File

@ -4,8 +4,9 @@ docs/
node_modules/ node_modules/
external/bcmaps/ external/bcmaps/
external/builder/fixtures/ external/builder/fixtures/
external/builder/fixtures_esprima/ external/builder/fixtures_babel/
external/quickjs/ external/quickjs/
test/stats/results/
test/tmp/ test/tmp/
test/pdfs/ test/pdfs/
web/locale/ web/locale/

35
.svglintrc.js Normal file
View File

@ -0,0 +1,35 @@
export default {
rules: {
valid: true,
custom: [
(reporter, $, ast, { filename }) => {
reporter.name = "no-svg-fill-context-fill";
const svg = $.find("svg");
const fill = svg.attr("fill");
if (fill === "context-fill") {
reporter.error(
"Fill attribute on svg element must not be set to 'context-fill'",
svg[0],
ast
);
}
},
],
},
ignore: [
"build/**",
"l10n/**",
"docs/**",
"node_modules/**",
"external/bcmaps/**",
"external/builder/fixtures/**",
"external/builder/fixtures_babel/**",
"external/quickjs/**",
"test/tmp/**",
"test/pdfs/**",
"web/locale/**",
"*~/**",
],
};

View File

@ -8,16 +8,21 @@ Andreas Gal <gal@mozilla.com>
Artur Adib <aadib@mozilla.com> Artur Adib <aadib@mozilla.com>
Brendan Dahl <bdahl@mozilla.com> Brendan Dahl <bdahl@mozilla.com>
Bill Walker <bwalker@mozilla.com> Bill Walker <bwalker@mozilla.com>
Calixte Denizet <calixte@mozilla.com>
Chris G Jones <cjones@mozilla.com> Chris G Jones <cjones@mozilla.com>
David Quintana <gigaherz@gmail.com> David Quintana <gigaherz@gmail.com>
Emily Wachowiak <ewachowiak@mozilla.com>
Felix Kälberer <@fkaelberer> Felix Kälberer <@fkaelberer>
Jakob Miland <saebekassebil@gmail.com> Jakob Miland <saebekassebil@gmail.com>
Jonas Jenwald <jonas.jenwald@gmail.com> Jonas Jenwald <jonas.jenwald@gmail.com>
Julian Viereck Julian Viereck
Justin D'Arcangelo <justindarc@gmail.com> Justin D'Arcangelo <justindarc@gmail.com>
Kalervo Kujala Kalervo Kujala
Marco Castelluccio <mcastelluccio@mozilla.com>
Marie-Lilas Onanga Ozavino <monangaozavino@mozilla.com>
Michał Gołębiowski-Owczarek <m.goleb@gmail.com> Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
Ophir Lojkine <@lovasoa> Ophir Lojkine <@lovasoa>
Ryan Casey <rcasey@mozilla.com>
Rob Wu <rob@robwu.nl> Rob Wu <rob@robwu.nl>
Shaon Barman <shaon.barman@gmail.com> Shaon Barman <shaon.barman@gmail.com>
Sehyun Park <premed055515@gmail.com> Sehyun Park <premed055515@gmail.com>

View File

@ -1,4 +1,4 @@
# PDF.js [![Build Status](https://github.com/mozilla/pdf.js/workflows/CI/badge.svg?branch=master)](https://github.com/mozilla/pdf.js/actions?query=workflow%3ACI+branch%3Amaster) # PDF.js [![CI](https://github.com/mozilla/pdf.js/actions/workflows/ci.yml/badge.svg?query=branch%3Amaster)](https://github.com/mozilla/pdf.js/actions/workflows/ci.yml?query=branch%3Amaster)
[PDF.js](https://mozilla.github.io/pdf.js/) is a Portable Document Format (PDF) viewer that is built with HTML5. [PDF.js](https://mozilla.github.io/pdf.js/) is a Portable Document Format (PDF) viewer that is built with HTML5.
@ -14,7 +14,7 @@ get involved, visit:
+ [Issue Reporting Guide](https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md) + [Issue Reporting Guide](https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md)
+ [Code Contribution Guide](https://github.com/mozilla/pdf.js/wiki/Contributing) + [Code Contribution Guide](https://github.com/mozilla/pdf.js/wiki/Contributing)
+ [Frequently Asked Questions](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions) + [Frequently Asked Questions](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions)
+ [Good Beginner Bugs](https://github.com/mozilla/pdf.js/issues?direction=desc&labels=good-beginner-bug&page=1&sort=created&state=open) + [Good Beginner Bugs](https://github.com/mozilla/pdf.js/issues?q=is%3Aissue%20state%3Aopen%20label%3Agood-beginner-bug)
+ [Projects](https://github.com/mozilla/pdf.js/projects) + [Projects](https://github.com/mozilla/pdf.js/projects)
Feel free to stop by our [Matrix room](https://chat.mozilla.org/#/room/#pdfjs:mozilla.org) for questions or guidance. Feel free to stop by our [Matrix room](https://chat.mozilla.org/#/room/#pdfjs:mozilla.org) for questions or guidance.
@ -40,7 +40,7 @@ PDF.js is built into version 19+ of Firefox.
+ The official extension for Chrome can be installed from the [Chrome Web Store](https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm). + The official extension for Chrome can be installed from the [Chrome Web Store](https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm).
*This extension is maintained by [@Rob--W](https://github.com/Rob--W).* *This extension is maintained by [@Rob--W](https://github.com/Rob--W).*
+ Build Your Own - Get the code as explained below and issue `gulp chromium`. Then open + Build Your Own - Get the code as explained below and issue `npx gulp chromium`. Then open
Chrome, go to `Tools > Extension` and load the (unpackaged) extension from the Chrome, go to `Tools > Extension` and load the (unpackaged) extension from the
directory `build/chromium`. directory `build/chromium`.
@ -52,24 +52,15 @@ To get a local copy of the current code, clone it using git:
$ cd pdf.js $ cd pdf.js
Next, install Node.js via the [official package](https://nodejs.org) or via Next, install Node.js via the [official package](https://nodejs.org) or via
[nvm](https://github.com/creationix/nvm). You need to install the gulp package [nvm](https://github.com/creationix/nvm). If everything worked out, install
globally (see also [gulp's getting started](https://github.com/gulpjs/gulp/tree/master/docs/getting-started)): all dependencies for PDF.js:
$ npm install -g gulp-cli@^2.3.0
If you prefer to not install `gulp-cli` globally, you have to prefix all the `gulp` commands with `npx` (for example, `npx gulp server` instead of `gulp server`).
If everything worked out, install all dependencies for PDF.js:
$ npm install $ npm install
> [!NOTE]
> On MacOS M1/M2 you may see some `node-gyp`-related errors when running `npm install`. This is because one of our dependencies, `"canvas"`, does not provide pre-built binaries for this platform and instead `npm` will try to build it from source. Please make sure to first install the necessary native dependencies using `brew`: https://github.com/Automattic/node-canvas#compiling.
Finally, you need to start a local web server as some browsers do not allow opening Finally, you need to start a local web server as some browsers do not allow opening
PDF files using a `file://` URL. Run: PDF files using a `file://` URL. Run:
$ gulp server $ npx gulp server
and then you can open: and then you can open:
@ -86,11 +77,11 @@ It is also possible to view all test PDF files on the right side by opening:
In order to bundle all `src/` files into two production scripts and build the generic In order to bundle all `src/` files into two production scripts and build the generic
viewer, run: viewer, run:
$ gulp generic $ npx gulp generic
If you need to support older browsers, run: If you need to support older browsers, run:
$ gulp generic-legacy $ npx gulp generic-legacy
This will generate `pdf.js` and `pdf.worker.js` in the `build/generic/build/` directory (respectively `build/generic-legacy/build/`). This will generate `pdf.js` and `pdf.worker.js` in the `build/generic/build/` directory (respectively `build/generic-legacy/build/`).
Both scripts are needed but only `pdf.js` needs to be included since `pdf.worker.js` will Both scripts are needed but only `pdf.js` needs to be included since `pdf.worker.js` will
@ -99,7 +90,7 @@ be loaded by `pdf.js`. The PDF.js files are large and should be minified for pro
## Using PDF.js in a web application ## Using PDF.js in a web application
To use PDF.js in a web application you can choose to use a pre-built version of the library To use PDF.js in a web application you can choose to use a pre-built version of the library
or to build it from source. We supply pre-built versions for usage with NPM and Bower under or to build it from source. We supply pre-built versions for usage with NPM under
the `pdfjs-dist` name. For more information and examples please refer to the the `pdfjs-dist` name. For more information and examples please refer to the
[wiki page](https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website) on this subject. [wiki page](https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website) on this subject.
@ -116,7 +107,7 @@ You can play with the PDF.js API directly from your browser using the live demos
+ [Interactive examples](https://mozilla.github.io/pdf.js/examples/index.html#interactive-examples) + [Interactive examples](https://mozilla.github.io/pdf.js/examples/index.html#interactive-examples)
More examples can be found in the [examples folder](https://github.com/mozilla/pdf.js/tree/master/examples/). Some of them are using the pdfjs-dist package, which can be built and installed in this repo directory via `gulp dist-install` command. More examples can be found in the [examples folder](https://github.com/mozilla/pdf.js/tree/master/examples/). Some of them are using the pdfjs-dist package, which can be built and installed in this repo directory via `npx gulp dist-install` command.
For an introduction to the PDF.js code, check out the presentation by our For an introduction to the PDF.js code, check out the presentation by our
contributor Julian Viereck: contributor Julian Viereck:
@ -143,4 +134,4 @@ Talk to us on Matrix:
File an issue: File an issue:
+ https://github.com/mozilla/pdf.js/issues/new + https://github.com/mozilla/pdf.js/issues/new/choose

View File

@ -1,20 +0,0 @@
{
"locals": {
"url": "http://localhost:8080",
"name": "PDF.js Documentation",
"description": ""
},
"require": {
"typogr": "typogr"
},
"jade": {
"pretty": true
},
"markdown": {
"smartLists": true,
"smartypants": true
},
"plugins": [
"./plugins/wintersmith-makerelative.coffee"
]
}

View File

@ -1,8 +1,11 @@
--- ---
title: API title: API
template: layout.jade layout: layout.njk
slug: api
--- ---
# API # API
We're currently working on <a href="draft/index.html">better API docs</a>, but the API is well documented in [api.js](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js). The generated API documentation, from the inline comments in [api.js](https://github.com/mozilla/pdf.js/blob/master/src/display/api.js), is available below.
<iframe src="draft/index.html" title="PDF.js API documentation"></iframe>

View File

@ -0,0 +1,100 @@
/*!
Theme: a11y-light
Author: @ericwbailey
Maintainer: @ericwbailey
Based on the Tomorrow Night Eighties theme: https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css
Original source: https://github.com/highlightjs/highlight.js/blob/main/src/styles/a11y-light.css
*/
.hljs {
background: #fefefe;
color: #545454;
}
/* Comment */
.hljs-comment,
.hljs-quote {
color: #696969;
}
/* Red */
.hljs-variable,
.hljs-template-variable,
.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-regexp,
.hljs-deletion {
color: #d91e18;
}
/* Orange */
.hljs-number,
.hljs-built_in,
.hljs-literal,
.hljs-type,
.hljs-params,
.hljs-meta,
.hljs-link {
color: #aa5d00;
}
/* Yellow */
.hljs-attribute {
color: #aa5d00;
}
/* Green */
.hljs-string,
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
color: #008000;
}
/* Blue */
.hljs-title,
.hljs-section {
color: #007faa;
}
/* Purple */
.hljs-keyword,
.hljs-selector-tag {
color: #7928a1;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}
@media screen and (-ms-high-contrast: active) {
.hljs-addition,
.hljs-attribute,
.hljs-built_in,
.hljs-bullet,
.hljs-comment,
.hljs-link,
.hljs-literal,
.hljs-meta,
.hljs-number,
.hljs-params,
.hljs-string,
.hljs-symbol,
.hljs-type,
.hljs-quote {
color: highlight;
}
.hljs-keyword,
.hljs-selector-tag {
font-weight: bold;
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,119 +1,40 @@
body { header {
} background-color: #f8f8f8;
.starter-template { border-bottom: 1px solid #e5e7e8;
padding: 0 15px;
}
.navbar-brand { .navbar-brand {
padding: 4px 15px; padding: 0;
}
.navbar-brand img { img {
height: 42px; height: 42px;
} }
.navbar {
border-color: #e5e7e8;
} }
.navbar-default .navbar-nav > .active > a, }
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus { main {
background-color: #fff; margin: 50px 0;
border: 1px solid #e5e7e8;
border-width: 0 1px; .description {
position: relative; font-size: 20px;
top: 1px; }
pre {
background-color: #f5f5f5;
border: 1px solid #cccccc;
border-radius: 4px;
padding: 10px;
}
iframe {
border: none;
height: calc(0.55 * 100vh);
width: 100%;
}
} }
footer { footer {
padding-top: 40px; border-top: 1px solid #e5e5e5;
padding-bottom: 40px; color: #777777;
margin-top: 100px; padding: 40px 0;
color: #777;
text-align: center; text-align: center;
border-top: 1px solid #E5E5E5;
}
/* code styling */
code {
font-family: 'Anonymous Pro', monospace;
font-size: 0.85em;
color: #000;
}
pre code {
display: block;
line-height: 1.1;
}
p code {
padding: 0.1em 0.3em 0.2em;
border-radius: 0.3em;
position: relative;
top: -0.15em;
background: #444;
color: #fff;
white-space: nowrap;
}
/* syntax hl stuff */
code.lang-markdown {
color: #424242;
}
code.lang-markdown .header,
code.lang-markdown .strong {
font-weight: bold;
}
code.lang-markdown .emphasis {
font-style: italic;
}
code.lang-markdown .horizontal_rule,
code.lang-markdown .link_label,
code.lang-markdown .code,
code.lang-markdown .header,
code.lang-markdown .link_url {
color: #555;
}
code.lang-markdown .blockquote,
code.lang-markdown .bullet {
color: #bbb;
}
/* Tomorrow Theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
.tomorrow-comment, pre .comment, pre .title {
color: #8e908c;
}
.tomorrow-red, pre .variable, pre .attribute, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo {
color: #c82829;
}
.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .literal, pre .params, pre .constant {
color: #f5871f;
}
.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute {
color: #eab700;
}
.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata {
color: #718c00;
}
.tomorrow-aqua, pre .css .hexcolor {
color: #3e999f;
}
.tomorrow-blue, pre .function, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title {
color: #4271ae;
}
.tomorrow-purple, pre .keyword, pre .javascript .function {
color: #8959a8;
} }

View File

@ -1,6 +1,7 @@
--- ---
title: Examples title: Examples
template: layout.jade layout: layout.njk
slug: examples
--- ---
## Hello World Walkthrough ## Hello World Walkthrough
@ -83,17 +84,17 @@ var scaledViewport = page.getViewport({ scale: scale, });
The example demonstrates how promises can be used to handle errors during loading. The example demonstrates how promises can be used to handle errors during loading.
It also demonstrates how to wait until a page is loaded and rendered. It also demonstrates how to wait until a page is loaded and rendered.
<script async src="//jsfiddle.net/pdfjs/9engc9mw/embed/html,css,result/"></script> <script async src="https://jsfiddle.net/pdfjs/9engc9mw/embed/html,css,result/"></script>
### Hello World using base64 encoded PDF ### Hello World using base64 encoded PDF
The PDF.js can accept any decoded base64 data as an array. The PDF.js can accept any decoded base64 data as an array.
<script async src="//jsfiddle.net/pdfjs/cq0asLqz/embed/html,css,result/"></script> <script async src="https://jsfiddle.net/pdfjs/cq0asLqz/embed/html,css,result/"></script>
### Previous/Next example ### Previous/Next example
The same canvas cannot be used to perform to draw two pages at the same time -- The same canvas cannot be used to perform to draw two pages at the same time --
the example demonstrates how to wait on previous operation to be complete. the example demonstrates how to wait on previous operation to be complete.
<script async src="//jsfiddle.net/pdfjs/wagvs9Lf/embed/html,css,result/"></script> <script async src="https://jsfiddle.net/pdfjs/wagvs9Lf/embed/html,css,result/"></script>

View File

@ -1,6 +1,7 @@
--- ---
title: Getting Started title: Getting Started
template: layout.jade layout: layout.njk
slug: getting_started
--- ---
# Getting Started # Getting Started
@ -76,51 +77,50 @@ Note that we only mention the most relevant files and folders.
### Prebuilt ### Prebuilt
``` ```plaintext
├── build/ ├── build/
   ├── pdf.js - display layer ├── pdf.mjs - display layer
   ├── pdf.js.map - display layer's source map ├── pdf.mjs.map - display layer's source map
   ├── pdf.worker.js - core layer ├── pdf.worker.mjs - core layer
   └── pdf.worker.js.map - core layer's source map └── pdf.worker.mjs.map - core layer's source map
├── web/ ├── web/
│ ├── cmaps/ - character maps (required by core) │ ├── cmaps/ - character maps (required by core)
│ ├── compressed.tracemonkey-pldi-09.pdf - PDF file for testing purposes │ ├── compressed.tracemonkey-pldi-09.pdf - PDF file for testing purposes
│ ├── debugger.js - helpful debugging features
│ ├── images/ - images for the viewer and annotation icons │ ├── images/ - images for the viewer and annotation icons
│ ├── locale/ - translation files │ ├── locale/ - translation files
│ ├── viewer.css - viewer style sheet │ ├── viewer.css - viewer style sheet
│ ├── viewer.html - viewer layout │ ├── viewer.html - viewer layout
│ ├── viewer.js - viewer layer │ ├── viewer.mjs - viewer layer
│ └── viewer.js.map - viewer layer's source map │ └── viewer.mjs.map - viewer layer's source map
└── LICENSE └── LICENSE
``` ```
### Source ### Source
``` ```plaintext
├── docs/ - website source code ├── docs/ - website source code
├── examples/ - simple usage examples ├── examples/ - simple usage examples
├── extensions/ - browser extension source code ├── extensions/ - browser extension source code
├── external/ - third party code ├── external/ - third party code
├── l10n/ - translation files ├── l10n/ - translation files
├── src/ ├── src/
   ├── core/ - core layer ├── core/ - core layer
   ├── display/ - display layer ├── display/ - display layer
   ├── shared/ - shared code between the core and display layers ├── shared/ - shared code between the core and display layers
   ├── interfaces.js - interface definitions for the core/display layers ├── interfaces.js - interface definitions for the core/display layers
   └── pdf.*.js - wrapper files for bundling └── pdf.*.js - wrapper files for bundling
├── test/ - unit, font, reference, and integration tests ├── test/ - unit, font, reference, and integration tests
├── web/ - viewer layer ├── web/ - viewer layer
├── LICENSE ├── LICENSE
├── README.md ├── README.md
├── gulpfile.js - build scripts/logic ├── gulpfile.mjs - build scripts/logic
├── package-lock.json - pinned dependency versions ├── package-lock.json - pinned dependency versions
└── package.json - package definition and dependencies └── package.json - package definition and dependencies
``` ```
## Trying the Viewer ## Trying the Viewer
With the prebuilt or source version, open `web/viewer.html` in a browser and the test pdf should load. Note: the worker is not enabled for file:// urls, so use a server. If you're using the source build and have node, you can run `gulp server`. With the prebuilt or source version, open `web/viewer.html` in a browser and the test pdf should load. Note: the worker is not enabled for file:// urls, so use a server. If you're using the source build and have node, you can run `npx gulp server`.
## More Information ## More Information

View File

@ -1,14 +1,13 @@
--- ---
title: PDF.js title: Home
template: layout.jade layout: layout.njk
slug: home
--- ---
<h1 class="text-center">PDF.js</h1> <h1 class="text-center">PDF.js</h1>
<p class="text-center" style="font-size: 20px">A general-purpose, web standards-based platform for parsing and rendering PDFs. <p class="text-center description">A general-purpose, web standards-based platform for parsing and rendering PDFs.</p>
</p>
<p class="text-center"> <p class="text-center">
<a type="button" class="btn btn-lg btn-default" href="getting_started/#download">Download</a> <a type="button" class="btn btn-outline-dark" href="/getting_started/#download">Download</a>
<a type="button" class="btn btn-lg btn-default" href="https://github.com/mozilla/pdf.js#online-demo">Demo</a> <a type="button" class="btn btn-outline-dark" href="https://github.com/mozilla/pdf.js#online-demo">Demo</a>
<a type="button" class="btn btn-lg btn-default" href="https://github.com/mozilla/pdf.js">GitHub Project</a> <a type="button" class="btn btn-outline-dark" href="https://github.com/mozilla/pdf.js">GitHub Project</a>
</p> </p>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
docs/contents/js/jquery-3.7.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,15 +0,0 @@
module.exports = (env, callback) ->
count = (string, substr) ->
num = pos = 0
return 1/0 unless substr.length
num++ while pos = 1 + string.indexOf(substr, pos)
num
env.helpers.makeRelative = (source, dest) ->
return dest unless dest.indexOf("/") == 0
depth = count(source, '/') # 1 being /
ret = ""
ret += "../" while depth = depth - 1
ret + dest.substring(1)
callback()

View File

@ -1,52 +0,0 @@
- makeRelative = env.helpers.makeRelative
doctype html
html(lang='en')
head
meta(charset='utf-8')
meta(name='viewport', content='width=device-width, initial-scale=1.0')
meta(name='description', content='A general-purpose, web standards-based platform for parsing and rendering PDFs.')
meta(name='author', content='')
link(rel='shortcut icon', href=makeRelative(page.url, '/images/favicon.ico'))
title=page.title
// Bootstrap core CSS
link(href=makeRelative(page.url, '/css/bootstrap.min.css'), rel='stylesheet')
// Custom styles for this template
link(href=makeRelative(page.url, '/css/main.css'), rel='stylesheet')
body
header.navbar.navbar-default.navbar-static-top
.container
.navbar-header
button.navbar-toggle(type='button', data-toggle='collapse', data-target='.navbar-collapse')
span.icon-bar
span.icon-bar
span.icon-bar
a.navbar-brand(href='#')
img(src=makeRelative(page.url, '/images/logo.svg'))
.collapse.navbar-collapse
ul.nav.navbar-nav
li(class=(page.url === '/' ? 'active' : ''))
a(href=makeRelative(page.url, '/')) Home
li(class=(page.url === '/getting_started/' ? 'active' : ''))
a(href=makeRelative(page.url, '/getting_started/')) Getting Started
li(class=(page.url === '/examples/' ? 'active' : ''))
a(href=makeRelative(page.url, '/examples/')) Examples
li
a(href='https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions') FAQ
li(class=(page.url === '/api/' ? 'active' : ''))
a(href=makeRelative(page.url, '/api/')) API
.container
.starter-template
section.content!= typogr(page.html).typogrify()
.container
footer
p &copy;Mozilla and individual contributors
:markdown-it
PDF.js is licensed under [Apache](https://github.com/mozilla/pdf.js/blob/master/LICENSE),
documentation is licensed under [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/)
// Bootstrap core JavaScript
script(src=makeRelative(page.url, '/js/jquery-2.1.0.min.js'))
script(src=makeRelative(page.url, '/js/bootstrap.min.js'))

56
docs/templates/layout.njk vendored Normal file
View File

@ -0,0 +1,56 @@
<!doctype html>
<html lang="en">
<head>
<title>{{ sitename }} - {{ title }}</title>
<meta charset="utf-8">
<meta name="description" content="{{ description }}">
<meta name="viewport" content="device-width, initial-scale=1.0">
<script src="/js/jquery-3.7.1.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<link rel="shortcut icon" href="/images/favicon.ico">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/a11y-light.css">
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<div class="navbar-brand"><img src="/images/logo.svg"></div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item {{ 'active' if slug == 'home' else '' }}">
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item {{ 'active' if slug == 'getting_started' else '' }}">
<a class="nav-link" href="/getting_started">Getting started</a>
</li>
<li class="nav-item {{ 'active' if slug == 'examples' else '' }}">
<a class="nav-link" href="/examples">Examples</a>
</li>
<li class="nav-item {{ 'active' if slug == 'api' else '' }}">
<a class="nav-link" href="/api">API</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions">FAQ</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<main class="container">
{{ contents | safe }}
</main>
<footer>
<p>&copy; Mozilla and individual contributors</p>
<p>
PDF.js is licensed under <a href="https://github.com/mozilla/pdf.js/blob/master/LICENSE">Apache 2.0</a>,
documentation is licensed under <a href="https://creativecommons.org/licenses/by-sa/2.5">CC BY-SA 2.5</a>.
</p>
</footer>
</body>
</html>

473
eslint.config.mjs Normal file
View File

@ -0,0 +1,473 @@
import globals from "globals";
import import_ from "eslint-plugin-import";
import jasmine from "eslint-plugin-jasmine";
import json from "eslint-plugin-json";
import noUnsanitized from "eslint-plugin-no-unsanitized";
import perfectionist from "eslint-plugin-perfectionist";
import prettierRecommended from "eslint-plugin-prettier/recommended";
import unicorn from "eslint-plugin-unicorn";
const jsFiles = folder => {
const prefix = folder === "." ? "" : folder + "/";
return [prefix + "**/*.js", prefix + "**/*.jsm", prefix + "**/*.mjs"];
};
// Include all files referenced in extensions/chromium/background.js
const chromiumExtensionServiceWorkerFiles = [
"extensions/chromium/extension-router.js",
"extensions/chromium/options/migration.js",
"extensions/chromium/pdfHandler.js",
"extensions/chromium/preserve-referer.js",
"extensions/chromium/suppress-update.js",
"extensions/chromium/telemetry.js",
];
export default [
{
ignores: [
"**/build/",
"**/l10n/",
"**/docs/",
"**/node_modules/",
"external/bcmaps/",
"external/builder/fixtures/",
"external/builder/fixtures_babel/",
"external/openjpeg/",
"external/qcms/",
"external/quickjs/",
"test/stats/results/",
"test/tmp/",
"test/pdfs/",
"web/locale/",
"web/wasm/",
"**/*~/",
],
},
/* ======================================================================== *\
Base configuration
\* ======================================================================== */
prettierRecommended,
{
files: ["**/*.json"],
...json.configs.recommended,
},
{
files: jsFiles("."),
ignores: chromiumExtensionServiceWorkerFiles,
languageOptions: {
globals: globals.browser,
},
},
{
files: jsFiles("."),
plugins: {
import: import_.flatConfigs.recommended.plugins.import,
json,
"no-unsanitized": noUnsanitized,
perfectionist,
unicorn,
},
languageOptions: {
globals: {
...globals.worker,
PDFJSDev: "readonly",
__raw_import__: "readonly",
},
ecmaVersion: 2025,
sourceType: "module",
},
rules: {
"import/export": "error",
"import/exports-last": "error",
"import/extensions": ["error", "always", { ignorePackages: true }],
"import/first": "error",
"import/named": "error",
"import/no-cycle": "error",
"import/no-empty-named-blocks": "error",
"import/no-commonjs": "error",
"import/no-mutable-exports": "error",
"import/no-restricted-paths": [
"error",
{
zones: [
{
target: "./web",
from: "./src",
},
],
},
],
"import/no-self-import": "error",
"import/no-unresolved": [
"error",
{
ignore: [
"display",
"pdfjs",
"pdfjs-lib",
"pdfjs-web",
"web",
"fluent-bundle",
"fluent-dom",
// See https://github.com/firebase/firebase-admin-node/discussions/1359.
"eslint-plugin-perfectionist",
],
},
],
"no-unsanitized/method": "error",
"no-unsanitized/property": "error",
"perfectionist/sort-exports": "error",
"perfectionist/sort-named-exports": "error",
"unicorn/no-abusive-eslint-disable": "error",
"unicorn/no-array-reduce": ["error", { allowSimpleOperations: true }],
"unicorn/no-console-spaces": "error",
"unicorn/no-instanceof-builtins": "error",
"unicorn/no-invalid-remove-event-listener": "error",
"unicorn/no-new-buffer": "error",
"unicorn/no-single-promise-in-promise-methods": "error",
"unicorn/no-typeof-undefined": ["error", { checkGlobalVariables: false }],
"unicorn/no-unnecessary-array-flat-depth": "error",
"unicorn/no-unnecessary-array-splice-count": "error",
"unicorn/no-unnecessary-slice-end": "error",
"unicorn/no-useless-promise-resolve-reject": "error",
"unicorn/no-useless-spread": "error",
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-flat": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-array-index-of": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-at": "error",
"unicorn/prefer-date-now": "error",
"unicorn/prefer-dom-node-append": "error",
"unicorn/prefer-dom-node-remove": "error",
"unicorn/prefer-import-meta-properties": "error",
"unicorn/prefer-includes": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-modern-dom-apis": "error",
"unicorn/prefer-modern-math-apis": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/prefer-optional-catch-binding": "error",
"unicorn/prefer-regexp-test": "error",
"unicorn/prefer-single-call": "error",
"unicorn/prefer-string-replace-all": "error",
"unicorn/prefer-string-starts-ends-with": "error",
"unicorn/prefer-ternary": ["error", "only-single-line"],
"unicorn/throw-new-error": "error",
// Possible errors
"for-direction": "error",
"getter-return": "error",
"no-async-promise-executor": "error",
"no-cond-assign": ["error", "except-parens"],
"no-constant-condition": ["error", { checkLoops: false }],
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-else-if": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": ["error", { allowEmptyCatch: true }],
"no-empty-character-class": "error",
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
"no-func-assign": "error",
"no-inner-declarations": ["error", "functions"],
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-loss-of-precision": "error",
"no-obj-calls": "error",
"no-promise-executor-return": "error",
"no-regex-spaces": "error",
"no-setter-return": "error",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"no-unsafe-optional-chaining": [
"error",
{ disallowArithmeticOperators: true },
],
"no-unused-private-class-members": "error",
"use-isnan": ["error", { enforceForIndexOf: true }],
"valid-typeof": ["error", { requireStringLiterals: true }],
// Best Practices
"accessor-pairs": [
"error",
{ setWithoutGet: true, enforceForClassMembers: true },
],
"consistent-return": "error",
curly: ["error", "all"],
"default-case-last": "error",
"dot-notation": "error",
eqeqeq: ["error", "always"],
"grouped-accessor-pairs": ["error", "getBeforeSet"],
"no-alert": "error",
"no-caller": "error",
"no-else-return": "error",
"no-empty-pattern": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-fallthrough": "error",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-implied-eval": "error",
"no-iterator": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-multi-str": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-symbol": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-octal": "error",
"no-redeclare": "error",
"no-return-await": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"no-throw-literal": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-useless-call": "error",
"no-useless-catch": "error",
"no-useless-concat": "error",
"no-useless-escape": "error",
"no-useless-return": "error",
"prefer-promise-reject-errors": "error",
"prefer-spread": "error",
"wrap-iife": ["error", "any"],
yoda: ["error", "never", { exceptRange: true }],
// Strict Mode
strict: ["off", "global"],
// Variables
"no-delete-var": "error",
"no-label-var": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-undef-init": "error",
"no-undef": ["error", { typeof: true }],
"no-unused-vars": ["error", { vars: "all", args: "none" }],
"no-use-before-define": [
"error",
{ functions: false, classes: false, variables: false },
],
// Stylistic Issues
"lines-between-class-members": ["error", "always"],
"max-len": ["error", { code: 1000, comments: 80, ignoreUrls: true }],
"new-cap": ["error", { newIsCap: true, capIsNew: false }],
"no-array-constructor": "error",
"no-multiple-empty-lines": ["error", { max: 1, maxEOF: 0, maxBOF: 1 }],
"no-nested-ternary": "error",
"no-new-object": "error",
"no-restricted-syntax": [
"error",
{
selector:
"BinaryExpression[operator='instanceof'][right.name='Object']",
message: "Use `typeof` rather than `instanceof Object`.",
},
{
selector: "CallExpression[callee.name='assert'][arguments.length!=2]",
message: "`assert()` must always be invoked with two arguments.",
},
{
selector: "CallExpression[callee.name='isCmd'][arguments.length<2]",
message:
"Use `instanceof Cmd` rather than `isCmd()` with one argument.",
},
{
selector: "CallExpression[callee.name='isDict'][arguments.length<2]",
message:
"Use `instanceof Dict` rather than `isDict()` with one argument.",
},
{
selector: "CallExpression[callee.name='isName'][arguments.length<2]",
message:
"Use `instanceof Name` rather than `isName()` with one argument.",
},
{
selector: "NewExpression[callee.name='Cmd']",
message: "Use `Cmd.get()` rather than `new Cmd()`.",
},
{
selector: "NewExpression[callee.name='Name']",
message: "Use `Name.get()` rather than `new Name()`.",
},
{
selector: "NewExpression[callee.name='ObjectLoader']",
message:
"Use `ObjectLoader.load()` rather than `new ObjectLoader()`.",
},
{
selector: "NewExpression[callee.name='Ref']",
message: "Use `Ref.get()` rather than `new Ref()`.",
},
{
selector: "ExportNamedDeclaration[declaration]",
message:
"Separate the declaration and the export statement, using `export { ... }`.",
},
{
selector: "ExportDefaultDeclaration:has(> :declaration)",
message:
"Separate the declaration and the export statement, using `export default <variable name>`.",
},
],
"no-unneeded-ternary": "error",
"operator-assignment": "error",
"prefer-exponentiation-operator": "error",
"spaced-comment": ["error", "always", { block: { balanced: true } }],
// ECMAScript 6
"arrow-body-style": ["error", "as-needed"],
"constructor-super": "error",
"no-class-assign": "error",
"no-const-assign": "error",
"no-dupe-class-members": "error",
"no-duplicate-imports": "error",
"no-this-before-super": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-var": "error",
"object-shorthand": ["error", "always", { avoidQuotes: true }],
"prefer-const": "error",
"require-yield": "error",
"sort-imports": ["error", { ignoreCase: true }],
"template-curly-spacing": ["error", "never"],
},
},
{
files: jsFiles("src"),
rules: {
"no-console": "error",
},
},
/* ======================================================================== *\
Test-specific rules
\* ======================================================================== */
{
files: jsFiles("test"),
plugins: { jasmine },
languageOptions: {
globals: {
...globals.node,
...globals.jasmine,
},
},
rules: {
...jasmine.configs.recommended.rules,
"jasmine/new-line-before-expect": "off",
"jasmine/new-line-between-declarations": "off",
"jasmine/no-focused-tests": "error",
"jasmine/no-pending-tests": "off",
"jasmine/no-spec-dupes": ["error", "branch"],
"jasmine/no-suite-dupes": ["error", "branch"],
"jasmine/prefer-jasmine-matcher": "off",
"jasmine/prefer-toHaveBeenCalledWith": "off",
},
},
{
files: jsFiles("test/unit"),
rules: {
"import/no-unresolved": ["error", { ignore: ["pdfjs/"] }],
"no-console": ["error", { allow: ["warn", "error"] }],
},
},
{
files: jsFiles("test/integration"),
rules: {
"no-console": ["error", { allow: ["warn", "error"] }],
"no-restricted-syntax": [
"error",
{
selector: "CallExpression[callee.name='waitForTimeout']",
message:
"`waitForTimeout` can cause intermittent failures and should not be used (see issue #17656 for replacements).",
},
],
},
},
/* ======================================================================== *\
External libraries
\* ======================================================================== */
{
files: jsFiles("external"),
languageOptions: { globals: globals.node },
},
/* ======================================================================== *\
Examples
\* ======================================================================== */
{
files: jsFiles("examples"),
languageOptions: {
globals: {
pdfjsImageDecoders: false,
pdfjsLib: false,
pdfjsViewer: false,
},
},
},
{
files: [...jsFiles("examples/node"), ...jsFiles("examples/webpack")],
languageOptions: { globals: globals.node },
},
/* ======================================================================== *\
Chromium extension
\* ======================================================================== */
{
files: jsFiles("extensions/chromium"),
languageOptions: {
globals: globals.webextensions,
sourceType: "script",
},
rules: {
"no-var": "off",
},
},
{
files: chromiumExtensionServiceWorkerFiles,
languageOptions: {
globals: globals.serviceworker,
sourceType: "script",
},
},
/* ======================================================================== *\
Other
\* ======================================================================== */
{
files: ["gulpfile.mjs"],
languageOptions: { globals: globals.node },
},
];

View File

@ -1,11 +0,0 @@
{
"extends": [
"../.eslintrc"
],
"globals": {
"pdfjsImageDecoders": false,
"pdfjsLib": false,
"pdfjsViewer": false,
},
}

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<!-- <!--
Copyright 2014 Mozilla Foundation Copyright 2014 Mozilla Foundation
@ -16,9 +16,9 @@ limitations under the License.
--> -->
<html dir="ltr" mozdisallowselectionprint> <html dir="ltr" mozdisallowselectionprint>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="google" content="notranslate"> <meta name="google" content="notranslate" />
<title>PDF.js page viewer using built components</title> <title>PDF.js page viewer using built components</title>
<style> <style>
@ -29,7 +29,7 @@ limitations under the License.
} }
</style> </style>
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css"> <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css" />
<script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<!-- <!--
Copyright 2014 Mozilla Foundation Copyright 2014 Mozilla Foundation
@ -16,9 +16,9 @@ limitations under the License.
--> -->
<html dir="ltr" mozdisallowselectionprint> <html dir="ltr" mozdisallowselectionprint>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="google" content="notranslate"> <meta name="google" content="notranslate" />
<title>PDF.js viewer using built components</title> <title>PDF.js viewer using built components</title>
<style> <style>
@ -35,7 +35,7 @@ limitations under the License.
} }
</style> </style>
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css"> <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css" />
<script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<!-- <!--
Copyright 2014 Mozilla Foundation Copyright 2014 Mozilla Foundation
@ -16,9 +16,9 @@ limitations under the License.
--> -->
<html dir="ltr" mozdisallowselectionprint> <html dir="ltr" mozdisallowselectionprint>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="google" content="notranslate"> <meta name="google" content="notranslate" />
<title>PDF.js Single Page Viewer using built components</title> <title>PDF.js Single Page Viewer using built components</title>
<style> <style>
@ -35,7 +35,7 @@ limitations under the License.
} }
</style> </style>
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css"> <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css" />
<script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<!-- <!--
Copyright 2018 Mozilla Foundation Copyright 2018 Mozilla Foundation
@ -16,9 +16,9 @@ limitations under the License.
--> -->
<html dir="ltr" mozdisallowselectionprint> <html dir="ltr" mozdisallowselectionprint>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="google" content="notranslate"> <meta name="google" content="notranslate" />
<title>PDF.js standalone JpegImage parser</title> <title>PDF.js standalone JpegImage parser</title>
<style> <style>

View File

@ -1,14 +1,13 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>'Hello, world!' example</title> <title>'Hello, world!' example</title>
</head> </head>
<body> <body>
<h1>'Hello, world!' example</h1> <h1>'Hello, world!' example</h1>
<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas> <canvas id="the-canvas" style="border: 1px solid black; direction: ltr"></canvas>
<script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
@ -17,13 +16,12 @@
// If absolute URL from the remote server is provided, configure the CORS // If absolute URL from the remote server is provided, configure the CORS
// header on that server. // header on that server.
// //
const url = './helloworld.pdf'; const url = "./helloworld.pdf";
// //
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc = "../../node_modules/pdfjs-dist/build/pdf.worker.mjs";
'../../node_modules/pdfjs-dist/build/pdf.worker.mjs';
// //
// Asynchronous download PDF // Asynchronous download PDF
@ -50,9 +48,7 @@
canvas.style.width = Math.floor(viewport.width) + "px"; canvas.style.width = Math.floor(viewport.width) + "px";
canvas.style.height = Math.floor(viewport.height) + "px"; canvas.style.height = Math.floor(viewport.height) + "px";
const transform = outputScale !== 1 const transform = outputScale !== 1 ? [outputScale, 0, 0, outputScale, 0, 0] : null;
? [outputScale, 0, 0, outputScale, 0, 0]
: null;
// //
// Render PDF page into canvas context // Render PDF page into canvas context
@ -65,12 +61,11 @@
page.render(renderContext); page.render(renderContext);
</script> </script>
<hr> <hr />
<h2>JavaScript code:</h2> <h2>JavaScript code:</h2>
<pre id="code"></pre> <pre id="code"></pre>
<script> <script>
document.getElementById('code').textContent = document.getElementById("code").textContent = document.getElementById("script").text;
document.getElementById('script').text;
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,14 +1,13 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>'Hello, world!' base64 example</title> <title>'Hello, world!' base64 example</title>
</head> </head>
<body> <body>
<h1>'Hello, world!' example</h1> <h1>'Hello, world!' example</h1>
<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas> <canvas id="the-canvas" style="border: 1px solid black; direction: ltr"></canvas>
<script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
@ -17,49 +16,47 @@
// (See also https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/ // (See also https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/
// Base64_encoding_and_decoding.) // Base64_encoding_and_decoding.)
var pdfData = atob( var pdfData = atob(
'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' + "JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog" +
'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' + "IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv" +
'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' + "TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K" +
'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' + "Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg" +
'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' + "L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+" +
'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' + "PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u" +
'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' + "dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq" +
'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' + "Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU" +
'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' + "CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu" +
'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' + "ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g" +
'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' + "CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw" +
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + "MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v" +
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G'); "dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G"
);
// //
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc = "../../node_modules/pdfjs-dist/build/pdf.worker.mjs";
'../../node_modules/pdfjs-dist/build/pdf.worker.mjs';
// Opening PDF by passing its binary data as a string. It is still preferable // Opening PDF by passing its binary data as a string. It is still preferable
// to use Uint8Array, but string or array-like structure will work too. // to use Uint8Array, but string or array-like structure will work too.
var loadingTask = pdfjsLib.getDocument({ data: pdfData, }); var loadingTask = pdfjsLib.getDocument({ data: pdfData });
var pdf = await loadingTask.promise; var pdf = await loadingTask.promise;
// Fetch the first page. // Fetch the first page.
var page = await pdf.getPage(1); var page = await pdf.getPage(1);
var scale = 1.5; var scale = 1.5;
var viewport = page.getViewport({ scale: scale, }); var viewport = page.getViewport({ scale: scale });
// Support HiDPI-screens. // Support HiDPI-screens.
var outputScale = window.devicePixelRatio || 1; var outputScale = window.devicePixelRatio || 1;
// Prepare canvas using PDF page dimensions. // Prepare canvas using PDF page dimensions.
var canvas = document.getElementById('the-canvas'); var canvas = document.getElementById("the-canvas");
var context = canvas.getContext('2d'); var context = canvas.getContext("2d");
canvas.width = Math.floor(viewport.width * outputScale); canvas.width = Math.floor(viewport.width * outputScale);
canvas.height = Math.floor(viewport.height * outputScale); canvas.height = Math.floor(viewport.height * outputScale);
canvas.style.width = Math.floor(viewport.width) + "px"; canvas.style.width = Math.floor(viewport.width) + "px";
canvas.style.height = Math.floor(viewport.height) + "px"; canvas.style.height = Math.floor(viewport.height) + "px";
var transform = outputScale !== 1 var transform = outputScale !== 1 ? [outputScale, 0, 0, outputScale, 0, 0] : null;
? [outputScale, 0, 0, outputScale, 0, 0]
: null;
// Render PDF page into canvas context. // Render PDF page into canvas context.
var renderContext = { var renderContext = {
@ -70,12 +67,11 @@
page.render(renderContext); page.render(renderContext);
</script> </script>
<hr> <hr />
<h2>JavaScript code:</h2> <h2>JavaScript code:</h2>
<pre id="code"></pre> <pre id="code"></pre>
<script> <script>
document.getElementById('code').textContent = document.getElementById("code").textContent = document.getElementById("script").text;
document.getElementById('script').text;
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,22 +1,21 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>Previous/Next example</title> <title>Previous/Next example</title>
</head> </head>
<body> <body>
<h1>'Previous/Next' example</h1> <h1>'Previous/Next' example</h1>
<div> <div>
<button id="prev">Previous</button> <button id="prev" type="button">Previous</button>
<button id="next">Next</button> <button id="next" type="button">Next</button>
&nbsp; &nbsp; &nbsp; &nbsp;
<span>Page: <span id="page_num"></span> / <span id="page_count"></span></span> <span>Page: <span id="page_num"></span> / <span id="page_count"></span></span>
</div> </div>
<div> <div>
<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas> <canvas id="the-canvas" style="border: 1px solid black; direction: ltr"></canvas>
</div> </div>
<script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
@ -26,23 +25,22 @@
// If absolute URL from the remote server is provided, configure the CORS // If absolute URL from the remote server is provided, configure the CORS
// header on that server. // header on that server.
// //
var url = '../../web/compressed.tracemonkey-pldi-09.pdf'; var url = "../../web/compressed.tracemonkey-pldi-09.pdf";
// //
// In cases when the pdf.worker.js is located at the different folder than the // In cases when the pdf.worker.js is located at the different folder than the
// PDF.js's one, or the PDF.js is executed via eval(), the workerSrc property // PDF.js's one, or the PDF.js is executed via eval(), the workerSrc property
// shall be specified. // shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc = "../../node_modules/pdfjs-dist/build/pdf.worker.mjs";
'../../node_modules/pdfjs-dist/build/pdf.worker.mjs';
var pdfDoc = null, var pdfDoc = null,
pageNum = 1, pageNum = 1,
pageRendering = false, pageRendering = false,
pageNumPending = null, pageNumPending = null,
scale = 0.8, scale = 0.8,
canvas = document.getElementById('the-canvas'), canvas = document.getElementById("the-canvas"),
ctx = canvas.getContext('2d'); ctx = canvas.getContext("2d");
/** /**
* Get page info from document, resize canvas accordingly, and render page. * Get page info from document, resize canvas accordingly, and render page.
@ -52,7 +50,7 @@
pageRendering = true; pageRendering = true;
// Using promise to fetch the page // Using promise to fetch the page
pdfDoc.getPage(num).then(function (page) { pdfDoc.getPage(num).then(function (page) {
var viewport = page.getViewport({ scale: scale, }); var viewport = page.getViewport({ scale: scale });
// Support HiDPI-screens. // Support HiDPI-screens.
var outputScale = window.devicePixelRatio || 1; var outputScale = window.devicePixelRatio || 1;
@ -61,9 +59,7 @@
canvas.style.width = Math.floor(viewport.width) + "px"; canvas.style.width = Math.floor(viewport.width) + "px";
canvas.style.height = Math.floor(viewport.height) + "px"; canvas.style.height = Math.floor(viewport.height) + "px";
var transform = outputScale !== 1 var transform = outputScale !== 1 ? [outputScale, 0, 0, outputScale, 0, 0] : null;
? [outputScale, 0, 0, outputScale, 0, 0]
: null;
// Render PDF page into canvas context // Render PDF page into canvas context
var renderContext = { var renderContext = {
@ -85,7 +81,7 @@
}); });
// Update page counters // Update page counters
document.getElementById('page_num').textContent = num; document.getElementById("page_num").textContent = num;
} }
/** /**
@ -110,7 +106,7 @@
pageNum--; pageNum--;
queueRenderPage(pageNum); queueRenderPage(pageNum);
} }
document.getElementById('prev').addEventListener('click', onPrevPage); document.getElementById("prev").addEventListener("click", onPrevPage);
/** /**
* Displays next page. * Displays next page.
@ -122,18 +118,17 @@
pageNum++; pageNum++;
queueRenderPage(pageNum); queueRenderPage(pageNum);
} }
document.getElementById('next').addEventListener('click', onNextPage); document.getElementById("next").addEventListener("click", onNextPage);
/** /**
* Asynchronously downloads PDF. * Asynchronously downloads PDF.
*/ */
var loadingTask = pdfjsLib.getDocument(url); var loadingTask = pdfjsLib.getDocument(url);
pdfDoc = await loadingTask.promise; pdfDoc = await loadingTask.promise;
document.getElementById('page_count').textContent = pdfDoc.numPages; document.getElementById("page_count").textContent = pdfDoc.numPages;
// Initial/first page rendering // Initial/first page rendering
renderPage(pageNum); renderPage(pageNum);
</script> </script>
</body> </body>
</html> </html>

View File

@ -113,8 +113,8 @@ footer {
background-color: rgb(0 0 0 / 0); background-color: rgb(0 0 0 / 0);
font-size: 1.2rem; font-size: 1.2rem;
color: rgb(255 255 255 / 1); color: rgb(255 255 255 / 1);
background-image: url(images/div_line_left.png), background-image:
url(images/div_line_right.png); url(images/div_line_left.png), url(images/div_line_right.png);
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: left, right; background-position: left, right;
background-size: 0.2rem, 0.2rem; background-size: 0.2rem, 0.2rem;

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<!-- <!--
Copyright 2016 Mozilla Foundation Copyright 2016 Mozilla Foundation
@ -16,13 +16,13 @@ limitations under the License.
--> -->
<html dir="ltr"> <html dir="ltr">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>PDF.js viewer</title> <title>PDF.js viewer</title>
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css"> <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css" />
<link rel="stylesheet" type="text/css" href="viewer.css"> <link rel="stylesheet" type="text/css" href="viewer.css" />
<script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script>
@ -43,13 +43,13 @@ limitations under the License.
</div> </div>
<footer> <footer>
<button class="toolbarButton pageUp" title="Previous Page" id="previous"></button> <button class="toolbarButton pageUp" title="Previous Page" id="previous" type="button"></button>
<button class="toolbarButton pageDown" title="Next Page" id="next"></button> <button class="toolbarButton pageDown" title="Next Page" id="next" type="button"></button>
<input type="number" id="pageNumber" class="toolbarField pageNumber" value="1" size="4" min="1"> <input type="number" id="pageNumber" class="toolbarField pageNumber" value="1" size="4" min="1" />
<button class="toolbarButton zoomOut" title="Zoom Out" id="zoomOut"></button> <button class="toolbarButton zoomOut" title="Zoom Out" id="zoomOut" type="button"></button>
<button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn"></button> <button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn" type="button"></button>
</footer> </footer>
<script src="viewer.mjs" type="module"></script> <script src="viewer.mjs" type="module"></script>

View File

@ -91,10 +91,10 @@ const PDFViewerApplication = {
let key = "pdfjs-loading-error"; let key = "pdfjs-loading-error";
if (reason instanceof pdfjsLib.InvalidPDFException) { if (reason instanceof pdfjsLib.InvalidPDFException) {
key = "pdfjs-invalid-file-error"; key = "pdfjs-invalid-file-error";
} else if (reason instanceof pdfjsLib.MissingPDFException) { } else if (reason instanceof pdfjsLib.ResponseException) {
key = "pdfjs-missing-file-error"; key = reason.missing
} else if (reason instanceof pdfjsLib.UnexpectedResponseException) { ? "pdfjs-missing-file-error"
key = "pdfjs-unexpected-response-error"; : "pdfjs-unexpected-response-error";
} }
self.l10n.get(key).then(msg => { self.l10n.get(key).then(msg => {
self.error(msg, { message: reason?.message }); self.error(msg, { message: reason?.message });

View File

@ -1,9 +0,0 @@
{
"extends": [
"../.eslintrc"
],
"env": {
"node": true,
},
}

View File

@ -9,9 +9,7 @@ Install the dependencies and build the PDF.js library:
$ npm install $ npm install
$ gulp dist-install $ gulp dist-install
Install the Node canvas library and run the example to convert the first page of a Run the example to convert the first page of a PDF file to a PNG image:
PDF file to a PNG image:
$ npm install canvas
$ cd examples/node/pdf2png $ cd examples/node/pdf2png
$ node pdf2png.js $ node pdf2png.mjs

View File

@ -13,41 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { strict as assert } from "assert";
import Canvas from "canvas";
import fs from "fs"; import fs from "fs";
import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs"; import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
class NodeCanvasFactory {
create(width, height) {
assert(width > 0 && height > 0, "Invalid canvas size");
const canvas = Canvas.createCanvas(width, height);
const context = canvas.getContext("2d");
return {
canvas,
context,
};
}
reset(canvasAndContext, width, height) {
assert(canvasAndContext.canvas, "Canvas is not specified");
assert(width > 0 && height > 0, "Invalid canvas size");
canvasAndContext.canvas.width = width;
canvasAndContext.canvas.height = height;
}
destroy(canvasAndContext) {
assert(canvasAndContext.canvas, "Canvas is not specified");
// Zeroing the width and height cause Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption.
canvasAndContext.canvas.width = 0;
canvasAndContext.canvas.height = 0;
canvasAndContext.canvas = null;
canvasAndContext.context = null;
}
}
// Some PDFs need external cmaps. // Some PDFs need external cmaps.
const CMAP_URL = "../../../node_modules/pdfjs-dist/cmaps/"; const CMAP_URL = "../../../node_modules/pdfjs-dist/cmaps/";
const CMAP_PACKED = true; const CMAP_PACKED = true;
@ -56,8 +24,6 @@ const CMAP_PACKED = true;
const STANDARD_FONT_DATA_URL = const STANDARD_FONT_DATA_URL =
"../../../node_modules/pdfjs-dist/standard_fonts/"; "../../../node_modules/pdfjs-dist/standard_fonts/";
const canvasFactory = new NodeCanvasFactory();
// Loading file from file system into typed array. // Loading file from file system into typed array.
const pdfPath = const pdfPath =
process.argv[2] || "../../../web/compressed.tracemonkey-pldi-09.pdf"; process.argv[2] || "../../../web/compressed.tracemonkey-pldi-09.pdf";
@ -69,7 +35,6 @@ const loadingTask = getDocument({
cMapUrl: CMAP_URL, cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
standardFontDataUrl: STANDARD_FONT_DATA_URL, standardFontDataUrl: STANDARD_FONT_DATA_URL,
canvasFactory,
}); });
try { try {
@ -78,6 +43,7 @@ try {
// Get the first page. // Get the first page.
const page = await pdfDocument.getPage(1); const page = await pdfDocument.getPage(1);
// Render the page on a Node canvas with 100% scale. // Render the page on a Node canvas with 100% scale.
const canvasFactory = pdfDocument.canvasFactory;
const viewport = page.getViewport({ scale: 1.0 }); const viewport = page.getViewport({ scale: 1.0 });
const canvasAndContext = canvasFactory.create( const canvasAndContext = canvasFactory.create(
viewport.width, viewport.width,
@ -91,7 +57,7 @@ try {
const renderTask = page.render(renderContext); const renderTask = page.render(renderContext);
await renderTask.promise; await renderTask.promise;
// Convert the canvas to an image buffer. // Convert the canvas to an image buffer.
const image = canvasAndContext.canvas.toBuffer(); const image = canvasAndContext.canvas.toBuffer("image/png");
fs.writeFile("output.png", image, function (error) { fs.writeFile("output.png", image, function (error) {
if (error) { if (error) {
console.error("Error: " + error); console.error("Error: " + error);

View File

@ -1,14 +1,13 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>Text-only PDF.js example</title> <title>Text-only PDF.js example</title>
<script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="pdf2svg.mjs" type="module"></script> <script src="pdf2svg.mjs" type="module"></script>
</head> </head>
<body> <body>
<p>Text-only PDF.js example</p> <p>Text-only PDF.js example</p>
<div id="pageContainer" style="display: inline-block; border: solid 1px black;"> <div id="pageContainer" style="display: inline-block; border: solid 1px black"></div>
</div>
</body> </body>
</html> </html>

View File

@ -1,9 +0,0 @@
{
"extends": [
"../.eslintrc"
],
"env": {
"node": true,
},
}

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>webpack example</title> <title>webpack example</title>
<script src="../../build/webpack/main.bundle.js"></script> <script src="../../build/webpack/main.bundle.js"></script>
</head> </head>

View File

@ -1,22 +0,0 @@
{
"extends": [
../../.eslintrc
],
"env": {
"webextensions": true
},
"plugins": [
"mozilla"
],
"parserOptions": {
"sourceType": "script"
},
"rules": {
"mozilla/import-globals": "error",
"no-var": "off",
},
}

View File

@ -1,6 +1,5 @@
<!doctype html> /*
<!-- Copyright 2024 Mozilla Foundation
Copyright 2015 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -13,5 +12,15 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> */
<script src="restoretab.js"></script>
"use strict";
importScripts(
"options/migration.js",
"preserve-referer.js",
"pdfHandler.js",
"extension-router.js",
"suppress-update.js",
"telemetry.js"
);

View File

@ -16,13 +16,16 @@ limitations under the License.
"use strict"; "use strict";
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html"); var VIEWER_URL = chrome.runtime.getURL("content/web/viewer.html");
function getViewerURL(pdf_url) { function getViewerURL(pdf_url) {
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url); return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url);
} }
document.addEventListener("animationstart", onAnimationStart, true); document.addEventListener("animationstart", onAnimationStart, true);
if (document.contentType === "application/pdf") {
chrome.runtime.sendMessage({ action: "canRequestBody" }, maybeRenderPdfDoc);
}
function onAnimationStart(event) { function onAnimationStart(event) {
if (event.animationName === "pdfjs-detected-object-or-embed") { if (event.animationName === "pdfjs-detected-object-or-embed") {
@ -221,3 +224,38 @@ function getEmbeddedViewerURL(path) {
path = a.href; path = a.href;
return getViewerURL(path) + fragment; return getViewerURL(path) + fragment;
} }
function maybeRenderPdfDoc(isNotPOST) {
if (!isNotPOST) {
// The document was loaded through a POST request, but we cannot access the
// original response body, nor safely send a new request to fetch the PDF.
// Until #4483 is fixed, POST requests should be ignored.
return;
}
// Detected PDF that was not redirected by the declarativeNetRequest rules.
// Maybe because this was served without Content-Type and sniffed as PDF.
// Or because this is Chrome 127-, which does not support responseHeaders
// condition in declarativeNetRequest (DNR), and PDF requests are therefore
// not redirected via DNR.
// In any case, load the viewer.
console.log(`Detected PDF via document, opening viewer for ${document.URL}`);
// Ideally we would use logic consistent with the DNR logic, like this:
// location.href = getEmbeddedViewerURL(document.URL);
// ... unfortunately, this causes Chrome to crash until version 129, fixed by
// https://chromium.googlesource.com/chromium/src/+/8c42358b2cc549553d939efe7d36515d80563da7%5E%21/
// Work around this by replacing the body with an iframe of the viewer.
// Interestingly, Chrome's built-in PDF viewer uses a similar technique.
const shadowRoot = document.body.attachShadow({ mode: "closed" });
const iframe = document.createElement("iframe");
iframe.style.position = "absolute";
iframe.style.top = "0";
iframe.style.left = "0";
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.border = "0 none";
iframe.src = getEmbeddedViewerURL(document.URL);
shadowRoot.append(iframe);
}

View File

@ -17,13 +17,12 @@ limitations under the License.
"use strict"; "use strict";
(function ExtensionRouterClosure() { (function ExtensionRouterClosure() {
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html"); var VIEWER_URL = chrome.runtime.getURL("content/web/viewer.html");
var CRX_BASE_URL = chrome.extension.getURL("/"); var CRX_BASE_URL = chrome.runtime.getURL("/");
var schemes = [ var schemes = [
"http", "http",
"https", "https",
"ftp",
"file", "file",
"chrome-extension", "chrome-extension",
"blob", "blob",
@ -47,6 +46,7 @@ limitations under the License.
} }
var scheme = url.slice(0, schemeIndex).toLowerCase(); var scheme = url.slice(0, schemeIndex).toLowerCase();
if (schemes.includes(scheme)) { if (schemes.includes(scheme)) {
// NOTE: We cannot use the `updateUrlHash` function in this context.
url = url.split("#", 1)[0]; url = url.split("#", 1)[0];
if (url.charAt(schemeIndex) === ":") { if (url.charAt(schemeIndex) === ":") {
url = encodeURIComponent(url); url = encodeURIComponent(url);
@ -56,73 +56,50 @@ limitations under the License.
return undefined; return undefined;
} }
// TODO(rob): Use declarativeWebRequest once declared URL-encoding is function resolveViewerURL(originalUrl) {
// supported, see http://crbug.com/273589 if (originalUrl.startsWith(CRX_BASE_URL)) {
// (or rewrite the query string parser in viewer.js to get it to
// recognize the non-URL-encoded PDF URL.)
chrome.webRequest.onBeforeRequest.addListener(
function (details) {
// This listener converts chrome-extension://.../http://...pdf to // This listener converts chrome-extension://.../http://...pdf to
// chrome-extension://.../content/web/viewer.html?file=http%3A%2F%2F...pdf // chrome-extension://.../content/web/viewer.html?file=http%3A%2F%2F...pdf
var url = parseExtensionURL(details.url); var url = parseExtensionURL(originalUrl);
if (url) { if (url) {
url = VIEWER_URL + "?file=" + url; url = VIEWER_URL + "?file=" + url;
var i = details.url.indexOf("#"); var i = originalUrl.indexOf("#");
if (i > 0) { if (i > 0) {
url += details.url.slice(i); url += originalUrl.slice(i);
}
return url;
} }
console.log("Redirecting " + details.url + " to " + url);
return { redirectUrl: url };
} }
return undefined; return undefined;
}
self.addEventListener("fetch", event => {
const req = event.request;
if (req.destination === "document") {
var url = resolveViewerURL(req.url);
if (url) {
console.log("Redirecting " + req.url + " to " + url);
event.respondWith(Response.redirect(url));
}
}
});
// Ctrl + F5 bypasses service worker. the pretty extension URLs will fail to
// resolve in that case. Catch this and redirect to destination.
chrome.webNavigation.onErrorOccurred.addListener(
details => {
if (details.frameId !== 0) {
// Not a top-level frame. Cannot easily navigate a specific child frame.
return;
}
const url = resolveViewerURL(details.url);
if (url) {
console.log(`Redirecting ${details.url} to ${url} (fallback)`);
chrome.tabs.update(details.tabId, { url });
}
}, },
{ { url: [{ urlPrefix: CRX_BASE_URL }] }
types: ["main_frame", "sub_frame"],
urls: schemes.map(function (scheme) {
// Format: "chrome-extension://[EXTENSIONID]/<scheme>*"
return CRX_BASE_URL + scheme + "*";
}),
},
["blocking"]
); );
// When session restore is used, viewer pages may be loaded before the
// webRequest event listener is attached (= page not found).
// Or the extension could have been crashed (OOM), leaving a sad tab behind.
// Reload these tabs.
chrome.tabs.query(
{
url: CRX_BASE_URL + "*:*",
},
function (tabsFromLastSession) {
for (const { id } of tabsFromLastSession) {
chrome.tabs.reload(id);
}
}
);
console.log("Set up extension URL router."); console.log("Set up extension URL router.");
Object.keys(localStorage).forEach(function (key) {
// The localStorage item is set upon unload by chromecom.js.
var parsedKey = /^unload-(\d+)-(true|false)-(.+)/.exec(key);
if (parsedKey) {
var timeStart = parseInt(parsedKey[1], 10);
var isHidden = parsedKey[2] === "true";
var url = parsedKey[3];
if (Date.now() - timeStart < 3000) {
// Is it a new item (younger than 3 seconds)? Assume that the extension
// just reloaded, so restore the tab (work-around for crbug.com/511670).
chrome.tabs.create({
url:
chrome.runtime.getURL("restoretab.html") +
"?" +
encodeURIComponent(url) +
"#" +
encodeURIComponent(localStorage.getItem(key)),
active: !isHidden,
});
}
localStorage.removeItem(key);
}
});
})(); })();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,6 +1,6 @@
{ {
"minimum_chrome_version": "88", "minimum_chrome_version": "103",
"manifest_version": 2, "manifest_version": 3,
"name": "PDF Viewer", "name": "PDF Viewer",
"version": "PDFJSSCRIPT_VERSION", "version": "PDFJSSCRIPT_VERSION",
"description": "Uses HTML5 to display PDF files directly in the browser.", "description": "Uses HTML5 to display PDF files directly in the browser.",
@ -10,61 +10,52 @@
"16": "icon16.png" "16": "icon16.png"
}, },
"permissions": [ "permissions": [
"fileBrowserHandler", "alarms",
"declarativeNetRequestWithHostAccess",
"webRequest", "webRequest",
"webRequestBlocking",
"<all_urls>",
"tabs", "tabs",
"webNavigation", "webNavigation",
"storage" "storage"
], ],
"host_permissions": ["<all_urls>"],
"content_scripts": [ "content_scripts": [
{ {
"matches": ["http://*/*", "https://*/*", "ftp://*/*", "file://*/*"], "matches": ["http://*/*", "https://*/*", "file://*/*"],
"run_at": "document_start", "run_at": "document_start",
"all_frames": true, "all_frames": true,
"css": ["contentstyle.css"], "css": ["contentstyle.css"],
"js": ["contentscript.js"] "js": ["contentscript.js"]
} }
], ],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", "content_security_policy": {
"file_browser_handlers": [ "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
{ },
"id": "open-as-pdf",
"default_title": "Open with PDF Viewer",
"file_filters": ["filesystem:*.pdf"]
}
],
"storage": { "storage": {
"managed_schema": "preferences_schema.json" "managed_schema": "preferences_schema.json"
}, },
"options_ui": { "options_ui": {
"page": "options/options.html", "page": "options/options.html"
"chrome_style": true
}, },
"options_page": "options/options.html", "options_page": "options/options.html",
"background": { "background": {
"page": "pdfHandler.html" "service_worker": "background.js"
},
"page_action": {
"default_icon": {
"19": "icon19.png",
"38": "icon38.png"
},
"default_title": "Show PDF URL",
"default_popup": "pageActionPopup.html"
}, },
"incognito": "split", "incognito": "split",
"web_accessible_resources": [ "web_accessible_resources": [
{
"resources": [
"content/web/viewer.html", "content/web/viewer.html",
"http:/*", "http:/*",
"https:/*", "https:/*",
"ftp:/*",
"file:/*", "file:/*",
"chrome-extension:/*", "chrome-extension:/*",
"blob:*", "blob:*",
"data:*", "data:*",
"filesystem:/*", "filesystem:/*",
"drive:*" "drive:*"
],
"matches": ["<all_urls>"],
"extension_ids": ["*"]
}
] ]
} }

View File

@ -13,10 +13,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* eslint strict: ["error", "function"] */
(function () {
"use strict"; "use strict";
chrome.runtime.onInstalled.addListener(({ reason }) => {
if (reason !== "update") {
// We only need to run migration logic for extension updates, not for new
// installs or browser updates.
return;
}
var storageLocal = chrome.storage.local; var storageLocal = chrome.storage.local;
var storageSync = chrome.storage.sync; var storageSync = chrome.storage.sync;
@ -37,16 +41,12 @@ limitations under the License.
}); });
}); });
function getStorageNames(callback) { async function getStorageNames(callback) {
var x = new XMLHttpRequest();
var schema_location = chrome.runtime.getManifest().storage.managed_schema; var schema_location = chrome.runtime.getManifest().storage.managed_schema;
x.open("get", chrome.runtime.getURL(schema_location)); var res = await fetch(chrome.runtime.getURL(schema_location));
x.onload = function () { var storageManifest = await res.json();
var storageKeys = Object.keys(x.response.properties); var storageKeys = Object.keys(storageManifest.properties);
callback(storageKeys); callback(storageKeys);
};
x.responseType = "json";
x.send();
} }
// Save |values| to storage.sync and delete the values with that key from // Save |values| to storage.sync and delete the values with that key from
@ -150,4 +150,4 @@ limitations under the License.
} }
); );
} }
})(); });

View File

@ -16,28 +16,33 @@ limitations under the License.
--> -->
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<title>PDF.js viewer options</title> <title>PDF.js viewer options</title>
<style> <style>
/* TODO: Remove as much custom CSS as possible - crbug.com/446511 */
body { body {
min-width: 400px; /* a page at the settings page is at least 400px wide */ min-width: 400px; /* a page at the settings page is at least 400px wide */
margin: 14px 17px; /* already added by default in Chrome 40.0.2212.0 */ margin: 14px 17px; /* already added by default in Chrome 40.0.2212.0 */
} }
.settings-row { .settings-row {
margin: 0.65em 0; margin: 1em 0;
}
.checkbox label {
display: inline-flex;
align-items: center;
}
.checkbox label input {
flex-shrink: 0;
} }
</style> </style>
</head> </head>
<body> <body>
<div id="settings-boxes"></div> <div id="settings-boxes"></div>
<button id="reset-button">Restore default settings</button> <button id="reset-button" type="button">Restore default settings</button>
<template id="checkbox-template"> <template id="checkbox-template">
<!-- Chromium's style: //src/extensions/renderer/resources/extension.css --> <div class="settings-row checkbox">
<div class="checkbox">
<label> <label>
<input type="checkbox"> <input type="checkbox" />
<span></span> <span></span>
</label> </label>
</div> </div>

View File

@ -1,45 +0,0 @@
/*
Copyright 2014 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
"use strict";
(function PageActionClosure() {
/**
* @param {number} tabId - ID of tab where the page action will be shown.
* @param {string} url - URL to be displayed in page action.
*/
function showPageAction(tabId, displayUrl) {
// rewriteUrlClosure in viewer.js ensures that the URL looks like
// chrome-extension://[extensionid]/http://example.com/file.pdf
var url = /^chrome-extension:\/\/[a-p]{32}\/([^#]+)/.exec(displayUrl);
if (url) {
url = url[1];
chrome.pageAction.setPopup({
tabId,
popup: "/pageAction/popup.html?file=" + encodeURIComponent(url),
});
chrome.pageAction.show(tabId);
} else {
console.log("Unable to get PDF url from " + displayUrl);
}
}
chrome.runtime.onMessage.addListener(function (message, sender) {
if (message === "showPageAction" && sender.tab) {
showPageAction(sender.tab.id, sender.tab.url);
}
});
})();

View File

@ -1,44 +0,0 @@
<!doctype html>
<!--
Copyright 2012 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
html {
/* maximum width of popup as defined in Chromium's source code as kMaxWidth
//src/chrome/browser/ui/views/extensions/extension_popup.cc
//src/chrome/browser/ui/gtk/extensions/extension_popup_gtk.cc
*/
width: 800px;
/* in case Chromium decides to lower the value of kMaxWidth */
max-width: 100%;
margin: 0;
padding: 0;
}
body {
box-sizing: border-box;
margin: 0;
padding: 5px;
width: 100%;
}
</style>
</head>
<body contentEditable="plaintext-only" spellcheck="false">
<script src="popup.js"></script>
</body>
</html>

View File

@ -1,25 +0,0 @@
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";
var url = location.search.match(/[&?]file=([^&]+)/i);
if (url) {
url = decodeURIComponent(url[1]);
document.body.textContent = url;
// Set cursor to end of the content-editable section.
window.getSelection().selectAllChildren(document.body);
window.getSelection().collapseToEnd();
}

View File

@ -1,102 +0,0 @@
/*
Copyright 2014 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* eslint strict: ["error", "function"] */
/* import-globals-from pdfHandler.js */
(function () {
"use strict";
if (!chrome.fileBrowserHandler) {
// Not on Chromium OS, bail out
return;
}
chrome.fileBrowserHandler.onExecute.addListener(onExecuteFileBrowserHandler);
/**
* Invoked when "Open with PDF Viewer" is chosen in the File browser.
*
* @param {string} id File browser action ID as specified in
* manifest.json
* @param {Object} details Object of type FileHandlerExecuteEventDetails
*/
function onExecuteFileBrowserHandler(id, details) {
if (id !== "open-as-pdf") {
return;
}
var fileEntries = details.entries;
// "tab_id" is the currently documented format, but it is inconsistent with
// the other Chrome APIs that use "tabId" (http://crbug.com/179767)
var tabId = details.tab_id || details.tabId;
if (tabId > 0) {
chrome.tabs.get(tabId, function (tab) {
openViewer(tab && tab.windowId, fileEntries);
});
} else {
// Re-use existing window, if available.
chrome.windows.getLastFocused(function (chromeWindow) {
var windowId = chromeWindow && chromeWindow.id;
if (windowId) {
chrome.windows.update(windowId, { focused: true });
}
openViewer(windowId, fileEntries);
});
}
}
/**
* Open the PDF Viewer for the given list of PDF files.
*
* @param {number} windowId
* @param {Array} fileEntries List of Entry objects (HTML5 FileSystem API)
*/
function openViewer(windowId, fileEntries) {
if (!fileEntries.length) {
return;
}
var fileEntry = fileEntries.shift();
var url = fileEntry.toURL();
// Use drive: alias to get shorter (more human-readable) URLs.
url = url.replace(
/^filesystem:chrome-extension:\/\/[a-p]{32}\/external\//,
"drive:"
);
url = getViewerURL(url);
if (windowId) {
chrome.tabs.create(
{
windowId,
active: true,
url,
},
function () {
openViewer(windowId, fileEntries);
}
);
} else {
chrome.windows.create(
{
type: "normal",
focused: true,
url,
},
function (chromeWindow) {
openViewer(chromeWindow.id, fileEntries);
}
);
}
}
})();

View File

@ -1,24 +0,0 @@
<!doctype html>
<!--
Copyright 2012 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="options/migration.js"></script>
<script src="preserve-referer.js"></script>
<script src="pdfHandler.js"></script>
<script src="extension-router.js"></script>
<script src="pdfHandler-vcros.js"></script>
<script src="pageAction/background.js"></script>
<script src="suppress-update.js"></script>
<script src="telemetry.js"></script>

View File

@ -13,11 +13,256 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* import-globals-from preserve-referer.js */
/* globals canRequestBody */ // From preserve-referer.js
"use strict"; "use strict";
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html"); var VIEWER_URL = chrome.runtime.getURL("content/web/viewer.html");
// Use in-memory storage to ensure that the DNR rules have been registered at
// least once per session. runtime.onInstalled would have been the most fitting
// event to ensure that, except there are cases where it does not fire when
// needed. E.g. in incognito mode: https://issues.chromium.org/issues/41029550
chrome.storage.session.get({ hasPdfRedirector: false }, async items => {
if (items?.hasPdfRedirector) {
return;
}
const rules = await chrome.declarativeNetRequest.getDynamicRules();
if (rules.length) {
// Dynamic rules persist across extension updates. We don't expect other
// dynamic rules, so just remove them all.
await chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: rules.map(r => r.id),
});
}
await registerPdfRedirectRule();
// Only set the flag in the end, so that we know for sure that all
// asynchronous initialization logic has run. If not, then we will run the
// logic again at the next background wakeup.
chrome.storage.session.set({ hasPdfRedirector: true });
});
/**
* Registers declarativeNetRequest rules to redirect PDF requests to the viewer.
* The caller should clear any previously existing dynamic DNR rules.
*
* The logic here is the declarative version of the runtime logic in the
* webRequest.onHeadersReceived implementation at
* https://github.com/mozilla/pdf.js/blob/0676ea19cf17023ec8c2d6ad69a859c345c01dc1/extensions/chromium/pdfHandler.js#L34-L152
*/
async function registerPdfRedirectRule() {
// "allow" means to ignore rules (from this extension) with lower priority.
const ACTION_IGNORE_OTHER_RULES = { type: "allow" };
// Redirect to viewer. The rule condition is expected to specify regexFilter
// that matches the full request URL.
const ACTION_REDIRECT_TO_VIEWER = {
type: "redirect",
redirect: {
// DNR does not support transformations such as encodeURIComponent on the
// match, so we just concatenate the URL as is without modifications.
// TODO: use "?file=\\0" when DNR supports transformations as proposed at
// https://github.com/w3c/webextensions/issues/636#issuecomment-2165978322
regexSubstitution: VIEWER_URL + "?DNR:\\0",
},
};
// Rules in order of priority (highest priority rule first).
// The required "id" fields will be auto-generated later.
const addRules = [
{
// Do not redirect for URLs containing pdfjs.action=download.
condition: {
urlFilter: "pdfjs.action=download",
resourceTypes: ["main_frame", "sub_frame"],
},
action: ACTION_IGNORE_OTHER_RULES,
},
{
// Redirect local PDF files if isAllowedFileSchemeAccess is true. No-op
// otherwise and then handled by webNavigation.onBeforeNavigate below.
condition: {
regexFilter: "^file://.*\\.pdf$",
resourceTypes: ["main_frame", "sub_frame"],
},
action: ACTION_REDIRECT_TO_VIEWER,
},
{
// Respect the Content-Disposition:attachment header in sub_frame. But:
// Display the PDF viewer regardless of the Content-Disposition header if
// the file is displayed in the main frame, since most often users want to
// view a PDF, and servers are often misconfigured.
condition: {
urlFilter: "*",
resourceTypes: ["sub_frame"], // Note: no main_frame, handled below.
responseHeaders: [
{
header: "content-disposition",
values: ["attachment*"],
},
],
},
action: ACTION_IGNORE_OTHER_RULES,
},
{
// If the query string contains "=download", do not unconditionally force
// viewer to open the PDF, but first check whether the Content-Disposition
// header specifies an attachment. This allows sites like Google Drive to
// operate correctly (#6106).
condition: {
urlFilter: "=download",
resourceTypes: ["main_frame"], // No sub_frame, was handled before.
responseHeaders: [
{
header: "content-disposition",
values: ["attachment*"],
},
],
},
action: ACTION_IGNORE_OTHER_RULES,
},
{
// Regular http(s) PDF requests.
condition: {
regexFilter: "^.*$",
// The viewer does not have the original request context and issues a
// GET request. The original response to POST requests is unavailable.
excludedRequestMethods: ["post"],
resourceTypes: ["main_frame", "sub_frame"],
responseHeaders: [
{
header: "content-type",
values: ["application/pdf", "application/pdf;*"],
},
],
},
action: ACTION_REDIRECT_TO_VIEWER,
},
{
// Wrong MIME-type, but a PDF file according to the file name in the URL.
condition: {
regexFilter: "^.*\\.pdf\\b.*$",
// The viewer does not have the original request context and issues a
// GET request. The original response to POST requests is unavailable.
excludedRequestMethods: ["post"],
resourceTypes: ["main_frame", "sub_frame"],
responseHeaders: [
{
header: "content-type",
values: ["application/octet-stream", "application/octet-stream;*"],
},
],
},
action: ACTION_REDIRECT_TO_VIEWER,
},
{
// Wrong MIME-type, but a PDF file according to Content-Disposition.
condition: {
regexFilter: "^.*$",
// The viewer does not have the original request context and issues a
// GET request. The original response to POST requests is unavailable.
excludedRequestMethods: ["post"],
resourceTypes: ["main_frame", "sub_frame"],
responseHeaders: [
{
header: "content-disposition",
values: ["*.pdf", '*.pdf"*', "*.pdf'*"],
},
],
// We only want to match by content-disposition if Content-Type is set
// to application/octet-stream. The responseHeaders condition is a
// logical OR instead of AND, so to simulate the AND condition we use
// the double negation of excludedResponseHeaders + excludedValues.
// This matches any request whose content-type header is set and not
// "application/octet-stream". It will also match if "content-type" is
// not set, but we are okay with that since the browser would usually
// try to sniff the MIME type in that case.
excludedResponseHeaders: [
{
header: "content-type",
excludedValues: [
"application/octet-stream",
"application/octet-stream;*",
],
},
],
},
action: ACTION_REDIRECT_TO_VIEWER,
},
];
for (const [i, rule] of addRules.entries()) {
// id must be unique and at least 1, but i starts at 0. So add +1.
rule.id = i + 1;
rule.priority = addRules.length - i;
}
try {
// Note: condition.responseHeaders is only supported in Chrome 128+, but
// does not trigger errors in Chrome 123 - 127 as explained at:
// https://github.com/w3c/webextensions/issues/638#issuecomment-2181124486
// We need to detect this and avoid registering rules, because otherwise all
// requests are redirected to the viewer instead of just PDF requests,
// because Chrome accepts rules while ignoring the responseHeaders condition
// - also reported at https://crbug.com/347186592
if (!(await isHeaderConditionSupported())) {
throw new Error("DNR responseHeaders condition is not supported.");
}
await chrome.declarativeNetRequest.updateDynamicRules({ addRules });
} catch (e) {
// When we do not register DNR rules for any reason, fall back to catching
// PDF documents via maybeRenderPdfDoc in contentscript.js.
console.error("Failed to register rules to redirect PDF requests.");
console.error(e);
}
}
// For the source and explanation of this logic, see
// https://github.com/w3c/webextensions/issues/638#issuecomment-2181124486
async function isHeaderConditionSupported() {
const ruleId = 123456; // Some rule ID that is not already used elsewhere.
try {
// Throws synchronously if not supported.
await chrome.declarativeNetRequest.updateSessionRules({
addRules: [
{
id: ruleId,
condition: {
responseHeaders: [{ header: "whatever" }],
urlFilter: "|does_not_match_anything",
},
action: { type: "block" },
},
],
});
} catch {
return false; // responseHeaders condition not supported.
}
// Chrome may recognize the properties but have the implementation behind a
// flag. When the implementation is disabled, validation is skipped too.
try {
await chrome.declarativeNetRequest.updateSessionRules({
removeRuleIds: [ruleId],
addRules: [
{
id: ruleId,
condition: {
responseHeaders: [],
urlFilter: "|does_not_match_anything",
},
action: { type: "block" },
},
],
});
return false; // Validation skipped = feature disabled.
} catch {
return true; // Validation worked = feature enabled.
} finally {
await chrome.declarativeNetRequest.updateSessionRules({
removeRuleIds: [ruleId],
});
}
}
function getViewerURL(pdf_url) { function getViewerURL(pdf_url) {
// |pdf_url| may contain a fragment such as "#page=2". That should be passed // |pdf_url| may contain a fragment such as "#page=2". That should be passed
@ -31,158 +276,27 @@ function getViewerURL(pdf_url) {
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url) + hash; return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url) + hash;
} }
/** // If the user has not granted access to file:-URLs, then declarativeNetRequest
* @param {Object} details First argument of the webRequest.onHeadersReceived
* event. The property "url" is read.
* @returns {boolean} True if the PDF file should be downloaded.
*/
function isPdfDownloadable(details) {
if (details.url.includes("pdfjs.action=download")) {
return true;
}
// Display the PDF viewer regardless of the Content-Disposition header if the
// file is displayed in the main frame, since most often users want to view
// a PDF, and servers are often misconfigured.
// If the query string contains "=download", do not unconditionally force the
// viewer to open the PDF, but first check whether the Content-Disposition
// header specifies an attachment. This allows sites like Google Drive to
// operate correctly (#6106).
if (details.type === "main_frame" && !details.url.includes("=download")) {
return false;
}
var cdHeader =
details.responseHeaders &&
getHeaderFromHeaders(details.responseHeaders, "content-disposition");
return cdHeader && /^attachment/i.test(cdHeader.value);
}
/**
* Get the header from the list of headers for a given name.
* @param {Array} headers responseHeaders of webRequest.onHeadersReceived
* @returns {undefined|{name: string, value: string}} The header, if found.
*/
function getHeaderFromHeaders(headers, headerName) {
for (const header of headers) {
if (header.name.toLowerCase() === headerName) {
return header;
}
}
return undefined;
}
/**
* Check if the request is a PDF file.
* @param {Object} details First argument of the webRequest.onHeadersReceived
* event. The properties "responseHeaders" and "url"
* are read.
* @returns {boolean} True if the resource is a PDF file.
*/
function isPdfFile(details) {
var header = getHeaderFromHeaders(details.responseHeaders, "content-type");
if (header) {
var headerValue = header.value.toLowerCase().split(";", 1)[0].trim();
if (headerValue === "application/pdf") {
return true;
}
if (headerValue === "application/octet-stream") {
if (details.url.toLowerCase().indexOf(".pdf") > 0) {
return true;
}
var cdHeader = getHeaderFromHeaders(
details.responseHeaders,
"content-disposition"
);
if (cdHeader && /\.pdf(["']|$)/i.test(cdHeader.value)) {
return true;
}
}
}
return false;
}
/**
* Takes a set of headers, and set "Content-Disposition: attachment".
* @param {Object} details First argument of the webRequest.onHeadersReceived
* event. The property "responseHeaders" is read and
* modified if needed.
* @returns {Object|undefined} The return value for the onHeadersReceived event.
* Object with key "responseHeaders" if the headers
* have been modified, undefined otherwise.
*/
function getHeadersWithContentDispositionAttachment(details) {
var headers = details.responseHeaders;
var cdHeader = getHeaderFromHeaders(headers, "content-disposition");
if (!cdHeader) {
cdHeader = { name: "Content-Disposition" };
headers.push(cdHeader);
}
if (!/^attachment/i.test(cdHeader.value)) {
cdHeader.value = "attachment" + cdHeader.value.replace(/^[^;]+/i, "");
return { responseHeaders: headers };
}
return undefined;
}
chrome.webRequest.onHeadersReceived.addListener(
function (details) {
if (details.method !== "GET") {
// Don't intercept POST requests until http://crbug.com/104058 is fixed.
return undefined;
}
if (!isPdfFile(details)) {
return undefined;
}
if (isPdfDownloadable(details)) {
// Force download by ensuring that Content-Disposition: attachment is set
return getHeadersWithContentDispositionAttachment(details);
}
var viewerUrl = getViewerURL(details.url);
// Implemented in preserve-referer.js
saveReferer(details);
return { redirectUrl: viewerUrl };
},
{
urls: ["<all_urls>"],
types: ["main_frame", "sub_frame"],
},
["blocking", "responseHeaders"]
);
chrome.webRequest.onBeforeRequest.addListener(
function (details) {
if (isPdfDownloadable(details)) {
return undefined;
}
var viewerUrl = getViewerURL(details.url);
return { redirectUrl: viewerUrl };
},
{
urls: ["file://*/*.pdf", "file://*/*.PDF"],
types: ["main_frame", "sub_frame"],
},
["blocking"]
);
chrome.extension.isAllowedFileSchemeAccess(function (isAllowedAccess) {
if (isAllowedAccess) {
return;
}
// If the user has not granted access to file:-URLs, then the webRequest API
// will not catch the request. It is still visible through the webNavigation // will not catch the request. It is still visible through the webNavigation
// API though, and we can replace the tab with the viewer. // API though, and we can replace the tab with the viewer.
// The viewer will detect that it has no access to file:-URLs, and prompt the // The viewer will detect that it has no access to file:-URLs, and prompt the
// user to activate file permissions. // user to activate file permissions.
chrome.webNavigation.onBeforeNavigate.addListener( chrome.webNavigation.onBeforeNavigate.addListener(
function (details) { function (details) {
if (details.frameId === 0 && !isPdfDownloadable(details)) { // Note: pdfjs.action=download is not checked here because that code path
// is not reachable for local files through the viewer when we do not have
// file:-access.
if (details.frameId === 0) {
chrome.extension.isAllowedFileSchemeAccess(function (isAllowedAccess) {
if (isAllowedAccess) {
// Expected to be handled by DNR. Don't do anything.
return;
}
chrome.tabs.update(details.tabId, { chrome.tabs.update(details.tabId, {
url: getViewerURL(details.url), url: getViewerURL(details.url),
}); });
});
} }
}, },
{ {
@ -198,7 +312,6 @@ chrome.extension.isAllowedFileSchemeAccess(function (isAllowedAccess) {
], ],
} }
); );
});
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message && message.action === "getParentOrigin") { if (message && message.action === "getParentOrigin") {
@ -245,6 +358,11 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
url, url,
}); });
} }
return undefined;
}
if (message && message.action === "canRequestBody") {
sendResponse(canRequestBody(sender.tab.id, sender.frameId));
return undefined;
} }
return undefined; return undefined;
}); });

View File

@ -45,7 +45,41 @@
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"enableML": { "enableHWA": {
"title": "Enable hardware acceleration",
"description": "Whether to enable hardware acceleration.",
"type": "boolean",
"default": true
},
"enableAltText": {
"type": "boolean",
"default": false
},
"enableGuessAltText": {
"type": "boolean",
"default": true
},
"enableAltTextModelDownload": {
"type": "boolean",
"default": true
},
"enableNewAltTextWhenAddingImage": {
"type": "boolean",
"default": true
},
"altTextLearnMoreUrl": {
"type": "string",
"default": ""
},
"commentLearnMoreUrl": {
"type": "string",
"default": ""
},
"enableSignatureEditor": {
"type": "boolean",
"default": false
},
"enableUpdatedAddImage": {
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
@ -68,21 +102,13 @@
"description": "Whether to allow execution of active content (JavaScript) by PDF files.", "description": "Whether to allow execution of active content (JavaScript) by PDF files.",
"default": false "default": false
}, },
"enableHighlightEditor": {
"type": "boolean",
"default": false
},
"enableHighlightFloatingButton": { "enableHighlightFloatingButton": {
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"highlightEditorColors": { "highlightEditorColors": {
"type": "string", "type": "string",
"default": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F" "default": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F,yellow_HCM=#FFFFCC,green_HCM=#53FFBC,blue_HCM=#80EBFF,pink_HCM=#F6B8FF,red_HCM=#C50043"
},
"enableStampEditor": {
"type": "boolean",
"default": true
}, },
"disableRange": { "disableRange": {
"title": "Disable range requests", "title": "Disable range requests",
@ -150,6 +176,10 @@
"enum": [-1, 0, 3, 15], "enum": [-1, 0, 3, 15],
"default": 0 "default": 0
}, },
"capCanvasAreaFactor": {
"type": "integer",
"default": 200
},
"enablePermissions": { "enablePermissions": {
"type": "boolean", "type": "boolean",
"default": false "default": false
@ -202,6 +232,21 @@
"description": "The color is a string as defined in CSS. Its goal is to help improve readability in high contrast mode", "description": "The color is a string as defined in CSS. Its goal is to help improve readability in high contrast mode",
"type": "string", "type": "string",
"default": "CanvasText" "default": "CanvasText"
},
"enableAutoLinking": {
"description": "Enable creation of hyperlinks from text that look like URLs.",
"type": "boolean",
"default": true
},
"enableComment": {
"description": "Enable creation of comment annotations.",
"type": "boolean",
"default": false
},
"enableOptimizedPartialRendering": {
"description": "Enable tracking of PDF operations to optimize partial rendering.",
"type": "boolean",
"default": false
} }
} }
} }

View File

@ -13,20 +13,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* import-globals-from pdfHandler.js */
/* exported saveReferer */
"use strict"; "use strict";
/** /**
* This file is one part of the Referer persistency implementation. The other * This file is one part of the Referer persistency implementation. The other
* part resides in chromecom.js. * part resides in chromecom.js.
* *
* This file collects request headers for every http(s) request, and temporarily * This file collects Referer headers for every http(s) request, and temporarily
* stores the request headers in a dictionary. Upon completion of the request * stores the request headers in a dictionary, for REFERRER_IN_MEMORY_TIME ms.
* (success or failure), the headers are discarded.
* pdfHandler.js will call saveReferer(details) when it is about to redirect to
* the viewer. Upon calling saveReferer, the Referer header is extracted from
* the request headers and saved.
* *
* When the viewer is opened, it opens a port ("chromecom-referrer"). This port * When the viewer is opened, it opens a port ("chromecom-referrer"). This port
* is used to set up the webRequest listeners that stick the Referer headers to * is used to set up the webRequest listeners that stick the Referer headers to
@ -36,49 +30,64 @@ limitations under the License.
* See setReferer in chromecom.js for more explanation of this logic. * See setReferer in chromecom.js for more explanation of this logic.
*/ */
// Remembers the request headers for every http(s) page request for the duration /* exported canRequestBody */ // Used in pdfHandler.js
// of the request.
var g_requestHeaders = {};
// g_referrers[tabId][frameId] = referrer of PDF frame. // g_referrers[tabId][frameId] = referrer of PDF frame.
var g_referrers = {}; var g_referrers = {};
var g_referrerTimers = {};
// The background script will eventually suspend after 30 seconds of inactivity.
// This can be delayed when extension events are firing. To prevent the data
// from being kept in memory for too long, cap the data duration to 5 minutes.
var REFERRER_IN_MEMORY_TIME = 300000;
(function () { // g_postRequests[tabId] = Set of frameId that were loaded via POST.
var requestFilter = { var g_postRequests = {};
urls: ["*://*/*"],
types: ["main_frame", "sub_frame"], var rIsReferer = /^referer$/i;
};
chrome.webRequest.onSendHeaders.addListener( chrome.webRequest.onSendHeaders.addListener(
function (details) { function saveReferer(details) {
g_requestHeaders[details.requestId] = details.requestHeaders; const { tabId, frameId, requestHeaders, method } = details;
g_referrers[tabId] ??= {};
g_referrers[tabId][frameId] = requestHeaders.find(h =>
rIsReferer.test(h.name)
)?.value;
setCanRequestBody(tabId, frameId, method !== "GET");
forgetReferrerEventually(tabId);
}, },
requestFilter, { urls: ["*://*/*"], types: ["main_frame", "sub_frame"] },
["requestHeaders", "extraHeaders"] ["requestHeaders", "extraHeaders"]
); );
chrome.webRequest.onBeforeRedirect.addListener(forgetHeaders, requestFilter);
chrome.webRequest.onCompleted.addListener(forgetHeaders, requestFilter);
chrome.webRequest.onErrorOccurred.addListener(forgetHeaders, requestFilter);
function forgetHeaders(details) {
delete g_requestHeaders[details.requestId];
}
})();
/** function forgetReferrerEventually(tabId) {
* @param {object} details - onHeadersReceived event data. if (g_referrerTimers[tabId]) {
*/ clearTimeout(g_referrerTimers[tabId]);
function saveReferer(details) {
var referer =
g_requestHeaders[details.requestId] &&
getHeaderFromHeaders(g_requestHeaders[details.requestId], "referer");
referer = (referer && referer.value) || "";
if (!g_referrers[details.tabId]) {
g_referrers[details.tabId] = {};
} }
g_referrers[details.tabId][details.frameId] = referer; g_referrerTimers[tabId] = setTimeout(() => {
}
chrome.tabs.onRemoved.addListener(function (tabId) {
delete g_referrers[tabId]; delete g_referrers[tabId];
}); delete g_referrerTimers[tabId];
delete g_postRequests[tabId];
}, REFERRER_IN_MEMORY_TIME);
}
// Keeps track of whether a document in tabId + frameId is loaded through a
// POST form submission. Although this logic has nothing to do with referrer
// tracking, it is still here to enable re-use of the webRequest listener above.
function setCanRequestBody(tabId, frameId, isPOST) {
if (isPOST) {
g_postRequests[tabId] ??= new Set();
g_postRequests[tabId].add(frameId);
} else {
g_postRequests[tabId]?.delete(frameId);
}
}
function canRequestBody(tabId, frameId) {
// Returns true unless the frame is known to be loaded through a POST request.
// If the background suspends, the information may be lost. This is acceptable
// because the information is only potentially needed shortly after document
// load, by contentscript.js.
return !g_postRequests[tabId]?.has(frameId);
}
// This method binds a webRequest event handler which adds the Referer header // This method binds a webRequest event handler which adds the Referer header
// to matching PDF resource requests (only if the Referer is non-empty). The // to matching PDF resource requests (only if the Referer is non-empty). The
@ -87,15 +96,13 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
if (port.name !== "chromecom-referrer") { if (port.name !== "chromecom-referrer") {
return; return;
} }
// Note: sender.frameId is only set in Chrome 41+.
if (!("frameId" in port.sender)) {
port.disconnect();
return;
}
var tabId = port.sender.tab.id; var tabId = port.sender.tab.id;
var frameId = port.sender.frameId; var frameId = port.sender.frameId;
var dnrRequestId;
// If the PDF is viewed for the first time, then the referer will be set here. // If the PDF is viewed for the first time, then the referer will be set here.
// Note: g_referrers could be empty if the background script was suspended by
// the browser. In that case, chromecom.js may send us the referer (below).
var referer = (g_referrers[tabId] && g_referrers[tabId][frameId]) || ""; var referer = (g_referrers[tabId] && g_referrers[tabId][frameId]) || "";
port.onMessage.addListener(function (data) { port.onMessage.addListener(function (data) {
// If the viewer was opened directly (without opening a PDF URL first), then // If the viewer was opened directly (without opening a PDF URL first), then
@ -104,80 +111,49 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
if (data.referer) { if (data.referer) {
referer = data.referer; referer = data.referer;
} }
chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders); dnrRequestId = data.dnrRequestId;
if (referer) { setStickyReferrer(dnrRequestId, tabId, data.requestUrl, referer, () => {
// Only add a blocking request handler if the referer has to be rewritten.
chrome.webRequest.onBeforeSendHeaders.addListener(
onBeforeSendHeaders,
{
urls: [data.requestUrl],
types: ["xmlhttprequest"],
tabId,
},
["blocking", "requestHeaders", "extraHeaders"]
);
}
// Acknowledge the message, and include the latest referer for this frame. // Acknowledge the message, and include the latest referer for this frame.
port.postMessage(referer); port.postMessage(referer);
}); });
});
// The port is only disconnected when the other end reloads. // The port is only disconnected when the other end reloads.
port.onDisconnect.addListener(function () { port.onDisconnect.addListener(function () {
if (g_referrers[tabId]) { unsetStickyReferrer(dnrRequestId);
delete g_referrers[tabId][frameId]; });
}
chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
chrome.webRequest.onHeadersReceived.removeListener(exposeOnHeadersReceived);
}); });
// Expose some response headers for fetch API calls from PDF.js; function setStickyReferrer(dnrRequestId, tabId, url, referer, callback) {
// This is a work-around for https://crbug.com/784528 if (!referer) {
chrome.webRequest.onHeadersReceived.addListener( unsetStickyReferrer(dnrRequestId);
exposeOnHeadersReceived, callback();
{ return;
urls: ["https://*/*"], }
types: ["xmlhttprequest"], const rule = {
tabId, id: dnrRequestId,
condition: {
urlFilter: `|${url}|`,
// The viewer and background are presumed to have the same origin:
initiatorDomains: [location.hostname], // = chrome.runtime.id.
resourceTypes: ["xmlhttprequest"],
tabIds: [tabId],
}, },
["blocking", "responseHeaders"] action: {
type: "modifyHeaders",
requestHeaders: [{ operation: "set", header: "referer", value: referer }],
},
};
chrome.declarativeNetRequest.updateSessionRules(
{ removeRuleIds: [dnrRequestId], addRules: [rule] },
callback
); );
function onBeforeSendHeaders(details) {
if (details.frameId !== frameId) {
return undefined;
}
var headers = details.requestHeaders;
var refererHeader = getHeaderFromHeaders(headers, "referer");
if (!refererHeader) {
refererHeader = { name: "Referer" };
headers.push(refererHeader);
} else if (
refererHeader.value &&
refererHeader.value.lastIndexOf("chrome-extension:", 0) !== 0
) {
// Sanity check. If the referer is set, and the value is not the URL of
// this extension, then the request was not initiated by this extension.
return undefined;
}
refererHeader.value = referer;
return { requestHeaders: headers };
} }
function exposeOnHeadersReceived(details) { function unsetStickyReferrer(dnrRequestId) {
if (details.frameId !== frameId) { if (dnrRequestId) {
return undefined; chrome.declarativeNetRequest.updateSessionRules({
} removeRuleIds: [dnrRequestId],
var headers = details.responseHeaders;
var aceh = getHeaderFromHeaders(headers, "access-control-expose-headers");
// List of headers that PDF.js uses in src/display/network_utils.js
var acehValue =
"accept-ranges,content-encoding,content-length,content-disposition";
if (aceh) {
aceh.value += "," + acehValue;
} else {
aceh = { name: "Access-Control-Expose-Headers", value: acehValue };
headers.push(aceh);
}
return { responseHeaders: headers };
}
}); });
}
}

View File

@ -1,31 +0,0 @@
/*
Copyright 2015 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* This is part of the work-around for crbug.com/511670.
* - chromecom.js sets the URL and history state upon unload.
* - extension-router.js retrieves the saved state and opens restoretab.html
* - restoretab.html (this script) restores the URL and history state.
*/
"use strict";
var url = decodeURIComponent(location.search.slice(1));
var historyState = decodeURIComponent(location.hash.slice(1));
historyState = historyState === "undefined" ? null : JSON.parse(historyState);
history.replaceState(historyState, null, url);
location.reload();

View File

@ -20,7 +20,10 @@ limitations under the License.
// viewer is not displaying any PDF files. Otherwise the tabs would close, which // viewer is not displaying any PDF files. Otherwise the tabs would close, which
// is quite disruptive (crbug.com/511670). // is quite disruptive (crbug.com/511670).
chrome.runtime.onUpdateAvailable.addListener(function () { chrome.runtime.onUpdateAvailable.addListener(function () {
if (chrome.extension.getViews({ type: "tab" }).length === 0) { chrome.tabs.query({ url: chrome.runtime.getURL("*") }, tabs => {
chrome.runtime.reload(); if (tabs?.length) {
return;
} }
chrome.runtime.reload();
});
}); });

View File

@ -42,8 +42,35 @@ limitations under the License.
return; return;
} }
// The localStorage API is unavailable in service workers. We store data in
// chrome.storage.local and use this "localStorage" object to enable
// synchronous access in the logic.
const localStorage = {
telemetryLastTime: 0,
telemetryDeduplicationId: "",
telemetryLastVersion: "",
};
chrome.alarms.onAlarm.addListener(alarm => {
if (alarm.name === "maybeSendPing") {
maybeSendPing(); maybeSendPing();
setInterval(maybeSendPing, 36e5); }
});
chrome.storage.session.get({ didPingCheck: false }, async items => {
if (items?.didPingCheck) {
return;
}
maybeSendPing();
await chrome.alarms.clear("maybeSendPing");
await chrome.alarms.create("maybeSendPing", { periodInMinutes: 60 });
chrome.storage.session.set({ didPingCheck: true });
});
function updateLocalStorage(key, value) {
localStorage[key] = value;
// Note: We mirror the data in localStorage because the following is async.
chrome.storage.local.set({ [key]: value });
}
function maybeSendPing() { function maybeSendPing() {
getLoggingPref(function (didOptOut) { getLoggingPref(function (didOptOut) {
@ -61,12 +88,20 @@ limitations under the License.
// send more pings. // send more pings.
return; return;
} }
doSendPing();
});
}
function doSendPing() {
chrome.storage.local.get(localStorage, items => {
Object.assign(localStorage, items);
var lastTime = parseInt(localStorage.telemetryLastTime) || 0; var lastTime = parseInt(localStorage.telemetryLastTime) || 0;
var wasUpdated = didUpdateSinceLastCheck(); var wasUpdated = didUpdateSinceLastCheck();
if (!wasUpdated && Date.now() - lastTime < MINIMUM_TIME_BETWEEN_PING) { if (!wasUpdated && Date.now() - lastTime < MINIMUM_TIME_BETWEEN_PING) {
return; return;
} }
localStorage.telemetryLastTime = Date.now(); updateLocalStorage("telemetryLastTime", Date.now());
var deduplication_id = getDeduplicationId(wasUpdated); var deduplication_id = getDeduplicationId(wasUpdated);
var extension_version = chrome.runtime.getManifest().version; var extension_version = chrome.runtime.getManifest().version;
@ -104,7 +139,7 @@ limitations under the License.
for (const c of buf) { for (const c of buf) {
id += (c >>> 4).toString(16) + (c & 0xf).toString(16); id += (c >>> 4).toString(16) + (c & 0xf).toString(16);
} }
localStorage.telemetryDeduplicationId = id; updateLocalStorage("telemetryDeduplicationId", id);
} }
return id; return id;
} }
@ -119,7 +154,7 @@ limitations under the License.
if (!chromeVersion || localStorage.telemetryLastVersion === chromeVersion) { if (!chromeVersion || localStorage.telemetryLastVersion === chromeVersion) {
return false; return false;
} }
localStorage.telemetryLastVersion = chromeVersion; updateLocalStorage("telemetryLastVersion", chromeVersion);
return true; return true;
} }

View File

@ -1,22 +0,0 @@
{
// Note: The root .eslintrc file will define the base rules,
// but mozilla/recommended will override them for the rules it sets. Finally,
// the rules in this file will take precedence.
"extends": [
"plugin:mozilla/recommended",
],
"plugins": [
"mozilla"
],
"rules": {
// Other rules mozilla/recommended hasn't enabled yet.
"no-shadow": "error",
"arrow-body-style": ["error", "as-needed"],
"arrow-parens": ["error", "always"],
"constructor-super": "error",
"no-confusing-arrow": "error",
"no-useless-constructor": "error",
},
}

9
external/.eslintrc vendored
View File

@ -1,9 +0,0 @@
{
"extends": [
../.eslintrc
],
"env": {
"node": true,
},
}

View File

@ -1,10 +1,7 @@
import { types as t, transformSync } from "@babel/core"; import { types as t, transformSync } from "@babel/core";
import fs from "fs";
import { join as joinPaths } from "path";
import vm from "vm"; import vm from "vm";
const PDFJS_PREPROCESSOR_NAME = "PDFJSDev"; const PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
const ROOT_PREFIX = "$ROOT/";
function isPDFJSPreprocessor(obj) { function isPDFJSPreprocessor(obj) {
return obj.type === "Identifier" && obj.name === PDFJS_PREPROCESSOR_NAME; return obj.type === "Identifier" && obj.name === PDFJS_PREPROCESSOR_NAME;
@ -40,18 +37,6 @@ function handlePreprocessorAction(ctx, actionName, args, path) {
return result; return result;
} }
break; break;
case "json":
if (!t.isStringLiteral(arg)) {
throw new Error("Path to JSON is not provided");
}
let jsonPath = arg.value;
if (jsonPath.startsWith(ROOT_PREFIX)) {
jsonPath = joinPaths(
ctx.rootPath,
jsonPath.substring(ROOT_PREFIX.length)
);
}
return JSON.parse(fs.readFileSync(jsonPath, "utf8"));
} }
throw new Error("Unsupported action"); throw new Error("Unsupported action");
} catch (e) { } catch (e) {
@ -62,6 +47,25 @@ function handlePreprocessorAction(ctx, actionName, args, path) {
} }
function babelPluginPDFJSPreprocessor(babel, ctx) { function babelPluginPDFJSPreprocessor(babel, ctx) {
function removeUnusedFunctions(path) {
let removed;
do {
removed = false;
path.scope.crawl();
for (const name in path.scope.bindings) {
const binding = path.scope.bindings[name];
if (!binding.referenced) {
const { path: bindingPath } = binding;
if (bindingPath.isFunctionDeclaration()) {
bindingPath.remove();
removed = true;
}
}
}
// If we removed some functions, there might be new unused ones
} while (removed);
}
return { return {
name: "babel-plugin-pdfjs-preprocessor", name: "babel-plugin-pdfjs-preprocessor",
manipulateOptions({ parserOpts }) { manipulateOptions({ parserOpts }) {
@ -168,23 +172,27 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
path.replaceWith(t.inherits(t.valueToNode(result), path.node)); path.replaceWith(t.inherits(t.valueToNode(result), path.node));
} }
if (t.isIdentifier(node.callee, { name: "__non_webpack_import__" })) { if (t.isIdentifier(node.callee, { name: "__raw_import__" })) {
if (node.arguments.length !== 1) { if (node.arguments.length !== 1) {
throw new Error("Invalid `__non_webpack_import__` usage."); throw new Error("Invalid `__raw_import__` usage.");
} }
// Replace it with a standard `import`-call and // Replace it with a standard `import`-call and attempt to ensure that
// ensure that Webpack will leave it alone. // various bundlers will leave it alone; this *must* include Webpack.
const source = node.arguments[0]; const source = node.arguments[0];
source.leadingComments = [ source.leadingComments = [
{ {
type: "CommentBlock", type: "CommentBlock",
value: "webpackIgnore: true", value: "webpackIgnore: true",
}, },
{
type: "CommentBlock",
value: "@vite-ignore",
},
]; ];
path.replaceWith(t.importExpression(source)); path.replaceWith(t.importExpression(source));
} }
}, },
BlockStatement: { "BlockStatement|StaticBlock": {
// Visit node in post-order so that recursive flattening // Visit node in post-order so that recursive flattening
// of blocks works correctly. // of blocks works correctly.
exit(path) { exit(path) {
@ -215,6 +223,10 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
} }
subExpressionIndex++; subExpressionIndex++;
} }
if (node.type === "StaticBlock" && node.body.length === 0) {
path.remove();
}
}, },
}, },
Function: { Function: {
@ -232,8 +244,50 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
// Function body ends with return without arg -- removing it. // Function body ends with return without arg -- removing it.
body.pop(); body.pop();
} }
removeUnusedFunctions(path);
}, },
}, },
ClassMethod: {
exit(path) {
const {
node,
parentPath: { parent: classNode },
} = path;
if (
// Remove empty constructors. We only do this for
// base classes, as the default constructor of derived
// classes is not empty (and an empty constructor
// must throw at runtime when constructed).
node.kind === "constructor" &&
node.body.body.length === 0 &&
node.params.every(p => p.type === "Identifier") &&
!classNode.superClass
) {
path.remove();
}
},
},
Program: {
exit(path) {
if (path.node.sourceType === "module") {
removeUnusedFunctions(path);
}
},
},
MemberExpression(path) {
// The Emscripten Compiler (emcc) generates code that allows the caller
// to provide the Wasm module (thorugh Module.instantiateWasm), with
// a fallback in case .instantiateWasm is not provided.
// We always define instantiateWasm, so we can hard-code the check
// and let our dead code elimination logic remove the unused fallback.
if (
path.parentPath.isIfStatement({ test: path.node }) &&
path.matchesPattern("Module.instantiateWasm")
) {
path.replaceWith(t.booleanLiteral(true));
}
},
}, },
}; };
} }

View File

@ -151,7 +151,7 @@ function preprocess(inFilename, outFilename, defines) {
let state = STATE_NONE; let state = STATE_NONE;
const stack = []; const stack = [];
const control = const control =
/^(?:\/\/|\s*\/\*|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:\*\/|-->)?$)?/; /^(?:\/\/|\s*\/\*|\s*<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:\*\/|-->)?$)?/;
while ((line = readLine()) !== null) { while ((line = readLine()) !== null) {
++lineNumber; ++lineNumber;
@ -213,7 +213,7 @@ function preprocess(inFilename, outFilename, defines) {
) { ) {
writeLine( writeLine(
line line
.replaceAll(/^\/\/|^<!--/g, " ") .replaceAll(/^\/\/|^\s*<!--/g, " ")
.replaceAll(/(^\s*)\/\*/g, "$1 ") .replaceAll(/(^\s*)\/\*/g, "$1 ")
.replaceAll(/\*\/$|-->$/g, "") .replaceAll(/\*\/$|-->$/g, "")
); );

View File

@ -8,3 +8,4 @@ function test() {
} }
"4"; "4";
} }
test();

View File

@ -17,3 +17,4 @@ function test() {
"4"; "4";
} }
} }
test();

View File

@ -2,10 +2,12 @@ function f1() {
"1"; "1";
"2"; "2";
} }
f1();
function f2() { function f2() {
"1"; "1";
"2"; "2";
} }
f2();
function f3() { function f3() {
if ("1") { if ("1") {
"1"; "1";
@ -15,3 +17,4 @@ function f3() {
"4"; "4";
} }
} }
f3();

View File

@ -6,6 +6,7 @@ function f1() {
"2"; "2";
/* tail */ /* tail */
} }
f1();
function f2() { function f2() {
// head // head
@ -14,6 +15,7 @@ function f2() {
"2"; "2";
// tail // tail
} }
f2();
function f3() { function f3() {
if ("1") { // begin block if ("1") { // begin block
@ -24,3 +26,4 @@ function f3() {
"4"; "4";
} }
} }
f3();

View File

@ -0,0 +1,23 @@
class A {
constructor() {
console.log("Hi!");
}
}
class B {
constructor(x = console.log("Hi!")) {}
}
class C {
constructor({
x
}) {}
}
class D {}
class E extends A {
constructor() {}
}
class F {
constructor() {
var a = 0;
}
}
class G {}

View File

@ -0,0 +1,37 @@
class A {
constructor() {
console.log("Hi!");
}
}
class B {
constructor(x = console.log("Hi!")) {}
}
class C {
constructor({ x }) {}
}
class D {
constructor(x, y, z) {}
}
class E extends A {
constructor() {}
}
class F {
constructor() {
if (PDFJSDev.test('TRUE')) {
var a = 0;
}
}
}
class G {
constructor() {
if (PDFJSDev.test('FALSE')) {
var a = 0;
}
}
}

View File

@ -1,14 +1,18 @@
function f1() {} function f1() {}
f1();
function f2() { function f2() {
return 1; return 1;
} }
f2();
function f3() { function f3() {
var i = 0; var i = 0;
throw "test"; throw "test";
} }
f3();
function f4() { function f4() {
var i = 0; var i = 0;
} }
f4();
var obj = { var obj = {
method1() {}, method1() {},
method2() {} method2() {}

View File

@ -2,17 +2,20 @@ function f1() {
return; return;
var i = 0; var i = 0;
} }
f1();
function f2() { function f2() {
return 1; return 1;
var i = 0; var i = 0;
} }
f2();
function f3() { function f3() {
var i = 0; var i = 0;
throw "test"; throw "test";
var j = 0; var j = 0;
} }
f3();
function f4() { function f4() {
var i = 0; var i = 0;
@ -22,6 +25,7 @@ function f4() {
throw "test"; throw "test";
var j = 0; var j = 0;
} }
f4();
var obj = { var obj = {
method1() { return; var i = 0; }, method1() { return; var i = 0; },

View File

@ -10,9 +10,6 @@ var g = {
}, },
j: 2 j: 2
}; };
var h = {
test: "test"
};
var i = '0'; var i = '0';
var j = { var j = {
i: 1 i: 1

View File

@ -5,7 +5,6 @@ var d = PDFJSDev.test('FALSE');
var e = PDFJSDev.eval('TRUE'); var e = PDFJSDev.eval('TRUE');
var f = PDFJSDev.eval('TEXT'); var f = PDFJSDev.eval('TEXT');
var g = PDFJSDev.eval('OBJ'); var g = PDFJSDev.eval('OBJ');
var h = PDFJSDev.json('$ROOT/external/builder/fixtures_esprima/evals.json');
var i = typeof PDFJSDev === 'undefined' ? PDFJSDev.eval('FALSE') : '0'; var i = typeof PDFJSDev === 'undefined' ? PDFJSDev.eval('FALSE') : '0';
var j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0'; var j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0';
var k = !PDFJSDev.test('TRUE'); var k = !PDFJSDev.test('TRUE');

View File

@ -16,3 +16,4 @@ if ('1') {
function f1() { function f1() {
"1"; "1";
} }
f1();

View File

@ -32,3 +32,4 @@ function f1() {
"2"; "2";
} }
} }
f1();

View File

@ -1,4 +1,7 @@
import { Test } from "import-name"; import { Test } from "import-name";
import { Test2 } from './non-alias'; import { Test2 } from './non-alias';
export { Test3 } from "import-name"; export { Test3 } from "import-name";
await import( /*webpackIgnore: true*/"./non-alias"); await import(
/*webpackIgnore: true*/
/*@vite-ignore*/
"./non-alias");

View File

@ -1,4 +1,4 @@
import { Test } from 'import-alias'; import { Test } from 'import-alias';
import { Test2 } from './non-alias'; import { Test2 } from './non-alias';
export { Test3 } from 'import-alias'; export { Test3 } from 'import-alias';
await __non_webpack_import__("./non-alias"); await __raw_import__("./non-alias");

View File

@ -0,0 +1,8 @@
class A {
static {
foo();
}
static {
var a = 0;
}
}

View File

@ -0,0 +1,20 @@
class A {
static {}
static {
{ foo() }
}
static {
{;}
}
static {
if (PDFJSDev.test('TRUE')) {
var a = 0;
}
}
static {
if (PDFJSDev.test('FALSE')) {
var a = 1;
}
}
}

Some files were not shown because too many files have changed in this diff Show More