Commit Graph

3445 Commits

Author SHA1 Message Date
Jonas Jenwald
99522c3201 Also test the latest Node.js version in GitHub Actions
Hopefully this will allow us to catch bugs in new Node.js versions earlier, rather than having to wait for bug reports.

Given that `CompressionStream` is (currently) only potentially used when saving a *modified* PDF document, which is unlikely to be a common use-case in Node.js environments, let's just disable the affected unit-test for now.
2023-11-02 16:58:03 +01:00
Jonas Jenwald
155a302e74 Use even more optional chaining in the code-base 2023-11-02 16:47:33 +01:00
Calixte Denizet
085aa4207d Render rich text with only one text element 2023-11-02 15:35:52 +01:00
Calixte Denizet
77475ac610 [Editor] Don't steal the keyboard events when editing mode is enabled 2023-10-30 10:03:44 +01:00
calixteman
1ab0f8a0ec
Merge pull request #17205 from calixteman/issue17200
Fix the intermittent failures with PageOpen/PageClose test
2023-10-29 23:23:09 +01:00
Calixte Denizet
66b1a1f34b Fix the intermittent failures with PageOpen/PageClose test 2023-10-29 20:11:51 +01:00
Jonas Jenwald
3f0b3b15de
Merge pull request #17196 from Snuffleupagus/annotationLayer-css-nesting
Use CSS nesting in the annotationLayer
2023-10-27 19:50:10 +02:00
Jonas Jenwald
b779e418a5 Use CSS nesting in the annotationLayer 2023-10-27 18:46:47 +02:00
Jonas Jenwald
525be9afea Use CSS nesting in the textLayer 2023-10-27 17:38:01 +02:00
Calixte Denizet
d72fd9ce4f Fix intermittents failure on mac 2023-10-27 16:10:06 +02:00
Calixte Denizet
517a262fb1 Fix keyboard shortcuts on mac and for some tests make sure that all
the page is displayed in using page-fit in order to make all tested
elements visible.
2023-10-27 16:09:35 +02:00
Calixte Denizet
133ed96f8f Don't take into account the INVISIBLE flag for well-known annotations 2023-10-25 10:16:14 +02:00
Jonas Jenwald
f098121644
Merge pull request #17161 from Snuffleupagus/NullL10n-test
Add a unit-test to ensure that `NullL10n` won't diverge from the `L10n`-class
2023-10-24 20:28:34 +02:00
Jonas Jenwald
e2af77fd6c Add a unit-test to ensure that NullL10n won't diverge from the L10n-class
To prevent the *standalone* viewer-components from breaking, we need to ensure that the `NullL10n`-interface won't accidentally diverge from the actual `L10n`-implementations.
2023-10-24 13:13:14 +02:00
Calixte Denizet
2f3797db34 [Annotation] Use the field V entry when there is no Parent one for a radio button (bug 1860602) 2023-10-23 22:11:30 +02:00
Jonas Jenwald
17af706070 [api-minor] Use "data-l10n-id"/"data-l10n-args", rather than manually updating DOM-elements, to trigger translation (PR 17146 follow-up)
This patch changes almost all viewer-components[1] to use "data-l10n-id"/"data-l10n-args" for localization, which means that in many cases we no longer need to pass around the `L10n`-instance any more.

One part of the code-base where the `L10n`-instance is still being used "directly" is the AnnotationEditors, however while it might be possible to convert (most of) that code as well that's not attempted in this patch.

---
[1] The one exception is the `PDFDocumentProperties` dialog, since the way it's currently implemented makes that less straightforward to fix without a lot of code changes.
2023-10-22 14:17:47 +02:00
Jonas Jenwald
f07675a6a8 [api-minor] Re-factor NullL10n and remove the hard-coded l10n strings (PR 17115 follow-up)
*Please note:* These changes only affect the GENERIC build, since `NullL10n` is only a stub elsewhere (see PR 17135).

After the changes in PR 17115, which modernized and improved l10n-handling, the `NullL10n`-implementation is no longer a good fallback for the "proper" `L10n`-classes.
To improve this situation, especially for the *standalone* viewer-components, this patch makes the following changes:
 - Let the `NullL10n`-implementation extend an actual `L10n`-class, which is constant and lazily initialized, to ensure that it works *exactly* like the "proper" ones.

 - Automatically bundle the "en-US" l10n-strings in the build, via the pre-processor, such that we don't need to remember to manually update them.

 - Ensure that the *standalone* viewer-components register their DOM-elements for translation, similar to the default viewer, since this will allow future code improvements by using "data-l10n-id"/"data-l10n-args" in most (if not all) parts of the viewer.

 - Remove the `NullL10n` from the `AnnotationLayer`, to avoid affecting bundle size too much.
   For third-party users that access the `AnnotationLayer`, as exposed in the main PDF.js library, they'll now need to *manually* register it for translation. (However, the *standalone* viewer-components still works given the point above.)
2023-10-20 21:49:33 +02:00
Jonas Jenwald
a4cd2ef1db
Merge pull request #17148 from JT-External/support-rotated-imagemask
Fix size of maskCanvas to draw image masks correctly
2023-10-20 17:25:55 +02:00
JT-External
0eacd5c107 Fix size of maskCanvas to draw image masks correctly
Use existing helper to calculate the Box

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Ensure that there are non-zero

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Add a reference test for #17147
2023-10-20 23:46:24 +09:00
Jonas Jenwald
69ad0d9861 Only bundle NullL10n in GENERIC builds (bug 1859818) 2023-10-19 13:51:00 +02:00
calixteman
5d8be99782
Merge pull request #17115 from calixteman/mv_to_fluent
[api-minor] Move to Fluent for the localization (bug 1858715)
2023-10-19 13:40:50 +02:00
Calixte Denizet
66982a2a11 [api-minor] Move to Fluent for the localization (bug 1858715)
- For the generic viewer we use @fluent/dom and @fluent/bundle
- For the builtin pdf viewer in Firefox, we set a localization url
  and then we rely on document.l10n which is a DOMLocalization object.
2023-10-19 11:20:41 +02:00
Jonas Jenwald
674052d3fc Re-factor the blob-URL caching in DownloadManager.openOrDownloadData
Cache blob-URLs on the actual data, rather than DOM elements, to reduce potential duplicates (note the updated unit-test).
2023-10-17 10:18:34 +02:00
Tim van der Meij
2bae8af96a
Fix intermittent problems on Windows in the XFA search integration test
The current test fails intermittently only on Windows for unknown
reasons: the code is correct and on Linux it always passes. However, we
have already spent quite a lot of time on this test, so rather than
spending even more time on it I figured we should look at what behavior
the test is trying to check and find an alternative way to do it that
can't trigger this intermittent issue anymore.

This commit changes the test to use a term that only exists once in the
entire document so we cannot accidentally highlight another match
anymore. This doesn't change anything about the behavior that this test
aims to check: we still test searching in the XFA layer, we still test
that the original term is matched case-insensitively and we still test
that that match is actually highlighted. Note that the only objective of
the test is confirming that the search functionality covers the XFA
layer, so the exact phrase/match is not the interesting bit.
2023-10-15 15:02:41 +02:00
Tim van der Meij
a9a1195582
Merge pull request #17123 from Snuffleupagus/eslint-globals
Update the ESLint `globals` list (PR 17055 follow-up)
2023-10-15 12:06:54 +02:00
Jonas Jenwald
d5acbbccd3 Update the ESLint globals list (PR 17055 follow-up)
Given that we only use standard `import`/`export` statements now, after recent PRs, the "exports" global is unused.
Instead we add "__non_webpack_import__" to the `globals` to avoid having to sprinkle disable statements throughout the code.

Finally, the way that `globals` are defined has changed in ESLint and we should thus explicitly specify them as "readonly"; please find additional details at https://eslint.org/docs/latest/use/configure/language-options#specifying-globals
2023-10-15 11:38:10 +02:00
Tim van der Meij
0c763d6c5a
Tweak the protocol timeout configuration for Puppeteer
The previous change that set the timeout had effect because we have seen
quite a few protocol timeouts now correctly being raised in the context
of the active test, however we have also still seen a handful of cases
where this wasn't the case and the one second difference turned out to
be too low (likely because the operation was started slightly after one
second into the test run). We therefore tweak the value to be 75% of the
Jasmine timeout. This should be enough to catch operations that happen
later on in the test run, and if a single operation takes that long any
hope for success is already gone anyway.
2023-10-14 18:20:22 +02:00
Tim van der Meij
48e41617f5
Remove Escape key press from the autoprint integration test
It's not necessary because we have configured silent printing for
Firefox and Chrome in the browser arguments we pass in `test.mjs`. This
means that the print dialog is not even shown at all or disappears
automatically once printing is done, so the Escape key press serves no
purpose. Since it has been shown to time out, likely because the page
loses focus during printing, and because the page itself doesn't know
when the printing dialog is shown and we therefore can't possibly do the
key press at the right time anyway, this commit gets rid of it to
stabilize the test.
2023-10-14 18:17:29 +02:00
Jonas Jenwald
d53093045a Enable the import/no-commonjs ESLint plugin rule
Given the amount of work put into removing `require`-calls from the code-base, let's ensure that new ones aren't accidentally added in the future.

Note that we still have a couple of files where `require` is being used, in particular:
 - The Node.js examples, however those will be updated to use `import` in PR 17081.
 - The Webpack examples, and related support files, however I unfortunately don't know enough about Webpack to be able to update those. (Hopefully users of that code will help out here, once version `4` is released.)
 - The `statcmp`-tool, since *some* of those `require`-calls cannot be converted to `import` without other code changes (and that file is only used during benchmarking).

Please find additional details at https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-commonjs.md
2023-10-14 12:49:17 +02:00
Jonas Jenwald
5e986cb514 Use native import maps in development mode
This patch seem to work fine locally now, and `mozregression` points to it being fixed in bug https://bugzilla.mozilla.org/show_bug.cgi?id=1803984 which landed in Firefox 116.

By using the native `import maps` functionality, we can remove a development dependency. Please find the specification at https://wicg.github.io/import-maps/
2023-10-13 20:35:34 +02:00
Jonas Jenwald
38245500fd Output JavaScript modules for the LIB build-target (PR 17055 follow-up)
This *finally* allows us to mark the entire PDF.js library as a "module", which should thus conclude the (multi-year) effort to re-factor and improve how we import files/resources in the code-base.

This also means that the `gulp ci-test` target, which is what's run in GitHub Actions, now uses JavaScript modules since that's supported in modern Node.js versions.
2023-10-13 18:54:33 +02:00
Jonas Jenwald
9878d058fe Convert the integration test-files to JavaScript modules 2023-10-12 13:18:20 +02:00
Jonas Jenwald
33456d3704 Rename the integration test-files, in preparation for converting them to modules
This is done separately to ensure that Git is able to track the history correctly.
2023-10-12 13:17:56 +02:00
Tim van der Meij
ede65e11c6
Fix the protocol timeout configuration for Puppeteer
The default protocol timeout is 180 seconds according to the
documentation at https://pptr.dev/api/puppeteer.browserconnectoptions,
but the Jasmine timeout we configure in the individual boot files is 30
seconds. The consequence of this is that if a protocol (CDP) error
occurs after 30 seconds Jasmine will fail the test, but the actual
protocol error from Puppeteer is raised much later in the context of
another test, which causes unrelated failures or tracebacks.

This commit fixes the problem by configuring Puppeteer to always use a
lower protocol timeout than the Jasmine timeout so that protocol errors
are always raised in the context of the test that actually triggered it.
2023-10-08 18:22:02 +02:00
Tim van der Meij
2c1d95b153
Activate the selector check for the autoprint integration test as soon as possible
The Windows bot is usually slower than the Linux bot, and therefore
text layer rendering is as well. However, the `autoprint` test awaited
text layer rendering to complete before activating the selector check,
which makes it timing-sensitive and causes it to never resolve because
the page is already printed (and the printed page div removed) by then.

This commit should fix the issue by activating the selector check as
soon as possible, namely as soon as the viewer appears, which should
ensure we're always registering the selector check in time because we're
doing it even before rendering is starting.
2023-10-07 19:27:34 +02:00
Tim van der Meij
bab4c7f617
Merge pull request #17055 from Snuffleupagus/output-modules
[api-major] Output JavaScript modules in the builds (issue 10317)
2023-10-07 15:02:59 +02:00
Tim van der Meij
89d8c639fa
Merge pull request #17077 from Snuffleupagus/css-rm-unneeded-alpha
Remove unnecessary alpha-value from CSS `rgb` colors
2023-10-07 12:33:48 +02:00
Jonas Jenwald
927e50f5d4 [api-major] Output JavaScript modules in the builds (issue 10317)
At this point in time all browsers, and also Node.js, support standard `import`/`export` statements and we can now finally consider outputting modern JavaScript modules in the builds.[1]

In order for this to work we can *only* use proper `import`/`export` statements throughout the main code-base, and (as expected) our Node.js support made this much more complicated since both the official builds and the GitHub Actions-based tests must keep working.[2]
One remaining issue is that the `pdf.scripting.js` file cannot be built as a JavaScript module, since doing so breaks PDF scripting.

Note that my initial goal was to try and split these changes into a couple of commits, however that unfortunately didn't really work since it turned out to be difficult for smaller patches to work correctly and pass (all) tests that way.[3]
This is a classic case of every change requiring a couple of other changes, with each of those changes requiring further changes in turn and the size/scope quickly increasing as a result.

One possible "issue" with these changes is that we'll now only output JavaScript modules in the builds, which could perhaps be a problem with older tools. However it unfortunately seems far too complicated/time-consuming for us to attempt to support both the old and modern module formats, hence the alternative would be to do "nothing" here and just keep our "old" builds.[4]

---
[1] The final blocker was module support in workers in Firefox, which was implemented in Firefox 114; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility

[2] It's probably possible to further improve/simplify especially the Node.js-specific code, but it does appear to work as-is.

[3] Having partially "broken" patches, that fail tests, as part of the commit history is *really not* a good idea in general.

[4] Outputting JavaScript modules was first requested almost five years ago, see issue 10317, and nowadays there *should* be much better support for JavaScript modules in various tools.
2023-10-07 09:31:08 +02:00
calixteman
905ad1fe68
Merge pull request #16761 from calixteman/editor_add_new_with_keyboard
[Editor] Add the possibility to create a new editor in using the keyboard (bug 1853424)
2023-10-06 11:44:07 +02:00
Jonas Jenwald
4ebddcb092 Remove unnecessary alpha-value from CSS rgb colors
Setting the alpha-value explicitly to `1` in `rgb` colors is unnecessary, since that's the default value, and this way we ever so slightly reduce the size of our CSS files.
Unfortunately I've not found a Stylelint rule to enforce this automatically, and the patch was generated using search and replace.
2023-10-06 09:50:03 +02:00
Calixte Denizet
ea5eafa265 [Editor] Add the possibility to create a new editor in using the keyboard (bug 1853424)
When an editing button is disabled, focused and the user press Enter (or space), an
editor is automatically added at the center of the current page.
Next creations can be done in using the same keys within the focused page.
2023-10-05 22:49:15 +02:00
Jonas Jenwald
4277205d78 Enable some Stylelint color-related rules to slightly reduce file sizes
- Use a consistent format for all alpha-values (this rule didn't require any code changes); see https://stylelint.io/user-guide/rules/alpha-value-notation
 - Use modern and slightly shorter color notation, since [according to MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb#browser_compatibility) that should be supported "everywhere" nowadays; see https://stylelint.io/user-guide/rules/color-function-notation/
 - Use "short" hexadecimal colors whenever possible; see https://stylelint.io/user-guide/rules/color-hex-length/
 - Help avoid adding broken hexadecimal colors (this rule didn't require any code changes); see https://stylelint.io/user-guide/rules/color-no-invalid-hex/
2023-10-05 17:51:21 +02:00
Calixte Denizet
40b1d92044 Update the noHTML flag to take into account the hasOwnCanvas one (fixes #17069)
When an element has the hasOwnCanvas flag we must have an HTML container to attach
the canvas where the element will be rendered.
So the noHTML flag must take this information into account:
 - in some cases the noHTML flag is resetted depending on the hasOwnCanvas value;
 - in some others, the hasOwnCanvas flag is set depending on the value of noHTML.
2023-10-04 18:06:21 +02:00
calixteman
40d6b0e1bf
Merge pull request #17062 from calixteman/resize_keyboard
[Editor] Support resizing editors with the keyboard (bug 1854340)
2023-10-04 13:55:04 +02:00
Calixte Denizet
05ca3fd99b [Editor] Support resizing editors with the keyboard (bug 1854340) 2023-10-04 12:57:37 +02:00
Jonas Jenwald
bf9c33e60f Add support for "GoToE" actions with destinations (issue 17056)
This shouldn't be very common in practice, since "GoToE" actions themselves seem quite uncommon; see PR 15537.
2023-10-04 11:14:23 +02:00
Calixte Denizet
1be9bbd2e1 Compute correctly the bounding box of a transformed rectangle (fixes #17065) 2023-10-03 23:50:59 +02:00
Jonas Jenwald
f113320bd5 Ensure that readonly TextWidget-annotations are rendered when forms are disabled (issue 17064)
To reduced the risk of regressing something else, given that the issue only applies to a (for the default viewer) non-default configuration, this patch is purposely limited to only TextWidget-annotations in the display layer.
2023-10-03 21:26:08 +02:00
Jonas Jenwald
426209c6e6
Merge pull request #16699 from Snuffleupagus/rm-svg
[api-major] Remove the SVG back-end (PR 15173 follow-up)
2023-10-03 15:13:14 +02:00
calixteman
0cc8c6671c
Merge pull request #17059 from calixteman/fix_copy_paste_integration_test
Remove timeouts from the copy_paste integration test
2023-10-03 13:27:13 +02:00
Calixte Denizet
bb59f445a9 Remove timeouts from the copy_paste integration test 2023-10-03 11:55:18 +02:00
Calixte Denizet
e3fbe2908a [Editor] Use the alt text to descibe the canvas used to display the image 2023-10-02 23:28:11 +02:00
Calixte Denizet
eebd251552 [Editor] Don't show the alt-text button when the alt-text dialog is visible
This way, the button doens't cover the image.
2023-10-02 20:34:30 +02:00
calixteman
f5367f01ca
Merge pull request #17051 from calixteman/test_stamp_svg
Fix new intermittent failures with ink and stamp tests
2023-10-02 18:10:00 +02:00
Calixte Denizet
077d239b96 Fix new intermittent failures with ink and stamp tests
It happens only on windows with chrome.
For any reason, click event isn't correctly triggered and it seems work correctly
with pointerup.
And it seems that when drawing a svg on an OffscreenCanvas we need to wait
a little in order to be able to transfer it: it's why this patch adds
a check on the canvas content.
2023-10-02 15:04:44 +02:00
Jonas Jenwald
3ced0dec1b [api-major] Remove the SVG back-end (PR 15173 follow-up)
This has been deprecated since version `2.15.349`, which is a year ago.
Removing this will also simplify some upcoming changes, specifically outputting of JavaScript modules in the builds.
2023-10-01 23:14:29 +02:00
Jonas Jenwald
9624505f0f Use a standard export statement in the web/pdfjs.js file
This removes the only remaining old and non-standard handling of exports in the `web/`-folder, since some initial attempts at outputting JavaScript modules in the builds have identified this file as a potential problem.
While this uses a hard-coded list, for overall simplicity, I don't believe that that's a big problem since:
 - Generating this file automatically would require a bunch more parsing *every single time* that the library is built.
 - The official API-surface doesn't change often enough for this to really impede development in any significant way.
 - The added unit-test helps ensure that this list cannot accidentally become outdated.
2023-09-30 12:10:02 +02:00
calixteman
3ca63c68ea
Merge pull request #17050 from calixteman/editor_delete_invisible
[Editor] Make a deleted (when it was invisible) editor undoable
2023-09-29 18:06:55 +02:00
calixteman
7d7a7a46a0
Merge pull request #17049 from calixteman/fix_stamp_tests
Remove the timeouts from the stampEditor integration tests
2023-09-29 17:02:10 +02:00
Calixte Denizet
b65b079ceb [Editor] Make a deleted (when it was invisible) editor undoable
When the editor is invisible (because on a non-rendered page) its parent is null.
But when we undo its deletion, we need to have a parent to attach it.
2023-09-29 16:19:11 +02:00
Calixte Denizet
b8c118db22 Remove the timeouts from the stampEditor integration tests 2023-09-29 15:57:16 +02:00
Calixte Denizet
627249f889 Remove the timeouts from the inkEditor integration tests 2023-09-29 15:01:52 +02:00
Calixte Denizet
55e5af2d01 [Editor] Remove almost all the waitForTimeout from the freetext integration tests 2023-09-29 11:14:21 +02:00
Calixte Denizet
f2196f7803 StructParents entry isn't required on pages with no tagged contents (bug 1855641) 2023-09-28 14:23:10 +02:00
Calixte Denizet
3ee5268a23 [Editor] Don't try to add data to the struct tree when there is no accessibilityData (bug 1855157) 2023-09-26 11:02:14 +02:00
Tim van der Meij
ce87167432
Merge pull request #17022 from timvandermeij/fix-intermittent-us
Fix integration test "Interaction in issue14307.pdf (1) must check input for US zip format"
2023-09-24 18:47:18 +02:00
Tim van der Meij
6e584adfc5
Use realistic typing delays for the scripting integration tests
In the scripting integration tests we use a few different typing
delays, mostly 100 or 200 milliseconds. According to for example
https://www.typingpal.com/en/documentation/school-edition/pedagogical-resources/typing-speed,
a fast typing speed is around 300 characters per minute, which is 5
characters per second and therefore a delay of 200 milliseconds between
each keystroke. Note that this is already above average, so in practice
the delay will be even larger. Therefore the 100 milliseconds variant
is unrealistically fast and therefore not suitable for the integration
tests which aim to simulate the average user behavior.

On top of that, the quick typing speeds are problematic for the tests
that involve validation alert dialogs appearing during typing. In those
tests a handler is registered to close the dialog once it pops up, but
it takes time for Puppeteer to notice the dialog, trigger the handler
and close it. If the typing delay, which is the delay between the key
down and key up events according to the Puppeteer source code at
https://github.com/puppeteer/puppeteer/blob/master/packages/puppeteer-core/src/cdp/Input.ts#L209-L215,
is too short, the key up event will be fired before the dialog is
closed. In that time the text box we're typing in is not focused, so
when the dialog is closed the `page.type()` call on the text box will
never resolve because the key up event never reached the text box.

This commit aims to fix the issues by converting all 100 millisecond
delays to 200 milliseconds. For instance the "must check input for US
zip format" failed pretty consistently locally before and hasn't failed
anymore with a 200 millisecond delay.
2023-09-24 15:47:21 +02:00
calixteman
48d75599d3
Merge pull request #17018 from calixteman/alt_text_test
[Editor] Add an integration test for the new alt-text flow
2023-09-24 14:34:58 +02:00
Calixte Denizet
de553456ce [Editor] Add an integration test for the new alt-text flow 2023-09-24 13:39:18 +02:00
Tim van der Meij
9b464047bc
Merge pull request #17021 from timvandermeij/fix-intermittent-autoprint
Fix integration test "Interaction in autoprint.pdf must check if printing is triggered when the document is open"
2023-09-24 13:37:18 +02:00
Tim van der Meij
b41bca7da9
Don't wait for scripting to be ready in the autoprint integration test
This integration test fails often because we wait for scripting to be
ready before we check the printed page, but most of the time the PDF
is already done printing before scripting is reported to be ready.

This happens because the print trigger is on the `Open` event, which is
one of the first events to be dispatched and, most notably, before
scripting is marked as ready; please see
https://github.com/mozilla/pdf.js/blob/master/web/pdf_scripting_manager.js#L176-L191.
Given that the PDF document is only one page, printing it is usually
finished between triggering the `Open` event and scripting reported
to be ready. If this happens the printed page is already destroyed
before we get to our actual test, which will then timeout because it
will never find the printed page in the DOM.

This commit fixes the problem by not awaiting scripting to be ready
because the fact that the printed page appears is already enough to know
that autoprint was triggered (after all, there is no other user
interaction involved here). While we're here we also switch to the
shorter `page.waitForSelector` function.
2023-09-24 12:48:58 +02:00
Calixte Denizet
57caa4601c [Editor] The ::before containter containing the border of a selected editor mustn't catch mouse events (bug 1854818) 2023-09-23 23:53:19 +02:00
Jonas Jenwald
1df31c0284 Use one noContextMenu function in both the src/- and web/-folders
Currently we duplicate this event handler function in multiple places, which seems unnecessary.
2023-09-23 15:37:13 +02:00
Tim van der Meij
a09b7228fb
Merge pull request #16970 from timvandermeij/fix-intermittent-border
Fix integration test "Interaction in issue15053.pdf must check that a button and text field with a border are hidden"
2023-09-23 14:35:07 +02:00
Tim van der Meij
f9eda5b30e
Merge pull request #16967 from timvandermeij/fix-intermittent-freetext
Fix integration test "FreeText Editor FreeText (edit existing in double clicking on it) must move an annotation"
2023-09-23 14:34:43 +02:00
Calixte Denizet
6545551e76 [Editor] Avoid to darken the current editor when opening the alt-text dialog 2023-09-21 20:44:53 +02:00
Jonas Jenwald
e2b7896826 [GeckoView] Avoid bundling the AltTextManager class, since it's unused 2023-09-21 12:51:34 +02:00
Jonas Jenwald
0ac8f33e13 Ignore optional content with missing /Type-entries
In the rare situation that an optional content dictionary lacks a /Type-entry we currently throw, which may prevent e.g. Form XObjects from rendering completely.

Fixes https://bugs.ghostscript.com/show_bug.cgi?id=707147
2023-09-19 14:11:03 +02:00
calixteman
3afb717eed
Merge pull request #16938 from calixteman/update_struct_tree
[Editor] Add the ability to create/update the structure tree when saving a pdf containing newly added annotations (bug 1845087)
2023-09-18 13:04:52 +02:00
Tim van der Meij
01428f1e23
Wait for visibility change in the issue15053 integration test
Especially on slower bots there is some time between clicking the
element and the actual visibility change, but we didn't await this and
checked the visibility state immediately after clicking. This can be
reproduced 100% of the time by introducing a delay in the `display` and
`hidden` handlers of the `_commonActions` shadow call.

This commit fixes the problem by waiting until the first visibility
change actually happened before continuing with the assertions.
2023-09-17 19:48:14 +02:00
Tim van der Meij
1b3ccf1321
Wait for selector instead of timeout in the freetext double click move integration test
This integration test currently fails intermittently on the bots because
of the fixed timeout in the test, which is sometimes too low on slower
systems. The issue can be reproduced 100% of the time by introducing a
delay just before dispatching the `switchannotationeditormode` event.

Puppeteer also discourages this and instead recommends waiting for a
selector instead, which we now do here. This ensures that the test only
continues if the element under test is available and therefore prevents
any timing problems.
2023-09-17 18:49:11 +02:00
Tim van der Meij
306cca930f
Fix off-by-one errors in the "FreeText must move several annotations" integration test
The x/y-coordinates are floats instead of integers like one might
expect. The current approach rounds both the old and the new
coordinates in order to do integer comparison. However, rounding each
coordinate individually causes too much loss of precision because,
depending on the decimal value, they are either rounded up or down
which causes intermittent off-by-one errors.

This commit fixes the problem by comparing coordinate differences
instead of the coordinates themselves. The precision loss is avoided
by subtracting the old from the new coordinate as-is and only rounding
the final result.
2023-09-17 15:56:51 +02:00
Tim van der Meij
0d3fbc1818
Wait for selector instead of timeout in the bug1844576 integration test
This integration test currently fails intermittently on the bots because
of the fixed timeout in the test, which is sometimes too low on slower
systems. The issue can be reproduced 100% of the time by introducing a
delay in the `WidgetAnnotationElement.showElementAndHideCanvas` method.

Puppeteer also discourages this and instead recommends waiting for a
selector instead, which we now do here. This ensures that the test only
continues if the element under test is available and therefore prevents
any timing problems.
2023-09-17 13:15:53 +02:00
Tim van der Meij
dd46110f6b
Use the page.$eval method in the bug1844576 integration test
We already use `page.$eval` in most other integration tests and it's
simpler because it already takes the selector as argument, so we don't
have to do a separate `querySelector` call ourselves.
2023-09-17 13:09:39 +02:00
Calixte Denizet
a8573d4e1b [Editor] Add the ability to create/update the structure tree when saving a pdf containing newly added annotations (bug 1845087)
When there is no tree, the tags for the new annotions are just put under the root element.
When there is a tree, we insert the new tags at the right place in using the value
of structTreeParentId (added in PR #16916).
2023-09-16 18:34:58 +02:00
Tim van der Meij
66507ccae8
Enable unit test "creates pdf doc from non-existent URL"
The unit test is re-enabled because it no longer seems to fail after 10
runs on Linux where this used to fail often. Code inspection also shows
that the code is correct and should raise the previous exception
(anymore). Finally, a lot has changed since this test was disabled such
as new Jasmine versions, new Linux bot OS version and new browser
versions.
2023-09-10 15:47:04 +02:00
Jonas Jenwald
18a661b6a0
Merge pull request #16920 from Snuffleupagus/annotationGlobals
Slightly reduce asynchronicity when parsing Annotations
2023-09-09 09:55:49 +02:00
Jonas Jenwald
df9cce39c0 Slightly reduce asynchronicity when parsing Annotations
Over time the amount of "document level" data potentially needed during parsing of Annotations have increased a fair bit, which means that we currently need to ensure that a bunch of data is available for each individual Annotation.
Given that this data is "constant" for a PDF document we can instead create (and cache) it lazily, only when needed, *before* starting to parse the Annotations on a page. This way the parsing of individual Annotations should become slightly less asynchronous, which really cannot hurt.

An additional benefit of these changes is that we can reduce the number of parameters that need to be explicitly passed around in the annotation-code, which helps overall readability in my opinion.

One potential drawback of these changes is that the `AnnotationFactory.create` method no longer handles "everything" on its own, however given how few call-sites there are I don't think that's too much of a problem.
2023-09-08 13:27:27 +02:00
Calixte Denizet
c6f7e722c9 [Editor] Add the parent tag id (if any) to the serialized editors (bug 1845087)
The tag id will be useful in order to update the StructTree when saving
the pdf.
2023-09-07 18:22:33 +02:00
calixteman
3e32d87be7
Merge pull request #16915 from calixteman/issue16914
Construct the correct field name and strip out classes when searching
2023-09-07 16:46:33 +02:00
Calixte Denizet
a8a50c567a Construct the correct field name and strip out classes when searching
The classes were stripped out during when creating the field name but
it led to a wrong name.
Since class components in a path are irrelevant, they're just ignored
when searching for a node in the datasets.
2023-09-07 15:56:47 +02:00
Calixte Denizet
8ab4e2e6e7 [Editor] Avoid to use parent of editors in destroyed pages 2023-09-07 12:30:29 +02:00
Calixte Denizet
d03494eeff Only call the focus/blur callbacks when it's necessary (bug 1851517)
Focus callback must be called only when the element has been blurred.
For example, blur callback (which implies some potential validation) is not called
because the newly focused element is an other tab, an alert dialog, ... so consequently
the focus callback mustn't be called when the element gets its focus back.
2023-09-05 14:18:51 +02:00
Calixte Denizet
a00b542f2f Unconditionally render non-form annotations in the annotation layer (bug 1851498)
The goal is to always have something which is focusable to let the user select
it with the keyboard.
It fixes the mentioned bug because, the annotation layer will now have a container
to attach the canvas for annotations having their own canvas.
2023-09-05 10:41:01 +02:00
Calixte Denizet
7f44f353b3 Make annotations focusable (bug 1851489)
When the annotation has a popup then the popup can be toggled in using
the Enter key and hidden in using the Escape key.
2023-09-04 17:12:23 +02:00
Jonas Jenwald
284f32f50b Ignore null-chars when using structTree-data in the viewer
Testing the `tagged_stamp.pdf` document locally in the viewer, I noticed that e.g. the /Alt entry for the StampAnnotation contains "Secondary text for stamp\u0000".
Elsewhere in the viewer we're skipping null-chars and it's easy enough to do that in the `StructTreeLayerBuilder` class as well. (Note that we generally let the API itself return the data as-is.)
2023-08-31 16:29:10 +02:00
Calixte Denizet
e7229854bd Fix the id used in aria-controls used to make a relationship between the popup and its parent 2023-08-31 15:48:32 +02:00
Calixte Denizet
d185db2b70 Add tagged annotations in the structure tree (bug 1850797) 2023-08-31 12:35:32 +02:00
Calixte Denizet
24b480fabe Don't reset all fields when the resetForm argument is an array
correctly set the readonly property in the annotation layer and set the default checkbox value to Off when none is provided.
2023-08-24 09:10:27 -04:00
Calixte Denizet
ee3ac35e05 Revert fix for bug 1838855 (bug 1849876)
The issue described in the mentioned bug is reall because
Acrobat is rendering the XFA instead of the Acroform.
The original patch just tried to workaround the issue but it
induces some regressions.
2023-08-23 12:34:41 -04:00
Tim van der Meij
5828ac0ee3
Merge pull request #16834 from Snuffleupagus/globalWorkerPort-parallel-test
Add a unit-test for the "correct" way of using the global `workerPort` in parallel (PR 16830 follow-up)
2023-08-19 13:38:16 +02:00
Jonas Jenwald
4d19db0b19 Re-format the code to account for prettier and globals updates
The `prettier` update slightly changed the formatting of some await-expressions; please see https://github.com/prettier/prettier/blob/main/CHANGELOG.md#302

The `globals` update removed the need for some eslint-disable statements; please see https://github.com/sindresorhus/globals/releases/tag/v13.21.0
2023-08-19 09:30:34 +02:00
Jonas Jenwald
29b2050ac2 Improve the "write a new annotation, save the pdf and check that the text content is correct" unit-test (PR 16559 follow-up)
Currently this unit-test will pass just fine if compression is disabled, e.g. by commenting out the relevant code in the `src/core/writer.js` file.
While we don't have a simple way of *directly* checking that the Annotation text-content is compressed, we can however use the resulting file-size as a fairly good proxy. (Note that if compression is disabled the file-size is more than doubled.)
2023-08-15 15:12:17 +02:00
Jonas Jenwald
2422492ee3 Add a unit-test for the "correct" way of using the global workerPort in parallel (PR 16830 follow-up)
Please note that for performance reasons it's not really advised to use the same worker-thread *in parallel* for parsing multiple PDF documents, since they will then unnecessarily compete for resources.
However, given that it's still possible to do that e.g. when using the global `workerPort` it probably won't hurt to add a unit-test for this particular situation.
2023-08-15 12:45:54 +02:00
Jonas Jenwald
66437917db Avoid using the global workerPort when destruction has started, but not yet finished (issue 16777)
Given that the `PDFDocumentLoadingTask.destroy()`-method is documented as being asynchronous, you thus need to await its completion before attempting to load a new PDF document when using the global `workerPort`.
If you don't await destruction as intended then a new `getDocument`-call can remain pending indefinitely, without any kind of indication of the problem, as shown in the issue.

In order to improve the current situation, without unnecessarily complicating the API-implementation, we'll now throw during the `getDocument`-call if the global `workerPort` is in the process of being destroyed.
This part of the code-base has apparently never been covered by any tests, hence the patch adds unit-tests for both the *correct* usage (awaiting destruction) as well as the specific case outlined in the issue.
2023-08-12 21:21:50 +02:00
Calixte Denizet
d527fb3ff2 [Editor] Remove the stamp editor displayed when the image was loading (bug 1848313)
Make the annotation editor layer unclickable while the image is loading and
change the cursor to 'wait'.
2023-08-11 16:46:23 +02:00
Calixte Denizet
659fbc5020 [Editor] Add a button to explicitly add an image (bug 1848108)
The main stamp button will be used to just enter in a add/edit image mode:
 - the user can add a new image in using the new button.
 - the user can edit an image in resizing, moving it.
In image mode, when the user clicks outside on the page but not on an editor,
then all the selected editors will be unselected.
2023-08-11 15:05:46 +02:00
calixteman
0dd70c4e66
Merge pull request #16824 from calixteman/editor_dont_unselect_on_render
[Editor] Avoid to unselect when a new page is rendered
2023-08-10 18:37:42 +02:00
Calixte Denizet
71f5050ed2 [Editor] Avoid to unselect when a new page is rendered 2023-08-10 18:02:27 +02:00
Jonas Jenwald
389a26c115 Fallback to check all pages when getting the pageIndex of FieldObjects
Given that the FieldObjects are parsed in parallel, in combination with the existing caching in the `getPage`-method and `annotations`-getter, adding additional caches for this fallback code-path doesn't seem entirely necessary.
2023-08-10 17:10:04 +02:00
calixteman
4be6c90796
Merge pull request #16822 from calixteman/issue16821
[Editor] Don't forget to encrypt image streams (see issue #16821)
2023-08-10 16:18:17 +02:00
Calixte Denizet
7a5b3423d6 [Editor] Don't forget to encrypt image streams (see issue #16821)
and encrypt a compressed stream after having been compressed.
2023-08-10 15:19:45 +02:00
Calixte Denizet
402e3fed95 [Editor] Add the possibility to move all the selected editors with the mouse (bug 1847894) 2023-08-10 14:45:36 +02:00
Calixte Denizet
7d8b53bf7a [Editor] Move an the editor div in the DOM once a translation with the keyboard is done
When moving an element in the DOM, the focus is potentially lost, so we need to make sure
that the focused element before the translation will get back its focus after it.
But we must take care to not execute any focus/blur callbacks because the user didn't
do anything which should trigger such events: it's a detail of implementation. For example,
when several editors are selected and moved, then at the end the same must be selected, so
no element receive a focus event which will set it as selected.
2023-08-08 21:02:05 +02:00
Calixte Denizet
8f6635bacf [Editor] Avoid to add a new line when hitting enter with a selected freetext editor 2023-08-08 18:24:48 +02:00
calixteman
e914870c14
Merge pull request #16793 from calixteman/editor_resize_rotated
[Editor] Fix the resizing of an editor when it's rotated (bug 1847268)
2023-08-08 18:24:20 +02:00
Jonas Jenwald
2e9f2e630c
Merge pull request #16804 from Snuffleupagus/issue-16800
Take fill-alpha into account with default icons for FileAttachment annotations (issue 16800)
2023-08-08 16:39:37 +02:00
Jonas Jenwald
e2819d0c67 Take fill-alpha into account with default icons for FileAttachment annotations (issue 16800) 2023-08-08 15:53:48 +02:00
Calixte Denizet
e2f20a1afe [Annotation] Strip out the array index in the path only when the path is from a terminal node (bug 1847733) 2023-08-08 15:05:27 +02:00
Calixte Denizet
aa71619c2d [Editor] Fix the resizing of an editor when it's rotated (bug 1847268)
There are 2 rotation we've to deal with: the viewer one and the editor one.
The previous implementation was a bit complex and having to deal with these
rotation would have potentially increase it.
So this patch aims to simplify the implementation and deal with all the possible
cases.
The main idea is to transform the mouse deltas according to the rotations and then
apply the resizing in the page coordinates system.
2023-08-08 12:54:12 +02:00
Jonas Jenwald
e414dfcff7 Use the round CSS function in the setLayerDimensions helper function
This has now been enabled unconditionally in Firefox, see https://bugzilla.mozilla.org/show_bug.cgi?id=1814589

For the `page`-containers in the viewer, this patch should restore the behaviour prior to PR 15770; see e.g. https://github.com/mozilla/pdf.js/pull/15770/files#diff-c48e3561004f5db8f11d5ebab2fd661591222ba911cb4173fbced15f026bac6bL182-L183
Note that these changes this will lead to a tiny bit of movement in some `text` and `annotations` reference tests.

Please find additional information at https://developer.mozilla.org/en-US/docs/Web/CSS/round
2023-08-04 14:33:06 +02:00
Calixte Denizet
b59b1a81a9 [Editor] Refactor dragging and dropping an editor (bugs 1802895, 1844618)
It'll help to have a full control on what's happening when moving an editor.
2023-08-03 14:47:16 +02:00
Jonas Jenwald
64e8557fb5 [api-minor] Deprecate the PDFDocumentProxy.getJavaScript method
This method is very old, however with the exception of the auto-print hack (when scripting is disabled) in the viewer it's never actually been used.

Most likely the idea with `PDFDocumentProxy.getJavaScript` was that it'd be useful if scripting support was added, however it turned out that it was a bit too simplistic and instead a number of new methods were added for the scripting use-cases.
2023-08-01 09:02:05 +02:00
Calixte Denizet
71960bea64 Don't print hidden annotatons (bug 1815196)
and handle correctly the NoView and NoPrint flags when they're changed
from JS.
2023-07-31 13:04:15 +02:00
Calixte Denizet
d16d1f0d23 Add the color changes in the annotation storage 2023-07-30 14:03:27 +02:00
Jonas Jenwald
69a9d777d7 Add an eq test for bug 858128
The ten year old bug 858128 was recently fixed upstream, see https://bugzilla.mozilla.org/show_bug.cgi?id=858128#c25, and it seems like a good idea for us to add a test-case to help catch any future regressions here.
2023-07-29 12:37:58 +02:00
calixteman
0b715e2a73
Merge pull request #16762 from calixteman/editor_focus
[Editor] When an editor is unselected give the focus to the current page
2023-07-27 21:31:24 +02:00
Calixte Denizet
9d576d5097 [Editor] When an editor is unselected give the focus to the current page
Follow-up of #16756.
2023-07-27 21:12:26 +02:00
Jonas Jenwald
d6c0950389 Avoid eagerly matching "trailer"-strings when searching for incomplete objects in XRef.indexObjects (issue 16759, PR 15854 follow-up, bug 1845762)
When searching for "endobj"-operators, make sure that we don't accidentally match a "trailer"-string in /Content-streams without /Filter-entries (i.e. streams that contain "raw" and thus human-readable data).
2023-07-27 17:57:12 +02:00
Calixte Denizet
59bcfd9b9e [Editor] Blur unselected editors
When an editor is selected in using the keyboard then it has the focus.
But then if the editor is unselected with Escape key then the focus must
be removed otherwise we still have a blue outline around it.
And add few missing timeout in the integration tests.
2023-07-27 16:26:38 +02:00
Calixte Denizet
93b09f6320 [Editor] Add the possibility to move an empty freetext editor with the keyboard (bug 1845088) 2023-07-27 09:56:26 +02:00
Calixte Denizet
bb6936c931 [Editor] Make editors movable in using the keyboard (bug 1845088)
Selected editors can be moved in using the arrows:
 - up/down/left/right will move the editors of 1 in page unit;
 - ctrl (or meta)+up/down/left/right will move them of 10 in page unit.
2023-07-26 21:05:26 +02:00
Calixte Denizet
76caaab195 [Editor] Set keyboard events on window instead of the main container
The keyboard shortcuts (copy, paste, ...) didn't work correctly when the
main container was not focused.
This patch adds few waitForTimeout in the integration test for FreeText
in order to avoid possible intermittent failures.
2023-07-25 18:38:31 +02:00
Jonas Jenwald
3b6d2554a8 Fix copying of the reduced Planck constant
Please see https://en.wikipedia.org/wiki/H_with_stroke
2023-07-24 18:42:46 +02:00
calixteman
71f113bf85
Merge pull request #16718 from calixteman/bug1844572
Don't replace Acroform dictionary if nothing has changed when saving (bug 1844572)
2023-07-24 10:00:43 +02:00
Calixte Denizet
33fdec1392 Don't replace Acroform dictionary if nothing has changed when saving (bug 1844572) 2023-07-22 17:51:06 +02:00
Calixte Denizet
d470e91223 Don't get the text content for an annotation when /NeedAppearances is true (bug 1844583)
When the flag is set, the appearance has to be generated from the value so it's
useless/meaningless to extract the content from the existing appearance.
2023-07-21 12:26:27 +02:00
Calixte Denizet
9277801493 Text annotations must use their own canvas when their appearance is generated (bug 1844576)
When a pdf has /NeedAppearances set to true, the annotation appearance must be
generated from its value and we must take into account the hasOwnCanvas property.
2023-07-21 09:51:50 +02:00
Calixte Denizet
8daf2f1eb1 [Annotation] Use the clip-path property when an annotation has some quad points
This way it'll avoid to split a div in multiple divs having the same id (which
is supposed to be unique).
2023-07-20 10:53:23 +02:00
Calixte Denizet
7cd062ec68 Draw correctly background images in ref tests
It's a workaround for bug https://bugzilla.mozilla.org/show_bug.cgi?id=1844414.
It should be reverted (in order to avoid a perf penalty) once the bug is fixed
in Firefox.
2023-07-19 20:29:54 +02:00
Calixte Denizet
7ac3bf6f17 [Editor] Don't forget to generate non-missing images when printing (bug 1844036) 2023-07-18 15:39:18 +02:00
Jonas Jenwald
d022912719 Remove most build-time require-calls from the src/display/-folder
By leveraging import maps we can get rid of *most* of the remaining `require`-calls in the `src/display/`-folder, since we should strive to use modern `import`-statements wherever possible.
The only remaining cases are Node.js-specific dependencies, since those seem very difficult to convert unless we start producing a bundle *specifically* for Node.js environments.
2023-07-17 19:47:13 +02:00
Jonas Jenwald
3a886e7264 Move the isNodeJS-helper into the src/shared/util.js file
With the changes in the previous patch the `isNodeJS`-helper no longer needs to live in its own file, which helps get rid of a closure in the *built* files.
2023-07-17 16:42:25 +02:00
Calixte Denizet
a8867cf68a [Editor] Avoid to have some part of an editor outside its page (bug 1843303) 2023-07-17 14:27:15 +02:00
Jonas Jenwald
86a868189c Re-factor the PDFScriptingManager-class for the viewer-components
Currently this class contains a few "special" code-paths for the COMPONENTS build-target, which normally wouldn't be a problem. However, in this particular case that means accessing code that we don't want to include unconditionally in all builds.
This is currently implemented using build-time `require`-calls which we nowadays want to avoid, and we should strive to remove all such cases from the code-base. (Generally speaking `import` is the future, and build-tools may not always play well with a mix of both formats.)

We can easily improve things here by using sub-classing for the COMPONENTS build-target, and then use the ability to re-name when exporting (to avoid breaking existing code).
2023-07-16 08:51:46 +02:00
Jonas Jenwald
bd67f7841f
Merge pull request #16695 from Snuffleupagus/tests-NaN
Ensure that a test-suite that runs no tests is treated as a failure
2023-07-16 08:32:43 +02:00
Jonas Jenwald
b019c13b33 Ensure that a test-suite that runs no tests is treated as a failure
Occasionally some test-suites may fail to start on the bots, however that's not correctly reflected in the botio-output posted to GitHub which makes it easy to accidentally overlook this situation.
Looking at the raw logs when that happens they always seem to contain a line such as `Run NaN tests` which means that we should be able to easily make this situation a *failure* as intended.
2023-07-15 12:03:47 +02:00
Jonas Jenwald
f84657d837 Address formatting changes from Prettier version 3 2023-07-15 10:44:39 +02:00
Calixte Denizet
944c68ee85 [Editor] Try to make the position of an edited FreeText the more accurated as possible
- Take into account the page translation,
- Take into account the correct translation for the editor border,
- Take into account the position of the first glyph in the annotation,
- Take into account the rotation of the editor.

Close #16633.
2023-07-12 19:53:57 +02:00
Jonas Jenwald
a209ce811d [ESM] Convert *most* of test-folder to use standard modules 2023-07-08 13:13:04 +02:00
Jonas Jenwald
5696c3aa3a
Merge pull request #16658 from Snuffleupagus/test-more-APIs
Add unit-tests to check that more PDF.js APIs expose the expected functionality
2023-07-08 08:16:57 +02:00
Calixte Denizet
5c5f9af803 [Editor] Edit an existing FreeText annotation in double-clicking on it (bug 1787298) 2023-07-07 17:44:45 +02:00
Calixte Denizet
4fcc2ef23f [Editor] Support svg images in the stamp annotation
createImageBitmap doesn't work with svg files (see bug 1841972), so we need to workaround
this in using an Image.
When printing/saving we must rasterize the image, hence we get the biggest bitmap as image
reference to avoid duplications or poor quality on rendering.
2023-07-07 15:59:13 +02:00
Jonas Jenwald
506bca5e6d Add unit-tests to check that more PDF.js APIs expose the expected functionality
Similar to e.g. PR 16587, let's ensure that the `pdf.worker.js` and `pdf.image_decoders.js` files expose the expected functionality.
2023-07-07 12:36:21 +02:00
calixteman
eb2527e9d7
Merge pull request #16652 from calixteman/rm_all_exceptions
[Editor] Avoid to throw when deleting some invisible editors
2023-07-06 19:11:44 +02:00
Calixte Denizet
e4b4d222fa [Editor] Avoid to throw when deleting some invisible editors 2023-07-06 16:55:51 +02:00
Jonas Jenwald
6442a6cc4e Improve parseAppearanceStream to handle more "complex" ColorSpaces
The existing code is unable to *correctly* extract the color from the appearance-stream when the ColorSpace-data is "complex". To reproduce this:
 - Open `freetexts.pdf` in the viewer.
 - Note the purple color of the "Hello World from Preview" annotation.
 - Enable any of the Editors.
 - Note how the relevant annotation is now black.
2023-07-06 15:58:09 +02:00
Calixte Denizet
77656ce881 [Editor] When saving/printing a FreeText, use the identity matrix for the AP and set the cm when rendering it
When there was a rotation, the generated bbox was wrong because of an inversion
between width and height.
This patch aims to fix this issue in re-writing the FreeText code generation
to have something similar to what Acrobat does.
And fix the name of the font which wasn't the correct one when calling the
evaluator.
2023-07-05 16:37:01 +02:00
Calixte Denizet
1ce6668a70 [Editor] Fix dimensions of a rotated FreeText after a dimensions change 2023-07-04 23:56:24 +02:00
Jonas Jenwald
39113baa33 Move the transfers computation into the AnnotationStorage class
Rather than having to *manually* determine the potential `transfers` at various spots in the API, we can let the `AnnotationStorage.serializable` getter include this.
To further simplify things, we can also let the `serializable` getter compute and include the `hash`-string as well.
2023-06-29 19:51:57 +02:00
calixteman
88c7c8b5bf
Merge pull request #16588 from calixteman/editor_stamp_2
[Editor] Add support for printing/saving newly added Stamp annotations
2023-06-28 22:42:54 +02:00
Calixte Denizet
599b9498f2 [Editor] Add support for printing/saving newly added Stamp annotations
In order to minimize the size the of a saved pdf, we generate only one
image and use a reference in each annotation using it.
When printing, it's slightly different since we have to render each page
independantly but we use the same image within a page.
2023-06-26 15:47:05 +02:00
Jonas Jenwald
5f5db4b160 Run the PDF.js-viewer API unit-test in Node.js environments (PR 16592 follow-up)
It occurred to me that we can actually run this unit-test in Node.js environments by making use of the preprocessor to stub out the browser globals there.
2023-06-26 09:37:34 +02:00
Jonas Jenwald
e153e3a741 Expose FindState in the viewer-components (issue 16589) 2023-06-24 13:23:02 +02:00
Jonas Jenwald
f596490a1b Add a unit-test to check that the *official* PDF.js-viewer API exposes the expected functionality
Until now we've not actually had *any* tests that ensure that the *official* PDF.js-viewer API exposes the intended functionality, which means that things can easily break accidentally.

*Please note:* This unit-test cannot (easily) be run in Node.js-environments, since the `external/webL10n/l10n.js` file contains various browser-specific functionality.
2023-06-23 12:22:54 +02:00
Jonas Jenwald
0bbadce066 Add a unit-test to check that the *official* PDF.js API exposes the expected functionality
Until now we've not actually had *any* tests that ensure that the *official* PDF.js API exposes the intended functionality, which means that things can easily break accidentally.
2023-06-22 15:21:10 +02:00
Calixte Denizet
8ae1c8dd81 [Editor] Hide visible popups when editing 2023-06-21 12:30:05 +02:00
Calixte Denizet
19f7a8b899 [Editor] Don't make editable an empty freetext annotation 2023-06-21 11:48:20 +02:00
Jonas Jenwald
19880fcf9a [api-minor] Move the l10n-translation into the AnnotationLayer
With the changes in PR 16552 we can now move general translation into the `AnnotationLayer` itself, which should improve things ever so slightly in third-party implementations where the default viewer isn't used.
2023-06-20 20:28:35 +02:00
Calixte Denizet
5ffaa64167 Fix integration tests 2023-06-20 17:52:20 +02:00
Calixte Denizet
d1e172458f [api-minor] Make the popup independent of their associated annotations
- it'll help to be able to move popups on screen to let the user read the text
- popups won't inherit some properties from their parent:
  - the popup can be misrendered if for example the parent has a clip-path property.
- add an outline to the popup when the parent is focused.
- hide a popup when it's clicked.
2023-06-20 15:30:39 +02:00
calixteman
d01efc6767
Merge pull request #16567 from calixteman/issue16566
[Editor] Show hidden annotations once editing is finished
2023-06-19 23:50:40 +02:00
Calixte Denizet
ae3cee95a6 [Editor] Show hidden annotations once editing is finished 2023-06-19 23:03:45 +02:00
calixteman
a5c10b6d89
Merge pull request #16563 from calixteman/bug1838855
Guess that a checkbox belongs to a group in using its T value (bug 1838855)
2023-06-16 20:40:34 +02:00
Calixte Denizet
5c0054d58d Guess that a checkbox belongs to a group in using its T value (bug 1838855) 2023-06-16 18:45:09 +02:00
calixteman
46b8f9e2f2
Merge pull request #16561 from calixteman/editor_copy_existing
[Editor] Avoid an exception when copying an existing editor
2023-06-16 14:47:55 +02:00
Calixte Denizet
ca3e45755c [Editor] Avoid an exception when copying an existing editor 2023-06-16 14:19:37 +02:00
Jonas Jenwald
2cb113b545 Improve handling of /Filter-entries in writeStream
Fix handling of /Filter-entries, since the current implementation could potentially corrupt the data if there's multiple filters present.
Please note that filters are applied *sequentially* during decoding, starting from the first one in the Array, hence the first Array-entry needs to be /FlateDecode in order for things to actually work correctly.

To prevent a future bug, if we want to save more "complex" data such as images, also ensure that we include any existing /DecodeParms-entries when updating the /Filter-entry.
2023-06-16 10:27:23 +02:00
Calixte Denizet
85b38fc247 Add a test to check that the compression is ok when saving an annotation 2023-06-16 10:05:42 +02:00
calixteman
8937cac621
Merge pull request #16556 from calixteman/no_dup_when_saving
[Editor] Avoid to have duplicated entries in the Annot array when saving an existing and modified annotation
2023-06-15 23:47:25 +02:00
Calixte Denizet
71479fdd21 [Editor] Avoid to have duplicated entries in the Annot array when saving an existing and modified annotation 2023-06-15 22:02:10 +02:00
Calixte Denizet
dd21139405 Disable events on canvas in the annotation layer 2023-06-15 21:10:40 +02:00
Calixte Denizet
1ab34d2ae4 [Editor] Don't add an editor for empty FreeText annotations 2023-06-15 18:33:03 +02:00
calixteman
5581e22cc7
Merge pull request #16535 from calixteman/restore_freetext
[Editor] Allow to edit FreeText annotations
2023-06-15 18:10:41 +02:00
calixteman
9f60686c59
Merge pull request #16554 from calixteman/issue16553
Add a container for Signature with their own canvas
2023-06-15 16:20:54 +02:00
Calixte Denizet
be25ee12bb Add a container for Signature with their own canvas 2023-06-15 16:11:52 +02:00
Calixte Denizet
0116a8f484 [Editor] Allow to edit FreeText annotations 2023-06-15 16:06:29 +02:00
Jonas Jenwald
877884029d
Merge pull request #16551 from Snuffleupagus/page-destroyed-complete
Ensure that `cleanup` during rendering is actually ignored, to prevent a blank canvas
2023-06-15 12:26:57 +02:00
Jonas Jenwald
0650be4641
Merge pull request #16550 from Snuffleupagus/rm-RenderingCancelledException-type
[api-minor] Remove the `type` from `RenderingCancelledException` (PR 16226 follow-up)
2023-06-15 12:26:27 +02:00
Jonas Jenwald
a591c3de84 Ensure that cleanup during rendering is actually ignored, to prevent a blank canvas
The existing unit-test doesn't work as intended, since the page never actually renders. Note how `cleanup` is *not* allowed to run when parsing and/or rendering is ongoing, however an (old) incorrect condition could prevent rendering from ever starting.

This is very old code, which has been slightly re-factored a couple of times (many years ago), however this doesn't appear to affect e.g. the default viewer since the incorrect behaviour seem highly dependent on "unlucky" timing.
Note also how at the start of the `PDFPageProxy.prototype.render`-method we purposely cancel any pending `cleanup`-call, to prevent unnecessary re-parsing for multiple sequential `render`-calls.

Finally, avoid running `cleanup` when document/page destruction has already started since it's pointless in that case.
2023-06-15 11:39:26 +02:00
Jonas Jenwald
225734dd00 [api-minor] Remove the type from RenderingCancelledException (PR 16226 follow-up)
After PR 16226 we're only using `RenderingCancelledException` together with canvas-rendering, hence the `type`-property is no longer necessary.
2023-06-14 15:40:25 +02:00
Jonas Jenwald
fee850737b Enable the unicorn/prefer-optional-catch-binding ESLint plugin rule
According to MDN this format is available in all browsers/environments that we currently support, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch#browser_compatibility

Please also see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-optional-catch-binding.md
2023-06-12 11:46:11 +02:00
Calixte Denizet
1a047f843c [Editor] Add the possibility to update an existing annotation with some new properties when saving or printing 2023-06-09 17:14:53 +02:00
Calixte Denizet
3d0ce1cff2 Concat data when push fails in the CFF compiler 2023-06-09 15:48:01 +02:00
Calixte Denizet
baebf7b26d [Editor] Fix test failures in m-c because of the new FreeText undo/redo stuff 2023-06-08 13:38:52 +02:00
Calixte Denizet
2f0bb9dc2f [Editor] Allow to undo/redo committed text modifications for FreeText 2023-06-05 21:31:19 +02:00
Calixte Denizet
ba8c996623 [Editor] Guess font size and color from the AS of FreeText annotations 2023-06-05 17:15:17 +02:00
Tim van der Meij
8a5af64749
Merge pull request #16519 from timvandermeij/puppeteer
Improve Puppeteer's `trimCache` API usage
2023-06-04 14:35:30 +02:00
Tim van der Meij
a9093a7f4d
Improve Puppeteer's trimCache API usage
The original `trimCache` functionality was intended to be exposed on the
top-level `puppeteer` module, but due to a bug in Puppeteer this didn't
work correctly and we had to call `trimCache` on the default Puppeteer
node instance instead, which was fortunately exposed. However, since
this didn't feel like intended API usage, this bug was reported and is
now fixed in Puppeteer 20.5.0, so this commits updates Puppeteer to that
version so we can use the intended API.

The full history of this issue can be found at
https://github.com/puppeteer/puppeteer/issues/10174.
2023-06-04 13:49:44 +02:00
Jonas Jenwald
cf3a35e9da Enable the import/no-cycle ESLint plugin rule
Having cyclical imports is obviously not a good idea, and this ESLint plugin rule can help detect those; please see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md
2023-06-04 13:44:15 +02:00