7512 Commits

Author SHA1 Message Date
Jonas Jenwald
60d6abdf4f A couple of small improvements of the new internal viewer
- Mention the internal viewer in the README, such that it's easier to find.

 - Implement a new `INTERNAL_VIEWER` define, such that it's easier to limit code to only the "internal-viewer" gulp target.

 - Only include the "GetRawData" message-handler when needed. Note that the `MessageHandler` [already throws](eb159abd6a/src/shared/message_handler.js (L121-L123)) for any missing handler.

 - Move the various new helper functions from `src/core/document.js` and into their own file. The reasons for doing this are:
    - That file is already quite large and complex as-is, and these helper functions are slightly orthogonal to its main functionality.
    - Babel isn't able to remove all of the new code, and by moving this into a separate file we can guarantee that no extra code ends up in e.g. Firefox.
2026-03-10 23:41:35 +01:00
Tim van der Meij
44a63549b0
Merge pull request #20831 from calixteman/internal_viewer
Add a new internal viewer to explore the structure of PDF files.
2026-03-10 20:48:40 +01:00
Tim van der Meij
15e58f3912
Merge pull request #20830 from Snuffleupagus/validateRangeRequestCapabilities-fix-tests
Improve the `validateRangeRequestCapabilities` unit-tests
2026-03-10 20:23:14 +01:00
Tim van der Meij
3f75c4e511
Merge pull request #20829 from Snuffleupagus/Blob-bytes
Start using `Blob.prototype.bytes()` in the code-base
2026-03-10 20:14:49 +01:00
Jonas Jenwald
5ef582fb20 Use optional chaining a little bit more in the src/display/api.js file
That format is preferred where possible, since it leads to ever so slightly shorter code overall.
2026-03-10 15:51:05 +01:00
Jonas Jenwald
873378b718
Merge pull request #20836 from Snuffleupagus/FontFaceObject-fix-asserts
Fix the `disableFontFace` and `fontExtraProperties` asserts in the `FontFaceObject` constructor (PR 20197 follow-up)
2026-03-09 20:08:58 +01:00
Jonas Jenwald
9f69617109 Fix the disableFontFace and fontExtraProperties asserts in the FontFaceObject constructor (PR 20197 follow-up)
In PR 19548 these checks were added to ensure that the font-data sent from the worker-thread *always* include correct `disableFontFace` and `fontExtraProperties` data.

For some reason PR 20197 then changed the code such that these checks became effectively pointless, since these properties are now checked after the fact *and* the new getters provide fallback values.
2026-03-09 18:00:11 +01:00
Jonas Jenwald
dbb6ffb8d5 Change the Font.prototype.glyphCacheValues method to return an iterator
This method is only used with loops, and it should be a tiny bit more efficient to use an iterator directly rather than first iterating through the underlying data to create a temporary `Array` that we finally iterate through at the call-site.

*Please note:* As port of these changes the chars/glyph caches, on the `Font` instances, are changed to use `Map`s rather than Objects.
2026-03-09 16:18:48 +01:00
Jonas Jenwald
8bbb7c88d3 Change the AnnotationLayer.prototype.getEditableAnnotations method to return an iterator
This method is only used with loops, and it should be a tiny bit more efficient to use an iterator directly rather than first iterating through the underlying `Map` to create a temporary `Array` that we finally iterate through at the call-site.
2026-03-09 16:11:21 +01:00
calixteman
9d81fafa8c
Add a new internal viewer to explore the structure of PDF files.
The one from pdf.js.utils is a bit too old: a lot of bugs have been fixed
in the code that parses PDF files since then.
It's just an internal development tool, so it doesn't need to be perfect,
but it should be good enough to be useful.
2026-03-09 14:16:12 +01:00
Calixte Denizet
0e48c16c3c
Add a UI to undo cut/delete and cancel a copy (bug 2021352, bug 2010832)
This happens in a bar on top of the thumbnails sidebar.
The label depending on the selected thumbnails is fixed.
2026-03-09 10:44:11 +01:00
Jonas Jenwald
a1b769caea Improve the validateRangeRequestCapabilities unit-tests
A number of these unit-tests didn't actually cover the intended code-paths, since many of them *accidentally* matched the "file size is smaller than two range requests"-check.

The patch also updates `validateRangeRequestCapabilities` to use return-value names that are consistent with the class fields used in the various stream implementations.
2026-03-08 18:28:50 +01:00
Jonas Jenwald
2598b0dcdd Start using Blob.prototype.bytes() in the code-base
Note that this isn't motivated by the miniscule reduction in code-size, but rather by wanting to unblock using this newer feature; see https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes
2026-03-08 14:06:03 +01:00
calixteman
253ce6e323
Handle outline with Structure Element (SE) destination 2026-03-08 12:28:24 +01:00
Jonas Jenwald
ddd69ce4e0 Remove the "DocProgress" loaded fallback from the getPdfManager function
Falling back to use the `loaded` byteLength if the server `contentLength` is unknown doesn't make a lot of sense, since it'd lead to the `onProgress` callback reporting `percent === 100` repeatedly while the document is loading despite that being obviously wrong.
Instead we'll now report `percent === NaN` in that case, thus showing the indeterminate progressBar, which seems more correct if the `contentLength` is unknown.

Please note that this code-path is normally not even reached, since streaming is enabled by default (applies e.g. to the Firefox PDF Viewer).
2026-03-08 10:22:01 +01:00
Jonas Jenwald
1f69cf964c Ensure that percent === NaN is consistently reported by the onProgress callback
With these changes `0`, `NaN`, `null`, and `undefined` in the `total`-property all result in `percent === NaN` being reported by the callback, since previously e.g. `0` would result in `percent === 100` being reported unconditionally which doesn't make a lot of sense.

Also, remove the "indeterminate" loadingBar (in the viewer) if the `PDFDocumentLoadingTask` fails since there won't be any more data arriving and displaying the animation thus seems wrong.
2026-03-08 10:21:55 +01:00
Tim van der Meij
98dc351cfa
Merge pull request #20824 from calixteman/bug2015853
Add the possibility to merge/update acroforms when merging/extracting (bug 2015853)
2026-03-07 20:12:02 +01:00
calixteman
baf8647b1f
Add the possibility to merge/update acroforms when merging/extracting (bug 2015853) 2026-03-07 19:03:02 +01:00
Jonas Jenwald
0c514b008b Use Response.prototype.bytes() more in the code-base (PR 20651 follow-up) 2026-03-07 15:50:36 +01:00
Jonas Jenwald
49e8240c19 Use Map.prototype.getOrInsertComputed in the scripting implementation
This adds a basic non-MOZCENTRAL polyfill for now, which we should be able to remove once the next QuickJS version is released; note the pending changelog at f1139494d1/Changelog (L7)
2026-03-07 13:19:40 +01:00
Jonas Jenwald
ca428aadae Use Math.sumPrecise in the scripting implementation
This adds a *very basic* non-MOZCENTRAL polyfill for now, which we should be able to remove once the next QuickJS version is released; note the pending changelog at f1139494d1/Changelog (L8)
2026-03-07 13:19:40 +01:00
Tim van der Meij
d34a15e03f
Merge pull request #20662 from Snuffleupagus/getPdfManager-async-read
Convert the data reading in `getPdfManager` to be asynchronous
2026-03-07 13:16:22 +01:00
Jonas Jenwald
d236b517fe Shorten the createActionsMap helper in the src/scripting_api/common.js file 2026-03-07 11:22:21 +01:00
Jonas Jenwald
efa13c5e2a Don't duplicate the Jbig2Error exception
Let `src/core/jbig2_ccittFax_wasm.js` import the existing exception, rather than duplicate its code.
2026-03-06 12:04:08 +01:00
Jonas Jenwald
29362e6afb Remove the JBig2CCITTFaxWasmImage instance when running clean-up
This follows the same pattern as the existing handling for the `JpxImage` instance.
2026-03-06 12:04:03 +01:00
Jonas Jenwald
7f4e29ed22 Change the "Terminate" worker-thread handler to an asynchronous function
This is a tiny bit shorter, which cannot hurt.
2026-03-06 11:24:12 +01:00
Jonas Jenwald
e8ab3cb335 Convert the data reading in getPdfManager to be asynchronous
This is not only shorter, but (in my opinion) it also simplifies the code.

*Note:* In order to keep the *five* different `BasePDFStreamReader` implementations consistent, we purposely don't re-factor the `PDFWorkerStreamReader` class to support `for await...of` iteration.
2026-03-05 22:50:26 +01:00
Tim van der Meij
688ae9b3e5
Merge pull request #20811 from calixteman/fix_xref
Add fetch** functions in the XRefWrapper
2026-03-05 22:02:08 +01:00
Tim van der Meij
01bc76e681
Merge pull request #20806 from Snuffleupagus/BinaryCMapStream-extends-Stream
Let `BinaryCMapStream` extend the `Stream` class
2026-03-05 20:43:37 +01:00
Calixte Denizet
150c1e80c2
Add fetch** functions in the XRefWrapper
It could fail to not have them if they're used during writing.
2026-03-05 19:21:12 +01:00
Jonas Jenwald
fccee4bffd Let BinaryCMapStream extend the Stream class
Looking at the `BinaryCMapStream` implementation, it's basically a "regular" `Stream` but with added functionality for reading compressed CMap data.
Hence, by letting `BinaryCMapStream` extend `Stream`, we can remove an effectively duplicate method and simplify/shorten the code a tiny bit.
2026-03-05 11:45:29 +01:00
Jonas Jenwald
aa445877a9 Use BaseStream.prototype.getString in the readPostScriptTable function
Currently the `customNames` are read one byte at a time, in a loop, and at every iteration converted to a string.
This can be replaced with the `BaseStream.prototype.getString` method, which didn't exist back when this function was written.
2026-03-04 18:34:07 +01:00
Jonas Jenwald
4d0709c174
Merge pull request #20795 from Snuffleupagus/Dict-more-iterators
Change the `Dict.prototype.{getKeys, getRawValues}` methods to return iterators
2026-03-04 18:26:42 +01:00
calixteman
7384359a41
Merge pull request #20781 from pengkunbin/fix/chinese-font-names-gbk
Fix missing Chinese font name variants (SimFang and XiaoBiaoSong) in GBK encoding detection
2026-03-04 16:49:44 +01:00
Jonas Jenwald
229e3642be Change the Dict.prototype.getRawValues method to return an iterator
This method is usually used with loops, and it should be a tiny bit more efficient to use an iterator directly rather than first iterating through ` Map`-values to create a temporary `Array` that we finally iterate through at the call-site.

Note that the `getRawValues` method is old code, and originally the `Dict` class stored its data in a regular `Object`, hence why the old code was written that way.
2026-03-04 16:07:49 +01:00
Jonas Jenwald
58996f21b2 Change the Dict.prototype.getKeys method to return an iterator
This method is usually used with loops, and it should be a tiny bit more efficient to use an iterator directly rather than first iterating through ` Map`-keys to create a temporary `Array` that we finally iterate through at the call-site.

Note that the `getKeys` method is old code, and originally the `Dict` class stored its data in a regular `Object`, hence why the old code was written that way.
2026-03-04 16:07:49 +01:00
Jonas Jenwald
40bd73551c
Merge pull request #20793 from Snuffleupagus/more-getRawEntries
Use the `Dict.prototype.getRawEntries` method more
2026-03-04 16:05:57 +01:00
calixteman
ce5f34ba13
Merge pull request #20780 from wooorm/wooorm/dismiss-popups
Add support for dismissing comment popups with click outside
2026-03-04 15:24:29 +01:00
calixteman
72f98d4e00
Merge pull request #20788 from calixteman/organize_context_menu
Add the pages organization actions in the Firefox context menu (bug 2018138)
2026-03-04 15:20:00 +01:00
Jonas Jenwald
50d66d7d34 Use the Dict.prototype.getRawEntries method more
This changes a number of loops currently using `Dict.prototype.{getKeys, getRaw}`, since it should be a tiny bit more efficient to use an iterator directly rather than first iterating through `Map`-keys to create a temporary `Array` that we finally iterate through at the call-site.

Note that the `getKeys` method is much older than `getRawEntries`, and originally the `Dict` class stored its data in a regular `Object`, hence why the old code was written that way.
2026-03-04 12:46:25 +01:00
Nicolò Ribaudo
2f2d5c9e27
Add script to check license headers 2026-03-04 10:40:39 +01:00
Calixte Denizet
d90530b86c
Add the pages organization actions in the Firefox context menu (bug 2018138) 2026-03-04 09:02:39 +01:00
Calixte Denizet
a474e81b8a
Add a way to extract some pages from a pdf (bug 2019682)
The user has to select some pages and then click on the "Save As" menu item in the Manage menu.
If they modify the structure of the pdf (deleted, moved, copied pages), they have to use the usual
save button.
2026-03-03 21:39:13 +01:00
Titus Wormer
8b4f9048cf
Add support for dismissing comment popups with click outside
This solves [bug 1989406](https://bugzilla.mozilla.org/show_bug.cgi?id=1989406).
(“The user should be able to dismiss the in-content message displayed by clicking somewhere else in the PDF”)
There’s a good gif there that shows the problematic behavior.

In the thread, there are also mentions of 2 similar but slightly separate problems:

* clicking on another highlight should also dismiss
* the mention that hitting the escape key does not dismiss

I found the last point, the escape key, to work already (first test case here).
But this PR solves the main bug (second test case) and the adjacent one
(third test case).
It works by using the existing `unselectAll` handling.
2026-03-03 11:14:22 +01:00
jizou
0e1b5cd7bb Fix missing Chinese font name variants (SimFang and XiaoBiaoSong) in GBK encoding detection 2026-03-03 17:04:59 +08:00
Tim van der Meij
f32b9d2677
Merge pull request #20738 from Snuffleupagus/function-shorten
Slightly shorten some code in the `src/core/function.js` file
2026-03-01 20:06:29 +01:00
Jonas Jenwald
86573cc995
Merge pull request #20757 from Snuffleupagus/getPdfFilenameFromUrl-fix-decode-regex
Fix the broken regular expression in the `decode` helper in the `getPdfFilenameFromUrl` function (issue 20664)
2026-02-27 23:14:18 +01:00
calixteman
9c3a752388
Merge branch 'master' into scientific 2026-02-27 18:39:44 +01:00
Jonas Jenwald
e3a7c0779d Fix the broken regular expression in the decode helper in the getPdfFilenameFromUrl function (issue 20664)
This will ignore filenames that become effectively empty, i.e. ones that are only ".pdf" and nothing more.

*Please note:* While this passes all existing unit-tests, I don't know if this is necessarily the "correct" solution here.
2026-02-27 15:19:43 +01:00
Jeff Muizelaar
8fa6ef36e4 Remove scientific notation parsing.
This behaviour comes from the initial pdf.js commit but is wrong and
doesn't match other PDF readers like muPDF or pdfium.

From PDF Spec 7.3.3:

A PDF writer shall not use the PostScript language syntax for numbers with non-decimal radices (such
as 16#FFFE) or in exponential format (such as 6.02E23).
2026-02-26 20:22:34 -05:00