1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 00:28:06 +02:00
Commit graph

6571 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
Calixte Denizet
9bd00859d3 Fix the telemetry for the new alt-text flow 2024-08-15 11:29:00 +01: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
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
Calixte Denizet
00305184b5 [Editor] Add the telemetry for the new alt text (bug 1912500) 2024-08-10 18:29:03 +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
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
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
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
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
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
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
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
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
Calixte Denizet
4b7f9a8d87 Empty fields are 0 when using AFSimple_Calculate
It fixes #18536 and #18532.
2024-08-02 21:51:27 +02:00
Calixte Denizet
d2c519e57a Guess alt text even when showing the dialog is disabled 2024-08-02 17:40:10 +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
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
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
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
Jonas Jenwald
c4cd405a8f Ignore non-dictionary nodes when parsing StructTree data (issue 18503) 2024-07-28 12:08:44 +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
Calixte Denizet
c3065629ca [Editor] Correctly save a non-ascii alt text 2024-07-24 19:13:45 +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
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
Calixte Denizet
71bae38afb Fallback on DeviceGray when a colorspace cannot be parsed 2024-07-21 17:56:31 +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
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
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
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