1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 09:08:07 +02:00
Commit graph

19681 commits

Author SHA1 Message Date
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 e037c5711d.
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