1506 Commits

Author SHA1 Message Date
Jonas Jenwald
fc9d9e49de Improve unit-testing for the PDFDocumentProxy.prototype.getPageIndex method
Given the existing worker-thread caching it doesn't seem, based on the coverage report, that all of the `getPageIndex` code is being tested.
2026-04-26 13:38:08 +02:00
Tim van der Meij
2674a9f3e4
Merge pull request #21137 from calixteman/bug2022700
Don't decode name of the checkboxes exported values (bug 2022700)
2026-04-26 12:00:58 +02:00
Tim van der Meij
f41c60ab7e
Merge pull request #21147 from Snuffleupagus/unittestcli-download-PDFs
Download linked PDFs when running `gulp unittestcli`
2026-04-24 20:29:14 +02:00
calixteman
2d896faa1e
Merge pull request #21142 from calixteman/input_color_alpha
[Ink] Replace the opacity slider with an alpha-enabled color input
2026-04-24 15:46:46 +02:00
calixteman
25204d359a
Merge pull request #21136 from calixteman/bug2033908
Avoid to add outlines having a deleted page which leads to clone a useless page (bug 2033908)
2026-04-23 22:24:58 +02:00
Jonas Jenwald
4e08d00466 Download linked PDFs when running gulp unittestcli
Currently a fair number of unit-tests are disabled in Node.js not because of missing functionality, but only because they use linked PDFs.
2026-04-23 21:52:08 +02:00
Calixte Denizet
f266c4d8b8
[Ink] Replace the opacity slider with an alpha-enabled color input
The alpha feature is available in Firefox nightly (with the pref `dom.forms.html_color_picker.enabled` set to `true`).
It's available in Safari but not in Chrome.
2026-04-23 21:37:37 +02:00
Jonas Jenwald
a6988582d2 [api-minor] Replace the CCITT and JBig2 fallback decoders with a JS version of the PDFium decoder
*Note:* This is similar to PR 19525, which did the same thing for the OpenJPEG decoder.

The advantages of doing this are:
 - The same JBig2 decoder is used regardless of WASM being supported or not, which means consistent rendering.
 - The old `Jbig2Image` implementation has various bugs and missing features.
 - Less code that needs to be maintained in the PDF.js project, since both the CCITT and the JBig2 decoder is replaced.

The disadvantage of doing this is:
 - Slightly larger bundle size, however the effect is limited since a fair amount of PDF.js code can be removed. For the `gulp mozcentral` target the size increase is approximately 54 kilo-bytes (which is small compared to the 452 kilo-bytes for the JS version of the OpenJPEG decoder).
2026-04-22 23:24:26 +02:00
Calixte Denizet
42ccca7ee8
Don't decode name of the checkboxes exported values (bug 2022700) 2026-04-22 18:30:43 +02:00
Calixte Denizet
a52c8334f5 Avoid to add outlines having a deleted page which leads to clone a useless page (bug 2033908) 2026-04-21 22:23:28 +02:00
Tim van der Meij
e070944ff0
Merge pull request #21131 from Snuffleupagus/fix-CopyLocalImage-unittests
Improve the "CopyLocalImage" unit-tests
2026-04-21 20:18:40 +02:00
Nicolò Ribaudo
f7725254f3
Fix unit test for dependency tracking
Follow up to PR #21102
2026-04-21 11:48:18 +02:00
Jonas Jenwald
b01eeaf8e1 Improve the "CopyLocalImage" unit-tests
Rather than relying on the time it takes to parse/render the pages, which leads to intermittent failures, add a test-only property and use it to check if the "CopyLocalImage" code-path was exercised.
2026-04-21 11:43:08 +02:00
Calixte Denizet
8ddbeda4a0
Remove user and password from URLs (bug 2025109) 2026-04-20 20:53:24 +02:00
Tim van der Meij
801236f8c4
Fix the gets text content, with correct properties (issue 8276) unit test
This unit test failed consistently in Firefox both locally and on GitHub
Actions (but not in Chrome or on the bots), which suggests a timing issue.

Since all other unit tests that rely on `commonObjs` actually render the
page, most likely to make sure that `commonObjs` is fully populated at
the time of the check, this commit mirrors that approach to this test,
which indeed fixes the issue.
2026-04-19 19:09:43 +02:00
Jonas Jenwald
c155a86733 Store the Type1 program privateData in a Map, rather than an Object
This is nicer when checking if fields exist in `Type1Font.prototype.wrap`, and a couple of loops in that method are also "modernized" slightly.
2026-04-18 12:32:22 +02:00
Jonas Jenwald
b2cc9ae6d5 Move the string32 helper to the src/display/font_loader.js file
After the previous patches the `string32` helper function is now only used in the `FontLoader.prototype._prepareFontLoadEvent` method, which is stubbed out in the Firefox PDF Viewer, hence move it there instead to avoid bundling dead code.
2026-04-14 20:36:34 +02:00
Nicolò Ribaudo
2ad6b88850
Fix dependency tracking in pattern fill
1. Record `fill` dependencies even if we early return due to `isPatternFill``
2. Isolate the `drawPattern` inner `executeOperationList` in a
   `CanvasNestedDependencyTracker` so that it does not consume pending
   dependencies from the outer list.
2026-04-14 14:16:26 +01:00
calixteman
1025af059f
Merge pull request #21099 from calixteman/no_gpu
Use the gpu for drawing meshes only when it has more than 16 triangles (bug 2030745)
2026-04-13 23:55:52 +02:00
Calixte Denizet
a2c57ee69e
Use the gpu for drawing meshes only when it has more than 16 triangles (bug 2030745)
And in order to slightly improve performances, move the figure creation in the worker.
2026-04-13 22:23:03 +02:00
Calixte Denizet
8c9b819b4e
Add the UI for merging PDFs (bug 2028071) 2026-04-13 19:38:56 +02:00
calixteman
f61e00f2fa
Merge pull request #21054 from calixteman/fix_writing_numbers
Fix the way to write numbers when saving a pdf
2026-04-07 16:55:36 +02:00
Jonas Jenwald
6f0431456c Reduce allocations when compiling CFF fonts
Currently the `CFFCompiler.prototype.compile` implementation seem a bit inefficient, since the data is stored in a plain Array that needs to grow (a lot) during compilation. Additionally, adding a lot of entries isn't very efficient either and requires special handling of the "too many elements" case.
Some of the "helper" methods that use TypedArrays internally currently need to convert their return data to plain Arrays, via the `compileTypedArray` method, which adds even more intermediate allocations.
Note also that the `OpenTypeFileBuilder` has a special-case for writing plain Array data, which is only needed because of how the CFF compilation is implemented.

To improve this situation the `CFFCompiler.prototype.compile` method is re-factored to store its data in a TypedArray, whose initial size is estimated from the "raw" file size.
This removes the need for most intermediate allocations, and it also handles adding of "many elements" more efficiently.
2026-04-07 14:27:55 +02:00
Calixte Denizet
3d95aab8d7
Fix the way to write numbers when saving a pdf
It'll avoid to have numbers like 1e-23.
2026-04-07 10:52:06 +02:00
calixteman
a9f142c796
Unconditionally create a gpu device
One drawback of the current implementation is that the GPU device can be
unavailable at the time of the first pattern fill, which causes the
GPU-accelerated canvas to be move on the main thread because of putImageData.

Most of the shading patterns stuff will be moved to the GPU and in order
to avoid creating some useless data we've to know if the GPU is available or not.

So in this patch we create the GPU device during the worker initialization
and pass a flag to the evaluator to know if the GPU is available or not.
2026-04-06 13:23:29 +02:00
Jonas Jenwald
ccab310a39 Add an optional parameter in buildPostScriptJsFunction to force use of the PSStackBasedInterpreter code
This way the test-only function `buildPostScriptProgramFunction` can be removed.
2026-04-05 13:52:09 +02:00
Tim van der Meij
68da778329
Introduce a function type enumeration
This improves readability by removing "magic" numbers, and matches what
we already have for e.g. annotation and shading types.

Note that function type 1 does not exist in the specification, but that
also applies to everything higher than 4, so we can also remove the
specific handling of function type 1 and instead just let it fall
through to throwing an exception for unknown function types, in which we
now also log the provided function type to aid debugging.
2026-04-04 14:57:59 +02:00
Jonas Jenwald
f6bac014ea [api-minor] Remove PostScriptCompiler and PostScriptEvaluator, since it's now dead code (PR 21023 follow-up)
These classes, and various related code, became unused after PR 21023 with only unit-tests actually running that code now.

Also removes the `isEvalSupported` API option, since the `PostScriptCompiler` was the only remaining code where `eval` was used.
2026-04-03 22:14:14 +02:00
Tim van der Meij
d1a711bca3
Merge pull request #21023 from calixteman/wasm_stack_js
Add a js fallback for interpreting ps code
2026-04-03 20:09:29 +02:00
Jonas Jenwald
68366e31e4 Move the MathClamp helper function to its own file
This allows using it in the `src/scripting_api/` folder, without increasing the size of the scripting-bundle by also importing a bunch of unused code.
2026-04-02 11:22:28 +02:00
calixteman
8c7a5f3500
Add a js fallback for interpreting ps code
It's a basic stack based interpreter.
A wasm version will come soon.
2026-04-01 21:40:45 +02:00
Calixte Denizet
f373923170 Encrypt pdf data when merging the same pdf (bug 2028369) 2026-04-01 19:01:11 +02:00
calixteman
399fce6471
Merge pull request #21010 from calixteman/ps_js
Add an interpreter for optimized ps code
2026-03-31 22:21:00 +02:00
Calixte Denizet
9f3de1edf6
Add an interpreter for optimized ps code
It'll be used as a fallback when wasm is disabled.
And add in the debugger a view for the generated js code and one for the ps code.
2026-03-31 21:00:22 +02:00
Calixte Denizet
3727b7095a Add support for function-based shadings (bug 1254066)
It fixes #5046.
We just generate a mesh for the pattern rectangle where the color of each vertex is computed from the function.
Since the mesh is generated in the worker we don't really take into account the current transform when it's drawn.
That being said, there are maybe some possible improvements in using directly the gpu for the shading creation
which could then take into account the current transform, but it could only work with ps function we can convert
ino wgsl language and simple enough color spaces (gray and rgb).
2026-03-31 20:46:01 +02:00
Tim van der Meij
58b807d8e8
Merge pull request #21008 from calixteman/ast_cse
Avoid expressions duplication in the ps AST and use a local instead when compiling to WASM
2026-03-31 20:21:59 +02:00
Tim van der Meij
48228e2756
Merge pull request #21013 from calixteman/bug2026956
Add attachments when merging/reorganizing a pdf (bug 2026956)
2026-03-31 20:17:54 +02:00
Calixte Denizet
5b8c04f383 Add attachments when merging/reorganizing a pdf (bug 2026956) 2026-03-31 14:48:06 +02:00
Calixte Denizet
63cf35b47f Avoid expressions duplication in the ps AST and use a local instead when compiling to WASM 2026-03-30 16:30:33 +02:00
Jonas Jenwald
bfffb6c0f0 Import fs/promises directly in a few spots in the unit-tests
Also, use the existing PDF.js helper function to fetch text-data when running the "bidi" tests in browsers.
2026-03-30 14:34:53 +02:00
calixteman
952952c905
[api-minor] Rewrite the ps lexer & parser and add a small Wasm compiler
The main goal is to remove the eval-based interpreter.
In order to have some good performances, the new parser performs some optimizations
on the AST (similar to the ones in the previous implementation),
and the Wasm compiler generates code for the optimized AST.
For now, in case of errors or unsupported features, the Wasm compiler returns null
and the old interpreter is used as a fallback.
Few things are still missing:
 - a wasm-based interpreter using a stack (in case the ps code isn't stack-free);
 - a better js implementation in case of disabled wasm.

 but they will be added in follow-up patches.
2026-03-30 09:22:33 +02:00
Tim van der Meij
ada3438039
Merge pull request #21001 from Snuffleupagus/getDestFromStructElement-unit-test
Add a unit-test for the `Catalog.#getDestFromStructElement` method
2026-03-29 16:08:21 +02:00
Jonas Jenwald
498daadf3c Simplify the applyOpacity helper function
This function only has a single call-site (if we ignore the unit-tests), where the colors are split into separate parameters.
Given that all the color components are modified in the exact same way, it seems easier (and shorter) to pass the colors as-is to `applyOpacity` and have it use `Array.prototype.map()` instead.
2026-03-29 14:52:06 +02:00
Jonas Jenwald
d1f15fe352 Add a unit-test for the Catalog.#getDestFromStructElement method
This code already has an integration-test, however also having a unit-test shouldn't hurt since those are often easier to run and debug (and it nicely complements the existing `outline` unit-tests).

The patch also makes the following smaller changes to the method itself:
 - Avoid creating and parsing an empty Array, when doing the `pageRef` search.
 - Use `XRef.prototype.fetch` directly, when walking the parent chain, since the check just above ensures that the value is a Reference.
 - Use the `lookupRect` helper when parsing the /BBox entry.
2026-03-29 14:01:43 +02:00
Calixte Denizet
2e3d79e616
Break text chunks only if the base font is different
It fixes #20956.
2026-03-26 21:39:32 +01:00
Calixte Denizet
42c229c267
Add the bidi tests coming from BidiTest.txt and BidiCharacterTest.txt
Some tests were failing and has been fixed:
 - "Hello" + Alef + "(" + Bet: the "(" (neutral) was not considered as a part of the group Alef(Bet and the group wasn't reverted;
 - some intermediate neutrals were considered as strong.
2026-03-25 15:18:50 +01:00
Jonas Jenwald
a0102abe76 Move the NetworkStream choice from src/display/api.js and into a separate file
This code already isn't used (or even bundled) in the Firefox PDF Viewer, and it also slightly reduces the number of import maps that need to be maintained.
2026-03-24 17:08:04 +01:00
Jonas Jenwald
3a372fde94 [api-minor] Replace the CMapReaderFactory, StandardFontDataFactory, and WasmFactory API options with a single factory/option
Currently we have no less than three different, but very similar, factories for reading built-in CMap files, standard font files, and wasm files on the main-thread.[1]
These factories were added at different points in time, since I cannot imagine that we'd add essentially three copies of the same code otherwise.

Nowadays these factories are often not even used[2], since worker-thread fetching is used whenever possible to improve performance. In particular, they will *only* be used when either:
 - The PDF.js library runs in Node.js environments.
 - The user manually sets `useWorkerFetch = false` when calling `getDocument`.
 - The user provides custom `CMapReaderFactory`, `StandardFontDataFactory`, and/or `WasmFactory` instances when calling `getDocument`.

By replacing these factories with *a single* new `BinaryDataFactory` factory/option the number of `getDocument` options are thus reduced, which cannot hurt.
This also reduces the total bundle-size of the Firefox PDF Viewer a little bit, and it slightly reduces the number of import maps that need to be maintained.

*Please note:* For users that provide custom `CMapReaderFactory`, `StandardFontDataFactory`, and `WasmFactory` instances when calling `getDocument` this will be a breaking change, however it's unlikely that (many) such users exist.
(The *internal* format data-format of `CMapReaderFactory` was changed in PR 18951, and there hasn't been a single question/complaint about it in well over a year.)

---

[1] Any new functionality could easily lead to more such factories being added in the future, which wouldn't be great.

[2] Note that the Firefox PDF Viewer no longer use these factories, since it "forcibly" sets `useWorkerFetch = true` during building.
2026-03-22 15:49:06 +01:00
calixteman
ec24053ddf
Don't add an EOL after a superscript 2026-03-22 14:20:18 +01:00
Jonas Jenwald
262aeef3fa [api-minor] Simplify BaseCMapReaderFactory by having the worker-thread create the filename
The `BaseCMapReaderFactory`, `BaseStandardFontDataFactory`, and `BaseWasmFactory` classes are all very similar, and the only difference is really in their respective `fetch` methods.
By have the worker-thread "compute" the complete `filename` it's possible to simplify the `BaseCMapReaderFactory.prototype.fetch` method, which will allow future improvements to all of these classes.

A couple of things to note:
 - This code is unused, and it's not even bundled, in the Firefox PDF Viewer.
 - In browsers it's unused by default, and worker-thread fetching will always be used when possible since that's more efficient.

*Please note:* For users that provide a custom `CMapReaderFactory` instance when calling `getDocument` this could be a breaking change, however it's unlikely that any such users exist.
(The *internal* format of this data was changed previously in PR 18951, and there hasn't been a single question/complaint about it in well over a year.)
2026-03-21 15:54:40 +01:00