20984 Commits

Author SHA1 Message Date
Calixte Denizet
09f0af5b83 Update qcms build
It's a follow-up of https://github.com/mozilla/pdf.js.qcms/pull/1.
2025-05-13 16:44:18 +02:00
Jonas Jenwald
5e3d26601e
Merge pull request #19922 from nicolo-ribaudo/vite-ignore-minified
Preserve webpack/vite ignore comments when minifying
2025-05-13 14:54:17 +02:00
Nicolò Ribaudo
ff432c39f9
Preserve webpack/vite ignore comments when minifying
They were removed in the minified build, but the code that made the comments necessary was still there (just minified). This commit updates the Terser config to preserve them.

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

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

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

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

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

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

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

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

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

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

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

[2] Unfortunately just skipping `stringToPDFString` in this case would cause other issues, such as the named destination becoming "unusable" in the viewer; see e.g. issues 14847 and 14864.
2025-04-30 20:51:10 +02:00
Jonas Jenwald
254431df1e Avoid extra lookup/parsing when all destinations are already available
Whenever we cannot find a destination we'll fallback to checking all destinations, to account for e.g. out-of-order NameTrees, and in those cases any subsequent destination-lookups can be made a tiny bit more efficient by immediately checking the already cached destinations.
2025-04-30 15:26:00 +02:00
calixteman
b8de9a372f
Merge pull request #19856 from calixteman/bug1936605
Don't update the visible canvas at 60 fps (bug 1936605)
2025-04-29 22:31:02 +02:00
Jonas Jenwald
0922aa9e9d
Merge pull request #19880 from Snuffleupagus/numberToString-assert-number
Assert that `numberToString` is called with a number (issue 19877)
2025-04-29 20:35:32 +02:00
calixteman
262a1f9895
Merge pull request #19881 from calixteman/bug1963407
Fix the bbox when saving a rotated text field (bug 1963407)
2025-04-29 20:33:53 +02:00
Jonas Jenwald
f5faf86180 Assert that numberToString is called with a number (issue 19877)
*NOTE:* Given that this is an *internal* function, used only in the worker-thread, it's not clear to me that this is an entirely "necessary" change.
2025-04-29 20:31:24 +02:00
Calixte Denizet
7a251b206e Fix the bbox when saving a rotated text field (bug 1963407) 2025-04-29 18:49:07 +02:00
Calixte Denizet
ecc56a61e6 Don't update the visible canvas at 60 fps (bug 1936605)
Instead, we update the visible canvas every 500ms.
With large canvas, updating at 60fps lead to a lot gfx transactions and it can take a lot of time.
For example, with wuppertal_2012.pdf on Windows, displaying it at 150% takes around 14 min !!! without
this patch when it takes only around 14 sec with. Even at 30% it helps to improve the performance
by around 20%.
2025-04-29 18:35:21 +02:00
Jonas Jenwald
c1a398d932
Merge pull request #19876 from Snuffleupagus/Node-polyfill-navigator
Add a basic `navigator` polyfill for older Node.js versions
2025-04-29 10:04:19 +02:00
calixteman
2e10ff6dd4
Merge pull request #19855 from 1Jesper1/hotfix/useractivation-response
Add useractivation check for response function
2025-04-28 13:14:51 +02:00