Compare commits

...

1522 Commits

Author SHA1 Message Date
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
c4784832ac
Merge pull request #19545 from hecerinc/hecerinc/issueLinkFix
Fix the link for issue5939.pdf
2025-02-24 10:08:15 +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
Aditi
04580168a2 Fix rendering problem when zooming on Safari 2024-04-29 17:32:06 +05:30
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
560 changed files with 57822 additions and 30895 deletions

View File

@ -1,13 +0,0 @@
build/
l10n/
docs/
node_modules/
external/bcmaps/
external/builder/fixtures/
external/builder/fixtures_esprima/
external/quickjs/
external/openjpeg/
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).

BIN
.github/security.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [18, lts/*, latest]
node-version: [20, 22, 23]
steps:
- name: Checkout repository
@ -25,7 +25,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
run: npm ci
- name: Run external tests
run: npx gulp externaltest

View File

@ -27,10 +27,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Use Python 3.12
- name: Use Python 3.13
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.13'
cache: 'pip'
- name: Install Fluent dependencies

View File

@ -46,12 +46,12 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
run: npm ci
- name: Use Python 3.12
- name: Use Python 3.13
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.13'
cache: 'pip'
- name: Install Fonttools

View File

@ -25,7 +25,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
run: npm ci
- name: Run lint
run: npx gulp lint

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

@ -0,0 +1,39 @@
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@v4
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
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 --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

View File

@ -27,7 +27,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
run: npm ci
- name: Build the website
run: npx gulp web

View File

@ -25,7 +25,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
run: npm ci
- name: Run types tests
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,9 @@ docs/
node_modules/
external/bcmaps/
external/builder/fixtures/
external/builder/fixtures_esprima/
external/builder/fixtures_babel/
external/quickjs/
test/stats/results/
test/tmp/
test/pdfs/
web/locale/

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/
external/bcmaps/
external/builder/fixtures/
external/builder/fixtures_esprima/
external/builder/fixtures_babel/
external/quickjs/
test/stats/results/
test/tmp/
test/pdfs/
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>
Brendan Dahl <bdahl@mozilla.com>
Bill Walker <bwalker@mozilla.com>
Calixte Denizet <calixte@mozilla.com>
Chris G Jones <cjones@mozilla.com>
David Quintana <gigaherz@gmail.com>
Emily Wachowiak <ewachowiak@mozilla.com>
Felix Kälberer <@fkaelberer>
Jakob Miland <saebekassebil@gmail.com>
Jonas Jenwald <jonas.jenwald@gmail.com>
Julian Viereck
Justin D'Arcangelo <justindarc@gmail.com>
Kalervo Kujala
Marco Castelluccio <mcastelluccio@mozilla.com>
Marie-Lilas Onanga Ozavino <monangaozavino@mozilla.com>
Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
Ophir Lojkine <@lovasoa>
Ryan Casey <rcasey@mozilla.com>
Rob Wu <rob@robwu.nl>
Shaon Barman <shaon.barman@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.
@ -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).
*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
directory `build/chromium`.
@ -52,24 +52,15 @@ To get a local copy of the current code, clone it using git:
$ cd pdf.js
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
globally (see also [gulp's getting started](https://github.com/gulpjs/gulp/tree/master/docs/getting-started)):
$ 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:
[nvm](https://github.com/creationix/nvm). If everything worked out, install
all dependencies for PDF.js:
$ 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
PDF files using a `file://` URL. Run:
$ gulp server
$ npx gulp server
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
viewer, run:
$ gulp generic
$ npx gulp generic
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/`).
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
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
[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)
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
contributor Julian Viereck:
@ -143,4 +134,4 @@ Talk to us on Matrix:
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
template: layout.jade
layout: layout.njk
slug: 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;
border-bottom: 1px solid #e5e7e8;
.navbar-brand {
padding: 0;
img {
height: 42px;
}
}
}
.starter-template {
padding: 0 15px;
}
.navbar-brand {
padding: 4px 15px;
}
.navbar-brand img {
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 {
background-color: #fff;
border: 1px solid #e5e7e8;
border-width: 0 1px;
position: relative;
top: 1px;
main {
margin: 50px 0;
.description {
font-size: 20px;
}
pre {
background-color: #f5f5f5;
border: 1px solid #cccccc;
border-radius: 4px;
padding: 10px;
}
iframe {
border: none;
height: calc(0.55 * 100vh);
width: 100%;
}
}
footer {
padding-top: 40px;
padding-bottom: 40px;
margin-top: 100px;
color: #777;
border-top: 1px solid #e5e5e5;
color: #777777;
padding: 40px 0;
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
template: layout.jade
layout: layout.njk
slug: examples
---
## 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.
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
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
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.
<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
template: layout.jade
layout: layout.njk
slug: getting_started
---
# Getting Started
@ -76,51 +77,50 @@ Note that we only mention the most relevant files and folders.
### Prebuilt
```
```plaintext
├── build/
   ├── pdf.js - display layer
   ├── pdf.js.map - display layer's source map
   ├── pdf.worker.js - core layer
   └── pdf.worker.js.map - core layer's source map
├── pdf.mjs - display layer
├── pdf.mjs.map - display layer's source map
├── pdf.worker.mjs - core layer
└── pdf.worker.mjs.map - core layer's source map
├── web/
│ ├── cmaps/ - character maps (required by core)
│ ├── compressed.tracemonkey-pldi-09.pdf - PDF file for testing purposes
│ ├── debugger.js - helpful debugging features
│ ├── images/ - images for the viewer and annotation icons
│ ├── locale/ - translation files
│ ├── viewer.css - viewer style sheet
│ ├── viewer.html - viewer layout
│ ├── viewer.js - viewer layer
│ └── viewer.js.map - viewer layer's source map
│ ├── viewer.mjs - viewer layer
│ └── viewer.mjs.map - viewer layer's source map
└── LICENSE
```
### Source
```
```plaintext
├── docs/ - website source code
├── examples/ - simple usage examples
├── extensions/ - browser extension source code
├── external/ - third party code
├── l10n/ - translation files
├── src/
   ├── core/ - core layer
   ├── display/ - display layer
   ├── shared/ - shared code between the core and display layers
   ├── interfaces.js - interface definitions for the core/display layers
   └── pdf.*.js - wrapper files for bundling
├── core/ - core layer
├── display/ - display layer
├── shared/ - shared code between the core and display layers
├── interfaces.js - interface definitions for the core/display layers
└── pdf.*.js - wrapper files for bundling
├── test/ - unit, font, reference, and integration tests
├── web/ - viewer layer
├── LICENSE
├── README.md
├── gulpfile.js - build scripts/logic
├── gulpfile.mjs - build scripts/logic
├── package-lock.json - pinned dependency versions
└── package.json - package definition and dependencies
```
## 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

View File

@ -1,14 +1,13 @@
---
title: PDF.js
template: layout.jade
title: Home
layout: layout.njk
slug: home
---
<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>
<p class="text-center description">A general-purpose, web standards-based platform for parsing and rendering PDFs.</p>
<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-lg btn-default" 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="/getting_started/#download">Download</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-outline-dark" href="https://github.com/mozilla/pdf.js">GitHub Project</a>
</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>

452
eslint.config.mjs Normal file
View File

@ -0,0 +1,452 @@
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/quickjs/",
"external/openjpeg/",
"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",
__non_webpack_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-push-push": "error",
"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-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-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-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='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"],
},
},
{
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

@ -9,8 +9,8 @@
<h1>'Previous/Next' example</h1>
<div>
<button id="prev">Previous</button>
<button id="next">Next</button>
<button id="prev" type="button">Previous</button>
<button id="next" type="button">Next</button>
&nbsp; &nbsp;
<span>Page: <span id="page_num"></span> / <span id="page_count"></span></span>
</div>

View File

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

View File

@ -43,13 +43,13 @@ limitations under the License.
</div>
<footer>
<button class="toolbarButton pageUp" title="Previous Page" id="previous"></button>
<button class="toolbarButton pageDown" title="Next Page" id="next"></button>
<button class="toolbarButton pageUp" title="Previous Page" id="previous" type="button"></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">
<button class="toolbarButton zoomOut" title="Zoom Out" id="zoomOut"></button>
<button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn"></button>
<button class="toolbarButton zoomOut" title="Zoom Out" id="zoomOut" type="button"></button>
<button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn" type="button"></button>
</footer>
<script src="viewer.mjs" type="module"></script>

View File

@ -91,10 +91,10 @@ const PDFViewerApplication = {
let key = "pdfjs-loading-error";
if (reason instanceof pdfjsLib.InvalidPDFException) {
key = "pdfjs-invalid-file-error";
} else if (reason instanceof pdfjsLib.MissingPDFException) {
key = "pdfjs-missing-file-error";
} else if (reason instanceof pdfjsLib.UnexpectedResponseException) {
key = "pdfjs-unexpected-response-error";
} else if (reason instanceof pdfjsLib.ResponseException) {
key = reason.missing
? "pdfjs-missing-file-error"
: "pdfjs-unexpected-response-error";
}
self.l10n.get(key).then(msg => {
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
$ gulp dist-install
Install the Node canvas library and run the example to convert the first page of a
PDF file to a PNG image:
Run the example to convert the first page of a PDF file to a PNG image:
$ npm install canvas
$ cd examples/node/pdf2png
$ node pdf2png.js
$ node pdf2png.mjs

View File

@ -13,41 +13,9 @@
* limitations under the License.
*/
import { strict as assert } from "assert";
import Canvas from "canvas";
import fs from "fs";
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.
const CMAP_URL = "../../../node_modules/pdfjs-dist/cmaps/";
const CMAP_PACKED = true;
@ -56,8 +24,6 @@ const CMAP_PACKED = true;
const STANDARD_FONT_DATA_URL =
"../../../node_modules/pdfjs-dist/standard_fonts/";
const canvasFactory = new NodeCanvasFactory();
// Loading file from file system into typed array.
const pdfPath =
process.argv[2] || "../../../web/compressed.tracemonkey-pldi-09.pdf";
@ -69,7 +35,6 @@ const loadingTask = getDocument({
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
standardFontDataUrl: STANDARD_FONT_DATA_URL,
canvasFactory,
});
try {
@ -78,6 +43,7 @@ try {
// Get the first page.
const page = await pdfDocument.getPage(1);
// Render the page on a Node canvas with 100% scale.
const canvasFactory = pdfDocument.canvasFactory;
const viewport = page.getViewport({ scale: 1.0 });
const canvasAndContext = canvasFactory.create(
viewport.width,
@ -91,7 +57,7 @@ try {
const renderTask = page.render(renderContext);
await renderTask.promise;
// 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) {
if (error) {
console.error("Error: " + error);

View File

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

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 2015 Mozilla Foundation
/*
Copyright 2024 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (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.
See the License for the specific language governing permissions and
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";
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");
var VIEWER_URL = chrome.runtime.getURL("content/web/viewer.html");
function getViewerURL(pdf_url) {
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url);
}
document.addEventListener("animationstart", onAnimationStart, true);
if (document.contentType === "application/pdf") {
chrome.runtime.sendMessage({ action: "canRequestBody" }, maybeRenderPdfDoc);
}
function onAnimationStart(event) {
if (event.animationName === "pdfjs-detected-object-or-embed") {
@ -221,3 +224,38 @@ function getEmbeddedViewerURL(path) {
path = a.href;
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";
(function ExtensionRouterClosure() {
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");
var CRX_BASE_URL = chrome.extension.getURL("/");
var VIEWER_URL = chrome.runtime.getURL("content/web/viewer.html");
var CRX_BASE_URL = chrome.runtime.getURL("/");
var schemes = [
"http",
"https",
"ftp",
"file",
"chrome-extension",
"blob",
@ -56,73 +55,50 @@ limitations under the License.
return undefined;
}
// TODO(rob): Use declarativeWebRequest once declared URL-encoding is
// supported, see http://crbug.com/273589
// (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) {
function resolveViewerURL(originalUrl) {
if (originalUrl.startsWith(CRX_BASE_URL)) {
// This listener converts chrome-extension://.../http://...pdf to
// chrome-extension://.../content/web/viewer.html?file=http%3A%2F%2F...pdf
var url = parseExtensionURL(details.url);
var url = parseExtensionURL(originalUrl);
if (url) {
url = VIEWER_URL + "?file=" + url;
var i = details.url.indexOf("#");
var i = originalUrl.indexOf("#");
if (i > 0) {
url += details.url.slice(i);
url += originalUrl.slice(i);
}
console.log("Redirecting " + details.url + " to " + url);
return { redirectUrl: url };
}
return undefined;
},
{
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);
return url;
}
}
);
console.log("Set up extension URL router.");
return undefined;
}
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,
});
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));
}
localStorage.removeItem(key);
}
});
// 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 }] }
);
console.log("Set up extension URL router.");
})();

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",
"manifest_version": 2,
"minimum_chrome_version": "103",
"manifest_version": 3,
"name": "PDF Viewer",
"version": "PDFJSSCRIPT_VERSION",
"description": "Uses HTML5 to display PDF files directly in the browser.",
@ -10,61 +10,52 @@
"16": "icon16.png"
},
"permissions": [
"fileBrowserHandler",
"alarms",
"declarativeNetRequestWithHostAccess",
"webRequest",
"webRequestBlocking",
"<all_urls>",
"tabs",
"webNavigation",
"storage"
],
"host_permissions": ["<all_urls>"],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*", "ftp://*/*", "file://*/*"],
"matches": ["http://*/*", "https://*/*", "file://*/*"],
"run_at": "document_start",
"all_frames": true,
"css": ["contentstyle.css"],
"js": ["contentscript.js"]
}
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"file_browser_handlers": [
{
"id": "open-as-pdf",
"default_title": "Open with PDF Viewer",
"file_filters": ["filesystem:*.pdf"]
}
],
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
},
"storage": {
"managed_schema": "preferences_schema.json"
},
"options_ui": {
"page": "options/options.html",
"chrome_style": true
"page": "options/options.html"
},
"options_page": "options/options.html",
"background": {
"page": "pdfHandler.html"
},
"page_action": {
"default_icon": {
"19": "icon19.png",
"38": "icon38.png"
},
"default_title": "Show PDF URL",
"default_popup": "pageActionPopup.html"
"service_worker": "background.js"
},
"incognito": "split",
"web_accessible_resources": [
"content/web/viewer.html",
"http:/*",
"https:/*",
"ftp:/*",
"file:/*",
"chrome-extension:/*",
"blob:*",
"data:*",
"filesystem:/*",
"drive:*"
{
"resources": [
"content/web/viewer.html",
"http:/*",
"https:/*",
"file:/*",
"chrome-extension:/*",
"blob:*",
"data:*",
"filesystem:/*",
"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
limitations under the License.
*/
/* eslint strict: ["error", "function"] */
"use strict";
(function () {
"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 storageSync = chrome.storage.sync;
@ -37,16 +41,12 @@ limitations under the License.
});
});
function getStorageNames(callback) {
var x = new XMLHttpRequest();
async function getStorageNames(callback) {
var schema_location = chrome.runtime.getManifest().storage.managed_schema;
x.open("get", chrome.runtime.getURL(schema_location));
x.onload = function () {
var storageKeys = Object.keys(x.response.properties);
callback(storageKeys);
};
x.responseType = "json";
x.send();
var res = await fetch(chrome.runtime.getURL(schema_location));
var storageManifest = await res.json();
var storageKeys = Object.keys(storageManifest.properties);
callback(storageKeys);
}
// Save |values| to storage.sync and delete the values with that key from
@ -150,4 +150,4 @@ limitations under the License.
}
);
}
})();
});

View File

@ -19,23 +19,28 @@ limitations under the License.
<meta charset="utf-8">
<title>PDF.js viewer options</title>
<style>
/* TODO: Remove as much custom CSS as possible - crbug.com/446511 */
body {
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 */
}
.settings-row {
margin: 0.65em 0;
margin: 1em 0;
}
.checkbox label {
display: inline-flex;
align-items: center;
}
.checkbox label input {
flex-shrink: 0;
}
</style>
</head>
<body>
<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">
<!-- Chromium's style: //src/extensions/renderer/resources/extension.css -->
<div class="checkbox">
<div class="settings-row checkbox">
<label>
<input type="checkbox">
<span></span>

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
limitations under the License.
*/
/* import-globals-from preserve-referer.js */
/* globals canRequestBody */ // From preserve-referer.js
"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 prority (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) {
// |pdf_url| may contain a fragment such as "#page=2". That should be passed
@ -31,174 +276,42 @@ function getViewerURL(pdf_url) {
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url) + hash;
}
/**
* @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(
// If the user has not granted access to file:-URLs, then declarativeNetRequest
// will not catch the request. It is still visible through the webNavigation
// 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
// user to activate file permissions.
chrome.webNavigation.onBeforeNavigate.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);
}
// 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;
}
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
// 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
// user to activate file permissions.
chrome.webNavigation.onBeforeNavigate.addListener(
function (details) {
if (details.frameId === 0 && !isPdfDownloadable(details)) {
chrome.tabs.update(details.tabId, {
url: getViewerURL(details.url),
});
}
},
{
url: [
{
urlPrefix: "file://",
pathSuffix: ".pdf",
},
{
urlPrefix: "file://",
pathSuffix: ".PDF",
},
],
});
}
);
});
},
{
url: [
{
urlPrefix: "file://",
pathSuffix: ".pdf",
},
{
urlPrefix: "file://",
pathSuffix: ".PDF",
},
],
}
);
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message && message.action === "getParentOrigin") {
@ -245,6 +358,11 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
url,
});
}
return undefined;
}
if (message && message.action === "canRequestBody") {
sendResponse(canRequestBody(sender.tab.id, sender.frameId));
return undefined;
}
return undefined;
});

View File

@ -45,7 +45,37 @@
"type": "boolean",
"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": ""
},
"enableSignatureEditor": {
"type": "boolean",
"default": false
},
"enableUpdatedAddImage": {
"type": "boolean",
"default": false
},
@ -68,10 +98,6 @@
"description": "Whether to allow execution of active content (JavaScript) by PDF files.",
"default": false
},
"enableHighlightEditor": {
"type": "boolean",
"default": false
},
"enableHighlightFloatingButton": {
"type": "boolean",
"default": false
@ -80,10 +106,6 @@
"type": "string",
"default": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F"
},
"enableStampEditor": {
"type": "boolean",
"default": true
},
"disableRange": {
"title": "Disable range requests",
"description": "Whether to disable range requests (not recommended).",
@ -202,6 +224,11 @@
"description": "The color is a string as defined in CSS. Its goal is to help improve readability in high contrast mode",
"type": "string",
"default": "CanvasText"
},
"enableAutoLinking": {
"description": "Enable creation of hyperlinks from text that look like URLs.",
"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
limitations under the License.
*/
/* import-globals-from pdfHandler.js */
/* exported saveReferer */
"use strict";
/**
* This file is one part of the Referer persistency implementation. The other
* part resides in chromecom.js.
*
* This file collects request headers for every http(s) request, and temporarily
* stores the request headers in a dictionary. Upon completion of the request
* (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.
* This file collects Referer headers for every http(s) request, and temporarily
* stores the request headers in a dictionary, for REFERRER_IN_MEMORY_TIME ms.
*
* 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
@ -36,49 +30,64 @@ limitations under the License.
* See setReferer in chromecom.js for more explanation of this logic.
*/
// Remembers the request headers for every http(s) page request for the duration
// of the request.
var g_requestHeaders = {};
/* exported canRequestBody */ // Used in pdfHandler.js
// g_referrers[tabId][frameId] = referrer of PDF frame.
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 () {
var requestFilter = {
urls: ["*://*/*"],
types: ["main_frame", "sub_frame"],
};
chrome.webRequest.onSendHeaders.addListener(
function (details) {
g_requestHeaders[details.requestId] = details.requestHeaders;
},
requestFilter,
["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];
}
})();
// g_postRequests[tabId] = Set of frameId that were loaded via POST.
var g_postRequests = {};
/**
* @param {object} details - onHeadersReceived event data.
*/
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] = {};
var rIsReferer = /^referer$/i;
chrome.webRequest.onSendHeaders.addListener(
function saveReferer(details) {
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);
},
{ urls: ["*://*/*"], types: ["main_frame", "sub_frame"] },
["requestHeaders", "extraHeaders"]
);
function forgetReferrerEventually(tabId) {
if (g_referrerTimers[tabId]) {
clearTimeout(g_referrerTimers[tabId]);
}
g_referrers[details.tabId][details.frameId] = referer;
g_referrerTimers[tabId] = setTimeout(() => {
delete g_referrers[tabId];
delete g_referrerTimers[tabId];
delete g_postRequests[tabId];
}, REFERRER_IN_MEMORY_TIME);
}
chrome.tabs.onRemoved.addListener(function (tabId) {
delete g_referrers[tabId];
});
// 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
// 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") {
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 frameId = port.sender.frameId;
var dnrRequestId;
// 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]) || "";
port.onMessage.addListener(function (data) {
// 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) {
referer = data.referer;
}
chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
if (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.
port.postMessage(referer);
dnrRequestId = data.dnrRequestId;
setStickyReferrer(dnrRequestId, tabId, data.requestUrl, referer, () => {
// Acknowledge the message, and include the latest referer for this frame.
port.postMessage(referer);
});
});
// The port is only disconnected when the other end reloads.
port.onDisconnect.addListener(function () {
if (g_referrers[tabId]) {
delete g_referrers[tabId][frameId];
}
chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
chrome.webRequest.onHeadersReceived.removeListener(exposeOnHeadersReceived);
unsetStickyReferrer(dnrRequestId);
});
// Expose some response headers for fetch API calls from PDF.js;
// This is a work-around for https://crbug.com/784528
chrome.webRequest.onHeadersReceived.addListener(
exposeOnHeadersReceived,
{
urls: ["https://*/*"],
types: ["xmlhttprequest"],
tabId,
},
["blocking", "responseHeaders"]
);
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) {
if (details.frameId !== frameId) {
return undefined;
}
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 };
}
});
function setStickyReferrer(dnrRequestId, tabId, url, referer, callback) {
if (!referer) {
unsetStickyReferrer(dnrRequestId);
callback();
return;
}
const rule = {
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],
},
action: {
type: "modifyHeaders",
requestHeaders: [{ operation: "set", header: "referer", value: referer }],
},
};
chrome.declarativeNetRequest.updateSessionRules(
{ removeRuleIds: [dnrRequestId], addRules: [rule] },
callback
);
}
function unsetStickyReferrer(dnrRequestId) {
if (dnrRequestId) {
chrome.declarativeNetRequest.updateSessionRules({
removeRuleIds: [dnrRequestId],
});
}
}

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
// is quite disruptive (crbug.com/511670).
chrome.runtime.onUpdateAvailable.addListener(function () {
if (chrome.extension.getViews({ type: "tab" }).length === 0) {
chrome.tabs.query({ url: chrome.runtime.getURL("*") }, tabs => {
if (tabs?.length) {
return;
}
chrome.runtime.reload();
}
});
});

View File

@ -42,8 +42,35 @@ limitations under the License.
return;
}
maybeSendPing();
setInterval(maybeSendPing, 36e5);
// 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();
}
});
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() {
getLoggingPref(function (didOptOut) {
@ -61,12 +88,20 @@ limitations under the License.
// send more pings.
return;
}
doSendPing();
});
}
function doSendPing() {
chrome.storage.local.get(localStorage, items => {
Object.assign(localStorage, items);
var lastTime = parseInt(localStorage.telemetryLastTime) || 0;
var wasUpdated = didUpdateSinceLastCheck();
if (!wasUpdated && Date.now() - lastTime < MINIMUM_TIME_BETWEEN_PING) {
return;
}
localStorage.telemetryLastTime = Date.now();
updateLocalStorage("telemetryLastTime", Date.now());
var deduplication_id = getDeduplicationId(wasUpdated);
var extension_version = chrome.runtime.getManifest().version;
@ -104,7 +139,7 @@ limitations under the License.
for (const c of buf) {
id += (c >>> 4).toString(16) + (c & 0xf).toString(16);
}
localStorage.telemetryDeduplicationId = id;
updateLocalStorage("telemetryDeduplicationId", id);
}
return id;
}
@ -119,7 +154,7 @@ limitations under the License.
if (!chromeVersion || localStorage.telemetryLastVersion === chromeVersion) {
return false;
}
localStorage.telemetryLastVersion = chromeVersion;
updateLocalStorage("telemetryLastVersion", chromeVersion);
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 fs from "fs";
import { join as joinPaths } from "path";
import vm from "vm";
const PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
const ROOT_PREFIX = "$ROOT/";
function isPDFJSPreprocessor(obj) {
return obj.type === "Identifier" && obj.name === PDFJS_PREPROCESSOR_NAME;
@ -40,18 +37,6 @@ function handlePreprocessorAction(ctx, actionName, args, path) {
return result;
}
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");
} catch (e) {
@ -184,7 +169,7 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
path.replaceWith(t.importExpression(source));
}
},
BlockStatement: {
"BlockStatement|StaticBlock": {
// Visit node in post-order so that recursive flattening
// of blocks works correctly.
exit(path) {
@ -215,6 +200,10 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
}
subExpressionIndex++;
}
if (node.type === "StaticBlock" && node.body.length === 0) {
path.remove();
}
},
},
Function: {
@ -234,6 +223,26 @@ function babelPluginPDFJSPreprocessor(babel, ctx) {
}
},
},
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();
}
},
},
},
};
}

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

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

View File

@ -5,7 +5,6 @@ var d = PDFJSDev.test('FALSE');
var e = PDFJSDev.eval('TRUE');
var f = PDFJSDev.eval('TEXT');
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 j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0';
var k = !PDFJSDev.test('TRUE');

View File

@ -1,4 +1,4 @@
import { Test } from "import-name";
import { Test2 } from './non-alias';
export { Test3 } from "import-name";
await import( /*webpackIgnore: true*/"./non-alias");
await import(/*webpackIgnore: true*/"./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;
}
}
}

View File

@ -1 +0,0 @@
{ "test": "test" }

View File

@ -7,7 +7,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
let errors = 0;
const baseDir = path.join(__dirname, "fixtures_esprima");
const baseDir = path.join(__dirname, "fixtures_babel");
const files = fs
.readdirSync(baseDir)
.filter(function (name) {
@ -49,7 +49,7 @@ files.forEach(function (expectationFilename) {
errors++;
// Allow regenerating the expected output using
// OVERWRITE=true node ./external/builder/test-fixtures_esprima.mjs
// OVERWRITE=true node ./external/builder/test-fixtures_babel.mjs
if (process.env.OVERWRITE) {
fs.writeFileSync(expectationFilename, out + "\n");
}

View File

@ -31,7 +31,7 @@ async function downloadLanguageCodes() {
console.log("Downloading language codes...\n");
const ALL_LOCALES =
"https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/locales/all-locales";
"https://raw.githubusercontent.com/mozilla/gecko-dev/master/browser/locales/all-locales";
const response = await fetch(ALL_LOCALES);
if (!response.ok) {
@ -52,8 +52,9 @@ async function downloadLanguageFiles(root, langCode) {
// Constants for constructing the URLs. Translations are taken from the
// Nightly channel as those are the most recent ones.
const MOZ_CENTRAL_ROOT = "https://hg.mozilla.org/l10n-central/";
const MOZ_CENTRAL_PDFJS_DIR = "/raw-file/default/toolkit/toolkit/pdfviewer/";
const MOZ_CENTRAL_ROOT =
"https://raw.githubusercontent.com/mozilla-l10n/firefox-l10n/main/";
const MOZ_CENTRAL_PDFJS_DIR = "/toolkit/toolkit/pdfviewer/";
// Defines which files to download for each language.
const files = ["viewer.ftl"];

39
external/openjpeg/LICENSE_OPENJPEG vendored Normal file
View File

@ -0,0 +1,39 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2003-2009, Francois-Olivier Devaux
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* Copyright (c) 2012, CS Systemes d'Information, France
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

View File

@ -0,0 +1,22 @@
Copyright (c) 2024, Mozilla Foundation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -9,4 +9,4 @@ In order to generate the file `openjpeg.js`:
## Licensing
[OpenJPEG](https://www.openjpeg.org/) is under [BSD 2-clause "Simplified" License](https://github.com/uclouvain/openjpeg/blob/master/LICENSE)
and [pdf.js.openjpeg](https://github.com/mozilla/pdf.js.openjpeg/) is released under [Apache 2](https://github.com/mozilla/pdf.js.openjpeg/blob/main/LICENSE) license so `openjpeg.js` is released under [Apache 2](https://github.com/mozilla/pdf.js.openjpeg/blob/main/LICENSE) license too.
and [pdf.js.openjpeg](https://github.com/mozilla/pdf.js.openjpeg/) is released under [BSD 2-clause](https://github.com/mozilla/pdf.js.openjpeg/blob/main/LICENSE) license so `openjpeg.js` is released under [BSD 2-clause](https://github.com/mozilla/pdf.js.openjpeg/blob/main/LICENSE) license too.

File diff suppressed because one or more lines are too long

BIN
external/openjpeg/openjpeg.wasm vendored Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

13
jsdoc.json Normal file
View File

@ -0,0 +1,13 @@
{
"source": {
"include": ["src/display/api.js"]
},
"opts": {
"destination": "build/jsdoc/"
},
"templates": {
"default": {
"includeDate": false
}
}
}

View File

@ -217,9 +217,56 @@ pdfjs-web-fonts-disabled = Kijuko dit pa coc me kakube woko: pe romo tic ki dit
## Editing
## Remove button for the various kind of editor.
##
## Alt-text dialog
## Editor resizers
## This is used in an aria label to help to understand the role of the resizer.
## Color picker
## Show all highlights
## This is a toggle button to show/hide all the highlights.
## New alt-text dialog
## Group note for entire feature: Alternative text (alt text) helps when people can't see the image. This feature includes a tool to create alt text automatically using an AI model that works locally on the user's device to preserve privacy.
## Image alt-text settings
## "Annotations removed" bar
## Add a signature dialog
## Tab names
## Tab panels
## Controls
## Dialog buttons
## Main menu for adding/removing signatures
## Editor toolbar
## Edit signature description dialog

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