Compare commits

...

3296 Commits

Author SHA1 Message Date
calixteman
2a68724b53
Merge pull request #17793 from calixteman/zoom_wheel_ctrl
When zooming the scrollbar can disappear and then no scrollend is triggered
2024-03-15 16:30:39 +01:00
Calixte Denizet
65d618635c When zooming the scrollbar can disappear and then no scrollend is triggered 2024-03-15 15:37:06 +01:00
Jonas Jenwald
30e69956db
Merge pull request #17694 from Snuffleupagus/validate-defaultOptions
Add better validation for the "PREFERENCE" kind `AppOptions`
2024-03-12 18:24:37 +01:00
Jonas Jenwald
e650b95253
Merge pull request #17714 from Snuffleupagus/Node-fs-promise
Use `fs/promises` in the Node.js-specific code in the `src/`-folder
2024-03-12 18:09:33 +01:00
calixteman
a7d47af474
Merge pull request #17732 from calixteman/editor_highlight_floating_button
[Editor] Add a floating button close to the selected text to highlight it (bug 1867742)
2024-03-12 15:43:19 +01:00
Jonas Jenwald
b54887cfab
Merge pull request #17717 from Snuffleupagus/pr-17681-follow-up
Combine a few lines in the `dist-pre` target (PR 17681 follow-up)
2024-03-12 15:15:19 +01:00
Calixte Denizet
b4267cd294 [Editor] Add a floating button close to the selected text to highlight it (bug 1867742)
For now keep this feature behind a pref in order to make some experiments before
deciding to enable it.
2024-03-12 15:06:46 +01:00
Jonas Jenwald
eb160726ee
Merge pull request #17726 from Snuffleupagus/OptionalContent-Usage
[api-minor] Implement basic support for OptionalContent `Usage` dicts (issue 5764, bug 1826783)
2024-03-12 14:09:57 +01:00
Jonas Jenwald
70b6ddc5d9 Move the /SetOCGState handling into the OptionalContentConfig class (PR 15377 follow-up)
This helps ensure that /SetOCGState actions always take the `Usage` dictionary into account as expected.
2024-03-12 13:18:15 +01:00
Jonas Jenwald
3c78ff5fb0 [api-minor] Implement basic support for OptionalContent Usage dicts (issue 5764, bug 1826783)
The following are some highlights of this patch:
 - In the Worker we only extract a *subset* of the potential contents of the `Usage` dictionary, to avoid having to implement/test a bunch of code that'd be completely unused in the viewer.

 - In order to still allow the user to *manually* override the default visible layers in the viewer, the viewable/printable state is purposely *not* enforced during initialization in the `OptionalContentConfig` constructor.

 - Printing will now always use the *default* visible layers, rather than using the same state as the viewer (as was the case previously).
   This ensures that the printing-output will correctly take the `Usage` dictionary into account, and in practice toggling of visible layers rarely seem to be necessary except in the viewer itself (if at all).[1]

---
[1] In the unlikely case that it'd ever be deemed necessary to support fine-grained control of optional content visibility during printing, some new (additional) UI would likely be needed to support that case.
2024-03-12 13:18:15 +01:00
calixteman
e647311a89
Merge pull request #17788 from calixteman/bug1881743
[Editor] Improve the accessibility of the highlight editor (bug 1881743)
2024-03-11 21:57:11 +01:00
Calixte Denizet
f676c2c0c8 [Editor] Improve the accessibility of the highlight editor (bug 1881743) 2024-03-11 14:21:43 +01:00
Jonas Jenwald
b14f696071
Merge pull request #17711 from Snuffleupagus/importl10n-Fetch-API
Use the Fetch API to download the l10n files
2024-03-08 11:51:34 +01:00
Jonas Jenwald
ea4b55a0e6 Update l10n files 2024-03-08 10:09:51 +01:00
Jonas Jenwald
2b407990e2 Use the Fetch API to download the l10n files
Given that the Fetch API is supported since Node.js 18 we should be able to use it when downloading l10n files, which allows us to simplify the code and to make it fully `async`.
2024-03-08 10:08:15 +01:00
calixteman
fb9e438442
Merge pull request #17781 from calixteman/stamp_altext_button_cp
[Editor] Make sure the alt-text button is there when pasting an image from an other tab
2024-03-07 21:44:53 +01:00
calixteman
406018934a
Merge pull request #17778 from calixteman/highlight_show_all
[Editor] Add a toggle button to show/hide all the highlights (bug 1867740)
2024-03-07 18:49:09 +01:00
Calixte Denizet
0f8dda1af0 [Editor] Make sure the alt-text button is there when pasting an image from an other tab 2024-03-07 18:24:34 +01:00
Calixte Denizet
39aeea3e94 [Editor] Add a toggle button to show/hide all the highlights (bug 1867740) 2024-03-07 13:16:59 +01:00
calixteman
6bb6ce6a5d
Merge pull request #17767 from calixteman/automation_win_listener
In the m-c automation, give the possibility to remove window listeners when a test ended
2024-03-06 14:39:58 +01:00
Calixte Denizet
6d0835dc52 In the m-c automation, give the possibility to remove window listeners when a test ended
The goal is to avoid to have some exceptions in the logs when a test finished.
2024-03-06 14:21:57 +01:00
calixteman
9ee4c6528d
Merge pull request #17776 from calixteman/bug1883609
[Annotations] Widget annotations must be in front of the other ones (bug 1883609)
2024-03-06 10:53:11 +01:00
Calixte Denizet
4e1b96c781 [Annotations] Widget annotations must be in front of the other ones (bug 1883609) 2024-03-05 19:04:58 +01:00
calixteman
f634cb533c
Merge pull request #17775 from calixteman/bug1883632
[Editor] Let a free highlight be clipped when its bounding box exceeds the page limits (bug 1883632)
2024-03-05 17:14:48 +01:00
Calixte Denizet
bd5875d066 [Editor] Let a free highlight be clipped when its bounding box exceeds the page limits (bug 1883632) 2024-03-05 16:47:07 +01:00
calixteman
f1272ee435
Merge pull request #17771 from calixteman/bug1832519
[GeckoView] Remove the open-in-app button (bug 1832519)
2024-03-05 14:11:12 +01:00
calixteman
b447a62fea
Merge pull request #17772 from calixteman/reporttelemetry
Don't stringify data for telemetry
2024-03-05 12:54:24 +01:00
Calixte Denizet
ba3e559583 Don't stringify data for telemetry 2024-03-04 20:17:47 +01:00
Calixte Denizet
3cb58f84a2 [GeckoView] Remove the open-in-app button (bug 1832519) 2024-03-04 19:32:12 +01:00
calixteman
c451b6d684
Merge pull request #17764 from calixteman/telemetry_null_stats
[Editor] Use a null instead of an empty stats object when sending the telemetry
2024-03-04 19:16:57 +01:00
calixteman
a55f976e2e
Merge pull request #17766 from calixteman/escape_color_picker
[Editor] Unselect highlight editor when pressing Escape when the focus is on the color picker without a dropdown menu
2024-03-04 19:16:34 +01:00
calixteman
7c9d3af85b
Merge pull request #17768 from calixteman/bug1883394
[Editor] Set the creation method for free highlights to 'main_toolbar' (bug 1883394)
2024-03-04 19:16:15 +01:00
Calixte Denizet
ecb4262b13 [Editor] Set the creation method for free highlights to 'main_toolbar' (bug 1883394) 2024-03-04 16:58:50 +01:00
Calixte Denizet
1859412507 [Editor] Unselect highlight editor when pressing Escape when the focus is on the color picker without a dropdown menu 2024-03-04 16:32:09 +01:00
Calixte Denizet
d096dc79b2 [Editor] Use a null instead of an empty stats object when sending the telemetry 2024-03-04 10:18:24 +01:00
Jonas Jenwald
dd3adc84db
Merge pull request #17761 from Snuffleupagus/thicknessPicker-disabled
[Editor] Indicate if the highlight-thickness slider is disabled
2024-03-01 17:01:05 +01:00
Jonas Jenwald
e781b553cb [Editor] Reduce a bit of CSS duplication for the highlight-thickness "indicators" 2024-03-01 16:18:39 +01:00
Jonas Jenwald
c7e7122e25 [Editor] Indicate if the highlight-thickness slider is disabled
The fact that the highlight-thickness can only be changed in "free" mode isn't really obvious visually in the toolbar, so attempt to provide at least some indication of the `disabled`-state by "dimming" the slider.
2024-03-01 16:18:31 +01:00
calixteman
29c493d36b
Merge pull request #17760 from calixteman/fix_quadpoints
[Editor] Fix the quadpoints value when serializing an highlight annotation
2024-03-01 13:08:44 +01:00
Calixte Denizet
30101cbb31 [Editor] Fix the quadpoints value when serializing an highlight annotation
The coordinates of each point in a box are in the page coordinates system.
2024-03-01 11:36:16 +01:00
Jonas Jenwald
61036383b5
Merge pull request #17710 from Snuffleupagus/pr-17277-followup
Simplify the `XMLHttpRequest`-branch in the `fetchData` helper function (PR 17277 follow-up)
2024-03-01 10:23:02 +01:00
calixteman
8f75e34b6f
Merge pull request #17757 from calixteman/bug1881219
[Editor] Enable the thickness input when no editors are selected (bug 1881219)
2024-02-29 23:26:49 +01:00
Calixte Denizet
7af90bb8bc [Editor] Enable the thickness input when no editors are selected (bug 1881219) 2024-02-29 23:05:33 +01:00
calixteman
c409121251
Merge pull request #17756 from calixteman/bug1882248
[Editor] Make the delete button clickable with the space key (bug 1882248)
2024-02-29 19:57:57 +01:00
Calixte Denizet
f52bf2836f [Editor] Make the delete button clickable with the space key (bug 1882248) 2024-02-29 19:05:38 +01:00
calixteman
7cc34cf4a7
Merge pull request #17755 from calixteman/bug1881684
[Editor] Add the possibility to move the caret with the keyboard once  an highlight has been made (bug 1881684)
2024-02-29 18:38:17 +01:00
Calixte Denizet
a9f47e87d5 [Editor] Add the possibility to move the caret with the keyboard once an highlight has been made (bug 1881684) 2024-02-29 18:18:13 +01:00
Jonas Jenwald
9600c48d4f
Merge pull request #17750 from Snuffleupagus/pr-17748-followup
Inline the `HighlightEditor.#telemetryType` getter at its only call-site (PR 17748 follow-up)
2024-02-29 10:34:37 +01:00
Jonas Jenwald
a92b38e71c Inline the HighlightEditor.#telemetryType getter at its only call-site (PR 17748 follow-up) 2024-02-28 20:47:01 +01:00
calixteman
9fe15d4a01
Merge pull request #17748 from calixteman/highlight_telemetry_followup
[Editor] Count the colors used when highlighting whatever the highlight kind is
2024-02-28 20:00:15 +01:00
Calixte Denizet
3a7e638fce [Editor] Count the colors used when highlighting whatever the highlight kind is 2024-02-28 18:24:24 +01:00
calixteman
07abd647f4
Merge pull request #17737 from calixteman/highlight_telemetry
[Editor] Add some telemetry for the highlight feature (bug 1866437)
2024-02-28 15:20:57 +01:00
Calixte Denizet
65342d2bee [Editor] Add some telemetry for the highlight feature (bug 1866437) 2024-02-28 10:17:11 +01:00
calixteman
b1a04fc184
Merge pull request #17738 from calixteman/issue17730
Always add links in the annotation layer
2024-02-28 09:34:10 +01:00
Calixte Denizet
e0b843d991 Always add links in the annotation layer
Fixes #17730.
2024-02-27 22:48:08 +01:00
calixteman
06aef89502
Merge pull request #17733 from calixteman/puppeteer_22_1_0
Update puppeteer to 22.3.0
2024-02-27 13:46:30 +01:00
Calixte Denizet
5e7941afbf Update puppeteer to 22.3.0 2024-02-27 12:19:54 +01:00
calixteman
e42b114e80
Merge pull request #17724 from calixteman/issue17707
Avoid to have to wait to zoom after scrolling
2024-02-26 11:05:10 +01:00
Calixte Denizet
9e042e7acc Avoid to have to wait to zoom after scrolling
Allow to zoom with the wheel once the scrolling is finished.
It's now possible to know that thanks to the scrollend event.

Fixes #17707.
2024-02-25 21:40:48 +01:00
calixteman
ca4ab064e5
Merge pull request #17720 from calixteman/editor_simplify_highlighting
[Editor] In caret browsing mode, allow to select in pressing shift and arrow down (bug 1881802)
2024-02-25 17:52:11 +01:00
Calixte Denizet
0520f2f0cb [Editor] In caret browsing mode, allow to select in pressing shift and arrow down (bug 1881802)
In implementing caret browsing mode in pdf.js, I didn't notice that selectstart isn't always triggered.
So this patch removes the use of selectstart and rely only on selectionchange.
In order to simplify the selection management, the selection code is moved in the AnnotationUIManager:
 - it simplifies the code;
 - it allows to have only one listener for selectionchange instead of having one by visible page
   for selectstart.
I had to add a delay in the integration tests for highlighting (there's a comment with an explanation),
it isn't really nice, but it's the only way I found and in real life there always is a delay between
press and release.
2024-02-25 15:35:30 +01:00
calixteman
1bd6af6dae
Merge pull request #17722 from calixteman/issue17721
Fix the string GlobalConstants.IDS_INVALID_DATE
2024-02-23 21:49:42 +01:00
Calixte Denizet
fe41e789de Fix the string GlobalConstants.IDS_INVALID_DATE 2024-02-23 21:39:06 +01:00
Jonas Jenwald
346efe919a
Merge pull request #17718 from Snuffleupagus/hexNumbers-tweak
Tweak how the `hexNumbers` Array, used by `Util.makeHexColor`, is built
2024-02-23 18:17:10 +01:00
calixteman
b8b8f1af66
Merge pull request #17719 from calixteman/bug1881692
[Editor] In caret browsing mode, get the caret position in the text layer (bug 1881692)
2024-02-23 17:11:51 +01:00
Calixte Denizet
bb19cf9b64 [Editor] In caret browsing mode, get the caret position in the text layer (bug 1881692)
The function caretPositionFromPoint return the position within the last visible element
and sometimes there are some elements on top of the ones in the text layer.
So the idea is to hide the visible elements which aren't in the text layer in order
to get the right caret position.
2024-02-23 16:50:19 +01:00
calixteman
101e8efad7
Merge pull request #17708 from calixteman/editor_highlight_context_menu
[Editor] Add the possibility to create an highlight from the context menu when some text is selected (bug 1867739)
2024-02-23 16:39:03 +01:00
Calixte Denizet
e1f6f5179f [Editor] Add the possibility to create an highlight from the context menu when some text is selected (bug 1867739) 2024-02-23 16:18:03 +01:00
Jonas Jenwald
49a2aff532 Tweak how the hexNumbers Array, used by Util.makeHexColor, is built
*Please note:* This is a micro optimization, hence I fully understand if the patch is rejected.

Currently we create two temporary Arrays and have to iterate twice in total when building the final `hexNumbers` Array.
With this patch there's only one temporary Array and a single iteration required to build the final `hexNumbers` Array.
2024-02-23 14:20:53 +01:00
Jonas Jenwald
dab8a2eaa4 Combine a few lines in the dist-pre target (PR 17681 follow-up)
In PR 17681 I completely missed that we can combine a number of lines in the `dist-pre` target, which helps reduce code size a little bit.
2024-02-23 13:32:04 +01:00
Jonas Jenwald
db2849cc17 Use fs/promises in the Node.js-specific code in the src/-folder
This is available in all Node.js versions that we currently support, and using it allows us to remove callback-functions; please see https://nodejs.org/docs/latest-v18.x/api/fs.html#promises-api
2024-02-22 16:50:13 +01:00
Jonas Jenwald
33c5ef349e Simplify the XMLHttpRequest-branch in the fetchData helper function (PR 17277 follow-up) 2024-02-21 23:00:24 +01:00
calixteman
72b8b29147
Merge pull request #17701 from calixteman/alt_text_ai
[Editor] Add the possibility to query some ML stuff to guess an alt text for an image
2024-02-21 10:14:40 +01:00
calixteman
0fb8a23051
Merge pull request #17702 from calixteman/bug1868759
[Editor] Disable annotation layer when highlighting (bug 1868759)
2024-02-21 09:49:48 +01:00
Calixte Denizet
46416bb131 [Editor] Add the possibility to query some ML stuff to guess an alt text for an image
It's only for an experimental purpose.
2024-02-20 21:29:33 +01:00
Calixte Denizet
95f9bedc7c [Editor] Disable annotation layer when highlighting (bug 1868759)
When highlighting, the annotation editor layer is disabled to get pointer events
from the text layer, but the annotation layer must be then disabled either in
order to avoid bad interactions.
2024-02-20 21:17:05 +01:00
Jonas Jenwald
38004b65b1 Re-factor how the compatibilityParams, in the viewer, are handled
Previously we'd simply export this directly from `web/app_options.js`, which meant that it'd be technically possible to *accidentally* modify the `compatibilityParams` Object when accessing it.
To avoid this we instead introduce a new `AppOptions`-method that is used to lookup data in `compatibilityParams`, which means that we no longer need to export this Object.

Based on these changes, it's now possible to simplify some existing code in `AppOptions` by taking full advantage of the nullish coalescing (`??`) operator.
2024-02-20 18:38:18 +01:00
Jonas Jenwald
90b2664622 Add better validation for the "PREFERENCE" kind AppOptions
Given that the "PREFERENCE" kind is used e.g. to generate the preference-list for the Firefox PDF Viewer, those options need to be carefully validated.
With this patch we'll now check this unconditionally in development mode, during testing, and when creating the preferences in the gulpfile.
2024-02-20 18:38:15 +01:00
calixteman
70015ffe6b
Merge pull request #17688 from calixteman/editor_no_scroll_unselect
[Editor] Avoid to scroll when an editor is unselected
2024-02-20 17:00:43 +01:00
calixteman
99fa713fba
Merge pull request #17690 from calixteman/issue17689
Avoid to access to a missing cidSystemInfo property
2024-02-19 12:04:07 +01:00
Calixte Denizet
a6eadf8150 Avoid to access to a missing cidSystemInfo property
Fixes #17689.
2024-02-19 09:55:23 +01:00
Calixte Denizet
c2fcc66302 [Editor] Avoid to scroll when an editor is unselected 2024-02-18 19:21:45 +01:00
Tim van der Meij
d96fd80ca0
Merge pull request #17687 from Snuffleupagus/pr-17686-followup
Disable source-map generation in the minified builds (PR 17686 follow-up)
2024-02-18 13:35:23 +01:00
Jonas Jenwald
673639c54b Disable source-map generation in the minified builds (PR 17686 follow-up)
As part of the changes in PR 17686 we "accidentally" enabled source-maps for the *minified* builds, which seems unnecessary since those have never been included in the `pdfjs-dist` output.
Locally this patch reduces the run-time of `gulp minified` by ~15 percent.
2024-02-17 22:14:37 +01:00
Tim van der Meij
4ac8ee8b6d
Merge pull request #17686 from Snuffleupagus/Webpack-TerserPlugin
Run minification directly during Webpack building
2024-02-17 19:42:35 +01:00
Jonas Jenwald
091e861531 Run minification directly during Webpack building
Rather than first building the library and then use Terser "manually" to minify the files, we can utilize a Webpack plugin to combine these steps which helps to simplify the gulpfile.
2024-02-17 18:51:34 +01:00
Tim van der Meij
8487c67cb8
Merge pull request #17684 from timvandermeij/modernize-webserver-pt2
Modernize the webserver code (part 2)
2024-02-17 18:22:51 +01:00
Tim van der Meij
33955980c8
Merge pull request #17685 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2024-02-17 18:09:51 +01:00
Tim van der Meij
2e6fa797d9
Improve the webserver's constructor
This makes the webserver configurable during instantiation rather than
having to set the parameters afterwards.
2024-02-17 16:22:10 +01:00
Tim van der Meij
985ba77579
Modernize the remainder of the webserver's code and enable the no-var ESLint rule
This commit also moves the content type logic into a helper method to
ever so slightly reduce duplication.
2024-02-17 16:22:10 +01:00
Tim van der Meij
0015eb2431
Modernize the webserver's handler method
This commit converts `var` to `const`/`let`, gives the variables more
readable names and annotates the code to make the flow clearer.
2024-02-17 16:22:10 +01:00
Tim van der Meij
6ef813af01
Extract and modernize the webserver's request checking code
The `handler` method contained this code in two inline functions,
triggered via callbacks, which made the `handler` method big and harder
to read. Moreover, this code relied on variables from the outer scope,
which made it harder to reason about because the inputs and outputs
weren't easily visible.

This commit fixes the problems by extracting the request checking code
into a dedicated private method, and modernizing it to use e.g. `const`/
`let` instead of `var` and using template strings. The logic is now
self-contained in a single method that can be read from top to bottom
without callbacks and with comments annotating each check/section.
2024-02-17 16:22:10 +01:00
Tim van der Meij
43cdc1ca8a
Update translations to the most recent versions 2024-02-17 16:00:18 +01:00
Tim van der Meij
6baa439e15
Update dependencies to the most recent versions 2024-02-17 16:00:18 +01:00
Tim van der Meij
f1a225889b
Merge pull request #17681 from Snuffleupagus/parseMinified-changes
Tweak the `parseMinified` handling slightly in the gulpfile
2024-02-17 15:08:30 +01:00
Tim van der Meij
678c79cc78
Merge pull request #17678 from Snuffleupagus/pr-17637-followup
Remove unneeded `tweakWebpackOutput` usage in the gulpfile (PR 17637 follow-up)
2024-02-17 14:58:24 +01:00
Tim van der Meij
fd5d040073
Merge pull request #17667 from Snuffleupagus/createPrintService-params
Change `PDFPrintServiceFactory.createPrintService` to take a parameter object
2024-02-17 14:54:53 +01:00
Jonas Jenwald
179a3ecee6
Merge pull request #17680 from Snuffleupagus/issue-17679
Add a dummy `beginMarkedContentProps` operator when optional content parsing fails (issue 17679)
2024-02-17 14:29:08 +01:00
Jonas Jenwald
b767e12111
Merge pull request #17676 from Snuffleupagus/app-findBar-optional-chain
Access `PDFViewerApplication.findBar` safely in more spots (PR 15831 follow-up)
2024-02-17 13:54:00 +01:00
Jonas Jenwald
a7bcc81eb1 Add a dummy beginMarkedContentProps operator when optional content parsing fails (issue 17679) 2024-02-17 13:45:16 +01:00
Jonas Jenwald
75a5b2051d Tweak the parseMinified handling slightly in the gulpfile
- Run the minification in "parallel" since that should be a *tiny* bit more efficient.
 - Don't rename the minified files since that seems unnecessary, especially considering that they are only used in the `dist-pre` target where we currently change the name back manually.
2024-02-16 16:54:13 +01:00
Jonas Jenwald
751611f690 Remove unneeded tweakWebpackOutput usage in the gulpfile (PR 17637 follow-up)
After the changes in PR 17637 there's no longer any reason to invoke `tweakWebpackOutput` without an argument, since the `__non_webpack_import__` re-writing was moved into the Babel plugin.
This way we can avoid a (little) bit of unnecessary parsing during building.
2024-02-16 11:42:40 +01:00
Jonas Jenwald
b420bd8b20 Access PDFViewerApplication.findBar safely in more spots (PR 15831 follow-up)
Note that this patch is the result of code-inspection, and the code as written doesn't (currently) cause any bugs in e.g. the GeckoView PDF Viewer.
2024-02-15 11:25:29 +01:00
calixteman
a83a8d7e4f
Merge pull request #17674 from calixteman/issue17671
Fix the endoffset of the last glyph when it's followed by a null offset in the loca table
2024-02-15 10:19:55 +01:00
Jonas Jenwald
dbda3ec5f9
Merge pull request #17637 from Snuffleupagus/babel-plugin-__non_webpack_import__
Move the `__non_webpack_import__` re-writing into the Babel plugin
2024-02-14 22:23:24 +01:00
Calixte Denizet
fcad3718f0 Fix the endoffset of the last glyph when it's followed by a null offset in the loca table
It fixes #17671.
2024-02-14 17:20:04 +01:00
Jonas Jenwald
a204f434f3 Change PDFPrintServiceFactory.createPrintService to take a parameter object
By "modernizing" the method to use a parameter object instead, we avoid having to pass along the needed parameters individually.
2024-02-13 21:28:02 +01:00
calixteman
14874e50b7
Merge pull request #17636 from calixteman/bug1878916
When updating, write the xref table in the same format as the previous one (bug 1878916)
2024-02-13 14:45:14 +01:00
Calixte Denizet
2133da166e When updating, write the xref table in the same format as the previous one (bug 1878916)
The specs are unclear about what kind of xref table format must be used.
In checking the validity of some pdfs in the preflight tool from Acrobat
we can guess that having the same format is the correct way to do.
The pdf in the mentioned bug, after having been changed, wasn't correctly
displayed in neither Chrome nor Acrobat: it's now fixed.
2024-02-13 14:14:37 +01:00
Jonas Jenwald
e60329cea1
Merge pull request #17666 from Snuffleupagus/issue-17665
Skip any whitespace after the first object in linearized PDFs (issue 17665)
2024-02-13 12:39:36 +01:00
Jonas Jenwald
37e98e39f6 Skip any whitespace after the first object in linearized PDFs (issue 17665)
This way the code is now consistent with the non-linearized branch in the `PDFDocument.startXRef` getter.
2024-02-12 22:05:36 +01:00
calixteman
05b035602e
Merge pull request #17664 from calixteman/bug1879281
[Editor] Ends a free highlight where the mouse pointer is (bug 1879281)
2024-02-12 18:39:18 +01:00
Calixte Denizet
750b8e328a [Editor] Ends a free highlight where the mouse pointer is (bug 1879281) 2024-02-12 17:26:33 +01:00
Jonas Jenwald
eb5e6e68d6
Merge pull request #17663 from Snuffleupagus/pr-17428-test
Tweak the issue 11878 unit-test parsing time check (PR 17428 follow-up)
2024-02-12 14:14:29 +01:00
calixteman
f0343dcfdb
Merge pull request #17662 from calixteman/bug1879108
[Editor] Set rotated free highlight at the right position after having changed its thickness (bug 1879108)
2024-02-12 12:41:43 +01:00
Jonas Jenwald
19ef3e367b Tweak the issue 11878 unit-test parsing time check (PR 17428 follow-up)
This unit-test has been failing occasionally in Chrome and Node.js, hence we tweak the parsing time check to reduce the likelihood of that happening.
2024-02-12 12:31:55 +01:00
Jonas Jenwald
18959e80be
Merge pull request #17661 from timvandermeij/modernize-webserver
Modernize the webserver code (part 1)
2024-02-12 11:50:24 +01:00
Jonas Jenwald
4ab0ad3216 Move the __non_webpack_import__ re-writing into the Babel plugin
Note how we're using custom `__non_webpack_import__`-calls in the code-base, that we replace during the post-processing stage of the build, to be able to write `import`-calls that Webpack will leave alone during parsing.
This work-around is necessary since we let Babel discards all comments, given that we generally don't need/want them in the builds, hence why we cannot utilize `/* webpackIgnore: true */`-comments in the source-code.

After the changes in PR 17563 it thus seems to me that we should be able to just move this re-writing into the Babel plugin instead.
2024-02-12 10:49:43 +01:00
Jonas Jenwald
d742daf4b7
Merge pull request #17647 from Snuffleupagus/babel-rm-empty-nodes
Remove empty, top-level, nodes in the Babel plugin
2024-02-12 09:25:59 +01:00
Calixte Denizet
de1985abbb [Editor] Set rotated free highlight at the right position after having changed its thickness (bug 1879108) 2024-02-11 21:06:56 +01:00
Tim van der Meij
ce4fe0c234
Extract and modernize the webserver's directory listing code
The `handler` method contained this code in an inline function, which
made the `handler` method big and harder to read. Moreover, this code
relied on variables from the outer scope, which made it harder to reason
about because the inputs and outputs weren't easily visible.

This commit fixes the problems by extracting the directory listing code
into a dedicated private method, and modernizing it to use e.g. `const`/
`let` instead of `var` and using template strings.
2024-02-11 20:06:21 +01:00
calixteman
5cfaff508c
Merge pull request #17651 from calixteman/add_enableStamp_pref
Revert "Remove the `enableStampEditor` preference" (bug 1879588)
2024-02-11 18:53:09 +01:00
calixteman
f15b4b34fd
Merge pull request #17650 from calixteman/editor_highlight_keyboard
[Editor] Add a way to highlight text in using the keyboard (bug 1877426)
2024-02-11 18:52:37 +01:00
calixteman
9980447d25
Merge pull request #17652 from calixteman/editor_disable_thickness
[Editor] Disable the thickness slider for non-free highlight
2024-02-11 18:32:36 +01:00
Tim van der Meij
336fcffd28
Extract and modernize the webserver's range file serving code
The `handler` method contained this code in an inline function, which
made the `handler` method big and harder to read. Moreover, this code
relied on variables from the outer scope, which made it harder to reason
about because the inputs and outputs weren't easily visible.

This commit fixes the problems by extracting the range file serving code
into a dedicated private method, and modernizing it to use e.g. `const`/
`let` instead of `var` and using template strings.
2024-02-11 17:04:38 +01:00
Tim van der Meij
56d9930a7b
Extract and modernize the webserver's file serving code
The `handler` method contained this code in an inline function, which
made the `handler` method big and harder to read. Moreover, this code
relied on variables from the outer scope, which made it harder to reason
about because the inputs and outputs weren't easily visible.

This commit fixes the problems by extracting the file serving code into
a dedicated private method, and modernizing it to use e.g. `const`/`let`
instead of `var` and using template strings.
2024-02-11 17:04:30 +01:00
Tim van der Meij
12b9685714
Convert the webserver to a proper class with private methods 2024-02-11 16:56:53 +01:00
Tim van der Meij
440208daa6
Merge pull request #17658 from Snuffleupagus/ESLint-more-rules
Enable the `no-new-symbol` and `require-yield` ESLint rules
2024-02-11 13:50:33 +01:00
Jonas Jenwald
8f67ea6dc6 Enable the no-new-symbol and require-yield ESLint rules
Given that we use both `Symbol`s and generator functions in the code-base enabling these rules cannot hurt (and there's no existing failures). Please find additional information at:
 - https://eslint.org/docs/latest/rules/no-new-symbol
 - https://eslint.org/docs/latest/rules/require-yield
2024-02-11 13:27:22 +01:00
Tim van der Meij
4b7382edcb
Merge pull request #17657 from Snuffleupagus/eslint-jasmine-no-dupes
Prevent duplicate names in unit/integration tests
2024-02-11 12:18:31 +01:00
Tim van der Meij
422e46dae9
Merge pull request #17655 from timvandermeij/updates
Update translations and dependencies to the most recent versions
2024-02-11 12:09:54 +01:00
Jonas Jenwald
5732faee1e Prevent duplicate names in unit/integration tests
Having identical names for different test-cases may result in less helpful output, which we can avoid with the use of the ESLint Jasmine plugin.
This patch enables the rules at the `branch` level, to limit the amount/scope of the changes slightly. (We could thus make this rule more strict in the future, if that's deemed useful.)

Please refer to:
 - https://github.com/tlvince/eslint-plugin-jasmine/blob/master/docs/rules/no-spec-dupes.md
 - https://github.com/tlvince/eslint-plugin-jasmine/blob/master/docs/rules/no-suite-dupes.md
2024-02-11 11:45:09 +01:00
Jonas Jenwald
485e9cecd7
Merge pull request #17646 from Snuffleupagus/app-break-import-cycles
Break import cycles, in the viewer, for `PDFViewerApplication`
2024-02-10 23:22:49 +01:00
Jonas Jenwald
e98b9b019a Break import cycles, in the viewer, for PDFViewerApplication
Currently the `web/app.js` file pulls in various build-specific dependencies, via the use of import maps, and those files in turn import from `web/app.js` thus creating undesirable import cycles.
To avoid this we instead pass in a `PDFViewerApplication`-reference, immediately after it's been created, to the relevant code.

Note that we use an ESLint plugin rule, see `import/no-cycle`, that is normally able to catch import cycles. However, in this case import maps are involved which is why this wasn't caught.
2024-02-10 23:15:57 +01:00
Tim van der Meij
28418598e5
Update puppeteer to version 22.0.0
This is a major version bump that requires two changes on our side:

- The new headless mode is now the default, so we can remove our
  transformation code (see https://github.com/puppeteer/puppeteer/pull/11815).
- The `page.waitForTimeout` API is removed. Sadly we still used it in
  the integration tests (but fortunately much less than before we worked
  on fixing intermittent failures), so until we remove the final
  occurrences we provide an implementation ourselves (see
  https://github.com/puppeteer/puppeteer/pull/11780).

The full changelog can be found here:
https://github.com/puppeteer/puppeteer/releases/tag/puppeteer-core-v22.0.0
2024-02-10 19:05:36 +01:00
Tim van der Meij
4feab0c1fa
Update gulp-postcss to version 10.0.0
This is a major version bump, but the breaking changes don't affect us;
please see https://github.com/postcss/gulp-postcss/releases/tag/10.0.0.
2024-02-10 19:05:28 +01:00
Tim van der Meij
29a665981a
Update eslint-plugin-unicorn to version 51.0.1
This is a major version bump, but the breaking changes don't affect us;
please see https://github.com/sindresorhus/eslint-plugin-unicorn/releases.
2024-02-10 19:04:54 +01:00
Tim van der Meij
913c2caf37
Update globals to version 14.0.0
This is a major version bump, but the breaking changes don't affect us;
please see https://github.com/sindresorhus/globals/releases/tag/v14.0.0.
2024-02-10 19:04:50 +01:00
Tim van der Meij
7da6f94ca3
Update dependencies to the most recent versions 2024-02-10 19:04:48 +01:00
Tim van der Meij
b278a74b6b
Update translations to the most recent versions 2024-02-10 19:04:46 +01:00
Calixte Denizet
b5e446213e [Editor] Disable the thickness slider for non-free highlight 2024-02-09 22:54:53 +01:00
Calixte Denizet
8fc6c5c8a6 [Editor] Add a way to highlight text in using the keyboard (bug 1877426) 2024-02-09 22:52:24 +01:00
Calixte Denizet
bcc95460b6 Revert "Remove the enableStampEditor preference" (bug 1879588)
This reverts commit e820688510e2c1c24088e76a178a82ef8ebcaf4d.
2024-02-09 18:21:21 +01:00
Jonas Jenwald
14ef0b4211 Remove empty, top-level, nodes in the Babel plugin
Looking at the *built* files you'll notice some lines containing nothing more than a semicolon. This is the result of (mostly top-level) `if`-statements, which include `PDFJSDev`-checks, that evalute to `false` during Babel parsing.

This has always annoyed me a bit, and looking at Babel plugin it seems that we can fix this simply by *removing* the relevant nodes.
2024-02-09 13:58:24 +01:00
calixteman
7cfcd00a38
Merge pull request #17645 from calixteman/update_quickjs_3f81070e573e3592728dbbbd04c84c498b20d6dc
Update quickjs to 3f81070e573e3592728dbbbd04c84c498b20d6dc
2024-02-09 13:56:21 +01:00
Calixte Denizet
275b6748b6 Update quickjs to 3f81070e573e3592728dbbbd04c84c498b20d6dc
According to:
3f81070e57
this is a new release of quickjs.
2024-02-09 11:51:24 +01:00
calixteman
964bfe522b
Merge pull request #17643 from calixteman/bug1879113
[Editor] Compute the position of the last point before applying rotation (bug 1879113)
2024-02-08 21:30:22 +01:00
Calixte Denizet
8d61fc1fde [Editor] Compute the position of the last point before applying rotation (bug 1879113) 2024-02-08 21:08:24 +01:00
Jonas Jenwald
0d5183a49f
Merge pull request #17634 from Snuffleupagus/rm-preprocessor-require
Remove support for `require` statements from the build system
2024-02-08 16:22:17 +01:00
calixteman
939134ee55
Merge pull request #17639 from calixteman/bug1879102
[Editor] Correctly rotate the mask when rotation a free highlight (bug 1879102)
2024-02-08 16:13:58 +01:00
Calixte Denizet
c4ac7eef95 [Editor] Correctly rotate the mask when rotation a free highlight (bug 1879102) 2024-02-08 15:29:29 +01:00
calixteman
d7479a59b7
Merge pull request #17638 from calixteman/bug1879107
[Editor] Set the right color to size samples in the highlight thickness panelwhen in HCM (bug 1879107)
2024-02-08 15:25:14 +01:00
Calixte Denizet
3f68a08ef3 [Editor] Set the right color to size samples in the highlight thickness panelwhen in HCM (bug 1879107) 2024-02-08 14:31:10 +01:00
Jonas Jenwald
6da9448f6c Remove the web-com import map (PR 17588 follow-up)
With the changes in PR 17588 we're already importing the relevant code via the `web/app.js` file.
2024-02-07 16:33:27 +01:00
Jonas Jenwald
898172e9d2 Re-factor PDFPrintServiceFactory to use import maps
This is very old code, which can (ever so slightly) be simplified now that import maps are available.
2024-02-07 16:33:25 +01:00
Jonas Jenwald
6a78cf0d93 Remove support for require statements from the build system
This part of the (modern) preprocessor is now dead code, since we no longer use `require` statements anywhere in the main code-base.

Note that as part of the changes leading up to PDF.js version `4` we removed all[1] the remaining `require` statements, and we also have an ESLint rule to ensure that no new ones are accidentally added.

---
[1] With two small exceptions, in benchmarking-code and in the Webpack-example.
2024-02-07 13:34:46 +01:00
calixteman
60fd9d583d
Merge pull request #17611 from calixteman/caret_browsing_mode
Implement caret browsing mode (bug 807730)
2024-02-07 10:16:52 +01:00
Calixte Denizet
81466ee039 Implement caret browsing mode (bug 807730)
The users will be able to navigate within the pdf in using the arrows
and they'll be able to select some text, for example in order to
highlight it.
2024-02-07 09:35:22 +01:00
Tim van der Meij
7d9cc49010
Merge pull request #17620 from Snuffleupagus/PDFDataTransportStream-signature
Simplify the signature of the `PDFDataTransportStream` constructor
2024-02-04 15:24:26 +01:00
Jonas Jenwald
06cd278808 Simplify the signature of the PDFDataTransportStream constructor
Given that we need to pass in a `PDFDataRangeTransport`-instance a number of the needed parameters can be obtained from it, rather than having to specify them manually.
2024-02-03 13:10:42 +01:00
Jonas Jenwald
247af2ee09
Merge pull request #17619 from Snuffleupagus/string-split-limit
Use a limit, in more places, when splitting strings
2024-02-02 15:04:12 +01:00
Jonas Jenwald
363dce6744 Use a limit, in more places, when splitting strings
This should be a *tiny* bit more efficient, since it avoids parsing substrings that we don't care about.

*Please note:* I cannot find an ESLint rule to enforce this automatically.
2024-02-02 13:10:52 +01:00
Jonas Jenwald
af4d2fa53c
Merge pull request #17610 from Snuffleupagus/createBundleFallback-dev-path
Point the *development mode* fallback locale-path to the `l10n`-folder (issue 17609, PR 17603 follow-up)
2024-02-01 14:22:19 +01:00
Jonas Jenwald
da8297115f Point the *development mode* fallback locale-path to the l10n-folder (issue 17609, PR 17603 follow-up) 2024-02-01 13:03:36 +01:00
calixteman
cbbd1fcaa3
Merge pull request #17608 from wojtekmaj/fix-annotation-layer-parameters
Make downloadManager optional in AnnotationLayerParameters
2024-02-01 12:06:27 +01:00
Wojciech Maj
f80ba44fb0
Make downloadManager optional in AnnotationLayerParameters
Continuation of fix started in #17038
2024-02-01 11:08:12 +01:00
calixteman
49bcce27c1
Merge pull request #17605 from calixteman/file_perm
Change file permissions for newly added cursors
2024-02-01 10:00:28 +01:00
Calixte Denizet
081be89f54 Change file permissions for newly added cursors 2024-02-01 09:56:59 +01:00
Jonas Jenwald
eb5c1d441a
Merge pull request #17604 from Snuffleupagus/externalServices-lazy-init
Initialize the `ExternalServices`-instance lazily in the viewer (PR 17588 follow-up)
2024-01-31 22:12:52 +01:00
Jonas Jenwald
f11dc611b3 Initialize the ExternalServices-instance lazily in the viewer (PR 17588 follow-up) 2024-01-31 20:22:57 +01:00
Jonas Jenwald
9588bceff5
Merge pull request #17603 from Snuffleupagus/GenericL10n-fallback
Ensure that `GenericL10n` works if the locale files cannot be loaded
2024-01-31 15:16:48 +01:00
Jonas Jenwald
97c2ce9da0 Ensure that GenericL10n works if the locale files cannot be loaded
- Ensure that localization works in the GENERIC viewer, even if the necessary locale files cannot be loaded.
   This was the behaviour prior to the introduction of Fluent, and it seems worthwhile to keep that (especially since we already bundle the en-US strings anyway).

 - Let the `GenericL10n`-implementation use the *bundled* en-US strings directly when no language is provided.

 - Remove the `NullL10n`-implementation, and simply fallback to `GenericL10n`, to reduce the maintenance burden of viewer-components localization.

 - Indirectly, given the previous point, stop exporting `NullL10n` in the viewer-components since it's now removed.
   Note that it was never really intended to be used directly and only existed as a fallback.

*Please note:* This doesn't affect the Firefox PDF Viewer, thanks to the use of import maps.
2024-01-31 14:07:11 +01:00
calixteman
833d7ac830
Merge pull request #17602 from calixteman/editor_free_highlight_lastpoint
[Editor] Fix the position of the free highlight toolbar
2024-01-30 20:34:47 +01:00
calixteman
245fd02141
Merge pull request #17586 from calixteman/editor_freehighlight_outline_inside
[Editor] Remove the outline which is inside the free highlight shape
2024-01-30 17:56:52 +01:00
calixteman
f7ed040aa6
Merge pull request #17598 from calixteman/update_highlight_cursors
[Editor] Update highlight cursors
2024-01-30 17:16:04 +01:00
Calixte Denizet
3064361099 [Editor] Update highlight cursors 2024-01-30 16:11:18 +01:00
Calixte Denizet
7529c1e3dc [Editor] Fix the position of the free highlight toolbar 2024-01-30 15:40:33 +01:00
Calixte Denizet
b88c6f9c39 [Editor] Remove the outline which is inside the free highlight shape
When an highlight is self-intersecting, the outline was drawn inside.
In order to remove it, we use a svg mask to exclude the shape inside
when drawing the outlines.
That leads to change the outline 1px,white-2px,blue-1px,white to a
2px,white-2px,blue: the part of the stroke which is inside the shape
is removed because of the mask.
2024-01-30 14:40:56 +01:00
Jonas Jenwald
56dabe9390
Merge pull request #17596 from nicolo-ribaudo/fix-babel-plugin
Fix transform of unary expression in Babel plugin
2024-01-29 12:57:42 +01:00
Nicolò Ribaudo
a352f28785
Fix transform of unary expression in Babel plugin
All of our static evaluation & dead-code elimination transforms need to
happen in post-order, transforming inner nodes first. This is so that
in complex nested cases all transforms see the simplified version of
their inner nodes.

For example:
  async getNimbusExperimentData() {
    if (!PDFJSDev.test("GECKOVIEW")) { return null; }
    // other code
  }
-> [evaluation of PDFJSDev.*]
  async getNimbusExperimentData() {
    if (!false) { return null; }
    // other code
  }
-> [!false -> true]
  async getNimbusExperimentData() {
    if (true) { return null; }
    // other code
  }
-> [if (true) -> replace with the if branch]
  async getNimbusExperimentData() {
    return null;
    // other code
  }
-> [early return -> remove dead code]
  async getNimbusExperimentData() {
    return null;
    // other code
  }

This was done correctly in all cases except for our `UnaryExpression`
transform, which was happening in pre-order.
2024-01-29 11:53:17 +01:00
Jonas Jenwald
802f702695
Merge pull request #17593 from Snuffleupagus/debuggerSrc-AppOptions
Move the `debuggerSrc`-parameter into the `AppOptions`
2024-01-28 18:54:15 +01:00
Jonas Jenwald
eb36fd375c Move the debuggerSrc-parameter into the AppOptions
Having this parameter among a list of DOM-elements seems slightly strange now, however this is very old code hence the explanation for why this was done is for historical reasons (as is often the case).
Hence we can simply move this into `AppOptions` instead, which seems more appropriate overall.
2024-01-28 18:47:51 +01:00
Tim van der Meij
2e2127cbb5
Merge pull request #17592 from Snuffleupagus/viewer-generate-fileInput
[GENERIC viewer] Generate the `fileInput` DOM-element dynamically
2024-01-28 18:11:21 +01:00
Jonas Jenwald
f394031c1d [GENERIC viewer] Generate the fileInput DOM-element dynamically
Given that only the GENERIC viewer supports opening more than one PDF document, we can simplify things a tiny bit by instead generating the necessary DOM-element in JavaScript.
2024-01-28 16:51:28 +01:00
Tim van der Meij
32a5bb83d4
Merge pull request #17591 from Snuffleupagus/issue-17399
Re-enable the `should compress and save text` unit-test (issue 17399)
2024-01-28 14:47:52 +01:00
Jonas Jenwald
384291234d Re-enable the should compress and save text unit-test (issue 17399)
This unit-test is now failing in up to date versions of Node.js respectively Chromium-browsers, since `CompressionStream` no longer produces consistent data across all environments/browsers.
However logging the compressed TypedArray produced by `writeStream`, with Firefox respectively Chrome, and then feeding *both* of those TypedArray as input to `DecompressionStream` produced the same (correct) result in both browsers.

Hence the *exact* output of `CompressionStream` shouldn't matter, as long as we're able to successfully decompress it when the resulting PDF document is opened with the PDF.js library, and the unit-test is thus extended to check this.
2024-01-28 14:31:07 +01:00
Tim van der Meij
ab392584f3
Merge pull request #17590 from timvandermeij/updates
Update dependencies/translations to the most recent versions
2024-01-28 12:10:20 +01:00
Tim van der Meij
94309edc9a
Disable the "should compress and save text" unit test in Chrome too
Starting with Chrome 120.0.6099.109 (shipped with Puppeteer 21.8.0+) the
unit test fails in Chrome as well. The issue is tracked in #17399, but
for now we'll only run the unit test in Firefox so we can continue to
update Puppeteer while also still having a browser in which it runs,
until we figure out why the behavior of `CompressionStream` changed.
2024-01-27 20:34:30 +01:00
Tim van der Meij
f103f277ac
Update translations to the most recent versions 2024-01-27 19:13:06 +01:00
Tim van der Meij
f855a6dae8
Update dependencies to the most recent versions 2024-01-27 19:12:59 +01:00
Tim van der Meij
a6e0b0292e
Merge pull request #17588 from Snuffleupagus/DefaultExternalServices-lighten
Re-factor `DefaultExternalServices` into a regular class, without static methods
2024-01-27 14:13:49 +01:00
Jonas Jenwald
c6594b73a7 Stub out the getNimbusExperimentData method in "regular" MOZCENTRAL builds 2024-01-27 13:12:54 +01:00
Jonas Jenwald
5dd25b6e80 Re-factor DefaultExternalServices into a regular class, without static methods
The `DefaultExternalServices` code, which is used to provide build-specific functionality, is very old. This results in a pattern where we first initialize `PDFViewerApplication.externalServices` and then *override* it for the different builds.

By converting `DefaultExternalServices` into a "regular" class, and leveraging import maps, we can directly initialize the correct instance depending on the build.
2024-01-27 12:07:15 +01:00
Jonas Jenwald
d1080e785a Remove the createPreferences method from DefaultExternalServices
Given the simplicity of the `createPreferences` method, we can leverage import maps to directly initialize the correct `Preferences`-instance depending on the build.
2024-01-27 11:38:42 +01:00
Jonas Jenwald
1698991ae2 Remove the createDownloadManager method from DefaultExternalServices
Given the simplicity of the `createDownloadManager` method, we can leverage import maps to directly initialize the correct `DownloadManager`-instance depending on the build.
2024-01-27 11:38:36 +01:00
calixteman
d8f77e6b84
Merge pull request #17582 from calixteman/editor_highlight_thickness_tooltip
[Editor] Add a tooltip to the slider to set the thickness of free highlights
2024-01-26 19:20:08 +01:00
calixteman
e63fafd0fb
Merge pull request #17581 from calixteman/editor_highlight_cursor
[Editor] Change the cursors for highlighting (bug 1876588)
2024-01-26 18:52:29 +01:00
Jonas Jenwald
3192d37aa7
Merge pull request #17587 from Snuffleupagus/fix-FontInspector-textLayer-opacity
Fix the textLayer-opacity when using the FontInspector (PR 17533 follow-up)
2024-01-26 18:37:50 +01:00
Calixte Denizet
0432d1e8e6 [Editor] Add a tooltip to the slider to set the thickness of free highlights 2024-01-26 18:34:26 +01:00
Jonas Jenwald
fed3ef1743 Fix the textLayer-opacity when using the FontInspector (PR 17533 follow-up) 2024-01-26 18:31:38 +01:00
Calixte Denizet
f3bdbedf9b [Editor] Change the cursors for highlighting (bug 1876588) 2024-01-26 18:17:05 +01:00
calixteman
4ec43488ff
Merge pull request #17580 from calixteman/freetext_icon
[Editor] Change the icon to add a FreeText annotation (bug 1876564)
2024-01-25 18:20:20 +01:00
Calixte Denizet
01280d8e08 [Editor] Change the icon to add a FreeText annotation (bug 1876564) 2024-01-25 17:18:28 +01:00
calixteman
bf92360095
Merge pull request #17574 from calixteman/improve_bezier_bbox
Reduce memory use and improve perfs when computing the bounding box of a bezier curve (bug 1875547)
2024-01-25 10:07:48 +01:00
calixteman
2f4017e22b
Merge pull request #17578 from Snuffleupagus/css-vars-unreferenced
Fix unreferenced CSS variables (PR 17533 follow-up)
2024-01-25 10:04:37 +01:00
Jonas Jenwald
1cbcb89dac Fix unreferenced CSS variables (PR 17533 follow-up)
The latest mozilla-central update has test failures, because some CSS variables are not "properly" referenced; in particular:
 - Give `--hcm-highlight-selected-filter` a default value, of `none`, similar to the previously existing HCM filter.
 - Remove the `--mix-blend-mode` variable, since it's unused.
2024-01-25 09:43:20 +01:00
Calixte Denizet
7f2428a77e Reduce memory use and improve perfs when computing the bounding box of a bezier curve (bug 1875547)
It isn't really a fix for the mentioned bug but it slightly improve things.
In reducing the memory use, the time spent in the GC is reduced either.
The algorithm to compute the bounding box is the same as before but it has just
been rewritten to be more efficient.
2024-01-24 23:41:14 +01:00
calixteman
a5d4660a75
Merge pull request #17568 from calixteman/editor_free_highlight_thickness
[Editor] Add the possibility to change the thickness of a free highlight (bug 1876096)
2024-01-24 22:37:40 +01:00
Calixte Denizet
2b8ecf5688 [Editor] Add the possibility to change the thickness of a free highlight (bug 1876096) 2024-01-24 22:04:39 +01:00
calixteman
f81f9bb7d3
Merge pull request #17564 from calixteman/editor_update_ui_undo
[Editor] Update the parameters in the UI of the last selected editor when undoing/redoing
2024-01-24 21:52:54 +01:00
Calixte Denizet
d713df28c3 [Editor] Update the parameters in the UI of the last selected editor when undoing/redoing 2024-01-24 18:16:51 +01:00
Jonas Jenwald
ae62787080
Merge pull request #17563 from nicolo-ribaudo/build-step-remove-custom-webpack
Replace the webpack+acorn transform with a Babel plugin
2024-01-23 19:00:28 +01:00
Nicolò Ribaudo
f724ae98a1
Replace the webpack+acorn transform with a Babel plugin
This commit converts the pdfjsdev-loader transform into a Babel plugin,
to skip a AST->string->AST round-trip.

Before this commit, the webpack build process was:
1. Babel parses the code
2. Babel transforms the AST
3. Babel generates the code
4. Acorn parses the code
5. pdfjsdev-loader transforms the AST
6. @javascript-obfuscator/escodegen generates the code
7. Webpack parses the file
8. Webpack concatenates the files

After this commit, it is reduced to:
1. Babel parses the code
2. Babel transforms the AST
3. babel-plugin-pdfjs-preprocessor transforms the AST
4. Babel generates the code
5. Webpack parses the file
6. Webpack concatenates the files

This change improves the build time by ~25% (tested on MacBook Air M2):
- `gulp lib`: 3.4s to 2.6s
- `gulp dist`: 36s to 29s
- `gulp generic`: 5.5s to 4.0s
- `gulp mozcentral`: 4.7s to 3.2s

The new Babel plugin doesn't support the `saveComments` option of
pdfjsdev-loader, and it just always discards comments. Even though
pdfjsdev-loader supported multiple values for that option, it was
effectively ignored due to `acorn` dropping comments by default.
2024-01-23 16:00:59 +01:00
Nicolò Ribaudo
f5bb9bc21b
Rename preprocessor2.mjs to babel-plugin-pdfjs-preprocessor.mjs
This is in preparation for the next commit, which will convert
preprocessor2.mjs to a Babel plugin. The purpose of this commit
is to help git track the rename regardless of the large amount
of changes.
2024-01-23 13:13:43 +01:00
Jonas Jenwald
8b24722113
Merge pull request #17562 from Snuffleupagus/evaluator-more-async
Add more `async` code in the `PartialEvaluator`
2024-01-23 10:35:27 +01:00
Jonas Jenwald
fa583427ef Always export the "raw" /ToUnicode-data from PartialEvaluator.preEvaluateFont (PR 13354 follow-up)
This, ever so slightly, simplifies the implementation in the `PartialEvaluator.extractDataStructures`-method.
2024-01-22 13:06:32 +01:00
Jonas Jenwald
f21a30dfb4 Convert the PartialEvaluator.readToUnicode method to be async 2024-01-22 12:47:06 +01:00
Jonas Jenwald
f5c01188dc Convert the PartialEvaluator.extractDataStructures method to be async 2024-01-22 12:47:06 +01:00
Jonas Jenwald
cf0797dfbd Use await consistently in the PartialEvaluator.setGState method 2024-01-22 12:47:06 +01:00
Jonas Jenwald
1cc83c4fdc Use await consistently in the PartialEvaluator.buildFormXObject method 2024-01-22 12:47:06 +01:00
calixteman
bba831821d
Merge pull request #17558 from calixteman/bug1669097
Print correctly documents containing chars with an unicode greater than 0xFFFF (bug 1669097)
2024-01-22 12:23:06 +01:00
Calixte Denizet
06601fd90c Print correctly documents containing chars with an unicode greater than 0xFFFF (bug 1669097) 2024-01-22 10:48:00 +01:00
Tim van der Meij
49b2d9b5af
Merge pull request #17556 from Snuffleupagus/issue-17554
Ensure that `EvaluatorPreprocessor.opMap` has a null-prototype (issue 17554)
2024-01-21 20:58:09 +01:00
Tim van der Meij
1ed68933e5
Merge pull request #17555 from timvandermeij/gulpfile-exit-code
Don't ignore `test.mjs` child process exit codes in the Gulpfile
2024-01-21 20:34:22 +01:00
Tim van der Meij
d549c2ef4c
Merge pull request #17553 from Snuffleupagus/async-handleSetFont
Add more `async` code when loading fonts in the `PartialEvaluator`
2024-01-21 20:00:29 +01:00
Jonas Jenwald
d7e41d4cb6 Ensure that EvaluatorPreprocessor.opMap has a null-prototype (issue 17554)
This accidentally regressed in PR 16956, sorry about that!
2024-01-21 19:59:13 +01:00
Tim van der Meij
6dd77b3c14
Don't ignore test.mjs child process exit codes in the Gulpfile
In the Gulpfile only the exit codes of `test.mjs` child processes
erroneously aren't checked. This causes failures in `test.mjs` to be
logged but not propagated to the master process, which in turn causes
test runners such as GitHub Actions to succeed because they only
monitor the master process. This is easy to reproduce by throwing an
error at the top of `test.mjs` and running `gulp makeref` or `gulp
unittest`: the error is logged, but the task that spawned the child
process succeeds and the master process exits with exit code 0. This is
problematic because it can easily cause errors to go by unnoticed.

This commit fixes the issue by making sure that the `test.mjs`
invocations are handled in the same way as the other child processes
in the file, i.e., if the child process exits with a non-zero exit code
then the master process also exits with a non-zero exit code. After this
patch the error is still logged, but the task now also fails and the
master process exits with exit code 1 to properly signal failure.
2024-01-21 19:37:13 +01:00
Jonas Jenwald
3c2c0ecd88 Use the ESLint arrow-body-style rule in more spots in src/core/evaluator.js 2024-01-21 17:42:33 +01:00
Jonas Jenwald
d1bef8cb86 Use await consistently in the PartialEvaluator.translateFont method 2024-01-21 17:36:50 +01:00
Jonas Jenwald
fc62eec901 Convert the handleSetFont methods, in src/core/evaluator.js, to be async 2024-01-21 17:32:05 +01:00
Jonas Jenwald
fce822cde0
Merge pull request #17550 from Snuffleupagus/arrow-fn-shorter
Use shorter arrow functions where possible
2024-01-21 17:21:32 +01:00
calixteman
10eef372ff
Merge pull request #17548 from calixteman/eslint_jasmine
Avoid to have focused tests in using eslint-plugin-jasmine
2024-01-21 16:36:41 +01:00
Jonas Jenwald
f9a384d711 Enable the arrow-body-style ESLint rule
This manually ignores some cases where the resulting auto-formatting would not, as far as I'm concerned, constitute a readability improvement or where we'd just end up with more overall indentation.

Please see https://eslint.org/docs/latest/rules/arrow-body-style
2024-01-21 16:20:55 +01:00
Jonas Jenwald
998184a00e Remove the no-confusing-arrow ESLint rule since it's deprecated
Please see https://eslint.org/docs/latest/rules/no-confusing-arrow
2024-01-21 15:45:28 +01:00
Jonas Jenwald
9dfe9c552c Use shorter arrow functions where possible
For arrow functions that are both simple and short, we can avoid using explicit `return` to shorten them even further without hurting readability.

For the `gulp mozcentral` build-target this reduces the overall size of the output by just under 1 kilo-byte (which isn't a lot but still can't hurt).
2024-01-21 10:13:12 +01:00
calixteman
6e46304357
Merge pull request #17539 from calixteman/color_picker_kb
[Editor] Don't add the keyboard listener on the color-picker each time the dropdown menu is shown
2024-01-20 22:24:37 +01:00
Calixte Denizet
99ee308f3d Avoid to have focused tests in using eslint-plugin-jasmine 2024-01-20 22:10:42 +01:00
Calixte Denizet
0cca9a0240 [Editor] Don't add the keyboard listener on the color-picker each time the dropdown menu is shown
and display/hide the dropdown menu when pressing arrow keys.
2024-01-20 21:57:54 +01:00
calixteman
f24246150e
Merge pull request #17541 from calixteman/issue17540
Use the original value of a field when propagating event (fixes #17540)
2024-01-20 21:51:37 +01:00
calixteman
03aa8a12d2
Merge pull request #17543 from calixteman/bug1869767
[Editor] Unselect highlights when the user click on the text layer (bug 1869767)
2024-01-20 21:50:19 +01:00
Tim van der Meij
626674553d
Merge pull request #17547 from timvandermeij/remove-dns-resolver-workaround
Remove DNS resolver workaround from the test framework
2024-01-20 20:23:37 +01:00
Tim van der Meij
c70edbced7
Remove DNS resolver workaround from the test framework
The `if` statement is no longer necessary because the Node.js versions
that didn't provide `dns.setDefaultResultOrder` are no longer supported,
but looking into this a bit more it turns out that the entire workaround
is no longer necessary because the issue got fixed in Firefox 105 in bug
1769994. Indeed, Firefox now starts nicely with the workaround removed.

Reverts 60ed3cd297c4045b90f4114a74e5baa4ef1c5056.
2024-01-20 20:05:08 +01:00
Tim van der Meij
c9b1a8f761
Merge pull request #17546 from Snuffleupagus/git-blame-ignore
Ignore auto-formatting patches in `git blame`
2024-01-20 14:04:55 +01:00
Tim van der Meij
9b0b099713
Merge pull request #17544 from Snuffleupagus/update-packages
Update packages and translations
2024-01-20 14:03:52 +01:00
Jonas Jenwald
c9755bdbc8 Ignore auto-formatting patches in git blame
When using Prettier to auto-format (parts of) the code-base you usually end up with *huge* patches that touch lots of lines without making any actual changes.
This often adds unnecessary steps when using `git blame`, however it's easy enough to avoid this; please refer to https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
2024-01-20 12:01:23 +01:00
Jonas Jenwald
2dd6910aa4 Update l10n files 2024-01-20 09:54:21 +01:00
Jonas Jenwald
a5a9357e15 Update npm packages 2024-01-20 09:52:57 +01:00
Calixte Denizet
5732c0c54a Use the original value of a field when propagating event (fixes #17540)
And avoid to not format a field when the value is 0.
2024-01-19 22:13:51 +01:00
Calixte Denizet
f3b76f5ae2 [Editor] Unselect highlights when the user click on the text layer (bug 1869767) 2024-01-19 20:16:55 +01:00
Jonas Jenwald
f8e3c79cb5
Merge pull request #17537 from Snuffleupagus/rm-isArrayBuffer
Remove the `isArrayBuffer` helper function
2024-01-19 15:37:02 +01:00
calixteman
f6c4b29aa2
Merge pull request #17531 from calixteman/editor_free_highlight_print_save
[Editor] Add support for printing/saving free highlight annotations
2024-01-19 15:23:29 +01:00
calixteman
5d2e7cf3fc
Merge pull request #17533 from calixteman/caret_mode
Make the caret visible in the text layer in caret browsing mode
2024-01-19 15:22:08 +01:00
Jonas Jenwald
b37536c38c Remove the isArrayBuffer helper function
This old helper function can now be replaced with `ArrayBuffer.isView()` and/or `instanceof ArrayBuffer` checks, as needed depending on the situation.
2024-01-19 14:10:52 +01:00
calixteman
a0e2b62245
Merge pull request #17534 from calixteman/bug1875357
[Editor] Change the arrow direction when the dropdown is visible in the color picker (bug 1875357)
2024-01-19 13:08:12 +01:00
Calixte Denizet
a1bf12537c [Editor] Change the arrow direction when the dropdown is visible in the color picker (bug 1875357)
and hide the dropdown when the user click outside of the color picker.
2024-01-19 13:02:11 +01:00
Calixte Denizet
d64f334f98 [Editor] Add support for printing/saving free highlight annotations 2024-01-19 12:58:46 +01:00
Calixte Denizet
83c78dbfa8 Make the caret visible in the text layer in caret browsing mode
In order to do that we must change the text layer opacity to 1 but
it has several implications:
 - the selection color must have an alpha component,
 - the background color of the span used for highlighted words
   must have an alpha component either, but now the opacity is 1
   we can use some backdrop-filters in HCM making the highlighted
   words more visible.
 - fix a regression caused by #17196: the css variable --hcm-highlight-filter
   has to live under the #viewer element because in HCM it's overwritten
   by js at this level, hence links annotations for example didn't
   have the right colors when hovered.
2024-01-18 19:44:21 +01:00
calixteman
1cdbcfef82
Merge pull request #17506 from calixteman/editor_free_highlight
[Editor] Add the ability to make a free highlight (i.e. without having to select some text) (bug 1856218)
2024-01-18 17:47:27 +01:00
Calixte Denizet
8fbfef0c07 [Editor] Add the ability to make a free highlight (i.e. without having to select some text) (bug 1856218)
The free highlighting is enabled when the mouse pointer isn't on some text.
Then we draw a shape with smoothed borders corresponding to the movement of
the mouse.
Printing/saving and changing the thickness will come later.
2024-01-18 16:26:04 +01:00
calixteman
a22b5a4f02
Merge pull request #17528 from calixteman/highlight_not_draggable
[Editor] Avoid to move a non-draggable editor with the keyboard
2024-01-16 22:27:14 +01:00
Jonas Jenwald
cb38882d74
Merge pull request #17529 from Snuffleupagus/skip-web-locale
Exclude the `web/locale/` folder from linting (PR 17525 follow-up)
2024-01-16 22:22:49 +01:00
Calixte Denizet
70a9d8f3bc [Editor] Avoid to move a non-draggable editor with the keyboard 2024-01-16 21:41:52 +01:00
calixteman
9c377922ef
Merge pull request #17527 from calixteman/color_pick_exception
[Editor] Avoid an exception when pressing space key to change the color of an highlight
2024-01-16 21:13:56 +01:00
Jonas Jenwald
79594ff876 Exclude the web/locale/ folder from linting (PR 17525 follow-up)
Given that the contents of this folder is generated by `gulp locale` it's essentially build-output and thus shouldn't be included in linting.
2024-01-16 20:25:01 +01:00
calixteman
bf6cc83e7a
Merge pull request #17525 from calixteman/prettier_json
Format json files in using prettier
2024-01-16 20:16:56 +01:00
Calixte Denizet
a76cc40ab8 [Editor] Avoid an exception when pressing space key to change the color of an highlight 2024-01-16 20:00:23 +01:00
Calixte Denizet
29de9bdce6 Format json files in using prettier 2024-01-16 19:40:25 +01:00
calixteman
e7d782e887
Merge pull request #17405 from calixteman/libertine
Add the font Linux Libertine as a possible substitution for Times New Roman
2024-01-16 14:32:30 +01:00
Calixte Denizet
10389c5017 Add the font Linux Libertine as a possible substitution for Times New Roman
and try to load the font family (guessed from the font name) before trying
the local substitution.
The local(...) command expects to have a real font name and not a predefined
substitution it's why we try the font family.
2024-01-16 12:31:23 +01:00
calixteman
51413be5b6
Merge pull request #17519 from calixteman/editor_movable_touchscreen
[Editor] Make editors draggable with touchscreens
2024-01-16 10:47:38 +01:00
Calixte Denizet
b8aab5d14e [Editor] Make editors draggable with touchscreens 2024-01-15 23:20:55 +01:00
calixteman
3110865484
Merge pull request #17517 from calixteman/editor_highlight_simplify_ser
[Editor] Slightly simplify the serialization of an highlight annotation
2024-01-15 18:50:37 +01:00
Calixte Denizet
ee72b32dc2 [Editor] Slightly simplify the serialization of an highlight annotation
We were computing width and height of the annotation before serializing
which is useless because the rect already contains this information.
2024-01-15 18:22:01 +01:00
calixteman
7769018316
Merge pull request #17514 from calixteman/issue17418
[Editor] Draw a line instead of a Bezier curve when an Ink has only one point
2024-01-15 14:23:04 +01:00
Calixte Denizet
e9946fa22a [Editor] Draw a line instead of a Bezier curve when an Ink has only one point
Fixes #17418.
2024-01-15 13:32:36 +01:00
calixteman
2ca20dea43
Merge pull request #17512 from calixteman/issue17492
Take into account empty lines when extracting text content from the appearance
2024-01-15 12:44:14 +01:00
calixteman
e98a813e09
Merge pull request #17511 from calixteman/issue17079
[Editor] Extract all the lines when adding a FreeText annotation
2024-01-15 10:40:49 +01:00
calixteman
d3b5f60995
Merge pull request #17513 from calixteman/update_l10n
Update l10n files
2024-01-15 10:18:46 +01:00
Calixte Denizet
7580770aac Update l10n files 2024-01-14 21:18:58 +01:00
Calixte Denizet
9765d57a26 [Editor] Extract all the lines when adding a FreeText annotation
Fixes #17079.
2024-01-14 21:11:51 +01:00
Calixte Denizet
405f573d70 Take into account empty lines when extracting text content from the appearance
Fixes #17492.
2024-01-14 20:23:29 +01:00
Tim van der Meij
dc92ab850a
Merge pull request #17508 from Snuffleupagus/pr-14388-followup
Consistently remove the "visibilitychange" listener in `PDFViewer` (PR 14388 follow-up)
2024-01-14 16:21:29 +01:00
Tim van der Meij
704747b143
Merge pull request #17489 from nicolo-ribaudo/gulp-cli-dep
Update `gulp-cli` to 2.3.0 and explicitly add it as a dependency
2024-01-14 16:18:26 +01:00
Tim van der Meij
07cb42243c
Merge pull request #17507 from Snuffleupagus/version-4.1
Bump library version to `4.1`
2024-01-14 16:09:18 +01:00
Tim van der Meij
ff93dfc560
Merge pull request #17490 from nicolo-ribaudo/macos-m2-note
Add note about running `npm install` on MacOS
2024-01-14 16:04:54 +01:00
Jonas Jenwald
b168f71fde Consistently remove the "visibilitychange" listener in PDFViewer (PR 14388 follow-up)
By always removing the "visibilitychange" listener in the `PDFViewer.#onePageRenderedOrForceFetch`-method we can (ever so slightly) reduce duplication in the code.
2024-01-13 10:51:26 +01:00
Jonas Jenwald
6dc225bdbb Bump library version to 4.1 2024-01-13 09:28:56 +01:00
Jonas Jenwald
56ca2fd658
Merge pull request #17504 from Snuffleupagus/GlobalWorkerOptions-validate
[api-minor] Validate the `workerPort`/`workerSrc` options
2024-01-13 09:23:29 +01:00
Jonas Jenwald
f0af52032b [api-minor] Validate the workerPort/workerSrc options
Ensure that users cannot provide incorrect values when trying to set the global worker-options.
This patch was prompted by occasionally seeing users manually loading the `pdf.worker.mjs`-file and then assigning it to the `workerSrc`-option, something that obviously doesn't make sense and will cause fake-workers to be used (with poor performance as a result).
2024-01-12 17:13:32 +01:00
calixteman
0d011472a4
Merge pull request #17501 from calixteman/editor_highlight_serialization
[Editor] Correctly serialize highlight data (regression from #17499)
2024-01-12 16:42:59 +01:00
Calixte Denizet
fc7c320bd8 [Editor] Correctly serialize highlight data (regression from #17499) 2024-01-12 15:37:01 +01:00
calixteman
61e5dae7fd
Merge pull request #17499 from calixteman/editor_outliner
[Editor] Move the code to generate the SVG path from draw_layer.js to outliner.js
2024-01-12 13:59:26 +01:00
Calixte Denizet
94ad3afab6 [Editor] Move the code to generate the SVG path from draw_layer.js to outliner.js
It'll be useful to avoid too much duplicated code when adding the free highlighting tool.
2024-01-11 19:10:33 +01:00
calixteman
35daccf34b
Merge pull request #17498 from calixteman/editor_dont_throw_highlight_color
[Editor] Don't throw when changing the color of an invisible highlight
2024-01-11 18:34:01 +01:00
Calixte Denizet
b4a7007397 [Editor] Don't throw when changing the color of an invisible highlight 2024-01-11 17:48:06 +01:00
Jonas Jenwald
12875359c3
Merge pull request #17494 from mozilla/dependabot/npm_and_yarn/follow-redirects-1.15.4
Bump follow-redirects from 1.15.3 to 1.15.4
2024-01-11 09:59:21 +01:00
dependabot[bot]
7d15d23147
Bump follow-redirects from 1.15.3 to 1.15.4
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.3 to 1.15.4.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.3...v1.15.4)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-11 04:54:43 +00:00
Nicolò Ribaudo
4197f6a284
Add note about running npm install on MacOS 2024-01-10 15:21:15 +01:00
Nicolò Ribaudo
d2a5210475
Update gulp-cli to 2.3.0 and explicitly add it as a dependency 2024-01-10 14:59:32 +01:00
calixteman
903af4ee00
Merge pull request #17487 from calixteman/fix_final_spaces
Remove terminal white spaces when extracting text from annotation appearances
2024-01-10 10:03:52 +01:00
Calixte Denizet
0392feaee4 Remove terminal white spaces when extracting text from annotation appearances 2024-01-09 10:42:53 +01:00
Tim van der Meij
29faa38dd7
Merge pull request #17482 from Snuffleupagus/update-packages
Update packages and translations
2024-01-06 14:16:56 +01:00
Jonas Jenwald
2cb93cc344 Update l10n files 2024-01-06 10:10:22 +01:00
Jonas Jenwald
c5a69544af Update npm packages 2024-01-06 10:09:12 +01:00
calixteman
6c5e237a40
Merge pull request #17481 from calixteman/editor_default_init
[Editor] Init the default highlight color before creating the first editor instance
2024-01-05 22:00:08 +01:00
Calixte Denizet
17e1519410 [Editor] Init the default highlight color before creating the first editor instance
We want to be able to draw an highlight with the default color but without having an
instance of the HighlightEditor.
2024-01-05 17:52:54 +01:00
calixteman
130a0fef3d
Merge pull request #17458 from calixteman/bug1871353
Preserve the whitespaces when getting text from FreeText annotations (bug 1871353)
2024-01-05 14:21:27 +01:00
Calixte Denizet
7839e7b495 Preserve the whitespaces when getting text from FreeText annotations (bug 1871353)
When the text of an annotation is extracted in using getTextContent, consecutive white spaces
are just replaced by one space and. So this patch add an option to make sure that white
spaces are preserved when appearance is parsed.
For the case where there's no appearance, we can have a fast path to get the correct string
from the Content entry.
When an existing FreeText is edited, space (0x20) are replaced by non-breakable (0xa0) ones
to make to see all of them on screen.
2024-01-05 10:20:32 +01:00
calixteman
1019b9f821
Merge pull request #17476 from calixteman/bug1869001
Avoid to have the text layer mismatching the rendered text with mismatching locales (bug 1869001)
2024-01-04 22:03:35 +01:00
Calixte Denizet
f84f48b5d0 Avoid to have the text layer mismatching the rendered text with mismatching locales (bug 1869001)
The system locale (used in OffscreenCanvas) can be different from the one guessed by Fluent,
consequently, in order to avoid any mismatch, we just use an attached canvas element.
The original issue can easily be reproduced locally in adding a lang="ja" in viewer.html
(or with an other language for Japanese users).
2024-01-04 19:20:20 +01:00
calixteman
7873ad98bb
Merge pull request #17477 from calixteman/puppeteer21.7.0
Update Puppeteer to version 21.7.0
2024-01-04 19:00:30 +01:00
Calixte Denizet
e5ccb70efb Update Puppeteer to version 21.7.0 2024-01-04 16:11:09 +01:00
calixteman
dc01782633
Merge pull request #17475 from calixteman/bug1872721
[Editor] Take into account the crop box when saving/printing some highlighted text (bug 1872721)
2024-01-03 13:43:31 +01:00
Calixte Denizet
35863cd54b [Editor] Take into account the crop box when saving/printing some highlighted text (bug 1872721) 2024-01-02 18:53:33 +01:00
Tim van der Meij
231c79800b
Merge pull request #17474 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2023-12-31 15:34:28 +01:00
Tim van der Meij
fea192fbf9
Bump the stable version in pdfjs.config 2023-12-31 15:31:03 +01:00
Tim van der Meij
9e14d04fd9
Merge pull request #17464 from Snuffleupagus/rm-toolbar-reset-events
Remove the internal "toolbarreset"/"secondarytoolbarreset" events and slightly re-factor the code
2023-12-29 12:47:20 +01:00
Tim van der Meij
afa65dc766
Merge pull request #17461 from mozilla/dependabot/github_actions/actions/deploy-pages-4
Bump actions/deploy-pages from 3 to 4
2023-12-29 12:27:35 +01:00
Tim van der Meij
aef9f7a0cd
Merge pull request #17460 from mozilla/dependabot/github_actions/actions/upload-artifact-4
Bump actions/upload-artifact from 3 to 4
2023-12-29 12:26:29 +01:00
Jonas Jenwald
b1ca270162 Remove the internal "secondarytoolbarreset" event and slightly re-factor the code
With modern JavaScript class features we can move the relevant event handling into private methods, and thus invoke it directly when resetting the toolbar UI-state.

*Please note:* This patch slightly reduces the size of the `web/secondary_toolbar.js` file.
2023-12-26 11:03:07 +01:00
Jonas Jenwald
234b57bb45 Remove the internal "toolbarreset" event and slightly re-factor the code
With modern JavaScript class features we can move the relevant event handling into private methods, and thus invoke it directly when resetting the toolbar UI-state.

*Please note:* This patch slightly reduces the size of the `web/toolbar.js` file.
2023-12-26 10:57:02 +01:00
dependabot[bot]
4e786f68bc
Bump actions/deploy-pages from 3 to 4
Bumps [actions/deploy-pages](https://github.com/actions/deploy-pages) from 3 to 4.
- [Release notes](https://github.com/actions/deploy-pages/releases)
- [Commits](https://github.com/actions/deploy-pages/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/deploy-pages
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-25 12:11:47 +00:00
dependabot[bot]
f56d6802ad
Bump actions/upload-artifact from 3 to 4
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-25 12:11:44 +00:00
Tim van der Meij
3b94e9fdce
Merge pull request #17456 from Snuffleupagus/update-packages
Update packages and translations
2023-12-23 13:34:32 +01:00
Jonas Jenwald
0324187734 Update l10n files 2023-12-23 12:32:00 +01:00
Jonas Jenwald
3793a56116 Update npm packages 2023-12-23 12:29:51 +01:00
Jonas Jenwald
faa24e8ce2
Merge pull request #17428 from Snuffleupagus/cacheGlobally-CopyImage
Attempt to further reduce re-parsing for globally cached images (PR 11912, 16108 follow-up)
2023-12-22 10:25:46 +01:00
Jonas Jenwald
9f02cc36d4 Attempt to further reduce re-parsing for globally cached images (PR 11912, 16108 follow-up)
In PR 11912 we started caching images that occur on multiple pages globally, which improved performance a lot in many PDF documents.
However, one slightly annoying limitation of the implementation is the need to re-parse the image once the global-caching threshold has been reached. Previously this was difficult to avoid, since large image-resources will cause cleanup to run on the main-thread after rendering has finished. In PR 16108 we started delaying this cleanup a little bit, to improve performance if a user e.g. zooms and/or rotates the document immediately after rendering completes.

Taking those two PRs together, we now have a situation where it's much more likely that the main-thread has "globally used" images cached at the page-level. Hence we can instead attempt to *copy* a locally cached image into the global object-cache on the main-thread and thus reduce unnecessary re-parsing of large/complex global images, which significantly reduces the rendering time in many cases.

For the PDF document in issue 11878, the rendering time of *the second page* changes as follows (on my computer):
 - With the `master`-branch it takes >600 ms to render.
 - With this patch that goes down to ~50 ms, which is one order of magnitude faster.

(Note that all other pages are, as expected, completely unaffected by these changes.)

This new main-thread copying is limited to "large" global images, since:
 - Re-parsing of small images, on the worker-thread, is usually fast enough to not be an issue.
 - With the delayed cleanup after rendering, it's still not guaranteed that an image is available in a page-level cache on the main-thread.
 - This forces the worker-thread to wait for the main-thread, which is a pattern that you always want to avoid unless absolutely necessary.
2023-12-21 21:26:21 +01:00
Jonas Jenwald
e547b198a3 Compute the length of the final image-bitmap/data on the worker-thread
Currently this is done in the API, but moving it into the worker-thread will simplify upcoming changes.
2023-12-21 21:26:21 +01:00
Jonas Jenwald
b09f238436 Add iteration support in the PDFObjects class
This (obviously) only includes "resolved" data, and will be used in an upcoming patch.
2023-12-21 21:26:21 +01:00
Jonas Jenwald
7ea0e40e58
Merge pull request #17441 from Snuffleupagus/outlineOptionsContainer-CSS-toggle
Toggle the visibility of the `outlineOptionsContainer`, in the sidebar, using only CSS
2023-12-20 20:27:15 +01:00
Jonas Jenwald
13da916885
Merge pull request #17445 from pulsejet/pulsejet/fix-destroy
Prevent errors in `AnnotationEditorUIManager.destroy` if the `altTextManager` is undefined
2023-12-20 20:25:36 +01:00
Varun Patil
4d34107228 Prevent error in AnnotationEditorUIManager.destroy if altTextManager is null 2023-12-20 23:18:34 +05:30
Jonas Jenwald
82464294b9 Toggle the visibility of the outlineOptionsContainer, in the sidebar, using only CSS
Now that `:has()` is available we no longer need to use JavaScript to toggle the visibility of this DOM element.
2023-12-19 10:01:16 +01:00
Jonas Jenwald
52ffd26da9
Merge pull request #17436 from mozilla/revert-17435-dependabot/github_actions/actions/upload-artifact-4
Revert "Bump actions/upload-artifact from 3 to 4"
2023-12-18 15:04:32 +01:00
Jonas Jenwald
933e107073
Revert "Bump actions/upload-artifact from 3 to 4" 2023-12-18 15:01:19 +01:00
Jonas Jenwald
6fc3b438f7
Merge pull request #17434 from mozilla/dependabot/github_actions/github/codeql-action-3
Bump github/codeql-action from 2 to 3
2023-12-18 14:54:11 +01:00
Jonas Jenwald
8d49a508f2
Merge pull request #17435 from mozilla/dependabot/github_actions/actions/upload-artifact-4
Bump actions/upload-artifact from 3 to 4
2023-12-18 14:53:52 +01:00
Jonas Jenwald
648c8f4abb
Merge pull request #17429 from jdanyow/patch-1
Center radio button checkmark
2023-12-18 14:06:36 +01:00
dependabot[bot]
25a0a68def
Bump actions/upload-artifact from 3 to 4
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-18 12:39:30 +00:00
dependabot[bot]
2e82d947a6
Bump github/codeql-action from 2 to 3
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-18 12:39:26 +00:00
Tim van der Meij
34eb6fecac
Merge pull request #17431 from timvandermeij/modernize-test
Modernize the code in the `test/downloadutils.mjs` file
2023-12-17 22:07:09 +01:00
Tim van der Meij
f9a0d4efe8
Modernize the rewriteWebArchiveUrl test helper function
This commit changes the code to use a template string and to use `const`
instead of `var`. Combined with the previous commits this allows for
enabling the ESLint `no-var` rule for this file now.
2023-12-17 21:53:50 +01:00
Tim van der Meij
0a10a7b57b
Modernize the downloadManifestFiles/ensurePDFsDownloaded test helper functions
The test helper code largely predates the introduction of modern
JavaScript features and should be refactored to improve readability.
In particular callbacks make the code harder to understand and maintain.

This commit:

- replaces the callback argument with returning a promise;
- replaces the recursive function calls with a simple loop;
- uses `const`/`let` instead of `var`;
- uses arrow functions for shorter code;
- uses template strings for shorter string formatting code.
2023-12-17 21:53:50 +01:00
Tim van der Meij
86bee4409a
Modernize the downloadFile test helper function
The test helper code largely predates the introduction of modern
JavaScript features and should be refactored to improve readability.
In particular callbacks make the code harder to understand and maintain.

This commit:

- replaces the callback argument with returning a promise;
- uses `const` instead of `var`;
- uses arrow functions for shorter code;
- uses template strings for shorter string formatting code;
- uses `Array.includes` for shorter response code checking code.
2023-12-17 21:53:50 +01:00
Jeremy Danyow
1299912744
Center radio button checkmark
fixes #12238
2023-12-16 07:28:03 -08:00
calixteman
91188cf2f8
Merge pull request #17414 from calixteman/fix_l11y_highlight
[Editor] Add some missing strings to localize for highlighting
2023-12-12 20:17:18 +01:00
Calixte Denizet
eff8b2c67b [Editor] Add some missing strings to localize for highlighting 2023-12-12 19:57:38 +01:00
Tim van der Meij
76e3e52021
Merge pull request #17415 from emielmolenaar/fix-viewer-button-closing-tag
Adds missing button closing tag
2023-12-11 22:30:53 +01:00
Tim van der Meij
27d4fff5f2
Merge pull request #17412 from mozilla/dependabot/github_actions/actions/deploy-pages-3
Bump actions/deploy-pages from 2 to 3
2023-12-11 22:24:13 +01:00
Tim van der Meij
51187dce06
Merge pull request #17411 from mozilla/dependabot/github_actions/actions/setup-python-5
Bump actions/setup-python from 4 to 5
2023-12-11 22:23:38 +01:00
Emiel Molenaar
844c4ebad3
Adds missing button closing tag 2023-12-11 17:42:43 +01:00
dependabot[bot]
b388d407a8
Bump actions/deploy-pages from 2 to 3
Bumps [actions/deploy-pages](https://github.com/actions/deploy-pages) from 2 to 3.
- [Release notes](https://github.com/actions/deploy-pages/releases)
- [Commits](https://github.com/actions/deploy-pages/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/deploy-pages
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-11 12:14:23 +00:00
dependabot[bot]
93143c03fa
Bump actions/setup-python from 4 to 5
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-11 12:14:19 +00:00
Tim van der Meij
39a1fc6992
Merge pull request #17400 from calixteman/autoprint_test
Set a print listener as soon as possible in the autoprint integration test
2023-12-09 20:12:45 +01:00
Calixte Denizet
82be74d036 Set a print listener as soon as possible in the autoprint integration test
This test intermittently fails, likely because the auto-print is triggered fast enough
that we don't manage to get it.
So this patch aims to try to set a listener very early in order to be sure that
we'll be aware that a print has been triggered.
2023-12-09 16:59:43 +01:00
Tim van der Meij
056e6393d0
Merge pull request #17398 from calixteman/test_dont_run_beforeunload
Don't run beforeunload callback when closing page in integration tests
2023-12-09 15:04:00 +01:00
Jonas Jenwald
553729869b
Merge pull request #17397 from Snuffleupagus/app-createScripting-move-options
Re-factor how the `sandboxBundleSrc` option is passed to `PDFScriptingManager`
2023-12-09 14:33:42 +01:00
Jonas Jenwald
92c15a61f1 Re-factor how the sandboxBundleSrc option is passed to PDFScriptingManager
Given that this option isn't used in the Firefox PDF Viewer, we can (ever so slightly) reduce the amount of code needed.
2023-12-09 14:29:31 +01:00
Jonas Jenwald
988d3a188f
Merge pull request #17395 from Snuffleupagus/pypdf-2332
Support Annotations with corrupt /BS-entries
2023-12-09 14:18:29 +01:00
Calixte Denizet
e25cf1ba6f Don't run beforeunload callback when closing page in integration tests
For now, running such callbacks is disabled in Firefox but there are some
plan to reenable them: https://bugzilla.mozilla.org/show_bug.cgi?id=1824220
Having them blocks us to switch to bidi with Chrome.
2023-12-09 14:15:18 +01:00
Jonas Jenwald
a1d859c082 Disable the "should compress and save text" unit-test in Node.js (PR 17202 follow-up)
It seems this unit-test now fails consistently in "all" up-to-date Node.js versions. We should probably try and understand why, but for now just disable it to get passing CI tests.
2023-12-09 14:13:11 +01:00
Tim van der Meij
d6b9e62463
Merge pull request #17391 from Snuffleupagus/AppOptions-collect-non-MOZCENTRAL
Collect a few non-MOZCENTRAL `AppOptions` default values together
2023-12-09 13:59:38 +01:00
Tim van der Meij
c908f2d55c
Merge pull request #17372 from Snuffleupagus/fuzzing-VerbosityLevel-ERRORS
Limit the amount of console "spam" during fuzz tests (PR 17337 follow-up)
2023-12-09 13:57:23 +01:00
Jonas Jenwald
63eb8991a3 Support Annotations with corrupt /BS-entries
There's obviously a few things wrong with the Annotations in the referenced PDF document, however parsing of an Annotation shouldn't just break if the /BS-entry isn't a dictionary.
2023-12-09 10:36:18 +01:00
calixteman
07aa706f1c
Merge pull request #17172 from whimboo/webdriver-bidi
Switch Puppeteer tests from CDP to WebDriver BiDi
2023-12-08 23:02:37 +01:00
Henrik Skupin
d04d28a56d
Remove unnecessary loop for closing open pages 2023-12-08 21:59:18 +01:00
Henrik Skupin
4db01746d8
Run integration tests with WebDriver BiDi instead of CDP for Firefox. 2023-12-08 20:32:50 +01:00
calixteman
15103600ea
Merge pull request #17393 from whimboo/puppeteer_21.6.0
Update Puppeteer to version 21.6.0 and force "CDP" protocol
2023-12-08 18:59:25 +01:00
Henrik Skupin
a067d38ce3
Update Puppeteer to version 21.6.0 and force "CDP" protocol 2023-12-08 12:27:44 +01:00
calixteman
d56453289c
Merge pull request #17387 from calixteman/integration_test_promises
Use page.evaluateHandle when we want to await on document promises in integration tests
2023-12-07 17:21:43 +01:00
Calixte Denizet
c63af10191 Use page.evaluateHandle when we want to await on document promises in integration tests
For reference: https://github.com/mozilla/pdf.js/pull/17378#issuecomment-1842864939
2023-12-07 17:00:12 +01:00
Jonas Jenwald
628054ee53 Collect a few non-MOZCENTRAL AppOptions default values together
Ideally we want as few build-specific branches as possible when defining the default values, to improve readability, hence this change cannot hurt.
2023-12-07 16:58:09 +01:00
calixteman
f54cfe065a
Merge pull request #17388 from calixteman/no_double_color_picker
[Editor] Avoid to have a color picker for highlighting twice in the main toolbar
2023-12-06 16:29:33 +01:00
Jonas Jenwald
a692f8681b
Merge pull request #17386 from Snuffleupagus/issue-17361
Remove focus from the toggleButton when closing the sidebar with a mouse (issue 17361)
2023-12-06 16:21:18 +01:00
Calixte Denizet
cb9c855993 [Editor] Avoid to have a color picker for highlighting twice in the main toolbar
When opening a pdf from the secondary toolbar, a second color picker is added.
So in order to avoid that, we just stop listening for annotationeditoruimanager
in the toolbar.
2023-12-06 16:10:33 +01:00
Jonas Jenwald
6b6b7867af Remove focus from the toggleButton when closing the sidebar with a mouse (issue 17361) 2023-12-06 11:11:11 +01:00
calixteman
8702e1bbb2
Merge pull request #17359 from calixteman/editor_highlight_color_picker
[Editor] Add a color picker with predefined colors for highlighting text (bug 1866434)
2023-12-06 11:06:55 +01:00
calixteman
7e64f8213d
Merge pull request #17385 from calixteman/bug1868503
Set text field value as a string when it's for a date or a time (bug 1868503)
2023-12-06 10:48:32 +01:00
calixteman
c8f6b39fc1
Merge pull request #17381 from calixteman/editor_highlight_selected
[Editor] Highlight must keep selected after the document has been scrolled
2023-12-06 10:28:39 +01:00
Calixte Denizet
098cc16c46 Set text field value as a string when it's for a date or a time (bug 1868503) 2023-12-06 09:44:30 +01:00
Calixte Denizet
ff23d37fa2 [Editor] Add a color picker with predefined colors for highlighting text (bug 1866434)
The doorhanger for highlighting has a basic color picker composed of 5 predefined colors
to set the default color to use.
These colors can be changed thanks to a preference for now but it's something which could
be changed in the Firefox settings in the future.
Each highlight has in its own toolbar a color picker to just change its color.
The different color pickers are so similar (modulo few differences in their styles) that
this patch introduces a new class ColorPicker which provides a color picker component
which could be reused in future editors.
All in all, a large part of this patch is dedicated to color picker itself and its style
and the rest is almost a matter of wiring the component.
2023-12-05 23:27:22 +01:00
Calixte Denizet
621b7af60d [Editor] Highlight must keep selected after the document has been scrolled 2023-12-05 23:22:35 +01:00
calixteman
c0436013a0
Merge pull request #17380 from calixteman/issue17379
[Editor] Don't remove elements from the draw layer after it has been destroyed
2023-12-05 23:03:12 +01:00
Calixte Denizet
f7fec8c6d7 [Editor] Don't remove elements from the draw layer after it has been destroyed
Fixes issue #17379.
2023-12-05 22:41:20 +01:00
Jonas Jenwald
319e85449e
Merge pull request #17377 from Snuffleupagus/pr-17352-follow-up
Remove the unused `--editor-toolbar-active-bg-color` CSS variable (PR 17352 follow-up)
2023-12-05 15:06:13 +01:00
calixteman
7f04ce4d22
Merge pull request #17374 from calixteman/bug1865341
[Editor] Avoid conflicts between new persistent refs and the ones created when saving (bug 1865341)
2023-12-05 14:50:15 +01:00
Jonas Jenwald
c0bc5f9013 Remove the unused --editor-toolbar-active-bg-color CSS variable (PR 17352 follow-up)
This CSS variable became unused in PR 17352 but we apparently forgot to remove it there, which causes issues when trying to update PDF.js in mozilla-central; see https://treeherder.mozilla.org/push-health/push?repo=try&revision=0701bd2c189d85cd9ff050d6d3e8336d8f36e625&tab=tests&testGroup=pr&selectedTest=browserbasecontentteststaticbrowserparsablecssjs&selectedTaskId=
2023-12-05 14:01:23 +01:00
Calixte Denizet
ae5828c968 [Editor] Avoid conflicts between new persistent refs and the ones created when saving (bug 1865341)
When a pdf as a FreeText without appearance, we use a fake font in order to render it
and that leads to create few new refs for the font.
But then when we're saving, we create some new refs which start at the same number
as the previous created ones.
Consequently, when saving we're using some wrong objects (like a font) to check if
we're able to render the newly added FreeText.
In order to fix this bug, we just remove the persistent refs (which are only used
when rendering/printing) during the saving.
2023-12-05 12:33:21 +01:00
calixteman
795c63e400
Merge pull request #17375 from calixteman/bug1867588
[Editor] Always give the focus to the ink editor when starting drawing (bug 1867588)
2023-12-05 10:54:11 +01:00
Calixte Denizet
11610a9e66 [Editor] Always give the focus to the ink editor when starting drawing (bug 1867588)
This way, when the editor is blurred, it can be committed and everything works fine.
It fixes issue #17373.
2023-12-05 10:26:59 +01:00
calixteman
a3637e653f
Merge pull request #17370 from calixteman/issue17368
[Editor] Make sure that all layers are disabled when an editing session is done
2023-12-04 16:58:41 +01:00
Jonas Jenwald
d7bec1b527 Limit the amount of console "spam" during fuzz tests (PR 17337 follow-up)
Having just tested PR 17337 locally I noticed that especially the `JpxImage`-test causes a "ridiculous" amount of warning messages to be printed, which doesn't seem helpful.
Given that only actual `Error`s should be relevant here, we can easily disable this logging during the tests.
2023-12-04 16:39:45 +01:00
Jonas Jenwald
476cb84d92
Merge pull request #17367 from timvandermeij/modernize-test
Modernize the `calculateMD5` and `verifyManifestFiles` test helper functions
2023-12-04 16:03:19 +01:00
Calixte Denizet
43eea0b38e [Editor] Make sure that all layers are disabled when an editing session is done
Fixes issue #17368.
2023-12-04 13:27:39 +01:00
Tim van der Meij
ac5667166e
Modernize the verifyManifestFiles test helper function
The test helper code largely predates the introduction of modern
JavaScript features and should be refactored to improve readability.
In particular callbacks and recursive function calls make the code
harder to understand and maintain.

This commit:

- replaces the callback argument with returning a promise;
- replaces the recursive function calls with a simple loop;
- uses `const`/`let` instead of `var`;
- uses template strings for shorter string formatting code;
- improves the error messages to have more details.
2023-12-03 20:42:50 +01:00
Tim van der Meij
c9a923066b
Modernize the calculateMD5 test helper function
The test helper code largely predates the introduction of modern
JavaScript features and should be refactored to improve readability.
In particular callbacks and recursive function calls make the code
harder to understand and maintain.

This commit:

- replaces the callback argument with returning a promise;
- uses `const` instead of `var`;
- uses arrow functions for shorter code;
- uses template strings for shorter string formatting code;
- improves the error messages to have more details.
2023-12-03 20:42:45 +01:00
Tim van der Meij
5111b6d371
Merge pull request #17337 from manunio/initial-fuzzing-support
fuzz: initial integration
2023-12-03 15:12:18 +01:00
manunio
8bb8070116 fuzz: initial integration
- Adds initial fuzz_target for image decoders.
  - Adds jazzer.js as dev-dependency.
  - Adds a .eslintrc rule to ignore import/no-unresolved error.
2023-12-03 18:52:48 +05:30
calixteman
6b3ae4492e
Merge pull request #17364 from calixteman/editor_disable_highlight
[Editor] Disable mouse events when leaving the highlight mode
2023-12-01 18:49:52 +01:00
Jonas Jenwald
a1d84f5ecf
Merge pull request #17363 from Snuffleupagus/issue-17353
[Firefox] Restore opening of PDF attachments (issue 17353, bug 1867764)
2023-12-01 18:12:52 +01:00
Calixte Denizet
83d0b6cb55 [Editor] Disable mouse events when leaving the highlight mode 2023-12-01 17:10:19 +01:00
Jonas Jenwald
4c92ec9008 [Firefox] Restore opening of PDF attachments (issue 17353)
This unfortunately broke in PR 17060, since I had completely forgotten about https://bugzilla.mozilla.org/show_bug.cgi?id=1632644#c5 when writing that patch.
The easiest solution, while slightly unfortunate, seems to be to add a couple of non-standard hash parameters specifically for the PDF attachment use-case in the Firefox PDF Viewer. (Note that we cannot use "nameddest" here, since we also need to support the stringified destination-Array case.)
2023-12-01 12:16:56 +01:00
Jonas Jenwald
096426f073
Merge pull request #17360 from Snuffleupagus/issue-17347
Remove the "transitionend" event listener from the default viewer (issue 17347)
2023-12-01 10:22:42 +01:00
Jonas Jenwald
fe3bc575de Disable the "should compress and save text" unit-test in additional Node.js versions (PR 17202 follow-up)
It seems this unit-test started failing in Node.js version 20.10 as well. We should probably try and understand why, but for now just disable it to get passing CI tests.
2023-11-30 20:47:15 +01:00
Jonas Jenwald
412502370d Remove the "transitionend" event listener from the default viewer (issue 17347)
Given that this event listener is only used to trigger rendering after the sidebar has been opened/closed, we can utilize the existing one in the `PDFSidebar` class for this purpose instead. That one is registered on the sidebar DOM-element, and is needed to remove a CSS-class indicating that the sidebar is moving.
2023-11-30 20:29:40 +01:00
calixteman
d65dca7811
Merge pull request #17358 from whimboo/mouse_click_count
Use "count" and not "clickCount" when calling page.mouse.click()
2023-11-30 10:12:37 +01:00
Henrik Skupin
9052327e07
Use "count" and not "clickCount" when calling page.mouse.click() 2023-11-30 09:40:57 +01:00
calixteman
9ac1ac6ed3
Merge pull request #17352 from calixteman/move_button_hcm
[Editor] Fix the colors in HCM when hovering a button in the editor toolbar
2023-11-29 20:21:16 +01:00
Calixte Denizet
91eda77f63 [Editor] Fix the colors in HCM when hovering a button in the editor toolbar
It fixes few errors in the CSS for HCM.
It now complies to the specs from UI/UX.
Only the foreground must change in HCM and not the background, similarly to what
we had for the alt-text button before moving it.
2023-11-29 19:53:03 +01:00
calixteman
6a35e4206e
Merge pull request #17351 from calixteman/fix_mc_test
[Editor] Fix subtype for telemetry data (follow-up of #17329)
2023-11-29 11:48:42 +01:00
Calixte Denizet
05ca005eeb [Editor] Fix subtype for telemetry data (follow-up of #17329)
Fix a test failure in m-c.
2023-11-29 11:09:22 +01:00
calixteman
59cf2ee5a9
Merge pull request #17338 from Snuffleupagus/rm-FirefoxCom-requestSync
[Firefox] Remove the `FirefoxCom.requestSync` method
2023-11-28 16:26:32 +01:00
Jonas Jenwald
b03ce96605 [Firefox] Remove the FirefoxCom.requestSync method, since it's unused
After the two previous commits, which removed the remaining call-sites, this method is no longer used and can thus be removed.
As mentioned in the JSDocs for the now removed method, synchronous communication between the viewer and the platform code isn't really a good idea.

Once this patch has landed in mozilla-central some additional clean-up of the platform code will also be possible.
2023-11-28 16:19:58 +01:00
Jonas Jenwald
9ca504e538 [Firefox] Don't send the "abortLoading" message synchronously
Despite the comment, I believe that changing this should be fine for two separate reasons:
 - The platform code has an "unload" event listener, see [this code](https://searchfox.org/mozilla-central/rev/edb2612db13e89f1c44ab95b1e4d4366c16eb9fb/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs#533-538), that invokes the same method. Hence we should still be guaranteed that the relevant platform method will run.

 - The `FirefoxComDataRangeTransport.abort` method is never actually invoked in the Firefox PDF Viewer.
   Note that the [`PDFDataRangeTransport.abort` method](f4b396f6c8/src/display/api.js (L759)) is only invoked via the [`PDFDataTransportStream.cancelAllRequests` method](f4b396f6c8/src/display/transport_stream.js (L167-L175)), which in turn is only invoked via the [`WorkerTransport.destroy` method](f4b396f6c8/src/display/api.js (L2485-L2487)). That method is invoked via the [`PDFDocumentLoadingTask.destroy` method](f4b396f6c8/src/display/api.js (L630)), which in the viewer is only invoked via the [`PDFViewerApplication.close` method](f4b396f6c8/web/app.js (L919)) which is never actually called in the Firefox PDF Viewer.

All-in-all, given the existing platform code *and* the current viewer-implementation it should thus be safe to not wait for the "abortLoading" message to complete.
2023-11-28 16:19:58 +01:00
Jonas Jenwald
ddebb0f954 [Firefox] Don't send the "initPassiveLoading" message synchronously
The return value is not, nor has it ever been, used for anything and we should thus be able to just send the message.
Note that the responses are already handled by the "message" event listener registered above.
2023-11-28 16:19:58 +01:00
calixteman
f4952399a4
Merge pull request #17329 from calixteman/move_alt_text_button
[Editor] Move the alt text button in the editor toolbar
2023-11-28 15:57:35 +01:00
Calixte Denizet
59112a7730 [Editor] Move the alt text button in the editor toolbar 2023-11-28 15:36:29 +01:00
calixteman
8e2507e0e8
Merge pull request #17317 from calixteman/editor_highlight
[Editor] Add a new editor to highlight some text in a pdf (bug 1866119)
2023-11-28 15:12:43 +01:00
Calixte Denizet
1ea6293923 [Editor] Add a new editor to highlight some text in a pdf (bug 1866119)
This patch is first big step for the new highlight feature.
Few patches will follow in order to conform to the specs UX/UI gave us.
2023-11-28 14:21:53 +01:00
calixteman
4bf7ff2027
Merge pull request #17344 from calixteman/issue17342
[Editor] Avoid to add a new ink editor when we aren't editing anymore
2023-11-27 16:53:48 +01:00
Calixte Denizet
2be136ab70 [Editor] Avoid to add a new ink editor when we aren't editing anymore 2023-11-27 16:18:31 +01:00
calixteman
b7e943bc7d
Merge pull request #17340 from calixteman/issue17332
Don't throw when there isn't enough data to get block info in flate stream
2023-11-26 19:23:25 +01:00
Calixte Denizet
52ea20eda4 Don't throw when there isn't enough data to get block info in flate stream
but just ends the stream.
2023-11-26 18:12:22 +01:00
Tim van der Meij
02a0189795
Merge pull request #17339 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2023-11-26 13:50:08 +01:00
Tim van der Meij
dd07267da6
Bump the stable version in pdfjs.config 2023-11-26 13:46:23 +01:00
Tim van der Meij
f4b396f6c8
Merge pull request #17334 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2023-11-25 19:42:40 +01:00
Tim van der Meij
ab692f805a
Update translations to the most recent versions 2023-11-25 19:34:44 +01:00
Tim van der Meij
dd7ff7e662
Update the JSDoc comments for the new TypeScript version
This commit fixes the JSDoc comment for the `annotationEditorMode` setter.
The types tests fail on that now because the input value was changed from
a number to an object with various properties in recent patches, but the
JSDoc comment was not updated accordingly.

Moreover, the types tests also fail because TypeScript 5.3 assumes that
getters and setters have equal return and input value types, which is
arguably also what one would expect, but our `annotationEditorMode`
getter and setter deviate from that because the getter returns a number
while the setter accepts an object. Given that it seems more important
to document the setter entirely, including the meaning and types of its
properties, and the type of the getter can easily be inferred from this
comment and the other JSDoc comments that have `annotationEditorMode` in
it, we remove the getter type to make the types tests pass again.
2023-11-25 19:34:44 +01:00
Tim van der Meij
8aa26fad24
Update the code style for the new Prettier version
This patch is automatically generated using `gulp lint --fix`.
2023-11-25 18:15:09 +01:00
Tim van der Meij
7381515e20
Update dependencies to the most recent versions 2023-11-25 17:25:35 +01:00
calixteman
9d863f5180
Merge pull request #17331 from calixteman/lang_marker
Remove language codes from text strings.
2023-11-25 16:43:37 +01:00
Calixte Denizet
eb5f610d18 Remove language codes from text strings.
And take care to have an even number of bytes with utf16 strings.
2023-11-25 15:09:31 +01:00
Tim van der Meij
4b1de1537f
Merge pull request #17320 from tamuratak/fix_webpack_readme
Fix examples/webpack/README.md.
2023-11-25 12:49:04 +01:00
Jonas Jenwald
3d9f68cb97
Merge pull request #17328 from Snuffleupagus/fetchData-blob
Use the `fetchData` helper function in more cases
2023-11-25 08:31:12 +01:00
calixteman
58316369e5
Merge pull request #17330 from calixteman/issue17327
[Editor] Only focus the canvas for mouse events when drawing in the canvas
2023-11-24 19:09:18 +01:00
Calixte Denizet
42147e8839 [Editor] Only focus the canvas for mouse events when drawing in the canvas
And if we've to focus it, we must prevent scrolling to avoid to draw at an
unexpected position.
2023-11-24 16:00:04 +01:00
Jonas Jenwald
fd7a7e2859 Use the fetchData helper function in more cases
- Extend the `fetchData` helper function to also support fetching of "blob" data.

 - Use the `fetchData` helper function more in the code-base, when fetching non-PDF data. Given that the Fetch API isn't supported for all protocols, this should improve compatibility for the PDF.js library.
2023-11-24 13:05:57 +01:00
calixteman
d679078beb
Merge pull request #17318 from calixteman/bug1864136_2
Make sure that only one radio button is checked in its group (bug 1864136)
2023-11-24 08:40:23 +01:00
Calixte Denizet
1f0f51613a Make sure that only one radio button is checked in its group (bug 1864136)
When the first checked radio is met, the others in the group are set to false.
2023-11-23 17:01:49 +01:00
Takashi Tamura
6e7381bc20 Fix examples/webpack/README.md. The .mjs extension is necessary. Close #17319 2023-11-23 09:25:20 +09:00
Jonas Jenwald
5781e722bf
Merge pull request #17294 from Snuffleupagus/toolbarViewerRight-reorder
Move the editor-buttons in the main toolbar
2023-11-22 14:06:24 +01:00
Jonas Jenwald
5df7c97074 Move the editor-buttons in the main toolbar
By introducing a CSS variable for the editor-toolbars we're able to handle resizing of the viewer without complicating the code too much.
2023-11-22 13:04:05 +01:00
calixteman
09ff1b98ee
Merge pull request #17304 from calixteman/editor_highlight2
[Editor] Add support for saving/printing a newly added Highlight annotation (bug 1865708)
2023-11-22 12:23:27 +01:00
Calixte Denizet
f8f4432961 [Editor] Add support for saving/printing a newly added Highlight annotation (bug 1865708) 2023-11-22 10:41:55 +01:00
Jonas Jenwald
83f0029212
Merge pull request #17287 from Snuffleupagus/CSS-loading-icon
Re-factor the loading-icons used in the viewer toolbars
2023-11-21 14:11:55 +01:00
Jonas Jenwald
625d4f794e Re-factor the loading-icons used in the viewer toolbars
Currently the SVG images for the loading-icons exist in two versions, for the light- respectively dark-theme, which nowadays are the only "duplicated" icons left.
The reason for this is that these icons are being used in `input`-elements, where the regular `mask-image` approach used for all buttons don't work.

To address this we add containers for the `input`-elements, such that we have a "regular" DOM-element where we can use `mask-image`.
2023-11-21 13:55:36 +01:00
calixteman
02ccdbb2b1
Merge pull request #17291 from calixteman/editor_highlight1
[Editor] Add a way to extract the outlines of a union of rectangles
2023-11-21 10:56:18 +01:00
Jonas Jenwald
086a5921dc
Merge pull request #17303 from Snuffleupagus/issue-17302
Throw a `JpegError` when a JPEG image has no frame data (issue 17302)
2023-11-20 18:53:35 +01:00
Calixte Denizet
31d9b9f574 [Editor] Add a way to extract the outlines of a union of rectangles
The goal is to be able to get these outlines to fill the shape corresponding
to a text selection in order to highlight some text contents.
The outlines will be used either to show selected/hovered highlights.
2023-11-20 18:45:19 +01:00
Jonas Jenwald
a6f0609a6e Throw a JpegError when a JPEG image has no frame data (issue 17302)
Given that there's nothing to parse in this case, since we're dealing with an invalid JPEG image, throwing an *explicit* Error makes sense here.
2023-11-20 17:33:49 +01:00
calixteman
d8424a43ba
Merge pull request #17300 from calixteman/issue17299
[Editor] Make the alt-text button large enough to display correctly whatever string
2023-11-20 15:45:53 +01:00
Calixte Denizet
bd6c2a192c [Editor] Make the alt-text button large enough to display correctly whatever string 2023-11-20 13:22:02 +01:00
calixteman
3459615ec3
Merge pull request #17293 from calixteman/dark
Restore the option to set light/dark mode for chromium and generic builds
2023-11-18 21:48:09 +01:00
Calixte Denizet
53101b379b Restore the option to set light/dark mode for chromium and generic builds 2023-11-18 21:32:25 +01:00
calixteman
ffbfd680ec
Merge pull request #17281 from calixteman/delete_button_tooltip
[Editor] Add a tooltip to the delete button
2023-11-15 12:59:52 +01:00
Calixte Denizet
b7d28a3bf6 [Editor] Add a tooltip to the delete button 2023-11-15 10:51:39 +01:00
Jonas Jenwald
1df648733e
Merge pull request #17277 from Snuffleupagus/L10n-fetchData
Re-factor how the `GenericL10n` class fetches localization-data
2023-11-14 16:09:05 +01:00
Jonas Jenwald
5099dc4699
Merge pull request #17273 from Snuffleupagus/L10n-lowercase-locales
Re-factor the `L10n`-implementations to use lowercase language-codes internally
2023-11-14 15:59:13 +01:00
Jonas Jenwald
709d89420e Re-factor how the GenericL10n class fetches localization-data
- Re-factor the existing `fetchData` helper function such that it can fetch more types of data, and it now supports "arraybuffer", "json", and "text".
   This only needed minor adjustments in the `DOMCMapReaderFactory` and `DOMStandardFontDataFactory` classes.[1]

 - Expose the `fetchData` helper function in the API, such that the viewer is able to access it.

 - Use the `fetchData` helper function in the `GenericL10n` class, since this should allow fetching of localization-data even if the default viewer is run in an environment without support for the Fetch API.

---
[1] While testing this I also noticed a minor inconsistency when handling standard font-data on the worker-thread.
2023-11-14 13:45:14 +01:00
Jonas Jenwald
1f9533bae9 Re-factor the L10n-implementations to use lowercase language-codes internally
This is consistent with the implementation used in the (now removed) webL10n-library, and by only using lowercase language-codes internally in the `L10n`-implementations we should avoid future issues e.g. when users manually set the `locale`-option (in the default viewer).
2023-11-13 21:06:03 +01:00
Jonas Jenwald
44cde3ccca
Merge pull request #17263 from timvandermeij/font-tests
Introduce a GitHub Actions workflow for running the font tests
2023-11-13 17:43:08 +01:00
calixteman
787d092ecb
Merge pull request #17271 from calixteman/maif
Get the field name from its parent when it doesn't have one when collecting fields (bug 1864136)
2023-11-13 15:57:42 +01:00
Calixte Denizet
09b4fe6a30 Get the field name from its parent when it doesn't have one when collecting fields (bug 1864136)
Some fields, somewhere under the Fields entry in Acroform, could have no name (in T)
but with a parent which has a name but which isn't somewhere under Fields.
As a side-effect, this patch prevents infinite loops because of potential cycles
under Fields.
2023-11-13 14:41:14 +01:00
Jonas Jenwald
096c5fe2b5
Merge pull request #17272 from Snuffleupagus/issue-17254
Fix typo in the `--hcm-highlight-filter` CSS variable name (issue 17254)
2023-11-13 11:34:02 +01:00
Jonas Jenwald
90864a5672 Fix typo in the --hcm-highlight-filter CSS variable name (issue 17254) 2023-11-13 11:18:35 +01:00
Jonas Jenwald
7b89e7e0d2
Merge pull request #17270 from Snuffleupagus/issue-17269
[GENERIC viewer] Fallback to the short-format of the language code (issue 17269)
2023-11-13 11:10:33 +01:00
Jonas Jenwald
3f7fd2f035 [GENERIC viewer] Fallback to the short-format of the language code (issue 17269)
This shouldn't cause any issues, since `GenericL10n.#createBundle` has an early return for languages that don't exist in the `locale.json` file.
2023-11-13 10:04:48 +01:00
Tim van der Meij
8157f39c62
Introduce a GitHub Actions workflow for running the font tests
This commit migrates the font tests away from the bots. Not only are the
font tests broken on the Windows bot since some time, they also run on
Python 2 (end of life since January 2020) and `ttx` 3.19.0 (released in
November 2017). The latter is installed via a submodule, which requires
more complicated logic for finding and running `ttx`.

We solve the issues by implementing a modern workflow that installs the
most recent stable Python and `ttx` (`fonttools` package) versions. This
simplifies the `ttx` driver code as well because it can now assume `ttx`
is available on the path (just like we do for e.g. `node` invocations).
GitHub Actions takes care of creating a virtual environment with
`fonttools` in it so that the `ttx`  entrypoint is available. Locally
the font tests can be run in a similar way by creating and sourcing a
virtual environment with `fonttools` in it before running the font
tests, and a README file is included with instructions for doing so.
2023-11-12 17:48:04 +01:00
Tim van der Meij
69452bb60e
Implement optionally running the tests in headless mode
This commit prepares for running the font tests on GitHub Actions where
we can't spin up headful browsers because there are no display
capabilities on the workers. This will also be useful for porting other
test targets to GitHub Actions at a later time, as well as running the
tests locally in headless mode.
2023-11-12 17:48:04 +01:00
Tim van der Meij
a1d84f8ce1
Refactor parameter passing for the startBrowser(s) functions in test.mjs
This commit prepares for the introduction of extra options in later
commits by changing the function signatures of the `startBrowser(s)`
functions to take parameter objects instead of plain parameters. This
makes the call sites explicitly state which parameters they pass,
improving overall readability as well.
2023-11-12 14:59:25 +01:00
Tim van der Meij
24fcc042f4
Refactor URL handling for the startBrowsers function in test.mjs
The current logic is more complicated than it needs to be because it's
passing a callback function to `startBrowsers` instead of a string.
This commit simplifies the logic by passing the base URL as a string to
`startBrowsers` and having it do further augmentation internally,
thereby removing all indirection of the function calls to `makeTestUrl`
and the inner function it returned.
2023-11-12 14:06:45 +01:00
Tim van der Meij
7884119975
Merge pull request #17268 from Snuffleupagus/ci-test-refactor
Clean-up the CI workflow a bit
2023-11-12 14:04:02 +01:00
Jonas Jenwald
5687326046 Clean-up the CI workflow a bit
After recent PRs the size and scope of the CI workflow is now reduced, and this patch tries to simplify things further. More specifically we can directly specify the gulp-tasks in the workflow, and thus clean-up the `gulpfile` a tiny bit.

Note that this will technically be slower, since the tests are now run in series (rather than in parallel), however `gulp externaltest` runs so quickly that it really won't matter in practice.
2023-11-12 13:48:02 +01:00
Tim van der Meij
af3147c3fe
Merge pull request #17266 from Snuffleupagus/typestest-workflow
Move `gulp typestest` to a separate GitHub Actions workflow
2023-11-12 13:32:20 +01:00
Jonas Jenwald
d89ca97887 Move gulp typestest to a separate GitHub Actions workflow
This way we introduce more parallelism in the GitHub Actions tests, which should reduce overall runtime and thus cannot hurt.
2023-11-12 13:27:29 +01:00
Tim van der Meij
e0e5be2c62
Merge pull request #17267 from Snuffleupagus/lint-workflow
Move linting to a separate GitHub Actions workflow
2023-11-12 13:08:26 +01:00
Tim van der Meij
9172d649ed
Merge pull request #17264 from calixteman/issue17262
[Editor] Avoid to click on the delete button in the freetext integration tests
2023-11-12 13:04:13 +01:00
Tim van der Meij
290b483167
Merge pull request #17255 from Snuffleupagus/issue-17228
Ensure that the viewer waits for the library to complete loading (issue 17228)
2023-11-12 13:02:34 +01:00
Tim van der Meij
2869b63800
Merge pull request #17252 from tamuratak/to_mts
Rename *.d.ts to *.d.mts
2023-11-12 13:00:44 +01:00
Tim van der Meij
37a8311b4c
Merge pull request #17265 from Snuffleupagus/createCDNWrapper-blob-type
Set a type for the `Blob` used in `createCDNWrapper` (issue 17259)
2023-11-12 12:58:21 +01:00
Jonas Jenwald
2f70369d02 Move linting to a separate GitHub Actions workflow
This way we introduce more parallelism in the GitHub Actions tests, which should reduce overall runtime and thus cannot hurt.
2023-11-12 10:21:29 +01:00
Jonas Jenwald
ade692ff2e Set a type for the Blob used in createCDNWrapper (issue 17259)
Hopefully this is enough to address the problem of initializing the Worker in Chromium-based browsers.
Locally I've tried to *force* use of `createCDNWrapper` in development mode, by commenting out the `isSameOrigin` checks, and worker-loading fails against `master` and works with this patch.
2023-11-12 09:30:26 +01:00
Takashi Tamura
61ed77cfb4 Rename *.d.ts to *.d.mts. Close #17241
Add a type test for legacy.

- https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution
2023-11-12 07:30:36 +09:00
Calixte Denizet
2d42c04543 [Editor] Avoid to click on the delete button in the freetext integration tests 2023-11-11 20:47:05 +01:00
Tim van der Meij
26fcd261fb
Merge pull request #17260 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2023-11-11 18:46:18 +01:00
Tim van der Meij
4b7a0d1841
Update translations to the most recent versions 2023-11-11 15:58:30 +01:00
Tim van der Meij
8e2c9a30d7
Update dependencies to the most recent versions 2023-11-11 15:57:28 +01:00
Jonas Jenwald
8e5311ebf7
Merge pull request #17256 from Snuffleupagus/editorParamsToolbar-color
Tweak the background-color of the `editorParamsToolbar`s
2023-11-10 23:04:30 +01:00
Jonas Jenwald
e61b832764 Tweak the background-color of the editorParamsToolbars
Currently the background-color of the `editorParamsToolbar`s don't match that of the arrow, which is especially noticable in dark mode (see zoomed-in screen-shots below).
The simplest solution seem to be to just style the `editorParamsToolbar`s like the `secondaryToolbar`, to limit the amount of CSS changes required.
2023-11-10 18:19:39 +01:00
calixteman
17213062cc
Merge pull request #17253 from calixteman/issue16839
Fix the maxp table version in font to make it visible on Windows
2023-11-10 17:57:33 +01:00
calixteman
f56215f246
Merge pull request #17243 from calixteman/editor_bin
[Editor] Add a toolbar to selected editors with a button to delete it  (bug 1863763)
2023-11-10 17:01:31 +01:00
Calixte Denizet
334f0eb060 [Editor] Add a toolbar to selected editors with a button to delete it (bug 1863763) 2023-11-10 15:19:43 +01:00
Calixte Denizet
59ce1a4a3f Fix the maxp table version in font to make it visible on Windows 2023-11-10 14:16:20 +01:00
Jonas Jenwald
823d375b8b Ensure that the viewer waits for the library to complete loading (issue 17228)
This should *hopefully* fix 17228, by tweaking the build scripts to give the GENERIC viewer something to await to avoid breaking third-party users of the standalone viewer components.
2023-11-10 13:22:49 +01:00
Jonas Jenwald
1b88aad0db
Merge pull request #17244 from Snuffleupagus/rm-openFile-button
Remove the "Open file"-button from the main toolbar
2023-11-10 10:24:30 +01:00
calixteman
f1122f048e
Merge pull request #17247 from calixteman/bug1863910
Don't avoid to execute the Blur callback when blurring a text field (bug 1863910)
2023-11-09 20:05:53 +01:00
Calixte Denizet
ec396c2150 Don't avoid to execute the Blur callback when blurring a text field (bug 1863910) 2023-11-09 13:50:33 +01:00
Jonas Jenwald
bf016743fc Remove the "Open file"-button from the main toolbar
This button is *only* used in the GENERIC viewer, and will currently be visible either in the main or secondary toolbars (depending on the viewer width).
To simplify upcoming changes, and to avoid then having to complicate the relevant CSS rules unnecessarily, let's place the "Open file"-button permanently in the secondary toolbar instead.

(Note that the GENERIC viewer also, since five years, supports drag-and-drop in order to open local files.)
2023-11-09 08:08:17 +01:00
Jonas Jenwald
42f3d57365
Merge pull request #17242 from Snuffleupagus/fieldObjects-async-fetch
Ensure that `fieldObjects` and `#collectFieldObjects` handles References correctly
2023-11-08 15:28:11 +01:00
Jonas Jenwald
ff62fc8e2c Skip fieldObjects that are not actually References
The `fieldObjects`-getter is implemented in the `PDFDocument` class, which means that the `this._localIdFactory`-property that we pass to `AnnotationFactory.create` doesn't actually exist.
The reason that this hasn't caused any bugs, that I'm aware of, is that all /Fields-entries need to be References to actually make sense.
2023-11-08 14:39:13 +01:00
Jonas Jenwald
65c827b0eb Ensure that fieldObjects and #collectFieldObjects handles References correctly
The `fieldObjects`-getter itself is called, from `src/core/worker.js`, in a way that'll ensure that any `MissingDataException`s are handled. However the problem is that the actual data-lookups in `fieldObjects` and `#collectFieldObjects` are done inside of a Promise, which means that `MissingDataException`s won't be handled and parsing could thus break.

To address this we change all data-lookups to be asynchronous instead.
2023-11-08 14:38:57 +01:00
calixteman
c6a717f900
Merge pull request #17233 from calixteman/issue17232
Don't try to collect a nonexistent field because of an invalid ref
2023-11-07 22:50:55 +01:00
Calixte Denizet
acc62f80de Don't try to collect a nonexistent field because of an invalid ref 2023-11-07 19:58:29 +01:00
Tim van der Meij
72338ce05d
Merge pull request #17226 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2023-11-05 19:01:34 +01:00
Tim van der Meij
f16401bd67
Bump the stable version in pdfjs.config 2023-11-05 18:58:09 +01:00
Jonas Jenwald
50f52b43a5
Merge pull request #17222 from Snuffleupagus/rm-viewerCssTheme
Remove the `viewerCssTheme`-option, since it's partially broken
2023-11-04 17:40:03 +01:00
Tim van der Meij
87c83ab31c
Merge pull request #17220 from Snuffleupagus/pr-17176-followup
Also pause translation when expanding the current outline-item (PR 17176 follow-up)
2023-11-04 15:29:14 +01:00
Tim van der Meij
0d574f66bc
Merge pull request #17224 from Snuffleupagus/dist-webpack
Update `external/dist/webpack.js` to account for outputting of JavaScript modules (PR 17055 follow-up)
2023-11-04 15:26:35 +01:00
Jonas Jenwald
13ca668be0 Update external/dist/webpack.js to account for outputting of JavaScript modules (PR 17055 follow-up)
Hopefully this makes sense, since I don't know enough about Webpack to tell exactly how this file is being used in practice.
2023-11-04 13:04:26 +01:00
Tim van der Meij
9eb9d3f949
Merge pull request #17218 from Snuffleupagus/app-open-API-options
Re-factor how some API-options are handled in `PDFViewerApplication.open` (PR 17208 follow-up)
2023-11-04 12:53:18 +01:00
Tim van der Meij
71a6c749d0
Merge pull request #17202 from Snuffleupagus/node-ci-latest
Also test the latest Node.js version in GitHub Actions
2023-11-04 12:45:03 +01:00
Tim van der Meij
09f45e6e52
Merge pull request #17217 from Snuffleupagus/more-optional-chaining-5
Use even more optional chaining in the code-base
2023-11-04 12:36:32 +01:00
Tim van der Meij
5e6d80ad07
Merge pull request #17223 from Snuffleupagus/update-packages
Update packages and translations
2023-11-04 12:30:22 +01:00
Jonas Jenwald
89bb0c9e66 Update l10n files 2023-11-04 09:47:38 +01:00
Jonas Jenwald
e0898a7ee3 Update npm packages
The new major version of `gulp-zip` shouldn't be a problem, given the changes listed in https://github.com/sindresorhus/gulp-zip/releases/tag/v6.0.0
2023-11-04 09:47:31 +01:00
Jonas Jenwald
d46578e959 Remove the viewerCssTheme-option, since it's partially broken
The `viewerCssTheme`-implementation has always been somewhat hacky, and now it's also *partially* broken ever since we've started using CSS nesting.
Trying to support nested media queries would thus require a lot more parsing of the CSS rules, which seems inefficient and thus generally undesirable.[1]

As discussed on Matrix, let's try to remove the `viewerCssTheme`-option and see if there's any (significant) fallout from this.

---
[1] If this option is brought back, it seems to me that it (in Firefox) should probably be set through the platform-code that handles theming.
2023-11-04 09:19:01 +01:00
Jonas Jenwald
bf7e8126df Also pause translation when expanding the current outline-item (PR 17176 follow-up)
Depending on the structure of the outline we could potentially need to expand a few levels, especially in long PDF documents, hence it cannot hurt to pause translation in that case as well.
2023-11-03 13:26:36 +01:00
Jonas Jenwald
84aaafcd3e Use a limit when splitting URL-strings in web/app.js
This should be a *tiny* bit more efficient, since it avoids parsing substrings that we don't care about.
2023-11-03 10:53:19 +01:00
Jonas Jenwald
e20dabb65b Simplify how the docBaseUrl-option is handled in PDFViewerApplication.open
Reduce the "special" handling a bit here, by setting the viewer-option such that it'll be automatically included in the API-parameters.
2023-11-03 10:52:31 +01:00
Jonas Jenwald
8bbfcd3bef Re-factor how the canvasMaxAreaInBytes-option is handled in PDFViewerApplication.open (PR 17208 follow-up)
With the changes in PR 17208, where browser-preferences are now handled as "regular" viewer-options, we can tweak the definition of `canvasMaxAreaInBytes` to slightly simplify things in the `PDFViewerApplication.open` method.
2023-11-03 10:52:27 +01:00
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
calixteman
f528f6f07b
Merge pull request #17216 from calixteman/issue17215
Render rich text with only one text element
2023-11-02 16:42:01 +01:00
Calixte Denizet
085aa4207d Render rich text with only one text element 2023-11-02 15:35:52 +01:00
Jonas Jenwald
20adb2c44d
Merge pull request #17201 from Snuffleupagus/node-ci-lts
Update the GitHub Actions workflows to use the current Node.js LTS version
2023-11-02 13:28:09 +01:00
Jonas Jenwald
6df897267f
Merge pull request #17208 from Snuffleupagus/browser-prefs-async-init
[Firefox] Fetch browser preferences/options together with the viewer preferences (bug 1862192)
2023-11-01 19:34:57 +01:00
Jonas Jenwald
ce9cfa2d72 Skip the PREFERENCE-branch in AppOptions.getAll in official builds
Given that this branch is only necessary in development mode and *during* building, but is never actually used in the final viewer-bundles, we can utilize the pre-processor to ignore this code.
2023-10-31 20:13:13 +01:00
Jonas Jenwald
eebc230cf1 [Firefox] Fetch browser preferences/options together with the viewer preferences (bug 1862192)
Currently we *synchronously* fetch a number of browser preferences/options, from the platform code, during the viewer respectively PDF document initialization paths.
This seems unnecessary, and we can re-factor the code to instead include the relevant data when fetching the regular viewer preferences.
2023-10-31 15:32:01 +01:00
calixteman
50c0fccda6
Merge pull request #17204 from calixteman/issue17167
[Editor] Don't steal the keyboard events when editing mode is enabled
2023-10-30 10:30:38 +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
Tim van der Meij
f95a2bbe29
Merge pull request #17203 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2023-10-29 15:25:57 +01:00
Tim van der Meij
447eeeba4d
Update translations to the most recent versions 2023-10-29 14:29:56 +01:00
Tim van der Meij
ecba5b7c6d
Update dependencies to the most recent versions 2023-10-29 14:22:30 +01:00
Jonas Jenwald
d00c7d5cdc Update the GitHub Actions workflows to use the current Node.js LTS version
The active LTS version is now based on Node.js version 20, hence let's update the relevant workflows to use that one instead; see https://en.wikipedia.org/wiki/Node.js#Releases

Given that we still support Node.js version 18, i.e. the maintenance LTS version, in the PDF.js library we'll keep testing both versions in GitHub Actions to prevent regressions.
2023-10-29 12:42:11 +01:00
Tim van der Meij
0329b5e130
Merge pull request #17153 from Snuffleupagus/src-navigator-checks
Guard `navigator`-object accesses in `src/`-files (issue 15728)
2023-10-29 11:59:32 +01:00
Tim van der Meij
355bce28f5
Merge pull request #17199 from timvandermeij/setup-node-4
Upgrade `setup-node` to version 4 in the GitHub Actions workflows
2023-10-29 11:44:28 +01:00
Jonas Jenwald
26fc69f241
Merge pull request #17192 from Snuffleupagus/textLayer-pause-l10n
Pause translation when appending the textLayer and structTreeLayer to the page
2023-10-29 09:31:09 +01:00
Jonas Jenwald
80612f3714
Merge pull request #17184 from Snuffleupagus/xfaLayer-append-print
Handle appending consistently in the xfaLayer regardless of rendering intent (PR 17177 follow-up)
2023-10-28 22:33:17 +02:00
Jonas Jenwald
b798415147
Merge pull request #17081 from Snuffleupagus/examples-modules
Update the `examples/`-folder to account for outputting of JavaScript modules (PR 17055 follow-up)
2023-10-28 22:08:45 +02:00
Tim van der Meij
6dff90ac1f
Upgrade setup-node to version 4 in the GitHub Actions workflows
This major version mainly involves not using Node.js 16 internally
anymore, which will be end of life on September 11th. This prevents the
workflows from using an unsupported version of Node.js as well as
deprecation warnings getting printed in the workflow logs.

For more information please refer to
https://github.com/actions/setup-node/releases/tag/v4.0.0 and
https://github.com/actions/setup-node/issues/850.
2023-10-28 21:08:02 +02:00
Tim van der Meij
973cbb000b
Merge pull request #17198 from timvandermeij/python-3.12-lint
Update the GitHub Actions workflow for the Fluent linter
2023-10-28 20:48:34 +02:00
Tim van der Meij
4845d35c50
Fix the configuration path in the GitHub Actions workflow for the Fluent linter
I noticed the following warning in the GitHub Actions workflow logs:

`Configuration file not found: .github/linter_config.yml`

The configuration file is called `fluent_linter_config.yml` instead, so
this commit fixes the path so it points to the correct file.

Fixes 487816b.
2023-10-28 20:15:25 +02:00
Tim van der Meij
9d6cdf216d
Use Python 3.12 in the GitHub Actions workflow for the Fluent linter
The current stable version of Python is Python 3.12, see
https://www.python.org/downloads, so we should switch to that since
Python 3.10 is older and only receives security updates.
2023-10-28 20:10:15 +02:00
Tim van der Meij
4be44a370e
Improve consistency in the GitHub Actions workflow for the Fluent linter
This commit tweaks the Fluent linter workflow to match the other
workflow files we have, so we make sure the steps have a newline between
them for better readability and align names and descriptions of steps
with how they are called in the other workflow files we have.
2023-10-28 20:02:39 +02:00
Jonas Jenwald
c1fef7d2f2 Guard navigator-object accesses in src/-files (issue 15728)
There are environments that include *incomplete* polyfills for the `navigator`-object, which may thus cause the PDF.js library to break.
Despite that clearly not being our fault, it may still result in bug reports filed against the PDF.js project; see e.g. 15728.

Currently this even seem to affect *the latest* version of Node.js; see e.g. [here].

*Please note:* Thanks to the pre-processor none of these changes affect the Firefox PDF Viewer, however it does add "overhead" when working with and reviewing the affected code (which is why I'm not crazy about this).
2023-10-28 14:41:46 +02:00
Tim van der Meij
238f3e728f
Merge pull request #17185 from Snuffleupagus/annotationLayer-modifier
Fix `WidgetAnnotationElement._getKeyModifier` to account for Linux
2023-10-28 14:21:19 +02:00
Jonas Jenwald
d7b39fe696 Update the webpack example to account for outputting of JavaScript modules (PR 17055 follow-up)
*Please note:* While following the steps in the README still works with this patch, in the sense that the example runs and successfully renders a PDF document, I unfortunately cannot tell if it illustrates Webpack best practices.
2023-10-28 10:26:34 +02:00
Jonas Jenwald
9ec2fda09f Simplify the l10n-handling in the mobile-viewer example
- Remove the `errorWrapper`-element, since it simplifies the example and is consistent with the default viewer; see PR 15533.

 - Simplify the l10n-handling, since the `NullL10n` should be able to translate everything e.g. without fallback values; see PR 17146.
2023-10-28 10:26:34 +02:00
Jonas Jenwald
59c4041a49 Update the examples/-folder to account for outputting of JavaScript modules (PR 17055 follow-up)
This patch also changes most examples to use "top level await", since that's now supported and slightly simplifies the code.
2023-10-28 10:26:25 +02: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
7d5b970eee Collect the forced-colors CSS rules for linkAnnotation in one spot 2023-10-27 19:29:33 +02:00
Jonas Jenwald
d30bf4482f
Merge pull request #17195 from Snuffleupagus/textLayer-css-nesting
Use CSS nesting in the textLayer
2023-10-27 19:24:15 +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
Jonas Jenwald
d293048c5d Pause translation when appending the textLayer and structTreeLayer to the page
Note that we must append the textLayer to the DOM *before* enabling the `highlighter` and `accessibilityManager`, to avoid breaking e.g. a pending searching operation.
The least invasive solution, that I was able to come up with, is to introduce a new `TextLayerBuilder` callback-function for this purpose.
2023-10-27 16:55:46 +02:00
calixteman
6115a328ea
Merge pull request #17189 from calixteman/mac_integration_test
Fix integration tests on Mac
2023-10-27 16:45:46 +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
Jonas Jenwald
34781121cd
Merge pull request #17186 from flodolo/fluent_linter
Add workflow to lint Fluent en-US files
2023-10-26 17:47:08 +02:00
Francesco Lodolo
487816bd68
Add workflow to lint Fluent en-US files 2023-10-26 17:27:42 +02:00
Jonas Jenwald
069096e78f Fix WidgetAnnotationElement._getKeyModifier to account for Linux
Currently the `WidgetAnnotationElement._getKeyModifier` method will always be falsy on Linux, which seems like a simple oversight. Looking at all the other `FeatureTest.platform` accesses we only handle the `isMac`-case specially, and it seems reasonable to do the same thing here.
The reason that this hasn't led to any bug reports is most likely that the `modifier`-property seems completely unused in the scripting-implementation.

Finally, with these changes we can (slightly) simplify the `FeatureTest.platform` implementation.
2023-10-26 13:36:42 +02:00
Jonas Jenwald
097f214222 Handle appending consistently in the xfaLayer regardless of rendering intent (PR 17177 follow-up)
After PR 17177 the interface of `XfaLayerBuilder` is now inconsistent, since whether or not we directly append the xfaLayer to the DOM now depends on the rendering intent.
2023-10-26 12:05:33 +02:00
calixteman
fbfacf8828
Merge pull request #17177 from Snuffleupagus/xfaLayer-pause-l10n
Pause translation when appending the xfaLayer to the page
2023-10-25 21:46:49 +02:00
Jonas Jenwald
399f444c84 Pause translation when appending the xfaLayer to the page 2023-10-25 20:33:39 +02:00
calixteman
b31e77df17
Merge pull request #17166 from calixteman/improve_oc_parsing
Improve performance of optional content parsing
2023-10-25 18:28:38 +02:00
Jonas Jenwald
806ac67ea4
Merge pull request #17176 from Snuffleupagus/BaseTreeViewer-pause-l10n
Pause translation when appending the outline/attachment/layer trees to the sidebar
2023-10-25 17:51:39 +02:00
Calixte Denizet
0c38c6e103 Improve performance of optional content parsing 2023-10-25 17:50:53 +02:00
Jonas Jenwald
6b265b3a15 Pause translation when appending the outline/attachment/layer trees to the sidebar
Also, pause translation when collapsing/expanding subtrees.
2023-10-25 17:38:02 +02:00
Jonas Jenwald
0fc899338c
Merge pull request #17006 from Snuffleupagus/rm-enableStampEditor-pref
Remove the `enableStampEditor` preference
2023-10-25 16:24:49 +02:00
calixteman
f27f2bb403
Merge pull request #17165 from calixteman/improve_removenullchars
Slightly improve the performance of removeNullCharacters
2023-10-25 15:01:32 +02:00
Jonas Jenwald
5d3823a81a
Merge pull request #17173 from Snuffleupagus/ConstL10n-setL10n
Fix error that's breaking the `ConstL10n` class (PR 17161 follow-up)
2023-10-25 14:51:33 +02:00
calixteman
31243230af
Merge pull request #17174 from calixteman/update_import_l10n
Update the path to get all locales and update locales
2023-10-25 14:40:22 +02:00
calixteman
3ba68f68dc
Merge pull request #17171 from calixteman/issue17169
Don't take into account the INVISIBLE flag for well-known annotations
2023-10-25 14:00:12 +02:00
Jonas Jenwald
bd9b39be28
Merge pull request #17175 from Snuffleupagus/rm-lint-ignores
Remove obsolete entries in the lint-ignore files
2023-10-25 13:46:13 +02:00
Jonas Jenwald
b575de9860 Remove obsolete entries in the lint-ignore files
- The `external/webL10n/` directory was removed in PR 17115.

 - The `src/shared/{cffStandardStrings, fonts_utils}.js` files were removed in PR 17120.
2023-10-25 13:38:51 +02:00
Calixte Denizet
2967eca605 Update the path to get all locales and update locales 2023-10-25 12:47:06 +02:00
Jonas Jenwald
846bd86520 Fix error that's breaking the ConstL10n class (PR 17161 follow-up)
I forgot to include `web/l10n_utils.js` in PR 17161, which currently breaks `ConstL10n` since there's no longer a method called `setL10n`; sorry about that!
2023-10-25 12:11:57 +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
Calixte Denizet
651057c039 Slightly improve the performance of removeNullCharacters
Most of the strings shouldn't contain special chars (<= 0x1F) so we can
have a fast path which just checks if the string contains at least one such
a char.
2023-10-25 10:11: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
calixteman
3f2072eaee
Merge pull request #17159 from calixteman/bug1860602
[Annotation] Use the field V entry when there is no Parent one for a radio button (bug 1860602)
2023-10-24 16:50:18 +02:00
Jonas Jenwald
bcb01e5e2b Tweak the matchCount l10n-args handling slightly (PR 17146 follow-up)
Given that providing unused parameters in the l10n-args shouldn't be a problem, let's simplify the relevant JavaScript code a tiny bit.
2023-10-24 13:17:02 +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
calixteman
377af6892b
Merge pull request #17157 from calixteman/auto_update_locale
Update locale on *.ftl change
2023-10-23 14:36:30 +02:00
Jonas Jenwald
cc18d9749a
Merge pull request #17156 from Snuffleupagus/landmark-pageLabel
Update the "aria-label" of the page when a `pageLabel` exists
2023-10-23 14:33:13 +02:00
Calixte Denizet
31cfec63c3 Update locale on *.ftl change 2023-10-23 14:03:31 +02:00
Jonas Jenwald
04696080f8 Update the "aria-label" of the page when a pageLabel exists
Looking at the `PDFThumbnailView.setPageLabel` method you'll see that we update e.g. the "aria-label" of the thumbnail-image for documents that contain (valid) pageLabels.
This isn't done in `PDFPageView`, which seems inconsistent, hence this patch.
2023-10-23 13:42:06 +02:00
Jonas Jenwald
8376b3fb05
Merge pull request #17141 from Snuffleupagus/l10n-more-setAttribute
[api-minor] Use "data-l10n-id"/"data-l10n-args", rather than manually updating DOM-elements, to trigger translation (PR 17146 follow-up)
2023-10-23 12:58:59 +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
Tim van der Meij
898cc2e399
Merge pull request #17151 from Snuffleupagus/Fluent-PDFDocumentProperties-fixes
A couple of `PDFDocumentProperties` tweaks (PR 17115 follow-up)
2023-10-22 12:33:34 +02:00
Jonas Jenwald
da186d1b89
Merge pull request #17146 from Snuffleupagus/NullL10n-refactor
[api-minor] Re-factor `NullL10n` and remove the hard-coded l10n strings (PR 17115 follow-up)
2023-10-21 17:53:30 +02:00
Jonas Jenwald
4c4676e5a4
Merge pull request #17152 from Snuffleupagus/findbar-resizeObserver
Use a `ResizeObserver` to update the layout of `PDFFindBar`
2023-10-21 17:46:30 +02:00
Jonas Jenwald
e20ef39f59 Use a ResizeObserver to update the layout of PDFFindBar
*Please note:* In the Firefox PDF Viewer this findbar is only used for PDF documents placed in e.g. `<iframe>` elements.

By registering a `ResizeObserver` when the `PDFFindBar` is open we slightly unify and simplify how the findbar layout (row vs column) is handled.
This will be especially helpful with upcoming changes, where we'll make use of "data-l10n-id"/"data-l10n-args" to trigger translation in the viewer.
2023-10-21 16:17:49 +02:00
Jonas Jenwald
7df082fce3 A couple of PDFDocumentProperties tweaks (PR 17115 follow-up)
- The old translation engine handled language code casing slightly differently, hence we need to tweak the non-metric locale check in `PDFDocumentProperties` to account for that.

 - Use only lowercase names for the pre-defined page names, to improve overall consistency.
2023-10-21 10:27: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
5f0e560949
Merge pull request #17140 from Snuffleupagus/l10n-move-init
Initialize the `L10n`-instance as soon as possible in Firefox (PR 17115 follow-up)
2023-10-19 20:13:33 +02:00
Jonas Jenwald
5c14c559dd Initialize the L10n-instance as soon as possible in Firefox (PR 17115 follow-up)
Given that there's now a bit more asynchronicity in the l10n-initialization in the Firefox PDF Viewer, after PR 17115, try to limit the impact of that by moving it to occur a tiny bit earlier in the default viewer initialization.
2023-10-19 18:40:52 +02:00
calixteman
d094e8aab0
Merge pull request #17142 from calixteman/no_connect_root
[L10n] Don't try to connect the root element when it has already been done
2023-10-19 18:29:25 +02:00
Calixte Denizet
a0b9c937ae [L10n] Don't try to connect the root element when it has already been done
In Firefox debug builds, there is an assertion to check that we don't connect
a subelement of an already connected root. Thanks to this assertion, we can see
that the root has already been added to Fluent, hence we don't need to do it
a second time.
We don't need to await anymore on the translation in order to update the
toolbar: it'll be done by Fluent, so we can safely remove the "localized"
event and avoid to wait for it.
2023-10-19 18:19:05 +02:00
Jonas Jenwald
e820688510 Remove the enableStampEditor preference 2023-10-19 15:45:07 +02:00
Jonas Jenwald
c60401a765
Merge pull request #17133 from Snuffleupagus/rm-builder-merge
Use object destructuring, rather than the `merge` helper, in the gulpfile
2023-10-19 15:41:40 +02:00
Jonas Jenwald
d6cfbd2839
Merge pull request #17130 from Snuffleupagus/AppOption-move-init
Try to make the `Preferences`/`AppOptions` initialization slightly more efficient
2023-10-19 15:12:30 +02:00
Jonas Jenwald
5ddc949159 Try to make the Preferences/AppOptions initialization slightly more efficient
*Please note:* This patch contains a couple of micro-optimizations, hence I understand if it's deemed unnecessary.

Move the `AppOptions` initialization into the `Preferences` constructor, since that allows us to remove a couple of function calls, a bit of asynchronicity and one loop that's currently happening in the early stages of the default viewer initialization.

Finally, move the `Preferences` initialization to occur a *tiny* bit earlier since that cannot hurt given that the entire viewer initialization depends on it being available.
2023-10-19 14:44:55 +02:00
Jonas Jenwald
929311fb9d
Merge pull request #17135 from Snuffleupagus/bug-1859818
Only bundle `NullL10n` in GENERIC builds (bug 1859818)
2023-10-19 14:35:01 +02:00
Jonas Jenwald
69ad0d9861 Only bundle NullL10n in GENERIC builds (bug 1859818) 2023-10-19 13:51:00 +02:00
Jonas Jenwald
f39bedd06c
Merge pull request #17138 from Snuffleupagus/issue-17137
Use a CSS-only solution to set the `dropdownToolbarButton` width (issue 17137)
2023-10-19 13:49:05 +02:00
Jonas Jenwald
482b789edf Use a CSS-only solution to set the dropdownToolbarButton width (issue 17137)
Note that CSS-features such as e.g. `flex` didn't exist, or had poor cross-browser support, back when the JavaScript-based solution was initially implemented.
2023-10-19 13:44:02 +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
Jonas Jenwald
6a6f6f122c
Merge pull request #17131 from Snuffleupagus/openOrDownloadData-caching
Re-factor the blob-URL caching in `DownloadManager.openOrDownloadData`
2023-10-19 11:25:47 +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
2a3090224f
Merge pull request #17134 from Snuffleupagus/writeStream-less-type-conversion
Reduce unnecessary type conversion in `writeStream`
2023-10-18 16:55:04 +02:00
Jonas Jenwald
25a1a9d28f Reduce unnecessary type conversion in writeStream
Currently we're unnecessarily converting data between strings and typed-arrays, when dealing with compressible data, in the `writeStream` function.
Note how we're *first* getting a string-representation of the stream, which involves converting the underlying typed-array into a string, only to immediately convert this back into a typed-array. This seems completely unnecessary, and is easy enough to avoid, and we'll now only do a *single* type-conversion in this function.
2023-10-18 15:39:01 +02:00
Jonas Jenwald
ae664ea8e0 Use object destructuring, rather than the merge helper, in the gulpfile
This helper function was originally added in PR 1953, eleven years ago, at which point object destructuring didn't exist.
2023-10-18 13:49:26 +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
22d6d95f03
Merge pull request #17125 from timvandermeij/find-intermittent
Fix intermittent problems on Windows in the XFA search integration test
2023-10-15 18:32:17 +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
93f24dd5d7 Remove the ESLint "amd" environment (PR 17055 follow-up)
Please see https://eslint.org/docs/latest/use/configure/language-options#specifying-environments
2023-10-15 11:50:57 +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
76bf3da4b1
Merge pull request #17122 from timvandermeij/autoprint
Remove Escape key press from the `autoprint` integration test, and tweak the protocol timeout configuration for Puppeteer
2023-10-15 11:29:11 +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
Tim van der Meij
5c45dfa0ae
Merge pull request #17119 from timvandermeij/updates
Update translations/dependencies to the most recent versions and fix dependency vulnerabilities
2023-10-14 14:36:25 +02:00
Tim van der Meij
d53e166538
Merge pull request #17120 from timvandermeij/code-scanning-alerts
Remove obsolete `src/shared/{cffStandardStrings,fonts_utils}.js` files
2023-10-14 14:26:35 +02:00
Tim van der Meij
58e4fcdc6f
Remove obsolete src/shared/{cffStandardStrings,fonts_utils}.js files
Those files only contain old debugging code that is not used/imported
anywhere anymore, which is generating code scanning alerts. Moreover,
they rely on globals/platform-specific code and don't import/export
logic properly.
2023-10-14 14:07:49 +02:00
Tim van der Meij
4c17f99fab
Fix dependency vulnerabilities with npm audit fix 2023-10-14 13:50:24 +02:00
Tim van der Meij
e1307fdba8
Update dependencies to the most recent versions 2023-10-14 13:50:19 +02:00
Tim van der Meij
e79bb25086
Update translations to the most recent versions 2023-10-14 13:50:12 +02:00
Tim van der Meij
23b8dbb730
Merge pull request #17117 from Snuffleupagus/eslint-import-no-commonjs
Enable the `import/no-commonjs` ESLint plugin rule
2023-10-14 13:11:37 +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
Tim van der Meij
57866cd31b
Merge pull request #14743 from Snuffleupagus/native-import-maps
Use native `import maps` in development mode
2023-10-14 12:07:39 +02:00
Tim van der Meij
7dfe08a0ee
Merge pull request #17098 from Snuffleupagus/createCDNWrapper-import
Tweak `PDFWorkerUtil.createCDNWrapper` to account for JavaScript modules (PR 17055 follow-up)
2023-10-14 12:05:46 +02:00
Jonas Jenwald
af9a7b0003 Tweak PDFWorkerUtil.createCDNWrapper to account for JavaScript modules (PR 17055 follow-up) 2023-10-14 11:34:40 +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
36c3c0a4c1
Merge pull request #17114 from Snuffleupagus/lib-modules
Output JavaScript modules for the `LIB` build-target (PR 17055 follow-up)
2023-10-13 20:33:35 +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
96258449e3
Merge pull request #17112 from Snuffleupagus/integration-test-modules
Convert the `integration` test-files to JavaScript modules
2023-10-13 18:53:52 +02:00
calixteman
4ac44b9d6d
Merge pull request #17113 from calixteman/bug1858700
Remove useless chrome.properties file (bug 1858700)
2023-10-12 17:19:57 +02:00
Calixte Denizet
cabda362c6 Remove useless chrome.properties file (bug 1858700) 2023-10-12 16:32:44 +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
Jonas Jenwald
158ab5bf37
Merge pull request #17106 from Snuffleupagus/bug-1854145
Don't store page-level data, in the API, after cleanup has run (bug 1854145)
2023-10-12 10:47:23 +02:00
Jonas Jenwald
0238cf134d Don't store page-level data, in the API, after cleanup has run (bug 1854145)
For large/complex images it's possible that the image-data arrives in the API *after* the page has been scrolled out-of-view and thus been cleaned-up. In this case we obviously shouldn't cache such page-level data, since it'll first of all be unused and secondly can increase memory usage *a lot*.
Also, ensure that we *immediately* release any `ImageBitmap` data in this case to help reclaim memory faster.
2023-10-11 11:51:42 +02:00
Jonas Jenwald
2c39a739f5
Merge pull request #17105 from Snuffleupagus/interactive-examples-update
Update the "Interactive examples" links (PR 17055 follow-up)
2023-10-10 09:53:14 +02:00
Jonas Jenwald
734caab747 Update the "Interactive examples" links (PR 17055 follow-up)
The examples themselves were updated to account for JavaScript modules, which didn't require changing the actual URLs.
However, since it seems that JSFiddle doesn't support JavaScript modules in its separate "JavaScript" editing-area we need to change how we embed the examples to avoid showing a blank "JavaScript"-tab.
2023-10-10 09:41:01 +02:00
calixteman
2c87c4854a
Merge pull request #17073 from calixteman/debug_subst_font
[Debugger] Add some info about substitution font
2023-10-09 14:34:58 +02:00
Calixte Denizet
7851c0da8d [Debugger] Add some info about substitution font
When pdfBug is true, the substitution font is used in the text layer in order
to be able to know what is the font really used thanks to the devtools.
And to be sure that fonts are loaded, the font cache isn't cleaned up when
the debugger is active.
2023-10-09 12:06:33 +02:00
Jonas Jenwald
b4cd8ad215
Merge pull request #17095 from timvandermeij/protocol-timeout
Fix the protocol timeout configuration for Puppeteer
2023-10-09 09:43:51 +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
Jonas Jenwald
d64f223d03
Merge pull request #17094 from Snuffleupagus/debugger-module
Rename `web/debugger.js` since it's actually a JavaScript module (PR 17055 follow-up)
2023-10-08 13:56:37 +02:00
Jonas Jenwald
6ac3da0d1f Rename web/debugger.js since it's actually a JavaScript module (PR 17055 follow-up)
It's been loaded as a JavaScript module for a long time, and given that the file is bundled as-is (without building) it seems reasonable to just change the file extension now.
2023-10-08 13:16:42 +02:00
Jonas Jenwald
f04967017f
Merge pull request #17093 from mozilla/dependabot/npm_and_yarn/postcss-8.4.31
Bump postcss from 8.4.30 to 8.4.31
2023-10-08 10:08:49 +02:00
dependabot[bot]
67b5c69d15
Bump postcss from 8.4.30 to 8.4.31
Bumps [postcss](https://github.com/postcss/postcss) from 8.4.30 to 8.4.31.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.4.30...8.4.31)

---
updated-dependencies:
- dependency-name: postcss
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-08 04:06:58 +00:00
Tim van der Meij
60a458de29
Merge pull request #17090 from timvandermeij/autoprint-intermittent
Activate the selector check for the `autoprint` integration test as soon as possible
2023-10-07 20:34:16 +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
f2c9b64cb2
Merge pull request #17086 from Snuffleupagus/rm-structuredClone-polyfill
[api-minor] Stop polyfilling `structuredClone` in legacy builds
2023-10-07 18:26:28 +02:00
Jonas Jenwald
8bd3cc0313 [api-minor] Stop polyfilling structuredClone in legacy builds
Comparing the currently supported browsers/environments, see [the FAQ](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support) and the [MDN compatibility data](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone#browser_compatibility), the `structuredClone` polyfill is *only* needed in Google Chrome versions < 98. Because of some limitations in the core-js polyfill we're currently forced to special-case the `transfer` handling to prevent bugs, and it'd be nice to avoid that.

Note that `structuredClone`, with transfers, is only used in two spots:
 - The `LoopbackPort` class, which is only used with fake workers. Given that fake workers should *never* be used in browsers, breaking that edge-case in older Google Chrome versions seem fine.
 - The `AnnotationStorage` class, when Stamp-annotations have been added to the document. Given that Google Chrome isn't the main focus of development, breaking *part* of the editing-functionality in older Google Chrome versions should hopefully be acceptable.
2023-10-07 16:52:47 +02:00
Jonas Jenwald
e6c3257175
Merge pull request #17080 from Snuffleupagus/scripting-module
Output `pdf.scripting.js` as a JavaScript module (PR 17055 follow-up)
2023-10-07 16:09:39 +02:00
Jonas Jenwald
4b489cd4e6 Output pdf.scripting.js as a JavaScript module (PR 17055 follow-up)
To avoid problems with `export` statements in the QuickJS Javascript Engine, we can work-around that by *explicitly* exposing `pdfjsScripting` globally instead.
2023-10-07 15:27:26 +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
Jonas Jenwald
0a970ee443 [api-major] Remove the fallbackWorkerSrc functionality in browsers
The user should *always* provide a correct `GlobalWorkerOptions.workerSrc` value when using the PDF.js library in browser environments. Note that the fallback:
 - Has been deprecated ever since PR 11418, first released in version `2.4.456` over three years ago.
 - Was always a best-effort solution, with no guarantees that it'd actually work correctly.
 - With upcoming changes, w.r.t. outputting JavaScript modules, it'd now be more diffiult to determine the correct value.
2023-10-06 12:12:30 +02:00
Jonas Jenwald
8158628a90 [api-minor] Stop building a minified default viewer
The minified default viewer has never been distributed in either official releases or through pdfjs-dist, which means that it's most likely unused, and it's has never been tested nor actively maintained.
2023-10-06 12:12:30 +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
calixteman
2453b79fa8
Merge pull request #17074 from calixteman/issue17071
Make the toolbar buttons usable with keyboard when Page Fit is used
2023-10-05 20:28:56 +02:00
Jonas Jenwald
3747c02d4c
Merge pull request #17076 from Snuffleupagus/stylelint-color-rules
Enable some Stylelint color-related rules to slightly reduce file sizes
2023-10-05 19:18:35 +02:00
Calixte Denizet
3263fd0307 Make the toolbar buttons usable with keyboard when Page Fit is used 2023-10-05 18:33:03 +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
calixteman
a60f90ae94
Merge pull request #17075 from calixteman/issue17069_followup
Add a HTML containter for locked FreeText annotations in order to be able to display a popup (follow-up of #17070)
2023-10-05 15:17:58 +02:00
Calixte Denizet
e737638a40 Add a HTML containter for locked FreeText annotations in order to be able to display a popup (follow-up iof #17070) 2023-10-05 14:01:34 +02:00
calixteman
c4c24c6d18
Merge pull request #17070 from calixteman/17069
Update the noHTML flag to take into account the hasOwnCanvas one (fixes #17069)
2023-10-05 11:10:40 +02:00
calixteman
66c3b239ae
Merge pull request #17072 from calixteman/resizer_role
[Editor] Add role=spinbutton to resizers when they're used with the keyboard
2023-10-04 23:13:44 +02:00
Calixte Denizet
335cea22b3 [Editor] Add role=spinbutton to resizers when they're used with the keyboard 2023-10-04 21:30:06 +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
c377f2d488
Merge pull request #17060 from Snuffleupagus/issue-17056
Add support for "GoToE" actions with destinations (issue 17056)
2023-10-04 11:36:42 +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
Jonas Jenwald
da4fdc76a3
Merge pull request #17063 from Snuffleupagus/version-4
Bump library version to `4.0`
2023-10-04 11:10:27 +02:00
calixteman
0e6d0ca7b6
Merge pull request #17067 from calixteman/issue17065
Compute correctly the bounding box of a transformed rectangle (fixes #17065)
2023-10-03 23:58:11 +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
4245d87de5
Merge pull request #17066 from Snuffleupagus/issue-17064
Ensure that readonly TextWidget-annotations are rendered when forms are disabled (issue 17064)
2023-10-03 23:13:41 +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
9cca13bb03 Bump library version to 4.0 2023-10-03 15:57:54 +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
Jonas Jenwald
0edc490e1b
Merge pull request #16774 from Snuffleupagus/rm-deprecated-options
[api-major] Remove various deprecated functionality and options
2023-10-03 15:12:39 +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
calixteman
0986e40842
Merge pull request #17058 from calixteman/alt_text_canvas
[Editor] Use the alt text to descibe the canvas used to display the image
2023-10-03 11:01:11 +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
calixteman
59d94b549f
Merge pull request #17032 from calixteman/alt_text_rm_button
[Editor] Don't show the alt-text button when the alt-text dialog is visible
2023-10-02 22:19:18 +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
Tim van der Meij
be53c7d6f5
Merge pull request #17053 from calixteman/issue17044
Add alt-text svg images to the dist (issue #17044)
2023-10-01 18:11:24 +02:00
Calixte Denizet
0d9aef1a5e Add alt-text svg images to the dist (issue #17044) 2023-10-01 16:47:34 +02:00
Tim van der Meij
71bffcc7a9
Merge pull request #17052 from Snuffleupagus/web-pdfjsLib-export
Use a standard `export` statement in the `web/pdfjs.js` file
2023-10-01 12:09:36 +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
calixteman
12ca22ba44
Merge pull request #17048 from calixteman/fix_ink_tests
Remove the timeouts from the inkEditor integration tests
2023-09-29 16:30:07 +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
calixteman
46940a5a52
Merge pull request #17036 from calixteman/fix_test_freetext
[Editor] Remove almost all the waitForTimeout from the freetext integration tests
2023-09-29 11:41:53 +02:00
Calixte Denizet
55e5af2d01 [Editor] Remove almost all the waitForTimeout from the freetext integration tests 2023-09-29 11:14:21 +02:00
Jonas Jenwald
52862893f5
Merge pull request #17026 from Snuffleupagus/layerProperties-Object
Convert `layerProperties` to an Object (PR 15811 follow-up)
2023-09-28 18:44:32 +02:00
Jonas Jenwald
46d8d36721
Merge pull request #17027 from Snuffleupagus/update-Puppeteer
Update Puppeteer to the latest version
2023-09-28 18:43:52 +02:00
calixteman
b6d75e736a
Merge pull request #17038 from ayushmourya/master
Make downloadManager optional in JSDoc types
2023-09-28 17:23:33 +02:00
Jonas Jenwald
790b480bbc Update Puppeteer to the latest version
This also required updating the `postinstall`-step to account for recent changes in Puppeteer.
2023-09-28 17:21:07 +02:00
Jonas Jenwald
03ce3b2d54 Convert layerProperties to an Object (PR 15811 follow-up)
Given that this is accessed multiple times per page in the viewer, that leads to a number of (strictly speaking unneeded) function calls and allocated Objects for each invocation. By converting `layerProperties` to a, lazily initialized, Object we can avoid this.
2023-09-28 17:20:23 +02:00
Jonas Jenwald
3072efa064
Merge pull request #17035 from Snuffleupagus/postcss-discard-comments
Remove comments from the *built* CSS files
2023-09-28 15:54:06 +02:00
calixteman
d7d900c65d
Merge pull request #17045 from calixteman/resize_disable_mouse
[Editor] Disable pointer events in the parent layer while an editor is resized
2023-09-28 15:51:53 +02:00
Calixte Denizet
4f6fa35a28 [Editor] Disable pointer events in the parent layer while an editor is resized 2023-09-28 15:09:50 +02:00
calixteman
f78a5ff79e
Merge pull request #17043 from calixteman/bug1855641
StructParents entry isn't required on pages with no tagged contents (bug 1855641)
2023-09-28 14:43:18 +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
calixteman
2daf9515b3
Merge pull request #17041 from calixteman/rm_timeouts
[Editor] Clear the different timeouts when destroying
2023-09-28 12:27:20 +02:00
Calixte Denizet
8417eee0c1 [Editor] Clear the different timeouts when destroying 2023-09-28 12:03:11 +02:00
Jonas Jenwald
00c8fbe7e0
Merge pull request #17040 from Snuffleupagus/rm-save-disabled-CSS
[Editor] Remove unused CSS rules for the altText "Save"-button (PR 17015 follow-up)
2023-09-27 16:29:16 +02:00
calixteman
fb16151247
Merge pull request #17039 from calixteman/alt_text_no_tooltip_when_resizing
[Editor] Disabled the alt-text button when the editor is being resized
2023-09-27 15:37:38 +02:00
Calixte Denizet
bdb8410ad4 [Editor] Disabled the alt-text button when the editor is being resized 2023-09-27 15:13:17 +02:00
Jonas Jenwald
880abd910e [Editor] Remove unused CSS rules for the altText "Save"-button (PR 17015 follow-up)
When PR 17015 removed the `disabled` handling for the "Save"-button it left a bunch of now unused CSS rules behind, which seems like a simply oversight.
Rather than shipping "dead" CSS rules, let's remove those until such a time that they're actually needed.
2023-09-27 14:58:22 +02:00
ayush
87a1baf29f docs: Make downloadManager optional in JSDoc 2023-09-27 12:47:50 +05:30
Jonas Jenwald
7413546e16 Remove comments from the *built* CSS files
The old pre-processor used for CSS, and HTML, files leaves comments intact which unnecessarily contributes to the overall size of the *built* CSS files (note that the built JavaScript files don't include comments).
Rather than trying to "hack" comment removal into the pre-processor it seems easier to use a PostCSS plugin instead. The one potential issue is that it also affects *some* whitespaces, and it's not clear to me if this'll work with the various CSS-related tests that run in mozilla-central.

Please refer to https://www.npmjs.com/package/postcss-discard-comments for additional information.
2023-09-26 13:38:26 +02:00
calixteman
3f7060e777
Merge pull request #17034 from calixteman/bug1855157
[Editor] Don't try to add data to the struct tree when there is no accessibilityData (bug 1855157)
2023-09-26 12:04:50 +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
calixteman
5f75404bc3
Merge pull request #17030 from calixteman/editor_remove_editing_class
[Editor] Remove the class fooEditing from the layer when destroying it
2023-09-25 19:44:50 +02:00
calixteman
549c414ff5
Merge pull request #17031 from calixteman/bug1854991
[Editor] Slightly postpone the move in the DOM in order to not block the UI (bug 1854991)
2023-09-25 19:44:27 +02:00
Calixte Denizet
71376f089c [Editor] Remove the class fooEditing from the layer when destroying it
and simplify the way to handle the different types of editors.
2023-09-25 18:56:11 +02:00
Calixte Denizet
29bc103fad [Editor] Slightly postpone the move in the DOM in order to not block the UI (bug 1854991) 2023-09-25 18:18:01 +02:00
Tim van der Meij
57d196e349
Merge pull request #17024 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2023-09-24 20:02:49 +02:00
Tim van der Meij
a93ac2a32b
Bump the stable version in pdfjs.config 2023-09-24 19:57:55 +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
Jonas Jenwald
6112f3ee74
Merge pull request #17023 from Snuffleupagus/altText-padding
[Editor] Add padding to the altText-button to account for different locales
2023-09-24 17:46:55 +02:00
Jonas Jenwald
fc898e1b38 [Editor] Add padding to the altText-button to account for different locales
*For many non-English locales the translated strings will be longer, which is easy to forget about during development/review.*

Note how for some locales (e.g. Swedish) the altText-button end up looking horizontally "cramped", hence it seems reasonable to add a bit of inline padding to improve this.
2023-09-24 16:13:16 +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
Jonas Jenwald
57f548c989
Merge pull request #17019 from calixteman/bug1854818
[Editor] The ::before containter containing the border of a selected editor mustn't catch mouse events (bug 1854818)
2023-09-24 12:42:50 +02:00
Tim van der Meij
587a3a2eae
Merge pull request #17020 from Snuffleupagus/update-packages
Update packages and translations
2023-09-24 12:11:43 +02:00
Jonas Jenwald
073a1da6f5 Update l10n files 2023-09-24 11:05:37 +02:00
Jonas Jenwald
1b95ab7cfa Update npm packages 2023-09-24 11:03:19 +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
f87ec67ab1 [api-major] Remove various deprecated functionality and options 2023-09-23 17:44:09 +02:00
Jonas Jenwald
0fc0dc3960
Merge pull request #17017 from Snuffleupagus/one-noContextMenu
Use one `noContextMenu` function in both the src/- and web/-folders
2023-09-23 16:18:26 +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
calixteman
d2e34dff93
Merge pull request #17016 from calixteman/alt_text_button_no_menu
[Editor] Disable context menu on alt-text button and in the associated dialog
2023-09-23 14:22:30 +02:00
Calixte Denizet
88f3ed7745 [Editor] Disable context menu on alt-text button and in the associated dialog
but keep it for the text area.
Disable pointerdown on the alt-text button to disable dragging the editor
when the button is clicked (especially when slightly moving the mouse
between the down and the up).
2023-09-22 23:27:55 +02:00
Jonas Jenwald
85568bd6cc
Merge pull request #17012 from Snuffleupagus/altText-telemetry-on-close
[Editor] Report telemetry when closing the altText dialog with `Esc` (PR 16987 follow-up)
2023-09-22 22:45:13 +02:00
Jonas Jenwald
9e0e67918f [Editor] Report telemetry when closing the altText dialog with Esc (PR 16987 follow-up)
The dialog element handles closing with <kbd>Esc</kbd> automatically, however we're not reporting telemetry in that case.
In order to fix that the easiest solution, as far as I'm concerned, seem to be moving the telemetry reporting into the dialog-close handler since it's always invoked.
2023-09-22 22:20:49 +02:00
Jonas Jenwald
d555f351d3
Merge pull request #17011 from Snuffleupagus/altText-destroy-keep-#currentEditor
Don't reset `this.#currentEditor` when destroying the dialog
2023-09-22 22:18:02 +02:00
Jonas Jenwald
8c5da23f67 Don't reset this.#currentEditor when destroying the dialog
This patch addresses an edge-case that'll probably never happen, but it nonetheless seems like something that we want to fix.

Note how we're using the `#currentEditor`-field to prevent opening the dialog when it's already active, and it being reset once the dialog has been closed.
By also resetting the `#currentEditor`-field during destruction, instead of waiting until the dialog has actually closed (assuming it's currently open), there's a *tiny* window of time[1] during which we could theoretically allow to (incorrectly) re-open the dialog and thus getting out-of-sync state in the viewer-component.

---
[1] Since the "close" event, on a dialog-element, is dispatched asynchronously by the browser.
2023-09-22 21:53:26 +02:00
calixteman
c027aaeefa
Merge pull request #17015 from calixteman/alt_text_save_button
[Editor] Let the Save button always enabled in the alt-text dialog
2023-09-22 21:18:30 +02:00
Calixte Denizet
d5936d9a15 [Editor] Let the Save button always enabled in the alt-text dialog 2023-09-22 20:46:29 +02:00
calixteman
f66613c8e4
Merge pull request #17005 from calixteman/alt_text_tweak_save_flow
[Editor] Tweak the save flow in the alt-text dialog
2023-09-22 17:45:49 +02:00
Jonas Jenwald
a68845c902
Merge pull request #17014 from Snuffleupagus/reporttelemetry-tweaks
Don't bother trying to unregister the "reporttelemetry" event listener
2023-09-22 17:35:55 +02:00
Jonas Jenwald
43c7e88fa9 Don't bother trying to unregister the "reporttelemetry" event listener
Note that both event-unbind methods are unused in MOZCENTRAL builds; see https://searchfox.org/mozilla-central/rev/48b6992e03fa66f77ac9688ba61c95d31a451bc1/toolkit/components/pdfjs/content/web/viewer.js#1864-1869
2023-09-22 17:24:32 +02:00
Calixte Denizet
050093c9f5 [Editor] Tweak the save flow in the alt-text dialog
When the user edit an existing alt-text and remove it, we want to be able
to save this state and consequently remove the done state from the
alt-text button.
Remove the button from its parent when the editor is removed: it should
help to save few Kb of memory.
2023-09-22 17:10:20 +02:00
calixteman
3f859f76e6
Merge pull request #17010 from calixteman/alt_text_mask_1
[Editor] Darken the toolbar when the alt-text dialog is opened
2023-09-22 13:34:57 +02:00
Jonas Jenwald
eff7ed580d
Merge pull request #17009 from Snuffleupagus/altText-label-clicks
[Editor] Make the altText dialog labels part of telemetry (PR 16987 follow-up)
2023-09-22 13:26:57 +02:00
Calixte Denizet
0237e2eb2b [Editor] Darken the toolbar when the alt-text dialog is opened
It aims to fix the issue spotted in:
https://github.com/mozilla/pdf.js/pull/17002#issuecomment-1730962273
2023-09-22 13:11:37 +02:00
Jonas Jenwald
ee5b8bcf9e [Editor] Make the altText dialog labels part of telemetry (PR 16987 follow-up)
Radio-buttons can also be toggled by clicking on their associated `label`-elements, and not only the `input`-elements itself, however it seems that "pointerdown" event listeners don't cover that case.
Hence it's possible that telemetry could miss certain cases of a mouse being used, and the easiest solution seem to be to instead use "click" event listeners and just ignore keyboard-based events.
2023-09-22 12:26:03 +02:00
calixteman
2fc8ab3477
Merge pull request #17002 from calixteman/alt_text_mask
[Editor] Avoid to darken the current editor when opening the alt-text dialog
2023-09-22 12:17:21 +02:00
Jonas Jenwald
edb83ffec2
Merge pull request #17004 from Snuffleupagus/dialog-disable-zooming
Prevent wheel/touch zooming in the viewer when a dialog is open
2023-09-22 09:19:19 +02:00
Jonas Jenwald
988222d7de
Merge pull request #17003 from Snuffleupagus/issue-17000
Restore the `collectFields` parameter in the Annotation code (issue 17000)
2023-09-22 09:11:52 +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
9b21f17b03 Prevent wheel/touch zooming in the viewer when a dialog is open 2023-09-21 20:08:08 +02:00
Jonas Jenwald
4cedc12341 Restore the collectFields parameter in the Annotation code (issue 17000)
Rather than trying to be "clever" here, and possibly affect code readability negatively, let's just restore the `collectFields` parameter to address the unneeded parsing that now happens when printing new Annotations.
2023-09-21 19:49:31 +02:00
Jonas Jenwald
e9f707ce3f
Merge pull request #16999 from Snuffleupagus/issue-16994
[GeckoView] Exclude `annotation_editor_layer_builder.css` in the build (issue 16994)
2023-09-21 19:26:50 +02:00
Jonas Jenwald
5711d0f95d [GeckoView] Exclude annotation_editor_layer_builder.css in the build (issue 16994)
Given the limitations of the old pre-processor that's used for CSS/HTML files, this unfortunately isn't as "easy" to implement as it is for JavaScript code.
Since this is the first case where we've wanted to do conditional CSS imports, rather than trying to completely re-write the pre-processor, this patch settles for handling it explicitly in the `expandCssImports` function.
2023-09-21 15:51:33 +02:00
calixteman
a7894a4d7b
Merge pull request #16993 from Snuffleupagus/gv-no-AltTextManager
[GeckoView] Avoid bundling the `AltTextManager` class, since it's unused
2023-09-21 14:19:51 +02:00
calixteman
9de432ba7a
Merge pull request #16998 from calixteman/fix_css_linter_issue_1
Make one of the m-c linters happy
2023-09-21 14:14:56 +02:00
Calixte Denizet
61c77c7d8b Make one of the m-c linters happy 2023-09-21 14:09:48 +02:00
calixteman
b002d16f04
Merge pull request #16996 from Snuffleupagus/issue-16995
Enable the Stylelint `declaration-block-no-duplicate-properties` rule (issue 16995)
2023-09-21 13:52:54 +02:00
Jonas Jenwald
80e691d2ad Enable the Stylelint declaration-block-no-duplicate-properties rule (issue 16995)
Please refer to https://stylelint.io/user-guide/rules/declaration-block-no-duplicate-properties
2023-09-21 13:42:05 +02:00
Jonas Jenwald
e2b7896826 [GeckoView] Avoid bundling the AltTextManager class, since it's unused 2023-09-21 12:51:34 +02:00
calixteman
561aea530b
Merge pull request #16991 from Snuffleupagus/alt_text_edit-boolean
Ensure that all "alt_text_*" save-telemetry values are boolean (PR 16987 follow-up)
2023-09-21 11:04:06 +02:00
calixteman
237b8ce4a8
Merge pull request #16988 from calixteman/alt_text_dialog_others
[Editor] Tweak few values after review from UX
2023-09-21 11:03:19 +02:00
calixteman
67ddabcbc2
Merge pull request #16990 from calixteman/alt_text_aria_label
[Editor] Add an aria-label to the alt-text button depending on its state
2023-09-21 10:56:25 +02:00
Calixte Denizet
b5d18006a7 [Editor] Tweak few values after review from UX 2023-09-21 10:52:58 +02:00
Jonas Jenwald
5660cdfe68 Ensure that all "alt_text_*" save-telemetry values are boolean (PR 16987 follow-up)
Looking at the save-telemetry values they're all boolean *except* for "alt_text_edit" in one instance, since `this.#previousAltText` may be an empty string (looking at the `editAltText` method) and this value may thus become an empty string as well.
2023-09-21 08:36:41 +02:00
Jonas Jenwald
34506f8874
Merge pull request #16989 from Snuffleupagus/more-reporttelemetry-event
Use the new "reporttelemetry" event in more viewer components
2023-09-20 22:06:14 +02:00
Calixte Denizet
c90ea2314e [Editor] Add an aria-label to the alt-text button depending on its state 2023-09-20 21:56:16 +02:00
Jonas Jenwald
fe60db27b1 Use the new "reporttelemetry" event in more viewer components
By utilizing the recently added "reporttelemetry" event, we can avoid having to manually pass in `externalServices` to a number of viewer components.
2023-09-20 20:18:10 +02:00
calixteman
f2d75d9221
Merge pull request #16985 from calixteman/btn_bg
[Editor] Change the colors for the disabled Save button in alt text dialoag in HCM
2023-09-20 19:03:01 +02:00
Calixte Denizet
7d0bf376d0 [Editor] Change the colors for the disabled Save button in alt text dialoag in HCM 2023-09-20 18:58:31 +02:00
calixteman
67646387c8
Merge pull request #16986 from calixteman/alt_text_contents
[Editor] Change some strings in the alt-text dialog
2023-09-20 18:52:37 +02:00
Calixte Denizet
9a677d0d4d [Editor] Change some strings in the alt-text dialog 2023-09-20 18:44:56 +02:00
calixteman
0317d3e168
Merge pull request #16987 from calixteman/alt_text_telemetry
[Editor] Add more telemetry for the 'add image' feature (bug 1853960)
2023-09-20 17:34:59 +02:00
Calixte Denizet
0a278ef0bc [Editor] Add more telemetry for the 'add image' feature (bug 1853960) 2023-09-20 17:23:23 +02:00
calixteman
b80e0d881d
Merge pull request #16984 from Snuffleupagus/altText-close
Don't try to close the `altText` dialog if it's not open (PR 16977 follow-up)
2023-09-20 11:14:28 +02:00
calixteman
b7fa4fb0f7
Merge pull request #16983 from calixteman/alt_text_tooltip
[Editor] Add a tooltip showing the alt text when hovering the alt-text button (bug 1844952)
2023-09-20 11:00:31 +02:00
Calixte Denizet
7952a36384 [Editor] Add a tooltip showing the alt text when hovering the alt-text button (bug 1844952) 2023-09-20 10:50:28 +02:00
Jonas Jenwald
21c55b56bf Don't try to close the altText dialog if it's not open (PR 16977 follow-up)
When closing a document in the viewer, e.g. by running `PDFViewerApplication.close()` in the console, the `AltTextManager.#finish` method currently throws *unless* the `altText` dialog is actually open.
Similar to e.g. the PasswordPrompt, we should thus only attempt to close the `altText` dialog when it's open.
2023-09-20 07:59:46 +02:00
calixteman
8d326e5e30
Merge pull request #16982 from calixteman/alt_text_rm_copy_listeners
[Editor] Remove copy/paste listener when alt text dialog is displayed
2023-09-19 22:52:49 +02:00
Calixte Denizet
c162b004ce [Editor] Remove copy/paste listener when alt text dialog is displayed 2023-09-19 22:41:47 +02:00
calixteman
54f6264d5b
Merge pull request #16977 from calixteman/add_alt_text
[Editor] Allow the user to add and save an alt-text for images (bug 1844952)
2023-09-19 21:59:59 +02:00
Calixte Denizet
c12049db07 [Editor] Allow the user to add and save an alt-text for images (bug 1844952) 2023-09-19 21:46:48 +02:00
Jonas Jenwald
29a48f9479
Merge pull request #16981 from Snuffleupagus/optionalContent-type-missing
Ignore optional content with missing /Type-entries
2023-09-19 15:15:00 +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
daae6589b6
Merge pull request #16979 from calixteman/alt_text_change_str1
[Editor] Update alt text dialog description
2023-09-19 10:36:50 +02:00
calixteman
b9469c2059
Merge pull request #16980 from calixteman/rounded_resizers
[Editor] Make the border of the resizers slightly rounded
2023-09-19 10:12:11 +02:00
Calixte Denizet
f7870c04ae [Editor] Make the border of the resizers slightly rounded
It's a part of the UX specifications. There's a drawing issue in Firefox
(see bug https://bugzilla.mozilla.org/1853288) but setting the
background-clip property to content-box seems to be a good workaround.
2023-09-19 09:57:00 +02:00
Calixte Denizet
0df9d1d934 [Editor] Update alt text dialog description 2023-09-19 09:27:43 +02:00
calixteman
5ac40b71c0
Merge pull request #16952 from calixteman/alt_text_window
[Editor] Add a dialog box in order to get alt-text data (bug 1844952)
2023-09-18 21:49:33 +02:00
Calixte Denizet
df0da86b64 [Editor] Add a dialog box in order to get alt-text data (bug 1844952)
Implement the specifications provided by UX for light, dark and HCM modes.
2023-09-18 21:42:52 +02:00
calixteman
c0ed7fff2c
Merge pull request #16975 from calixteman/alt_text_fix_icon_dims
[Editor] Use the same height as in the svg for icons for the alt-text button
2023-09-18 19:53:48 +02:00
Calixte Denizet
60ccce5cb1 [Editor] Use the same height as in the svg for icons for the alt-text button 2023-09-18 19:07:36 +02:00
calixteman
c8727d9c70
Merge pull request #16974 from calixteman/fix_css_linter_issue
Fix a CSS linter issue in removing a useless comma
2023-09-18 19:01:33 +02:00
calixteman
2bd7bb3847
Merge pull request #16972 from calixteman/alt_text_icon_alpha
[Editor] Avoid to have some transparency in the icon used in the 'Alt text' button
2023-09-18 18:46:46 +02:00
Calixte Denizet
9b6e37c2cd Fix a CSS linter issue in removing a useless comma 2023-09-18 18:45:14 +02:00
Calixte Denizet
9dbe95c63c [Editor] Avoid to have some transparency in the icon used in the 'Alt text' button 2023-09-18 18:25:03 +02:00
calixteman
b85281914f
Merge pull request #16955 from calixteman/alt_text_button
[Editor] Add a button to trigger a dialog for adding an alt text (bug 1844952)
2023-09-18 15:50:10 +02:00
Calixte Denizet
a216836fd5 [Editor] Add a button to trigger a dialog for adding an alt text (bug 1844952) 2023-09-18 15:07:09 +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
97819891b6
Merge pull request #16964 from timvandermeij/fix-intermittent-annotations-move
Fix off-by-one errors in the "FreeText must move several annotations" integration test
2023-09-17 17:46:19 +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
e37e7b6f39
Merge pull request #16962 from timvandermeij/fix-intermittent-bug1844576
Fix integration test "Interaction in bug1844576.pdf must check that a field has the correct formatted value"
2023-09-17 14:12:55 +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
Tim van der Meij
518590ac7d
Merge pull request #16961 from Snuffleupagus/debugger-rm-closure
Remove (some) closures from `web/debugger.js`
2023-09-17 11:45:14 +02:00
Tim van der Meij
98671c3618
Merge pull request #16959 from Snuffleupagus/rm-CipherTransformFactory-closure
Remove the closure from the `CipherTransformFactory` class
2023-09-17 11:42:20 +02:00
Jonas Jenwald
2d79be941e Convert PDFBug, in web/debugger.js, to a class with static methods
This gets rid of one more closure from the code-base.
2023-09-17 08:06:43 +02:00
Jonas Jenwald
c9cd934f8a Stop hard-coding the panel width in web/debugger.js
Thanks to CSS variables we can avoid hard-coding the panel width in the JavaScript code.
2023-09-17 08:06:33 +02:00
Jonas Jenwald
22cd0c6ff8 Remove the closure from the Stepper class in web/debugger.js 2023-09-17 08:06:26 +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
Jonas Jenwald
0304b65fcd Remove the closure from the CipherTransformFactory class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-16 16:34:24 +02:00
Tim van der Meij
b49fe5baac
Merge pull request #16958 from timvandermeij/puppeteer
Update Puppeteer to version 21.2.1
2023-09-16 15:09:56 +02:00
Tim van der Meij
7f8de83e96
Merge pull request #16957 from Snuffleupagus/SaveDocument-more-await
Use `await` even more in the "SaveDocument" worker-thread handler
2023-09-16 14:31:05 +02:00
Tim van der Meij
6c5d5f3cb9
Update Puppeteer to version 21.2.1
This release fixes the upstream bug that caused old Firefox revisions to
not be removed from the cache.

Fixes #16904.
2023-09-16 14:05:26 +02:00
Tim van der Meij
89c8f90a14
Merge pull request #16956 from Snuffleupagus/opMap-rm-getLookupTableFactory
Simplify the `EvaluatorPreprocessor.opMap` getter a little bit
2023-09-16 13:51:33 +02:00
Jonas Jenwald
ff96c413d3 Use await even more in the "SaveDocument" worker-thread handler
Given that the function is already asynchronous we can make use of `await` even more and reduce the amount of indentation a little bit.
2023-09-16 13:06:48 +02:00
Tim van der Meij
4dd197ae3f
Merge pull request #16954 from Snuffleupagus/rm-colorspace-closure
Remove the remaining closures in the `src/core/colorspace.js` file
2023-09-16 12:28:32 +02:00
Jonas Jenwald
316d1ec5ef Simplify the EvaluatorPreprocessor.opMap getter a little bit
Given that this is a shadowed getter, the `opMap` is already lazily initialized and it shouldn't be necessary to *also* use the `getLookupTableFactory` helper function here. Looking at the history of the code, it seems that this is simply a leftover from before JavaScript classes existed.
2023-09-16 12:26:38 +02:00
Jonas Jenwald
8cb5d01acd Remove the closure from the LabCS class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-16 12:20:14 +02:00
Jonas Jenwald
52fa66a98b Remove the closure from the CalRGBCS class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-16 12:20:12 +02:00
Jonas Jenwald
4d615f087f Remove the closure from the CalGrayCS class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-15 15:53:16 +02:00
Jonas Jenwald
d2c8997380 Remove the closure from the DeviceCmykCS class
Now that modern JavaScript is fully supported also in the worker-thread we no longer need to keep old closures, which slightly reduces the size of the code.
2023-09-15 15:53:05 +02:00
Jonas Jenwald
586d3add46
Merge pull request #16951 from Snuffleupagus/tweak-pattern-getB
Make it possible to clear the cache, used by the `getB` function in `src/core/pattern.js`
2023-09-15 14:06:51 +02:00
Jonas Jenwald
628ca737dd Make it possible to clear the cache, used by the getB function in src/core/pattern.js
While this cache will not contain a huge amount of data in practice, it's nonetheless a *global* cache that currently will never be cleared.

This patch also removes the existing closure, since it shouldn't really be necessary nowadays given that the code is a JavaScript module which means that only explicitly listed properties will be exported.
2023-09-15 12:23:06 +02:00
calixteman
4c0fbe51e5
Merge pull request #16950 from calixteman/resizers_hcm
[Editor] Change the colors of the outline and the resizers for selected editors in HCM
2023-09-15 11:52:27 +02:00
Jonas Jenwald
93ce7c5a89 Change the getB function, in src/core/pattern.js, to use the exponentiation operator 2023-09-15 11:46:00 +02:00
Calixte Denizet
38f60a7eff [Editor] Change the colors of the outline and the resizers for selected editors in HCM 2023-09-15 10:29:49 +02:00
calixteman
8d695c982f
Merge pull request #16943 from calixteman/new_resizers
[Editor] Change the style of the bounding box and the resizers (bug 1852897)
2023-09-14 10:42:18 +02:00
Calixte Denizet
01f9f385d7 [Editor] Change the style of the bounding box and the resizers (bug 1852897) 2023-09-14 09:45:41 +02:00
calixteman
920e51a1e6
Merge pull request #16944 from calixteman/move_dom_after_position
[Editor] Move an editor in the DOM just after having moved it on the screen
2023-09-13 12:34:21 +02:00
Calixte Denizet
720963bbe6 [Editor] Move an editor in the DOM just after having moved it on the screen
It avoids to have to remember to call moveInDOM after fixAndSetPosition is called.
2023-09-13 10:51:25 +02:00
Jonas Jenwald
b1578225fc
Merge pull request #16941 from Snuffleupagus/SaveDocument-await-requestLoadedStream
Ensure that the entire PDF document is loaded *before* we begin saving it
2023-09-12 17:34:34 +02:00
Jonas Jenwald
50937a3539 Ensure that the entire PDF document is loaded *before* we begin saving it
When I started looking at PR 16938 it occurred to me that some of the new structTree-methods are synchronously accessing certain dictionary-data (not used during "normal" structTree-parsing), which may not be generally safe since everything in a dictionary could be a reference (and the relevant data may not have been loaded yet).

Rather than suggesting that we make all those new methods even more asynchronous, to me the overall simplest and safest solution is to ensure that the *entire* PDF document has been loaded *before* we begin saving it. In practice this shouldn't really affect "performance" of saving noticeably, since it's always depended on the entire PDF document being downloaded.

Finally note that with the exception of the PDF document possibly not having been fully downloaded when saving is triggered, all other "global" document properties are pretty much guaranteed to already be available at this point.
2023-09-12 13:26:57 +02:00
calixteman
953f271425
Merge pull request #16940 from calixteman/get_back_focus_when_required
[Editor] Only get back the focus when it has been lost after an editor has been moved in the DOM
2023-09-12 13:22:47 +02:00
Calixte Denizet
5646604883 [Editor] Only get back the focus when it has been lost after an editor has been moved in the DOM 2023-09-12 12:17:24 +02:00
Tim van der Meij
221ee6ca37
Merge pull request #16932 from timvandermeij/unit-test-enable
Enable unit test "creates pdf doc from non-existent URL"
2023-09-10 18:12:56 +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
Tim van der Meij
5f93638045
Merge pull request #16925 from timvandermeij/updates
Update packages and translations
2023-09-10 11:30:56 +02:00
Tim van der Meij
981ef9e31e
Update translations 2023-09-09 17:53:43 +02:00
Tim van der Meij
f42d70a24e
Update packages 2023-09-09 17:53:43 +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
calixteman
cf7efdb040
Merge pull request #16921 from calixteman/simplify_write
Simplify writeObject function
2023-09-08 21:25:44 +02:00
Calixte Denizet
52cc1220e4 Simplify writeObject function
It'll avoid to have the duplication of the code to get the encrypt transform,
and last but not least, it'll avoid to forget about encryption.
2023-09-08 19:59:59 +02:00
calixteman
b903b3030a
Merge pull request #16916 from calixteman/parent_in_struct_tree
[Editor] Add the parent tag id (if any) to the serialized editors (bug 1845087)
2023-09-08 16:24:47 +02:00
Jonas Jenwald
b5b061cdb6 Slightly re-factor the parameter handling in Catalog.parseDestDictionary
While it makes sense to check that the `destDict` parameter is indeed a Dictionary, since that data comes from the PDF document itself, the `resultObj` parameter is an internal PDF.js implementation detail that should always be correct (or tests will fail).
2023-09-08 13:27:31 +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
calixteman
5ffa23c7f1
Merge pull request #16911 from calixteman/issue16872
[Editor] Avoid to use parent of editors in destroyed pages
2023-09-07 14:59:47 +02:00
Calixte Denizet
8ab4e2e6e7 [Editor] Avoid to use parent of editors in destroyed pages 2023-09-07 12:30:29 +02:00
Jonas Jenwald
cf5a1d60a6
Merge pull request #16897 from mozilla/dependabot/github_actions/actions/checkout-4
Bump actions/checkout from 3 to 4
2023-09-05 17:46:48 +02:00
calixteman
03eabae613
Merge pull request #16905 from calixteman/bug1851517
Only call the focus/blur callbacks when it's necessary (bug 1851517)
2023-09-05 15:19:36 +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
Jonas Jenwald
92792a8215
Merge pull request #16902 from Snuffleupagus/FileAttachment-keyboard-download
Support downloading FileAttachment annotations with the keyboard
2023-09-05 12:45:04 +02:00
Jonas Jenwald
e7800c22dd Support downloading FileAttachment annotations with the keyboard
While reviewing PR 16898 it occurred to me that it's currently impossible to trigger downloading of FileAttachment annotations using the keyboard.
Hence this patch adds `Ctrl + Enter` as the keyboard shortcut to download those, thus supplementing the existing double-clicking when using a mouse.
2023-09-05 11:31:30 +02:00
calixteman
f2a4f2adaf
Merge pull request #16899 from calixteman/bug1851498
Unconditionally render non-form annotations in the annotation layer (bug 1851498)
2023-09-05 11:28:23 +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
calixteman
08f9e48280
Merge pull request #16898 from calixteman/make_annotation_focusable
Make annotations focusable (bug 1851489)
2023-09-04 18:08:58 +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
dependabot[bot]
48a2c29f98
Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-04 12:51:59 +00:00
Jonas Jenwald
b18a1669ac
Merge pull request #16896 from Rob--W/grab-to-pan-css-fix
Drop redundant styles from .grab-to-pan-grab:active
2023-09-04 10:23:12 +02:00
Rob Wu
28bda9f68b Drop redundant styles from .grab-to-pan-grab:active
`.grab-to-pan-grab:active` is `#viewerContainer` when the mouse is
pressed down.  It is supposed to have a `cursor: grabbing` appearance
immediately on mousedown,

`.grab-to-pan-grabbing` is the overlay that is supposed to cover
everything, and also has the `cursor: grabbing` appearance. The "cover
everything" result is achieved through `position:fixed`, `inset:0`, etc.

The block with these CSS properties for "cover everything" is currently
shared by `.grab-to-pan-grab:active` and `.grab-to-pan-grabbing`, but
only "cursor" need to be shared. The original JS and CSS code at
https://github.com/Rob--W/grab-to-pan.js shows that these were supposed
to be associated with the overlay only.

The PR that added this to PDF.js also shows that the "cover everything"
CSS properties were supposed to be limited to the overlay only:
https://github.com/mozilla/pdf.js/pull/4209#discussion-diff-9285917

But the final version of the PR mistakenly merged them together.
This patch rectifies that mistake.
2023-09-03 19:45:18 +02:00
Tim van der Meij
1e7c907fbf
Merge pull request #16881 from Snuffleupagus/InternalRenderTask-tweaks
A couple of small `InternalRenderTask` changes
2023-09-03 13:05:31 +02:00
Tim van der Meij
11c5213185
Merge pull request #16895 from Snuffleupagus/update-packages
Update packages and translations
2023-09-03 13:03:28 +02:00
Jonas Jenwald
07cca3ddd9 Update l10n files 2023-09-03 10:01:37 +02:00
Jonas Jenwald
92831455bf Update npm packages 2023-09-03 09:59:08 +02:00
Jonas Jenwald
87ea2ed4e2
Merge pull request #16890 from stof/fix_type_generator
[Type-definitions] Fix type generator to support import maps
2023-09-01 12:00:27 +02:00
Christophe Coevoet
46f2c5893d Revert "Temporarily stop running gulp typestest in GitHub Actions"
This reverts commit d9350c38997b31ee9f0058f438b332997eb53e07.
2023-09-01 09:48:39 +02:00
Christophe Coevoet
d0f14b1ce3 Add support for the import map in the type generator
The typescript compiler is now configured to know about the import map
to be able to resolve those imports and find the associated types.
As tsc outputs declaration files using the original module identifiers
and not the resolved ones, tsc-alias is used to post-process the
declaration files by resolving those paths.
2023-09-01 09:48:39 +02:00
Christophe Coevoet
bbf11a5783 Migrate the typescript options to a config file
Some configurations settings like `paths` cannot be provided through CLI
arguments but only in a configuration file. And when using a
configuration file, only a few options (like `--outDir` can still be
provided) through the CLI.
2023-09-01 09:48:34 +02:00
Jonas Jenwald
b5c8849111
Merge pull request #16892 from Snuffleupagus/addLinkAttributes-rm-removeNullCharacters
Stop using `removeNullCharacters` in the `addLinkAttributes` helper function
2023-08-31 21:52:44 +02:00
Jonas Jenwald
c5ee72bb95 Stop using removeNullCharacters in the addLinkAttributes helper function
Using `removeNullCharacters` on the URL should be completely redundant, given the kind of data that we're passing to the `addLinkAttributes` helper function. Note that whenever we're handling a URL, originating in the worker-thread, in the viewer that helper function is always being used.

Furthermore, on the worker-thread all URLs are parsed with the `createValidAbsoluteUrl` helper function, which uses `new URL()` to ensure that a valid URL is obtained. Note that the `URL` constructor will either throw, or in some cases just ignore them, when encountering `\u0000`-characters during parsing.

Hence it should be *impossible* for a valid URL to contain `\u0000`-characters and we can thus simplify the viewer-code a tiny bit. The use of `removeNullCharacters` is most likely a left-over from back when `new URL()` wasn't generally available in browsers.
2023-08-31 20:10:50 +02:00
Jonas Jenwald
9190445a21
Merge pull request #16891 from Snuffleupagus/structElement-removeNullCharacters
Ignore null-chars when using structTree-data in the viewer
2023-08-31 18:09:04 +02:00
Jonas Jenwald
b159cc9e4b
Merge pull request #16888 from stof/fix_jsdoc_types
Fix JSDoc types
2023-08-31 16:36:09 +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
calixteman
14b2a31e78
Merge pull request #16889 from calixteman/fix_aria_controls_id
Fix the id used in aria-controls used to make a relationship between the popup and its parent
2023-08-31 16:06:11 +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
calixteman
20b0be973c
Merge pull request #16886 from calixteman/struct_tree_annotation
Add tagged annotations in the structure tree (bug 1850797)
2023-08-31 14:05:55 +02:00
Christophe Coevoet
f84f2646f4 Fix JSDoc types
This fixes invalid type references (either due to invalid paths for the
import or missing imports) in the JS doc, as well as some missing or
invalid parameter names for @param annotations.
2023-08-31 13:09:52 +02:00
Calixte Denizet
d185db2b70 Add tagged annotations in the structure tree (bug 1850797) 2023-08-31 12:35:32 +02:00
Jonas Jenwald
1b8441dacc Don't pass in unused pageColors to CanvasGraphics.endDrawing (PR 16380 follow-up)
This became unnecessary in PR 16380, however we forgot to update one of the API call-sites.
2023-08-28 16:14:22 +02:00
Jonas Jenwald
9b4efe2c2f Use WeakSet.prototype.delete() unconditionally in the InternalRenderTask class
It's not necessary to check if an object exists before trying remove it from a `WeakSet`; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete#return_value
2023-08-28 16:10:33 +02:00
Tim van der Meij
92f7653cfb
Merge pull request #16876 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-08-27 18:09:29 +02:00
Tim van der Meij
fd32a53a86
Bump versions in pdfjs.config 2023-08-27 18:04:05 +02:00
Tim van der Meij
e142baecb1
Merge pull request #16875 from Snuffleupagus/more-optional-chaining-4
Introduce more optional chaining in the code-base
2023-08-27 11:16:56 +02:00
Jonas Jenwald
ec3d2be761 Introduce more optional chaining in the code-base
Also, use logical OR assignment a bit more.
2023-08-26 10:52:23 +02:00
Jonas Jenwald
598421b11f
Merge pull request #16856 from Snuffleupagus/limit-lineEndings
Exclude `lineEndings`, in Annotation-data, in MOZCENTRAL builds (PR 14899 follow-up)
2023-08-24 15:58:32 +02:00
calixteman
62a294bb52
Merge pull request #16864 from calixteman/issue16863
Don't reset all fields when the resetForm argument is an array
2023-08-24 09:56:11 -04: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
calixteman
08f26be7b4
Merge pull request #16862 from calixteman/revert_1838855
Revert fix for bug 1838855 (bug 1849876)
2023-08-23 13:23:59 -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
Jonas Jenwald
847da21c95
Merge pull request #16858 from Snuffleupagus/stamp-aria-controls
Add the "aria-controls" attribute to the StampEditor toolbar-button
2023-08-23 17:17:52 +02:00
Jonas Jenwald
6da4fe5778
Merge pull request #16860 from Snuffleupagus/editorconfig-mjs
Add the `.mjs` file-extension to the EditorConfig
2023-08-23 17:16:50 +02:00
Jonas Jenwald
89779b3f6c Add the .mjs file-extension to the EditorConfig
Given that this file-extension is used for JavaScript modules, those files should obviously be formatted just like any "normal" JS file.
2023-08-23 11:22:25 +02:00
Jonas Jenwald
de52c98ddf Add the "aria-controls" attribute to the StampEditor toolbar-button
Given that the other Editor toolbar-buttons use this attribute, it seems that the StampEditor should as well.
2023-08-22 10:05:21 +02:00
Jonas Jenwald
cd181eb746 Exclude lineEndings, in Annotation-data, in MOZCENTRAL builds (PR 14899 follow-up)
This was added in PR 14899, over a year ago, however it's still completely unused in the PDF.js library/viewer. In hindsight I think that it was a mistake to add unused functionality, and the issue should probably have been WONTFIXed instead, however we probably can't just remove it now.
Thanks to the pre-processor, we can at least exclude this code in the *built-in* Firefox PDF Viewer.
2023-08-21 10:15:04 +02:00
Tim van der Meij
a7d829155b
Merge pull request #16852 from Snuffleupagus/less-workerPort
Initialize the `PDFWorker.#workerPorts` WeakMap lazily
2023-08-20 12:45:41 +02:00
Jonas Jenwald
988ce2820b Initialize the PDFWorker.#workerPorts WeakMap lazily
By default this WeakMap isn't needed, and it's simple enough to initialize it lazily instead.
2023-08-19 16:18:38 +02:00
Jonas Jenwald
2993c7725b [Firefox] Exclude more workerPort related code in MOZCENTRAL builds
Given that this code is (and has always been) unused in the Firefox PDF Viewer, we don't need to include it in that build-target.
2023-08-19 15:52:00 +02: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
Tim van der Meij
05fa7dcc7e
Merge pull request #16850 from Snuffleupagus/update-packages
Update packages and translations
2023-08-19 13:33:48 +02:00
Jonas Jenwald
d762986bb0 Update l10n files 2023-08-19 09:30:41 +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
c5ebfa51a7 Update npm packages 2023-08-19 09:08:11 +02:00
Jonas Jenwald
60581c427e
Merge pull request #16844 from Snuffleupagus/StampEditor-isEmpty
Update the `StampEditor.isEmpty` method to handle File (PR 16828 follow-up)
2023-08-18 20:40:09 +02:00
Jonas Jenwald
520397e1e8
Merge pull request #16840 from Snuffleupagus/Stamp-#getBitmapFetched
Add a helper method to reduce duplication in `StampEditor.#getBitmap`
2023-08-18 20:38:55 +02:00
Jonas Jenwald
d513899fc7 Update the StampEditor.isEmpty method to handle File (PR 16828 follow-up)
After the changes in PR 16828 the `StampEditor` can now be initialized with a File, in addition to a URL, hence it seems that the `isEmpty` method ought to take that property into account as well.

Looking at this I also noticed that the assignment in the constructor may cause the `this.#bitmapUrl`/`this.#bitmapFile` fields be `undefined` which "breaks" the comparisons in the `isEmpty` method.
We could obviously fix those specific cases, but it seemed overall safer (with future changes) to just update the `isEmpty` method to be less sensitive to exactly how these fields are initialized and reset.
2023-08-17 09:25:58 +02:00
Jonas Jenwald
df9cb772d9 Add a helper method to reduce duplication in StampEditor.#getBitmap
Currently we're repeating virtually the same code *four times* when fetching the bitmap-data, which seems unnecessary.

Also, ensure that the `#bitmapPromise` is always `null`ed by moving that into the `StampEditor.#getBitmapDone` method.
2023-08-17 08:36:07 +02:00
Jonas Jenwald
c72cb5436d
Merge pull request #16835 from Snuffleupagus/improve-Annotation-compression-test
Improve the "write a new annotation, save the pdf and check that the text content is correct" unit-test (PR 16559 follow-up)
2023-08-15 16:44:18 +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
Tim van der Meij
8cf2f6d352
Merge pull request #16830 from Snuffleupagus/issue-16777-2
Avoid using the global `workerPort` when destruction has started, but not yet finished (issue 16777)
2023-08-13 12:18:28 +02:00
Tim van der Meij
43ab1d2da7
Merge pull request #16831 from Snuffleupagus/rm-no-babel-preset
Remove the "no-babel-preset" comment used with the LIB build-target (PR 16829 follow-up)
2023-08-13 12:09:43 +02:00
Jonas Jenwald
6669a99299 Remove the "no-babel-preset" comment used with the LIB build-target (PR 16829 follow-up)
Similar to the changes in PR 16829, this no longer seems necessary now.
2023-08-13 08:55:58 +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
Tim van der Meij
690b873897
Merge pull request #16829 from Snuffleupagus/gulpfile-rm-src-babel-excludes
Remove the `src/core/` Babel excludes, since they no longer seem necessary
2023-08-12 13:35:31 +02:00
Jonas Jenwald
1810191be2 Remove the src/core/ Babel excludes, since they no longer seem necessary
- The `src/core/unicode.js` exclude ought to have become unnecessary already with PR 16200, which significantly shortened and simplified that file.
 - The `src/core/glyphlist.js` exclude no longer seems necessary in practice either, possibly because of improvements in Babel.
2023-08-12 10:09:03 +02:00
calixteman
890550653a
Merge pull request #16828 from calixteman/editor_paste_image
[Editor] Add the possibility to paste an image from the clipboard (bug 1848317)
2023-08-11 22:28:33 +02:00
Calixte Denizet
2dd6f07b57 [Editor] Add the possibility to paste an image from the clipboard (bug 1848317) 2023-08-11 19:49:18 +02:00
calixteman
4b2eebf32e
Merge pull request #16826 from calixteman/editor_remove_empty_stamp
[Editor] Remove the stamp editor displayed when the image was loading (bug 1848313)
2023-08-11 17:17:45 +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
calixteman
4eca3ca199
Merge pull request #16819 from calixteman/editor_stamp_button
[Editor] Add a button to explicitly add an image (bug 1848108)
2023-08-11 15:32:47 +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
Jonas Jenwald
d57e3ebbe4
Merge pull request #16810 from Snuffleupagus/_initializeAutoPrint-refactor
Re-factor `PDFViewerApplication._initializeAutoPrint` slightly (PR 16779 follow-up)
2023-08-11 08:49:45 +02:00
Jonas Jenwald
caebe335b2 Re-factor PDFViewerApplication._initializeAutoPrint slightly (PR 16779 follow-up)
After the `src/core/`-changes in PR 16779 the `PDFDocumentProxy.getJSActions` method should no longer be able to return *empty* entries, which means that we can simplify the "JavaScript support is not enabled"-warning in the viewer.
Furthermore, improve the auto-printing hack used when scripting is disabled.
2023-08-10 21:36:08 +02:00
calixteman
1d523d3ec1
Merge pull request #16825 from calixteman/editor_avoid_right_click
[Editor] Avoid showing the context menu or resizing when a resizer is right clicked
2023-08-10 18:37:59 +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
96a1f323c4 [Editor] Avoid showing the context menu or resizing when a resizer is right clicked 2023-08-10 18:24:57 +02:00
Jonas Jenwald
f1bd98c6d8
Merge pull request #16823 from Snuffleupagus/_getPageIndex-fallback
Fallback to check all pages when getting the pageIndex of FieldObjects
2023-08-10 18:06:54 +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
calixteman
ea259710fa
Merge pull request #16811 from calixteman/editor_drag_selected
[Editor] Add the possibility to move all the selected editors with the mouse (bug 1847894)
2023-08-10 15:23:34 +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
calixteman
d4ba312f00
Merge pull request #16820 from calixteman/editor_stamp_integer_dims
[Editor] Avoid to have slightly truncated images because of non-integer canvas dimensions
2023-08-10 14:16:46 +02:00
Calixte Denizet
b6b51f57ed [Editor] Avoid to have slightly truncated images because of non-integer canvas dimensions 2023-08-10 14:11:42 +02:00
Jonas Jenwald
4962d005f8
Merge pull request #16815 from Snuffleupagus/more-optional-chaining-3
Introduce even more optional chaining in the code-base
2023-08-10 13:33:20 +02:00
calixteman
f66072b658
Merge pull request #16818 from calixteman/no_cancelled_stamp_in_unod
[Editor] Avoid to add a cancelled added image in the undo/redo stack
2023-08-10 13:19:20 +02:00
Calixte Denizet
b6432ef9de [Editor] Avoid to add a cancelled added image in the undo/redo stack
We're adding the action in the undo/redo stack whatever the status of the
operation was. This patch aims to add the action only when the image has been
successfully added.
2023-08-10 12:18:15 +02:00
Jonas Jenwald
ec7746350d Introduce even more optional chaining in the code-base
This replaces a few more small/simple if-statements with optional chaining.
2023-08-09 17:04:54 +02:00
calixteman
f89020e9b1
Merge pull request #16813 from calixteman/editor_move_params
[Editor] Move the parameter elements for FreeText and Ink annotations at the right place (follow-up of #16802)
2023-08-09 14:06:21 +02:00
calixteman
1447049513
Merge pull request #16812 from calixteman/editor_dont_lose_selection_on_bluring
[Editor] Avoid to unselect some editors when the main window is focused
2023-08-09 14:06:04 +02:00
Calixte Denizet
149f18b766 [Editor] Move the parameter elements for FreeText and Ink annotations at the right place (follow-up of #16802) 2023-08-09 13:35:45 +02:00
Calixte Denizet
9ae7ad0fa6 [Editor] Avoid to unselect some editors when the main window is focused
When several editors are selected and the window loses and then gets back its focus,
the previously focused editor is triggering its focus callback making it the only
selected one.
This patch aims to avoid triggering the focus callback called when the main window
gets its focus back.
2023-08-09 12:09:15 +02:00
calixteman
77392dfce4
Merge pull request #16809 from calixteman/editor_focus_after_moving_in_dom
[Editor] Move an the editor div in the DOM once a translation with the keyboard is done
2023-08-09 10:10:28 +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
calixteman
ec2b717705
Merge pull request #16808 from calixteman/editor_no_newline_freetext
[Editor] Avoid to add a new line when hitting enter with a selected freetext editor
2023-08-08 20:15:10 +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
calixteman
a476000271
Merge pull request #16802 from calixteman/editor_bug1847707
[Editor] Move the stamp button on the right of the pen one (bug 1847707)
2023-08-08 17:09:13 +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
calixteman
007b46279d
Merge pull request #16807 from calixteman/bug1847733
[Annotation] Strip out the array index in the path only when the path is from a terminal node (bug 1847733)
2023-08-08 16:14:23 +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
calixteman
15c21d7758
Merge pull request #16798 from calixteman/issue16797
[Editor] Fix the dimensions of the annotation editor layer (follow-up of #16794)
2023-08-08 14:06:50 +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
Calixte Denizet
35d1f5485e [Editor] Move the stamp button on the right of the pen one (bug 1847707) 2023-08-08 11:35:51 +02:00
Calixte Denizet
400699687e [Editor] Fix the dimensions of the annotation editor layer (follow-up of #16794) 2023-08-08 11:19:04 +02:00
Jonas Jenwald
19c712c2d0
Merge pull request #16799 from Snuffleupagus/editor-resize-cursors
[Editor] Change the resize cursors to bidirectional variants
2023-08-07 08:34:26 +02:00
Jonas Jenwald
8bd45cb260 [Editor] Change the resize cursors to bidirectional variants
When resizing an editor we're currently using unidirectional cursors, please refer to https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
Given that editors can (generally) be resized to become either smaller or larger, it seems overall more appropriate to use bidirectional cursors to make this clearer to the user.

Note that as mentioned in the MDN article some environments, which seems to apply to e.g. Windows 11, doesn't differentiate between the two cursor formats and simply use bidirectional ones unconditionally.

One additional benefit of these changes is that the relevant CSS rules become slightly more compact.
2023-08-06 22:09:15 +02:00
Tim van der Meij
de1f31aae8
Merge pull request #16794 from Snuffleupagus/CSS-round
Use the `round` CSS function in the `setLayerDimensions` helper function
2023-08-06 13:22:07 +02:00
Tim van der Meij
b67c60922f
Merge pull request #16790 from Snuffleupagus/addGlobalExports
Attempt to expose e.g. `pdfjsLib` globally regardless of how the library is imported (issue 16778)
2023-08-06 12:58:58 +02:00
Tim van der Meij
64b33da236
Merge pull request #16795 from Snuffleupagus/update-packages
Update packages and translations
2023-08-06 12:48:30 +02:00
Jonas Jenwald
1182f4965d Update l10n files 2023-08-06 09:25:38 +02:00
Jonas Jenwald
d50237da3c Update npm packages 2023-08-06 09:25:30 +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
calixteman
399475247f
Merge pull request #16781 from calixteman/editor_rewrite_dragging
[Editor] Refactor dragging and dropping an editor (bug 1802895, bug 1844618)
2023-08-03 15:38:12 +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
calixteman
be29a4dce5
Merge pull request #16786 from calixteman/editor_resizers_blur
[Editor] Stop the resize session when the window is blurred
2023-08-03 13:47:11 +02:00
Jonas Jenwald
42e6243ebf Attempt to expose e.g. pdfjsLib globally regardless of how the library is imported (issue 16778)
We obviously don't want to re-introduce any `require` usage in e.g. the viewer, since we should strive to only use native `import` statements wherever possible.[1]
Hopefully exposing e.g. the library globally in more cases won't break anything, however it's somewhat difficult for me to imagine all the ways in which third-party users may be accessing the PDF.js library. (Given the lack of a runnable test-case in the issue, I also cannot guarantee that this is enough to fully address the problem.)

---
[1] Ideally we should probably not rely on e.g. `pdfjsLib` being globally available in the *built* viewer, and rather always `import` the library instead.
Unfortunately this would require larger (possibly breaking) changes in the builds that we provide, however note that Firefox only recently got support for `import` in workers and that Webpack still only have *experimental* support for outputting "proper" modules.
2023-08-03 12:53:27 +02:00
Calixte Denizet
99c62f9248 [Editor] Stop the resize session when the window is blurred 2023-08-03 10:51:47 +02:00
calixteman
2747928a54
Merge pull request #16784 from calixteman/editor_fix_rescale_svg
[Editor] Use a getter and not a function for the _checkIfSVGFitsInCanvas (bug 1846727)
2023-08-03 10:16:28 +02:00
Calixte Denizet
fcfb2457bc [Editor] Use a getter and not a function for the _checkIfSVGFitsInCanvas (bug 1846727)
It's a followup of #16780.
2023-08-03 09:46:31 +02:00
calixteman
0725b6299f
Merge pull request #16780 from calixteman/editor_fix_rescale_svg
[Editor] Let SVG images be resized horizontally/vertically without keeping the aspect ratio (bug 1846727)
2023-08-02 14:21:21 +02:00
Calixte Denizet
556f42fe52 [Editor] Let SVG images be resized horizontally/vertically without keeping the aspect ratio (bug 1846727) 2023-08-02 12:43:39 +02:00
Jonas Jenwald
e6728f94f4
Merge pull request #16779 from Snuffleupagus/deprecate-getJavaScript
[api-minor] Deprecate the `PDFDocumentProxy.getJavaScript` method
2023-08-01 20:58:36 +02:00
calixteman
4735ed8f16
Merge pull request #16776 from calixteman/gv_print_or_save
[GeckoView] Allow to query pdf.js to know if we can avoid to print a pdf (bug 1846296)
2023-08-01 15:21:10 +02:00
Calixte Denizet
8bd4a18190 [GeckoView] Allow to query pdf.js to know if we can avoid to print a pdf (bug 1846296) 2023-08-01 15:15:04 +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
calixteman
5b8f680480
Merge pull request #16029 from calixteman/bug1815196
[api-minor] Don't print hidden annotations (bug 1815196)
2023-07-31 20:14:43 +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
calixteman
ce9f94848c
Merge pull request #16773 from calixteman/editor_stamp_input_filter
[Editor] Limit image types to the ones supported by the browser (bug 1846230)
2023-07-31 11:06:21 +02:00
Calixte Denizet
f2bf0ccc4f [Editor] Limit image types to the ones supported by the browser (bug 1846230) 2023-07-31 11:01:28 +02:00
Jonas Jenwald
0e6d141edf
Merge pull request #16771 from Snuffleupagus/gv-dialog-css-vars
[GeckoView] Add missing CSS variables for the dialog functionality
2023-07-30 19:45:09 +02:00
calixteman
621c92dbdd
Merge pull request #16766 from calixteman/fix_willprint
Make sure WillPrint ran before starting printing
2023-07-30 18:37:26 +02:00
Jonas Jenwald
ffb932b84a [GeckoView] Add missing CSS variables for the dialog functionality
Without this patch the password dialog is pretty difficult to use in the GeckoView-viewer, because of a number of missing CSS variables.

*Please note:* This patch makes no effort at actually styling the dialog to better suite the overall look of the GeckoView-viewer, but focuses solely on making it actually usable (since password protected PDF documents are somewhat rare).
2023-07-30 17:23:21 +02:00
Jonas Jenwald
02aa561003 Ensure that the password dialog is always closed with the document
If the current PDF document is closed while the password dialog is open, e.g. manually by calling `PDFViewerApplication.close()` from the console, the password dialog wouldn't be closed as intended.

*Please note:* This could only affect the GENERIC viewer, although it's very unlikely to ever happen, since that's the only one that supports opening more than one PDF document.
2023-07-30 17:13:39 +02:00
Tim van der Meij
f7155ad8fa
Merge pull request #16770 from Snuffleupagus/fix-baseVersion
Fix typo in the `baseVersion` commit hash (PR 16769 follow-up)
2023-07-30 16:58:53 +02:00
Jonas Jenwald
1ca3bbd2b6 Fix typo in the baseVersion commit hash (PR 16769 follow-up)
Looking at the demo-viewer I noticed that the version number seems to be stuck at version `3.10.0` despite a couple of PRs having landed since the version bump in PR 16769.

Searching for the current `baseVersion` doesn't find an actual commit, see https://github.com/search?q=repo%3Amozilla%2Fpdf.js+1ef6fbc525856318e78a6035b200ba1c6ec02d491&type=commits

However, looking at the commit hash it seems to be too long and removing the trailing `1` appears to fix things; see https://github.com/search?q=repo%3Amozilla%2Fpdf.js+1ef6fbc525856318e78a6035b200ba1c6ec02d49&type=commits
2023-07-30 15:21:49 +02:00
calixteman
7bdd3491b0
Merge pull request #16767 from calixteman/color_storage
Add the color changes in the annotation storage
2023-07-30 15:17:27 +02:00
Calixte Denizet
d16d1f0d23 Add the color changes in the annotation storage 2023-07-30 14:03:27 +02:00
Tim van der Meij
8ad0f08099
Merge pull request #16769 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-07-30 13:17:48 +02:00
Tim van der Meij
445ffa920a
Bump versions in pdfjs.config 2023-07-30 13:13:09 +02:00
Calixte Denizet
8439e11160 Make sure WillPrint ran before starting printing 2023-07-30 12:38:46 +02:00
Tim van der Meij
1ef6fbc525
Merge pull request #16768 from Snuffleupagus/pr-15335-followup
Ensure that failing to open the password dialog once won't permanently disable it (PR 15335 follow-up)
2023-07-30 12:18:49 +02:00
Jonas Jenwald
930cbc4d27 Make the passwordCapability field, in WorkerTransport, actually private as intended 2023-07-30 11:45:35 +02:00
Jonas Jenwald
81dfa61777 Ensure that failing to open the password dialog once won't permanently disable it (PR 15335 follow-up)
*Please note:* This situation should never happen in practice, but it nonetheless cannot hurt to fix this.

If the `PasswordPrompt.open` method would ever be called synchronously back-to-back *and* if opening of the dialog fails the first time, then the second invocation would remain pending indefinitely since we just clear out the capability.
2023-07-30 08:46:11 +02:00
Tim van der Meij
7ae5a0fef7
Merge pull request #16731 from Snuffleupagus/rm-useOnlyCssZoom
[api-minor] Replace the `useOnlyCssZoom` option with `maxCanvasPixels = 0` instead (PR 16729 follow-up)
2023-07-29 14:07:45 +02:00
Jonas Jenwald
0ee2a352ec [api-minor] Replace the useOnlyCssZoom option with maxCanvasPixels = 0 instead (PR 16729 follow-up)
Given that the `useOnlyCssZoom` option is essentially just a special-case of the `maxCanvasPixels` functionality, we can combine the two options in order to simplify the overall implementation.
Note that the `useOnlyCssZoom` functionality was only ever used, by default, in the PDF Viewer for the B2G/FirefoxOS project (which was abandoned years ago).
2023-07-29 13:58:03 +02:00
Tim van der Meij
2a77f0877c
Merge pull request #16765 from Snuffleupagus/bug-858128-test
Add an `eq` test for bug 858128
2023-07-29 13:48:30 +02:00
Tim van der Meij
aea13b4478
Merge pull request #16744 from Snuffleupagus/app-small-simplifications
A few small `web/app.js` simplifications
2023-07-29 13:41:01 +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
cfd179f23f
Merge pull request #16163 from Snuffleupagus/bug-1810111
[GeckoView] Bundle the Firefox printing code in the viewer (bug 1810111)
2023-07-28 14:28:57 +02:00
Jonas Jenwald
e77c7f336d [GeckoView] Bundle the Firefox printing code in the viewer (bug 1810111)
This may not be enough, on its own, to completely fix [bug 1810111](https://bugzilla.mozilla.org/show_bug.cgi?id=1810111) however it's impossible for printing to work in GeckoView without this patch.
2023-07-28 14:10:40 +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
0ad5a5551a
Merge pull request #16760 from Snuffleupagus/issue-16759
Avoid eagerly matching "trailer"-strings when searching for incomplete objects in `XRef.indexObjects` (issue 16759, PR 15854 follow-up, bug 1845762)
2023-07-27 18:39:50 +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
Jonas Jenwald
5560643597
Merge pull request #16758 from Snuffleupagus/cMapUrl-standardFontDataUrl-validation
Tweak the `useWorkerFetch` default value checks (PR 15879 follow-up)
2023-07-27 17:52:57 +02:00
calixteman
8679199a2f
Merge pull request #16756 from calixteman/editor_blur_unselected
[Editor] Blur unselected editors
2023-07-27 16:57:20 +02:00
Jonas Jenwald
c09bd5568c Tweak the useWorkerFetch default value checks (PR 15879 follow-up)
Currently we accidentally accept `cMapUrl` and `standardFontDataUrl` parameters that are empty strings or `null`, since e.g. `new URL(null, document.baseURI)` doesn't throw, when validating the `useWorkerFetch` parameter via the `isValidFetchUrl` helper function.
Please note that we are currently failing gracefully in this case, as intended, however the warning-messages printed in the console are perhaps less helpful without this patch.
2023-07-27 16:26:39 +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
Jonas Jenwald
611acf52c4
Merge pull request #16755 from Snuffleupagus/_keyboardManager-proto
[Editor] Reduce a bit of duplication on `_keyboardManager` initialization
2023-07-27 12:43:11 +02:00
Jonas Jenwald
2fbfd9517f Remove the unneeded error-handling at the end of PDFViewerApplication.run
This is quite old code, however the error-handling no longer seems necessary for a couple of reasons:
 - The `PDFViewerApplication.open` method is asynchronous, which means that it cannot throw a "raw" `Error` and the try-catch is not needed in that case.
 - None of the other affected methods should throw, and if they do that'd rather indicate an *implementation* error in the code.
 - Finally, and most importantly, with the `PDFViewerApplication.run` method now being asynchronous an (unlikely) `Error` thrown within it will lead to a rejected `Promise` and not affect execution of other code.
2023-07-27 12:14:14 +02:00
Jonas Jenwald
ecf95e552f Simplify handling of any ViewHistory errors during document loading in the viewer
We can use modern JavaScript features, in this case optional chaining, to (ever so slightly) simplify how `ViewHistory` errors are handled.

Also, use arrow functions when handling a few other (very rare) errors during loading since that's a tiny bit shorter.
2023-07-27 12:12:19 +02:00
Jonas Jenwald
34f2e7d4f9 [Editor] Reduce a bit of duplication on _keyboardManager initialization
The way that the callback-methods are specified feels unnecessarily verbose, however we can introduce a short-hand to improve this.

Also, adds a couple of new-lines to improve overall readability.
2023-07-27 11:42:01 +02:00
calixteman
82faae26c0
Merge pull request #16750 from calixteman/editor_keeboard_freetext
[Editor] Add the possibility to move an empty freetext editor with the keyboard (bug 1845088)
2023-07-27 11:38:17 +02:00
Jonas Jenwald
ef776eaacd
Merge pull request #16753 from Snuffleupagus/eslint-prefer-ternary
Enable the `unicorn/prefer-ternary` ESLint plugin rule
2023-07-27 10:39:12 +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
Jonas Jenwald
c0fe96b8fe Additional *manual* unicorn/prefer-ternary changes
Not all cases could be automatically fixed, and the changes also triggered a number of `prefer-const` errors that needed to be handled manually.
2023-07-27 09:48:24 +02:00
Jonas Jenwald
674e7ee381 Enable the unicorn/prefer-ternary ESLint plugin rule
To limit the readability impact of these changes, the `only-single-line` option was used; please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-ternary.md

These changes were done automatically, using the `gulp lint --fix` command.
2023-07-27 09:18:26 +02:00
calixteman
8f83a1359e
Merge pull request #16749 from calixteman/editor_mac_shortcut
[Editor] Use the same keyboard shortcut as in Preview to move an editor on mac
2023-07-26 21:40:20 +02:00
Calixte Denizet
9078587422 [Editor] Use the same keyboard shortcut as in Preview to move an editor on mac 2023-07-26 21:23:38 +02:00
calixteman
7f634e468f
Merge pull request #16746 from calixteman/editor_keyboard_movable
[Editor] Make editors movable in using the keyboard (bug 1845088)
2023-07-26 21:17:15 +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
calixteman
a2eca47ed1
Merge pull request #16748 from calixteman/hcm_toolbar_button
Improve rendering of buttons in the toolbar in HCM (bug 1845515)
2023-07-26 17:20:38 +02:00
Calixte Denizet
7ce4e288e1 Improve rendering of buttons in the toolbar in HCM (bug 1845515)
With this patch, in HCM, make a button visible when it's active and
add an outline around toggled buttons when they're hovered.
2023-07-26 16:49:55 +02:00
calixteman
48cc67f17e
Merge pull request #16741 from calixteman/editor_no_ed_when_pinching
[Editor] Avoid to trigger an editor creation when pinching on a touchscreen
2023-07-25 20:25:30 +02:00
calixteman
e40fd171e9
Merge pull request #16740 from calixteman/editor_keyevent_on_window
[Editor] Set keyboard events on window instead of the main container
2023-07-25 19:54:29 +02:00
Jonas Jenwald
7448e89d1f
Merge pull request #16738 from Snuffleupagus/debugger-import
Re-factor how the `debugger` accesses API-functionality
2023-07-25 19:31:15 +02:00
Calixte Denizet
6b545d666e [Editor] Avoid to trigger an editor creation when pinching on a touch screen 2023-07-25 19:00:05 +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
calixteman
86165a7ba6
Merge pull request #16737 from calixteman/insets
[Editor] Use inset instead of top/left in css
2023-07-25 15:17:29 +02:00
Jonas Jenwald
690adb093e Re-factor how the debugger accesses API-functionality
Given that the `debugger` is loaded as a module we can use "top level await" in development mode to access the necessary API-functionality, which removes the need to manually pass in the required properties.
2023-07-25 15:08:02 +02:00
Calixte Denizet
84e6154b0f [Editor] Use inset instead of top/left in css 2023-07-25 15:05:35 +02:00
calixteman
e00629966d
Merge pull request #16732 from calixteman/editor_resize
[Editor] Add some resizers all around an editor (bug 1843302)
2023-07-25 14:17:09 +02:00
Calixte Denizet
2688bf2ebd [Editor] Add some resizers all around an editor (bug 1843302)
- it'll improve the way to resize images: diagonally (in keeping ratio between dimensions)
  or horizontally/vertically.
- the resizer was almost invisible in HCM.
- make a resize undoable/redoable.
2023-07-25 13:53:30 +02:00
Jonas Jenwald
24d01ec682
Merge pull request #16735 from Snuffleupagus/reduced-Planck-constant-copy
Fix copying of the reduced Planck constant
2023-07-24 21:57:12 +02:00
calixteman
f508084c21
Merge pull request #16736 from calixteman/editor_avoid_text_selection
[Editor] Avoid spurious text selection when double clicking to add a FreeText
2023-07-24 21:03:45 +02:00
Calixte Denizet
3f58e25961 [Editor] Avoid spurious text selection when double clicking to add a FreeText
In order to reproduce the original issue:
 - switch to freetext mode
 - add a text somewhere
 - double click outside and add some text
 - repeat the previous step several times

no text is selected during the edition.
2023-07-24 19:38:00 +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
Jonas Jenwald
fb3ae82820
Merge pull request #16733 from Snuffleupagus/node-polyfills-catch
[api-minor] Attempt to prevent Node.js-specific polyfill errors from completely breaking the library
2023-07-24 14:50:56 +02:00
Jonas Jenwald
d188b66af6 [api-minor] Attempt to prevent Node.js-specific polyfill errors from completely breaking the library
The existing Node.js-specific polyfills depend on the `node-canvas` package, which has unfortunately (repeatedly) shown to cause trouble for many users. We attempted to improve the situation by listing the relevant packages as `optionalDependencies`, but that didn't seem to really fix the problem.

With this patch the library should be able to load in Node.js-environments even if polyfilling fails, and any errors will instead occur during rendering. Obviously this is *not* a proper solution, since it basically moves the problem to another part of the code-base.
However for certain "simpler" use-cases, such as e.g. text-extraction, these changes should hopefully improve general usability of the PDF.js library in Node.js-environments.

*Please note:* For most PDF documents rendering should still work though, since `DOMMatrix` is *currently* only used with Patterns and `Path2D` only with Type3-fonts and Patterns.
2023-07-24 13:00:34 +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
calixteman
1e69b6a03d
Merge pull request #16726 from calixteman/gv_fix_dl_button
[GeckoView] Fix string for download button
2023-07-24 09:54:41 +02:00
Tim van der Meij
4a0468a601
Merge pull request #16730 from timvandermeij/vinyl-fs
Remove the `vinyl-fs` dependency
2023-07-23 18:43:28 +02:00
Tim van der Meij
b7b3636ec2
Remove the vinyl-fs dependency
In Gulp 4, which we use for years now, the `gulp.src()` function
supports the `removeBOM` option to disable the default BOM stripping,
so this commit uses that to get rid of our `vinyl-fs` dependency.

Note that this actually makes disabling BOM stripping work again. It's
currently broken because in `vinyl-fs` 3, that we already use since 2018
in commit 95de23e, the `stripBOM` option was renamed to `removeBOM`, so
the current code doesn't actually disable BOM stripping which we now
confirmed and sadly broke for years without anyone noticing. Most likely
this is because the BOM is not required for UTF-8 documents, but while
not necessary it also can't hurt to have it for tools that use it to
determine if a document is UTF-8.
2023-07-23 18:33:20 +02:00
Tim van der Meij
8b2380823c
Merge pull request #16729 from Snuffleupagus/rm-useOnlyCssZoom-pref
Remove the `useOnlyCssZoom` preference
2023-07-23 13:32:09 +02:00
Tim van der Meij
7e8ee4f0b9
Merge pull request #16728 from Snuffleupagus/update-packages
Update packages and translations
2023-07-23 13:30:34 +02:00
Jonas Jenwald
66645d30cc Remove the useOnlyCssZoom preference
*Please note:* This only removes the preference itself, however both the viewer-option and the actual implementation is still available.

The `useOnlyCssZoom` functionality was only ever used, by default, in the PDF Viewer for the B2G/FirefoxOS project (which was abandoned years ago). Given that CSS-only zooming can easily make the document look blurry even at low zoom levels, this functionality was only intended for low-powered mobile devices.
Hence it seems reasonable to remove the `useOnlyCssZoom` preference now, since neither the default viewer nor the GeckoView-specific viewer uses this functionality.
2023-07-23 11:20:36 +02:00
Jonas Jenwald
fd6b9d7b48 Update l10n files 2023-07-23 09:54:11 +02:00
Jonas Jenwald
c073484241 Update npm packages 2023-07-23 09:49:53 +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
74642b59af [GeckoView] Fix string for download button 2023-07-22 16:54:48 +02:00
Tim van der Meij
aed7f6edcf
Merge pull request #16725 from Snuffleupagus/stylelint-update
Update Stylelint to the latest version
2023-07-22 13:55:52 +02:00
Tim van der Meij
4f72251322
Merge pull request #16724 from Snuffleupagus/eslint-no-var-firefox
Enable the ESLint `no-var rule` in the `extensions/firefox/` folder
2023-07-22 13:53:58 +02:00
Jonas Jenwald
198f89ffce Update Stylelint to the latest version
Trying to update Stylelint to version `15.10.1`, and beyond, broke linting. Looking at the changes the issue appears to be that the `bin/stylelint.js` file was replaced with `bin/stylelint.mjs` instead, which our `gulp lint` runner wasn't able to automatically find; see https://github.com/stylelint/stylelint/compare/15.10.0...15.10.1
2023-07-22 11:34:14 +02:00
Jonas Jenwald
8a2320bd18 Use modern JavaScript more in the extensions/firefox/tools/l10n.js file
- Introduce optional chaining in a few spots.
 - Use more logical OR assignment in the code.
2023-07-22 10:12:43 +02:00
Jonas Jenwald
25cb4883e9 Enable the ESLint no-var rule in the extensions/firefox/ folder
This was done automatically, using the `gulp lint --fix` command.
2023-07-22 10:05:37 +02:00
Jonas Jenwald
6d783d2722
Merge pull request #16715 from Snuffleupagus/eslint-no-lonely-if
Enable the `no-lonely-if` ESLint rule
2023-07-22 09:33:48 +02:00
Jonas Jenwald
c018070e80 Enable the no-lonely-if ESLint rule
These changes were mostly done automatically, using `gulp lint --fix`, and only a few spots with comments needed manual tweaking; please see https://eslint.org/docs/latest/rules/no-lonely-if
2023-07-21 20:10:44 +02:00
Jonas Jenwald
abb24f82fb
Merge pull request #16714 from TaTo30/xfa-select-storage
XFA - Set storage values to select and option elements
2023-07-21 20:09:32 +02:00
TaTo30
18619ce4c9 [XFA] Update select and option element attributes with the stored data and
removes the 'selected' attribute from option element if it's not actually selected.
2023-07-21 10:32:33 -06:00
calixteman
d74b68cd09
Merge pull request #16722 from calixteman/dont_set_filter
Don't uselessly change the filter when drawing (bug 1508765)
2023-07-21 14:37:54 +02:00
calixteman
d9278200d7
Merge pull request #16721 from calixteman/bug1844583
Don't get the text content for an annotation when /NeedAppearances is true (bug 1844583)
2023-07-21 13:54:50 +02:00
Calixte Denizet
9a4750fee5 Don't uselessly change the filter when drawing
When profiling the pdf in https://bugzilla.mozilla.org/show_bug.cgi?id=1508765,
I noticed that half a second was spent to set the filter to "none".
2023-07-21 13:29:29 +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
calixteman
1a69b6ad64
Merge pull request #16720 from calixteman/bug1844576
Text annotations must use their own canvas when their appearance is generated (bug 1844576)
2023-07-21 10:30:55 +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
calixteman
2a508b95e1
Merge pull request #16719 from calixteman/bug1844625
[Editor] Allow to delete an editor in using the Delete key (aka fn+backspace) (bug 1844625)
2023-07-20 19:42:38 +02:00
Calixte Denizet
cd97fcb414 [Editor] Allow to delete an editor in using the Delete key (aka fn+backspace) (bug 1844625) 2023-07-20 19:08:54 +02:00
Jonas Jenwald
7220b93911
Merge pull request #16717 from Snuffleupagus/saveDocument-resetNewTemporaryRef
Don't reset temporary XRef-entries during saving (PR 16392 follow-up)
2023-07-20 17:58:18 +02:00
Jonas Jenwald
88524bf9ae Don't reset temporary XRef-entries during saving (PR 16392 follow-up)
*Please note:* I'm not aware of any bugs caused by this, however that might be more luck than anything else.

In PR 16392 the `incrementalUpdate` function, and all of its various helpers, were made asynchronous. However the call-site in `src/core/worker.js` wasn't updated, which means that we currently reset temporary XRef-entries while saving is ongoing.
2023-07-20 15:49:59 +02:00
calixteman
0702663b7d
Merge pull request #16492 from calixteman/clip_path
[Annotation] Use the clip-path property when an annotation has some quad points
2023-07-20 15:01:27 +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
calixteman
dca4bc0f24
Merge pull request #16713 from calixteman/draw_bg
Draw correctly background images in ref tests
2023-07-19 21:18:04 +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
calixteman
9f390755b0
Merge pull request #16709 from calixteman/bug1844293
[Editor] Bind redo action on meta+shift+z on mac (bug 1844293)
2023-07-19 12:01:58 +02:00
Calixte Denizet
295eb13a44 [Editor] Bind redo action on meta+shift+z on mac (bug 1844293) 2023-07-19 11:17:50 +02:00
Jonas Jenwald
f19991a36f
Merge pull request #16707 from mozilla/dependabot/npm_and_yarn/word-wrap-1.2.4
Bump word-wrap from 1.2.3 to 1.2.4
2023-07-19 08:41:03 +02:00
dependabot[bot]
186a6fd0cb
Bump word-wrap from 1.2.3 to 1.2.4
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-18 20:14:51 +00:00
calixteman
e83febcbb6
Merge pull request #16706 from calixteman/bug1844036
[Editor] Don't forget to generate non-missing images when printing (bug 1844036)
2023-07-18 17:01:10 +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
43fc78899f
Merge pull request #16698 from Snuffleupagus/src-display-rm-require
Remove most build-time `require`-calls from the `src/display/`-folder
2023-07-18 11:35:57 +02:00
Jonas Jenwald
d9350c3899 Temporarily stop running gulp typestest in GitHub Actions
This is necessary to unblock the previous patch, which removes more build-time `require`-calls from the `src/display/` folder.
2023-07-18 09:07:32 +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
e81c084a92
Merge pull request #16703 from Snuffleupagus/babel-corejs
[api-minor] Let Babel handle the necessary `core-js` polyfills automatically
2023-07-17 19:45:06 +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
Jonas Jenwald
67303b16f1 [api-minor] Let Babel handle the necessary core-js polyfills automatically
In the last couple of years we've been quicker to remove support for older browsers/environments, which means that at this point in time we don't bundle that many polyfills. (The polyfills are also generally simpler nowadays, ever since we removed support for e.g. Internet Explorer.)
Rather than having to *manually* handle the polyfills, we can actually let Babel take care of bundling the necessary polyfills for us; please refer to https://babeljs.io/docs/babel-preset-env

The only exception here is the Node.js-specific compatibility-code, which is moved into the `src/display/node_utils.js` file. This ought to be fine since workers are not available/used in Node.js-environments.

*Please note:* For the `legacy`-builds this will increase the size of the *built* files, however that seems like a very small price to pay in order to simplify maintenance of the general PDF.js library.
2023-07-17 16:42:08 +02:00
calixteman
9db65ad083
Merge pull request #16702 from calixteman/editor_2_decimals
[Editor] Use 2 decimals for editor positions and dimensions
2023-07-17 15:43:26 +02:00
Calixte Denizet
983b269e26 [Editor] Use 2 decimals for editor positions and dimensions
I noticed that after adding an image in issue16278.pdf, the image was constantly
resizing itself.
It appears that it's because of rounding errors.
2023-07-17 15:08:09 +02:00
calixteman
67e19171c4
Merge pull request #16689 from calixteman/bug1843303
[Editor] Avoid to have some part of an editor outside its page (bug 1843303)
2023-07-17 14:59:21 +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
717c766a42
Merge pull request #16701 from Snuffleupagus/gv-fix-toolbar-l10n
[GeckoView] Fix l10n of the download toolbar-button (PR 16340 follow-up)
2023-07-17 13:16:49 +02:00
Jonas Jenwald
8614621d8d [GeckoView] Fix l10n of the download toolbar-button (PR 16340 follow-up)
Localization of this button broke in PR 16340, which I assume was completely accidental, since the download-button now tries to access a l10n-id that was removed some time ago (see PR 15617).
Note how loading even the development viewer, i.e. http://localhost:8888/web/viewer-geckoview.html#locale=en-US, currently logs l10n-warnings on the `master` branch.
2023-07-17 11:47:11 +02:00
Tim van der Meij
d03a8d0efc
Merge pull request #16687 from Snuffleupagus/rm-more-require
Re-factor the `PDFScriptingManager`-class for the viewer-components
2023-07-16 15:16:07 +02:00
Tim van der Meij
8765306203
Merge pull request #16697 from Snuffleupagus/eslint-more-unicorn
Enable more ESLint `unicorn` plugin rules
2023-07-16 15:10:35 +02:00
Jonas Jenwald
9660ca53af Enable more ESLint unicorn plugin rules
- `prefer-array-some`, which didn't require any code changes; please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-some.md

 - `prefer-modern-math-apis`, which should be fine given the currently supported browsers; please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-modern-math-apis.md
2023-07-16 09:24:14 +02:00
Jonas Jenwald
bad4bfffdf Remove the require from the web/pdfjs.js
Having a `require` in this file has never made sense in e.g. the Firefox PDF Viewer and shouldn't really be necessary.
Possibly the idea was to facilitate some kind of third-party bundling, however the *built* `pdf.js` file has always exposed the API-contents globally.
2023-07-16 08:51:46 +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
337cba736e [ESM] Remove the remaining require from the gulpfile 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
22c0bf4ec2
Merge pull request #16693 from Snuffleupagus/update-packages
Update packages and translations
2023-07-16 08:21:13 +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
b05c2e0343 Update l10n files 2023-07-15 10:44:39 +02:00
Jonas Jenwald
f84657d837 Address formatting changes from Prettier version 3 2023-07-15 10:44:39 +02:00
Jonas Jenwald
1a4bfd2fc3 Update npm packages
Note that while some packages increased the *major* version, it doesn't appear to cause any breakage as far as I can tell.
2023-07-15 10:44:30 +02:00
calixteman
ee373b313b
Merge pull request #16690 from calixteman/stamp_resize
[Editor] Resize the image when the page is zoomed
2023-07-14 12:16:44 +02:00
Calixte Denizet
5a692b2c33 [Editor] Resize the image when the page is zoomed
In order to reproduce the issue:
 - scale down the image
 - zoom the page and the image is pixellated
So this patch allow to redraw the image when zooming.
2023-07-13 20:36:23 +02:00
calixteman
36fc34ebe8
Merge pull request #16686 from calixteman/bug1843255
[Editor] Always use the data url when loading a SVG in order to avoid CSP issue (bug 1843255)
2023-07-13 15:12:49 +02:00
Calixte Denizet
ed42577d9c [Editor] Always use the data url when loading a SVG in order to avoid CSP issue (bug 1843255) 2023-07-13 14:10:28 +02:00
Jonas Jenwald
762d86a59e
Merge pull request #16683 from Snuffleupagus/app-isOffscreenCanvasSupported
Access the `isOffscreenCanvasSupported` option *once* in `PDFViewerApplication._initializeViewerComponents`
2023-07-12 21:44:34 +02:00
Jonas Jenwald
b449da31ca
Merge pull request #16678 from Snuffleupagus/writeStream-tweaks
Tweak the `writeStream` implementation slightly
2023-07-12 21:43:01 +02:00
Jonas Jenwald
040d5bb294
Merge pull request #16675 from Snuffleupagus/pr-16659-followup
Re-enable editing, if necessary, when exiting PresentationMode (PR 16659 follow-up)
2023-07-12 21:41:43 +02:00
calixteman
46cec96900
Merge pull request #16642 from calixteman/issue16633
[Editor] Try to make the position of an edited FreeText the more accurated as possible
2023-07-12 21:08:16 +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
7e04ca395f Access the isOffscreenCanvasSupported option *once* in PDFViewerApplication._initializeViewerComponents
There's no good reason for getting this option multiple times in the same method. Also, we can slightly re-factor how the `editorStampButton` is made visible.
2023-07-12 17:33:20 +02:00
Jonas Jenwald
5cfe792349 Tweak the writeStream implementation slightly
- Do the /Filter and /DecodeParms lookup in parallel, since that ought to be a *tiny* bit more efficient.
 - Avoid code-duplication when `CompressionStream` isn't supported, since we already have a fallback code-path at the end of the function.
2023-07-12 13:24:02 +02:00
Jonas Jenwald
7daa6b5fd8 Re-enable editing, if necessary, when exiting PresentationMode (PR 16659 follow-up)
This regressed in PR 16659, when the signature of the `PDFViewer.annotationEditorMode`-setter was changed, and it currently leads to an Error being thrown when exiting PresentationMode.
2023-07-11 22:34:20 +02:00
Jonas Jenwald
73d650af3e
Merge pull request #16669 from Snuffleupagus/esm-builder
[ESM] Convert the `external/builder/`-folder to use standard modules
2023-07-11 12:29:33 +02:00
Jonas Jenwald
5174232326 [ESM] Convert the external/builder/-folder to use standard modules 2023-07-11 11:38:59 +02:00
Jonas Jenwald
bcf14a49c0
Merge pull request #16668 from Snuffleupagus/esm-gulpfile
[ESM] Convert the `gulpfile` to use standard modules
2023-07-11 11:38:24 +02:00
calixteman
09d1be72f4
Merge pull request #16672 from calixteman/cheat_editorStamp_svg
[Editor] Cheat the stamp editor icon to make a linter in m-c happy
2023-07-11 09:59:32 +02:00
Calixte Denizet
414ea4a365 [Editor] Cheat the stamp editor icon to make a linter in m-c happy
At some point we won't use this icon anymore in the build-in pdf viewer
but we'll the one already in the m-c tree.
2023-07-10 21:18:05 +02:00
Jonas Jenwald
0bc9012b8f [ESM] Convert the gulpfile to use standard modules
This is a necessary intermediate step to allow converting files in the `external/builder/` folder.
2023-07-09 15:58:19 +02:00
Tim van der Meij
35202ec0f3
Merge pull request #16671 from Snuffleupagus/esm-parseDefaultPreferences
[ESM] Convert the "default preferences"-handling to use `import()` syntax
2023-07-09 15:38:30 +02:00
Tim van der Meij
1972b7311b
Merge pull request #16667 from Snuffleupagus/esm-cmaps
[ESM] Convert the "cmaps"-task to use `import()` syntax
2023-07-09 15:33:57 +02:00
Tim van der Meij
c0cc7f3eca
Merge pull request #16666 from Snuffleupagus/esm-wintersmith
[ESM] Convert the "wintersmith"-task to use `import()` syntax
2023-07-09 15:32:10 +02:00
Tim van der Meij
5a8ecbf560
Merge pull request #16665 from Snuffleupagus/esm-test
[ESM] Convert *most* of `test`-folder to use standard modules
2023-07-09 15:30:13 +02:00
Jonas Jenwald
6c601d3922 [ESM] Convert the "default preferences"-handling to use import() syntax
Unfortunately I wasn't able to come up with a *simple* way to just replace the synchronous `require`-call, since we need to ensure that the default preferences are available when bundling starts.
Hence this patch adds a new intermediate parsing-step in all the relevant gulp-tasks, but this shouldn't affect build-times noticeable since the amount of extra parsing is very small.

*Please note:* It's very possible that there's a better way to handle this, however I figured that unblocking further ESM-work is more important than a "perfect" solution.
2023-07-09 11:54:11 +02:00
Tim van der Meij
3efb276695
Merge pull request #16664 from Snuffleupagus/esm-terser
[ESM] Convert `parseMinified` to use `import()` syntax
2023-07-08 19:43:02 +02:00
Tim van der Meij
656c6d86fc
Merge pull request #16663 from Snuffleupagus/esm-importL10n
[ESM] Convert the `external/importL10n`-folder to use standard modules
2023-07-08 19:40:52 +02:00
Jonas Jenwald
f012fc5e70 [ESM] Convert the "cmaps"-task to use import() syntax 2023-07-08 18:52:58 +02:00
Tim van der Meij
42edc4d895
Merge pull request #16630 from Rob--W/crx-url-hash-init
Correct recognition of fragments at document load
2023-07-08 14:05:33 +02:00
Tim van der Meij
1567d022d9
Merge pull request #16631 from Rob--W/crx-remove-old-chrome-compat-code
[CRX] Drop code supporting ancient Chrome versions
2023-07-08 14:02:30 +02:00
Jonas Jenwald
ac3661972b [ESM] Convert the "wintersmith"-task to use import() syntax 2023-07-08 13:50:19 +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
adfee2a723 [ESM] Convert parseMinified to use import() syntax 2023-07-08 10:01:16 +02:00
Jonas Jenwald
cec2a9a03f Update l10n files 2023-07-08 09:36:47 +02:00
Jonas Jenwald
a650fcd634 [ESM] Convert the external/importL10n-folder to use standard modules 2023-07-08 09:36:32 +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
calixteman
52c98eb751
Merge pull request #16659 from calixteman/edit_freetexts
[Editor] Edit an existing FreeText annotation in double-clicking on it (bug 1787298)
2023-07-07 22:02:11 +02:00
Jonas Jenwald
c625230c71
Merge pull request #16661 from Snuffleupagus/issue-16660
Don't try to hide an already invisible PopupAnnotation (issue 16660)
2023-07-07 20:47:38 +02:00
Jonas Jenwald
559ea194f2 Don't try to hide an already invisible PopupAnnotation (issue 16660) 2023-07-07 19:13:48 +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
calixteman
c33e6ceb03
Merge pull request #16650 from calixteman/editor_allow_svg
[Editor] Support svg images in the stamp annotation
2023-07-07 16:30:12 +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
Jonas Jenwald
091266c6fe
Merge pull request #16648 from Snuffleupagus/AppearanceStreamEvaluator-setFillColorSpace
Improve `parseAppearanceStream` to handle more "complex" ColorSpaces
2023-07-06 18:30:17 +02:00
Jonas Jenwald
c5caa98e8d
Merge pull request #16649 from Snuffleupagus/stamp-l10n
[Editor] Add l10n-strings for the Stamp-editor (PR 16585 follow-up)
2023-07-06 18:04:08 +02:00
Jonas Jenwald
7a896d1c4b [Editor] Add l10n-strings for the Stamp-editor (PR 16585 follow-up)
This ought to have been included in PR 16585, since we obviously need default (en-US) l10n-strings for this feature.
2023-07-06 17:57:29 +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
calixteman
8281bb8858
Merge pull request #16585 from calixteman/editor_stamp_1
[Editor] Add a basic stamp editor  (bug 1790255)
2023-07-06 12:21:50 +02:00
Jonas Jenwald
716493f10a
Merge pull request #16646 from Snuffleupagus/default_appearance-CMYK-typos
Fix typos when handling CMYK colors in `src/core/default_appearance.js`
2023-07-06 12:05:06 +02:00
Calixte Denizet
37bd78c707 [Editor] Add a basic stamp editor (bug 1790255)
For now it allows to add a stamp annotation with an image selected from the file system.
2023-07-06 11:27:50 +02:00
Jonas Jenwald
174d04fd27 Fix typos when handling CMYK colors in src/core/default_appearance.js
Note how we're accidentally using the wrong operator when trying to parse CMYK colors. I'm not aware of any bugs caused by this, since it seems uncommon in practice for annotations to specify text-colors in CMYK format.
2023-07-06 11:12:16 +02:00
calixteman
2a837ba0b5
Merge pull request #16645 from calixteman/editor_simplify_aspectratio
[Editor] Use css aspect-ratio property to keep the aspect ratio during resize
2023-07-06 10:17:03 +02:00
Calixte Denizet
fab1157549 [Editor] Use css aspect-ratio property to keep the aspect ratio during resize
It slightly simplifies the implementation and it avoids some possible artifacts
when resizing too quickly.
2023-07-06 09:21:37 +02:00
calixteman
683cdf44db
Merge pull request #16641 from calixteman/mv_aspectratio_to_editor
[Editor] Move the 'keep aspect ratio' stuff to the AnnotationEditor level
2023-07-05 21:03:00 +02:00
Calixte Denizet
caf3462911 [Editor] Move the 'keep aspect ratio' stuff to the AnnotationEditor level
It'll help to avoid code duplication between the different editors having
this feature.
2023-07-05 18:32:58 +02:00
calixteman
66fc19b272
Merge pull request #16640 from calixteman/freetext_ap
[Editor] When saving/printing a FreeText, use the identity matrix for the AP and set the cm when rendering it
2023-07-05 17:53:36 +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
calixteman
6d82f7f66f
Merge pull request #16637 from calixteman/issue16636
[Editor] Fix dimensions of a rotated FreeText after a dimensions change
2023-07-05 09:41:49 +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
9802bd805e
Merge pull request #16635 from Snuffleupagus/README-tweaks
Tweak the README slightly
2023-07-04 13:25:16 +02:00
Jonas Jenwald
e96c89d7a1 Tweak the README slightly
- Update the "Getting the Code" section to specifically mention Mozilla Firefox, since while the development viewer *works* it may look slightly "broken" in Chromium-based browsers. (This is caused by a lack of support for unprefixed CSS properties, e.g. `mask-image`, however this does *not* affect the built PDF.js viewer.)

 - Remove the Twitter-link, since that account has not been updated since 2016 (i.e. over seven years ago).
2023-07-04 11:32:25 +02:00
Rob Wu
70db938fe7 [CRX] Drop code supporting ancient Chrome versions 2023-07-02 17:23:18 +02:00
Rob Wu
f2753d6220 [CRX] Avoid encoding the fragment in file key
Semantically, it is more correct to encode the fragment in the URL
instead of the URL-encoded `file` query parameter. This shouldn't matter
in practice, because `rewriteUrlClosure` in `chromecom.js` decodes the
`file` parameter and restores the fragment. However, as #16625 shows,
there was a case where this did not work as expected.
2023-07-02 15:31:35 +02:00
Tim van der Meij
8b50836d76
Merge pull request #16629 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-07-02 15:28:47 +02:00
Rob Wu
1d07ef401e [CRX] Re-initialize initialBookmark after URL rewrite
`PDFViewerApplication` reads from `location.hash` to initialize
`initialBookmark`. But when extensions/chromium/pdfHandler.js prepares
the redirect URL, the reference fragment is encoded instead of bare.
`rewriteUrlClosure` in `chromecom.js` is responsible for decoding the
URL, but that currently runs too late.

To fix this, update `initialBookmark` after rewriting the URL.

This was not a problem in the past because `rewriteUrlClosure` in
`chromecom.js` executed before the initialization of `initialBookmark`.
2023-07-02 15:28:33 +02:00
Tim van der Meij
f3df202a31
Bump versions in pdfjs.config 2023-07-02 15:22:05 +02:00
Tim van der Meij
2c74323e3d
Merge pull request #16628 from Snuffleupagus/app-webViewerInitialized-inline
Inline the `webViewerInitialized` function in `PDFViewerApplication.run`
2023-07-02 13:27:12 +02:00
Jonas Jenwald
58252a528d Inline the webViewerInitialized function in PDFViewerApplication.run
Given the size of this function respectively method, it seems reasonable to simply inline the `webViewerInitialized`-code here.
2023-07-02 11:43:28 +02:00
Jonas Jenwald
cae8fe4c7e Move the setTitleUsingUrl-call into PDFViewerApplication.initPassiveLoading
This seems overall nicer, rather than having to "manually" call this when initializing passive loading.
2023-07-02 11:43:16 +02:00
Tim van der Meij
73b6ee5325
Merge pull request #16612 from erm1116/fix-contentscript-updateEmbedElement
Fix reading property of null object in chrome extension's updateEmbedElement function
2023-07-01 13:30:37 +02:00
Tim van der Meij
8a954823b5
Merge pull request #16616 from Snuffleupagus/PDFCursorTools-tweaks
A couple of small tweaks of the `PDFCursorTools` class
2023-07-01 13:04:44 +02:00
Tim van der Meij
e070e730c7
Merge pull request #16627 from Snuffleupagus/rm-Node-Buffer
[api-minor] Stop "supporting" binary data provided as `Buffer` in Node.js environments (PR 16055 follow-up)
2023-07-01 13:00:19 +02:00
Tim van der Meij
366a4ff1e9
Merge pull request #16626 from Snuffleupagus/rm-pageColors-supports-check
[api-minor] Remove the `CSS.supports` checks for the `pageColors`-option in the GENERIC viewer
2023-07-01 12:58:30 +02:00
Tim van der Meij
94015c71ad
Merge pull request #16601 from Rob--W/crx-maintained-again
Revert "Temporarily stop listing the official Chrome extension in the main README"
2023-07-01 12:54:45 +02:00
Tim van der Meij
d057caedf5
Merge pull request #16607 from Rob--W/lint-chromium-actionable-warnings
Improve lint-chromium to output actionable information
2023-07-01 12:53:56 +02:00
Jonas Jenwald
25bac064d8 [api-minor] Stop "supporting" binary data provided as Buffer in Node.js environments (PR 16055 follow-up)
Given that the PDF.js library has never officially supported/documented that binary data can be provided as a `Buffer`, and that it's been explicitly deprecated in *four* releases, it seems reasonable that we outright reject such data instead (to reduce the amount of Node.js specific code-paths).
2023-07-01 10:34:18 +02:00
Jonas Jenwald
be775143b2 [api-minor] Remove the CSS.supports checks for the pageColors-option in the GENERIC viewer
Given the browsers that we currently support it's probably not necessary to keep the checks for the color-values.
2023-06-30 18:37:16 +02:00
Jonas Jenwald
ac937a9b3c
Merge pull request #16622 from Snuffleupagus/image_decoders-rm-polyfill-comment
Remove outdated polyfill comment from `src/pdf.image_decoders.js`
2023-06-30 17:18:45 +02:00
erm1116
fcf38f6ae9 fix: use node.insertBefore for adding embed element 2023-06-30 22:38:59 +09:00
Jonas Jenwald
ffa9795ca9
Merge pull request #16620 from Snuffleupagus/AnnotationStorage-transfers
Move the `transfers` computation into the `AnnotationStorage` class
2023-06-30 14:28:55 +02:00
Jonas Jenwald
2f80fc1b3d
Merge pull request #16623 from Snuffleupagus/fully-rm-render-canvasFactory
Fully remove the `canvasFactory` option from `PDFPageProxy.render` (PR 16242 follow-up)
2023-06-30 10:25:45 +02:00
Jonas Jenwald
64aa28953d Fully remove the canvasFactory option from PDFPageProxy.render (PR 16242 follow-up)
We've now been throwing an Error in *three* releases if the `canvasFactory` option is provided, hence it ought to be fine to stop doing that and simply ignore the option instead.
2023-06-30 09:21:45 +02:00
Jonas Jenwald
d3723cec95 Remove outdated polyfill comment from src/pdf.image_decoders.js
Given that none of the mentioned polyfills are used any more, the comment is no longer helpful.
2023-06-30 07:29:45 +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
Jonas Jenwald
f373fcb356 Remove a couple of unused options from the GrabToPan constructor
These options are completely unused in the PDF.js viewer, and given that the last update of the `GrabToPan`-code from upstream was in 2016 it shouldn't hurt to remove them.
2023-06-29 13:16:10 +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
Jonas Jenwald
d329267926 Use Element.scrollTo unconditionally in the GrabToPan class
According to the MDN compatibility data this is available in all browsers that we currently support; please see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo#browser_compatibility
2023-06-28 12:43:36 +02:00
Jonas Jenwald
4f82dd3932 Create a GrabToPan-instance lazily in the PDFCursorTools class
Unless the user enables the "HandTool" we don't actually need to create a `GrabToPan`-instance.
2023-06-28 12:43:36 +02:00
Jonas Jenwald
789e318cf7 A couple of small tweaks of the PDFCursorTools class
- Introduce a few private fields for internal state.

 - Inline a small method at its only call-site.
2023-06-28 12:43:34 +02:00
Rob Wu
8330390757 Improve lint-chromium to output actionable information
Before this commit, lint-chromium complained without an obvious course
of action:

> Warning: Pref objects doesn't have the same length.
> Error: chromium/preferences_schema is not in sync

With this commit, the error message is more actionable:

> Warning: extensions/chromium/preferences_schema.json does not contain an entry for pref: enableFloatingToolbar
> Error: chromium/preferences_schema is not in sync
2023-06-28 12:30:21 +02:00
Jonas Jenwald
50488d7a47
Merge pull request #16608 from Snuffleupagus/PDFPageView-refactor-filterFactory
Re-factor how HCM highlight-filters are handled in the viewer components (PR 16593 follow-up)
2023-06-27 15:13:00 +02:00
Jonas Jenwald
a024cd0127 Re-factor how HCM highlight-filters are handled in the viewer components (PR 16593 follow-up)
This is something that I completely overlooked during review of PR 16593, since the idea is (obviously) that the viewer-components should be usable as-is without the user needing to manually pass in any *additional* parameters.

To support this we can very easily expose the current `FilterFactory`-instance on the `PDFPageProxy`-class[1], and if needed initialize the highlight-filters when initializing the page (again limited to the viewer-components).
2023-06-26 23:37:39 +02:00
Rob Wu
9aedf00ffe Revert "Temporarily stop listing the official Chrome extension in the main README"
This reverts commit afabbc28c52ff74fa8ddca5b36c2e005094415e1.
2023-06-26 18:54:11 +02:00
calixteman
c4a61a7692
Merge pull request #16593 from calixteman/popup_hcm
Improve highlightments and popups in HCM (bug 1830850)
2023-06-26 16:34:17 +02:00
Jonas Jenwald
d357906c3f
Merge pull request #16605 from Snuffleupagus/rm-enableFloatingToolbar-pref
[GeckoView] Remove the `enableFloatingToolbar` preference
2023-06-26 15:56:14 +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
80b4708fa3 [GeckoView] Remove the enableFloatingToolbar preference
Note that we'll now display the toolbar unconditionally in GeckoView.
2023-06-26 15:17:03 +02:00
Jonas Jenwald
21383fb2d1
Merge pull request #16602 from Snuffleupagus/gulpfile-TESTING-nullish-coalescing
Use nullish coalescing when handling the `TESTING` build-target
2023-06-26 14:54:45 +02:00
Jonas Jenwald
d7ae2f86e8
Merge pull request #16604 from Snuffleupagus/pdfviewer_api-test-Node
Run the PDF.js-viewer API unit-test in Node.js environments (PR 16592 follow-up)
2023-06-26 14:50:45 +02:00
Calixte Denizet
c519cc821b Improve highlightments and popups in HCM (bug 1830850)
- Modify the text and background colors in popup to fit a11y requirements
- Add a backdrop filter on clickable areas in using a svg filter mapping
  canvas colors to Highlight and HighlightText ones.
2023-06-26 14:45:03 +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
9e7023776e Use nullish coalescing when handling the TESTING build-target
Given that nullish coalescing is now available in all environments/browser that we support, we can (ever so slightly) simplify handling of the `TESTING` build-target.
2023-06-25 16:02:31 +02:00
Tim van der Meij
ccb72073b0
Merge pull request #16598 from Snuffleupagus/update-packages
Update packages and translations
2023-06-25 15:19:01 +02:00
Tim van der Meij
0126774e98
Merge pull request #16600 from Rob--W/crx-min-version-88
[CRX] Set minimum_chrome_version to 88
2023-06-25 15:14:20 +02:00
Rob Wu
1f29baad22 Set minimum_chrome_version to 88
Set minimum_chrome_version to 88 to not distribute an incompatible
version of the extension to older Chrome versions.

See https://github.com/mozilla/pdf.js/issues/13669#issuecomment-1510485564
2023-06-25 14:19:50 +02:00
Jonas Jenwald
a4ddf7baaa Update l10n files 2023-06-25 09:19:03 +02:00
Jonas Jenwald
744b01b637 Update npm packages 2023-06-25 09:18:41 +02:00
Tim van der Meij
fa95bbce12
Merge pull request #16569 from Snuffleupagus/PDFScriptingManager-private
[api-minor] Re-factor the `PDFScriptingManager` class to use private fields/methods
2023-06-24 19:50:17 +02:00
Tim van der Meij
436699b0db
Merge pull request #16592 from Snuffleupagus/rm-viewer-component-default-factory
[api-minor] Remove the default-factories from the viewer components (PR 15811 follow-up)
2023-06-24 19:39:37 +02:00
Tim van der Meij
1ea502aaf9
Merge pull request #16590 from Snuffleupagus/rm-util-unused-const
Remove a couple of unused constants from `src/shared/util.js`
2023-06-24 19:36:11 +02:00
Tim van der Meij
371ee778ff
Merge pull request #16597 from Snuffleupagus/firefox-getPreferences-cleanup
[Firefox] Simplify `FirefoxPreferences._readFromStorage` (PR 16583 follow-up)
2023-06-24 19:34:42 +02:00
Jonas Jenwald
7667f55e45 [Firefox] Simplify FirefoxPreferences._readFromStorage (PR 16583 follow-up)
Now that https://bugzilla.mozilla.org/show_bug.cgi?id=1840064 has landed in mozilla-central we can implement the final piece of clean-up for the `FirefoxPreferences._readFromStorage` method.
2023-06-24 18:37:43 +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
c5e4a22ee0 [api-minor] Remove the default-factories from the viewer components (PR 15811 follow-up)
The changes in PR 15811 have now been included in no less than six official releases, hence it should hopefully be OK to remove this now.
2023-06-23 11:54:30 +02:00
Jonas Jenwald
b4b9419841 Remove a couple of unused constants from src/shared/util.js
These constants were added "speculatively" in PR 10820, almost four years ago, but have never actually been used. We already have issue 10982 that tracks *potentially* extending support for the affected annotation-format, however until that happens I really don't think that we should keep shipping completely unused code in the PDF.js library.

For the MOZCENTRAL build-target, i.e. the Firefox PDF Viewer, this reduces the total bundle size by 1.1 kilo-byte.
2023-06-23 10:44:08 +02:00
Jonas Jenwald
e9ccbd2856
Merge pull request #16587 from Snuffleupagus/test-pdfjs-API
Add a unit-test to check that the *official* PDF.js API exposes the expected functionality
2023-06-22 17:53:45 +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
Jonas Jenwald
25a07d92d0 [Firefox] Stub out the isValidFetchUrl function in MOZCENTRAL builds
This helper function is completely unused in the Firefox PDF Viewer.
2023-06-22 15:02:54 +02:00
Jonas Jenwald
547b8276e6 [api-minor] Re-factor the PDFScriptingManager class to use private fields/methods
- Change (most) fields/methods into private ones, since that's now supported.
 - Tweak the constructor-parameters, and simplify the sandbox initialization w.r.t. the viewer components.
 - Remove some unused function/method parameters.
 - Slightly simplify the "updatefromsandbox"-handler by using local variables and inverting some conditions.
2023-06-22 08:09:58 +02:00
Jonas Jenwald
cca299eeb9 [GeckoView] Ignore Scroll/Spread-modes in the PDFViewer setters
Rather than sprinkling pre-processor statements throughout the viewer-code, simply "disable" the relevant `PDFViewer` setters instead.

Also, given that the GeckoView-specific viewer doesn't have a sidebar we don't actually need to explicitly ignore a `pageMode` during loading.
2023-06-22 08:09:58 +02:00
Jonas Jenwald
03059e1f86
Merge pull request #16573 from Snuffleupagus/move-fixupLangCode
Move the `fixupLangCode` helper function into the `web/genericl10n.js` file
2023-06-21 22:18:26 +02:00
Jonas Jenwald
fe1c36a0ed Move the fixupLangCode helper function into the web/genericl10n.js file
This helper function was added almost two years ago, in PR 13696, and it still has only a single call-site. Furthermore, with the changes made in PR 16572 it also cannot hurt to reduce the size of the `web/l10n_utils.js` file slightly.
2023-06-21 21:42:53 +02:00
Jonas Jenwald
24b2c3a5e3
Merge pull request #16583 from Snuffleupagus/Firefox-disable-pref-changes
[Firefox] Disable the ability to change preferences directly from the viewer
2023-06-21 21:07:28 +02:00
Jonas Jenwald
5c0872d1b0 [Firefox] Avoid unnecessary string-parsing when reading preferences
Note how the [`ChromeActions.getPreferences` method](https://searchfox.org/mozilla-central/rev/4e8f62a231e71dc53eb50b6d74afca21d6b254e9/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs#497-530) returns the preferences as a string, which we then have to convert back into an Object in the viewer.
Back when that code was originally written it wasn't possible to send Objects from the platform-code, however that's no longer the case and we should be able to (eventually) remove this unnecessary string-parsing now.

*Please note that in order to prevent breakage we'll need to land these changes in stages:*
 - Land this patch in mozilla-central, as part of regular the PDF.js updates.
 - Change the return type in the `ChromeActions.getPreferences` method, in a mozilla-central patch.
 - Remove the string-handling from the `FirefoxPreferences._readFromStorage` method.
2023-06-21 20:14:46 +02:00
Jonas Jenwald
1f9d1f3696 [Firefox] Disable the ability to change preferences directly from the viewer
Please note that we've never had any functionality in the viewer itself that *set* preferences, and we've thus only ever read them.
For the GENERIC viewer it obviously makes sense for the user to be able to modify preferences, e.g. via the console, but that doesn't really apply to the *built-in* Firefox PDF Viewer since preferences are already accessible via `about:config` there. Hence it does seems somewhat strange to expose, a limited part of, the Firefox preference system in this way when we're not even using it.

Note that the unused preference setting-code also include a fair amount of *additional* validation on the platform-side, such as limiting any possible preference changes to the `pdfjs.`-branch and also an explicit white-list of preference names[1], to make sure that this is safe; please see:
 - https://searchfox.org/mozilla-central/rev/4e8f62a231e71dc53eb50b6d74afca21d6b254e9/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs#458-495
 - https://searchfox.org/mozilla-central/rev/4e8f62a231e71dc53eb50b6d74afca21d6b254e9/toolkit/modules/AsyncPrefs.sys.mjs#21-48

Assuming that this patch lands, I'll follow-up with a mozilla-central patch to remove the code mentioned above.

---
[1] This hard-coded list contains preferences that no longer exist, and also at least one (fairly obvious) typo.
2023-06-21 20:14:16 +02:00
Jonas Jenwald
7742d6e4a6
Merge pull request #16581 from Snuffleupagus/Lexer-getNumber-sign
Simplify the `sign` handling in the `Lexer.getNumber` method
2023-06-21 15:34:55 +02:00
Jonas Jenwald
fe869aca38 Simplify the sign handling in the Lexer.getNumber method
After the changes in PR 15606, we can (slightly) simplify the `sign` handling.
2023-06-21 14:47:29 +02:00
calixteman
9a6f439dc7
Merge pull request #16578 from calixteman/issue16576
[Editor] Hide visible popups when editing
2023-06-21 13:55:51 +02:00
Jonas Jenwald
71c60d523d
Merge pull request #16580 from Snuffleupagus/rm-OverlayManager-unregister
Remove the `OverlayManager.unregister` method since it's completely unused
2023-06-21 13:23:07 +02:00
Jonas Jenwald
7f53fb82a5 Remove the OverlayManager.unregister method since it's completely unused
This method was added only for consistency with the `register`-method, however it's never actually been used. To avoid including dead code in the builds, let's just remove the `unregister`-method for now.

*Please note:* If this method ever becomes useful, it'll be trivial to revert this commit.
2023-06-21 13:13:53 +02:00
Calixte Denizet
8ae1c8dd81 [Editor] Hide visible popups when editing 2023-06-21 12:30:05 +02:00
calixteman
b8f5a14925
Merge pull request #16579 from calixteman/issue16577
[Editor] Don't make editable an empty freetext annotation
2023-06-21 12:26:02 +02:00
Calixte Denizet
19f7a8b899 [Editor] Don't make editable an empty freetext annotation 2023-06-21 11:48:20 +02:00
Jonas Jenwald
7588418b09
Merge pull request #16572 from Snuffleupagus/annotationLayer-NullL10n
[api-minor] Ensure that the `AnnotationLayer` gets a default l10n-instance in GENERIC builds (PR 16552 follow-up)
2023-06-20 21:20:19 +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
Jonas Jenwald
197e806c86 [api-minor] Ensure that the AnnotationLayer gets a default l10n-instance in GENERIC builds (PR 16552 follow-up)
*This is something that I completely overlooked during review of PR 16552, despite leaving a l10n-related comment.*

The new l10n-handling of PopupAnnotations assume that the `AnnotationLayer` is always initialized with a l10n-instance, which might not actually be the case in third-party implementations where the default viewer isn't used.
To work-around that we'll now bundle, and fallback on, the existing `NullL10n`-implementation in GENERIC builds of the PDF.js library. This will only result in a slight file-size increase for the *built* `pdf.js` file, again limited to GENERIC builds, since the `web/l10n_utils.js` file has no dependencies.

Also, tweaks a couple of TESTING pre-processor checks to *only* include that code when running the reference tests.
2023-06-20 20:28:29 +02:00
calixteman
a656d71959
Merge pull request #16570 from calixteman/it
Fix integration tests
2023-06-20 18:10:50 +02:00
Calixte Denizet
5ffaa64167 Fix integration tests 2023-06-20 17:52:20 +02:00
calixteman
fc487c8aa9
Merge pull request #16552 from calixteman/simplify_popup
[api-minor] Make the popup independent of their associated annotations
2023-06-20 16:10:45 +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
04c31a55d2
Merge pull request #16558 from Snuffleupagus/writeStream-filter-fixes
Improve handling of /Filter-entries in `writeStream`
2023-06-16 13:07:41 +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
Jonas Jenwald
bd46a934ec
Merge pull request #16559 from calixteman/test_compression
Add a test to check that the compression is ok when saving an annotation
2023-06-16 10:27:10 +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
calixteman
5f1fba503c
Merge pull request #16557 from calixteman/no_events_on_canvas
Disable events on canvas in the annotation layer
2023-06-15 22:18:12 +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
calixteman
64520a0c63
Merge pull request #16555 from calixteman/empty_freetext
[Editor] Don't add an editor for empty FreeText annotations
2023-06-15 19:44:13 +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
a37f7d2477
Merge pull request #16543 from Snuffleupagus/limit-more-to-GENERIC
Limit more code to GENERIC builds
2023-06-15 13:58:52 +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
033228a2fc
Merge pull request #16544 from Snuffleupagus/eslint-prefer-optional-catch-binding
Enable the `unicorn/prefer-optional-catch-binding` ESLint plugin rule
2023-06-15 12:25:42 +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
89f29192a5 Actually limit SVGGraphics to GENERIC builds (PR 16226 follow-up)
After PR 16226 the deprecated SVG back-end is now unused in development mode, with the exception of unit-tests, hence we can re-factor how it's exposed in the API to avoid including a useless webpack-closure in e.g. the *built-in* Firefox PDF Viewer.
2023-06-14 21:38:10 +02:00
Jonas Jenwald
a8d4aad8b9 Limit PDFPageProxy.getOperatorList to development mode and GENERIC builds
Given that this API method isn't used anywhere within the PDF.js library itself, except for the unit-tests, we can avoid including what's effectively dead code in e.g. the *built-in* Firefox PDF Viewer.
2023-06-14 21:33:22 +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
Tim van der Meij
9af50dc358
Merge pull request #16541 from Snuffleupagus/inline-image-mask-checks
Improve SMask/Mask lookup when parsing inline images
2023-06-11 13:01:45 +02:00
Tim van der Meij
1e2f82050f
Merge pull request #16542 from Snuffleupagus/update-packages
Update packages and translations
2023-06-11 12:59:07 +02:00
Jonas Jenwald
68b05fb9cd Update l10n files 2023-06-11 11:32:48 +02:00
Jonas Jenwald
8415ff51b4 Update npm packages 2023-06-11 11:30:39 +02:00
Jonas Jenwald
1f42aaf21b Improve SMask/Mask lookup when parsing inline images
- Don't attempt to lookup an "SM" entry, since we're only using "SMask" in the `PDFImage` code and I also cannot find any mention in the PDF specification about that being a valid abbreviation for a Soft Mask entry. (There's only a `SM = Smoothness Tolerance` Graphics State parameter, which is obviously something completely different.)

 - Don't lookup the /SMask and /Mask entries unless it's actually an inline image, since it's pointless otherwise.

 - Last, but most importantly, only check for the *existence* of /SMask and /Mask entries but don't actually fetch the data. Note that if either one exists it'll contain a Stream, and those cannot be cached on the `XRef`-instance, which leads to unnecessary parsing/allocations and in this case we're not using the actual data for anything.
2023-06-10 13:19:43 +02:00
calixteman
b8447eb49f
Merge pull request #16523 from calixteman/restore_save
[Editor] Add the possibility to update an existing annotation with some new properties when saving or printing
2023-06-09 19:26:42 +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
calixteman
f8a84a6f03
Merge pull request #16539 from calixteman/issue16538
Concat data when push fails in the CFF compiler
2023-06-09 17:09:49 +02:00
Calixte Denizet
3d0ce1cff2 Concat data when push fails in the CFF compiler 2023-06-09 15:48:01 +02:00
calixteman
f2a29e858f
Merge pull request #16533 from calixteman/fix_freetext_undo
[Editor] Fix test failures in m-c because of the new FreeText undo/redo stuff
2023-06-08 14:30:39 +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
calixteman
22d350cae6
Merge pull request #16528 from calixteman/bug1831574
[Editor] Commit the text when the user hits ctrl+s (bug 1831574)
2023-06-06 12:13:14 +02:00
Calixte Denizet
3d98fb3c0b [Editor] Commit the text when the user hits ctrl+s (bug 1831574) 2023-06-06 11:40:54 +02:00
calixteman
a2b9e23f83
Merge pull request #16525 from calixteman/editor_undo_text_change
[Editor] Allow to undo/redo committed text modifications for FreeText
2023-06-06 10:53:35 +02:00
Calixte Denizet
2f0bb9dc2f [Editor] Allow to undo/redo committed text modifications for FreeText 2023-06-05 21:31:19 +02:00
calixteman
9cd84aa0b2
Merge pull request #16522 from calixteman/restore_get_freetext_info_from_as
[Editor] Guess font size and color from the AS of FreeText annotations
2023-06-05 18:08:58 +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
calixteman
77fb6834d6
Merge pull request #16521 from calixteman/restore_connect_layers
[Editor] Connect then annotation layer and the editor one
2023-06-05 14:20:24 +02:00
Calixte Denizet
9f861c39f4 [Editor] Connect then annotation layer and the editor one 2023-06-05 14:05:52 +02:00
Tim van der Meij
184cad3daf
Merge pull request #16520 from Snuffleupagus/issue-16518
Remove unused variables in `InkAnnotation.createNewAppearanceStream` (issue 16518, PR 16494 follow-up)
2023-06-04 17:43:18 +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
Jonas Jenwald
046b9050dd Remove unused variables in InkAnnotation.createNewAppearanceStream (issue 16518, PR 16494 follow-up) 2023-06-04 13:51:24 +02:00
Jonas Jenwald
a5d0af38f7
Merge pull request #16515 from Snuffleupagus/eslint-import-no-cycle
Enable the `import/no-cycle` ESLint plugin rule
2023-06-04 13:50:17 +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
Tim van der Meij
605d9f492f
Merge pull request #16517 from Snuffleupagus/eslint-import-more
Enable more `import` ESLint plugin rules
2023-06-04 12:22:21 +02:00
Jonas Jenwald
5fad931a3f Enable more import ESLint plugin rules
This patch enables more `import` rules to help prevent bugs/inconsistencies, and most of these rules didn't require code changes; please find additional details here:
 - https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/export.md
 - https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/exports-last.md
 - https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/first.md
 - https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-empty-named-blocks.md
 - https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-mutable-exports.md
 - https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-self-import.md
2023-06-04 09:58:25 +02:00
Tim van der Meij
bb5d38acc1
Merge pull request #16495 from Snuffleupagus/PDFRenderingQueue-components
Limit some `PDFRenderingQueue`-related code to the GENERIC viewer
2023-06-03 12:33:18 +02:00
calixteman
63b61ca082
Merge pull request #16508 from calixteman/restore_mk_annotation_layer_an_object
[api-minor] Make the AnnotationLayer an object in order to use it in the AnnotationEditorLayer
2023-06-02 23:12:50 +02:00
Calixte Denizet
4351708ae6 [api-minor] Make the AnnotationLayer an object in order to use it in the AnnotationEditorLayer
It'll be useful to make the Freetext and Ink annotations editable.
2023-06-02 22:44:14 +02:00
Jonas Jenwald
cccdc8dba4
Merge pull request #16513 from Snuffleupagus/issue-7454
Improve handling of mismatching /BaseFont and /FontName entries for non-embedded fonts (issue 7454)
2023-06-02 18:11:05 +02:00
Jonas Jenwald
666e35301b
Merge pull request #16499 from Snuffleupagus/Chrome-92
[api-minor] Update the minimum supported Google Chrome version to 92
2023-06-02 17:16:22 +02:00
Jonas Jenwald
459d26edec Improve handling of mismatching /BaseFont and /FontName entries for non-embedded fonts (issue 7454)
This patch is the result of me going through some old issues regarding non-embedded Wingdings support.

There's a few different things wrong in the referenced PDF document:
 - The /BaseFont and /FontName entries don't agree on the name of the fonts, with one font using `/BaseFont /Wingdings-Regular` and `/FontName /wg09np` which obviously makes no sense.
   To address this we'll compare the font-names against our lists of known ones and ignore /FontName entries that don't make sense iff the /BaseFont entry is a known font-name.
 - The non-embedded Wingdings font also set an incorrect /Encoding, in this case /MacRomanEncoding, which should have been fixed by PR 16465. However this doesn't work since the font has *bogus* font-flags, that fail to categorize the font as Symbolic.
   To address this we'll also compare the font-name against the list of known symbol fonts.
2023-06-02 17:10:25 +02:00
Jonas Jenwald
ba67bd717a
Merge pull request #16516 from Snuffleupagus/lazy-KeyboardManager-init
[editor] Initialize `KeyboardManager`-instances lazily
2023-06-02 16:17:31 +02:00
Jonas Jenwald
ea93c507f5 [editor] Initialize KeyboardManager-instances lazily
As far as I can tell there's no particular reason for initializing `KeyboardManager`-instances eagerly, since the user may never use editing, and we can easily do this lazily instead by utilizing shadowed getters.
2023-06-02 16:03:22 +02:00
Jonas Jenwald
0023c4a511
Merge pull request #16514 from Snuffleupagus/eslint-import-named
Enable the `import/named` ESLint plugin rule
2023-06-02 15:59:16 +02:00
Jonas Jenwald
9fe0423a4c
Merge pull request #16497 from Snuffleupagus/more-Util-getAxialAlignedBoundingBox
Use the `Util.getAxialAlignedBoundingBox` helper function more
2023-06-02 13:34:10 +02:00
Jonas Jenwald
89a17abadf Enable the import/named ESLint plugin rule
This would've prevented issue 16512, please see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/named.md
2023-06-02 13:22:26 +02:00
Jonas Jenwald
a43b1246c8
Merge pull request #16511 from Snuffleupagus/pr-15618-followup
Fix incorrect `USERACTIVATION_CALLBACKID` import (15618 follow-up)
2023-06-02 13:10:08 +02:00
Jonas Jenwald
2db0eff70f Fix incorrect USERACTIVATION_CALLBACKID import (15618 follow-up)
This constant is currently imported from the wrong file, where it doesn't exist; see PR 15618.
2023-06-02 10:02:23 +02:00
Jonas Jenwald
665ff78051
Merge pull request #16505 from maxired/fix/export-image-kind
export ImageKind
2023-06-02 09:48:23 +02:00
Jonas Jenwald
6b16d903b1
Merge pull request #16507 from Snuffleupagus/zooming-regressions-2
Fix more regressions from PR 15812
2023-06-02 09:26:09 +02:00
Maxence Dalmais
e4ecf59727 export ImageKind type externally 2023-06-02 08:51:18 +02:00
Jonas Jenwald
a60bb5f936 Don't use partially rendered pages to generate thumbnails when drawingDelay is used (PR 15812 follow-up)
While it's slightly difficult to trigger in practice, unless the `defaultZoomDelay`-value is increased, it's currently possible to generate thumbnails from *partially* rendered pages when doing *temporary* CSS-only zooming.
2023-06-01 19:01:57 +02:00
Jonas Jenwald
af8df207bb Don't dispatch "pagerendered"-events on the *temporary* CSS-only zooming done when drawingDelay is used (PR 15812 follow-up)
We shouldn't dispatch a "pagerendered"-event when doing *temporary* CSS-only zooming, but simply wait until the actual rendering is done.
While I don't believe that this regression has caused any actual bugs, dispatching *duplicate* events is nonetheless inconsistent and should be fixed.
2023-06-01 19:01:50 +02:00
Jonas Jenwald
32964db6ef
Merge pull request #16504 from wojtekmaj/fix-canvasMaxAreaInBytes
Fix canvasMaxAreaInBytes type
2023-06-01 17:28:24 +02:00
Wojciech Maj
1add9bc131
Fix canvasMaxAreaInBytes type
Fixes #16503
2023-06-01 15:41:43 +02:00
calixteman
1ef918239c
Merge pull request #16501 from calixteman/issue16500
Try to not omit some values when printing a choice list with several selected items
2023-06-01 12:05:58 +02:00
Calixte Denizet
0e610cab04 Try to not omit some values when printing a choice list with several selected items 2023-05-31 21:17:22 +02:00
calixteman
a2118f52b0
Merge pull request #16494 from calixteman/save_more_info_for_ink
[Editor] Add few more info when saving ink data (thickness, opacity, …)
2023-05-31 15:56:45 +02:00
Calixte Denizet
133d103186 [Editor] Add few more info when saving ink data (thickness, opacity, ...)
Fix the InkList entry: the coordinates were relative to the page and not
to the bounding box of the annotation.
2023-05-31 15:43:07 +02:00
Jonas Jenwald
c60a3ce96a [api-minor] Update the minimum supported Google Chrome version to 92
This patch updates the minimum supported browsers as follows:
 - Google Chrome 92, which was released on 2021-07-20; see https://support.google.com/chrome/a/answer/10314655

Note that nowadays we usually try, where feasible and possible, to support browsers that are about two years old. By limiting support to only "recent" browsers we reduce the risk of holding back improvements of the *built-in* Firefox PDF Viewer, and also (significantly) reduce the maintenance/support burden for the PDF.js contributors.

*Please note:* As always, the minimum supported browser version assumes that a `legacy`-build of the PDF.js library is being used; see https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
2023-05-31 11:03:39 +02:00
Jonas Jenwald
d3c0928121 Use the Util.getAxialAlignedBoundingBox helper function more
There's a couple of spots in the code-base that effectively re-implement this helper function, which seems like unnecessary repetition.
2023-05-31 09:32:19 +02:00
Jonas Jenwald
e8c727742c Limit some PDFRenderingQueue-related code to the GENERIC viewer
Given that this functionality is only relevant in third-party use-cases, for example the viewer-components, we can avoid needlessly including it in e.g. the MOZCENTRAL build.
2023-05-30 21:24:19 +02:00
Tim van der Meij
071e6bc7e7
Merge pull request #16489 from timvandermeij/puppeteer
Update Puppeteer to version 20
2023-05-29 18:56:10 +02:00
Tim van der Meij
ca620e4cc9
Update Puppeteer to version 20
This commit makes the following required changes:

- Replace custom cache trimming logic in favor of the (per our request)
  newly added `trimCache` method in Puppeteer. Not only does this greatly
  simplify our code and prevents having to import Puppeteer internals,
  it's also necessary because Puppeteer 20 removed the `BrowserFetcher`
  API in favor of the new separate `@puppeteer/browsers` package.
- Start browsers in series instead of in parallel. Parallel browser
  starts broke since Puppetter 19.1.0 and it turns out that it has never
  been supported officially, so it worked more-or-less by accident.
  Starting browsers in series is the supported way, is almost equally
  fast and ensures that we avoid any race conditions during startup.
  Finally, it also allows us to remove the `browserPromise` state on our
  session objects.

Fixes #15865.
2023-05-29 15:45:24 +02:00
Tim van der Meij
7f6f33da3c
Merge pull request #16487 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-05-29 14:23:44 +02:00
Tim van der Meij
1096e69879
Bump versions in pdfjs.config 2023-05-29 14:16:43 +02:00
Tim van der Meij
036f855dca
Merge pull request #16484 from Snuffleupagus/PDFSidebar-onUpdateThumbnails
Re-factor updating of thumbnails in the `PDFSidebar`-class
2023-05-29 12:56:24 +02:00
calixteman
f06d0b2a9e
Merge pull request #16483 from calixteman/bug1529502
[OTS] Remove cntrmask instruction with no stem in charstring (bug 1529502)
2023-05-28 20:42:59 +02:00
Calixte Denizet
78e6020a6e [OTS] Remove cntrmask instruction with no stem in charstring (bug 1529502) 2023-05-28 19:03:37 +02:00
Jonas Jenwald
c4c8227d20 Re-factor updating of thumbnails in the PDFSidebar-class
This patch does two things:
 - Moves the updating of thumbnails into `web/app.js`, via a new `PDFSidebar` callback-function, to avoid having to include otherwise unnecessary parameters when initializing a `PDFSidebar`-instance.
 - Only attempt to generate thumbnail-images from pages that are *cached* in the viewer. Note that only pages that exist in the `PDFPageViewBuffer`-instance can be rendered, hence it's not actually meaningful to check every single page when updating the thumbnails.
   For large documents, with thousands of pages, this should be a tiny bit more efficient when e.g. opening the sidebar since we no longer need to check pages that we know have not been rendered.
2023-05-28 17:54:34 +02:00
Jonas Jenwald
0e604f8f42 Use local variables more in PDFViewerApplication._initializeViewerComponents 2023-05-28 15:33:23 +02:00
Tim van der Meij
60feb2d5b6
Merge pull request #16470 from Snuffleupagus/thumbnailrendered-event
Introduce a "thumbnailrendered" event to simplify cleanup after thumbnail rendering (PR 12613 follow-up)
2023-05-28 14:15:24 +02:00
Tim van der Meij
9b3e1d41ae
Merge pull request #16481 from Snuffleupagus/update-packages
Update packages and translations
2023-05-28 14:12:32 +02:00
Jonas Jenwald
b51bbdf055 Update l10n files 2023-05-28 09:44:15 +02:00
Jonas Jenwald
0e129c9e5e Update npm packages 2023-05-28 09:39:34 +02:00
Jonas Jenwald
bc8523ac29 Introduce a "thumbnailrendered" event to simplify cleanup after thumbnail rendering (PR 12613 follow-up)
The way that the cleanup was implemented in PR 12613 has always bothered me slightly, since the `isPageCached`-method that I introduced there always felt quite out-of-place in the `IPDFLinkService`-implementations.
By introducing a new "thumbnailrendered" event, similar to the existing "pagerendered" one, we're able to move the cleanup handling into the `PDFViewer`-class instead.
2023-05-26 15:30:22 +02:00
Jonas Jenwald
6d8810b55c
Merge pull request #16479 from Snuffleupagus/PDFFindController-onIsPageVisible
Re-factor the `isPageVisible`-handling in the find-controller (PR 10217 follow-up)
2023-05-26 15:25:55 +02:00
Jonas Jenwald
d0bf505312 Re-factor the isPageVisible-handling in the find-controller (PR 10217 follow-up)
The way that this was implemented in PR 10217 has always bothered me slightly, since the `isPageVisible`-method that I introduced there always felt quite out-of-place in the `IPDFLinkService`-implementations.
Hence this is instead replaced by a callback-function in `PDFFindController`, to handle the page-visibility checks. Note that since the `PDFViewer`-constructor always sets this callback-function, e.g. the viewer-component examples still work as-is.
2023-05-26 13:59:39 +02:00
calixteman
cbc4b20b12
Merge pull request #16474 from calixteman/issue16473
Reset the formatted value when after a text field has been modified
2023-05-26 10:43:40 +02:00
Calixte Denizet
be5db13005 Reset the formatted value when after a text field has been modified 2023-05-26 10:17:14 +02:00
Jonas Jenwald
2bf68f3c7f
Merge pull request #16472 from calixteman/issue16471
Extract all the text of text annotations
2023-05-26 09:33:48 +02:00
Calixte Denizet
35a58ed987 Extract all the text of text annotations 2023-05-25 23:11:42 +02:00
Jonas Jenwald
2890c464da
Merge pull request #16466 from Snuffleupagus/gv-rm-Toolbar-stub
[GeckoView] Remove the `Toolbar`-stub since the viewer has an actual toolbar now
2023-05-25 22:23:10 +02:00
calixteman
8d5da54cd5
Merge pull request #16467 from calixteman/non_null_ultimate
Avoid to have a null fallback if none has been provided
2023-05-24 17:00:14 +02:00
Jonas Jenwald
ba654343e1
Merge pull request #16451 from Snuffleupagus/Wingdings
Attempt to improve non-embedded Wingdings font support (bug 1652224)
2023-05-24 16:04:12 +02:00
Jonas Jenwald
5a7beb9f30 Attempt to improve non-embedded Wingdings font support (bug 1652224)
Now that font-substitution has been implemented, we should be able to do much a better job at supporting non-embedded Wingdings fonts.
Given that this is a Windows-specific font, see https://en.wikipedia.org/wiki/Wingdings, this is however not guaranteed to work (well) on other platforms.
2023-05-24 14:59:13 +02:00
Calixte Denizet
7dce0a27f6 Avoid to have a null fallback if none has been provided 2023-05-24 14:44:36 +02:00
Jonas Jenwald
76ca395c32 [GeckoView] Remove the Toolbar-stub since the viewer has an actual toolbar now 2023-05-24 12:31:27 +02:00
Jonas Jenwald
daa48e5305
Merge pull request #16465 from Snuffleupagus/issue-16464
Ignore named encoding for non-embedded symbol fonts (issue 16464)
2023-05-24 11:56:59 +02:00
Jonas Jenwald
aeed6f2b67 Ignore named encoding for non-embedded symbol fonts (issue 16464)
The affected font is non-embedded ZapfDingbats, however the PDF document for some inexplicable reason specifies the encoding as "WinAnsiEncoding" (which is obviously wrong).
To work-around this bug in the PDF generator, we'll simply ignore any explicitly specified named encoding for non-embedded symbol fonts.
2023-05-24 10:48:47 +02:00
Jonas Jenwald
a6f9505a39
Merge pull request #16461 from Snuffleupagus/issue-16454
Improve "EI" detection in inline images (PR 12028 follow-up, issue 16454)
2023-05-23 22:23:22 +02:00
calixteman
1886012874
Merge pull request #16462 from calixteman/last_elem_TJ
Take into account the final space if any in the TJ command
2023-05-23 21:26:58 +02:00
calixteman
7cfe00a190
Merge pull request #16445 from calixteman/smoothing
[Editor] Improve curve smoothing for Ink tool (bug 1789443)
2023-05-23 19:20:24 +02:00
Calixte Denizet
d2b4ed3cea [Editor] Improve curve smoothing for Ink tool (bug 1789443)
- Remove the dependency on fit-curve;
- Improve the way to draw the current line in using a Path2D and
  in clearing only the last part of the curve instead of clearing
  all the canvas;
- Smooth the curve when drawing to avoid to have some changes after
  the drawing ends;
- Make the smoothing a bit less agressive.
2023-05-23 17:15:21 +02:00
Calixte Denizet
a76a69e1ed Take into account the final space if any in the TJ command
The final space was just ignored and that led to wrongly position
the next chunk of text.
2023-05-23 17:09:32 +02:00
Jonas Jenwald
dfbbb8c0ac Improve "EI" detection in inline images (PR 12028 follow-up, issue 16454)
Given that inline images may contain "EI"-sequences in the image-data itself, actually finding the end-of-image operator isn't always straightforward.
Here we extend the implementation from PR 12028 to potentially check all of the following bytes, rather than stopping immediately. While we have fairly decent test-coverage for this code, whenever you're changing it there's unfortunately a slightly higher than normal risk of regressions. (You'd really wish that PDF generators just stop using inline images.)
2023-05-23 17:04:51 +02:00
calixteman
094fb3c783
Merge pull request #16453 from calixteman/gv_telemetry
[GeckoView] Add some telemetry for the toolbar buttons (bug 1829216)
2023-05-22 17:08:43 +02:00
Calixte Denizet
7f1e8d1920 [GeckoView] Add some telemetry for the toolbar buttons (bug 1829216) 2023-05-22 16:43:09 +02:00
calixteman
1c4e4b4092
Merge pull request #16450 from calixteman/issue16300
Sanitize the glyph bounding box
2023-05-21 17:40:36 +02:00
Calixte Denizet
ca12bca276 Sanitize the glyph bounding box
- if the contours count is lower than -1, the glyph is really likely wrong
so just remove it from the font;
- if a contour has the repeat flag then repeats count mustn't be 0.
2023-05-21 16:24:41 +02:00
Tim van der Meij
d09c27d231
Merge pull request #16449 from Snuffleupagus/attachments-viewer-rm-sort
Stop trying to sort the attachments in the sidebar
2023-05-21 12:25:28 +02:00
Jonas Jenwald
14fd59c4d0 Stop trying to sort the attachments in the sidebar
Looking at the behaviour in Adobe Reader it doesn't appear that attachments are sorted alphabetically, hence it doesn't seem necessary for us to do so either in the viewer.
An additional benefit of *not* sorting the attachments is that any "actual" attachments are now always placed at the top of the list in the sidebar, and if any `FileAttachment`-annotations exist in the document they will now be appended at the end.
2023-05-21 09:54:24 +02:00
calixteman
65e23432cd
Merge pull request #16448 from calixteman/improve_rescaleandstroke
Improve performance of canvas::rescaleAndStroke by around 30% (bug 1135277)
2023-05-20 21:06:40 +02:00
Calixte Denizet
e5454be0f2 Improve performance of canvas::rescaleAndStroke by around 30%
The pdf linked in bug 1135277 contains a lot of stroke instructions.
In using the Firefox profiler, this patch helps to reduce the overall
spent time in this function by 30%.
2023-05-20 18:21:25 +02:00
Tim van der Meij
1d74936ea9
Merge pull request #16446 from Snuffleupagus/bug-1365930
Extend `getNonStdFontMap` for non-embedded Impact fonts (bug 1365930)
2023-05-20 12:20:52 +02:00
Jonas Jenwald
f657de7de2 Extend getNonStdFontMap for non-embedded Impact fonts (bug 1365930)
According to https://en.wikipedia.org/wiki/Impact_(typeface) this font should be available on all current versions of Windows, and with the recently added font-substitution we should actually be able to render it correctly (at least on Windows).
2023-05-19 18:40:03 +02:00
Tim van der Meij
38287d9435
Merge pull request #16443 from Snuffleupagus/idFactory-shorter
[api-minor] Slightly shorten some `idFactory` strings
2023-05-19 11:36:06 +02:00
Jonas Jenwald
8c4821ceda [api-minor] Slightly shorten the marked-content ids used in the textLayer
Generally we try to keep the ids that we create short, hence we can slightly shorten the "static" parts of them.
2023-05-18 22:32:10 +02:00
Jonas Jenwald
04de155aaa Slightly shorten the loadedName-ids used with font-substitutions
Generally we try to keep the ids that we create short, hence we can slightly shorten the "static" part of them.
2023-05-18 22:27:11 +02:00
Jonas Jenwald
3be66f59d6
Merge pull request #16440 from Snuffleupagus/more-modern-JS
Introduce even more modern JavaScript features in the code-base
2023-05-18 20:56:00 +02:00
calixteman
e8537e4d30
Merge pull request #16439 from calixteman/issue14755
Flush the current chunk when the font changed because of a restore op (issue #14755)
2023-05-18 20:10:31 +02:00
Calixte Denizet
3091e70aad Flush the current chunk when the font changed because of a restore op (issue #14755) 2023-05-18 19:37:16 +02:00
Jonas Jenwald
e8030752f3 Introduce even more modern JavaScript features in the code-base
After PR 12563 we're now free to use e.g. logical OR assignment, nullish coalescing, and optional chaining in the entire code-base.
2023-05-18 18:55:41 +02:00
calixteman
a24d5b629e
Merge pull request #16438 from mozilla/loc_note_openinapp
Add a localization note to explain that 'Open in app' strings are for mobile (bug 1833858)
2023-05-18 17:27:39 +02:00
Marco Castelluccio
77f8fd91ec Add a localization note to explain that 'Open in app' strings are for mobile (bug 1833858) 2023-05-18 16:43:12 +02:00
Jonas Jenwald
356f3cf285
Merge pull request #16437 from Snuffleupagus/loadFont-simpler-fontID
Simplify the `fontID` handling in `PartialEvaluator.loadFont`
2023-05-18 13:36:00 +02:00
Jonas Jenwald
4355e76c60 Simplify the fontID handling in PartialEvaluator.loadFont
The `fontID` handling is quite old and predates the use of the `idFactory` to generate a unique id for each font, hence we can simplify this code a little bit.
2023-05-18 13:09:08 +02:00
Tim van der Meij
ac8032628b
Merge pull request #16424 from Snuffleupagus/core-optional-chaining
Introduce more optional chaining in the `src/core/` folder
2023-05-18 12:40:08 +02:00
calixteman
839be801a0
Merge pull request #16433 from calixteman/bug1825002
For text widgets, get the text from the AP stream instead of from the format callback (bug 1825002)
2023-05-17 16:48:59 +02:00
Calixte Denizet
177036e6ae For text widgets, get the text from the AP stream instead of from the format callback (bug 1825002)
When fixing bug 1766987, I thought the field formatted value came from
the result of the format callback: I was wrong. The format callback is ran
but the value is unused (maybe it's useful to set some global vars... or
it's just a bug in Acrobat). Anyway the value to display is the one rendered
in the AP stream.
The field value setter has been simplified and that fixes issue #16409.
2023-05-17 14:07:28 +02:00
Jonas Jenwald
46bbabbd5d
Merge pull request #16434 from Snuffleupagus/issue-16432
Attempt to fallback to a default font, for non-available ones, in more cases (issue 16432)
2023-05-17 12:30:08 +02:00
Jonas Jenwald
bfb374dbf6 Attempt to fallback to a default font, for non-available ones, in more cases (issue 16432)
This essentially extends PR 11218 to also apply when looking up the final font-reference, via the XRef-table, fails because the font isn't available.

This patch also changes `PartialEvaluator.fallbackFontDict` to simply use "Helvetica" as the default font-name, since that seems generally reasonable given the now existing font-substitution code.
2023-05-17 11:41:08 +02:00
calixteman
5ae353cf4d
Merge pull request #16431 from calixteman/warn_missing_os_font
Warn when pdf.js can't load an OS font
2023-05-16 15:25:16 +02:00
Calixte Denizet
385f275ad9 Warn when pdf.js can't load an OS font 2023-05-16 14:58:38 +02:00
Jonas Jenwald
95ab2b8b17
Merge pull request #16430 from Snuffleupagus/npm-lockfile-version-3
Update `package-lock.json` to lockfileVersion=3
2023-05-16 10:14:00 +02:00
Jonas Jenwald
cc46d303e9 Update package-lock.json to lockfileVersion=3
This reduces the size of the `package-lock.json` file a lot, and given that we recently updated the minimum supported Node.js version to 18 this shouldn't be a problem; please also see
 - https://docs.npmjs.com/cli/v9/configuring-npm/package-lock-json#lockfileversion
 - https://docs.npmjs.com/cli/v9/using-npm/config?v=true#lockfile-version
2023-05-16 09:50:57 +02:00
calixteman
2c0478ecb2
Merge pull request #16426 from calixteman/generate_fallback_one_time
For non-embedded fonts, don't generate the fallback several times
2023-05-15 21:25:29 +02:00
Calixte Denizet
4e8dd54e8e For non-embedded fonts, don't generate the fallback several times 2023-05-15 20:02:45 +02:00
calixteman
107874fcd4
Merge pull request #16420 from calixteman/simplify_subst
Simplify the code to generate font substitution information
2023-05-15 19:58:53 +02:00
Calixte Denizet
b264e0301a Simplify the code to generate font substitution information 2023-05-15 19:17:52 +02:00
calixteman
5f91d39f13
Merge pull request #16425 from calixteman/gv_nimbus
[GeckoView] Add a Nimbus experiment for the toolbar (bug 1833093)
2023-05-15 18:26:28 +02:00
Calixte Denizet
4ed512ab2c [GeckoView] Add a Nimbus experiment for the toolbar (bug 1833093) 2023-05-15 17:18:14 +02:00
Jonas Jenwald
1b4a7c5965 Introduce more optional chaining in the src/core/ folder
After PR 12563 we're now free to use optional chaining in the worker-thread as well. (This patch also fixes one previously "missed" case in the `web/` folder.)

For the MOZCENTRAL build-target this patch reduces the total bundle-size by `1.6` kilobytes.
2023-05-15 12:38:28 +02:00
Jonas Jenwald
c20c1b3362
Merge pull request #16422 from Snuffleupagus/getFontSubstitution-css-tests
Check the `css` property in the `getFontSubstitution` unit-tests
2023-05-15 10:09:17 +02:00
Jonas Jenwald
cb1a10e358 Check the css property in the getFontSubstitution unit-tests
Given that the `css` property isn't constant, since it contains document/font ids, we cannot just check it directly. However, we can make use of regular expressions to ensure that the format is generally correct.
2023-05-14 19:11:35 +02:00
calixteman
4101128c09
Merge pull request #16421 from calixteman/font_subst_test
Add tests for the font substitution
2023-05-14 18:23:12 +02:00
Calixte Denizet
89140fcd98 Add tests for the font substitution 2023-05-14 18:07:03 +02:00
Jonas Jenwald
9cbc2c389f
Merge pull request #16418 from Snuffleupagus/jasmine-5
Update `jasmine` to version 5
2023-05-14 14:03:46 +02:00
Jonas Jenwald
95ac708fbd Update jasmine to version 5
Despite this being a *major* version increase, it doesn't appear to require any updates in our test-suites.
Note in particular that the minimum supported browsers/environments were updated, however this isn't a problem given our recent support-changes in the PDF.js library.

Please find additional details at https://github.com/jasmine/jasmine/blob/main/release_notes/5.0.0.md
2023-05-14 13:04:08 +02:00
Tim van der Meij
693092c980
Merge pull request #16415 from Snuffleupagus/no-useless-promise-resolve-reject
Enable the `unicorn/no-useless-promise-resolve-reject` ESLint plugin rule
2023-05-14 12:41:11 +02:00
Tim van der Meij
521bea4f8f
Merge pull request #16417 from Snuffleupagus/update-packages
Update packages and translations
2023-05-14 12:40:22 +02:00
calixteman
202496a7ca
Merge pull request #16416 from calixteman/use_local_font_2
For missing font, use a local font if it exists even if there's no standard substitution
2023-05-14 12:27:55 +02:00
Jonas Jenwald
62f47588b4 Update l10n files 2023-05-14 10:15:01 +02:00
Jonas Jenwald
d25994e85d Update npm packages 2023-05-14 10:12:06 +02:00
Calixte Denizet
d4b70ec306 For missing font, use a local font if it exists even if there's no standard substitution
If the font foo is missing we just try lo load local(foo) and maybe
we'll be lucky.
2023-05-13 21:54:27 +02:00
Jonas Jenwald
8fbd6755eb Enable the unicorn/no-useless-promise-resolve-reject ESLint plugin rule
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-promise-resolve-reject.md

Note that this patch also re-sorts the existing `unicorn`-rules in proper alphabetical order.
2023-05-13 11:30:25 +02:00
Tim van der Meij
e738e15aa3
Merge pull request #16413 from Snuffleupagus/PDFSidebar-inline-resizing
Move the sidebar-resizing handling into the `PDFSidebar` class
2023-05-12 10:15:35 +02:00
Tim van der Meij
a5336d9d79
Merge pull request #16401 from Snuffleupagus/Safari-15.4
[api-minor] Update the minimum supported Safari version to 15.4
2023-05-12 10:11:53 +02:00
Jonas Jenwald
8f3940fbf3 Move the sidebar-resizing handling into the PDFSidebar class
Originally the `PDFSidebarResizer` class was slightly larger, since the code used to contain e.g. feature testing for older (and no longer supported) browsers.
Given that there's some amount of overlap, when it comes to what DOM-elements and state that these classes need, it now seems reasonable to simply move the sidebar-resizing into the `PDFSidebar` class.

For the MOZCENTRAL build-target this patch reduces the size of the *built* `web/viewer.js` file by just over `1.1` kilobytes.
2023-05-12 10:00:12 +02:00
Jonas Jenwald
9417a37c71
Merge pull request #16410 from Snuffleupagus/toggleExpandedBtn
Reduce some duplication when toggling "expanded" buttons in the viewer toolbars
2023-05-11 13:10:39 +02:00
Jonas Jenwald
0305b04e26 Add the "aria-controls" attribute to the editor-toolbar buttons
Similar to other toolbar/secondaryToolbar buttons that open toolbars or dialogs, it seems reasonable to use "aria-controls" for the editor-toolbar buttons as well.
2023-05-11 12:04:16 +02:00
Jonas Jenwald
362be760e3 Reduce some duplication when toggling "expanded" buttons in the viewer toolbars
This is very similar to PR 16281, but for buttons that use the "aria-expanded" attribute.
2023-05-11 12:04:14 +02:00
calixteman
d520754bcf
Merge pull request #16408 from calixteman/local_font_cache
Add a cache to avoid to load several times a local font
2023-05-10 20:41:51 +02:00
Calixte Denizet
cfb908c999 Add a cache to avoid to load several times a local font
On my computer, it takes few tenths of a second to load a local font.
Since a font can be used several times in a document, the cache will
improve performances.
2023-05-10 20:01:21 +02:00
calixteman
2d2f7b315e
Merge pull request #16363 from calixteman/use_local_font
[api-minor] Use a local font or fallback on an embedded one (if it exists) for non-embedded fonts (bug 1766039)
2023-05-10 14:19:05 +02:00
Calixte Denizet
53134c0c0b [api-minor] Use a local font or fallback on an embedded one (if it exists) for non-embedded fonts (bug 1766039)
- Replace FoxitSans with LiberationSans: LiberationSans is already there (for XFA) and we can use
it as a good replacement of FoxitSans.
- For now we just try to substitue standard fonts, the strategy is the following:
  * we try to find a font locally from a hardcoded list;
  * if it fails then we use Liberation as fallback (only for Helvetica for the moment);
  * else we just fallback on the system serif/sansserif/monospace font.
2023-05-10 14:10:23 +02:00
calixteman
1a2e787e47
Merge pull request #16392 from calixteman/compress
Compress the data when saving annotions
2023-05-09 17:26:46 +02:00
Calixte Denizet
2486536843 Compress the data when saving annotions
CompressionStream API has been added in Firefox 113
(see https://bugzilla.mozilla.org/show_bug.cgi?id=1823619)
hence we can use it to compress the streams with added/modified
annotations.
2023-05-09 14:46:50 +02:00
calixteman
8f2d8f62f3
Merge pull request #16397 from calixteman/issue14565
Make something similar to Acrobat when Underline annotation has no appearance
2023-05-08 21:16:49 +02:00
Jonas Jenwald
d1adab8c7b [api-minor] Update the minimum supported Safari version to 15.4
This patch updates the minimum supported browsers as follows:
 - Safari 15.4, which was released on 2022-03-15; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_15

Nowadays we usually we try, where feasible and possible, to support browsers that are about two years old. The reasons for limiting support to a *somewhat* more recent Safari version include:
 - Throughout the history of the PDF.js project, Safari has always been the worst browser to attempt to support. Compared to other browsers there's a disproportionate number of bugs affecting Safari, especially on iOS, and in most cases those are browser-specific issues that we simply cannot address.[1]
 - Safari has often been a lot slower, compared to other browsers, at implementing new web-platform features. Historically this has sometimes blocked usage of new features, for the benefit of the Firefox PDF Viewer, and it's very often meant having to include and maintain polyfills *only* for Safari.
 - The current (minimum) supported Safari version lack enough functionality that polyfills placed in the `src/shared/compatibility.js` file are unfortunately not sufficient, but it also requires a bunch of special-cases in both the `gulpfile` and in the `web/`-code.
 - Given that the *built-in* Firefox PDF Viewer is the primary development target for the PDF.js library, and the general development pace these days, we need to limit the maintenance "overhead" caused by other browsers.

 ---
 [1] In a few cases a work-around might be possible, however it'd negatively affect e.g. performance, readability, and/or maintainability of the code.
2023-05-07 15:01:15 +02:00
Jonas Jenwald
2c2acdfd1c Revert "Add a <dialog> polyfill for the generic-legacy build"
This reverts commit c9f262c480e0d22fdcc6991700f9ce92b72812b2 now that Safari-compatibility is updated.
2023-05-07 15:00:42 +02:00
Jonas Jenwald
c5eb79577a Revert "Bundle the <dialog> polyfill-CSS in the GENERIC legacy/-viewer (PR 14710 follow-up)"
This reverts commit bb8f5ec20bf6a2fed1f962178b06bc4d99d1e2ef now that Safari-compatibility is updated.
2023-05-07 15:00:42 +02:00
Jonas Jenwald
cfa15bbf59 Revert "Compatible with ResizeObserver borderBoxSize in legacy safari"
This reverts commit 6ca702d6804097514ecf4f5ded84efa87771182a now that Safari-compatibility is updated.
2023-05-07 15:00:42 +02:00
Tim van der Meij
bfb664b9a1
Merge pull request #16398 from Snuffleupagus/xfa-optional-chaining
Introduce some optional chaining in the `src/core/xfa/` folder
2023-05-07 14:54:05 +02:00
Tim van der Meij
7ecb3236f0
Merge pull request #16293 from Snuffleupagus/Node-18
[api-minor] Update the minimum supported Node.js version to 18
2023-05-07 14:48:26 +02:00
Jonas Jenwald
dcd55a7164 Enable unicorn/prefer-at unconditionally (PR 15014 follow-up)
Now that Node.js version 18 is required, we should be able to use `Array.prototype.at()` everywhere in the code-base.
2023-05-07 13:43:19 +02:00
Jonas Jenwald
f79f48c2b4 Remove the IMAGE_DECODERS special-case when polyfilling structuredClone
Originally we only used the `structuredClone` polyfill in the `LoopbackPort`-implementation, and that obviously isn't used anywhere within the various image decoders.
At this point in time we've started to use `structuredClone` a little bit more, hence it seems overall simpler to just bundle the polyfill even in the `legacy`-version of the IMAGE_DECODERS built-target.
2023-05-07 13:43:19 +02:00
Jonas Jenwald
1753e321cd Remove the compatibility checks in WorkerMessageHandler.createDocumentHandler
For some time these checks have only targeted Node.js environments, since the features in question exist in all supported browsers (even when a `legacy`-build is used).

Now that we've updated the minimum supported Node.js version to 18, a number of polyfills are thus (finally) no longer necessary in that environment. Hence for certain *basic* functionality, such as e.g. text-extraction, it's now possible to use either a modern- or a `legacy`-build of the PDF.js library in Node.js environments.

*Please note:* For e.g. canvas-rendering in Node.js environments it's still necessary to use a `legacy`-build, since that functionality requires various polyfills.
2023-05-07 13:43:19 +02:00
Jonas Jenwald
ed8be6f882 [api-minor] Update the minimum supported Node.js version to 18
This patch updates the minimum supported environments as follows:
 - Node.js 18, which was released on 2022-04-19; see https://en.wikipedia.org/wiki/Node.js#Releases

Note also that Node.js 16 will soon reach EOL, and thus no longer receive any security updates.
2023-05-07 13:43:19 +02:00
Tim van der Meij
eca40773b8
Merge pull request #16399 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-05-07 13:33:09 +02:00
Tim van der Meij
594ce65a47
Bump versions in pdfjs.config 2023-05-07 13:22:16 +02:00
Jonas Jenwald
89f768322d Introduce some optional chaining in the src/core/xfa/ folder
After PR 12563 we're now free to use optional chaining in the worker-thread as well.
2023-05-07 12:49:07 +02:00
Calixte Denizet
6c0fdc6ec2 Make something similar to Acrobat when Underline annotation has no appearance 2023-05-06 21:19:25 +02:00
Jonas Jenwald
4d3dfe254f
Merge pull request #16396 from Snuffleupagus/issue-16395
Improve handling of JPEG images with non-standard /Decode-entries (issue 16395)
2023-05-06 16:59:05 +02:00
Jonas Jenwald
722e5910e1 Improve handling of JPEG images with non-standard /Decode-entries (issue 16395)
The /Decode-implementation in the our JPEG decoder, i.e. `src/core/jpg.js`, seems to only handle *inverting* of images properly. To support arbitrary /Decode-entries correctly we'll always use the `PDFImage.decodeBuffer` method, even for "simple" JPEG images, which should be fine since non-default /Decode-entries aren't a very common occurrence.

*Please note:* This patch will lead to a little bit of movement in some existing test-cases, however it should be virtually imperceivable to the naked eye.
2023-05-06 13:55:39 +02:00
Tim van der Meij
3aa96e071b
Merge pull request #16394 from Snuffleupagus/no-invalid-remove-event-listener
Enable the `unicorn/no-invalid-remove-event-listener` ESLint plugin rule
2023-05-06 12:59:52 +02:00
Jonas Jenwald
b4aa10bb86 Enable the unicorn/no-invalid-remove-event-listener ESLint plugin rule
This rule won't only be helpful when writing code, but will also help during reviews to make sure that we don't accidentally leave any event-listeners attached; please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-invalid-remove-event-listener.md
2023-05-06 09:08:11 +02:00
calixteman
da03d322ed
Merge pull request #16391 from calixteman/gv_open_in_app
[GeckoView] Add a button to download and open the file in an external app (bug 1829367)
2023-05-05 16:38:46 +02:00
Calixte Denizet
a652dc85e4 [GeckoView] Add a button to download and open the file in an external app (bug 1829367) 2023-05-05 15:52:15 +02:00
calixteman
f151a39d14
Merge pull request #16387 from calixteman/issue16384
[Annotations] Draw readonly annotations on their own canvas and show the HTML elements when there is a JS interaction (issue #16384)
2023-05-04 21:49:08 +02:00
Calixte Denizet
72da14f005 [Annotations] Draw readonly annotations on their own canvas and show the HTML elements when there is a JS interaction (issue #16384) 2023-05-04 20:08:32 +02:00
calixteman
a24e11a91c
Merge pull request #16106 from bungeman/improve_color_stop_detection
Better approximate gradient color stops
2023-05-04 19:48:57 +02:00
Jonas Jenwald
2fab583fb4
Merge pull request #16379 from Snuffleupagus/sidebar-forceRendering
Simplify the `PDFSidebar.#forceRendering` method
2023-05-04 13:12:16 +02:00
Jonas Jenwald
9dcc50402e Simplify the PDFSidebar.#forceRendering method
The fallback code-path has never really been used, since the `PDFSidebar` is only used in the default viewer (and has never been exposed in e.g. the COMPONENTS-build).
2023-05-04 12:51:30 +02:00
Jonas Jenwald
4931f293eb
Merge pull request #16374 from Snuffleupagus/thumbnail-styles
Simplify the thumbnail styling in the viewer
2023-05-04 12:24:58 +02:00
Jonas Jenwald
74c615b5b0 Remove unused canvas clean-up code in PDFThumbnailView.reset (PR 13357 follow-up) 2023-05-04 12:17:51 +02:00
Jonas Jenwald
1b6a83da4a Simplify the thumbnail styling in the viewer
This patch tries to simplify, and improve, the thumbnail styling:
 - For rendered thumbnails there's one less DOM-element per thumbnail, which can't hurt in longer documents.
 - Use CSS-variables to set the dimensions of all relevant DOM-elements at once.
 - Simplify the visual styling of the thumbnails, e.g. remove the border since the viewer no longer has visible borders around pages, since the relevant CSS-rules are quite old code.
   These changes also, at least in my opinion, makes the relevant CSS-rules much easier to understand and work with.
 - Make it easier to work on e.g. [bug 1690428](https://bugzilla.mozilla.org/show_bug.cgi?id=1690428) without affecting the other sidebarViews.
2023-05-04 12:17:49 +02:00
Jonas Jenwald
e89da6d940
Merge pull request #16375 from Snuffleupagus/pageViewsReady-tweak
Re-factor the `PDFViewer.pageViewsReady` getter slightly
2023-05-04 12:13:21 +02:00
Jonas Jenwald
667085ee33
Merge pull request #16368 from Snuffleupagus/rm-GlobalImageCache-addPageIndex
Inline the `addPageIndex` method in `GlobalImageCache.shouldCache`
2023-05-04 12:09:04 +02:00
Jonas Jenwald
001acfb5ac
Merge pull request #16381 from Snuffleupagus/rm-isStandardFont-prop
Remove the unused `isStandardFont` font-property (PR 15880 follow-up)
2023-05-04 00:30:05 +02:00
Jonas Jenwald
f31b320113
Merge pull request #12563 from Snuffleupagus/rm-SystemJS-worker
[api-minor] Remove SystemJS usage, in development mode, from the worker
2023-05-03 23:57:17 +02:00
calixteman
ade1e52227
Merge pull request #16380 from calixteman/hcm_annotation_canvas
Apply HCM filters on annotations which have their own canvas (bug 1830850)
2023-05-03 22:30:21 +02:00
Jonas Jenwald
24a75bda5d Remove the unused isStandardFont font-property (PR 15880 follow-up)
This property was added in PR 12726 specifically for use in the `getFontType` function, indirectly used by the `PDFDocumentProxy.stats` getter in the API.
In PR 15880 that functionality was removed, but I forgot to remove this now unused font-property.
2023-05-03 11:52:54 +02:00
Calixte Denizet
c07149a44f Apply HCM filters on annotations which have their own canvas (bug 1830850) 2023-05-03 10:19:59 +02:00
Jonas Jenwald
c8246b0720 Re-factor the PDFViewer.pageViewsReady getter slightly 2023-04-30 22:32:13 +02:00
Jonas Jenwald
88616f77ae Remove the closure from BitModel in the src/core/jpx.js file 2023-04-29 13:49:39 +02:00
Jonas Jenwald
b0a1af306d Simplify initialization of static class properties in the worker-thread
Now that we no longer depend on the old Babel version in SystemJS we can remove the `static get ...` work-arounds used to define constants, which leads to slightly more compact code.
2023-04-29 13:49:38 +02:00
Jonas Jenwald
d950b91c4e Introduce some logical assignment in the src/core/ folder 2023-04-29 13:49:37 +02:00
Jonas Jenwald
317abd6d07 Change the createPromiseCapability helper function into a PromiseCapability class
This is not only slightly more compact, but it also simplifies the handling of the `settled` getter.
2023-04-29 13:43:24 +02:00
Jonas Jenwald
f9c2a8d437 Introduce some optional chaining in the src/shared/ folder 2023-04-29 13:43:24 +02:00
Jonas Jenwald
94c2d08975 Revert "Add a getArrayLookupTableFactory helper function and use it to re-format src/core/{glyphlist, unicode}.js"
This reverts commit 56fa6d414cb1115e03f9c1aa9f1d5bc52efcb7ac now that SystemJS is gone.
2023-04-29 13:43:24 +02:00
Jonas Jenwald
95bf9fc17f Remove SystemJS usage, in development mode, from the worker
Now that https://bugzilla.mozilla.org/show_bug.cgi?id=1247687 has landed in Firefox, we're able to use worker-modules during development :-)

This removes the final piece of SystemJS usage from the PDF.js library, thus allowing a fair bit of clean-up, and we now use *only* native `import`/`export` statements everywhere in development mode.
2023-04-29 13:43:24 +02:00
Tim van der Meij
797f8d3dca
Merge pull request #16370 from Snuffleupagus/publish-website-only-master
Limit the `publish_website.yml` work-flow to only the `master` branch (issue 16369)
2023-04-29 11:36:33 +02:00
Tim van der Meij
16017d6669
Merge pull request #16371 from Snuffleupagus/issue-16366
Include the entire `git` history in the work-flows (issue 16366)
2023-04-29 11:34:51 +02:00
Jonas Jenwald
7c1e505f6a Include the entire git history in the work-flows (issue 16366)
Without this change we're not able to correctly determine the version number, please refer to https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
2023-04-29 10:50:37 +02:00
Jonas Jenwald
09edd6657f Limit the publish_website.yml work-flow to only the master branch (issue 16369)
This is a tentative patch, based on https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#using-filters
2023-04-28 10:31:52 +02:00
Jonas Jenwald
f28d915a42
Merge pull request #16362 from SebCorbin/update-types
Update type documentations for #16307, #16359
2023-04-28 10:19:08 +02:00
Jonas Jenwald
bb1228cb64 Inline the addPageIndex method in GlobalImageCache.shouldCache
When the `GlobalImageCache` implementation originally landed, back in PR 11912, the image handling was slightly more complex (with e.g. browser-decoding of some JPEG images). At this point it no longer seems necessary to manually handle pageIndexes in this way, and we should be able to simply inline that in the `GlobalImageCache.shouldCache` method.
2023-04-28 09:40:32 +02:00
Sebastien Corbin
d18b9ee472 Update type documentations for #16307 and #16359 2023-04-28 09:28:21 +02:00
Marco Castelluccio
9eea9993df
Merge pull request #16364 from timvandermeij/github-pages
Introduce a GitHub Actions workflow for publishing the website
2023-04-27 23:17:16 +02:00
calixteman
de42ecb59f
Merge pull request #16365 from calixteman/chmod_1
Chmod ugo-x gv-toolbarButton-download.svg
2023-04-27 20:33:16 +02:00
Calixte Denizet
263ef59fc7 Chmod ugo-x gv-toolbarButton-download.svg 2023-04-27 20:27:27 +02:00
Tim van der Meij
30ca27ac48
Introduce a GitHub Actions workflow for publishing the website
This commit migrates this functionality away from the bots. Nowadays
it's possible to build and deploy the website to GitHub Pages directly
through the GitHub Actions, which provides a nice simplication of the
process. Not only does this remove the requirement to have a `gh-pages`
branch in the repository, it also avoids the complexity of having to
configure the workflow to commit to Git branches and allows us to remove
the Git committing code from the Gulpfile.

Note that deploying directly though GitHub Actions workflows needs to be
enabled in the repository settings, but this is easy and well documented
on the link below.

The following resources are relevant for this patch:

- Enabling deployment to GitHub Pages directly through GitHub Actions:
  https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow
- Uploading GitHub Pages artifacts example:
  https://github.com/actions/upload-pages-artifact#usage
- Deploying GitHub Pages artifacts example:
  https://github.com/actions/deploy-pages#usage
2023-04-27 19:18:03 +02:00
calixteman
4dee3b83d5
Merge pull request #16344 from calixteman/intermittent_integration_test
Fix two intermittents issues in integration tests
2023-04-27 17:18:41 +02:00
Jonas Jenwald
cefa8c601a
Merge pull request #16361 from timvandermeij/jsdoc-pdfvieweroptions
Declare the `linkService` and `l10n` properties as optional in the `PDFViewerOptions` documentation
2023-04-27 17:16:32 +02:00
Tim van der Meij
8259fb4d2f
Declare the linkService and l10n properties as optional in the PDFViewerOptions documentation
Both properties have a fallback to `SimpleLinkService` respectively
`NullL10n` if no other value is provided explicitly.
2023-04-27 15:39:29 +02:00
Tim van der Meij
34ee77396c
Merge pull request #16356 from Snuffleupagus/issue-16355
Update the styling of the findbar `findMsg`-element (issue 16355)
2023-04-27 14:23:18 +02:00
Tim van der Meij
0ee0fcc6b3
Merge pull request #16350 from Snuffleupagus/dist-rm-lib
[api-minor] Stop including the "lib"-build in the `pdfjs-dist` repository
2023-04-27 14:01:55 +02:00
Tim van der Meij
a86265f7b7
Merge pull request #16354 from Snuffleupagus/crypto-less-stringToBytes
Avoid some repeated `stringToBytes`-calls in the `src/core/crypto.js` file
2023-04-27 14:00:50 +02:00
Tim van der Meij
13b168f1bb
Merge pull request #16357 from Snuffleupagus/network-rm-getXhr
Remove the unused `getXhr`-option in the `NetworkManager` constructor
2023-04-27 13:59:23 +02:00
Jonas Jenwald
924a8901d1 Remove the unused getXhr-option in the NetworkManager constructor
Originally this file was shared, using pre-processor statements, between the generic PDF.js library and the *built-in* Firefox PDF Viewer. In the latter case the `getXhr`-option is being used, see https://searchfox.org/mozilla-central/rev/f32d5f3949a3f4f185122142b29f2e3ab776836e/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs#612-621
2023-04-27 11:32:32 +02:00
Jonas Jenwald
89ea6b3bb6 Update the styling of the findbar findMsg-element (issue 16355)
This patch tries to mimic the look of the message-element in the Firefox browser-findbar, and thus makes the following changes:
 - Remove the red colour, since it didn't take the light/dark themes into account.
 - Display the "notFound" message in bold.
2023-04-26 22:11:02 +02:00
Jonas Jenwald
e12535457f Avoid some repeated stringToBytes-calls in the src/core/crypto.js file
Currently we repeatedly lookup, and convert to bytes, the "O" and "U" encryption-dictionary entries.
2023-04-26 17:52:46 +02:00
Jonas Jenwald
62a9435190 [api-minor] Stop including the "lib"-build in the pdfjs-dist repository
The `pdfjs-dist/lib/` directory contains a README file that explicitly advises against using those files, however based on a fairly large number of issues filed over the years users seem to be (mostly) overlooking that warning.
In particular it unfortunately seems to be somewhat common for users to attempt to "combine" proper builds from `pdfjs-dist/build/` together with individual components from the `pdfjs-dist/lib/web/` directory, which more often than not leads to subtle bugs and general problems.

When we receive bug reports about this it's often not immediately obvious what the problem is, given that many issues lack enough details (such as runnable test-cases), but after some back-and-forth it usually turns out that usage of `pdfjs-dist/lib/` is the culprit.
Considering that keeping the general PDF.js library working is challenging and time-consuming enough nowadays, this patch thus proposes that we stop including the "lib"-build in the `pdfjs-dist` repository to both reduce user confusion and the support burden.
2023-04-26 12:11:13 +02:00
Jonas Jenwald
598408b7af
Merge pull request #16347 from Snuffleupagus/getAllTextInProgress-no-copy
Prevent incomplete copy-all behaviour while text-extraction is running (PR 16286 follow-up)
2023-04-26 08:24:17 +02:00
Jonas Jenwald
2de6fd8e70 Prevent incomplete copy-all behaviour while text-extraction is running (PR 16286 follow-up)
Currently we only prevent triggering the actual text-extraction multiple times in "parallel", when using the "copy all text" feature, however the "copy"-event itself is not prevented.
The result is that if the user selects all text in a long PDF document and then uses the copy-shortcut multiple times in quick succession, we'll actually populate the clipboard with "incomplete" contents (via a `TextLayerBuilder` copy-listener) until all text-extraction finishes.
2023-04-25 21:39:16 +02:00
Calixte Denizet
b4264e9648 Fix two intermittents issues in integration tests 2023-04-25 12:31:36 +02:00
Jonas Jenwald
495819fbc6
Merge pull request #16333 from Snuffleupagus/enablePermissions-allow-text-selection
Allow text-selection, but not copying, when `enablePermissions` is set (PR 16320 follow-up)
2023-04-25 11:32:21 +02:00
Jonas Jenwald
8a9d7a18cc Allow text-selection, but not copying, when enablePermissions is set (PR 16320 follow-up) 2023-04-25 11:07:05 +02:00
calixteman
1b79b0cd21
Merge pull request #16340 from calixteman/gv_new_toolbar
[GeckoView] Change the toolbar for a static one on the top of the viewer (bug 1829366)
2023-04-24 14:35:35 +02:00
Calixte Denizet
e00d26798c [GeckoView] Change the toolbar for a static one on the top of the viewer (bug 1829366) 2023-04-24 14:03:23 +02:00
Tim van der Meij
28f96d2ac2
Merge pull request #16336 from timvandermeij/custom-event
Don't use the deprecated `CustomEvent.initCustomEvent` method anymore
2023-04-23 16:06:10 +02:00
Tim van der Meij
870b942568
Don't use the deprecated CustomEvent.initCustomEvent method anymore
In PR #16295 one occurrence of this was changed, but a few more remained
in the codebase. This commit fixes the other occurrences so that we
don't use the deprecated way of creating custom events anywhere anymore.

According to MDN, see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/initCustomEvent,
using the `CustomEvent.initCustomEvent` method is deprecated and the
`CustomEvent` constructor should be used instead.

Extends d9bf571f5c49e1cac9054cf6b7acfc0b5b719876.
2023-04-23 15:41:02 +02:00
Tim van der Meij
2f86f5bb75
Merge pull request #16338 from timvandermeij/updates
Update translations and packages
2023-04-23 15:39:06 +02:00
Tim van der Meij
edb09855dc
Fix package vulnerabilities reported by npm audit
This commit is generated automatically using `npm audit fix`.
2023-04-23 14:37:51 +02:00
Tim van der Meij
f6f33065ef
Update mkdirp to version 3.0.0
The only change in this major version is the removal of the default
export, so we must simply use the named export instead.
2023-04-23 14:37:40 +02:00
Tim van der Meij
1b228091fa
Update packages to the most recent versions 2023-04-23 14:12:17 +02:00
Tim van der Meij
9c023c847c
Update translations to the most recent versions 2023-04-23 14:12:05 +02:00
Tim van der Meij
d6d3fdc489
Merge pull request #16335 from timvandermeij/npm-install-force
Don't force-install packages in the CI job anymore
2023-04-23 12:53:18 +02:00
Tim van der Meij
43d390759b
Don't force-install packages in the CI job anymore
In PR #16327 the `eslint-plugin-mozilla` package was updated so we no
longer have to force-install packages, and the force-install flags for
`npm install` were removed. However, the CI job was missing from this
commit, which we fix here. In general force-installing packages
shouldn't be necessary unless there are problems with dependencies,
which we would like to know about, so especially in the CI job it seems
like a good idea to not force-install packages to catch upcoming defects
early on.

Extends 19526d2322fabd4425688bb7c5504fa9ea015c5c.
2023-04-23 12:45:29 +02:00
Tim van der Meij
bf01edb452
Merge pull request #16334 from Snuffleupagus/rm-PDF20-closure
Remove the `PDF20` closure, in the `src/core/crypto.js` file
2023-04-23 11:39:49 +02:00
Jonas Jenwald
74585c7c59 Remove the unused PDF20.hash method
This method was added in PR 4938, almost nine years ago, however it doesn't appear to ever have been used.
Given the similarities between the `PDF17` and `PDF20` classes, and how they're used, if the `PDF20.hash` method was actually necessary you'd also expect a similiar method in the `PDF17` class.
2023-04-23 10:13:46 +02:00
Jonas Jenwald
5e0722e4c2 Remove the PDF20 closure, in the src/core/crypto.js file
To allow doing this the existing helper function was changed into a "private" method instead.
2023-04-23 10:08:17 +02:00
Jonas Jenwald
6e1b234c6b
Merge pull request #16332 from Snuffleupagus/rm-primitives-closures
Remove the remaining unnecessary closures in the `src/core/primitives.js` file
2023-04-22 15:55:10 +02:00
Jonas Jenwald
9cb3236ac0 Remove the remaining unnecessary closures in the src/core/primitives.js file 2023-04-22 15:33:04 +02:00
Tim van der Meij
e304423ba1
Merge pull request #16331 from Snuffleupagus/cmap-rm-closure
Remove unnecessary closures in the CMap code
2023-04-22 14:58:13 +02:00
Tim van der Meij
2588924b0f
Merge pull request #16326 from Snuffleupagus/limit-Chrome-CSS
Don't include Chrome-specific CSS rules in MOZCENTRAL builds
2023-04-22 14:54:50 +02:00
Tim van der Meij
c9359957e6
Merge pull request #16305 from Snuffleupagus/PDFJSDev-skip-PRODUCTION
Remove the `PRODUCTION` build-target
2023-04-22 14:53:30 +02:00
Jonas Jenwald
bc7aa8a585 Re-factor some String.fromCharCode usage in the src/core/binary_cmap.js file
We can replace one case of `apply` with rest parameters, and avoid doing repeated `String.fromCharCode` calls within a loop.
2023-04-21 12:21:31 +02:00
Jonas Jenwald
cabc98f310 Remove the remaining closure in the src/core/cmap.js file
With modern JavaScript we (usually) no longer need to keep old closures, which slightly reduces the size of the code.
2023-04-21 12:21:31 +02:00
Jonas Jenwald
244002502b Move the BinaryCMapReader into its own file
The "binary" CMap-format is specific to the PDF.js library, and is used to reduce the size of the built-in CMap data-files.
By moving this code to its own file we can remove the nowadays unnecessary closures, which helps to slightly reduce the size of this code.
2023-04-21 12:21:20 +02:00
Jonas Jenwald
434445973d
Merge pull request #16327 from Snuffleupagus/update-eslint-plugin-mozilla
Update `eslint-plugin-mozilla` to avoid having to force-install packages (issue 15429)
2023-04-20 16:20:31 +02:00
Jonas Jenwald
19526d2322 Update eslint-plugin-mozilla to avoid having to force-install packages (issue 15429)
The latest version of `eslint-plugin-mozilla` removed the Prettier dependency, see https://bugzilla.mozilla.org/show_bug.cgi?id=1677562, which means that we no longer need to use `npm install --force` in the PDF.js library.
2023-04-20 16:14:31 +02:00
Jonas Jenwald
d4e8657e8f
Merge pull request #16324 from Snuffleupagus/debugger-CSS-is
Introduce some `:is` usage in the debugger CSS
2023-04-20 15:17:03 +02:00
Jonas Jenwald
1b2b6910ac Don't include Chrome-specific CSS rules in MOZCENTRAL builds 2023-04-20 14:14:33 +02:00
Jonas Jenwald
f675bfe178
Merge pull request #16323 from Snuffleupagus/viewer-CSS-is
Introduce some `:is` usage in the viewer CSS
2023-04-20 09:34:46 +02:00
Jonas Jenwald
7926c1bc88 Introduce some :is usage in the viewer CSS 2023-04-20 09:26:19 +02:00
Jonas Jenwald
3e05d7e7fd Introduce some :is usage in the debugger CSS
Also adds one more instance of `:is` in the `web/annotation_editor_layer_builder.css` file.
2023-04-19 20:47:57 +02:00
Jonas Jenwald
58b5eb89b8
Merge pull request #16315 from Snuffleupagus/annotationLayer-CSS-is
Introduce some `:is` usage in the annotationLayer CSS
2023-04-19 15:32:10 +02:00
Jonas Jenwald
36ff19c53b
Merge pull request #16314 from Snuffleupagus/pdfViewer-CSS-is
Introduce some `:is` usage in the PDFViewer CSS
2023-04-19 15:28:53 +02:00
Jonas Jenwald
5119e7fd6a
Merge pull request #16313 from Snuffleupagus/textLayer-CSS-is
Introduce some `:is` usage in the textLayer CSS
2023-04-19 15:17:22 +02:00
Jonas Jenwald
f98358aa45
Merge pull request #16310 from Snuffleupagus/xfaLayer-CSS-is
Introduce some `:is` usage in the xfaLayer CSS
2023-04-19 15:15:38 +02:00
Jonas Jenwald
3420b2fe8a
Merge pull request #16317 from Snuffleupagus/css-before-after
Enforce double-colon notation for CSS pseudo-elements
2023-04-19 15:14:01 +02:00
Jonas Jenwald
42faecf310
Merge pull request #16320 from Snuffleupagus/enablePermissions-disable-copy-all
Disable the "copy all text" feature when `enablePermissions` is set (PR 16286 follow-up)
2023-04-18 22:13:19 +02:00
Jonas Jenwald
6bfcc96651 Disable the "copy all text" feature when enablePermissions is set (PR 16286 follow-up)
When permissions are enabled and the PDF document doesn't have the COPY-flag set, it shouldn't be possible for the user to trigger the "copy all text" feature.
2023-04-18 21:12:18 +02:00
calixteman
3e292dc222
Merge pull request #16318 from calixteman/issue16316
Correctly clip the text in the text layer (fixes #16316)
2023-04-18 17:48:51 +02:00
Calixte Denizet
19ca41896e Correctly clip the text in the text layer (fixes #16316) 2023-04-18 17:00:42 +02:00
Jonas Jenwald
529dbf9b65 Enforce double-colon notation for CSS pseudo-elements
These changes are part of https://phabricator.services.mozilla.com/D170496, and thanks to a Stylelint rule we can both enforce and fix this automatically; see also https://stylelint.io/user-guide/rules/selector-pseudo-element-colon-notation/
2023-04-18 15:50:22 +02:00
Jonas Jenwald
88e2d04b90
Merge pull request #16311 from linxianxi/fix-viewer-browser-compatibility
Compatible with ResizeObserver borderBoxSize in legacy safari
2023-04-18 13:05:13 +02:00
Jonas Jenwald
fcc535706a Introduce some :is usage in the annotationLayer CSS
While this slightly reduces duplication in the CSS rules, some of the auto-formatting done by Prettier is perhaps not great. (Given the overall advantage of using Prettier, we'll probably have to simply accept this.)
2023-04-18 12:42:13 +02:00
Jonas Jenwald
04ed5ddeba Introduce some :is usage in the PDFViewer CSS 2023-04-18 12:01:08 +02:00
linxianxi
6ca702d680 Compatible with ResizeObserver borderBoxSize in legacy safari
See https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/borderBoxSize\#browser_compatibility
2023-04-18 17:40:26 +08:00
Jonas Jenwald
5cb99321d7 Introduce some :is usage in the textLayer CSS 2023-04-18 11:39:09 +02:00
Jonas Jenwald
9be2ba6170 Introduce some :is usage in the xfaLayer CSS
Hopefully these changes make sense (since this functionality is new to me), however the existing `xfa`-tests should help avoid any outright regressions.
2023-04-17 23:32:04 +02:00
calixteman
f1b005d7b8
Merge pull request #16308 from calixteman/gv_remove_button_hover
[GeckoView] Don't change style for the download button when focused/hovered
2023-04-17 16:53:33 +02:00
calixteman
dbe0c4e60c
Merge pull request #16200 from calixteman/dont_normalize
[api-minor] Don't normalize the text used in the text layer.
2023-04-17 16:50:26 +02:00
Calixte Denizet
dde79edba1 [GeckoView] Don't change style for the download button when focused/hovered 2023-04-17 16:47:05 +02:00
Calixte Denizet
117bbf7cd9 [api-minor] Don't normalize the text used in the text layer.
Some arabic chars like \ufe94 could be searched in a pdf, hence it must be normalized
when creating the search query. So to avoid to duplicate the normalization code,
everything is moved in the find controller.
The previous code to normalize text was using NFKC but with a hardcoded map, hence it
has been replaced by the use of normalize("NFKC") (it helps to reduce the bundle size
by 30kb).
In playing with this \ufe94 char, I noticed that the bidi algorithm wasn't taking into
account some RTL unicode ranges, the generated font wasn't embedding the mapping this
char and the unicode ranges in the OS/2 table weren't up-to-date.

When normalized some chars can be replaced by several ones and it induced to have
some extra chars in the text layer. To avoid any regression, when copying some text
from the text layer, a copied string is normalized (NFKC) before being put in the
clipboard (it works like this in either Acrobat or Chrome).
2023-04-17 14:31:23 +02:00
Jonas Jenwald
89b0fd9628 Remove the remaining PRODUCTION build-target usage
After the previous patch we now have only *a single* `PRODUCTION` occurrence in the entire code-base, more specifically in the `web/viewer.html` file.
This special build-target can be replaced with any condition that always evaluate to `false`, such as e.g. a comment.

*Please note:* This patch might be considered too hacky, hence I completely understand if it's rejected.
2023-04-17 12:07:20 +02:00
Jonas Jenwald
804aa896a7 Stop using the PRODUCTION build-target in the JavaScript code
This *special* build-target is very old, and was introduced with the first pre-processor that only uses comments to enable/disable code.
When the new pre-processor was added `PRODUCTION` effectively became redundant, at least in JavaScript code, since `typeof PDFJSDev === "undefined"` checks now do the same thing.

This patch proposes that we remove `PRODUCTION` from the JavaScript code, since that simplifies the conditions and thus improves readability in many cases.
*Please note:* There's not, nor has there ever been, any gulp-task that set `PRODUCTION = false` during building.
2023-04-17 12:04:34 +02:00
calixteman
3e08eee511
Merge pull request #16301 from calixteman/issue16278
[Editor] Take into account the initial rotation (issue #16278)
2023-04-17 09:42:07 +02:00
Calixte Denizet
8e5f4c0622 [Editor] Take into account the initial rotation (issue #16278) 2023-04-16 21:36:26 +02:00
Jonas Jenwald
1503701d9e
Merge pull request #16295 from Pascal-D/updateDeprecatedCustomEvents
Use CustomEvent when dispatching the "webviewerloaded" event
2023-04-16 16:47:20 +02:00
Pascal Drinkuth
d9bf571f5c Use CustomEvent when dispatching the "webviewerloaded" event
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/initCustomEvent, using initCustomEvent() is deprecated.
2023-04-16 15:36:19 +02:00
Tim van der Meij
f46ed43b81
Merge pull request #16247 from Snuffleupagus/issue-7442
[api-minor] Add support, in `PDFFindController`, for mixing phrase/word searches (issue 7442)
2023-04-16 14:23:41 +02:00
Tim van der Meij
67ce8f18c6
Merge pull request #16299 from Snuffleupagus/TypeScript-5
Update TypeScript to version `5`
2023-04-16 14:14:22 +02:00
Tim van der Meij
6de59e6b3e
Merge pull request #16296 from Snuffleupagus/update-packages
Update packages and translations
2023-04-16 14:08:05 +02:00
Jonas Jenwald
6b4c087e9c
Merge pull request #16298 from Snuffleupagus/generate-hiddenCopyElement
Create the "hiddenCopyElement" in the `PDFViewer` constructor (PR 16286 follow-up)
2023-04-16 12:46:42 +02:00
Jonas Jenwald
5f7e43a2b1
Merge pull request #16297 from Snuffleupagus/copy-all-null-chars
Remove null chars, i.e. `\u0000`, when getting all text (PR 16286 follow-up)
2023-04-16 12:45:16 +02:00
Jonas Jenwald
de03731e92 Update TypeScript to version 5
Note that this is a major version increase, however the `gulp types` and `gulp typestest` tasks seem to work as-is; please see https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/
2023-04-16 11:34:45 +02:00
Jonas Jenwald
2fbbdd68cc Create the "hiddenCopyElement" in the PDFViewer constructor (PR 16286 follow-up)
To make this functionality work out-of-the-box in custom implementations, see e.g. the "viewer components" examples, it'd be slightly easier if we dynamically create/insert the "hiddenCopyElement" in the `PDFViewer` constructor.
Given that the "copy all text" feature still appears to work just as before with this patch, hopefully I'm not overlooking any reason why doing this would be a bad idea.
2023-04-16 09:14:05 +02:00
Jonas Jenwald
4736767b76 Remove null chars, i.e. \u0000, when getting all text (PR 16286 follow-up)
I was playing with the new "copy all text" feature, and stumbled upon one document where the copied text was truncated; see http://mirrors.ctan.org/info/lshort/english/lshort.pdf

The problem turns out to be that on [page 83](https://ftp.acc.umu.se/mirror/CTAN/info/lshort/english/lshort.pdf#page=83) the textLayer contains `\u0000` and apparently copying just stops when a null char is encountered.
To fix this we can simply use an existing helper function, and with this patch we're able to successfully copy all the text in that document.
2023-04-16 08:43:20 +02:00
Jonas Jenwald
a6409e9887 Update l10n files 2023-04-15 22:18:24 +02:00
Jonas Jenwald
877c867a92 Update npm packages 2023-04-15 22:10:02 +02:00
calixteman
92baf14531
Merge pull request #16286 from calixteman/copy_all
Add the possibility to copy all the pdf text whatever the rendered pages are (bug 1788035)
2023-04-15 19:43:13 +02:00
Calixte Denizet
ca54ea12b3 Add the possibility to copy all the pdf text whatever the rendered pages are (bug 1788035) 2023-04-15 18:59:40 +02:00
Jonas Jenwald
0e19c3a120 [api-minor] Add support, in PDFFindController, for mixing phrase/word searches (issue 7442)
*Please note:* This patch only extends the `PDFFindController` implementation itself to support this functionality, however it's *purposely* not exposed in the default viewer.

This replaces the previous `phraseSearch`-parameter, and a `query`-string will now always be interpreted as a phrase-search.
To enable searching for individual words, the `query`-parameter must instead consist of an Array of strings. This way it's now also possible to combine phrase/word searches, with a `query`-parameter looking something like `["Lorem ipsum", "foo", "bar"]` which will search for the phrase "Lorem ipsum" *and* the words "foo" respectively "bar".
2023-04-15 13:32:37 +02:00
Tim van der Meij
4d8a60b435
Merge pull request #16288 from Snuffleupagus/print-code-cleanup
Slightly modernize print-related code
2023-04-15 13:08:37 +02:00
Tim van der Meij
953c29873d
Merge pull request #16281 from Snuffleupagus/toggleCheckedBtn
Reduce some duplication when toggling buttons in the viewer toolbars
2023-04-15 13:00:23 +02:00
Jonas Jenwald
c7daa66b26
Merge pull request #16294 from Snuffleupagus/rm-compileGlobalSubrIndex
Remove `CFFCompiler.compileGlobalSubrIndex`, and simplify `CFFCompiler.compileTypedArray`
2023-04-15 12:17:02 +02:00
Jonas Jenwald
c79bdd6ae6 Simplify the CFFCompiler.compileTypedArray method
Rather than manually creating the Array, we can use the now existing `Array.from` method instead.
2023-04-15 11:13:34 +02:00
Jonas Jenwald
0ce568e789 Remove CFFCompiler.compileGlobalSubrIndex since it's completely unused
This method was originally added in PR 1320, eleven years ago, however it doesn't appear to ever have been used (not even from the start).
Furthermore, this method also tries to access a property that doesn't exist (`this.out`) and then call a method that also doesn't exist (`writeByteArray`).
2023-04-15 11:13:21 +02:00
Jonas Jenwald
ab2773416b
Merge pull request #16291 from Snuffleupagus/issue-16289
Limit the `Path2D`-checks in the worker-thread to Node.js (PR 16238 follow-up, issue 16289)
2023-04-14 21:26:12 +02:00
calixteman
a44173ea51
Merge pull request #16292 from calixteman/improve_cff_compiling
Avoid when it's possible to use Array.concat when compiling a CFF font
2023-04-14 21:17:53 +02:00
Calixte Denizet
5eab8ec610 Avoid when it's possible to use Array.concat when compiling a CFF font
In looking at https://bugs.ghostscript.com/show_bug.cgi?id=706451 I noticed that bug2.pdf was pretty
slow to load for such a basic file.
In profiling I noticed that a lot of time is spent in Array.concat, hence this patch use Array.push when
it's possible (it's now ~3 times faster).
2023-04-14 19:01:01 +02:00
Jonas Jenwald
edd13895dd Limit the Path2D-checks in the worker-thread to Node.js (PR 16238 follow-up, issue 16289)
The changes in PR 16238 were intended specifically for Node.js environments, however they accidentally applied to older browsers as well.

*Please note:* In up-to-date browsers `Path2D` is available in Workers, which should be connected to the introduction of `OffscreenCanvas`.
2023-04-14 11:51:11 +02:00
Jonas Jenwald
aeb8e36cdb Convert FirefoxPrintService and PDFPrintService into standard classes
Note that both of the affected files are old enough to predate the general availability of `class`.
2023-04-14 10:02:28 +02:00
Jonas Jenwald
ebf493f726 Slightly modernize the print layout-methods
By getting the width/height of the first page initially, we can slightly reduce the amount of code needed both in the `hasEqualPageSizes`-check and when building the print-styles.
2023-04-14 10:02:25 +02:00
calixteman
342dc760da
Merge pull request #16284 from calixteman/gv_keep_button
[GeckoView] Show the download button by default and add a pref to disable it (bug 1827963)
2023-04-13 21:17:32 +02:00
Calixte Denizet
7f0d45ce47 [GeckoView] Show the download button by default and add a pref to disable it (bug 1827963)
For the moment there is no real consensus on how we should download a pdf on Android.
Hence we keep this solution for the moment but behind a pref (which will be true on
nightly only).
2023-04-13 20:33:03 +02:00
Jonas Jenwald
2a195beb30 Reduce some duplication when toggling buttons in the viewer toolbars
Currently we repeat the same code in lots of places, to update the "toggled" class and "aria-checked" attribute, when various toolbar buttons are clicked.

For the MOZCENTRAL build-target this patch reduces the size of the *built* `web/viewer.js` file by just over `1.2` kilo-bytes.
2023-04-13 13:18:37 +02:00
Jonas Jenwald
b3932f70ed
Merge pull request #16279 from Snuffleupagus/structuredClone-transfer-legacy
Skip transfers, in `LoopbackPort.postMessage`, for PDF.js `legacy`-builds (issue 16255)
2023-04-13 10:20:11 +02:00
Jonas Jenwald
82a0bcecfa Skip transfers, in LoopbackPort.postMessage, for PDF.js legacy-builds (issue 16255)
Apparently the `structuredClone` polyfill doesn't handle transfers correctly, and `DOMException`s may thus be thrown. This is particularly problematical in Node.js environments, where that exception (obviously) isn't available.

To work-around these issues we'll simply ignore any transfers in `legacy`-builds, since those *may* use the `structuredClone` polyfill. This will obviously lead to slightly higher memory usage in those builds, however this really only affects Node.js environments. (Browsers are only affected if workers are disabled, however that's never been an officially recommended/supported configuration.)
2023-04-12 14:18:29 +02:00
calixteman
7571842d84
Merge pull request #16275 from calixteman/ifx_search_with_fractions
Fix search of numbers inside fractions
2023-04-11 21:52:56 +02:00
Calixte Denizet
d8795f9f8f Fix search of numbers inside fractions 2023-04-11 20:57:26 +02:00
Jonas Jenwald
3a36a9d337
Merge pull request #16268 from Snuffleupagus/RegionalImageCache
Attempt to also cache images at the "page"-level (issue 16263)
2023-04-11 12:06:29 +02:00
calixteman
c1c372c320
Merge pull request #16225 from calixteman/16224
Thin whitespaces must have their own span
2023-04-11 11:13:16 +02:00
Jonas Jenwald
a43151103e
Merge pull request #16265 from Snuffleupagus/float-inline
[Firefox] Use `float: inline-start/inline-end` directly in MOZCENTRAL builds (PR 15968 follow-up)
2023-04-10 16:36:28 +02:00
Jonas Jenwald
d3d16b15ac [Firefox] Use float: inline-start/inline-end directly in MOZCENTRAL builds (PR 15968 follow-up)
Currently `float: inline-start/inline-end` is only supported in Firefox, see https://developer.mozilla.org/en-US/docs/Web/CSS/float#browser_compatibility, and in order to support other browsers we're thus forced to jump through some hoops.
This leads to slightly less nice code in the *built-in* Firefox PDF Viewer, and this patch attempts to improve the current situation:
 - Use Stylelint to forbid direct use of `float: inline-start/inline-end` in the CSS files, to prevent future bugs in the general PDF.js viewer.
 - Do a build-time replacement, only in MOZCENTRAL builds, to replace the CSS-variables with raw `float: inline-start/inline-end` instances.
2023-04-10 16:26:19 +02:00
Tim van der Meij
8398cabd17
Merge pull request #16249 from Snuffleupagus/Chrome-88
[api-minor] Update the minimum supported Google Chrome version
2023-04-10 15:41:42 +02:00
Tim van der Meij
20f79f870e
Merge pull request #16246 from Snuffleupagus/dist-install-force
Force-install when using `gulp dist-install` (issue 15435)
2023-04-10 15:40:09 +02:00
Jonas Jenwald
9881dbf927 Attempt to also cache images at the "page"-level (issue 16263)
Currently we have two separate image-caches on the worker-thread:
 - A local one, which is unique to each `PartialEvaluator.getOperatorList` invocation. This one caches both names *and* references, since image-resources may be accessed in either way.
 - A global one, which applies to the entire PDF documents and all its pages. This one only caches references, since nothing else would work.

This patch introduces a third image-cache, which essentially sits "between" the two existing ones. The new `RegionalImageCache`[1] will be usable throughout a `PartialEvaluator` instance, and consequently it *only* caches references, which thus allows us to keep track of repeated image-resources found in e.g. different /Form and /SMask objects.

---
[1] For lack of a better word, since naming things is hard...
2023-04-10 11:34:41 +02:00
Jonas Jenwald
195db2cff5
Merge pull request #16262 from Snuffleupagus/pageNumber-rtl
Tweak the `pageNumber` CSS to better support RTL locales
2023-04-08 20:19:12 +02:00
Jonas Jenwald
c95a09047a
Merge pull request #16261 from Snuffleupagus/loadingBar-rtl
Tweak the `loadingBar` CSS to better support RTL locales
2023-04-08 20:17:09 +02:00
Jonas Jenwald
61860ff56f Tweak the pageNumber CSS to better support RTL locales
This effectively implements some of the changes from https://phabricator.services.mozilla.com/D170496, but in such a way that the loading-icon won't overlay the page-number in RTL locales.
2023-04-08 13:57:17 +02:00
calixteman
1e9e3cafb8
Merge pull request #16260 from calixteman/gv_add_dl_button
[GeckoView] Add a basic toolbar with a download button for GV (bug 1823164)
2023-04-07 19:20:44 +02:00
Jonas Jenwald
6419e59036 Tweak the loadingBar CSS to better support RTL locales
This effectively implements some of the changes from https://phabricator.services.mozilla.com/D170496, but using our existing "direction aware" CSS-variable to limit the amount of code changes needed.
2023-04-07 13:36:06 +02:00
Calixte Denizet
3b147205ba [GeckoView] Add a basic toolbar with a download button for GV (bug 1823164) 2023-04-07 11:54:16 +02:00
Jonas Jenwald
08c8d310d3
Merge pull request #16256 from Snuffleupagus/issue-16254
Tweak the `--scale-factor` CSS-variable warning threshold (issue 16254)
2023-04-06 15:47:55 +02:00
Jonas Jenwald
4bf8e5c13d Tweak the --scale-factor CSS-variable warning threshold (issue 16254)
This is apparently needed to account for the rounding used in Chromium-browsers, such that the warning message isn't displayed unnecessarily.
2023-04-06 13:11:12 +02:00
Jonas Jenwald
65c4a4b3fe
Merge pull request #16241 from fchasen/bug_1820651
[Firefox] Add CSS at-page size when printing from FirefoxPrintService (bug 1820651)
2023-04-05 21:03:46 +02:00
Fred Chasen
3c326974a0 [Firefox] Add CSS at-page size when printing from FirefoxPrintService (bug 1820651)
- Duplicates at-page size method from PDFPrintService
- Updates getPagesOverview to rotate pages to fit the initial orientation
2023-04-05 10:33:56 -07:00
Jonas Jenwald
184076fe7a
Merge pull request #16226 from Snuffleupagus/rm-svg-viewer
[api-minor] Remove SVG-rendering from the viewer (PR 15173 follow-up)
2023-04-04 15:10:27 +02:00
Jonas Jenwald
96a3210501
Merge pull request #16248 from Snuffleupagus/editor-params-dispatchEvent
Reduce duplication when dispatching the "switchannotationeditorparams" event
2023-04-03 13:32:33 +02:00
Jonas Jenwald
ce3ea58778 [api-minor] Update the minimum supported Google Chrome version
The patch changes the minimum supported version of Google Chrome as follows:
 - Chrome 88, which was released on 2021-01-19; see https://en.wikipedia.org/wiki/Google_Chrome_version_history

This is done to allow use of modern CSS features, such as e.g. `:is()` and `:where()` in the code-base.
2023-04-03 13:23:26 +02:00
Jonas Jenwald
d256168b62 Reduce duplication when dispatching the "switchannotationeditorparams" event
Currently we repeat virtually the same code multiple times, which can be avoided by the introduction of a simple helper function.
2023-04-03 09:05:07 +02:00
Jonas Jenwald
bf57a8f660 Force-install when using gulp dist-install (issue 15435)
When installing the PDF.js project itself it's currently necessary to use `--force` in order for all packages to install correctly, see issue 15429, hence the same is also necessary when using the `gulp dist-install` command for local development/testing.
2023-04-02 16:06:36 +02:00
Jonas Jenwald
484da62f50 Inline PDFPageView.paintOnCanvas in the draw method, now that SVG-rendering is removed 2023-04-02 15:23:45 +02:00
Jonas Jenwald
92cf183f56 Re-factor the showCanvas function, reducing function calls during rendering 2023-04-02 15:23:45 +02:00
Jonas Jenwald
6858dae1c3 Change the finishPaintTask/finishPaintTask helpers into private methods 2023-04-02 15:23:45 +02:00
Jonas Jenwald
c2f1e65cc3 [api-minor] Remove SVG-rendering from the viewer (PR 15173 follow-up) 2023-04-02 15:23:45 +02:00
Tim van der Meij
b135dadb17
Merge pull request #16244 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-04-02 15:08:44 +02:00
Tim van der Meij
4eecd9e308
Bump versions in pdfjs.config 2023-04-02 15:03:13 +02:00
Tim van der Meij
be0f6ee080
Merge pull request #16242 from Snuffleupagus/rm-render-canvasFactory
[api-minor] Remove the `canvasFactory` option from `PDFPageProxy.render` (PR 16100 follow-up)
2023-04-02 13:51:01 +02:00
Tim van der Meij
1c7e2defea
Merge pull request #16243 from Snuffleupagus/toolbars-object-spread
Use object-spread when dispatching events in the toolbars
2023-04-02 13:49:03 +02:00
Jonas Jenwald
51113c17e9 Use object-spread when dispatching events in the toolbars
This format is more compact, and should be available in all browsers that we currently support; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#browser_compatibility
2023-04-02 12:10:15 +02:00
Jonas Jenwald
b35c03ac3a [api-minor] Remove the canvasFactory option from PDFPageProxy.render (PR 16100 follow-up) 2023-04-01 16:00:31 +02:00
Jonas Jenwald
8b7e44682c
Merge pull request #16159 from nmtigor/b-Object_in_api
Write some {Object} in api.js more precise
2023-04-01 15:57:46 +02:00
Tim van der Meij
b384d3bc24
Merge pull request #16232 from Snuffleupagus/firefox-rm-linkService-baseUrl
[Firefox] Stop using a `baseUrl` in the `PDFLinkService` (PR 16153 follow-up)
2023-04-01 15:37:51 +02:00
Tim van der Meij
13f2426aab
Merge pull request #16238 from Snuffleupagus/update-Node-compat-check
Update the Node.js compatibility-check in the worker-thread
2023-04-01 14:20:33 +02:00
Tim van der Meij
a9af0a6cc2
Merge pull request #16234 from Snuffleupagus/rm-disableCombineTextItems
[api-minor] Remove the `disableCombineTextItems` option
2023-04-01 14:18:00 +02:00
Jonas Jenwald
57a307d0cd Update the Node.js compatibility-check in the worker-thread
*Please note:* In Node.js environments a `legacy`-build must be used since only those versions include any polyfills.

Previously we'd only check if `ReadableStream` is natively supported, however since Node.js version 18 that's now been implemented; please see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#browser_compatibility
Hence we'll also check for the availability of `Path2D`, since that's browser-specific functionality not expected to be available in Node.js environments; please see https://developer.mozilla.org/en-US/docs/Web/API/Path2D#browser_compatibility
2023-03-30 18:36:15 +02:00
Jonas Jenwald
2358757b66
Merge pull request #16235 from Standard8/bug-1825522-generate-cleanup
Remove now unnecessary eslint-disable statement generated for PdfJsDefaultPreferences.sys.mjs. (bug 1825522).
2023-03-30 18:02:09 +02:00
Mark Banner
bb5467789b Remove now unnecessary eslint-disable statement generated for PdfJsDefaultPreferences.sys.mjs. (bug 1825522). 2023-03-30 14:47:31 +01:00
Jonas Jenwald
5063a6f2a9 [api-minor] Remove the disableCombineTextItems option
*Please note:* This parameter has never been used within the PDF.js library/viewer itself, and it was only ever added for backwards compatibility reasons.

This parameter was added in PR 7475, over six years ago, to try and optionally maintain the previous *default* text-extraction behaviour.
However as part of the general text-extraction improvements in PR 13257, almost two years ago, the `disableCombineTextItems` functionality was accidentally "broken" in various ways. Note how the only (very basic) unit-test was updated in a way that doesn't really make sense, since generally speaking you'd expect that using the option should result in *more* (or at least the same number of) text-items. Furthermore there's also the recent issue 16209, where the option causes almost all textContent to be concatenated together.

Hence this patch proposes that we simply remove the `disableCombineTextItems` option since it's essentially unused/untested functionality, as evident from the fact that it took almost two years for someone to notice that it's broken.
2023-03-30 14:23:38 +02:00
Jonas Jenwald
40a96a2524 [Firefox] Stop using a baseUrl in the PDFLinkService (PR 16153 follow-up)
With the changes in PR 16153 we're no longer setting a `<base href>` in the Firefox PDF Viewer, hence it shouldn't be necessary to keep setting a `baseUrl` in the `PDFLinkService`-class.
Given that the original document URL is now kept, the browser itself will handle relative URLs and we can thus slightly reduce the amount of string parsing required when handling various links in the viewer.
2023-03-30 11:51:25 +02:00
Jonas Jenwald
09da8026b6
Merge pull request #16228 from Snuffleupagus/firefox-imageResourcesPath
[Firefox] Set the `imageResourcesPath` correctly (PR 16153 follow-up)
2023-03-29 14:57:58 +02:00
Jonas Jenwald
e0e56e9e9c [Firefox] Set the imageResourcesPath correctly (PR 16153 follow-up)
We missed updating this path in PR 16153, which breaks loading of annotation-icons in the Firefox PDF Viewer.
2023-03-29 14:33:08 +02:00
Jonas Jenwald
43917796c2
Merge pull request #16227 from Snuffleupagus/zooming-regressions
Fix various zooming regressions (PR 15812 follow-up)
2023-03-29 12:15:26 +02:00
Calixte Denizet
4b7eb1436d Thin whitespaces must have their own span 2023-03-29 11:23:58 +02:00
Jonas Jenwald
7bca3c81a9 Fix CSS-only zooming in the viewer (PR 15812 follow-up)
Currently if you e.g. enable the `useOnlyCssZoom` option rendering may no longer finish as intended. To reproduce:
 - Enable the `useOnlyCssZoom` option.
 - Load https://github.com/mozilla/pdf.js/files/1522715/wuppertal_2012.pdf (in the development viewer).
 - When rendering starts, *immediately* change the zoom-level.

In this case the document will never finish rendering, since the `postponeDrawing`-functionality will (here incorrectly) abort rendering and with CSS-only zooming rendering is only expected to happen once per page.
To fix this we'll simply ignore any `drawingDelay` when CSS-only zooming is used (regardless if it's triggered via the option or the zoom-level being very large).
2023-03-29 10:36:48 +02:00
Jonas Jenwald
2c5a2d112c Fix rotation of the zoomLayer (PR 15812 follow-up)
Currently the `zoomLayer` isn't rotated correctly in all cases. To reproduce:
 - Load https://github.com/mozilla/pdf.js/files/1522715/wuppertal_2012.pdf
 - Let the document render.
 - Rotate the document *four* times, such that the original rotation is restored.

The easiest solution, as far as I can tell, is that we always set the `transform` just as we did (for years) prior to the changes in PR 15812.
2023-03-29 10:04:20 +02:00
calixteman
622465dc20
Merge pull request #16223 from calixteman/16221
Create a new chunk when the char is too rised compared to the previous one
2023-03-28 15:30:14 +02:00
Calixte Denizet
a96f10e55d Create a new chunk when the char is too rised compared to the previouse one 2023-03-28 13:56:46 +02:00
Jonas Jenwald
d584513cb2
Merge pull request #16213 from Snuffleupagus/validateCSSFont-quotes
Reduce duplication in the `validateCSSFont` helper function
2023-03-28 12:40:23 +02:00
Jonas Jenwald
ec08bd5c41
Merge pull request #16218 from Snuffleupagus/isPDFFunction-simplify
Simplify the `isPDFFunction` helper function
2023-03-28 11:16:25 +02:00
calixteman
b292d1ab95
Merge pull request #16217 from calixteman/bug1824610
ESMify some modules for m-c (bug 1824610)
2023-03-28 11:01:35 +02:00
Calixte Denizet
5f5256b4c4 ESMify some modules for m-c (bug 1824610) 2023-03-27 12:01:31 +02:00
Jonas Jenwald
20cbb89412 Simplify the isPDFFunction helper function
Originally we used helper functions for checking if something was a Dictionary or Stream, and then having an initial `typeof` check probably made sense.
However, given that we're using `instanceof` nowadays the additional check longer seems necessary.
2023-03-27 11:34:20 +02:00
Tim van der Meij
384bd96165
Merge pull request #16212 from Snuffleupagus/geckoview-rm-transition-CSS
[GeckoView] Remove unused `transition` CSS-rules
2023-03-26 16:01:08 +02:00
Jonas Jenwald
ef70988027 Reduce duplication in the validateCSSFont helper function
Currently we're *virtually* duplicating the same code, for validating quotation marks, twice in this helper function.

The size decrease is quite small (107 bytes) and this makes the code slightly harder to reader, hence I completely understand if this patch is rejected.
2023-03-26 12:12:49 +02:00
Jonas Jenwald
71fdf804de [GeckoView] Remove unused transition CSS-rules
Given that the GeckoView-viewer doesn't have a sidebar, there's no reason to have CSS-rules for it (and the variables are also undefined).
2023-03-26 10:35:19 +02:00
nmtigor
167b363eb3 Write some {Object} in api.js more precise 2023-03-25 22:00:06 +01:00
Jonas Jenwald
8a2dfdb032
Merge pull request #16211 from Snuffleupagus/occur-spelling
Fix spelling of `occurred` in a couple of comments
2023-03-25 20:54:29 +01:00
Jonas Jenwald
007c367018 Fix spelling of occurred in a couple of comments 2023-03-25 20:46:02 +01:00
Tim van der Meij
a1685fd0d8
Merge pull request #16199 from Snuffleupagus/commonobj-FontInspector
Slightly reduce the size of the `FontInspector`-integration in the API
2023-03-25 15:27:01 +01:00
Tim van der Meij
ca03b0a811
Merge pull request #16206 from Snuffleupagus/update-packages
Update packages and translations
2023-03-25 15:23:31 +01:00
Tim van der Meij
35322bcbaa
Merge pull request #16207 from Snuffleupagus/declaration-block-no-redundant-longhand-properties
Enable the `declaration-block-no-redundant-longhand-properties` Stylelint rule
2023-03-25 15:22:01 +01:00
Tim van der Meij
b3e2e26079
Merge pull request #16208 from Snuffleupagus/recoverJsURL-replaceAll
Use `replaceAll` in the `recoverJsURL` helper function
2023-03-25 15:20:33 +01:00
Jonas Jenwald
035a273d30 Use replaceAll in the recoverJsURL helper function
We can just do direct replacement when building the regular expression, rather than splitting the string into an Array and then re-joining it.
2023-03-25 12:31:39 +01:00
Jonas Jenwald
a4dfa04a0b Enable the declaration-block-no-redundant-longhand-properties Stylelint rule
Note that these changes were done automatically, using `gulp lint --fix`.
This rule will help avoid unnecessary repetition in the CSS; please see https://stylelint.io/user-guide/rules/declaration-block-no-redundant-longhand-properties/
2023-03-25 10:08:27 +01:00
Jonas Jenwald
a8af946bdc Update l10n files 2023-03-25 09:46:07 +01:00
Jonas Jenwald
ee15ec9144 Update npm packages 2023-03-25 09:41:15 +01:00
Jonas Jenwald
c706c6c34f
Merge pull request #16185 from Snuffleupagus/prefer-negative-index
Enable the `unicorn/prefer-negative-index` ESLint plugin rule
2023-03-24 12:12:11 +01:00
Jonas Jenwald
96e34fbb7d Enable the unicorn/prefer-negative-index ESLint plugin rule
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-negative-index.md
2023-03-24 10:18:32 +01:00
Jonas Jenwald
b119cde030
Merge pull request #16198 from Snuffleupagus/viewer-ChangeScale-cap
Reduce some duplication in the `PDFViewer.{increaseScale, decreaseScale}` methods
2023-03-24 10:07:22 +01:00
Jonas Jenwald
378caa7203 Slightly reduce the size of the FontInspector-integration in the API
Given that this functionality only applies in the viewer, when `PDFBug` is being enabled and used, it can't hurt to slightly reduce the size of this code.
2023-03-23 14:07:10 +01:00
Jonas Jenwald
184f5701e9
Merge pull request #16196 from Snuffleupagus/String-replaceAll
Use `String.prototype.replaceAll()` where appropriate
2023-03-23 13:59:59 +01:00
Jonas Jenwald
1fc09f0235 Enable the unicorn/prefer-string-replace-all ESLint plugin rule
Note that the `replaceAll` method still requires that a *global* regular expression is used, however by using this method it's immediately obvious when looking at the code that all occurrences will be replaced; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#parameters

Please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-replace-all.md
2023-03-23 12:57:10 +01:00
Jonas Jenwald
56b4699650 Reduce some duplication in the PDFViewer.{increaseScale, decreaseScale} methods
- Reduce a little bit of duplication by enforcing the max/min scale-values once, at the end, in the `increaseScale`/`decreaseScale` methods.
 - Convert the "private" `PDFViewer` scale-related methods into actually private ones, now that JavaScript supports that.
2023-03-23 09:25:23 +01:00
Jonas Jenwald
c3e62e1e4e
Merge pull request #16192 from nchevobbe/cursor-draggable
Use cursor:move for draggable texts and drawings (Bug 1804252)
2023-03-22 16:15:11 +01:00
Jonas Jenwald
5f64621d46 Use String.prototype.replaceAll() where appropriate
This fairly new method allows replacing *multiple* occurrences within a string without having to use regular expressions.

Please refer to:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#browser_compatibility
2023-03-22 15:31:10 +01:00
Jonas Jenwald
076bb30b6c
Merge pull request #16182 from Snuffleupagus/inset-block
Introduce `inset-block` usage in the viewer CSS
2023-03-22 12:59:10 +01:00
Jonas Jenwald
915bdd6576
Merge pull request #16173 from Snuffleupagus/inset
Introduce `inset` usage in the CSS files
2023-03-22 12:57:57 +01:00
Jonas Jenwald
39bbd8c94f
Merge pull request #16193 from Snuffleupagus/non-standard-ligatures
Add even more non-standard ligatures (PR 15517 follow-up)
2023-03-22 12:27:54 +01:00
Jonas Jenwald
137a2d6e30 Add even more non-standard ligatures (PR 15517 follow-up)
Given that we already create multi-byte ToUnicode entries in other cases, see e.g. the `getNormalizedUnicodes` table, this is hopefully fine.
2023-03-22 10:42:52 +01:00
Jonas Jenwald
f39ff20485
Merge pull request #16191 from Snuffleupagus/XRefStm-Set
Track previous "XRefStm"s in a `Set`, rather than an `Object`
2023-03-22 10:25:53 +01:00
Nicolas Chevobbe
7f80052fdf Use cursor:move for draggable texts and drawings (Bug 1804252) 2023-03-22 09:49:43 +01:00
Jonas Jenwald
122d5e549a Track previous "XRefStm"s in a Set, rather than an Object
Having just reviewed a patch touching this code, I couldn't help noticing that an `Object` isn't really the optimal data-structure for this and nowadays we can do better by using a `Set` instead.
2023-03-22 09:41:19 +01:00
Jonas Jenwald
9321758d91
Merge pull request #16186 from Snuffleupagus/issue-16176
Support multi-byte ToUnicode entries, when using predefined CMaps (issue 16176)
2023-03-21 22:17:18 +01:00
Jonas Jenwald
d4bcfe8c16 Support multi-byte ToUnicode entries, when using predefined CMaps (issue 16176)
Hopefully this makes sense, since we already "create" multi-byte ToUnicode entries in other cases (see e.g. the `getNormalizedUnicodes` table).
2023-03-21 21:35:57 +01:00
calixteman
8bfebf1c24
Merge pull request #16188 from calixteman/bug1823296
Use the position of the previous xref stream if any when saving a pdf (bug 1823296)
2023-03-21 21:21:49 +01:00
Calixte Denizet
2d0f30a67c Use the position of the previous xref stream if any when saving a pdf (bug 1823296) 2023-03-21 19:27:24 +01:00
Jonas Jenwald
a3ab2f6790 Introduce inset-block usage in the viewer CSS
Given that the viewer always set the `dir`-attribute, to either LTR or RTL, we should be able to use this logical CSS property to (very slightly) reduce the size of the CSS; please see https://developer.mozilla.org/en-US/docs/Web/CSS/inset-block
2023-03-20 16:42:39 +01:00
Jonas Jenwald
b1e0253f29
Merge pull request #16175 from Snuffleupagus/LoopbackPort-transfer
Fix the `transfer` parameter, for `structuredClone`, in the `LoopbackPort`
2023-03-20 14:22:09 +01:00
Jonas Jenwald
a29c131e90
Merge pull request #16181 from Snuffleupagus/pr-16162
Only warn about missing `--scale-factor` CSS-variable for visible textLayers (PR 16162 follow-up)
2023-03-20 14:21:37 +01:00
Jonas Jenwald
8bf5e96af9 Only warn about missing --scale-factor CSS-variable for visible textLayers (PR 16162 follow-up)
This is something that I completely overlooked in PR 16162, which in some cases cause the default viewer to incorrectly print warnings.
This can be reproduced with the PAGE scrolling-mode, and/or the PresentationMode, and this patch simply work-around it by checking the visibility as well (since the warning is a best-effort solution anyway).
2023-03-20 12:51:26 +01:00
Jonas Jenwald
fb2367d14f
Merge pull request #16180 from Snuffleupagus/appendFeFunc
Add a helper, in `DOMFilterFactory`, to reduce duplication when creating `<feFuncX>`s
2023-03-20 12:41:03 +01:00
Jonas Jenwald
cc9f6650a8 Stop passing in pageColors to the CanvasGraphics-constructor (PR 16075 follow-up)
The `pageColors`-option was removed from the `CanvasGraphics`-constructor in PR 16075, hence the code in the API no longer needs to pass in that option; this is something that I missed during review.
2023-03-20 11:41:57 +01:00
Jonas Jenwald
86cf62699c Add a helper, in DOMFilterFactory, to reduce duplication when creating <feFuncX>s
Currently we repeat the same code verbatim multiple times in the `DOMFilterFactory`, which seems completely unnecessary.
2023-03-20 11:27:47 +01:00
calixteman
3903391f3c
Merge pull request #16075 from calixteman/svg_filter_hcm
[api-minor] Use a SVG filter when rendering pages in HCM
2023-03-20 10:18:25 +01:00
Jonas Jenwald
c4a725fe98 Fix the transfer parameter, for structuredClone, in the LoopbackPort
The way that we handle the `transfer` parameter is unfortunately wrong, ever since PR 14392 which introduced the code, given that the MDN article originally contained incorrect information; please see https://github.com/mdn/content/pull/23164

By updating the `structuredClone` call such that it works correctly, we can enable more unit-tests in Node.js environments; please refer to https://developer.mozilla.org/en-US/docs/Web/API/structuredClone#parameters
2023-03-19 22:04:01 +01:00
Jonas Jenwald
553c2e05cd Introduce inset usage in the CSS files
The `inset` property is a nice shorthand that can be used to avoid having to specify the positions individually; please see
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline
2023-03-19 14:32:37 +01:00
Tim van der Meij
33f5d94f23
Merge pull request #16172 from Snuffleupagus/margin-inline
Use `margin-inline` in the `web/pdf_viewer.css` file (PR 14670 follow-up)
2023-03-19 12:43:44 +01:00
Tim van der Meij
6b89e66bd0
Merge pull request #16169 from Snuffleupagus/viewer-html-preprocessor-cleanup
Clean-up the pre-processor statements in `web/viewer.html`
2023-03-19 12:34:11 +01:00
Jonas Jenwald
1efe41c248 Use margin-inline in the web/pdf_viewer.css file (PR 14670 follow-up)
Given that the viewer always set the `dir`-attribute, we should be able to use logical margins in this CSS file as well; please also see https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline
2023-03-19 12:31:34 +01:00
Tim van der Meij
27fe7e9e72
Merge pull request #16171 from Snuffleupagus/PDFViewer-cleanup-scale-methods
Clean-up the `PDFViewer.{increaseScale, decreaseScale}` methods
2023-03-19 12:30:11 +01:00
Jonas Jenwald
9060757064 Clean-up the PDFViewer.{increaseScale, decreaseScale} methods
The signatures of these methods were changed in PR 15886, which has now been included in a couple of releases, hence it should hopefully be OK to remove the fallback code-paths now.
Also, the methods are updated slightly to be explicit about what options are supported and we'll no longer pass along any arbitrary options to the "private" methods.
2023-03-19 11:47:02 +01:00
Jonas Jenwald
7d688769cf Clean-up the pre-processor statements in web/viewer.html
Some of these pre-processor statements are *many* years old, and could thus do with some clean-up. Note that the pre-processor originally didn't support else-if statements, and by using those the code becomes a bit less verbose.
2023-03-18 17:17:46 +01:00
Tim van der Meij
9db4509664
Merge pull request #16166 from Snuffleupagus/pr-16151-followup
Simplify the `applyTransferMapsToCanvas` method (PR 16151 follow-up)
2023-03-18 14:06:42 +01:00
Calixte Denizet
da080cc26e [api-minor] Use a SVG filter when rendering pages in HCM
The idea is to apply an overall filter on each page: the main advantage
is to have some filtered images which could help to make them visible for
some users.
2023-03-18 12:45:10 +01:00
Jonas Jenwald
2fea9ee21b Simplify the applyTransferMapsToCanvas method (PR 16151 follow-up)
During review of PR 16151 this method was simplified, however I overlooked the fact that we now can (and really should) improve this by removing duplication.
2023-03-17 12:58:35 +01:00
Jonas Jenwald
85166c60fd
Merge pull request #16162 from Snuffleupagus/issue-16139
Warn about missing/incorrect `--scale-factor` CSS-variable in `renderTextLayer` (issue 16139)
2023-03-16 16:41:13 +01:00
Jonas Jenwald
0e54a3c37a Warn about missing/incorrect --scale-factor CSS-variable in renderTextLayer (issue 16139)
Unfortunately I don't believe that we can simply add a default `--scale-factor` CSS-variable to the `container`-element, since that might not be entirely appropriate/correct in all cases.[1]
However, we can at least print a console-error to hopefully make this situation more apparent to users. (This is purposely not using the `warn` helper-function, since those messages can be disabled.)

---
[1] One example is in our reference-tests, where we don't need to add it to the `container`-element itself.
2023-03-16 11:53:12 +01:00
Jonas Jenwald
5e4b3d13eb
Merge pull request #16151 from Snuffleupagus/DefaultFilterFactory
[api-minor] Extend general transfer function support to browsers without `OffscreenCanvas`
2023-03-14 14:03:26 +01:00
Jonas Jenwald
07a3283e53
Merge pull request #16152 from Snuffleupagus/type-fixes
Miscellaneous small TypeScript fixes
2023-03-14 13:24:51 +01:00
Jonas Jenwald
50c844c5b8 Stop including isOffscreenCanvasSupported in the "StartRenderPage" message
With the previous commit this is now completely unused in API, hence it can be removed. This is done in a separate commit to make it easier to re-instate it, would the need ever arise.
2023-03-14 13:09:20 +01:00
Jonas Jenwald
fc055dbd80 [api-minor] Extend general transfer function support to browsers without OffscreenCanvas
This patch extends PR 16115 to work in all browsers, regardless of their `OffscreenCanvas` support, such that transfer functions will be applied to general rendering (and not just image data).
In order to do this we introduce the `BaseFilterFactory` that is then extended in browsers/Node.js environments, similar to all the other factories used in the API, such that we always have the necessary factory available in `src/display/canvas.js`.

These changes help simplify the existing `putBinaryImageData` function, and the new method can easily be stubbed-out in the Firefox PDF Viewer.

*Please note:* This patch removes the old *partial* transfer function support, which only applied to image data, from Node.js environments since the `node-canvas` package currently doesn't support filters. However, this should hopefully be fine given that:
 - Transfer functions are not very commonly used in PDF documents.
 - Browsers in general, and Firefox in particular, are the *primary* development target for the PDF.js library.
 - The FAQ only lists Node.js as *mostly* supported, see https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
2023-03-14 13:09:08 +01:00
calixteman
945855a2b8
Merge pull request #16153 from calixteman/rm_base
Remove <base> tag from the Firefox built-in viewer (bug 1821408)
2023-03-14 10:40:15 +01:00
Calixte Denizet
ea1d090109 Remove <base> tag from the Firefox built-in viewer (bug 1821408)
The tag <base> is used to resolve relative URIs within the document.
Newly added SVG filters use a relative URI which then use the URI in base
but this one mismatches with the document URI and consequently filters are
not found in the Firefox viewer.
So this patch just removes <base> and replace few relative URLs by absolute
ones.
2023-03-14 10:12:42 +01:00
Jonas Jenwald
103fda1d91 Update the canvasContext parameter, in RenderParameters (issue 16133)
Hopefully this works correctly (since I don't know anything about TypeScript), given that `CanvasRenderingContext2D` is a standard name; please see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
2023-03-13 16:56:36 +01:00
Jonas Jenwald
e981badb94 Mark updateMatchesCountOnProgress, in the PDFFindControllerOptions, as optional (issue 15990) 2023-03-13 16:46:33 +01:00
Tim van der Meij
351d11c9bd
Merge pull request #16147 from Snuffleupagus/update-packages
Update packages and translations
2023-03-12 13:29:51 +01:00
Jonas Jenwald
c6c9eb4ccb Update l10n files 2023-03-12 10:40:53 +01:00
Jonas Jenwald
1d06523366 Update npm packages 2023-03-12 10:36:00 +01:00
Tim van der Meij
9819f1cc6b
Merge pull request #16108 from Snuffleupagus/delay-cleanup
Slightly delay cleanup, after rendering, in documents with large images
2023-03-11 15:52:12 +01:00
Tim van der Meij
05f29c8720
Merge pull request #16141 from Snuffleupagus/FilterFactory-docId
Include the document-id in the SVG-filter names (PR 16062 follow-up)
2023-03-11 15:45:42 +01:00
Tim van der Meij
1234d207e9
Merge pull request #16142 from Snuffleupagus/issue-16134
Fix the JSDoc `returns`-type for two `PageViewport`-methods (issue 16134)
2023-03-11 14:53:21 +01:00
Tim van der Meij
cc499505df
Merge pull request #16123 from Snuffleupagus/Node-16
[api-minor] Update the minimum supported Node.js version to 16
2023-03-11 14:49:59 +01:00
calixteman
b2a86350fc
Merge pull request #16096 from bungeman/fix_trig_functions
Correct PostScript trigonometric operators
2023-03-11 14:32:23 +01:00
calixteman
4a4c5d0fe2
Merge pull request #16145 from calixteman/issue16135
Move the svg definitions in its own div
2023-03-10 17:45:29 +01:00
Calixte Denizet
f9539e57ef Move the svg definitions in its own div
This way the svg element doesn't take up space in the viewer.
Fixes issue #16135.
2023-03-10 17:03:40 +01:00
calixteman
0338df2f6d
Merge pull request #16138 from calixteman/bug1820909
Fix search in pdf a containing some UTF-32 characters (bug 1820909)
2023-03-09 19:15:49 +01:00
Jonas Jenwald
9232264b8a Fix the JSDoc returns-type for two PageViewport-methods (issue 16134)
The affected methods have always returned Arrays, however the JSDoc did not accurately reflect that.
2023-03-09 15:57:16 +01:00
Jonas Jenwald
92296fa6a1 Include the document-id in the SVG-filter names (PR 16062 follow-up)
In the general PDF.js library multiple PDF documents may be opened on the same web-page, which is why we many years ago started using document-specific identifiers to prevent issues with global data such e.g. with fonts.
Hence we need to treat the identifiers generated by the `FilterFactory` in the same way, since the SVG-filters for two separate PDF documents may otherwise get identical ids.
2023-03-09 15:35:29 +01:00
Calixte Denizet
07b094729e Fix search in pdf a containing some UTF-32 characters (bug 1820909)
Some chars were supposed to have a length equals to 1 but UTF-32 chars
can be longuer.
2023-03-09 15:03:01 +01:00
Ben Wagner
5fad91a680 Better approximate gradient color stops
PDF gradients do not have color stops but an arbitrary PDF function of
the type f(t) -> color. CSS gradients are only based on color stops.
Most PDF gradient functions are produced from color stop oriented
gradients.

Take advantage of this by sampling the PDF function at a higher
frequency but not converting any samples which could be interpolated to
color stops. The sampling frequency is chosen to be the least common
multiple of as many values as practical to exactly re-create the common
case of the PDF function implementing equally spaced linearly
interpolated stops in RGB color space. This also allows for better
approximation of other smooth PDF functions (non-linear, or non-equally
spaced, or in different color space).

Fixes: #10572, #14165
2023-03-09 08:49:50 -05:00
Jonas Jenwald
c0671ac133 Slightly increase the maximum image sizes that we'll cache
The current value originated in PR 2317, and in the decade that have passed the amount of RAM available in (most) devices should have increased a fair bit.
Nowadays we also do a much better job of detecting repeated images at both the page- and document-level, which helps reduce overall memory-usage in many documents.

Finally the constant is also moved into the `src/shared/util.js` file, since it was implicitly used on both the main- and worker-thread previously.
2023-03-08 17:06:10 +01:00
Jonas Jenwald
15d9faba57 Slightly delay cleanup, after rendering, in documents with large images
Currently in PDF documents with large images we immediately cleanup once rendering has finished, in order to reduce memory-usage.
Normally that shouldn't be a big problem, however when e.g. repeated zooming happens in the viewer that could easily lead to a lot of wasted resources (and waiting).

Hence this patch, which introduces a new `PDFPageProxy` method that will slightly delay cleanup after rendering.
2023-03-08 17:06:09 +01:00
Jonas Jenwald
e7a7f02f4c Convert a couple of fields/methods into properly private ones in PDFPageProxy
These were always intended to be *private*, so let's use modern JS features to actually enforce that.
2023-03-08 17:06:09 +01:00
calixteman
a0ef5a4ae1
Merge pull request #16115 from calixteman/issue16114
Apply transfer filters to any graphic commands
2023-03-08 14:53:41 +01:00
calixteman
32e2f7c8e5
Merge pull request #16131 from calixteman/issue16049
Partially revert PR 15578
2023-03-08 12:57:18 +01:00
Jonas Jenwald
6839f15a32
Merge pull request #16128 from Snuffleupagus/issue-16127
Support (rare) Type3 fonts with Pattern resources (issue 16127)
2023-03-08 12:21:53 +01:00
Jonas Jenwald
e5427ab11b
Merge pull request #16122 from Snuffleupagus/rm-onUnsupportedFeature
[api-minor] Remove the deprecated `onUnsupportedFeature` functionality (PR 15758 follow-up)
2023-03-08 12:16:27 +01:00
Calixte Denizet
dabfbc623e Partially revert PR 15578
The dimensions still need to be fixed (from times to times they're in px)
but it doesn't have to be postponed anymore.
To test it: draw something and when resizing look at the dimensions of the div
in devtools, the units must be %.
2023-03-08 12:10:27 +01:00
calixteman
cc555a389b
Merge pull request #16117 from calixteman/workaround_bug1820511
Avoid to have a factor too close to 2 when downscaling image
2023-03-08 11:12:56 +01:00
Calixte Denizet
1617ee6c3f Avoid to have a factor too close to 2 when downscaling image
It's a workaround for bug 1820511: it only affects Firefox on Windows
using the D2D backend.
2023-03-08 11:05:46 +01:00
calixteman
39ff039b8a
Merge pull request #16125 from calixteman/firefox_max_area
[api-minor] Add an option to set the max canvas area
2023-03-08 10:56:03 +01:00
Calixte Denizet
e9474f1c84 [api-minor] Add an option to set the max canvas area 2023-03-08 10:37:06 +01:00
Jonas Jenwald
471aef5fc6 Support (rare) Type3 fonts with Pattern resources (issue 16127)
This simply extends the approach in PR 10727 to also cover Patterns, which shouldn't be a common occurrence in Type3 fonts (since this is the first issue we've seen).
2023-03-08 09:20:52 +01:00
Calixte Denizet
8304df2520 Apply transfer filters to any graphic commands 2023-03-07 22:17:19 +01:00
calixteman
e0d934ac9d
Merge pull request #16124 from calixteman/issue16119
Slightly modify the max width of a tracking space
2023-03-07 22:12:02 +01:00
Calixte Denizet
b8dda089e2 Slightly modify the max width of a tracking space 2023-03-07 19:38:49 +01:00
Jonas Jenwald
6d3506548d [api-minor] Update the minimum supported Node.js version to 16
This patch updates the minimum supported environments as follows:
 - Node.js 16, which was released on 2021-04-20; see https://en.wikipedia.org/wiki/Node.js#Releases

Note also that Node.js 14 will very soon reach EOL, and thus no longer receive any security updates.
2023-03-07 16:33:56 +01:00
calixteman
ec5288caa5
Merge pull request #16121 from calixteman/issue16120
Use appearance stream to render locked annotations (bug 1723568)
2023-03-07 15:43:50 +01:00
Calixte Denizet
8db77cc361 Use appearance stream to render locked annotations (bug 1723568) 2023-03-07 15:01:31 +01:00
Jonas Jenwald
076fdbf6df
Merge pull request #16118 from Snuffleupagus/revert-update-rimraf
Revert "Update `rimraf` to version 4"
2023-03-07 13:38:30 +01:00
Jonas Jenwald
2f3dcc2327 [api-minor] Remove the deprecated onUnsupportedFeature functionality (PR 15758 follow-up)
This was deprecated in PR 15758, which has now been included in three official PDF.js releases.
While PR 15880 did limit the bundle-size impact of this functionality on e.g. the Firefox PDF Viewer, it still leads to some unnecessary "bloat" that these changes remove.
Furthermore, with this being deprecated there'd also be no effort put into e.g. extending the `UNSUPPORTED_FEATURES` list when handling future error cases.
2023-03-07 10:18:43 +01:00
Jonas Jenwald
2f2f1e5088 Revert "Update rimraf to version 4"
This reverts commit 32357e3d172a552e0408b3e1ed743e87fe7d5a21.
2023-03-06 19:57:00 +01:00
calixteman
e11371c75f
Merge pull request #16110 from calixteman/norotate
[Annotation] Don't rotate an annotation when it has the NoRotate flag
2023-03-06 19:17:44 +01:00
Calixte Denizet
3849063d36 [Annotation] Don't rotate an annotation when it has the NoRotate flag 2023-03-06 17:27:11 +01:00
calixteman
652a6df62b
Merge pull request #16077 from calixteman/large_image
Render large images even if they're larger than the canvas limits (bug 1720282)
2023-03-05 15:38:51 +01:00
Calixte Denizet
05b0c9d7e6 Render large images even if they're larger than the canvas limits (bug 1720282)
The idea is to encode large image in BMP format (which is very simple and doesn't
require to compute any checksums) and then use createImageBitmap with a BMP blob
(which doesn't suffer of the Canvas/ImageData limits).
From a performance point of view, it isn't crazy (generating a large blob + decoding
it on the main thread is really not ideal) but at least we've something to display
which is a way better than a blank page (and one can notice that most of the time is
spent in decoding the image from the pdf stream).
2023-03-05 14:07:07 +01:00
Jonas Jenwald
d7e4be9cdb
Merge pull request #16107 from mozilla/dependabot/npm_and_yarn/minimist-1.2.7
Bump minimist from 1.2.5 to 1.2.7
2023-03-04 10:10:37 +01:00
dependabot[bot]
5cc65d193f
Bump minimist from 1.2.5 to 1.2.7
Bumps [minimist](https://github.com/minimistjs/minimist) from 1.2.5 to 1.2.7.
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](https://github.com/minimistjs/minimist/compare/v1.2.5...v1.2.7)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-04 02:42:21 +00:00
Ben Wagner
158c836e26 Correct PostScript trigonometric operators
PDF 32000-1:2008 7.10.5.1 "Type 4 (PostScript Calculator) Functions"
defers to the PostScript Language Reference for the description of these
functions. The PostScript Language Reference, third edition chapter 8
"Operators" defines the `angle` type as a "number of degrees". Section
8.1 defines "angle `sin` real", "angle `cos` real", and "num den `atan`
angle". The documentation for `atan` further states that it will return
an angle in degrees between 0 and 360.

Handle these operators correctly in `PostScriptEvaluator.execute`.
Convert the inputs to `sin` and `cos` from degrees to radians for use
with `Math.sin` and `Math.cos`. Correctly pop two values from the stack
for `atan`, use `Math.atan2`, and convert from radians to (positive)
degrees.
2023-03-03 17:25:11 -05:00
Jonas Jenwald
4e52bcee44
Merge pull request #16103 from Snuffleupagus/rm-direct-PDFDataRangeTransport
[api-minor] Remove calling `getDocument` directly with a `PDFDataRangeTransport`-instance (PR 15943 follow-up)
2023-03-02 18:25:00 +01:00
Jonas Jenwald
ceec93c832
[api-minor] Remove calling getDocument directly with a PDFDataRangeTransport-instance (PR 15943 follow-up)
This was deprecated in PR 15943, which has now been included in two official PDF.js releases.
Given that `PDFDataRangeTransport` is somewhat unlikely to be used outside of the *built-in* Firefox PDF Viewer, it doesn't seem necessary to wait longer before removing this.

Also, removes the specific error-message for GENERIC builds to not unnecessarily "advertise" using non-objects when calling the `getDocument`-function.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
2023-03-02 15:12:01 +01:00
calixteman
d4216264e8
Merge pull request #16062 from calixteman/create_image_in_worker
[api-minor] Generate images in the worker instead of the main thread.
2023-03-02 13:34:50 +01:00
Calixte Denizet
fd03cd5493 [api-minor] Generate images in the worker instead of the main thread.
We introduced the use of OffscreenCanvas in #14754 and this patch aims
to use them for all kind of images.
It'll slightly improve performances (and maybe slightly decrease memory use).
Since an image can be rendered in using some transfer maps but because of
OffscreenCanvas we don't have the underlying pixels array the transfer maps
stuff is re-implemented in using the SVG filter feComponentTransfer.
2023-03-01 17:40:12 +01:00
Jonas Jenwald
9640add1f7
Merge pull request #16100 from Snuffleupagus/getDocument-canvasFactory
[api-minor] Move the `canvasFactory` option into `getDocument`
2023-03-01 10:34:11 +01:00
Jonas Jenwald
f42a2e8451
[api-minor] Move the canvasFactory option into getDocument
Rather than repeatedly initializing a `canvasFactory`-instance for every page, move it to the document-level instead.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
2023-03-01 09:07:16 +01:00
Jonas Jenwald
22c9970309
Merge pull request #16095 from Snuffleupagus/worker-isOffscreenCanvasSupported
Check `OffscreenCanvas` support once on the worker-thread
2023-02-28 08:25:50 +01:00
Jonas Jenwald
45c332110e
Check OffscreenCanvas support once on the worker-thread
Currently we repeat the `FeatureTest.isOffscreenCanvasSupported` checks all over the worker-thread code, and with upcoming changes this will become even "worse".

Hence this patch, which changes the *worker-thread* default value for the `isOffscreenCanvasSupported`-parameter to `false` and moves the feature-testing into the `BasePdfManager`-constructor.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
2023-02-27 12:27:28 +01:00
Tim van der Meij
2da2ac492e
Merge pull request #16093 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-02-26 13:22:23 +01:00
Tim van der Meij
580180a720
Bump versions in pdfjs.config 2023-02-26 13:15:43 +01:00
Jonas Jenwald
af64149885
Merge pull request #16086 from mozilla/Snuffleupagus-textLayer-OffscreenCanvas
Use `OffscreenCanvas` as intended for all code-paths in `src/display/text_layer.js` (PR 15722 follow-up)
2023-02-24 22:40:18 +01:00
Jonas Jenwald
5075d0495b
Use OffscreenCanvas as intended for all code-paths in src/display/text_layer.js (PR 15722 follow-up)
Currently some `getCtx` calls will have `isOffscreenCanvasSupported === undefined` set, meaning that `OffscreenCanvas` isn't being used as intended, since no `TextLayerRenderTask._isOffscreenCanvasSupported` property exists.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
2023-02-24 11:29:58 +01:00
calixteman
9c58d4f7f2
Merge pull request #16082 from calixteman/fix_class_in_path
[Acroform] Use the full path to find the node in the XFA datasets where to store the value
2023-02-23 13:38:54 +01:00
Calixte Denizet
3a21423386 [Acroform] Use the full path to find the node in the XFA datasets where to store the value
I noticed several 'Path not found' errors because of a field called #subform[2].
From the XFA specs, the hash is used for a class of elements in the template tree.
When we're looking for a node in the datasets tree, it doesn't make sense to search
for a class. Hence the path element starting with a hash are just skipped.
2023-02-23 12:09:39 +01:00
calixteman
e676c9388d
Merge pull request #16080 from calixteman/link_hcm
[a11y] Improve the visibility of link annotations in HCM
2023-02-22 20:31:51 +01:00
Calixte Denizet
a074525bfb [a11y] Improve the visibility of link annotations in HCM
In order to help to identify a link, we add a border around it with the LinkText color.
And backdrop colors are inverted when the mouse pointer hovers them, this way it should
help to identify the link where the pointer is.
2023-02-22 19:39:28 +01:00
Jonas Jenwald
3f33fbf8cf
Merge pull request #16079 from mozilla/Snuffleupagus-PDFObjects-bitmap
Move the `ImageBitmap` clean-up into the `PDFObjects` class
2023-02-22 13:51:12 +01:00
Jonas Jenwald
1b076b7a35
Move the ImageBitmap clean-up into the PDFObjects class
With upcoming changes we'll potentially start to cache `ImageBitmap` data at the document-level, in addition to just at the page-level.
Hence we need to ensure that such data is actually released on clean-up, and rather than duplicating the existing *manual* handling this code is instead moved into the `PDFObjects.clear` method. (In my opinion, this is an overall improvement even without globally cached `ImageBitmap` data.)

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it's correct and makes sense.
2023-02-21 12:00:45 +01:00
calixteman
534b22aec5
Merge pull request #16071 from calixteman/issue16067
[JS] Send a Validate action on change on Choice widget
2023-02-20 11:15:20 +01:00
Calixte Denizet
dca54c8f8a [JS] Send a Validate action on change on Choice widget 2023-02-19 16:33:05 +01:00
Tim van der Meij
255e982542
Merge pull request #16056 from Snuffleupagus/xfaLayer-on-top
Don't try to place the `xfaLayer` "on top" in regular PDF documents
2023-02-19 12:22:10 +01:00
Tim van der Meij
f2baa48608
Merge pull request #16055 from Snuffleupagus/deprecated-Node-Buffer
[api-minor] Deprecate providing binary data as `Buffer` in Node.js environments
2023-02-19 12:20:09 +01:00
Tim van der Meij
9fac676796
Merge pull request #16054 from Snuffleupagus/Driver-getDocument-cleanup
A little clean-up of the `getDocument` call in `test/driver.js`
2023-02-19 12:12:07 +01:00
calixteman
13af3f3442
Merge pull request #16065 from calixteman/issue16063
Don't replace an eol by a whitespace when the last char is a Katakana-Hiragana diacritic
2023-02-17 13:40:54 +01:00
Calixte Denizet
fc7d74385f Don't replace an eol by a whitespace when the last char is a Katakana-Hiragana diacritic 2023-02-16 11:31:58 +01:00
Jonas Jenwald
3c66b031e3 Don't try to place the xfaLayer "on top" in regular PDF documents
Given that we only create an `xfaLayer` in "pure" XFA-documents, this code can be moved into the appropriate branch instead.
2023-02-14 12:54:44 +01:00
Jonas Jenwald
b6ba8cc84a [api-minor] Deprecate providing binary data as Buffer in Node.js environments
The `Buffer`-object is Node.js specific functionality[1], thus (obviously) not found in browsers. Please note that the PDF.js library has never officially supported/documented that binary data can be passed as a `Buffer`, and that *internally* in the `src/core`-code we only work with standard `Uint8Array`s.
This means that if, in Node.js environments, a `Buffer` is passed to the API we need to wrap it into a `Uint8Array`, which essentially means creating a copy of the data and thus increasing memory usage.

---
[1] Refer to https://nodejs.org/api/buffer.html#buffer
2023-02-14 11:30:40 +01:00
Jonas Jenwald
df3b359280 Remove "else after return" from the getUrlProp/getDataProp helper functions
This helps readability of this code a little bit, in my opinion, and it's actually ever so slightly less code in the *built* `pdf.js` file.
2023-02-14 10:50:22 +01:00
Jonas Jenwald
0e840f1c39 A little clean-up of the getDocument call in test/driver.js
- Pass the `URL`-object directly to `getDocument`, since that's been supported since PR 13166.
 - Remove support for the `disableRange`-option in the test-manifest, since it's completely unused. Please note that it's originally added in PR 2719, however there's never actually been any reference tests using it (not even from the start).
   Given that the option is `false` by default everywhere (e.g. in the Firefox PDF Viewer) and that we have unit-tests for `disableRange = true`, it doesn't seem necessary to add new reference tests for it now.
2023-02-13 14:49:33 +01:00
Jonas Jenwald
546902df63
Merge pull request #16053 from Snuffleupagus/test-set-annotationStorage
Reduce duplication for reference tests with an `annotationStorage` entry
2023-02-13 11:56:12 +01:00
Jonas Jenwald
8026ed6b0a Reduce duplication for reference tests with an annotationStorage entry
Currently we duplicate the same code more than once in the `test/driver.js` file, which we can avoid by adding a new `AnnotationStorage` helper method instead.
2023-02-13 11:09:16 +01:00
Tim van der Meij
f66cbb0b5e
Merge pull request #16051 from Snuffleupagus/rm-PDFThumbnailViewer-eventBus
Remove the unused `eventBus` option in `PDFThumbnailViewer` (PR 15215 follow-up)
2023-02-12 19:29:52 +01:00
Jonas Jenwald
6985286300 Remove the unused eventBus option in PDFThumbnailViewer (PR 15215 follow-up)
This became unused with PR 15215, but I unfortunately forgot to remove it.
2023-02-12 18:38:31 +01:00
Tim van der Meij
22618213c7
Merge pull request #16040 from Snuffleupagus/arrayBuffersToBytes
Re-factor the `arraysToBytes` helper function (PR 16032 follow-up)
2023-02-12 11:47:57 +01:00
Jonas Jenwald
6d4d402a78 Move the arrayBuffersToBytes helper function into the worker-thread
Given that this helper function is only used on the worker-thread, there's no reason to duplicate it in both of the *built* `pdf.js` and `pdf.worker.js` files.
2023-02-11 21:34:37 +01:00
Tim van der Meij
25a6bc4e01
Merge pull request #16013 from Snuffleupagus/COMPONENTS-rm-inline-attachment-open
Remove inline opening of PDF attachments in the COMPONENTS build
2023-02-11 19:03:51 +01:00
Tim van der Meij
ddf05b0795
Merge pull request #16028 from Snuffleupagus/move-CHROME-rewriteUrlClosure
Move `rewriteUrlClosure` into the `web/chromecom.js` file
2023-02-11 19:02:32 +01:00
Tim van der Meij
3daf4274e8
Merge pull request #16045 from Snuffleupagus/viewer-initializeOptions
Slightly re-factor preferences/options initialization in the viewer
2023-02-11 19:01:31 +01:00
Tim van der Meij
ec4c84176f
Merge pull request #16047 from Snuffleupagus/BasePdfManager-args
Improve the consistency between the `LocalPdfManager`/`NetworkPdfManager` constructor
2023-02-11 18:58:29 +01:00
Tim van der Meij
5c3017b6ae
Merge pull request #16048 from Snuffleupagus/update-Stylelint
Update Stylelint to version 15
2023-02-11 18:49:52 +01:00
Jonas Jenwald
5023a41fb7 Update Stylelint to version 15
Notably this obsoletes the `stylelint-config-prettier` package; please see https://github.com/stylelint/stylelint/blob/main/docs/migration-guide/to-15.md for additional details.
2023-02-11 14:41:32 +01:00
Tim van der Meij
fd1c9e34ac
Merge pull request #16046 from Snuffleupagus/update-packages
Update packages and translations
2023-02-11 14:10:09 +01:00
Jonas Jenwald
18042163ce Improve the consistency between the LocalPdfManager/NetworkPdfManager constructor
Currently these classes take a bunch of parameters (somewhat randomly ordered), probably because this is very old code that's been extended over the years.
Hence this patch changes the constructors to use parameter-objects instead, which improves consistency and (slightly) reduces the amount of code as well.

*Please note:* Also removes the `msgHandler`-property on these classes, since I cannot find a single call-site that accesses it.
2023-02-11 13:39:52 +01:00
Jonas Jenwald
34ec3caaa7 Update l10n files 2023-02-11 10:35:21 +01:00
Jonas Jenwald
650fd79f92 Update npm packages 2023-02-11 10:30:43 +01:00
Jonas Jenwald
0e070c805e Slightly re-factor preferences/options initialization in the viewer
Given that the debugging hash-parameters will only be used when the `pdfBugEnabled` option is manually set[1], we can skip a *tiny* bit of asynchronicity for "regular" users.

---
[1] Note that it's enabled by default in the development viewer, i.e. in `gulp server` mode.
2023-02-10 15:45:39 +01:00
Jonas Jenwald
6c158da5a8 Limit AppOptions._hasUserOptions to only GENERIC builds
It's completely unused elsewhere, e.g. in the Firefox PDF Viewer.
2023-02-10 15:37:51 +01:00
Jonas Jenwald
903adc8708
Merge pull request #16042 from Snuffleupagus/GetAnnotations-rethrow
Ensure that "GetAnnotations" errors are propagated to the main-thread (PR 15267 follow-up)
2023-02-10 12:55:19 +01:00
Jonas Jenwald
14b0e8c0b6 Ensure that "GetAnnotations" errors are propagated to the main-thread (PR 15267 follow-up)
With the changes in PR 15267 we're now accidentally swallowing "GetAnnotations" errors, rather than propagating them to the main-thread as intended.
2023-02-10 12:18:35 +01:00
Jonas Jenwald
c56f25409d Re-factor the arraysToBytes helper function (PR 16032 follow-up)
Currently this helper function only has two call-sites, and both of them only pass in `ArrayBuffer` data. Given how it's implemented there's a couple of code-paths that are completely unused (e.g. the "string" one), and in particular the intended fast-paths don't actually work.
This patch re-factors and simplifies the helper function, and it'll no longer accept anything except `ArrayBuffer` data (hence why it's also re-named).

Note that at the time when `arraysToBytes` was added we still supported browsers without TypedArray functionality, and we'd then simulate them using regular Arrays.
2023-02-10 10:26:35 +01:00
Jonas Jenwald
5ba596786c Change WorkerTasks, in WorkerMessageHandler.createDocumentHandler, to a use a Set
This is a tiny bit more compact, thanks to the `Set.prototype.delete` method.
2023-02-09 22:01:16 +01:00
calixteman
0fca6e187c
Merge pull request #16035 from calixteman/fix_combo_value
[Annotation] A combo can have a value other than one in the options
2023-02-09 19:56:16 +01:00
Jonas Jenwald
1fc8350795
Merge pull request #16032 from Snuffleupagus/less-arrayByteLength
Reduce usage of the `arrayByteLength` helper function
2023-02-09 18:56:20 +01:00
Calixte Denizet
cb1638530d [Annotation] A combo can have a value other than one in the options
When printing the pdf in #12233 in Acrobat, we can see that the combo for country
is empty: it's because the V entry doesn't have to be one of the options.
2023-02-09 18:50:57 +01:00
calixteman
972744a68f
Merge pull request #16033 from calixteman/bug1640217
Ignore position of combining diacritics when getting text (bug 1640217)
2023-02-09 18:23:59 +01:00
calixteman
533a461db0
Merge pull request #16031 from calixteman/bug1770750
[Annotation] For choice widget, use the I entry instead of the V one (bug 1770750)
2023-02-09 18:01:28 +01:00
Calixte Denizet
58e4d92884 [Annotation] For choice widget, use the I entry instead of the V one (bug 1770750)
It isn't really conform to the specifications but Acrobat is working like that...
2023-02-09 17:26:13 +01:00
Calixte Denizet
4e9f26afa3 Ignore position of combining diacritics when getting text (bug 1640217) 2023-02-09 17:13:57 +01:00
Jonas Jenwald
96d338e437 Reduce usage of the arrayByteLength helper function
We're using this helper function when reading data from the [`PDFWorkerStreamReader.read`](a49d1d1615/src/core/worker_stream.js (L90-L98)) and [`PDFWorkerStreamRangeReader.read`](a49d1d1615/src/core/worker_stream.js (L122-L128)) methods, and as can be seen they always return `ArrayBuffer` data. Hence we can simply get the `byteLength` directly, and don't need to use the helper function.

Note that at the time when `arrayByteLength` was added we still supported browsers without TypedArray functionality, and we'd then simulate them using regular Arrays.
2023-02-09 15:50:38 +01:00
Jonas Jenwald
323d3d246a Re-factor the readChunk function in ChunkedStreamManager.sendRequest
Move the `done` branch to the top of the function, similar to how we usually format things when `ReadableStream`s are used.
2023-02-09 15:33:06 +01:00
Jonas Jenwald
a49d1d1615
Merge pull request #16030 from Snuffleupagus/LoopbackPort-Set
Change the `LoopbackPort` class to use a Set internally
2023-02-09 12:58:14 +01:00
Jonas Jenwald
9d29abdfa0 Change the LoopbackPort class to use a Set internally
This is a tiny bit more compact, thanks to the `Set.prototype.delete` method.
2023-02-09 12:34:41 +01:00
calixteman
ff3b9ccf6e
Merge pull request #16017 from calixteman/hide_struct_tree
Hide the struct tree layer during zooming
2023-02-09 11:32:28 +01:00
calixteman
8df06f62bc
Merge pull request #16025 from calixteman/no_display_for_spinner
Avoid a useless animation when the spinner is invisible
2023-02-09 11:31:27 +01:00
Jonas Jenwald
40a3de8c37 Move rewriteUrlClosure into the web/chromecom.js file
Given that this is only used for the Chrome-addon, we can move this code into the relevant file instead.
2023-02-09 11:18:08 +01:00
calixteman
9cea76483a
Merge pull request #16026 from calixteman/ptz_mac
Fix pinch-to-zoom on mac for the Firefox builtin viewer
2023-02-08 15:16:59 +01:00
Calixte Denizet
c92ba393c2 Fix pinch-to-zoom on mac for the Firefox builtin viewer
In the mac case we don't want to care about the scaleFactor threshold
because else if too big another move could start and then subsequent
events aren't considered as wheel events.
It isn't really ideal and at some point we'll need to find a way at
least for the Firefox case to get the real events instead of the fake
wheel ones.
2023-02-08 15:04:41 +01:00
Jonas Jenwald
9faf2fa8a0
Merge pull request #16019 from Snuffleupagus/viewer-rm-require
Remove most build-time `require` statements from the viewer (PR 16009 follow-up)
2023-02-08 15:02:40 +01:00
Calixte Denizet
bb89daa2a8 Avoid a useless animation when the spinner is invisible
In looking at a profile, I noticed in Marker chart that there's an animation
for loading-icon.gif even if this icon isn't visible.
This patch doesn't completely remove it but just slightly postpones it.
2023-02-08 11:57:53 +01:00
calixteman
c8d9ad894b
Merge pull request #16023 from calixteman/issue16021
[Annotation] Take into account the stroke alpha for a FreeText without appearance
2023-02-07 23:17:16 +01:00
Jonas Jenwald
90ffbc1d39 Remove most build-time require statements from the viewer (PR 16009 follow-up)
This further extends the web-specific import maps introduced in PR 16009, to allow removing *most* of the build-time `require` statements from the viewer. The few remaining ones are fallbacks used for the COMPONENTS respectively the `legacy` GENERIC builds.
2023-02-07 22:45:19 +01:00
Calixte Denizet
a25895bf72 [Annotation] Take into account the stroke alpha for a FreeText without appearance 2023-02-07 22:15:27 +01:00
Jonas Jenwald
8f37301d1f Remove the "div-css" gulp task (PR 15968 follow-up)
After the compatibility updates in PR 15968 it's no longer strictly necessary to build the `viewer.css` file in order for the *development viewer* to work in Chromium-based browsers.

*Please note:* Given that Chromium-based browsers still don't support the *unprefixed* `mask-image` property the icons won't look right, however the development viewer itself works.
Given that Firefox is the *primary* development target, and that running `gulp generic` locally will generate polyfilled CSS, it seems reasonable to make this simplification here.
2023-02-07 21:37:41 +01:00
Jonas Jenwald
72abcedf48
Merge pull request #16018 from Snuffleupagus/GeckoView-skip-pageLabels
[GeckoView] Skip fetching/parsing of pageLabels
2023-02-07 21:36:30 +01:00
calixteman
ecd86ccffc
Merge pull request #16020 from calixteman/bug1815476
[Annotation] Avoid to encrypt the appearance stream two times (bug 1815476)
2023-02-07 20:57:49 +01:00
Calixte Denizet
ea7b4b4d6c [Annotation] Avoid to encrypt the appearance stream two times (bug 1815476) 2023-02-07 19:26:46 +01:00
Jonas Jenwald
00560ed830
Merge pull request #16009 from Snuffleupagus/GeckoView-viewer-bundle-size
[GeckoView] Reduce the size of the *built* viewer
2023-02-07 18:28:44 +01:00
Jonas Jenwald
a348162c5b [GeckoView] Skip fetching/parsing of pageLabels
Currently there's no toolbar in the GV-viewer, hence invoking the pageLabels functionality isn't meaningful and just leads to unnecessary parsing on both the main- and worker-threads. (And if a toolbar is added at some point, it's not clear to me if we'd want to support pageLabels in the GV-viewer anyway.)
2023-02-07 16:20:27 +01:00
Jonas Jenwald
8c4843f69a [GeckoView] Introduce a development mode constant to tell the viewers apart
Currently we have a couple of pre-processor checks, specifically for the GV-viewer, spread throughout the code. This works fine when *building* the viewer, however they're obviously ignored in development mode (i.e. `gulp server`).
This leads to a situation where the GV development viewer, i.e. http://localhost:8888/web/viewer-geckoview.html, behaves subtly different from its built version. This could easily lead to bugs, hence this patch introduces a development mode constant to hopefully improve things here.

Finally, in a follow-up to PR 15842, also ignores the `pageMode`-state since there's no sidebar available.
2023-02-07 16:07:12 +01:00
Calixte Denizet
5bd352f69b Hide the struct tree layer during zooming 2023-02-07 15:33:01 +01:00
Jonas Jenwald
c971f4a0a9
Merge pull request #16016 from Snuffleupagus/GeckoView-skip-sidebar-fetching
[GeckoView] Avoid unused outline, attachments, and layers fetching
2023-02-07 13:25:02 +01:00
Jonas Jenwald
0cf4fbd471 [GeckoView] Avoid unused outline, attachments, and layers fetching
Currently there's no UI for this functionality in the GV-viewer, however we still call the API methods. This potentially leads to a bunch of worker-thread parsing, for PDF documents with these features, despite the result being completely unused.
Given that mobile devices are usually more resource constrained than desktop/laptop computers, not to mentioned battery life, we can avoid doing work that'll just be ignored anyway.
2023-02-07 12:30:05 +01:00
Jonas Jenwald
c00e237421 Remove inline opening of PDF attachments in the COMPONENTS build
The `DownloadManager.openOrDownloadData` method is written for the default-viewer specifically, assuming a viewer able to handle e.g. URL search/hash parameters. In the viewer components there's obviously no such functionality, and we should thus trigger downloading of PDF attachments directly instead.
2023-02-06 12:02:22 +01:00
Jonas Jenwald
a98e80c4ff [GeckoView] Reduce the size of the *built* viewer
Given that the GV-viewer isn't using most of the UI-related components of the default-viewer, we can avoid including them in the *built* viewer to save space.[1]
The least "invasive" way of implementing this, at least that I could come up with, is to leverage import maps with suitable stubs for the GV-viewer.

The one slightly annoying thing is that we now have larger import maps across multiple html-files, and you'll need to remember to update all of them when making future changes.

---
[1] With this patch, the built `viewer.js` size is 391 kB and `viewer-geckoview.js` is 285 kB.
2023-02-05 14:12:32 +01:00
Tim van der Meij
05d821e680
Merge pull request #16007 from Snuffleupagus/getDocument-params-init
Re-factor the parameter parsing/validation in `getDocument`
2023-02-05 13:16:59 +01:00
Tim van der Meij
ab6b4ca1f2
Merge pull request #16006 from Snuffleupagus/viewer-rm-pdfDocument-checks
Miscellaneous small viewer improvements
2023-02-05 12:53:17 +01:00
Jonas Jenwald
0a0f3fc733 Move the main-thread CMap/StandardFontData factory initialization to getDocument
By default we're using worker-thread fetching (in browsers) of this data nowadays, however in Node.js environments or if the user provides custom factories we still fallback to main-thread fetching.
Hence it makes sense, as far as I'm concerned, to move this initialization into the `getDocument` function to ensure that the factories can actually be initialized *before* attempting to load the document.

Also, this further reduces the amount of `getDocument` parameters that we need to pass into into the `WorkerTransport` class.
2023-02-05 11:52:35 +01:00
Jonas Jenwald
ce8ac6d96a Only pass the necessary parameters to _fetchDocument and WorkerTransport
Currently we're passing all available parameters to this function respectively class, despite that not actually being necessary.
By splitting the parameters we not only improve the structure, and basically "document" the code a little bit, but we can also simplify the `_fetchDocument` function considerably.
2023-02-05 11:52:33 +01:00
Jonas Jenwald
512aa50fdd Re-factor the parameter parsing/validation in getDocument
This is very old code, where we loop through the user-provided options and build an internal parameter object. To prevent errors we also need to ensure that the parameters are correct/valid, which is especially important for the ones that are sent to the worker-thread such that structured cloning won't fail.[1]

Over the years this has led to more and more code being added in `getDocument` to validate the user-provided options, and at this point *most* of them have at least basic validation. However the way that this is implemented feels slightly backwards, since we first build the internal parameter object and only *afterwards* validate those parameters.[2]

Hence this patch changes the `getDocument` function to instead check/validate the supported options upfront, and then *explicitly* build the internal parameter object with only the needed properties.

---
[1] Note the supported types at https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types

[2] The internal parameter object may also, because of the loop, end up with lots of unnecessary properties since anything that the user provides is being copied.
2023-02-05 11:52:25 +01:00
Jonas Jenwald
d9181236b2 [GENERIC viewer] Simplify the keyboard find-again state building
By using modern JavaScript features, we can ever so slightly reduce the amount of code needed here.
2023-02-04 23:16:04 +01:00
Jonas Jenwald
d6178a13d7 Reduce a tiny bit of duplication in the webViewerInitialized function 2023-02-04 23:16:04 +01:00
Jonas Jenwald
d930f267f6 Remove a couple of unnecessary PresentationMode-checks in webViewerKeyDown
Given that the `PDFViewerApplication.{zoomIn, zoomOut}` methods already contain PresentationMode-checks, this is just unnecessary duplication.
2023-02-04 23:15:56 +01:00
Jonas Jenwald
ea1ec7ffab Remove a couple of unnecessary pdfDocument checks in web/app.js
These functions invoke the `PDFViewer.currentPageNumber` setter, which already checks that a `pdfDocument` is currently active. Also, given that they're event handlers for the First/Last-page buttons (in the SecondaryToolbar) they can't be invoked before the viewer has been fully initalized.
2023-02-04 22:17:53 +01:00
Tim van der Meij
e698664927
Merge pull request #16004 from Snuffleupagus/WorkerTransport-cacheSimpleMethod
Improve how we cache Promises in `WorkerTransport`
2023-02-04 15:13:12 +01:00
Tim van der Meij
b75dafba87
Merge pull request #15987 from Snuffleupagus/onOpenWithTransport-params
Remove unused parameters from the `onOpenWithTransport` method in `PDFViewerApplication.initPassiveLoading`
2023-02-04 15:07:42 +01:00
Tim van der Meij
bdb6d978a9
Merge pull request #15968 from Snuffleupagus/rm-postCSS-logical
[api-minor] Update the minimum supported browsers, and remove the PostCSS `logical` plugin
2023-02-04 15:04:29 +01:00
Tim van der Meij
e848a0e61c
Merge pull request #15981 from Snuffleupagus/cMapPacked-true
[api-minor] Let the `cMapPacked` parameter, in `getDocument`, default to `true`
2023-02-04 15:00:26 +01:00
Jonas Jenwald
df71f82037
Merge pull request #16003 from Snuffleupagus/scaleSelect-width-CSS-var
Move the `--scale-select-width` CSS variable to the relevant DOM element
2023-02-04 14:23:43 +01:00
Jonas Jenwald
eb341cadd7
Merge pull request #16005 from Snuffleupagus/rm-isEmptyObj
Remove the `isEmptyObj` unit-test helper function
2023-02-04 14:19:51 +01:00
Jonas Jenwald
849b492b33 Move the --scale-select-width CSS variable to the relevant DOM element
The default value of the `--scale-select-width` CSS variable has been choosen such that it should be large enough for most locales. This means that in many locales we don't even update the CSS variable at all, and for those locales where we do the update happens *one time* early during the viewer initialization (i.e. before the PDF document has loaded).

*Please note:* Compared to other recent PRs, the effect of these changes ought to be really tiny and are mostly done to promote better coding patterns.
2023-02-04 14:18:48 +01:00
Jonas Jenwald
3a7fce49a3 A tiny improvement of the MetadataParser._repair method
We can just insert the initial greater-than sign at the start of the buffer, rather than doing that manually at the end.
2023-02-04 12:43:55 +01:00
Jonas Jenwald
851c394e64 Remove the isEmptyObj unit-test helper function
We should be able to let Jasmine simply compare directly against an actually empty Object, rather than using a manually implemented helper function for that.
2023-02-04 12:43:53 +01:00
Jonas Jenwald
2de03a7d91 Improve how we cache Promises in WorkerTransport
A number of methods have their Promises cached, to avoid repeated worker round-trips, since they're expected to be called more than once from the default viewer. The way that the caching is currently implemented means that we need to remember to manually clear these Promises on document cleanup/destruction, and it'd be nice to avoid that.

With this patch the relevant Promises are now instead placed in just one `Map`, which is easy to clear, and a new helper method is also introduced to reduce duplication for *simple* `WorkerTransport` methods.
2023-02-04 11:57:37 +01:00
Jonas Jenwald
25253034d5
Merge pull request #16001 from Snuffleupagus/rm-GeckoView-cursor-tools
[GeckoView] Don't initalize the cursor-tools, since they're unused
2023-02-03 18:50:42 +01:00
Jonas Jenwald
94a235db93 [GeckoView] Don't initalize the cursor-tools, since they're unused
The reasons for making this change are:
 - There's no UI available to toggle the cursor-tools in the GeckoView-specific viewer.
 - The `HandTool`-implementation basically *simulates* touch scrolling, and is thus unlikely to be helpful/useful anyway.
 - PR 15831 already changed the relevant call-sites to handle `PDFViewerApplication.pdfCursorTools` being undefined.
2023-02-03 18:20:36 +01:00
Jonas Jenwald
cbe4912a16
Merge pull request #15991 from Snuffleupagus/PDFViewerApplication-open-loops
Remove a couple of manual loops in the `PDFViewerApplication.open` method
2023-02-03 15:43:30 +01:00
Jonas Jenwald
72bf36ea70
Merge pull request #15998 from Snuffleupagus/limit-removePageBorders
Limit the `removePageBorders` option, in `PDFViewer`, to only GENERIC builds
2023-02-03 15:04:33 +01:00
Jonas Jenwald
2c2443ffac
Merge pull request #15999 from Snuffleupagus/rm-GeckoView-CSS
[GeckoView] Remove unused `@media` CSS rules
2023-02-03 15:02:56 +01:00
Jonas Jenwald
d906a383ca Remove a couple of manual loops in the PDFViewerApplication.open method
Some of the code in this method is *very* old, and we could thus modernize it a little bit by removing a couple of the loops used to build the `getDocument` argument.
2023-02-03 14:55:07 +01:00
Jonas Jenwald
aba39d271b [GeckoView] Remove unused @media CSS rules
These `@media` rules were most likely just copy-pasted from the regular viewer, however none of them are currently necessary since the GeckoView-specific viewer doesn't have any toolbars.
Note that the whole purpose of these CSS rules are to make the toolbar, of the regular viewer, responsive. If we in the future add toolbars for the GeckoView-specific viewer, these rules most likely wouldn't be usable as-is anyway.
2023-02-03 14:23:58 +01:00
Jonas Jenwald
ddf5563174 Limit the removePageBorders option, in PDFViewer, to only GENERIC builds
This option was added specifically for third-party users, but has never been used in the PDF.js project itself. Furthermore there's no preference that can be used to enable it, and you need to provide the `removePageBorders` option when initializing a `PDFViewer`-instance.

This patch thus get rid of a little bit more unused code in the Firefox PDF Viewer.
2023-02-03 10:15:26 +01:00
Jonas Jenwald
39bdd09447
Merge pull request #15997 from Snuffleupagus/loadingIcon-INITIAL-remove
Remove the `loadingIcon` in all cases when resetting the page (PR 15992 follow-up)
2023-02-02 22:20:53 +01:00
Jonas Jenwald
f94b348782 Remove the loadingIcon in all cases when resetting the page (PR 15992 follow-up)
*Unfortunately I missed this during testing/reviewing of PR 15992.*

With the changes in PR 15992 we're now only adding the `loadingIcon`-class when rendering is actually `RUNNING`, in order to improve overall performance.
However when resetting the page, i.e. the `INITIAL` state, we also need to remove the `loadingIcon` completely. Without this patch if you scroll through a document where the pages don't load instantaneously, see e.g. issue 2504, we'll leave the `loadingIcon`-class attached to pages that have had their rendering cancelled *and* also been evicted from the `PDFPageViewBuffer`-instance.
2023-02-02 21:29:11 +01:00
Jonas Jenwald
9261daa233
Merge pull request #15996 from Snuffleupagus/skip-CSS-singlePageView
Limit the `singlePageView` CSS rules to only the COMPONENTS build
2023-02-02 18:13:49 +01:00
Jonas Jenwald
fc8494b2c2 Limit the singlePageView CSS rules to only the COMPONENTS build
These CSS rules exist solely for the `pageviewer` viewer-component example, see https://github.com/mozilla/pdf.js/tree/master/examples/components, and consequently it doesn't make sense in other builds.
2023-02-02 18:00:12 +01:00
calixteman
1ba1b8c711
Merge pull request #15992 from calixteman/remove_loading_icon
Remove the loading icon div and replace it by a pure css solution using :after.
2023-02-02 16:40:44 +01:00
Calixte Denizet
aac073feeb Remove the loading icon div and replace it by a pure css solution using :after.
This way we don't have a lot of useless divs and we let the css engine handle the
creation/destruction of the :after pseudo-element.
It'll help to slightly improve performance when zooming.
2023-02-02 15:33:53 +01:00
calixteman
1bdee0b59b
Merge pull request #15970 from calixteman/editor_invisible
[Editor] Make the annotation editor layer invisible when disabled and empty
2023-02-01 21:25:32 +01:00
Calixte Denizet
185281957d [Editor] Make the annotation editor layer invisible when disabled and empty
It'll help to avoid to consider them when the browser is restyling.
2023-02-01 17:53:44 +01:00
Jonas Jenwald
cf8ee47589 Remove unused parameters from the onOpenWithTransport method in PDFViewerApplication.initPassiveLoading
The only parameter that we actually need here is the `PDFDataRangeTransport`-instance, since the others are not necessary.
 - The `url` parameter, as passed to the `getDocument` function in the API, is simply being ignored; see 2d87a2eb1c/src/display/api.js (L447-L458)
 - The `length` parameter, as passed to the `getDocument` function in the API, is always being overwritten; see 2d87a2eb1c/src/display/api.js (L519-L525)
2023-02-01 09:33:22 +01:00
Jonas Jenwald
2d87a2eb1c
Merge pull request #15984 from Snuffleupagus/optional-workerModules
Allow, optionally, using worker-modules during local development
2023-01-31 13:05:59 +01:00
Jonas Jenwald
5e88228767 Allow, optionally, using worker-modules during local development
Until PR 12563 is deemed safe to land, I'd still like to be able to use worker-modules in the viewer during local development.
Hence this patch which *temporarily* adds a new `workerModules` hash-parameter, only available in non-PRODUCTION mode, that allows using worker-modules in the development viewer.

To enable this functionality, simply use http://localhost:8888/web/viewer.html#workerModules=true
2023-01-31 12:09:44 +01:00
Jonas Jenwald
c5d6391898 [api-minor] Let the cMapPacked parameter, in getDocument, default to true
The initial CMap support was added in PR 4259 using the "raw" Adobe files, however they were quickly deemed to be unnecessarily large. As a result PR 4470 introduced the more compact "binary" CMap format, with both of those PRs being included in the very same release (version `0.8.1334`) .

Please note that we've thus never shipped anything *except* the "binary" CMap files with the PDF library, and furthermore note that we've not even once updated the CMap files since they were originally added almost nine years ago.

Requiring users to remember that `cMapPacked = true` is necessary, in addition to setting the `cMapUrl` parameter, in order for CMap loading to work feels like a less than ideal API.
Hence this patch, which suggests that we simply let `cMapPacked` default to `true` now.
2023-01-30 15:35:02 +01:00
Jonas Jenwald
3d35b48f46
Merge pull request #15979 from Snuffleupagus/issue-15977
Extend `getGlyphMapForStandardFonts` with additional entries (issue 15977)
2023-01-30 14:46:43 +01:00
Jonas Jenwald
808ca828f1 Extend getGlyphMapForStandardFonts with additional entries (issue 15977) 2023-01-30 12:13:21 +01:00
calixteman
2ebbeb7499
Merge pull request #15973 from calixteman/1813138
Remove the transition when displaying the sidebar when the user prefers reduced motion (bug 1813138)
2023-01-30 11:26:16 +01:00
Calixte Denizet
f14413989c Remove the transition when displaying the sidebar when the user prefers reduced motion (bug 1813138)
In Firefox, it can be easily testesd in setting the pref `ui.prefersReducedMotion` to 1.
2023-01-30 10:56:37 +01:00
Jonas Jenwald
ca996d2546 [api-minor] Update the minimum supported browsers, and remove the PostCSS logical plugin
The patch updates the minimum supported browsers/environments as follows:
 - Chrome 87, which was released on 2020-11-17; see https://en.wikipedia.org/wiki/Google_Chrome_version_history
 - Firefox ESR (no change); see https://wiki.mozilla.org/Release_Management/Calendar
 - Safari 14.1, which was released on 2021-04-26; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_14
 - Node.js 14 (no change); see https://en.wikipedia.org/wiki/Node.js#Releases

The recent *major* release of the PostCSS `logical` plugin effectively removed support for all of the things that we used it for, which includes (but may not be limited to): preserving the original CSS code (for up-to-date browsers), re-writing the `:dir` pseudo-class, and support for re-writing `float: inline-start;`/`float: inline-end;` properties.
Please find additional details at https://github.com/csstools/postcss-plugins/blob/main/plugins/postcss-logical/CHANGELOG.md#600-january-24-2023
Hence the primary reason for these changes are related to native support for *logical* CSS properties/values. Currently, in the default viewer, we're using the following ones:
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/text-align#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/float#browser_compatibility

By updating the minimum supported browsers, we thus only have to worry about the *last* case here. Thankfully there's not that many `float: inline-start;`/`float: inline-end;` occurrences, and we can utilize CSS variables together with the pre-processor to support those in a way that won't affect the Firefox PDF Viewer.
2023-01-29 20:25:05 +01:00
Tim van der Meij
f492d96301
Merge pull request #15974 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-01-29 13:53:41 +01:00
Tim van der Meij
e3aaaa378d
Bump versions in pdfjs.config 2023-01-29 13:47:28 +01:00
Tim van der Meij
5620456072
Merge pull request #15972 from Snuffleupagus/PDFViewerApplication-open-signature
Change the `PDFViewerApplication.open` method to only accept objects
2023-01-28 19:10:01 +01:00
Tim van der Meij
ee3be2f979
Merge pull request #15951 from Snuffleupagus/polyfill-Path2D
Polyfill `Path2D` in Node.js environments
2023-01-28 19:06:54 +01:00
Jonas Jenwald
6129be7b68 Change the PDFViewerApplication.open method to only accept objects
If this method was added today, I really can't imagine that we'd support anything *except* objects. Unfortunately we cannot just remove this now, since the code has existed since "forever", however we can deprecate this and limit it to only the GENERIC build.

Furthermore, we can avoid a redundant `PDFViewerApplication.setTitleUsingUrl` call in the Firefox PDF Viewer since the title has already been set previously in that case.
2023-01-28 18:55:22 +01:00
Tim van der Meij
e539d2da1e
Merge pull request #15964 from Snuffleupagus/getDocument-non-object
Only accept non-objects passed to `getDocument` in GENERIC builds
2023-01-28 18:42:09 +01:00
Jonas Jenwald
cf0369d622 Polyfill Path2D in Node.js environments
Until just recently the only existing `Path2D` polyfill didn't have support for Node.js and/or the `node-canvas` package. Given that this was just fixed, in the latest version, we can now finally remove our inline-checks at the relevant call-sites; please also see https://github.com/nilzona/path2d-polyfill#usage-with-node-canvas
2023-01-28 18:28:22 +01:00
Tim van der Meij
cb5a28ceca
Merge pull request #15954 from Snuffleupagus/getDocument-URL-tweaks
Tweak the internal handling of the `url`-parameter in `getDocument` (PR 13166 follow-up)
2023-01-28 18:18:17 +01:00
Tim van der Meij
16aef95937
Merge pull request #15966 from Snuffleupagus/GlobalWorkerOptions-defaults
Simplify setting the `GlobalWorkerOptions` default values (PR 9480 follow-up)
2023-01-28 18:15:32 +01:00
Tim van der Meij
42caf64ae8
Merge pull request #15963 from Snuffleupagus/README-support-info
Update various README files to be less specific about the supported JavaScript features
2023-01-28 18:10:16 +01:00
Tim van der Meij
7c6324f3d4
Merge pull request #15971 from Snuffleupagus/update-packages
Update packages and translations
2023-01-28 18:08:46 +01:00
Jonas Jenwald
52d61aceda Update l10n files 2023-01-28 08:15:21 +01:00
Jonas Jenwald
07ba352903 Update npm packages 2023-01-28 08:13:13 +01:00
calixteman
075cc8d8df
Merge pull request #15965 from calixteman/bug1811510
[JS] Correctly format field with numbers (bug 1811694, bug 1811510)
2023-01-26 16:10:29 +01:00
Calixte Denizet
6f4d037a8e [JS] Correctly format field with numbers (bug 1811694, bug 1811510)
In PR #15757, a value is automatically converted into a number when it's possible
but the case of numbers like "000123" has been overlooked and their format must
be preserved.
When a script is doing something like "foo.value + bar.value" and the values are
numbers then "foo.value" must return a number but the displayed value must be what
the user entered or what a script set, so this patch is just adding a a field
_orginalValue in order to track the value has it has defined.
Some people are used to use a comma as decimal separator, hence it must be considered
when a value is parsed into a number.
This patch is fixing a regression introduced by #15757.
2023-01-26 14:57:02 +01:00
Jonas Jenwald
1c4af2727c Simplify setting the GlobalWorkerOptions default values (PR 9480 follow-up)
There's really no need for these "complicated" default value assignments, since `GlobalWorkerOptions` is a local variable at this point, and this is rather a case of too much copy-and-paste.
Note that years ago, when all options were set using a global `PDFJS` object, it's possible that options had been set (from the outside) *before* the object had been properly initialized; see e.g. a89071bdef/src/display/global.js
2023-01-26 14:16:01 +01:00
Jonas Jenwald
4758e6649c Only accept non-objects passed to getDocument in GENERIC builds
In general it's always recommended to pass a *parameter object* when calling the `getDocument`-function in the API, since that's the only way to provide additional options, and the fact that it also accepts a URL or TypedArray directly is now mostly for backwards compatibility reasons.
Unfortunately we cannot really remove this, since that code has existed since "forever", however we can limit it to only the GENERIC build to avoid completely unnecessary checks in e.g. the Firefox PDF Viewer.

Finally, note that the default-viewer always provides a *parameter object* when calling the `getDocument`-function and it's thus completely unaffected by these changes.
2023-01-26 10:48:58 +01:00
Jonas Jenwald
c0a023eaf9 Update various README files to be less specific about the supported JavaScript features
By being less specific about which *exact* JavaScript features are required for the default vs `legacy` build, we don't need to worry about keeping multiple README files up-to-date.
These README files will now refer back to the FAQ for current browser/environment support information.
2023-01-25 15:46:53 +01:00
Jonas Jenwald
1b1ebf6a77
Merge pull request #15960 from Snuffleupagus/issue-15958
Move `ProgressBar`-related CSS variables into the `loadingBar` DOM-element (issue 15958)
2023-01-25 12:17:24 +01:00
Jonas Jenwald
ce941255e2
Merge pull request #15959 from Snuffleupagus/normalizeWheelEventDelta-tweaks
Tweak the `normalizeWheelEventDelta` helper function
2023-01-25 11:13:50 +01:00
Jonas Jenwald
9d5085347a Move ProgressBar-related CSS variables into the loadingBar DOM-element (issue 15958)
This way we avoid reflowing the entire viewer when e.g. updating the loading progress.
2023-01-25 11:09:28 +01:00
Jonas Jenwald
85fd765462 Tweak the normalizeWheelEventDelta helper function
This function is only used in PresentationMode these days, but we can still improve it a little bit:
 - Use the existing web-platform `deltaMode` constants, rather than defining our own constants for those values.
 - Access the `deltaMode` first, before the `delta{X, Y}` properties, to avoid being affected by bug 1392460 (similar to the default viewer).
2023-01-25 10:47:03 +01:00
calixteman
0b9d32bdad
Merge pull request #15957 from calixteman/1810800
Try to avoid to interpret wheel events as pinch-to-zoom ones (bug 1810800)
2023-01-24 21:35:12 +01:00
Calixte Denizet
1cb482be6a Try to avoid to interpret wheel events as pinch-to-zoom ones (bug 1810800) 2023-01-24 20:12:12 +01:00
Jonas Jenwald
755319130e Tweak the internal handling of the url-parameter in getDocument (PR 13166 follow-up)
- Use a `URL`-instance directly, since it's by definition an absolute URL.
 - Actually limit the "raw" url-string handling to Node.js environments, as intended.
 - Skip the warning, since we're already throwing an Error if the `url`-parameter is invalid.
2023-01-24 11:18:41 +01:00
calixteman
673f6820d1
Merge pull request #15952 from calixteman/l10n
Set up automated l10n review for new English strings
2023-01-22 20:44:37 +01:00
Calixte Denizet
be93a2a7d4 Set up automated l10n review for new English strings 2023-01-22 19:39:31 +01:00
Tim van der Meij
edfdb693e5
Merge pull request #15948 from Snuffleupagus/bug-1811668
Tweak `adjustType1ToUnicode` for fonts with a predefined *named* encoding (bug 1811668, PR 14050 follow-up)
2023-01-21 14:02:40 +01:00
Tim van der Meij
8278abb3f3
Merge pull request #15949 from Snuffleupagus/ProgressBar-setDisableAutoFetch
Move the `disableAutoFetch` functionality into the `ProgressBar`-class
2023-01-21 13:54:18 +01:00
Tim van der Meij
a27d7ba524
Merge pull request #15943 from Snuffleupagus/deprecate-direct-PDFDataRangeTransport
[api-minor] Deprecate calling `getDocument` directly with a `PDFDataRangeTransport`-instance
2023-01-21 13:50:20 +01:00
Jonas Jenwald
d7013bee54 Move the disableAutoFetch functionality into the ProgressBar-class
It seems nicer overall, since we're exporting the `ProgressBar` in the viewer-components, to move this functionality into the `ProgressBar`-class itself rather than handling it "manually" in the default-viewer.
2023-01-21 12:32:34 +01:00
Jonas Jenwald
40a46e4397 Tweak adjustType1ToUnicode for fonts with a predefined *named* encoding (bug 1811668, PR 14050 follow-up)
*Please note:* I cannot reproduce the problem reported in bug 1811668, regarding the context menu, and in any case it's not clear that that part is even a PDF Viewer bug.

Looking at bug 1811668 I couldn't help but noticing that the textLayer isn't correct, and it's unfortunately once again a problem with the `adjustType1ToUnicode` function. That's intended to help improve text-selection for fonts without a /ToUnicode-entry, and in many cases it does help (the original PR fixed lots of issues) however it's also caused some problems.

In order to improve text-selection in bug 1811668, we'll now properly ignore fonts that have a predefined *named* encoding specified since that's really the intention with PR 14050.
2023-01-21 12:21:21 +01:00
calixteman
7b95788248
Merge pull request #15947 from calixteman/gv_dont_update_find
[GV] Avoid to update the finder when the results aren't complete
2023-01-20 18:48:39 +01:00
Calixte Denizet
dc94b750de [GV] Avoid to update the finder when the results aren't complete
At the beginning of a search we can an update can be triggered with 0 over 0
found matches.
In the GeckoView context, we can't update the finder whenever we want but only
when it has been required.
2023-01-20 18:13:16 +01:00
calixteman
deb07aee06
Merge pull request #15941 from calixteman/change_current_view
Change 'Current View' to 'Current Page' in the secondary toolbar
2023-01-20 10:59:18 +01:00
Jonas Jenwald
29cd5ab24e
Merge pull request #15945 from Snuffleupagus/issue-15942
[JBIG2] Ensure that the `decodeInteger` function returns valid integers (issue 15942)
2023-01-19 21:14:47 +01:00
Jonas Jenwald
f2fce93826 [JBIG2] Ensure that the decodeInteger function returns valid integers (issue 15942)
The JBIG2 images in this PDF document are corrupt enough that even Adobe Reader warns about it when opening the file.
*Please note:* I don't really know the JBIG2 image format at all, however from a very brief look at the specification it seems that integers should be 32-bit.
2023-01-19 17:14:17 +01:00
Jonas Jenwald
7976fc7851 [api-minor] Deprecate calling getDocument directly with a PDFDataRangeTransport-instance
In general it's recommended to pass a *parameter object* when calling the `getDocument`-function in the API, since that's the only way to provide additional options, and the fact that it also accepts a URL or TypedArray directly is now mostly for backwards compatibility reasons.
However, the `getDocument`-function also accepts a direct `PDFDataRangeTransport`-instance which just seems unnecessary.

*Please note:* The `PDFDataRangeTransport`-implementation was added specifically for the *built-in* Firefox PDF Viewer, however it's most likely not commonly used by any third-party (given that it requires manual PDF-data loading).
Furthermore, the default-viewer always provides a *parameter object* when calling the `getDocument`-function and it's thus completely unaffected by these changes.
2023-01-19 14:25:55 +01:00
Jonas Jenwald
c629a85a5c
Merge pull request #15935 from Snuffleupagus/_centerAtPos
Add a `PDFViewerApplication` helper method to center the position after wheel/pinch-zooming
2023-01-19 14:25:10 +01:00
Jonas Jenwald
1a95890728
Merge pull request #15937 from Snuffleupagus/textLayer-highlight-color-vars
Use CSS variables for the textLayer `highlight` colors (PR 15921 follow-up)
2023-01-19 13:38:58 +01:00
Jonas Jenwald
eee65e4b6e Add a PDFViewerApplication helper method to center the position after wheel/pinch-zooming
This avoids having to repeat the same code twice, now that we support both wheel- and pinch-zooming.
2023-01-19 13:35:35 +01:00
Calixte Denizet
31ae3a4ba0 Change 'Current View' to 'Current Page' in the secondary toolbar
Content Design team (UX) proposed this change.
2023-01-19 09:54:25 +01:00
Jonas Jenwald
f25e33ee7f
Merge pull request #15940 from Snuffleupagus/license_header_2023
Update the year in the `license_header` files
2023-01-18 22:36:21 +01:00
Jonas Jenwald
7b36686fca Update the year in the license_header files 2023-01-18 22:28:18 +01:00
Jonas Jenwald
4b5817f8ff Use consistent forced-colors media-queries throughout the CSS files
Note how e.g. the `viewer.css` and `pdf_viewer.css` files already used this format.
2023-01-18 10:49:52 +01:00
Jonas Jenwald
67b1d15384 Use CSS variables for the textLayer highlight colors (PR 15921 follow-up)
Rather than adding `@media (forced-colors: active) { ... }`-blocks throughout the CSS code, we should utilize CSS variables instead as in our other CSS files.
2023-01-18 10:42:22 +01:00
Jonas Jenwald
42b1cff7b0
Merge pull request #15934 from Snuffleupagus/issue-15910-2
Fallback to using the `name` table to infer the encoding for TrueType fonts missing such data (issue 15910)
2023-01-17 23:01:23 +01:00
calixteman
e65f1767ab
Merge pull request #15930 from calixteman/15929
Move --scale-factor variable in the viewer container (fix #15929)
2023-01-17 16:37:49 +01:00
Jonas Jenwald
d6be5141e9 Fallback to using the name table to infer the encoding for TrueType fonts missing such data (issue 15910)
The relevant TrueType font is missing both /ToUnicode *and* /Encoding entires, either of which would have prevented the (current) broken textLayer rendering.
My first idea was that we could use the `post` table in the TrueType font, see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6post.html, to get the actual glyphNames and amend the fallback ToUnicode-map that way. Unfortunately that didn't work, since the `post` table only contained ".notdef" and "" (i.e. empty string) entries.

Instead we try to use the `name` table in the TrueType font, see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html, to determine if the platform is Windows and thus fallback to generate a ToUnicode-map from the `WinAnsiEncoding`.
2023-01-17 16:04:51 +01:00
Calixte Denizet
089ed6fb65 Move --scale-factor variable in the viewer container (fix #15929)
When a css variable is update in a node then all the children under this
node are updated.
In order to avoid to update all the UI when a page is rescaling, this
patch moves the --scale-factor from the :root to the viewer container.
2023-01-17 10:50:53 +01:00
Jonas Jenwald
d8d5545e03
Merge pull request #15926 from Snuffleupagus/annotation-appearance-stream
Ensure that Annotation `appearance`-entries are actually Streams
2023-01-16 15:00:12 +01:00
Jonas Jenwald
8f3fa18c93
Merge pull request #15920 from Snuffleupagus/transfer-pdf-data
[api-minor] Enable transferring of TypedArray PDF data by default (PR 15908 follow-up)
2023-01-16 13:20:57 +01:00
Jonas Jenwald
cefaecc2e8 Ensure that Annotation appearance-entries are actually Streams
Note how all over the `src/core/annotation.js`-code we're assuming that if an `appearance`-entry exists it's also a Stream. However, we're not actually checking that thoroughly enough which causes issues in some badly generated PDF documents.
2023-01-16 13:02:53 +01:00
calixteman
e9c8aa63e3
Merge pull request #15921 from fchasen/forced-colors-highlights
Update highlight background when forced colors are active (bug 1759886)
2023-01-16 11:16:22 +01:00
Tim van der Meij
0e563ee6da
Merge pull request #15925 from Snuffleupagus/update-rimraf
Update `rimraf` to version 4
2023-01-15 18:15:59 +01:00
Jonas Jenwald
32357e3d17 Update rimraf to version 4
The primary change is that the `rimraf` function now returns a Promise instead of taking a callback; please see https://github.com/isaacs/rimraf#major-changes-from-v3-to-v4
2023-01-15 15:38:30 +01:00
Jonas Jenwald
1ca0a7a26c
Merge pull request #15923 from Snuffleupagus/zoom-black-canvas
[Regression] Avoid showing a black canvas during zooming with a `drawingDelay` set (PR 15812 follow-up)
2023-01-15 12:29:06 +01:00
Tim van der Meij
bc3b59fa5e
Merge pull request #15924 from Snuffleupagus/update-packages
Update packages and translations
2023-01-15 11:35:16 +01:00
Jonas Jenwald
cbf9843a79 Update l10n files 2023-01-15 10:43:46 +01:00
Jonas Jenwald
d527bd0d92 Update npm packages 2023-01-15 10:34:56 +01:00
Jonas Jenwald
906745de38 [Regression] Avoid showing a black canvas during zooming with a drawingDelay set (PR 15812 follow-up)
After the changes in PR 15812 we'll now *intermittently* display completely black canvases during zooming. To reproduce this, try switching to wrapped-scrolling and zoom in/out very quickly using either the mouse-wheel or pinching.
2023-01-14 23:25:04 +01:00
Tim van der Meij
517d7a6dc3
Merge pull request #15905 from timvandermeij/core-utils-unit-tests
Improve unit test coverage of `src/core/core_utils.js`
2023-01-14 15:24:53 +01:00
Tim van der Meij
9e3adb5ec7
Implement unit tests for the numberToString utility function 2023-01-14 15:09:58 +01:00
Tim van der Meij
a6dfcc89fa
Implement unit tests for the recoverJsURL utility function 2023-01-14 15:09:58 +01:00
Jonas Jenwald
397f943ca3 [api-minor] Enable transferring of TypedArray PDF data by default (PR 15908 follow-up)
This patch removes the recently introduced `transferPdfData` API-option, and simply enables transferring of TypedArray data *by default* instead of copying it. This will help reduce main-thread memory usage, however it will take ownership of the TypedArrays. Currently this only applies to the following cases:
 - TypedArrays passed to the `getDocument`-function in the API, in order to open PDF documents from binary data.
 - TypedArrays passed to a `PDFDataRangeTransport`-instance, used to support custom PDF document fetching/loading (see e.g. the Firefox PDF Viewer).

*PLEASE NOTE:* To avoid being affected by this, please simply *copy* any TypedArray data before passing it to either of the functions/methods mentioned above.

Now that we transfer TypedArray data that we previously only copied, we need to be more careful with input validation. Given how the `{IPDFStreamReader, IPDFStreamRangeReader}.read` methods will always return ArrayBuffer data, which is then transferred to the worker-thread[1], the actual TypedArray data passed to the API thus need to have the same exact size as its underlying ArrayBuffer to prevent issues.
Hence we'll check for this and only allow transferring of *safe* TypedArray data, and fallback to simply copying the data just as before. This obviously shouldn't be an issue in the Firefox PDF Viewer, but for the general PDF.js library we need to be more careful here.

---
[1] See e09ad99973/src/display/api.js (L2492-L2506) respectively e09ad99973/src/display/api.js (L2578-L2590)
2023-01-14 10:39:36 +01:00
Fred Chasen
0a6b1cd2e9 Update highlight background color for forced colors 2023-01-13 14:35:12 -08:00
Jonas Jenwald
99cfab18c1 Combine the array-like and ArrayBuffer branches, when handling binary data, in getDocument 2023-01-13 13:28:44 +01:00
Jonas Jenwald
e09ad99973
Merge pull request #15916 from Snuffleupagus/fetch-transfer
[api-minor] Enabling transferring of data fetched with the `PDFFetchStream` implementation
2023-01-13 13:28:12 +01:00
Jonas Jenwald
1d683708e8
Merge pull request #15917 from Snuffleupagus/pr-15908-followup
Improve input validation in `PDFDataTransportStream._onReceiveData` (PR 15908 follow-up)
2023-01-12 15:32:59 +01:00
Jonas Jenwald
1362cd91d0 Improve input validation in PDFDataTransportStream._onReceiveData (PR 15908 follow-up)
The mozilla-central [method `PdfDataListener.readData`](https://searchfox.org/mozilla-central/rev/893a8f062ec6144c84403fbfb0a57234418b89cf/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#207-210) can return `null`, hence it seems like a very good idea to update `PDFDataTransportStream._onReceiveData` to handle that gracefully since the current code will throw in that case.

Also, improves the JSDocs for the `PDFDataRangeTransport` class in the API.
2023-01-12 15:24:59 +01:00
Jonas Jenwald
cee97fcd15 [api-minor] Enabling transferring of data fetched with the PDFFetchStream implementation
Note how in the API we're transferring the PDF data that's fetched over the network[1]:
 - f28bf23a31/src/display/api.js (L2467-L2480)
 - f28bf23a31/src/display/api.js (L2553-L2564)

To support that functionality we have the `PDFDataTransportStream`, `PDFFetchStream`, `PDFNetworkStream`, and `PDFNodeStream` implementations. Here these stream-implementations vary slightly in how they handle `ArrayBuffer`s internally, w.r.t. transferring or copying the data:
 - In `PDFDataTransportStream` we optionally, after PR 15908, allow transferring of the PDF data as provided externally (used e.g. in the Firefox PDF Viewer).
 - In `PDFFetchStream` we're currenly always copying the PDF data returned by the Fetch API, which seems unnecessary. As discussed in PR 15908, it'd seem very weird if this sort of browser API didn't allow transferring of the returned data.
 - In `PDFNetworkStream` we're already, since many years, transferring the PDF data returned by the `XMLHttpRequest` functionality. Note how the `getArrayBuffer` helper function simply returns an `ArrayBuffer` response as-is.
 - In `PDFNodeStream` we're currently copying the PDF data, however this is unfortunately necessary since Node.js returns data as a `Buffer` object[2].

Given that the `PDFNetworkStream` has been, indirectly, supporting transferring of PDF data for years it would seem really strange if this didn't also apply to the `PDFFetchStream`-implementation.
Hence this patch simply enables transferring of PDF data, when accessed using the Fetch API, unconditionally to help reduced main-thread memory usage since the `PDFFetchStream`-implementation is used *by default* in browsers (for the GENERIC build).

---
[1] As opposed to PDF data being provided as e.g. a TypedArray when calling `getDocument` in the API.

[2] This is a "special" Node.js object, see https://nodejs.org/api/buffer.html#buffer, which doesn't exist in browsers.
2023-01-12 13:59:21 +01:00
Jonas Jenwald
f28bf23a31
Merge pull request #15908 from Snuffleupagus/bug-1809164
[api-minor] Add a new `transferPdfData` option to allow transferring more data to the worker-thread (bug 1809164)
2023-01-11 17:34:51 +01:00
calixteman
dafcf82365
Merge pull request #15909 from calixteman/pinch_trackpad
Add support for smooth pinch-to-zoom on a trackpad (bug 1659492)
2023-01-11 16:26:21 +01:00
Calixte Denizet
f5dcc69ea1 Add support for smooth pinch-to-zoom on a trackpad (bug 1659492)
- Scale factor is rounded to only scale by integer percent, hence the unused
  ticks are accumulated (like we already do for zoom with the mouse wheel).
- Use the same thing for the pinch-to-zoom on a touchscreen: it led to slightly
  refactor the code because it happened to ignore a not so small scale which
  led to a not so smooth zooming.
2023-01-11 15:14:33 +01:00
calixteman
633d5e7af0
Merge pull request #15914 from calixteman/15894_followup
Simplify PDFViewerApplication::supportsPrinting (follow-up of #15894)
2023-01-11 14:07:52 +01:00
Calixte Denizet
8068dff9d1 Simplify PDFViewerApplication::supportsPrinting (follow-up of #15894) 2023-01-11 12:33:33 +01:00
Jonas Jenwald
bbe629018d [api-minor] Add a new transferPdfData option to allow transferring more data to the worker-thread (bug 1809164)
Also, removes the `initialData`-parameter JSDocs for the `getDocument`-function given that this parameter has been completely unused since PR 8982 (over five years ago). Note that the `initialData`-parameter is, and always was, intended to be provided when initializing a `PDFDataRangeTransport`-instance.
2023-01-10 21:03:44 +01:00
calixteman
d6f63b5fb7
Merge pull request #15907 from calixteman/bug1809080
Fix pinch-to-zoom on a macbook trackpad (bug 1809080)
2023-01-09 15:41:25 +01:00
Calixte Denizet
0c1cf2c237 Fix pinch-to-zoom on a macbook trackpad (bug 1809080) 2023-01-09 13:48:46 +01:00
Jonas Jenwald
067d3b70aa
Merge pull request #15906 from timvandermeij/nodejs
Upgrade Node.js to version 18 in the CI workflow
2023-01-08 20:32:22 +01:00
Tim van der Meij
588447aa90
Upgrade Node.js to version 18 in the CI workflow
Version 16 that we used before is now in maintenance mode, so we should
upgrade to the most recent LTS version. For more information on the
Node.js release schedule please refer to
https://github.com/nodejs/release#release-schedule.
2023-01-08 17:35:08 +01:00
Tim van der Meij
ca668dfd41
Merge pull request #15904 from Snuffleupagus/tweak-sidebarContent-background
Remove the `background-color` of the sidebarContent (PR 15850 follow-up)
2023-01-08 14:21:15 +01:00
Jonas Jenwald
8ab5476cb8 Remove the background-color of the sidebarContent (PR 15850 follow-up)
After the changes in PR 15850, the `background-color` of the sidebar is now unnecessarily dark in the light-theme. Hence, we can simply remove this CSS rule to improve things overall (and these changes don't affect the dark-theme much at all).
This is even an overall consistency improvement, given the existing `--sidebar-narrow-bg-color` values.
2023-01-08 14:06:02 +01:00
Jonas Jenwald
173bd88dbd
Merge pull request #15903 from mozilla/dependabot/npm_and_yarn/json5-1.0.2
Bump json5 from 1.0.1 to 1.0.2
2023-01-08 11:33:15 +01:00
dependabot[bot]
f51e85e84b
Bump json5 from 1.0.1 to 1.0.2
Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-08 06:05:38 +00:00
calixteman
fcaeb5db88
Merge pull request #15901 from calixteman/15289_followup
Avoid null ExpansionFactor in type1 fonts (follow-up of #15289)
2023-01-07 18:20:31 +01:00
Jonas Jenwald
74e4b515c5
Merge pull request #15897 from Snuffleupagus/issue-15893
Support parsing encrypted documents in `XRef.indexObjects` (issue 15893)
2023-01-07 16:55:41 +01:00
Calixte Denizet
c170245fc0 Avoid null ExpansionFactor in type1 fonts (follow-up of #15289) 2023-01-07 16:25:24 +01:00
calixteman
e1f7355de4
Merge pull request #15900 from calixteman/15289
Set ExpansionFactor to 0.06 when it's equals to 0 in the private dict of CFF fonts
2023-01-07 16:13:33 +01:00
Calixte Denizet
e565e455e2 Set ExpansionFactor to 0.06 when it's equals to 0 in the private dict of CFF fonts 2023-01-07 14:53:13 +01:00
Tim van der Meij
d6984f9395
Merge pull request #15899 from Snuffleupagus/tweak-toolbar-border-color
Tweak the `--toolbar-border-color` CSS variable (PR 15850 follow-up)
2023-01-07 13:53:35 +01:00
Jonas Jenwald
bd84bf4ebd Tweak the --toolbar-border-color CSS variable (PR 15850 follow-up)
After the changes in PR 15850, the toolbar-border is now quite difficult to spot in the light-theme. Hence, let's tweak it slightly to improve things.
2023-01-07 13:44:21 +01:00
Tim van der Meij
38e46e7614
Merge pull request #15850 from calixteman/15836
Remove shadow around each pages (fix issue #15836)
2023-01-07 13:29:41 +01:00
Tim van der Meij
69113f08f2
Merge pull request #15887 from Snuffleupagus/rm-setPDFNetworkStreamFactory
Inline the `setPDFNetworkStreamFactory` functionality in `src/display/api.js`
2023-01-07 13:16:23 +01:00
Tim van der Meij
b428824269
Merge pull request #15879 from Snuffleupagus/useWorkerFetch-defaults
[api-minor] Improve the `useWorkerFetch` default value checks
2023-01-07 13:13:25 +01:00
calixteman
91c44ec7ab
Merge pull request #15857 from calixteman/delay_loading_icon
Delay the loading icon display
2023-01-06 16:09:32 +01:00
Jonas Jenwald
1d5de9f4f4 Inline the setPDFNetworkStreamFactory functionality in src/display/api.js
Given that this is internal functionality, not exposed in the official API, it's not entirely clear (at least to me) why we can't just initialize this directly in `src/display/api.js` instead.
When testing both the development viewer and all the ways in which we run tests, everthing still appears to work just fine with this patch.
2023-01-06 13:23:07 +01:00
Jonas Jenwald
7d94fdeb48 Support parsing encrypted documents in XRef.indexObjects (issue 15893)
*Please note:* The reduced test-case is *not* a perfect reproduction of the original PDF document, since this one fails to open in e.g. Adobe Reader, but I do believe that it captures the most important points here.

For corrupt *and* encrypted PDF documents, it's possible that only some trailer dictionaries actually contain an /Encrypt-entry. Previously we'd could easily miss that, since we generally pick the first not obviously corrupt trailer dictionary, and the solution implemented here is to simply pre-parse all trailer dictionaries to see if there's any /Encrypt-entries.
2023-01-06 13:09:37 +01:00
Calixte Denizet
dd29f8705c Delay the loading icon display
In most of the cases, showing the loading icon is useless because
it's for a very short time, consequently it doesn't bring any useful
information for the user.
After a delay (400ms), the icon is shown in order to inform the user
that the viewer isn't stuck but it's doing something.
2023-01-06 12:28:32 +01:00
calixteman
e36564668b
Merge pull request #15896 from calixteman/gv_update_matches_count
[GV] Add an option in the find controller to update matches count only when the last page is reached (bug 1803188).
2023-01-06 12:11:20 +01:00
Calixte Denizet
661f425934 [GV] Add an option in the find controller to update matches count only when the last page is reached (bug 1803188).
In GeckoView, on an event, a callback must be executed with the result of an action,
but the callback can be used only one time.
So for each FindInPage event, we must trigger only one matches count update.
2023-01-06 10:56:26 +01:00
calixteman
8a0ca04399
Merge pull request #15894 from calixteman/gv_disable_print
[GV] Remove print stuff because window.print isn't implemented (bug 1808668)
2023-01-05 13:43:53 +01:00
Calixte Denizet
409c8b344f [GV] Remove print stuff because window.print isn't implemented (bug 1808668) 2023-01-05 13:02:29 +01:00
calixteman
7da591048c
Merge pull request #15892 from calixteman/fix_autoprint
[JS] UserActivation must be enabled before running document actions
2023-01-04 21:50:29 +01:00
Calixte Denizet
dea2471e96 [JS] UserActivation must be enabled before running document actions
else auto-print is broken (it's a regression from patch #15822).
2023-01-04 21:26:36 +01:00
Jonas Jenwald
1e1a2fce49
Merge pull request #15891 from Snuffleupagus/accumulateTicks
Reduce duplication in the `accumulateWheelTicks`/`accumulateTouchTicks` methods (PR 15886 follow-up)
2023-01-04 19:30:47 +01:00
Jonas Jenwald
66a3aa28fd Reduce duplication in the accumulateWheelTicks/accumulateTouchTicks methods (PR 15886 follow-up)
It just occurred to me that we can reduce some duplication by having the, virtually identical, `accumulateWheelTicks`/`accumulateTouchTicks` methods use a common helper instead that takes advantage of [bracket notation](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics#bracket_notation).
2023-01-04 18:19:39 +01:00
calixteman
4faf927030
Merge pull request #15886 from calixteman/pinch_to_zoom
[api-minor] Add the pinch-to-zoom feature (bug 1677933)
2023-01-04 17:20:29 +01:00
Calixte Denizet
d6b7a1f034 [api-minor] Add the pinch-to-zoom feature (bug 1677933) 2023-01-04 16:00:46 +01:00
Jonas Jenwald
da1365a309
Merge pull request #15885 from Snuffleupagus/font-update-type-subtype
Update the `type`/`subtype` at the end of font parsing
2023-01-02 17:18:05 +01:00
Jonas Jenwald
6bdbb5c5ca Update the type/subtype at the end of font parsing
This fixes a warning reported by CodeQL, and should also make general sense given that we parse the font-data to determine the *actual* `type`/`subtype` rather than trusting the PDF document.
2023-01-02 16:21:48 +01:00
Jonas Jenwald
42aa08563b
Merge pull request #15880 from Snuffleupagus/rm-docStats
[api-minor] Remove the `PDFDocumentProxy.stats` getter (PR 15758 follow-up)
2023-01-02 16:03:53 +01:00
Jonas Jenwald
1ba6e9437c
Merge pull request #15884 from Snuffleupagus/enable-defaultZoomDelay
Enable the `defaultZoomDelay` option/preference unconditionally, and other (small) improvements
2023-01-02 15:38:29 +01:00
Calixte Denizet
685b5866e4 Remove shadow around each pages (fix issue #15836) 2023-01-02 14:58:53 +01:00
Jonas Jenwald
9089e75cce Validate the options before adding the ResizeObserver in the PDFViewer constructor (PR 15830 follow-up)
In the GENERIC viewer, it doesn't make sense to register the `ResizeObserver` if the `container`/`viewer` options are not valid.
2023-01-02 14:52:00 +01:00
Jonas Jenwald
0860a5b168 Ensure that a document is loaded in PDFViewer.{increaseScale, decreaseScale} (PR 14053 follow-up)
This was always "wrong", since these methods (just like all the zoom-related ones) don't make sense unless there's an active document.
2023-01-02 14:05:33 +01:00
Jonas Jenwald
9f50b0af37 Enable the defaultZoomDelay option/preference unconditionally (PR 15812 follow-up)
This option/preference was disabled in GENERIC builds, see PR 15812, to avoid landing it *just before* a new release. Hence it should be fine to enable this now.
2023-01-02 14:00:16 +01:00
calixteman
e7cea29ad4
Merge pull request #15883 from calixteman/infinite_loop_search_diacritic
Avoid an infinite loop when searching for a single diacritic
2023-01-02 13:13:32 +01:00
Calixte Denizet
69c88477a9 Avoid an infinite loop when searching for a single diacritic 2023-01-02 12:27:07 +01:00
Jonas Jenwald
1a69d537c1 [api-minor] Limit the PDFDocumentLoadingTask.onUnsupportedFeature functionality to GENERIC builds (PR 15758 follow-up)
This was deprecated in PR 15758 but it's unfortunately quite difficult to tell if third-party users are depending on this, e.g. to implement custom error reporting, and if so to what extent.
However, thanks to the pre-processor we can limit *most* of this code to GENERIC builds which still seem like a worthwhile change.

These changes reduce the bundle size of the Firefox PDF Viewer by 3.8 kB in total.
2023-01-01 17:53:12 +01:00
Jonas Jenwald
0c1fb4e740 [api-minor] Remove the PDFDocumentProxy.stats getter (PR 15758 follow-up)
This was deprecated in PR 15758 and given that it's quite unlikely that any third-party users are relying on this functionality, since it was only ever added to support telemetry reporting in the Firefox PDF Viewer, it should hopefully be fine to remove this fairly quickly.

These changes reduce the bundle size of the Firefox PDF Viewer by 4.5 kB in total.
2023-01-01 17:06:47 +01:00
Jonas Jenwald
2c57a4232c [api-minor] Improve the useWorkerFetch default value checks
Given that the Fetch API only supports the http/https protocols, worker-thread fetching of CMaps and Standard-fonts may thus fail in certain cases. To improve the default behaviour we'll now also check that the `cMapUrl` and `standardFontDataUrl` options are appropriate, except in Firefox where this should always work.
2023-01-01 14:48:28 +01:00
Tim van der Meij
1e3e2defe4
Merge pull request #15878 from timvandermeij/bump
Bump versions in `pdfjs.config`
2023-01-01 14:44:41 +01:00
Tim van der Meij
195846a716
Bump versions in pdfjs.config 2023-01-01 14:35:58 +01:00
Tim van der Meij
3fd2a35482
Merge pull request #15874 from Snuffleupagus/progressBar-decouple-colors
Decouple the loadingBar `background-color` from the rest of the viewer
2022-12-31 15:14:59 +01:00
Jonas Jenwald
c791e01bfc
Merge pull request #15875 from Snuffleupagus/viewer-name-consistency
Improve name consistency in the viewer (PR 15812 follow-up)
2022-12-29 11:52:25 +01:00
Jonas Jenwald
88432a0e3f Improve name consistency in the viewer (PR 15812 follow-up)
This tweaks a few name that originated in PR 15812, to improve overall consistency:
 - Use the `drawingDelay` parameter-name in all methods that accept a delay.
 - Use the `postponeDrawing` variable-name in all relevant methods.
2022-12-28 13:26:01 +01:00
Jonas Jenwald
c2d17cac34 [GeckoView] Remove the progressBar CSS variables, since they're unused
Given that there's no loadingBar element present in the GeckoView-viewer, we shouldn't need CSS variables for it.
2022-12-28 12:14:22 +01:00
Jonas Jenwald
49c09eda9b Decouple the loadingBar background-color from the rest of the viewer
With upcoming background changes elsewhere in the viewer, this should be helpful in separating the styling of the loadingBar. These changes also means that both the "regular" and the "indeterminate" loadingBar now uses the same `background-color` value.

Also, shortens the related CSS variables a little bit since that can't hurt.
2022-12-28 12:07:39 +01:00
Jonas Jenwald
35ca6ab319
Merge pull request #15867 from Snuffleupagus/loadingIcon-toggle
Only display the loadingIcons when rendering is currently running
2022-12-27 13:51:20 +01:00
Jonas Jenwald
4224984525 Only display the pageNumber-loadingIcon when rendering is currently running
*This makes the same kind of changes as in the previous patch, but for the pageNumber-loadingIcon in the main toolbar.*

To display the pageNumber-loadingIcon when rendering starts, if the page is the most visible one, we'll utilize the existing "pagerender" event.
To toggle the pageNumber-loadingIcon as the user moves through the document we'll now instead utilize the "pagechanging" event, which should actually be slightly more efficient overall[1]. Note how we'd, in the old code, only consider the most visible page anyway when toggling the pageNumber-loadingIcon.

---
[1] Even in a PDF document as relatively short/simple as `tracemonkey.pdf`, scrolling through the entire document can easily trigger the "updateviewarea" event more than a thousand times.
2022-12-27 13:28:39 +01:00
Jonas Jenwald
a578571f59 Only display the page-loadingIcon when rendering is currently running
Given that we only render one page at a time, this will lead to only *one* page-loadingIcon being displayed at a time even if multiple pages are visible in the viewer. However, this will make it clearer which page is the currently parsing/rendering one.

To simplify toggling of the page-loadingIcon visibility, the existing `PDFPageView.renderingState` is changed into a getter/setter-pair with the latter also handling the page-loadingIcon state.
An additional benefit of these changes is that the `PDFViewer` no longer needs to handling toggling of page-loadingIcon visibility during rendering, since there can only ever be *one* page rendering.
Finally, this may also simplify future changes w.r.t. page-loadingIcon visibility toggling (using e.g. a show-timeout).
2022-12-27 13:28:39 +01:00
Jonas Jenwald
3110d1f29a
Merge pull request #15869 from Snuffleupagus/_abortOperatorList-clearTimeout
Always abort a pending `streamReader` cancel timeout in `PDFPageProxy._abortOperatorList` (PR 15825 follow-up)
2022-12-27 13:26:43 +01:00
Jonas Jenwald
1dce95613a
Merge pull request #15870 from Snuffleupagus/rm-PDFPageProxy-getJSActions-caching
Remove `PDFPageProxy.getJSActions` caching, since it's unused, in the API
2022-12-27 13:25:24 +01:00
Jonas Jenwald
ec6ad91bb7
Merge pull request #15872 from Snuffleupagus/PDFPageView-setDimensions-regression
[Regression] Ensure that documents with varying page sizes are initialized correctly (PR 15812 follow-up)
2022-12-27 13:24:06 +01:00
Jonas Jenwald
05169efec1 [Regression] Ensure that documents with varying page sizes are initialized correctly (PR 15812 follow-up)
The rotation-caching added in PR 15812 completely breaks initialization of PDF documents with varying page sizes, causing all pages to wrongly get the same size; see e.g. `sizes.pdf` from the test-suite.
To fix that without having to e.g. add a new parameter, which feels error prone, this patch changes the `PDFPageView.#setDimensions` method to completely ignore the rotation-caching until the `setPdfPage`-method has been called.
2022-12-27 12:14:42 +01:00
Jonas Jenwald
841abb53e6 Remove PDFPageProxy.getJSActions caching, since it's unused, in the API
Note how, in the scripting initialization in the viewer, we only ever invoke `PDFPageProxy.getJSActions` *once* per page in order to improve overall performance; see a575aa13b9/web/pdf_scripting_manager.js (L372-L375)

Hence it really shouldn't be necessary to cache its result in the API, especially when that is done *manually* rather than using something like `shadow`.
2022-12-27 10:39:33 +01:00
Jonas Jenwald
ae24dbd064 Always abort a pending streamReader cancel timeout in PDFPageProxy._abortOperatorList (PR 15825 follow-up)
When we're destroying a `PDFPageProxy`-instance, during full document destruction, we'll force-abort any worker-thread parsing of operatorLists. Hence we should make sure that any pending cancel timeout is always aborted, since a later `PDFPageProxy._abortOperatorList` call should always "replace" a previous one.

*Please note:* Technically this was always wrong, but with the changes in PR 15825 it became *ever so slightly* easier to trigger this thanks to the potentially longer timeout.
2022-12-27 10:19:39 +01:00
calixteman
a575aa13b9
Merge pull request #15862 from calixteman/layers_zindex
Set a z-index for the different layers within a page (fixes #15861)
2022-12-26 23:14:21 +01:00
Calixte Denizet
c677b167b6 Set a z-index for the different layers within a page (fixes #15861)
Each layer has an absolute position, hence it induces the creation of
some stacking contexts (see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context).
Thanks to this feature, we don't have to worry about the z-index used in
the annotation layer and how form elements interact with the other layers.
2022-12-26 22:55:08 +01:00
calixteman
e49dd525b0
Merge pull request #15812 from calixteman/refactor_zoom
Only redraw after zooming is finished (bug 1661253)
2022-12-26 19:44:03 +01:00
Calixte Denizet
663007a5c7 Only redraw after zooming is finished (bug 1661253)
Right now, the visible pages are redrawn for each scale change.
Consequently, zooming with mouse wheel or in pinching can be pretty janky
(even on a desktop machine but with a hdpi screen).
So the main idea in this patch is to draw the visible pages only once zooming
is finished.
2022-12-26 18:13:17 +01:00
Jonas Jenwald
31da2fad51
Merge pull request #15864 from Snuffleupagus/update-packages
Update packages and translations
2022-12-25 13:53:28 +01:00
Jonas Jenwald
3b02d23ce2 Update l10n files 2022-12-25 12:59:37 +01:00
Jonas Jenwald
492ce090bd Update npm packages 2022-12-25 12:59:34 +01:00
Jonas Jenwald
8aed0c3613
Merge pull request #15854 from Snuffleupagus/issue-15803
Re-factor searching for incomplete objects in `XRef.indexObjects` (issue 15803)
2022-12-24 10:23:39 +01:00
Jonas Jenwald
869807406d
Merge pull request #15860 from Snuffleupagus/loadingIcon-last
Ensure that the `loadingIconDiv` is always visible (PR 15829 follow-up)
2022-12-23 11:45:27 +01:00
Jonas Jenwald
d042a3ca76 Ensure that the loadingIconDiv is always visible (PR 15829 follow-up)
After the changes in PR 15829 the `loadingIconDiv` is no longer always visible when it should be, specifically in the case where we cancel and re-render a partially parsed/rendered page.
To reproduce this, try opening https://github.com/mozilla/pdf.js/files/1522715/wuppertal_2012.pdf in the viewer and change the zoom level while rendering is ongoing. In this case the `loadingIconDiv` doesn't actually become visible, despite being present in the DOM, since it's no longer at the end of the page-div.

I don't know to what extent this renders PR 15829 "pointless", however we're not repeatedly re-creating and re-inserting the `loadingIconDiv` but rather just *move* the existing element in the DOM.
2022-12-22 12:34:32 +01:00
Jonas Jenwald
a749f6cc14
Merge pull request #15852 from Snuffleupagus/layerProperties-followup
A couple of small viewer fixes (PR 15811 and 15831 follow-up)
2022-12-19 23:09:26 +01:00
Jonas Jenwald
2fcf8bb5be Re-factor searching for incomplete objects in XRef.indexObjects (issue 15803)
When trying to find incomplete objects, i.e. those missing the "endobj"-string at the end, there's unfortunately a number of possible operators that we need to check for. Otherwise we could miss e.g. the "trailer" at the end of a corrupt PDF document, which is why the referenced document didn't work.

Currently we do all searching on the "raw" bytes of the PDF document, for efficiency, however this doesn't really work when we need to check for *multiple* potential command-strings. To keep the complexity manageable we'll instead use regular expressions here, but we can at least avoid creating lots of substrings thanks to the `RegExp.lastIndex` property; which is well supported across browsers according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex#browser_compatibility

Note that this repeated regular expression usage could perhaps be slightly less efficient than the old code, however this method is only invoked for corrupt PDF documents.
2022-12-19 23:01:09 +01:00
Jonas Jenwald
f3d7f2e64f Fix the loadingBar initialization in the "mobile-viewer" example (PR 15831 follow-up)
Given that the `ProgressBar`-constructor was updated, we need to update the "mobile-viewer" example as well; this is yet another thing I missed during review.
2022-12-19 01:20:06 +01:00
Jonas Jenwald
e8c7278337 Improve the linkService handling in the DEFAULT_LAYER_PROPERTIES (PR 15811 follow-up)
We'll no longer import the `SimpleLinkService` dependency unconditionally in the file, since it's only used in COMPONENTS-builds.
Furthermore, for the COMPONENTS-builds, we'll create a `SimpleLinkService`-instance only for those layers that actually need it.
2022-12-19 01:04:04 +01:00
Tim van der Meij
6a9a567670
Merge pull request #15811 from Snuffleupagus/rm-web-default-factory
[api-minor] Remove the default factories, used to initialize various layers, in the viewer
2022-12-18 14:22:13 +01:00
Jonas Jenwald
d9cdc46f84 Update the "pageviewer" example to account for the previous patches
This uses a simple version number check, to prevent breakage if the example is used with older PDF.js versions.
2022-12-18 13:26:56 +01:00
Jonas Jenwald
8b8d890064 [api-minor] Remove the xfaLayerFactory in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `xfaLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-18 13:26:54 +01:00
Jonas Jenwald
c393148748 [api-minor] Remove the textLayerFactory in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `textLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-18 13:26:33 +01:00
Jonas Jenwald
4c78290028 [api-minor] Remove the textHighlighterFactory in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `textHighlighterFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-18 13:26:10 +01:00
Jonas Jenwald
f1d1f6edfd [api-minor] Remove the structTreeLayerFactory in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `structTreeLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-18 13:26:08 +01:00
Jonas Jenwald
ca69da735e [api-minor] Remove the annotationLayerFactory in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-18 13:25:45 +01:00
Jonas Jenwald
7aedb8ed7a [api-minor] Remove the annotationEditorLayerFactory in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-18 13:10:23 +01:00
Jonas Jenwald
8fa8310ec9 Decouple the annotationLayer and annotationEditorLayer in the viewer
Currently we'll only initialize and render the `annotationEditorLayer` once the regular `annotationLayer` has been rendered.
While it obviously makes sense to render the `annotationEditorLayer` *last*, the way that the code is currently written means that if a third-party user disables the `annotationLayer` then the editing-functionality indirectly becomes disabled as well.
Given that this seems like a somewhat arbitrary limitation, this patch simply decouples these two layers while still keeping the rendering order consistent.
2022-12-18 13:10:23 +01:00
Jonas Jenwald
ded02941f2 [api-minor] Move, most of, the isPureXfa-handling from PDFViewer and into PDFPageView
By moving this code the "pageviewer"-component example will become slightly more usable on its own, it may simplify a future addition of XFA Foreground document support, and finally also serves as preparation for the following patches.
2022-12-18 13:10:23 +01:00
calixteman
dd96ee1512
Merge pull request #15849 from calixteman/15744
[Editor] Avoid to scroll when an annotation is commited (fixes issue #15744)
2022-12-17 16:16:36 +01:00
Calixte Denizet
a84d14b382 [Editor] Avoid to scroll when an annotation is commited (fixes issue #15744) 2022-12-17 13:48:19 +01:00
calixteman
1ab711e2ac
Merge pull request #15830 from calixteman/dont_compute_rect
Avoid to compute the client rect of the viewer
2022-12-17 12:34:40 +01:00
calixteman
65a476a386
Merge pull request #15847 from calixteman/followup_15845
Display the text layer before running the a11y stuff (follow-up of #15845)
2022-12-17 11:58:39 +01:00
Calixte Denizet
f4914849df Display the text layer before running the a11y stuff (follow-up of #15845) 2022-12-16 21:34:12 +01:00
Calixte Denizet
c550953c6d Avoid to compute the client rect of the viewer
The container position and dimensions should be almost constant, hence
it's pretty useless to query them on each rescale.
Finally it avoids to trigger some reflows.
2022-12-16 20:55:29 +01:00
calixteman
ee7a947d1f
Merge pull request #15845 from calixteman/15844
[TextLayer] Hide the text layer when it's created in order to avoid reflows (fix #15844)
2022-12-16 18:13:21 +01:00
Jonas Jenwald
18eb1a0ffd
Merge pull request #15842 from Snuffleupagus/gv-pageLayout
[GeckoView] Ignore the pageLayout, from the PDF document, to prevent issues
2022-12-16 17:56:18 +01:00
Calixte Denizet
c3a3ba2ebe [TextLayer] Hide the text layer when it's created in order to avoid reflows (fix #15844) 2022-12-16 17:24:40 +01:00
calixteman
cb212b24fd
Merge pull request #15841 from calixteman/15784
Strip out a reserved operator (9) from CFF char strings (fixes issue #15784)
2022-12-16 15:55:02 +01:00
Calixte Denizet
f80880ccaa Strip out a reserved operator (9) from CFF char strings (fixes issue #15784) 2022-12-16 15:17:46 +01:00
Jonas Jenwald
0c83bebf03
Merge pull request #15832 from Snuffleupagus/issue-15828
Attempt to expose `OnProgressParameters` in the TypeScript definitions (issue 15828)
2022-12-16 12:44:29 +01:00
Jonas Jenwald
0289038961 [GeckoView] Ignore the pageLayout, from the PDF document, to prevent issues
First of all, given the screen-sizes of most mobile phones using Spread modes is unlikely to be useful.
Secondly, and more importantly, since there's (currently) no UI available for the user to override a PDF document-specified Spread mode this would result in a bad UX otherwise.

Also, removes an outdated comment from the `apiPageLayoutToViewerModes` helper function.
2022-12-16 12:09:56 +01:00
Jonas Jenwald
b518d93b45
Merge pull request #15835 from Snuffleupagus/viewer-safe-element-access
Protect a few additional DOM element accesses in the viewer (PR 15831 follow-up)
2022-12-15 19:48:13 +01:00
Jonas Jenwald
4bd66a2150 Protect a few additional DOM element accesses in the viewer (PR 15831 follow-up)
A couple of cases that I missed during review, for code-paths that don't run by default in the viewer.
2022-12-15 18:48:10 +01:00
Jonas Jenwald
826c358b3a
Merge pull request #15834 from Snuffleupagus/issue-15833
Always parse the entire `startXRefQueue` in `XRef.readXRef` (issue 15833)
2022-12-15 16:48:14 +01:00
calixteman
0021d65dc0
Merge pull request #15831 from calixteman/android_viewer
[GV] Add a viewer for GeckoView
2022-12-15 15:45:26 +01:00
Jonas Jenwald
26135b0313 Always parse the entire startXRefQueue in XRef.readXRef (issue 15833)
Previously we'd abort all parsing if an Error was encountered, despite the fact that multiple `startXRefQueue`-entries may be available and that continued parsing could thus eventually be able to find usable data.

Note that in the referenced PDF document the `startxref`-operator, at the end of the file, points to a position in the middle of an arbitrary `stream` which is why things break.
2022-12-15 13:46:28 +01:00
Calixte Denizet
f19572c4cc [GV] Add a viewer for GeckoView 2022-12-15 13:39:48 +01:00
Jonas Jenwald
8587ce6afd
Merge pull request #15829 from calixteman/dont_remove_spinner
Don't remove the loading icon from the DOM when a page is resetted
2022-12-15 10:31:21 +01:00
Calixte Denizet
20037e9919 Don't remove the loading icon from the DOM when a page is resetted 2022-12-15 10:19:49 +01:00
Jonas Jenwald
0ef72044e2 Attempt to expose OnProgressParameters in the TypeScript definitions (issue 15828)
Hopefully this works, since as usual I don't really know anything about TypeScript...
2022-12-14 21:36:31 +01:00
Jonas Jenwald
506bbb7283
Merge pull request #15825 from Snuffleupagus/cancel-extraDelay
[api-minor] Allow specifying an extra-delay, in `RenderTask.cancel`, for worker-thread aborting of operatorList parsing
2022-12-14 19:26:39 +01:00
Jonas Jenwald
d90e62e806
Merge pull request #15824 from Snuffleupagus/annotationLayer-params
Handle possibly undefined parameters *once* per `AnnotationLayer.render` invocation
2022-12-14 15:16:56 +01:00
Jonas Jenwald
68f36d82d5
Merge pull request #15826 from Snuffleupagus/lazy-textHighlighter
Initialize the `TextHighlighter`-instance lazily in `PDFPageView`
2022-12-14 14:17:34 +01:00
Jonas Jenwald
8ac94d6519 Initialize the TextHighlighter-instance lazily in PDFPageView
Depending on e.g. the `textLayerMode` option it might not actually be necessary to always initialize this eagerly.
*Please note:* Unfortunately we cannot `shadow` a private field, hence why this is only made semi-"private".
2022-12-14 13:23:05 +01:00
Jonas Jenwald
5df341ed7e Make the various layer-render methods, in PDFPageView, properly private 2022-12-14 13:12:49 +01:00
Jonas Jenwald
91524d1a60 [api-minor] Allow specifying an extra-delay, in RenderTask.cancel, for worker-thread aborting of operatorList parsing
This is done to support upcoming viewer-changes, and in order to prevent third-party users from outright breaking things we'll simply ignore too large values.
2022-12-14 12:34:16 +01:00
Jonas Jenwald
dcf9ff2182 Handle possibly undefined parameters *once* per AnnotationLayer.render invocation
There's no reason to repeat this for every single annotation. Also, adds a couple of missing JSDoc-parameters.
2022-12-14 12:23:24 +01:00
calixteman
e182597cb1
Merge pull request #15822 from calixteman/15818
[JS] Run the named actions before running the format when the file is open (issue #15818)
2022-12-13 21:56:50 +01:00
Calixte Denizet
2ebf8745a2 [JS] Run the named actions before running the format when the file is open (issue #15818)
It's a follow-up of #14950: some format actions are ran when the document is open
but we must be sure we've everything ready for that, hence we have to run some
named actions before runnig the global format.
In playing with the form, I discovered that the blur event wasn't triggered when
JS called `setFocus` (because in such a case the mouse was never down). So I removed
the mouseState thing to just use the correct commitKey when blur is triggered by a
TAB key.
2022-12-13 21:12:32 +01:00
calixteman
2d596045d1
Merge pull request #15819 from calixteman/15815
[JS] Handle correctly choice widgets where the display and the export values are different (issue #15815)
2022-12-13 19:40:23 +01:00
Calixte Denizet
0c1ec946aa [JS] Handle correctly choice widgets where the display and the export values are different (issue #15815) 2022-12-13 19:08:26 +01:00
calixteman
64786b4c93
Merge pull request #15820 from calixteman/fix_visual_order
The annotation layer dimensions must be set before adding some elements (follow-up of #15770)
2022-12-13 15:54:47 +01:00
Calixte Denizet
1a397681fe The annotation layer dimensions must be set before adding some elements (follow-up of #15770)
In order to move the annotations in the DOM to have something which corresponds
to the visual order, we need to have their dimensions/positions which means that
the parent must have some dimensions.
2022-12-13 14:54:45 +01:00
Jonas Jenwald
0fdac9ba70
Merge pull request #15797 from Snuffleupagus/PageViewport-rawDims
[api-minor] Add a new `PageViewport`-getter to access the original, un-scaled, viewport dimensions
2022-12-12 11:12:38 +01:00
Jonas Jenwald
cafdc48147 [api-minor] Add a new PageViewport-getter to access the original, un-scaled, viewport dimensions
While reviewing recent patches, I couldn't help but noticing that we now have a lot of call-sites that manually access the `PageViewport.viewBox`-property.
Rather than repeating that verbatim all over the code-base, this patch adds a lazily computed and cached getter for this data instead.
2022-12-11 18:37:35 +01:00
Jonas Jenwald
8e11cf9b1c
Merge pull request #15806 from Snuffleupagus/AnnotationLayerBuilder-no-annotations
Don't attempt to re-create the `annotationLayer`, for pages without any annotations, on zooming and rotation
2022-12-11 18:32:24 +01:00
Jonas Jenwald
9b6d0d994d Remove the API-caching of annotation-data
This was essentially done only to compensate for the viewer calling `PDFPageProxy.getAnnotations` unconditionally on every annotationLayer-rendering invocation. With the previous patch that's no longer happening, and this API-caching should thus no longer be necessary.
2022-12-11 18:12:10 +01:00
Jonas Jenwald
8e56f072e0 Don't attempt to re-create the annotationLayer, for pages without any annotations, on zooming and rotation
For pages without any annotations, applies e.g. to the `tracemonkey.pdf` document, we'll repeatedly try to re-create the `annotationLayer` on every zoom and rotation operation.
The reason that this happens is because we don't insert the `annotationLayer`-div into the DOM unless there's annotations present on the page, which thus means that we miss the existing `annotationLayer`-caching present in the `PDFPageView` implementation.

This is a very old issue, and the easiest solution is to simply always insert an *empty* (and hidden) `annotationLayer`-div such that the existing code/caching starts working for the "no annotations" case as well.
Note that this is consistent with other layers, since e.g. the `textLayer` and/or `annotationEditorLayer` may be empty. Given that only a limited, by default ten, number of pages are ever active at once the additional DOM-elements shouldn't effect things negatively here.
2022-12-11 18:12:09 +01:00
calixteman
d9f13558d6
Merge pull request #15770 from calixteman/set_dims
Set the dimensions of the various layers at their creation
2022-12-11 17:32:29 +01:00
Tim van der Meij
6c2f34b6bb
Merge pull request #15805 from Snuffleupagus/XfaLayerBuilder-render-async
Change the `XfaLayerBuilder.render` method to be asynchronous
2022-12-11 14:02:45 +01:00
Jonas Jenwald
828efd9d00 Change the XfaLayerBuilder.render method to be asynchronous
This is consistent with the `render` methods of the other layers, and reduces overall indentation in the method.
Furthermore, don't "swallow" errors since the `PDFPageView._renderXfaLayer` method is already able to deal with that.
2022-12-11 13:08:23 +01:00
Jonas Jenwald
879a7432b5
Merge pull request #15800 from Snuffleupagus/AnnotationEditorLayerBuilder-destroy
[AnnotationEditorLayerBuilder] Inline the `destroy` code in the `cancel` method
2022-12-10 15:02:43 +01:00
Calixte Denizet
a989b5a879 Set the dimensions of the various layers at their creation
- Use a unique helper function in display/display_utils.js;
- Move those dimensions in css' side.
2022-12-10 14:35:06 +01:00
Jonas Jenwald
bed1a1baa1 [AnnotationEditorLayerBuilder] Inline the destroy code in the cancel method
It doesn't seem necessary to have a *separate* `destroy` method given that the `cancel` method always invokes it unconditionally.
In the `PDFPageView.reset` method we currently attempt to call `destroy` directly, however that'll never actually happen since either:
 - We're keeping the annotationEditorLayer, in which case we're just hiding the layer and nothing more (and the relevant branch is never entered).
 - We're removing the annotationEditorLayer, in which case the `PDFPageView.cancelRendering` method has already cancelled *and* nulled it (and there's thus nothing left to `destroy` here).

*Please note:* Hopefully I'm not overlooking something obvious here, since both reading through the code *and* also adding `console.log(this.annotationEditorLayer);` [before this line](9d4aadbf7a/web/pdf_page_view.js (L438)) suggests that it's indeed unnecessary.
2022-12-10 10:16:20 +01:00
Jonas Jenwald
9d4aadbf7a
Merge pull request #15796 from Snuffleupagus/issue-15795
Ensure that the various layers always get the correct initial size (issue 15795)
2022-12-09 17:26:35 +01:00
Jonas Jenwald
527258c316 Ensure that the various layers always get the correct initial size (issue 15795) 2022-12-09 14:30:12 +01:00
Jonas Jenwald
3155e2a63b
Merge pull request #15798 from Snuffleupagus/PresentationMode-spreadMode-hPadding
Fix page-switching for landscape documents with SpreadModes and PresentationMode (PR 14877 follow-up)
2022-12-09 14:19:09 +01:00
Jonas Jenwald
47ac706972 Fix page-switching for landscape documents with SpreadModes and PresentationMode (PR 14877 follow-up)
In PR 14877 I forgot to update the horizontal padding, used when computing the scale of the pages, for the case where SpreadModes and PresentationMode are being used together.

Steps to reproduce:
 1. Open the viewer with the default `tracemonkey.pdf` document.
 1. Enable any SpreadMode.
 2. Rotate the document *once*, either clockwise or counterclockwise.
 3. Enter PresentationMode.
 4. Try swithching page, e.g. by clicking on the document.

Expected result:
 The visible pages change as you click.

Actual result:
 The visible pages are "stuck" in the current view.
2022-12-09 14:09:56 +01:00
Jonas Jenwald
ba2fec9891
Merge pull request #15788 from Snuffleupagus/web-small-fixes
A few small viewer-related fixes
2022-12-08 18:05:37 +01:00
calixteman
baff5ad565
Merge pull request #15791 from calixteman/15789
[Editor] Take all the viewBox into account when computing the coordinates of an annotation in the page (fixes #15789)
2022-12-08 15:45:36 +01:00
Jonas Jenwald
d7d21f0d6e Change AnnotationEditorLayerBuilder.render to not access "private" API functionality
The `PDFPageProxy._pageIndex` property is a "private" one that shouldn't be accessed, since it could theoretically break tomorrow if we re-factor the relevant API code.

Also, try to clean-up and improve consistency in a couple of JSDoc comments.
2022-12-08 15:40:04 +01:00
Jonas Jenwald
6a5c1343f8 Stop trying to disable searching in PresentationMode
This change was made in PR 5552, however I cannot tell why we needed to disable searching in PresentationMode. Furthermore, with the changes in PR 13908 which effectively moved where this code is invoked, searching has now (accidentally) been working in PresentationMode in e.g. the Firefox PDF Viewer for well over a year.

So, let's just enable searching unconditionally in PresentationMode to simplify the code.
2022-12-08 15:33:57 +01:00
Calixte Denizet
4f0bfabe7a Take all the viewBox into account when computing the coordinates of an annotation in the page (fixes #15789) 2022-12-08 15:02:20 +01:00
calixteman
fe3df4dcb4
Merge pull request #15782 from calixteman/15780
[api-minor][Editor] Don't use the editor parent which can be null.
2022-12-08 14:27:42 +01:00
Calixte Denizet
b93bf9f654 [Editor] Don't use the editor parent which can be null.
An annotation editor layer can be destroyed when it's invisible, hence some
annotations can have a null parent but when printing/saving or when changing
font size, color, ... of all added annotations (when selected with ctrl+a) we
still need to have some parent properties especially the page dimensions, global
scale factor and global rotation angle.
This patch aims to remove all the references to the parent in the editor instances
except in some cases where an editor should obviously have one.
It fixes #15780.
2022-12-08 14:06:06 +01:00
Jonas Jenwald
c639063050
Merge pull request #15776 from Snuffleupagus/rm-createDownloadManager-options
Remove the unused `DefaultExternalServices.createDownloadManager` options (PR 12191 follow-up)
2022-12-07 10:31:15 +01:00
Jonas Jenwald
0ca92bf2a8
Merge pull request #15775 from Snuffleupagus/vars-all
Tighten the `vars`-argument for the ESLint `no-unused-vars` rule
2022-12-07 10:30:47 +01:00
calixteman
feb6f5951c
Merge pull request #15786 from calixteman/15780_bis
[Editor] Add a very basic and incomplete workaround for issue #15780
2022-12-06 19:11:33 +01:00
Calixte Denizet
9af89381cd [Editor] Add a very basic and incomplete workaround for issue #15780
The main issue is due to the fact that an editor's parent can be null when
we want to serialize it and that lead to an exception which break all the
saving/printing process.
So this incomplete patch fixes only the saving/printing issue but not the
underlying problem (i.e. having a null parent) and doesn't bring that much
complexity, so it should help to uplift it the next Firefox release.
2022-12-06 16:22:24 +01:00
Jonas Jenwald
cdd39ec69e
Merge pull request #15778 from Snuffleupagus/keep-structTree
Don't re-create the `structTreeLayer` on zooming and rotation
2022-12-06 10:02:20 +01:00
Jonas Jenwald
96152f56e7
Merge pull request #15779 from Snuffleupagus/textContentSource
[api-minor] Combine the `textContent`/`textContentStream` parameters
2022-12-06 09:58:07 +01:00
Jonas Jenwald
0274245e90 Remove the unused TextLayerRenderTask._renderingDone property (PR 15259 follow-up)
This is yet another property that I forgot to remove in PR 15259.
2022-12-05 11:49:14 +01:00
Jonas Jenwald
fe8fded23b [api-minor] Combine the textContent/textContentStream parameters
Rather than handling these parameters separately, which is a left-over from back when streaming of textContent was originally added, we can simply pass either data directly to the `TextLayer` and let it handle things accordingly.

Also, improves a few JSDoc comments and `typedef`-imports.
2022-12-04 21:22:14 +01:00
Jonas Jenwald
b659bacc43 Tighten the vars-argument for the ESLint no-unused-vars rule
Please see https://eslint.org/docs/latest/rules/no-unused-vars#vars
2022-12-04 16:15:50 +01:00
Jonas Jenwald
da0e6bc590 Don't re-create the structTreeLayer on zooming and rotation
Compared to the recent PR 15722 for the `textLayer` this one should be a (comparatively) much a smaller win overall, since most documents don't have any structTree-data and the required parsing should be cheaper. However, it seems to me that it cannot hurt to improve this nonetheless.

Note that by moving the `structTreeLayer` initialization we remove the need for the "textlayerrendered" event listener, which thus simplifies the code a little bit.

Also, removes the API-caching of the structTree-data since this was basically done to offset the lack of caching in the viewer.
2022-12-04 10:18:58 +01:00
Jonas Jenwald
cd72818438 Remove unused StructTreeLayerBuilder constructor parameter
Also change the "private" methods into properly private ones.
2022-12-03 22:58:37 +01:00
Jonas Jenwald
9369adb4bd Remove the unused DefaultExternalServices.createDownloadManager options (PR 12191 follow-up) 2022-12-03 12:52:36 +01:00
Tim van der Meij
67e1c37e0f
Merge pull request #15773 from Snuffleupagus/view-worker-normalize
[api-minor] Normalize the `view`-getter on the worker-thread
2022-12-02 19:52:44 +01:00
Tim van der Meij
99cfef882f
Merge pull request #15752 from Snuffleupagus/no-typeof-undefined
Enable the `no-typeof-undefined` ESLint plugin rule
2022-12-02 19:48:16 +01:00
Jonas Jenwald
5f8598abb7 [api-minor] Normalize the view-getter on the worker-thread
*Please note:* I don't really expect that this is will be an observable change, since virtually all PDF documents already order e.g. /MediaBox and /CropBox entries correctly.

By normalizing boundingBoxes already on the worker-thread, we can be sure that even a corrupt document won't cause issues.
Note how we're passing the `view`-getter to the `PartialEvaluator.getTextContent` method, in order to detect textContent which is outside of the page, hence it makes sense to ensure that it's formatted as expected.
Furthermore, by normalizing this once on the worker-tread we should no longer have to worry about a possibly negative width/height in the `PageViewport` constructor.

Finally, the patch also simplifies the `view`-getter a little bit.
2022-12-02 15:46:39 +01:00
calixteman
e3c2af14b3
Merge pull request #15772 from calixteman/chmod
Remove execution permission on cursor-editorFreeText.svg
2022-12-02 10:02:08 +01:00
Jonas Jenwald
2c4bb5d91d
Merge pull request #15771 from mozilla/dependabot/npm_and_yarn/decode-uri-component-0.2.2
Bump decode-uri-component from 0.2.0 to 0.2.2
2022-12-02 09:55:19 +01:00
Calixte Denizet
973478e704 Remove execution permission on cursor-editorFreeText.svg 2022-12-02 09:52:03 +01:00
dependabot[bot]
b7083d7a0e
Bump decode-uri-component from 0.2.0 to 0.2.2
Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-02 04:48:04 +00:00
calixteman
6e4968225e
Merge pull request #15722 from calixteman/refactor_textlayer
[api-minor] Refactor the text layer code in order to avoid to recompute it on each draw
2022-12-01 18:56:02 +01:00
Calixte Denizet
eed9bf71c5 Refactor the text layer code in order to avoid to recompute it on each draw
The idea is just to resuse what we got on the first draw.
Now, we only update the scaleX of the different spans and the other values
are dependant of --scale-factor.
Move some properties in the CSS in order to avoid any updates in JS.
2022-12-01 18:42:43 +01:00
Jonas Jenwald
47dbfc4ade Enable the no-typeof-undefined ESLint plugin rule
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-typeof-undefined.md
2022-12-01 18:20:39 +01:00
Jonas Jenwald
4793a0717f
Merge pull request #15768 from Snuffleupagus/issue-15767
Prevent the `debugger` from breaking on unbalanced save/restore OPS (issue 15767)
2022-12-01 17:06:53 +01:00
Jonas Jenwald
0cf4e6620d Prevent the debugger from breaking on unbalanced save/restore OPS (issue 15767) 2022-12-01 15:43:17 +01:00
Jonas Jenwald
fa54a58790
Merge pull request #15765 from Snuffleupagus/rm-textLayer-timeout
[api-minor] Remove the TextLayer `timeout` parameter (PR 15742 follow-up)
2022-11-29 21:21:45 +01:00
calixteman
f3206b351f
Merge pull request #15764 from calixteman/15753
[Annotation] Send correctly the updated values to the JS sandbox
2022-11-29 20:04:12 +01:00
Jonas Jenwald
7c25b1b455 [api-minor] Remove the TextLayer timeout parameter (PR 15742 follow-up)
The deprecation is included in the current release, i.e. version `3.1.81`, and given the edge-case nature of this option I really don't think that we need to keep it deprecated for multiple releases.
2022-11-29 19:57:38 +01:00
Calixte Denizet
20fd9099f8 [Annotation] Send correctly the updated values to the JS sandbox 2022-11-29 17:34:06 +01:00
Jonas Jenwald
1f082d3e1d
Merge pull request #15761 from Snuffleupagus/platform
Stop duplicating the `platform` getter in multiple files
2022-11-29 17:32:52 +01:00
calixteman
a3ac8a6438
Merge pull request #15718 from calixteman/test_text_cursor
[Editor] Change the text annotation cursor for the high dpi screens.
2022-11-29 16:37:36 +01:00
Calixte Denizet
8689905a19 [Editor] Change the text annotation cursor for the high dpi screens. 2022-11-29 15:48:55 +01:00
Jonas Jenwald
ff9d21ff0e
Merge pull request #15762 from Snuffleupagus/bug-1803050
Ignore PDF documents opened from "data:"-URLs when handling internal links (bug 1803050)
2022-11-29 15:16:33 +01:00
Jonas Jenwald
0d648f531b Ignore PDF documents opened from "data:"-URLs when handling internal links (bug 1803050)
This patch has been successfully tested in a local, artifact, Firefox build.

*Please note:* The only thing that'll no longer work for PDF documents opened using "data:"-URLs is middle-clicking on internal/outline links, in order to open the destination in a new tab. This is however an extremely small loss of functionality, and as can be seen in the bug the alternative (i.e. doing nothing) is surely much worse.
2022-11-29 14:08:01 +01:00
Jonas Jenwald
82d127883d Stop duplicating the platform getter in multiple files
Currently both of the `AnnotationElement` and `KeyboardManager` classes contain *identical* `platform` getters, which seems like unnecessary duplication.
With the pre-processor we can also limit the feature-testing to only GENERIC builds, since `navigator` should always be available in browsers.
2022-11-29 12:14:40 +01:00
calixteman
5d79cc5bee
Merge pull request #15760 from calixteman/15759
Don't add an extra space after a Katakana or a Hiragana at the eol when searching
2022-11-29 11:05:56 +01:00
Calixte Denizet
ea1995991b Don't add an extra space after a Katakana or a Hiragana at the eol when searching 2022-11-29 10:46:48 +01:00
calixteman
44bc315444
Merge pull request #15758 from calixteman/cleanup_telemetry
[api-minor] Remove all the useless telemetry stuff in the viewer (bug 1802468)
2022-11-28 21:54:00 +01:00
Calixte Denizet
b9cb651c44 [api-minor] Remove all the useless telemetry stuff in the viewer (bug 1802468)
Add a deprecation notification for PDFDocumentLoadingTask.onUnsupportedFeature and PDFDocumentProxy.stats
which are likely useless.
The unsupported feature stuff have initially been added in (#4048) in order to be able to display a
warning bar and to help to have some numbers to know how a feature was used.
Those data are no more used in Firefox.
2022-11-28 20:55:15 +01:00
calixteman
f96b99c30c
Merge pull request #15757 from calixteman/bug1802888
[JS] By default, a text field value must be treated as a number (bug 1802888)
2022-11-28 17:31:35 +01:00
Calixte Denizet
ae7da6ae48 [JS] By default, a text field value must be treated as a number (bug 1802888) 2022-11-28 16:24:01 +01:00
calixteman
33f9d1aab2
Merge pull request #15755 from calixteman/rounding_printf
[JS] Fix a rounding issue in printf (bug 1802888)
2022-11-28 15:39:36 +01:00
Calixte Denizet
4ee0c83548 [JS] Fix a rounding issue in printf (bug 1802888) 2022-11-28 14:37:15 +01:00
Tim van der Meij
8bac57172a
Merge pull request #15751 from Snuffleupagus/modernize-isSyncFontLoadingSupported
Slightly modernize the `FontLoader.isSyncFontLoadingSupported` getter
2022-11-27 13:48:54 +01:00
Jonas Jenwald
f458b52bc7
Merge pull request #15750 from Snuffleupagus/update-packages
Update packages and translations
2022-11-27 12:35:50 +01:00
Jonas Jenwald
85f03c0ea4 Slightly modernize the FontLoader.isSyncFontLoadingSupported getter
This is very old code, which is unused (by default) in browsers nowadays since the Font Loading API will always be preferred.
For Node.js environments we use the same constant as elsewhere throughout the code-base, and we can also simplify the Firefox-specific check given that the lowest supported version is `102` (as of this writing).

Finally the old TODO is removed, since the general availability of the Font Loading API has made it redundant.
2022-11-27 12:19:11 +01:00
Jonas Jenwald
6aa8c3bd3f Update l10n files 2022-11-27 10:22:14 +01:00
Jonas Jenwald
69a2e6d3ea Update npm packages 2022-11-27 10:18:30 +01:00
Jonas Jenwald
73760144e0
Merge pull request #15747 from Snuffleupagus/FileAttachment-icons
Add default icons for FileAttachment annotations (bug 1230933)
2022-11-26 17:59:52 +01:00
Tim van der Meij
ba9174406c
Merge pull request #15749 from timvandermeij/bump
Bump versions in `pdfjs.config`
2022-11-26 15:01:12 +01:00
Tim van der Meij
67f1a5b59a
Bump versions in pdfjs.config 2022-11-26 14:52:56 +01:00
Tim van der Meij
0766898d5d
Merge pull request #15720 from Snuffleupagus/issue-15695
Ensure that the initial document position is always correct with non-default Scroll/Spread modes (issue 15695)
2022-11-26 13:05:54 +01:00
Jonas Jenwald
aa5b678f94 Add default icons for FileAttachment annotations (bug 1230933)
*Please note:* This "borrows" the icons from Thunderbird.

According to the PDF specification, see https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2096626, we should be providing default icons for FileAttachment annotations without appearances.
2022-11-26 11:24:59 +01:00
Jonas Jenwald
37c2408199 Ensure that the initial document position is always correct with non-default Scroll/Spread modes (issue 15695)
Please refer to the inline comment for additional details. The patch also improves internal consistency when `#scrollIntoView` is called directly.
2022-11-26 10:06:29 +01:00
Jonas Jenwald
4f1b6f345b
Merge pull request #15715 from Snuffleupagus/getQuadPoints-refactor
Re-factor and simplify the `getQuadPoints` helper function
2022-11-25 12:38:52 +01:00
Jonas Jenwald
4b02610e8c Re-factor and simplify the getQuadPoints helper function
The use of `Array.prototype.reduce()` is, in my opinion, hurting overall readability since it's not particularly easy to look at the relevant code and immediately understand what's going on here. Furthermore this code leads to strictly speaking unnecessary allocations and parsing, since we could just track the min/max values directly in the relevant loop instead.
2022-11-25 10:40:16 +01:00
Jonas Jenwald
67741aeaa9
Merge pull request #15742 from Snuffleupagus/deprecate-textLayer-timeout
[api-minor] Deprecate the TextLayer `timeout` parameter
2022-11-25 08:44:02 +01:00
Jonas Jenwald
b3e161c328 [api-minor] Deprecate the TextLayer timeout parameter
This has never really been used anywhere within the PDF.js library[1], and when streaming of textContent was introduced this parameter was effectively made redundant.
Note that when streaming of textContent is used, all text-layout has already happened by the time that this `timeout`-functionality is actually invoked (thus making it pointless).
While the `timeout`-functionality may still "work" when the textContent is provided upfront, although it's never been used/tested, streaming will generally perform better (in e.g. a viewer setting).

*Please note:* While unrelated here, also removes a now unused property that I forgot in PR 15259.

---
[1] At least not since the code was moved into its current file, which happened in PR 6619 and landed seven years ago.
2022-11-24 23:08:39 +01:00
Jonas Jenwald
8fda3f04fe
Merge pull request #15732 from Snuffleupagus/issue-15719
Add a fallback for non-embedded *composite* Tahoma fonts (issue 15719)
2022-11-24 19:09:12 +01:00
Jonas Jenwald
823723121d
Merge pull request #15740 from mozilla/revert-15721-issue-15714
Revert "Remove the overflowing text special-case from `scrollIntoView` (issue 15714)"
2022-11-24 12:44:19 +01:00
Jonas Jenwald
9f5e1f4818
Revert "Remove the overflowing text special-case from scrollIntoView (issue 15714)" 2022-11-24 12:37:07 +01:00
Jonas Jenwald
5960e20cde
Merge pull request #15731 from Snuffleupagus/issue-15716
Add support for Optional Content in TilingPatterns (issue 15716)
2022-11-23 15:54:41 +01:00
Jonas Jenwald
d1c01b3164 Add a fallback for non-embedded *composite* Tahoma fonts (issue 15719) 2022-11-23 15:51:18 +01:00
Jonas Jenwald
47682985d3 Add support for Optional Content in TilingPatterns (issue 15716)
This can't be a particularly common feature, since we've supported Optional Content for over two years and this is the very first TilingPattern-case we've seen.
2022-11-23 12:58:00 +01:00
Jonas Jenwald
73c268dc1c
Merge pull request #15730 from Snuffleupagus/issue-15729
Support FileAttachments with hash-signs in the filename (issue 15729)
2022-11-23 12:52:11 +01:00
calixteman
8cd2adf8a1
Merge pull request #15727 from calixteman/bug1801341
Unblock the load event when the pdf has a password (bug 1801341)
2022-11-23 12:09:12 +01:00
Jonas Jenwald
f3e0f86641 Simplify the getFilenameFromUrl helper function 2022-11-23 11:48:08 +01:00
Calixte Denizet
38dd219d85 Unblock the load event when the pdf has a password (bug 1801341) 2022-11-23 11:17:58 +01:00
Jonas Jenwald
0ba242ea4a Support FileAttachments with hash-signs in the filename (issue 15729)
The reason for the issue is that we use the generic `getFilenameFromUrl` helper function, which was originally intended for regular URLs.
For the filenames we're dealing with in FileAttachments, we really only want to strip the path when one exists[1].

---
[1] See [bug 1230933](https://bugzilla.mozilla.org/show_bug.cgi?id=1230933) for an example of such a case.
2022-11-23 10:47:33 +01:00
Jonas Jenwald
a0db81723b
Merge pull request #15721 from Snuffleupagus/issue-15714
Remove the overflowing text special-case from `scrollIntoView` (issue 15714)
2022-11-22 14:51:02 +01:00
Jonas Jenwald
0ff43b27bb Remove the overflowing text special-case from scrollIntoView (issue 15714)
With the changes made in PR 14564 this *should* no longer be necessary now, however we still need to keep the `scrollMatches` parameter to handle textLayers with markedContent correctly when searching.
2022-11-22 11:54:30 +01:00
Jonas Jenwald
748be3f702
Merge pull request #15713 from Snuffleupagus/annotation-no-appearance-cleanup
Reduce duplication when creating a fallback appearance for `MarkupAnnotation`s
2022-11-20 17:12:41 +01:00
Jonas Jenwald
2ff9799e7a Tweak assignment of common parameters in the Annotation classes
This is slightly more compact, and also unifies the format across the various classes.
2022-11-20 12:29:59 +01:00
Jonas Jenwald
c92de947b6 Reduce duplication when creating a fallback appearance for MarkupAnnotations
Currently we repeat the same color-conversion code verbatim in lots of classes, which seems completely unnecessary.
2022-11-20 12:05:25 +01:00
Tim van der Meij
ae7c97aef8
Merge pull request #15710 from Snuffleupagus/issue-10791
Add localization support for the `annotationLayer` reference tests (issue 10791)
2022-11-19 11:25:15 +01:00
Tim van der Meij
d6908ee145
Merge pull request #15701 from Snuffleupagus/move-string-helpers
Move some string helper functions to the worker-thread
2022-11-19 11:20:07 +01:00
Tim van der Meij
3d49459d64
Merge pull request #15706 from Snuffleupagus/worker-rm-fn-names
Remove unnecessary function names in the `src/core/worker.js` file
2022-11-19 11:14:24 +01:00
Jonas Jenwald
2ff904fb2b Add localization support for the annotationLayer reference tests (issue 10791) 2022-11-18 23:08:11 +01:00
Jonas Jenwald
70d362f22c Remove an unnecessary variable in getPdfManager, in the src/core/worker.js file
Another tiny piece of clean-up, since adding a `catch`-handler to a Promise shouldn't require an intermediate variable.
2022-11-17 15:31:41 +01:00
Jonas Jenwald
a2a200175f Remove unnecessary function names in the src/core/worker.js file
Currently *some* functions in this file have names while others don't, and in a few cases the names are no longer entirely accurate.
For the relevant functions there should really be no need to name them, and if memory serves this was originally done since browsers (many years ago) didn't always handle anonymous functions correctly in stack traces.
2022-11-17 15:12:48 +01:00
Jonas Jenwald
7d029f8bfe Add a basic stringToUTF16HexString unit-test 2022-11-16 12:39:35 +01:00
Jonas Jenwald
9adc7859c8 Move the escapeString helper function into the worker-thread
Given that this helper function is only used on the worker-thread, there's no reason to duplicate it in both of the `pdf.js` and `pdf.worker.js` files.
2022-11-16 12:35:48 +01:00
Jonas Jenwald
e5859e145d Move the isAscii helper function into the worker-thread
Given that this helper function is only used on the worker-thread, there's no reason to duplicate it in both of the `pdf.js` and `pdf.worker.js` files.
2022-11-16 12:35:48 +01:00
Jonas Jenwald
2eaa708e3a Combine the stringToUTF16String and stringToUTF16BEString helper functions
Given that these functions are virtually identical, with the latter only adding a BOM, we can combine the two. Furthermore, since both functions were only used on the worker-thread, there's no reason to duplicate this functionality in both of the `pdf.js` and `pdf.worker.js` files.
2022-11-16 12:35:44 +01:00
Jonas Jenwald
c7d6ab2f71
Merge pull request #15699 from Snuffleupagus/isOffscreenCanvasSupported-Annotation
Move the `_isOffscreenCanvasSupported` property to the base `Annotation` class
2022-11-15 17:18:03 +01:00
Jonas Jenwald
f358e76f5b Move the _isOffscreenCanvasSupported property to the base Annotation class
Having just played around with adding FreeText-annotations and then trying to print, there were `FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly.` messages printed in the console.
The reason for this is that `FreeTextAnnotation` inherits from `MarkupAnnotation`, however only `WidgetAnnotation` actually defines the `_isOffscreenCanvasSupported` property.
2022-11-15 16:30:53 +01:00
Jonas Jenwald
e089d07994
Merge pull request #15698 from Snuffleupagus/DIACRITICS_EXCEPTION_STR-lazy
Initialize the find-related `DIACRITICS_EXCEPTION_STR` constant lazily
2022-11-15 14:01:14 +01:00
Jonas Jenwald
176e8f0ddc Initialize the find-related DIACRITICS_EXCEPTION_STR constant lazily
Adding some logging with `console.{time, timeEnd}` around all the constant definitions at the top of the `web/pdf_find_controller.js` file, I noticed that computing `DIACRITICS_EXCEPTION_STR` took close to half the total time.
My first idea was just to try and make it slightly more efficient, by reducing the amount of iterations and intermediate allocations. However, with this constant only being used during "match diacritics" searches it thus seemed like a good candidate for lazy initialization.

*Please note:* Given that this is a micro optimization, I fully understand if the patch is rejected.
2022-11-15 12:46:16 +01:00
calixteman
859335a1ae
Merge pull request #15694 from calixteman/15690
Normalize fullwidth, halfwidth and circled chars when searching
2022-11-14 21:36:29 +01:00
Calixte Denizet
2be64d63e1 Normalize fullwidth, halfwidth and circled chars when searching 2022-11-14 19:27:51 +01:00
Jonas Jenwald
3078e2c1d9
Merge pull request #15692 from mozilla/dependabot/npm_and_yarn/minimatch-3.1.2
Bump minimatch from 3.0.4 to 3.1.2
2022-11-14 15:56:27 +01:00
Jonas Jenwald
6d7250bfca
Merge pull request #15693 from Snuffleupagus/dependabot-labels
Stop Dependabot from creating its own, otherwise unused, labels
2022-11-14 15:19:56 +01:00
Jonas Jenwald
26883c0d7e Stop Dependabot from creating its own, otherwise unused, labels
Currently all Dependabot update PRs get tagged with a "javascript" label, which is annoying since we don't actually use that one.
To try and avoid this we specify the labels explicitly, please see https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#labels
2022-11-14 15:07:55 +01:00
dependabot[bot]
497b32a0a3
Bump minimatch from 3.0.4 to 3.1.2
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Release notes](https://github.com/isaacs/minimatch/releases)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-14 13:54:34 +00:00
Jonas Jenwald
82795a3b81
Merge pull request #15688 from Snuffleupagus/bug-1799927-mask
Take the mask-offset into account when rendering repeated image masks (bug 1799927)
2022-11-14 14:49:06 +01:00
Jonas Jenwald
8f676e88fb
Merge pull request #15689 from Snuffleupagus/update-packages
Update packages and translations
2022-11-14 14:48:26 +01:00
Jonas Jenwald
b85ce7f761 Update l10n files 2022-11-13 21:32:12 +01:00
Jonas Jenwald
fbcc20adb7 Update npm packages 2022-11-13 21:28:21 +01:00
Jonas Jenwald
3e4caf2e13 Take the mask-offset into account when rendering repeated image masks (bug 1799927)
*Please note:* As usual when I'm working with the `src/display/canvas.js` code I don't really know what I'm doing, but it at least *appears* to work.
2022-11-13 16:15:30 +01:00
Tim van der Meij
bfe6ff5893
Merge pull request #15686 from Snuffleupagus/findDefaultInlineStreamEnd-assert
Change the `assert` in `Parser.findDefaultInlineStreamEnd` to a non-PRODUCTION one
2022-11-13 13:20:03 +01:00
Jonas Jenwald
a1d48e3651 Add a *linked* test-case for issue 2618
Given that this PDF document is an interesting test-case for performance reasons, w.r.t. inline image caching, it probably can't hurt to add it to the test-suite to make it more readily available.
Considering the contents of that PDF document I'm not sure if we can include it directly in the repository, hence why a *linked* test-case was choosen here.
2022-11-12 16:31:01 +01:00
Jonas Jenwald
d22eb3591e Change the assert in Parser.findDefaultInlineStreamEnd to a non-PRODUCTION one
Given that this `assert` is only intended to catch any implementation bugs in our code, and not actually to validate the PDF data directly[1], we can avoid making this function call unconditionally.

---
[1] In those cases, for example a `FormatError` should have been thrown instead.
2022-11-12 16:30:58 +01:00
Jonas Jenwald
2d1b1e7968
Merge pull request #15682 from Snuffleupagus/constructor-cleanup
Some small `AnnotationStorage` and `StatTimer` clean-up
2022-11-11 13:37:49 +01:00
Jonas Jenwald
bab1097db3 Remove the constructor in the StatTimer class
With modern EcmaScript features, we can define these fields directly instead. Please note that for backwards compatibility purposes they are still public as before, however note that this functionality is *disabled* by default (see the `pdfBug` API option).
Also, we can (slightly) simplify the two loops used in the `toString` method.
2022-11-11 12:31:04 +01:00
Jonas Jenwald
d6cd48e12a Use actually private fields in the AnnotationStorage class
These fields were never intended to be public, since modifying them manually would lead to inconsistent state, and with modern EcmaScript features we can now enforce this.
Also, this patch removes a couple of JSDoc comments that we generally don't use.
2022-11-11 12:30:02 +01:00
Jonas Jenwald
595711bd7c
Merge pull request #15679 from Snuffleupagus/bug-1799927-2
Use the *full* inline image as the cacheKey in `Parser.makeInlineImage` (bug 1799927)
2022-11-10 22:54:48 +01:00
calixteman
592d92424e
Merge pull request #15587 from calixteman/save_unicode
[Annotation] Fix printing/saving for annotations containing some non-ascii chars and with no fonts to handle them (bug 1666824)
2022-11-10 20:57:34 +01:00
Calixte Denizet
3ca03603c2 [Annotation] Fix printing/saving for annotations containing some non-ascii chars and with no fonts to handle them (bug 1666824)
- For text fields
 * when printing, we generate a fake font which contains some widths computed thanks to
   an OffscreenCanvas and its method measureText.
   In order to avoid to have to layout the glyphs ourselves, we just render all of them
   in one call in the showText method in using the system sans-serif/monospace fonts.
 * when saving, we continue to create the appearance streams if the fonts contain the char
   but when a char is missing, we just set, in the AcroForm dict, the flag /NeedAppearances
   to true and remove the appearance stream. This way, we let the different readers handle
   the rendering of the strings.
- For FreeText annotations
  * when printing, we use the same trick as for text fields.
  * there is no need to save an appearance since Acrobat is able to infer one from the
    Content entry.
2022-11-10 19:05:39 +01:00
Jonas Jenwald
e8ec6af73e Remove a couple of unnecessary temporary variables in MurmurHash3_64.hexdigest
These variables are left-over from the initial implementation, back when `String.prototype.padStart` didn't exist and we thus had to pad manually (using a loop).
2022-11-10 18:27:26 +01:00
Jonas Jenwald
7abb6429b0 Initialize the dictionary *lazily* when parsing inline images
This helps improve performance for some PDF documents with a huge number of inline images, e.g. the PDF document from issue 2618.
Given that we no longer create `Stream`-instances unconditionally, we also don't need `Dict`-instances for cached inline images (since we only access the filter).
2022-11-10 18:27:26 +01:00
Jonas Jenwald
b46e0d61cf Use the *full* inline image as the cacheKey in Parser.makeInlineImage (bug 1799927)
*Please note:* This only fixes the "wrong letter" part of bug 1799927.

It appears that the simple `computeAdler32` function, used when caching inline images, generates hash collisions for some (very short) TypedArrays. In this case that leads to some of the "letters", which are actually inline images, being rendered incorrectly.
Rather than switching to another hashing algorithm, e.g. the `MurmurHash3_64` class, we simply cache using a stringified version of the inline image data as the cacheKey to prevent any future collisions. While this will (naturally) lead to slightly higher peak memory usage, it'll however be limited to the current `Parser`-instance which means that it's not persistent.

One small benefit of these changes is that we can avoid creating lots of `Stream`-instances for already cached inline images.
2022-11-10 18:27:26 +01:00
Jonas Jenwald
f7449563ef
Merge pull request #15659 from sxyuan/system-font-name-fix
[api-minor] Propagate the translated font name to TextContentItem for system fonts
2022-11-08 21:56:49 +01:00
Samuel Yuan
36fb5c1e2b Propagate the translated font name to TextContentItems.
This allows font data for system fonts to be looked up in the
PDFObjects.
2022-11-08 11:16:21 -08:00
Jonas Jenwald
7e5008f0ff
Merge pull request #15665 from Snuffleupagus/Glyph-category
[api-minor] Initialize the unicode-category *lazily* on the `Glyph`-instance
2022-11-05 15:26:57 +01:00
Jonas Jenwald
c8868a1c7a [api-minor] Initialize the unicode-category *lazily* on the Glyph-instance
The purpose of this patch is twofold:
 - Initialize the unicode-category data *lazily* during text-extraction, since this is completely unused during general parsing/rendering.
 - Stop exposing this data in the API, since it's unused on the main-thread and it seems like it was *accidentally* included.

Obviously these changes are API-observable, but hopefully no user is depending on this. Furthermore, it's trivial for a user to re-create this unicode-category data manually with a regular expression (from the exposed `unicode` property).
2022-11-05 10:12:17 +01:00
Jonas Jenwald
26f6f77db6
Merge pull request #15657 from Snuffleupagus/Glyph-normalizedUnicode
Cache the normalized unicode-value on the `Glyph`-instance
2022-11-05 09:18:35 +01:00
Jonas Jenwald
0b27d703fa
Merge pull request #15663 from Snuffleupagus/viewer-classes-private-fields
Use private fields in a few more viewer classes
2022-11-04 15:51:53 +01:00
Jonas Jenwald
e7a6e7393a Use private fields in a few more viewer classes
These properties were always intended to be *private*, so let's use modern JS features to actually enforce that.
2022-11-04 15:29:45 +01:00
Jonas Jenwald
c33b8d7692 Cache the normalized unicode-value on the Glyph-instance
Currently, during text-extraction, we're repeatedly normalizing and (when necessary) reversing the unicode-values every time. This seems a little unnecessary, since the result won't change, hence this patch moves that into the `Glyph`-instance and makes it *lazily* initialized.

Taking the `tracemonkey.pdf` document as an example: When extracting the text-content there's a total of 69236 characters but only 595 unique `Glyph`-instances, which mean a 99.1 percent cache hit-rate. Generally speaking, the longer a PDF document is the more beneficial this should be.

*Please note:* The old code is fast enough that it unfortunately seems difficult to measure a (clear) performance improvement with this patch, so I completely understand if it's deemed an unnecessary change.
2022-11-03 22:36:53 +01:00
Jonas Jenwald
eda51d1dcc
Merge pull request #15613 from Snuffleupagus/issue-15590
[api-minor] Let `Catalog.getAllPageDicts` return an *empty*  dictionary when loading the first /Page fails (issue 15590)
2022-11-03 15:41:39 +01:00
Jonas Jenwald
23930a249e [api-minor] Let Catalog.getAllPageDicts return an *empty* dictionary when loading the first /Page fails (issue 15590)
In order to support opening certain corrupt PDF documents, particularly hand-edited ones, this patch adds support for letting the `Catalog.getAllPageDicts` method fallback to returning an *empty* dictionary to replace (only) the first /Page of the document.
Given that the viewer cannot initialize/load without access to the first page, this will thus allow e.g. document-level scripting to run as expected. Note that by effectively replacing a corrupt or missing first /Page in this way[1], we'll now render nothing but a *blank* page for certain cases of broken/corrupt PDF documents which may look weird.

*Please note:* This functionality is controlled via the existing `stopAtErrors` option, that can be passed to `getDocument`, since it's easy to imagine use-cases where this sort of fallback behaviour isn't desirable.

---
[1] Currently we still require that a /Pages-dictionary is found though, however it *may* be possible to relax even that assumption if that becomes absolutely necessary in future corrupt documents.
2022-11-03 12:51:48 +01:00
Jonas Jenwald
2516ffa78e Fallback to finding the first "obj" occurrence, when the trailer-dictionary is incomplete (issue 15590)
Note that the "trailer"-case is already a fallback, since normally we're able to use the "xref"-operator even in corrupt documents. However, when a "trailer"-operator is found we still expect "startxref" to exist and be usable in order to advance the stream position. When that's not the case, as happens in the referenced issue, we use a simple fallback to find the first "obj" occurrence instead.

This *partially* fixes issue 15590, since without this patch we fail to find any objects at all during `XRef.indexObjects`. However, note that the PDF document is still corrupt and won't render since there's no actual /Pages-dictionary and the /Root-entry simply points to the /OpenAction-dictionary instead.
2022-11-03 12:46:30 +01:00
Jonas Jenwald
2ae90f9615
Merge pull request #15655 from tamuratak/move_canvas_to_optionaldeps
Move canvas to optionalDependencies
2022-11-02 09:49:04 +01:00
Takashi Tamura
0bb478cb23 Move canvas to optionalDependencies, which enables npm to continue installing pdfjs-dist
even if the installation of canvas fails. Close #15652
2022-11-02 08:33:31 +09:00
Jonas Jenwald
6193537cd3
Merge pull request #15648 from Snuffleupagus/issue-12232
Prevent interaction with form elements in PresentationMode (issue 12232)
2022-10-31 11:14:23 +01:00
calixteman
e42e1cde61
Merge pull request #15615 from calixteman/bug1796741
[Form] Don't use field appearances when /NeedAppearances is set to true (bug 1796741)
2022-10-31 09:58:27 +01:00
Jonas Jenwald
bc4e5e39ff
Merge pull request #15649 from SpartanApple/patch-1
Changed link for "Gulp's getting started guide"
2022-10-31 09:20:18 +01:00
Mitchell Gale
8d147b993f
Changed link for "Gulp's getting started guide"
Gulp's getting started guide changed location to https://github.com/gulpjs/gulp/tree/master/docs/getting-started. Link updated in readme to reflect that.
2022-10-30 15:30:42 -07:00
Jonas Jenwald
547556b5b2 Prevent keyboard interaction with form elements in PresentationMode (issue 12232)
This uses the relatively new `HTMLElement.inert` property, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert for additional information. The only "problem" is that this isn't yet available in all Firefox channels, but until https://bugzilla.mozilla.org/show_bug.cgi?id=1764263 is fixed we're no worse off than before.
2022-10-30 21:57:55 +01:00
Jonas Jenwald
f0811a4a3c Prevent mouse interaction with form elements in PresentationMode (issue 12232) 2022-10-30 21:55:44 +01:00
Tim van der Meij
c059c13785
Merge pull request #15643 from timvandermeij/bump
Bump versions in `pdfjs.config`
2022-10-29 20:11:04 +02:00
Tim van der Meij
ab136c5c39
Bump versions in pdfjs.config 2022-10-29 20:04:37 +02:00
Tim van der Meij
d0823066cc
Merge pull request #15642 from mozilla/dependabot/npm_and_yarn/minimist-and-minimist-1.2.6
Bump minimist
2022-10-29 19:19:40 +02:00
dependabot[bot]
131819a15c
Bump minimist
Bumps [minimist](https://github.com/minimistjs/minimist) and [minimist](https://github.com/minimistjs/minimist). These dependencies needed to be updated together.

Updates `minimist` from 1.2.0 to 1.2.6
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](https://github.com/minimistjs/minimist/compare/v1.2.0...v1.2.6)

Updates `minimist` from 1.2.5 to 1.2.6
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](https://github.com/minimistjs/minimist/compare/v1.2.0...v1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-29 17:14:12 +00:00
Tim van der Meij
b74fbdeda7
Merge pull request #15640 from Snuffleupagus/update-packages
Update packages and translations
2022-10-29 19:12:29 +02:00
Tim van der Meij
eeca44d162
Merge pull request #15641 from Snuffleupagus/rm-PdfManager-onLoadedStream
Remove the `PdfManager.onLoadedStream` method (PR 15616 follow-up)
2022-10-29 19:09:35 +02:00
Jonas Jenwald
caef47a0cf Remove the PdfManager.onLoadedStream method (PR 15616 follow-up)
After the clean-up in PR 15616, the `PdfManager.onLoadedStream` method now only has a single call-site.
Hence why this patch suggests that we remove this method and replace it with an *optional* parameter in `PdfManager.requestLoadedStream` instead. By making the new behaviour opt-in, we'll thus not change any existing call-site.
2022-10-29 14:42:17 +02:00
Jonas Jenwald
5b46400240
Merge pull request #15633 from calixteman/cursors
[Editor] Change the cursor icons
2022-10-29 12:24:10 +02:00
Calixte Denizet
67778eac60 [Editor] Change the cursor icons 2022-10-29 12:05:09 +02:00
Jonas Jenwald
571a986496 Update l10n files 2022-10-29 11:34:45 +02:00
Jonas Jenwald
f6746854ac Update npm packages 2022-10-29 11:34:43 +02:00
Jonas Jenwald
8b970109ea
Merge pull request #15632 from Snuffleupagus/issue-15629-2
[api-minor] Move the handling of unbalanced markedContent to the worker-thread (PR 15630 follow-up)
2022-10-29 09:37:07 +02:00
calixteman
8f80efa4ab
Merge pull request #15618 from calixteman/15614
[JS] Some functions (print, alert,...) must be called only after a user activation
2022-10-28 21:04:42 +02:00
Calixte Denizet
0de804a256 [JS] Some functions (print, alert,...) must be called only after a user activation
- Some events, which require a user interaction, will allow those functions to be called.
But after few seconds, if there are no more user interaction, it won't be possible
anymore.
The idea is to give an opportunity to the user to leave the pdf.
- Disable print function when we're printing, the same with saving and disallow to save
on open events.
2022-10-28 18:52:07 +02:00
Jonas Jenwald
a7232339d8
Merge pull request #15637 from Snuffleupagus/Array-from-map
Combine `Array.from` and `Array.prototype.map` calls
2022-10-28 18:29:02 +02:00
Jonas Jenwald
ba05e47b3e Combine Array.from and Array.prototype.map calls
This isn't just a tiny bit more compact, but it also avoids an intermediate allocation; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#description
2022-10-28 13:46:30 +02:00
Jonas Jenwald
1e7274e9c6 [api-minor] Move the handling of unbalanced markedContent to the worker-thread (PR 15630 follow-up) 2022-10-27 11:14:54 +02:00
calixteman
27b251ac99
Merge pull request #15631 from calixteman/15627
[JS] Avoid to trigger a commit event on 'ENTER' when the textfield is multiline
2022-10-27 10:29:25 +02:00
Calixte Denizet
87f53b9cc9 [JS] Avoid to trigger a commit event on 'ENTER' when the textfield is multiline 2022-10-26 19:29:13 +02:00
Jonas Jenwald
05e5927c41
Merge pull request #15630 from Snuffleupagus/issue-15629
Prevent textLayer errors in documents with unbalanced beginMarkedContent/endMarkedContent operators (issue 15629)
2022-10-26 19:27:23 +02:00
Jonas Jenwald
980acddbfa Prevent textLayer errors in documents with unbalanced beginMarkedContent/endMarkedContent operators (issue 15629) 2022-10-26 18:35:48 +02:00
Calixte Denizet
9f95a14e91 [Form] Don't use field appearances when /NeedAppearances is set to true (bug 1796741)
When a form isn't changed, we used the appearances we had in the file, but when
/NeedAppearances is true, all the appearances have to be regenerated whatever they're.
2022-10-26 12:10:51 +02:00
calixteman
9a33a0fba9
Merge pull request #15623 from calixteman/editor_int_test
Fix editor tests on Windows
2022-10-26 11:31:07 +02:00
calixteman
00279d6e64
Merge pull request #15625 from calixteman/bug1797310
Fix font for the 'current view' entry in the secondary toolbar (bug 1797310)
2022-10-26 11:02:55 +02:00
Calixte Denizet
0996398372 Fix font for the 'current view' entry in the secondary toolbar (bug 1797310) 2022-10-26 10:49:23 +02:00
Calixte Denizet
2384fbcb89 Fix editor tests on Windows
- In #15373, we implemented copy/paste actions in using the system
clipboard.
For any reasons, on Windows, the clipboard doesn't contain the expected
data when the tests are ran in parallel, hence the tests which are
using the clipboard need to be ran sequentially.
- Make sure that we can paste after having copied.
2022-10-25 22:48:02 +02:00
Jonas Jenwald
098ca670d0
Merge pull request #15616 from Snuffleupagus/PdfManager-requestLoadedStream-return
Let the `PdfManager.requestLoadedStream` method return the stream
2022-10-25 11:39:01 +02:00
Jonas Jenwald
22225a1eaa
Merge pull request #15617 from Snuffleupagus/bug-1662416
Update the l10n-strings for the download-buttons (bug 1662416)
2022-10-24 19:18:30 +02:00
Jonas Jenwald
03775917db Update the l10n-strings for the download-buttons (bug 1662416)
According to https://bugzilla.mozilla.org/show_bug.cgi?id=1662416#c8
2022-10-24 18:29:44 +02:00
Jonas Jenwald
bcffbf74f3 Let the PdfManager.requestLoadedStream method return the stream
*This is very old code, and it could thus do with some simplification.*

Note how in the `src/core/worker.js` file we're combining both the `PdfManager.requestLoadedStream` and `PdfManager.onLoadedStream` methods in order to access the stream-data. This seems unnecessary, and it's simple enough to always let the `PdfManager.requestLoadedStream` method return the stream-data as well.
2022-10-24 17:00:48 +02:00
Jonas Jenwald
987062c302
Merge pull request #15581 from Snuffleupagus/rm-setTransform-catch
Revert "Avoid all rendering breaking completely when CanvasPattern.setTransform() is unsupported" (PR 13725 follow-up)
2022-10-22 14:09:43 +02:00
Jonas Jenwald
497edbd0ee Revert "Avoid all rendering breaking completely when CanvasPattern.setTransform() is unsupported" (PR 13725 follow-up)
PR 13725 was only intended as a temporary work-around, and it seems that we can now revert that.
 - Firefox 102 is the currently maintained ESR-branch, and the PDF.js project only supports the active one.
 - Node.js now works, thanks to the `node-canvas` package, and I've confirmed locally that following the STR in issue 13724 generates a correct image.
2022-10-22 10:58:51 +02:00
Jonas Jenwald
f5711fc385
Merge pull request #15606 from Snuffleupagus/issue-15604
Let `Lexer.getNumber` treat more invalid "numbers" as zero (issue 15604)
2022-10-21 17:23:55 +02:00
calixteman
5e045b8688
Merge pull request #15608 from calixteman/new_icons
Update icons (last and final update)
2022-10-21 12:46:40 +02:00
Calixte Denizet
80dfd5404f Update icons (last and final update) 2022-10-21 12:31:34 +02:00
Jonas Jenwald
71bd8b4de9 Let Lexer.getNumber treat more invalid "numbers" as zero (issue 15604)
In the referenced PDF document there are "numbers" which consist only of `-.`, and while that's obviously not valid Adobe Reader seems to handle it just fine.
Letting this method ignore more invalid "numbers" was suggested during the review of PR 14543, so let's simply relax our the validation here.
2022-10-20 22:36:15 +02:00
Jonas Jenwald
7dc16c237a
Merge pull request #15603 from Snuffleupagus/pr-15593-followup
Restore a weaker version of the /Pages dictionary /Count check for corrupt documents (PR 15593 follow-up)
2022-10-20 15:13:25 +02:00
Jonas Jenwald
e591378ff1 Restore a weaker version of the /Pages dictionary /Count check for corrupt documents (PR 15593 follow-up)
It appears that PR 15593 broke `issue12402`, and we thus need to partially restore the /Count check.
 I completely missed this when looking at the test-results for PR 15593, both locally and on the bots, since the `Driver._getLastPageNumber` method would "swallow" an unavailable page number.
2022-10-20 14:22:29 +02:00
Jonas Jenwald
36967fcedb
Merge pull request #15586 from Snuffleupagus/rm-matchesForCache
Remove the `Glyph.matchesForCache` method (PR 13494 follow-up)
2022-10-20 10:35:00 +02:00
Jonas Jenwald
f3949ba69d
Merge pull request #15598 from calixteman/15597
[Annotation] Replace use of id by data-element-id to have the correct id
2022-10-20 00:01:24 +02:00
Calixte Denizet
6db9cefaaf [Annotation] Replace use of id by data-element-id to have the correct id 2022-10-19 23:36:28 +02:00
calixteman
ba3a0e104a
Merge pull request #15595 from calixteman/1793419
[Editor] Make FreeText annotations visible for screen readers when in editing mode (bug 1793419)
2022-10-19 19:33:49 +02:00
Jonas Jenwald
238570c0da
Merge pull request #15596 from Snuffleupagus/issue-15594
Extend `getSupplementalGlyphMapForCalibri` with some umlauts (issue 15594)
2022-10-19 18:35:10 +02:00
Jonas Jenwald
3c046c0a21 Extend getSupplementalGlyphMapForCalibri with some umlauts (issue 15594) 2022-10-19 17:49:40 +02:00
Jonas Jenwald
e00a040a80
Merge pull request #15593 from Snuffleupagus/issue-9105-other
Relax the /Pages dictionary /Count check for corrupt documents (issue 9105)
2022-10-19 16:26:14 +02:00
Calixte Denizet
535c624e0d [Editor] Make FreeText annotations visible for screen readers when in editing mode (bug 1793419)
- When we're editing some annotations, keeping the role="text-box" make them visible
as editable and VoiceOver (Mac) is able to read the contents when they're focused;
- Add an attribute "aria-activedescendant" in order to make the content discoverable
by NVDA on Windows.
2022-10-19 16:21:04 +02:00
calixteman
cc450b405d
Merge pull request #15592 from calixteman/1794403
[Annotation] Take the border into account when computing the font size (bug 1794403)
2022-10-19 12:33:11 +02:00
Jonas Jenwald
bc13a277ce Relax the /Pages dictionary /Count check for corrupt documents (issue 9105)
After PR 14311, and follow-up patches, we no longer require that the /Count entry (in the /Pages dictionary) is either present or even valid in order to parse/render a PDF document.
Hence it seems strange to keep this requirement for *corrupt* PDF documents, when trying to find a usable `trailer` in the `XRef.indexObjects` method.
2022-10-19 12:28:25 +02:00
Calixte Denizet
69b01d4398 [Annotation] Take the border into account when computing the font size (bug 1794403) 2022-10-19 10:27:27 +02:00
Jonas Jenwald
fd35cda8bc Re-factor the glyph-cache lookup in the Font._charToGlyph method
With the changes in the previous patch we can move the glyph-cache lookup to the top of the method and thus avoid a bunch of, in *almost* every case, completely unnecessary re-parsing for every `charCode`.
2022-10-19 09:55:09 +02:00
Jonas Jenwald
3e391aaed9 Remove the Glyph.matchesForCache method (PR 13494 follow-up)
This method, and its class, was originally added in PR 4453 to reduce memory usage when parsing text. Then PR 13494 extended the `Glyph`-representation slightly to also include the `charCode`, which made the `matchesForCache` method *effectively* redundant since most properties on a `Glyph`-instance indirectly depends on that one. The only exception is potentially `isSpace` in multi-byte strings.

Also, something that I noticed when testing this code: The `matchesForCache` method never worked correctly for `Glyph`s containing `accent`-data, since Objects are passed by reference in JavaScript. For affected fonts, of which there's only a handful of examples in our test-suite, we'd fail to find an already existing `Glyph` because of this.
2022-10-19 09:54:35 +02:00
Jonas Jenwald
782d098baf
Merge pull request #15589 from Snuffleupagus/issue-15577
Fallback and try a *previous* generation if all else fails in `XRef.indexObjects` (issue 15577)
2022-10-19 09:44:18 +02:00
Jonas Jenwald
de99f99a01 Fallback and try a *previous* generation if all else fails in XRef.indexObjects (issue 15577)
When we fail to find a usable PDF document `trailer` *and* there were errors during parsing, try and fallback to a *previous* generation as a last resort during fetching of uncompressed references.
*Please note:* This will not affect "normal" PDF documents, with valid /XRef data, and even most *corrupt* documents should be completely unaffected by these changes.
2022-10-18 20:24:01 +02:00
calixteman
9355b72931
Merge pull request #15583 from calixteman/15582
[Editor] Commit the current editor before setting the new viewport
2022-10-17 12:56:21 +02:00
Calixte Denizet
6fb694658e [Editor] Commit the current editor before setting the new viewport 2022-10-17 11:58:29 +02:00
Tim van der Meij
54c97d295f
Merge pull request #15580 from Snuffleupagus/update-packages
Update packages and translations
2022-10-16 13:25:40 +02:00
Tim van der Meij
8bf56078c5
Merge pull request #15579 from Snuffleupagus/sidebar-notification-position
Tweak the vertical position of the sidebar notification icon
2022-10-16 13:21:11 +02:00
Jonas Jenwald
db215fe289 Update l10n files 2022-10-16 09:39:00 +02:00
Jonas Jenwald
7bd484ebd3 Update npm packages 2022-10-16 09:38:58 +02:00
Jonas Jenwald
0983ebb257 Tweak the vertical position of the sidebar notification icon
Given that the new sidebar icon is slightly shorter than the old one, it cannot hurt to ever so slightly tweak the vertical position of the notification icon.

(While the patch also changes the CSS rule used for the horizontal position, this is a no-op and was done to improve consistency between the two values.)
2022-10-15 22:19:24 +02:00
calixteman
e0cf25d109
Merge pull request #15578 from calixteman/15571
[Editor] Ink editors must have their dimensions in percents after having been resized
2022-10-15 20:59:24 +02:00
Calixte Denizet
9e2bc8853f [Editor] Ink editors must have their dimensions in percents after having been resized 2022-10-15 19:59:10 +02:00
Tim van der Meij
06599f487f
Merge pull request #15576 from Snuffleupagus/version
Re-factor the PDF version parsing in the worker-thread
2022-10-15 13:03:43 +02:00
Tim van der Meij
2508792f29
Merge pull request #15572 from Snuffleupagus/simpleFontToUnicode-refactor
Slightly re-factor `PartialEvaluator._simpleFontToUnicode`
2022-10-15 12:31:27 +02:00
Jonas Jenwald
d470010293 Re-factor the PDF version parsing in the worker-thread
Part of this is very old code, and back when support for parsing the catalog-version was added things became less clear (in my opinion).
Hence this patch tries to improve things, by e.g. validating the header- and catalog-version separately.
2022-10-15 12:06:39 +02:00
Jonas Jenwald
951564d697
Merge pull request #15575 from Snuffleupagus/startCleanup-destroyed
Don't trigger worker-thread cleanup when destruction has already started
2022-10-14 17:08:25 +02:00
Jonas Jenwald
a576ea216f Don't trigger worker-thread cleanup when destruction has already started
Note how we're currently skipping all main-thread cleanup when document destruction has started, but for some reason we're still dispatching the "Cleanup" message.
This seems like a simple oversight, since destruction will already invoke the `BasePdfManager.cleanup` method (on the worker-thread) to fully clear-out all caches.
2022-10-14 16:43:49 +02:00
Jonas Jenwald
9f5fd075e7
Merge pull request #15574 from calixteman/bug1795263
Use all the current transform as key when caching some image for masks used with pattern fill (bug 1795263, #15573)
2022-10-14 15:12:52 +02:00
Calixte Denizet
556513a6e7 Use all the current transform as key when caching some image for masks used with pattern fill (bug 1795263, #15573) 2022-10-14 14:37:58 +02:00
Jonas Jenwald
15d4d80d45
Merge pull request #15563 from Snuffleupagus/issue-15559
Take the /CIDToGIDMap into account when getting the glyph mapping for CFF fonts (issue 15559)
2022-10-14 09:13:41 +02:00
Jonas Jenwald
d5036d7bfe
Merge pull request #15569 from Snuffleupagus/rm-worker-GetOperatorList-UnsupportedFeature
[api-minor] Stop sending "UnsupportedFeature" from the worker-thread GetOperatorList-handling
2022-10-14 09:12:10 +02:00
calixteman
09d077dc25
Merge pull request #15570 from calixteman/15568
[JS] Take into account all the required fields for some computations
2022-10-13 21:57:35 +02:00
Jonas Jenwald
fa47d4b9b1 Slightly re-factor PartialEvaluator._simpleFontToUnicode
Given the sheer number of heuristics added to this method over the years, moving the *valid* unicode found case to the top should improve readability of the code.
2022-10-13 21:42:57 +02:00
Calixte Denizet
e756bb69e4 [JS] Take into account all the required fields for some computations
- Fix Field::getArray in order to collect only the fields which have a value;
- Fix AFSimple_Calculate:
  * allow to have a string with a list of field names as argument;
  * since a field can be non-terminal, use Field::getArray to collect
    the field under it and then apply the calculation on all the descendants.
2022-10-13 18:33:12 +02:00
Jonas Jenwald
f2f0a1e871 [api-minor] Stop sending "UnsupportedFeature" from the worker-thread GetOperatorList-handling
This code was added all the way back in PR 6698, almost seven years ago, for backwards compatibility reasons. At this point in time, it seems that we can remove that since:
 - We have more fine-grained "UnsupportedFeature" reporting elsewhere in the worker-thread code nowadays.
 - The GetOperatorList-handling is now using `ReadableStream`s, which means that errors are being forwarded to the main-thread anyway.
 - We're also no longer displaying a notification-bar, in the *built-in* Firefox PDF Viewer, for any of these "UnsupportedFeature" messages.
2022-10-13 11:46:17 +02:00
Jonas Jenwald
858d941ff8 Take the /CIDToGIDMap into account when getting the glyph mapping for CFF fonts (issue 15559)
*Please note:* I don't really know what I'm doing here, however the patch appears to fix the referenced issue when comparing the rendering with Adobe Reader (with the caveat that I don't speak the language in question).
2022-10-13 10:02:25 +02:00
calixteman
c6cc7c6e6a
Merge pull request #15567 from calixteman/bug1794717
[Editor] Change the caret cursor into the arrow one only when a text editor isn't empty (bug 1794717)
2022-10-12 10:51:46 +02:00
Calixte Denizet
bc51571a00 [Editor] Change the caret cursor into the arrow one only when a text editor isn't empty (bug 1794717)
When a text editor is empty, clicking outside will create a new editor, hence it makes sense
to keep a caret cursor.
2022-10-12 10:05:34 +02:00
Jonas Jenwald
c42f58c235
Merge pull request #15565 from Snuffleupagus/issue-15564
[GENERIC viewer] Ensure that the we register the `editorTypes` for each `AnnotationEditorUIManager`-instance (issue 15564)
2022-10-12 09:26:14 +02:00
Jonas Jenwald
00c3bc3aab [GENERIC viewer] Ensure that the we register the editorTypes for each AnnotationEditorUIManager-instance (issue 15564)
When a new PDF document is opened in the GENERIC viewer we (obviously) create a new `AnnotationEditorUIManager`-instance, since those are document-specific, and thus we need to ensure that we actually register the `editorTypes` for each one.
2022-10-12 09:02:23 +02:00
Jonas Jenwald
21c2d0c7b0
Merge pull request #15562 from Snuffleupagus/checkHeader-prefix
Slightly re-factor the version fetching in `PDFDocument.checkHeader`
2022-10-11 15:27:41 +02:00
Jonas Jenwald
5bc6f964db Slightly re-factor the version fetching in PDFDocument.checkHeader
Note how after having found the "%PDF-" prefix we then read both the prefix and the version in the loop, only to then remove the prefix at the end.
It seems better to instead advance the stream position past the "%PDF-" prefix, and then read only the version data.

Finally the loop-condition can also be simplified slightly, to further clean-up some very old code.
2022-10-11 13:15:01 +02:00
calixteman
348665934e
Merge pull request #15558 from Snuffleupagus/issue-15557
Ensure that `Page.getOperatorList` handles Annotation parsing errors correctly (issue 15557, bug 1794351)
2022-10-10 11:29:33 +02:00
Jonas Jenwald
081e897588 Ensure that Page.getOperatorList handles Annotation parsing errors correctly (issue 15557)
*Fixes a regression from PR 15246, sorry about that!*

The return value of all `Annotation.getOperatorList` methods was changed in PR 15246, however I missed updating the error code-path in `Page.getOperatorList` which thus breaks all operatorList-parsing for pages with corrupt Annotations.
2022-10-10 09:48:01 +02:00
Tim van der Meij
dff444d441
Merge pull request #15555 from Snuffleupagus/improve-GetDocRequest
Clean-up the data that we're sending with "GetDocRequest"
2022-10-09 14:10:44 +02:00
Tim van der Meij
bf6e287572
Merge pull request #15552 from Snuffleupagus/simplify-dropdownToolbarButton
Simplify the `dropdownToolbarButton`-select width computation
2022-10-09 13:37:15 +02:00
Tim van der Meij
229d21b50d
Merge pull request #15553 from Snuffleupagus/rm-CMapCompressionType-STREAM
Remove the unused `CMapCompressionType.STREAM` value
2022-10-09 13:33:54 +02:00
Jonas Jenwald
8a4f6aca97 Stop using the source-object when sending "GetDocRequest"
Looking at the code on the worker-thread, there doesn't appear to be any particular reason for placing *some* of the properties in a `source`-object when sending them with "GetDocRequest".
As is often the case the explanation for this structure is rather "for historical reasons", since originally we simply sent the `source`-object as-is. Doing that was obviously a bad idea, for a couple of reasons:
 - It makes it less clear what is/isn't actually needed on the worker-thread.
 - Sending unused properties will unnecessarily increase memory usage.
 - The `source`-object may contain unclonable data, which would break the library.
2022-10-09 12:45:24 +02:00
Jonas Jenwald
c84b717773 Group the evaluatorOptions on the main-thread, when sending "GetDocRequest"
Rather than sending all of these parameters individually and then grouping them together on the worker-thread, we can simply handle that in the API instead.
2022-10-09 12:31:03 +02:00
Jonas Jenwald
447915af9d Stop sending the unused source.url property in "GetDocRequest"
It seems that this property became *effectively* unused already in PR 8617, however we missed removing it as part of the clean-up in PR 10376.
2022-10-09 12:30:46 +02:00
Jonas Jenwald
30f968fd7f
Merge pull request #15554 from Snuffleupagus/rm-deprecated-constants
[api-major] Remove some deprecated constants
2022-10-09 09:16:11 +02:00
Jonas Jenwald
484e81ef6e [api-major] Remove some deprecated constants
All of the these constants have been deprecated for a while, and with the upcoming *major* version this seems like a good time to remove them.
For the string-constants we can simply remove them, but the number-constants are left commented out since we don't want to re-number the list to prevent third-party breakage.
2022-10-08 18:13:53 +02:00
Jonas Jenwald
4cc98de6d7 Remove the unused CMapCompressionType.STREAM value
This was added in PR 8064, over five years ago, for a possible future CMap file-format that was never implemented.
2022-10-08 17:10:05 +02:00
Jonas Jenwald
4f5f362d60 Remove unnecessary size attribute from the pageNumber-input
This attribute is overridden by the explicit `width` that's specified in the CSS rules, hence we can remove one more small piece of very old code; see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#size
2022-10-08 12:34:13 +02:00
Jonas Jenwald
450be1ad3e Simplify the dropdownToolbarButton-select width computation
The way that we set the width of the `dropdownToolbarButton`-select is very old, and despite some improvements over the years this is still somewhat hacky.
In particular, note how we're assigning the select-element a larger width than its containing `dropdownToolbarButton`-element. This was done to prevent displaying *two* separate icons, i.e. the native and the PDF.js one, since it's the only way to handle this in older browsers (particularly Internet Explorer).

Given the currently supported browsers, there's however a better solution available: use `appearance: none;` to disable native styling of the select-element. [According to MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/appearance#browser_compatibility), this is supported in all reasonably modern browsers.
This way we're able to simplify both the CSS rules and the JS-code that's used to adjust the `dropdownToolbarButton` width in a localization aware way.
2022-10-07 18:19:10 +02:00
calixteman
3dc9b427b9
Merge pull request #15549 from calixteman/padding_inline
[XFA] Add some padding inline in selects
2022-10-07 03:49:14 -10:00
calixteman
b27753aa3d
Merge pull request #15548 from calixteman/simplify_remainder
Simplify the way to compute the remainder modulo 3 in PDF20Hash function
2022-10-07 03:48:41 -10:00
Calixte Denizet
24757e32d1 [XFA] Add some padding inline in selects
Because of https://bugzilla.mozilla.org/show_bug.cgi?id=1582545, the padding-inline is by default 0.
0 is not really enough because of the outline, so just set it to 2px (it was 4px before the patch)
in order to have something visually correct.
2022-10-07 15:11:58 +02:00
Jonas Jenwald
9931295bea
Merge pull request #15547 from Snuffleupagus/rm-Util-apply3dTransform
Remove the unused `Util.apply3dTransform` method
2022-10-07 15:03:19 +02:00
Calixte Denizet
c0e165bf97 Simplify the way to compute the remainder modulo 3 in PDF20Hash function
I noticed the 256 % 3 (which is equal to 1) so I slighty simplify the code.
The sum of the 16 Uint8 doesn't exceed 2^12, hence we can just take the
sum modulo 3.
2022-10-07 14:43:31 +02:00
Jonas Jenwald
4b39b1c76b Remove the unused Util.apply3dTransform method
This method was originally added in PR 1157 (back in 2012), however its only call-site was then removed in PR 2423 (also in 2012).
Hence this method has been completely unused for nearly a decade, and it should thus be safe to remove it.
2022-10-07 13:55:36 +02:00
Jonas Jenwald
8629a55215
Merge pull request #15538 from Snuffleupagus/viewer-error-logging
Stop localizing error *details* in the viewer (PR 15533 follow-up)
2022-10-07 11:16:22 +02:00
Jonas Jenwald
3cb119cb32
Merge pull request #15539 from Snuffleupagus/DecryptStream-set
Replace loop with `TypedArray.prototype.set` in the `DecryptStream.readBlock` method
2022-10-07 11:14:28 +02:00
Jonas Jenwald
a5a6b9f641
Merge pull request #15542 from Snuffleupagus/issue-14952
[api-minor] Make `isOffscreenCanvasSupported` configurable via the API (issue 14952)
2022-10-07 10:05:03 +02:00
Jonas Jenwald
1ea4c4b519 [api-minor] Make isOffscreenCanvasSupported configurable via the API (issue 14952)
This patch first of all makes `isOffscreenCanvasSupported` configurable, defaulting to `true` in browsers and `false` in Node.js environments, with a new `getDocument` parameter. While you normally want to use this, in order to improve performance, it should still be possible for users to control it (similar to e.g. `isEvalSupported`).

The specific problem, as reported in issue 14952, is that the SVG back-end doesn't support the new ImageMask data-format that's introduced in PR 14754. In particular:
 - When the SVG back-end is used in Node.js environments, this patch will "just work" without the user needing to make any code changes.
 - If the SVG back-end is used in browsers, this patch will require that `isOffscreenCanvasSupported: false` is added to the `getDocument`-call.
2022-10-07 00:10:46 +02:00
Jonas Jenwald
6877d8b9e2 Replace loop with TypedArray.prototype.set in the DecryptStream.readBlock method
There's no reason to use a manual loop, when a native method exists.
2022-10-06 14:43:24 +02:00
Jonas Jenwald
2f238a11c1 Stop localizing error *details* in the viewer (PR 15533 follow-up)
While it can't hurt to localize the main error-messages, also localizing the error *details* has always seemed somewhat unnecessary since those are only intended for debugging/development purposes. However, I can understand why that's done since the GENERIC viewer used to expose this information in the UI; via the `errorWrapper` UI that's removed in PR 15533.

At this point, when any errors are simply logged in the console, it no longer seems necessary to keep localizing the error *details* in the default viewer.
2022-10-06 13:09:39 +02:00
Jonas Jenwald
6bd5ef29ae Log the build number, in addition to the version, in the viewer
Given that the `build` number allows you to *directly* find the relevant commit, it cannot hurt to log that one as well.
2022-10-06 12:03:22 +02:00
Jonas Jenwald
7d5f7a517c
Merge pull request #15537 from Snuffleupagus/issue-8844
[api-minor] Add partial support for the "GoToE" action (issue 8844)
2022-10-06 11:34:52 +02:00
Jonas Jenwald
ce66fefbff [api-minor] Add partial support for the "GoToE" action (issue 8844)
*Please note:* The referenced issue is the only mention that I can find, in either GitHub or Bugzilla, of "GoToE" actions.
Hence why I've purposely settled for a very simple, and partial, "GoToE" implementation to avoid complicating things initially.[1] In particular, this patch only supports "GoToE" actions that references the /EmbeddedFiles-dict in the PDF document.

See https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2048909

---
[1] Usually I always prefer having *real-world* test-cases to work with, whenever I'm implementing new features.
2022-10-06 10:33:07 +02:00
Jonas Jenwald
8c59cc72a3
Merge pull request #15536 from Snuffleupagus/more-for-of-2
Use more `for...of` loops in the code-base
2022-10-05 11:32:19 +02:00
Jonas Jenwald
60f6272ed9 Use more for...of loops in the code-base
Most, if not all, of this code is old enough to predate the general availability of `for...of` iteration.
2022-10-03 13:08:38 +02:00
Tim van der Meij
4e58dabb32
Merge pull request #15534 from Snuffleupagus/FontLoader-cleanup-3
[api-minor] Stop setting an `id` on the styleElement used with CSS font-loading
2022-10-02 14:22:51 +02:00
Jonas Jenwald
fe5d9b4b6a Remove duplicated destroy-calls in the "custom ownerDocument" unit-tests
Given that `PDFDocumentProxy.destroy` is nothing but an alias for `PDFDocumentLoadingTask.destroy` calling both methods is obviously not useful.
2022-10-02 12:01:41 +02:00
Jonas Jenwald
8e4ef6d89d [api-minor] Stop setting an id on the styleElement used with CSS font-loading
This is yet another small piece of clean-up of the `FontLoader`-code, since we've not used this `id`-property for anything ever since PR 6571 (which landed almost seven years ago). Furthermore, by default we're also not even using that code-path now since the Font Loading API will always be used when available.

*Please note:* This is tagged `[api-minor]` since it's technically observable from the outside, however no user ought to be directly interacting with these CSS font rules.
2022-10-02 12:01:33 +02:00
Tim van der Meij
beff913813
Merge pull request #15533 from Snuffleupagus/rm-errorWrapper
[GENERIC viewer] Remove the `errorWrapper` UI
2022-10-01 19:07:28 +02:00
Tim van der Meij
284634f30d
Merge pull request #15508 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2022-10-01 19:03:51 +02:00
Tim van der Meij
606fb8c394
Fix intermittent errors in the "check that first text field has focus" scripting test
This commit fixes the "Expected null to equal '401R'" errors that
surfaced after the Puppeteer 18 upgrade. Note that even before that
this would have been an improvement because it takes some time between
scripting being reported ready (i.e., triggering the execution of any
OpenActions) and those OpenActions actually completing execution, so
it's only safe to check which element is focused if we know an element
actually became focused.
2022-10-01 18:08:15 +02:00
Tim van der Meij
9525bfaa66
Update translations to the most recent versions 2022-10-01 18:07:44 +02:00
Tim van der Meij
b0725e75c6
Update dependencies to the most recent versions 2022-10-01 18:04:29 +02:00
Jonas Jenwald
62c1a4e8c8 [Firefox viewer] Skip unused printing-string in DEFAULT_L10N_STRINGS
Given that the Firefox PDF Viewer uses the *browser* print UI, this fallback l10n-string isn't necessary in the MOZCENTRAL build.
2022-10-01 17:35:43 +02:00
Jonas Jenwald
75e06fddf1 [GENERIC viewer] Remove the errorWrapper UI
In the Firefox PDF Viewer this has never been used, with the error message simply printed in the web-console, and (somewhat) recently we've also updated the viewer code to avoid bundling the relevant code there. Furthermore, in the Firefox PDF Viewer we're not even display the *browser* fallback bar any more; see https://bugzilla.mozilla.org/show_bug.cgi?id=1705327.

Hence it seems slightly strange to keep this UI around in the GENERIC viewer, and this patch proposes that we simply remove it to simplify/unify the relevant code in the viewer. In particular this also allows us to remove a couple of l10n-strings, which have always been unused in the Firefox PDF Viewer.
2022-10-01 17:35:35 +02:00
Jonas Jenwald
a93c01ae6a
Merge pull request #15510 from Snuffleupagus/compatibility-loading
Change how `src/shared/compatibility.js` is imported
2022-10-01 13:47:44 +02:00
Jonas Jenwald
3e625994bd Change how src/shared/compatibility.js is imported
Currently the compatibility-file is loaded using a standard `import`-statement and while its code is enclosed in a pre-processor block, and thus is excluded in e.g. the MOZCENTRAL build-target, it still results in the *built* `pdf.js`/`pdf.worker.js` files having an effectively empty closure as a result.
By moving the checks from `src/shared/compatibility.js` and into `src/shared/util.js` instead, we can load the file using a build-time `require`-statement and thus avoid that closure.

Note that with these changes the compatibility-file will no longer be loaded in development mode, i.e. when `gulp server` is used. However, this shouldn't be a big issue given that none of its included polyfills could be loaded then anyway (since `require`-statements are being used) and that it's really only intended for the `legacy`-builds of the library.
2022-10-01 13:29:54 +02:00
Tim van der Meij
2c38a14a14
Merge pull request #15530 from Snuffleupagus/sidebar-toggleButton-l10n
Re-factor the `toggleButton` l10n in the `PDFSidebar` class
2022-10-01 13:10:32 +02:00
Tim van der Meij
0cca2d4f6e
Merge pull request #15511 from Snuffleupagus/FontLoader-cleanup-2
More `FontLoader` clean-up
2022-10-01 13:04:29 +02:00
Tim van der Meij
29a784c240
Merge pull request #15514 from Snuffleupagus/DOMMatrix-polyfill
Replace the `DOMMatrix` polyfill, used with Node.js, with the one from `node-canvas`
2022-10-01 12:56:57 +02:00
Jonas Jenwald
7b24931f67
Merge pull request #15517 from Snuffleupagus/issue-15516
Add more non-standard ligatures in the `glyphlist.js` file (issue 15516)
2022-09-30 23:30:50 +02:00
Jonas Jenwald
1ee096d229
Merge pull request #15515 from mozilla/revert-15418-pr-15319-followup
Revert "Don't listen for window resolution changes in old browsers (PR 15319 follow-up)"
2022-09-30 10:15:05 +02:00
Jonas Jenwald
bad00f825a Re-factor the toggleButton l10n in the PDFSidebar class
Rather than "manually" looking up the l10n-string and then updating the button, we can (and probably even should) just update the l10n-id and then trigger proper translation for the button DOM-element.
2022-09-30 09:59:58 +02:00
Jonas Jenwald
0011a747f7
Merge pull request #15527 from calixteman/15523
[JS] Add the function AFExactMatch
2022-09-30 09:32:16 +02:00
Calixte Denizet
330048ad6b [JS] Add the function AFExactMatch 2022-09-29 14:23:56 -10:00
Jonas Jenwald
294db228bc
Merge pull request #15522 from Snuffleupagus/editor-disable-cursor-tools
[Editing] Disable the HandTool during editing (bug 1792422)
2022-09-29 11:09:44 +02:00
Jonas Jenwald
205ab95819 [Editing] Disable the HandTool during editing (bug 1792422)
This extends the approach used in PresentationMode to also cover the AnnotationEditor, and tries to handle the combination of both cases correctly.
In order to simplify the overall implementation we simply track the *first* seen "previous" cursorTool, and don't allow it to be reset as long as either PresentationMode or an AnnotationEditor is being used.
2022-09-29 10:44:06 +02:00
Jonas Jenwald
c87f90102c Add more non-standard ligatures in the glyphlist.js file (issue 15516)
Note that this PR only adds the "underscore"-variant of *actually existing* ligatures, however the referenced PDF document also uses a couple of non-standard ones (e.g. `ft`, `Th`, and `fh`) that we cannot easily support without larger changes (since they don't have official Unicode-entries).
Given that it's clearly the PDF document, and its fonts, that's the culprit here it's not entirely clear to me that we actually want to attempt a larger refactoring/rewriting of the `glyphlist.js` code, assuming it's even generally possible. Especially when this patch alone already improves our copy-paste behaviour when compared to both Adobe Reader and PDFium, and that this is only the *second* time this sort of bug has been reported.
2022-09-27 16:31:51 +02:00
Jonas Jenwald
4c7a03c4cb
Revert "Don't listen for window resolution changes in old browsers (PR 15319 follow-up)" 2022-09-27 12:27:27 +02:00
Jonas Jenwald
c894be92fb Replace the DOMMatrix polyfill, used with Node.js, with the one from node-canvas
Fewer dependencies shouldn't be a bad idea in general, and given that the `node-canvas` package already include a `DOMMatrix` polyfill we can simply use that one instead.
2022-09-27 12:12:50 +02:00
Jonas Jenwald
5675a6ee64
Merge pull request #15512 from Snuffleupagus/issue-15509
[JS] Override the `Doc.external`-getter to avoid `alert`-modals on load (issue 15509)
2022-09-26 21:59:58 +02:00
Jonas Jenwald
9769b3b71a [JS] Override the Doc.external-getter to avoid alert-modals on load (issue 15509)
This property is documented in https://web.archive.org/web/20201112021418if_/https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_api_reference.pdf#G5.1977075

Given that PR 14207, which is *somewhat* similar, landed without tests that's hopefully fine here as well.
2022-09-26 20:55:26 +02:00
Jonas Jenwald
9ce2427e79 [Firefox viewer] Skip some unnecessary code in the FontLoader.bind method
Given that Firefox supports *synchronous* font loading, when the Font Loading API isn't being used, there's really no point including code which if called would just throw in the MOZCENTRAL build. (This is safe, since the `FontLoader.isSyncFontLoadingSupported`-getter always return `true` there.)
2022-09-26 15:18:22 +02:00
Jonas Jenwald
2161f334a0 Remove the ability to pass in more than one font to the _prepareFontLoadEvent method (PR 10539 follow-up)
After the changes in PR 10539 (which landed over three years ago) the `FontLoader.bind` method can only be called with *a single* font at a time, hence the `_prepareFontLoadEvent` method obviously don't need to support multiple fonts any more.
2022-09-26 13:33:52 +02:00
Jonas Jenwald
ca05b650aa Remove the unused rules parameter from the _prepareFontLoadEvent method (PR 3477 follow-up)
This is yet another small piece of functionality that became unused in PR 3477 (which landed nine years ago).
2022-09-26 13:26:14 +02:00
calixteman
da1780f826
Merge pull request #15486 from nmtigor/fix_orders_of_prop
Fix property chain orders of Operators in isDotExpression
2022-09-25 04:13:25 -10:00
Tim van der Meij
dab81f5981
Merge pull request #15507 from Snuffleupagus/FontLoader-cleanup
Improve the `FontLoader` code
2022-09-25 13:31:33 +02:00
Jonas Jenwald
ad83fbe2a1 Replace the BaseFontLoader classes with one FontLoader class
By having just *one* class, and using pre-processor blocks directly in the relevant methods, we reduce the size of this code in the *built* `pdf.js` file.
Originally, when the `BaseFontLoader` abstraction was added in PR 9982, the idea was probably that additional build-targets would get their own implementations. Given that this hasn't happened in the four years since that landed, it doesn't seem meaningful to keep it around.
2022-09-25 12:31:58 +02:00
Jonas Jenwald
9a03d36af4 Remove some unused code from the _queueLoadingCallback method (PR 3477 follow-up)
The existing `loadingContext` class-property can be simplified slightly, since we've not been using the `id`-property on the requests ever since PR 3477 (which landed nine years ago).
Furthermore, by default we're also not even using that code-path now since the Font Loading API will always be used when available.
2022-09-25 10:41:06 +02:00
Tim van der Meij
5f65df774f
Merge pull request #15504 from Snuffleupagus/rm-stopImmediatePropagation-checks
Use `stopImmediatePropagation` without checking for its existence first
2022-09-24 15:15:04 +02:00
Jonas Jenwald
b420f0165a Use stopImmediatePropagation without checking for its existence first
These checks were added years ago, but given the following compatibility data we should just be able to call the method directly: https://developer.mozilla.org/en-US/docs/Web/API/Event/stopImmediatePropagation#browser_compatibility
2022-09-24 15:02:12 +02:00
Tim van der Meij
907ef467ea
Merge pull request #15503 from Snuffleupagus/consistent-outline
Use a consistent `outline` for all UI buttons (PR 15438 follow-up)
2022-09-24 14:48:21 +02:00
Tim van der Meij
27a1ab52b1
Merge pull request #15501 from Snuffleupagus/errorWrapper-font
Restore the old fonts in the `errorWrapper` (PR 15438 follow-up)
2022-09-24 14:46:54 +02:00
Tim van der Meij
4cedbca365
Merge pull request #15500 from Snuffleupagus/LoopbackPort-rm-export
[api-minor] Stop exposing the `LoopbackPort` class in the API
2022-09-24 14:45:59 +02:00
Tim van der Meij
369f23ff3d
Merge pull request #15499 from Snuffleupagus/support-docs
Reference supported browsers Wiki-page in more README files
2022-09-24 14:43:45 +02:00
Tim van der Meij
10f6a0154f
Merge pull request #15485 from Snuffleupagus/more-optional-chaining-2
Use more optional chaining in the code-base (PR 15398 follow-up)
2022-09-24 14:41:43 +02:00
Jonas Jenwald
5296fc991c Restore the old fonts in the errorWrapper (PR 15438 follow-up)
This only applies to the GENERIC viewer, hence we use the pre-processor to exclude it from the Firefox PDF Viewer.
2022-09-24 13:54:34 +02:00
Jonas Jenwald
616535b7a7 Use a consistent outline for all UI buttons (PR 15438 follow-up)
Currently the `viewBookmark`-button, which is actually a `href`-element, gets an inconsistent `outline`.
Similarly, the `dialog`-buttons also have an inconsistent `outline` after the changes in PR 15438.

Finally, simplifies a couple of `border` rules since setting a border-width when "none" is being used doesn't seem meaningful.
2022-09-24 13:42:27 +02:00
Jonas Jenwald
cf038d0368 [api-minor] Stop exposing the LoopbackPort class in the API
This was done all the way back in PR 8361, for a mozilla-central test that's since been removed. As can be seen in the following search results, there's no `LoopbackPort` invocation outside of the PDF.js code itself: https://searchfox.org/mozilla-central/search?q=LoopbackPort&path=

Given that the `LoopbackPort` is only used in connection with "fake workers", which is something that we don't officially recommend/support, this doesn't seem like functionality that we want to keep exposing in the public API.
2022-09-23 13:44:35 +02:00
Jonas Jenwald
499610779e Re-factor the LoopbackPort class to use *proper* private fields 2022-09-23 13:25:15 +02:00
Jonas Jenwald
c1c78f9e8c Reference supported browsers Wiki-page in more README files
I've just updated https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support to hopefully provide better support data, and it cannot hurt to explicitly link that from a couple of places.
2022-09-23 11:06:47 +02:00
Jonas Jenwald
7404091787
Merge pull request #15498 from Snuffleupagus/more-spread
Replace some `Array.prototype`-usage with spread syntax
2022-09-23 10:23:14 +02:00
Jonas Jenwald
6538409282 Replace some Array.prototype-usage with spread syntax
We have a few, quite old, call-sites that use the `Array.prototype`-format and which can now be replaced with spread syntax instead.
2022-09-23 09:35:30 +02:00
Jonas Jenwald
91bdcd8b20
Merge pull request #15495 from mozilla/revert-15459-1774427
Revert "Don't use window.print in the Firefox builtin viewer (bug 1774427)"
2022-09-22 17:07:21 +02:00
calixteman
034017d526
Merge pull request #15494 from Snuffleupagus/issue-15492
Tweak the heuristic that handles JPEG images with a wildly incorrect SOF (Start of Frame) `scanLines` parameter (issue 15492)
2022-09-22 17:05:49 +02:00
calixteman
9ded9dd4e5
Revert "Don't use window.print in the Firefox builtin viewer (bug 1774427)" 2022-09-22 16:58:49 +02:00
calixteman
9bdcdeef67
Merge pull request #15493 from calixteman/15490
[JS] Try to guess what the date is when it doesn't follow the given format (issue #15490)
2022-09-22 16:54:33 +02:00
Calixte Denizet
9e40938a29 [JS] Try to guess what the date is when it doesn't follow the given format (issue #15490)
We use the format to guess in which order we can find month, day, ... we get the numbers
in the date and consider them as month, day, ...
2022-09-22 16:30:39 +02:00
Jonas Jenwald
f1b0dc6f04 Tweak the heuristic that handles JPEG images with a wildly incorrect SOF (Start of Frame) scanLines parameter (issue 15492) 2022-09-22 14:09:04 +02:00
Jonas Jenwald
784ec3978a
Merge pull request #15491 from Snuffleupagus/annotationLayer-input-hover-border
Set a `border-radius` when hovering annotationLayer-inputs (PR 15438 follow-up)
2022-09-22 10:26:56 +02:00
Jonas Jenwald
1558c0e85e Set a border-radius when hovering annotationLayer-inputs (PR 15438 follow-up)
The changes in PR 15438 added a `border-radius` when input-elements are focused, however there's no radius when the same elements are hovered. Having the radius change, and not just the `border-color`, when input goes from hovered to focused feels a bit inconsistent (at least to me).
2022-09-22 10:01:24 +02:00
Jonas Jenwald
547fa3ed2c
Merge pull request #15489 from Snuffleupagus/debugger-fonts
Restore the old fonts in the debugger (PR 15438 follow-up)
2022-09-21 22:39:53 +02:00
Jonas Jenwald
2a1d536ec6 Restore the old fonts in the debugger (PR 15438 follow-up)
The changes in PR 15438 affected the debugger as well, which means that some of the panels/buttons look (in my opinion) a bit less nice than before.
2022-09-21 21:49:17 +02:00
nmtigor
22cc9b7dc7 Fix property chain orders of Operators in isDotExpression and isSomPredicate 2022-09-21 17:20:23 +02:00
Jonas Jenwald
9f637966f8 Use more optional chaining in the code-base (PR 15398 follow-up)
*Fixes a few cases that I missed in PR 15398.*
2022-09-21 16:47:36 +02:00
Jonas Jenwald
2146d93609
Merge pull request #15483 from Snuffleupagus/rm-app-duplicate-document
[JS] Remove duplicate `this._document` assignment in the `App`-class
2022-09-21 12:13:21 +02:00
nmtigor
01ec5e3b32 [JS] Remove duplicate this._document assignment in the App-class
This property is already being assigned earlier in the constructor, see ea1d359767/src/scripting_api/app.js (L42)
2022-09-21 11:40:28 +02:00
Jonas Jenwald
ea1d359767
Merge pull request #15478 from calixteman/1791583
Initialize values in the path bounding box before flushing the operator list (bug 1791583)
2022-09-20 21:12:10 +02:00
Calixte Denizet
198e9a3db1 Initialize values in the path bounding box before flushing the operator list (bug 1791583)
OperatorList.addOp can trigger a flush if it's required, hence the values passed to it must
be correctly initialized in order to avoid some wrong values in the renderer.
Because of that a clip path was considered as empty, nothing was clipped, hence the wrong
rendering in bug 1791583.
2022-09-20 20:01:54 +02:00
Jonas Jenwald
ff8f850936
Merge pull request #15477 from Snuffleupagus/sandbox-destroy-timeout
Access the `setTimeout`-functionRefs correctly in `SandboxSupportBase.destroy`
2022-09-20 15:34:05 +02:00
Jonas Jenwald
fdb7b086bd
Merge pull request #15476 from calixteman/fix_formcalc_lexer
[XFA] Fix an hidden issue in the FormCalc lexer
2022-09-20 14:32:30 +02:00
calixteman
cd7ce6a295
Merge pull request #15468 from calixteman/1791515
[Editor] Make sure to have the annotation editor layer on top of the annotation one (bug 1791515)
2022-09-20 14:17:56 +02:00
Jonas Jenwald
fde1e4996d Access the setTimeout-functionRefs correctly in SandboxSupportBase.destroy
*This effectively replaces PR 15465.*

As outlined in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach, the argument order when iterating through a `Map` is actually `value, key`.
Ignoring the incorrect Array used in the old code, I cannot imagine that this would've worked anyway since we didn't use the actual `setTimeout`-functionRefs to clear the timeouts; please refer to the `setTimeout`/`setInterval` methods in the `SandboxSupportBase.createSandboxExternals` method.
2022-09-20 14:10:44 +02:00
Calixte Denizet
f5b835157b [XFA] Fix an hidden issue in the FormCalc lexer
Since there are no script engine with XFA, the FormCalc parser is not used irl.
The bug @nmtigor noticed was hidden by another one (the wrong check on `match`).
2022-09-20 13:53:55 +02:00
Jonas Jenwald
8dd2b48488
Merge pull request #15474 from nmtigor/fix_bugs_10
Fix #selectEditors typo in the AnnotationEditorUIManager.unselectAll method
2022-09-20 13:15:26 +02:00
Jonas Jenwald
09b54a8c9e
Merge pull request #15473 from nmtigor/fix_bugs_9
Fix commFunc typo in the SandboxSupportBase.destroy method
2022-09-20 12:15:59 +02:00
nmtigor
4348ffee8d Fix #selectEditors typo in the AnnotationEditorUIManager.unselectAll method 2022-09-20 11:55:42 +02:00
nmtigor
d7103a4439 Fix commFunc typo in the SandboxSupportBase.destroy method 2022-09-20 11:39:13 +02:00
Calixte Denizet
3b536f2701 [Editor] Make sure to have the annotation editor layer on top of the annotation one (bug 1791515)
Some z-index have been added in the annotation layer because the elements inside are re-ordered
in order to improve accessibility.
Hence we must add a "high" z-index on the annotation editor layer in order to avoid any bad
interaction between the different layers.
2022-09-20 10:58:35 +02:00
calixteman
e5fc7cf4bd
Merge pull request #15461 from calixteman/1790309
Use AccentColor as background for selected text in the text layer (bug 1790309)
2022-09-19 22:36:37 +02:00
calixteman
5b4a44dbab
Merge pull request #15462 from calixteman/update_xfa
[XFA] - Avoid an exception when zooming on a XFA
2022-09-19 22:22:16 +02:00
Calixte Denizet
403aa5cfa0 [XFA] - Avoid an exception when zooming on a XFA 2022-09-19 21:31:52 +02:00
Calixte Denizet
68977ebc26 Use AccentColor as background for selected text in the text layer (bug 1790309)
and use the default color for the viewer in general.
2022-09-19 21:25:56 +02:00
Jonas Jenwald
d262ca314d
Merge pull request #15460 from Snuffleupagus/prefer-regexp-test
Enable the `unicorn/prefer-regexp-test` ESLint plugin rule
2022-09-19 17:32:21 +02:00
Jonas Jenwald
20b9887476 Enable the unicorn/prefer-regexp-test ESLint plugin rule
Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-regexp-test.md
2022-09-19 16:34:01 +02:00
calixteman
bf78ccac30
Merge pull request #15459 from calixteman/1774427
Don't use window.print in the Firefox builtin viewer (bug 1774427)
2022-09-19 15:07:10 +02:00
Calixte Denizet
620f1ef1a9 Don't use window.print in the Firefox builtin viewer (bug 1774427)
Currently, it's impossible to print a pdf in a sandboxed iframe in using window.print.
2022-09-19 14:22:40 +02:00
Jonas Jenwald
2642573702
Merge pull request #15458 from Snuffleupagus/rm-some-search
Replace some unnecessary `String.prototype.search` usage
2022-09-19 14:14:41 +02:00
Jonas Jenwald
bb75b36b77 Replace some unnecessary String.prototype.search usage
Most of the `String.prototype.search` call-sites found throughout the code-base is actually not necessary, since we usually only want a *boolean*, and those can be replaced with `RegExp.prototype.test` instead.
2022-09-19 12:51:46 +02:00
calixteman
dc6c3eacbc
Merge pull request #15438 from calixteman/1726183
Improve CSS for HCM (bug 1726183)
2022-09-18 16:04:56 +02:00
Calixte Denizet
07cd7cb3dc Improve CSS for HCM (bug 1726183)
The default outline for a focused text input is not that bad but for any reason when changing
the background color, all the good default border/outline properties are lost (it's the same
behaviour in Edge).
So in order have something consistent in HCM/non-HCM, a 2px-border+1px-outline (on @MReschenberg
advices) is added when an input is focused with different colors depending on HCM.
While working on the above issue, I noticed few bugs I fixed when in HCM:
 - input, button and select have some default properties which have been created at a time where
   annotation layer didn't exist, hence this patch remove them and set those properties where
   they should live;
 - some elements (like the main toolbar) is using a box-shadow which is invisible in HCM, hence
   it's replaced by a border-bottom in HCM;
 - some separators are invisible in HCM, hence use GrayText color to render them correctly;
 - the options for the zoom selection were invisible in HCM with Desert (one of the Windows 11
   themes).
2022-09-18 16:03:24 +02:00
Tim van der Meij
67160f4cae
Merge pull request #15455 from Snuffleupagus/issue-15453
Don't update the Scroll/Spread-mode in the ViewHistory while PresentationMode is active (issue 15453)
2022-09-18 14:35:00 +02:00
Tim van der Meij
f7ab417757
Merge pull request #15432 from Snuffleupagus/validateFileURL-var
Some *small* viewer clean-up for non-GENERIC builds
2022-09-18 14:32:13 +02:00
Tim van der Meij
d78619cd66
Merge pull request #15452 from Snuffleupagus/chrome-extension
Temporarily stop listing the official Chrome extension in the main README
2022-09-18 14:29:46 +02:00
Tim van der Meij
f91cc3dd5d
Merge pull request #15451 from Snuffleupagus/major-support
[api-major] Update the minimum supported browsers/environments
2022-09-18 14:28:31 +02:00
Tim van der Meij
965713f3e7
Merge pull request #15446 from Snuffleupagus/rm-component-examples-enableScripting
Remove the `enableScripting`-parameter from the component examples (PR 13816 follow-up)
2022-09-18 14:24:27 +02:00
Tim van der Meij
58e30a7048
Merge pull request #15454 from Snuffleupagus/update-packages
Update packages and translations
2022-09-18 14:23:43 +02:00
Jonas Jenwald
2c02a2fc5c Don't update the Scroll/Spread-mode in the ViewHistory while PresentationMode is active (issue 15453)
By force-quitting the browser while the FullScreen API is active, we don't get a chance to exit PresentationMode *cleanly* and some of its state thus remains (via the `ViewHistory`).
To try and improve things here we can skip updating the Scroll/Spread-mode while PresentationMode is active, since they will be changed when entering PresentationMode, which seems to help and is really the best that we can do here (and what the issue describes is very much an edge-case anyway).
2022-09-18 11:42:01 +02:00
Jonas Jenwald
1a04a38a06 Update l10n files 2022-09-18 10:34:53 +02:00
Jonas Jenwald
6a9e584215 Update npm packages 2022-09-18 10:31:32 +02:00
Jonas Jenwald
b7f987a185 [api-major] Update the minimum supported browsers/environments
In the `legacy`-builds we (obviously) support the currently maintained Firefox ESR version, and looking at the [release history](https://wiki.mozilla.org/Release_Management/Calendar) those are officially supported (by Mozilla) for about 1-1.5 years.
However, for non-Firefox browsers the `legacy`-builds currently attempt to "support" browsers that are approximately *three* years old.[1] Historically, in the PDF.js project, trying to support old browsers have caused some maintenance problems and even delayed adoption of new web-platform features/functionality.

To lessen the support burden, given that the primary purpose of the PDF.js library is still to develop the *built-in* Firefox PDF Viewer, this patch proposes that the upcoming *major* release changes the minimum supported browsers/environments as follows:
 - Chrome 85, which was released on 2020-08-25; see https://en.wikipedia.org/wiki/Google_Chrome_version_history
 - Firefox ESR (as before); see https://wiki.mozilla.org/Release_Management/Calendar
 - Safari 14, which was released on 2020-09-16; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_14
 - Node.js 14 (as before), which is now explicitly listed to prevent it from accidentally breaking; see https://en.wikipedia.org/wiki/Node.js#Releases

---
[1] In older browsers some functionality may not be available and generally we'll ask users to update to a modern browser when bugs, specific to old browsers, are being reported.
2022-09-18 01:12:15 +02:00
Jonas Jenwald
afabbc28c5 Temporarily stop listing the official Chrome extension in the main README
The [official Chrome extension](https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm) has unfortunately not been updated for *three years*, which means that it's currently missing out on years worth of bug fixes, performance improvements, and new features.
In particular, the Chrome extension suffers from a known bug with non-embedded standard fonts; see issue 13669 for details.

For the time being, this patch proposes that we *temporary* make the following changes:
 - Remove the mention of the official Chrome extension from the main README, since it seems unfortunate to somewhat prominently recommend users an old and partially non-working extension.
 - Don't run the `gulp lint-chromium` task as part of the CI, since in addition to the official extension not having been updated its code is also not being actively maintained.[1]

Once the official Chrome extension has been updated, and it's being actively maintained again, this patch should be simple enough to revert.

---
[1] The last commits, which aren't e.g. linting or general code-maintenance related, happened a year ago now.
2022-09-17 16:29:19 +02:00
Jonas Jenwald
2f3417a590 Remove the enableScripting-parameter from the component examples (PR 13816 follow-up)
This became unnecessary with PDF.js version `2.11.338`, which was relasesed almost a year ago and is no longer supported.
2022-09-16 10:19:05 +02:00
Jonas Jenwald
bcdf161967
Merge pull request #15445 from Snuffleupagus/issue-15443
Extend `getSupplementalGlyphMapForCalibri` with more entries (issue 15443)
2022-09-15 22:56:44 +02:00
Jonas Jenwald
7a19def34c Extend getSupplementalGlyphMapForCalibri with more entries (issue 15443) 2022-09-15 22:19:16 +02:00
Jonas Jenwald
9bfd997c12
Merge pull request #15442 from Snuffleupagus/issue-15441
Extend `getGlyphMapForStandardFonts` with some quote-entries (issue 15441)
2022-09-15 13:11:06 +02:00
Jonas Jenwald
2f2ecad8fd Extend getGlyphMapForStandardFonts with some quote-entries (issue 15441) 2022-09-15 11:37:20 +02:00
Jonas Jenwald
c21d00ef44
Merge pull request #15430 from srmagura/webpack5
[api-minor] Use `new Worker()` syntax in webpack entrypoint
2022-09-14 10:32:01 +02:00
Sam Magura
1c2d200918 [api-minor] Use new Worker() syntax in webpack entrypoint
This requires Webpack 5 and will break for anyone using Webpack 4.
worker-loader no longer needs to be installed.
2022-09-13 11:12:00 -04:00
Jonas Jenwald
5e5aa9fb69
Merge pull request #15339 from Snuffleupagus/enable-editor
[api-major] Enable editing by default
2022-09-13 15:57:54 +02:00
Jonas Jenwald
3c6b3b55c7 Move the errorWrapper definition in the getViewerConfiguration function
Similar to how we handle e.g. the "Open File"-buttons in non-GENERIC builds, we can handle the `errorWrapper` definition in the same way.
2022-09-13 14:18:38 +02:00
Jonas Jenwald
0988915d06 Only define the validateFileURL variable in GENERIC builds
There's no point in having this variable defined (implicitly) as `undefined` in e.g. the Firefox PDF Viewer.
By defining it with `var` and using an ESLint ignore, rather than `let`, we can move it into the relevant pre-processor block instead. Note that since the entire viewer-code is placed, by Webpack, in a top-level closure this variable will thus not become globally accessible.
2022-09-13 14:18:23 +02:00
Jonas Jenwald
5a6cdffb4b
Merge pull request #15431 from Snuffleupagus/bug-1790552
Disable the editing-indicator, in the document title, during printing (bug 1790552, PR 15351 follow-up)
2022-09-13 11:41:33 +02:00
Jonas Jenwald
00aef590cf Disable the editing-indicator, in the document title, during printing (bug 1790552, PR 15351 follow-up) 2022-09-13 11:33:24 +02:00
Jonas Jenwald
3e8394ee33 [api-major] Enable editing by default
Note that this patch *at least* shouldn't land until both [bug 1784272](https://bugzilla.mozilla.org/show_bug.cgi?id=1784272) and [bug 1785248](https://bugzilla.mozilla.org/show_bug.cgi?id=1785248) are fixed.
2022-09-12 14:58:31 +02:00
calixteman
493bb65005
Merge pull request #15425 from Snuffleupagus/cursor-failed-fullscreen
Don't try to update the cursorTool when switching to PresentationMode failed
2022-09-12 14:51:55 +02:00
calixteman
2d1d64b214
Merge pull request #15416 from calixteman/buttons_telemetry
Add some telemetry to know how often the buttons in the secondary toolbar are used (bug 1789883)
2022-09-12 13:59:45 +02:00
Jonas Jenwald
71f8680d66 Don't try to update the cursorTool when switching to PresentationMode failed
Currently this may print an Error message in the console, and while nothing breaks (since no actual Error is thrown) we should probably avoid this.
2022-09-12 13:36:37 +02:00
Calixte Denizet
05e4aed787 Add some telemetry to know how often the buttons in the secondary toolbar are used (bug 1789883) 2022-09-12 12:37:48 +02:00
Tim van der Meij
f63d584cb1
Merge pull request #15414 from Snuffleupagus/mv-PDFViewer
Remove the abstract `BaseViewer`-class
2022-09-10 13:37:04 +02:00
Tim van der Meij
ae12a219d1
Merge pull request #15420 from Snuffleupagus/issue-15419
Send the `verbosity` when using a workerPort (issue 15419)
2022-09-10 13:31:47 +02:00
Jonas Jenwald
a274f63d50
Merge pull request #15421 from Snuffleupagus/separator-followup
Fix the visibility of a separator in the secondaryToolbar (PR 15391 follow-up)
2022-09-09 18:54:37 +02:00
Jonas Jenwald
4189a8567e Fix the visibility of a separator in the secondaryToolbar (PR 15391 follow-up)
After the changes in PR 15391 one separator may now become visible too soon when the viewer is narrow, applies e.g. to the MOZCENTRAL viewer, since the wrong CSS class is being used.
The reason that this happens is that only the GENERIC viewer includes the "openFile"-buttons, and we thus need the separator to also be conditionally defined.
2022-09-09 17:50:29 +02:00
Jonas Jenwald
d846b8601e Send the verbosity when using a workerPort (issue 15419)
This *should* fix issue 15419, but given the lack of a runnable example it's difficult to know for sure.
2022-09-09 11:47:26 +02:00
Jonas Jenwald
a21ce7ac8b
Merge pull request #15418 from Snuffleupagus/pr-15319-followup
Don't listen for window resolution changes in old browsers (PR 15319 follow-up)
2022-09-09 11:18:15 +02:00
Jonas Jenwald
c36205f10d Don't listen for window resolution changes in old browsers (PR 15319 follow-up)
This is a slightly speculative change, based on something that I happened to notice while browsing MDN, to hopefully prevent PDF.js from outright breaking in older browsers.
According to the following information on MDN, Safari didn't implement support for the necessary features until version 14:
 - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/change_event#browser_compatibility

Given the browsers that we currently support only older versions of Safari should be affected, hence it seems reasonable to simply disable the functionality rather than trying to polyfill it.
(It's interesting how it's very often Safari which is *much* slower than the other browsers at implementing new features.)
2022-09-09 10:39:35 +02:00
Jonas Jenwald
21fe5017bb Remove the abstract BaseViewer-class
After the changes in PR 14112 the `PDFViewer`-class is now "identical" to the `BaseViewer`-class and the `PDFSinglePageViewer`-class is just a very thin wrapper around the `BaseViewer`-class.
Hence we can rename these files, and also remove the abstract `BaseViewer`-class, which helps reduce some unnecessary "closures" in the *built* viewer.

*Please note:* These changes are made in two separate commits, to allow GitHub to preserve `blame` for the affected files.
2022-09-08 12:38:17 +02:00
Jonas Jenwald
6dc4c994b8 Remove the abstract BaseViewer-class
After the changes in PR 14112 the `PDFViewer`-class is now "identical" to the `BaseViewer`-class and the `PDFSinglePageViewer`-class is just a very thin wrapper around the `BaseViewer`-class.
Hence we can rename these files, and also remove the abstract `BaseViewer`-class, which helps reduce some unnecessary "closures" in the *built* viewer.

*Please note:* These changes are made in two separate commits, to allow GitHub to preserve `blame` for the affected files.
2022-09-08 12:38:17 +02:00
calixteman
b0a021d2cc
Merge pull request #15413 from calixteman/items_size
Set a display value for the secondary toolbar buttons
2022-09-08 12:35:08 +02:00
Calixte Denizet
f8ae49d20b Set a display value for the secondary toolbar buttons
and remove a useless property: visibleSmallView.
2022-09-08 12:19:21 +02:00
Calixte Denizet
e56c30eb59 Move 'presentation mode' and 'bookmarks' buttons in the secondary toolbar (bug 1789082) 2022-09-08 12:18:08 +02:00
calixteman
6852001b02
Merge pull request #15384 from calixteman/icons
Update some icons in the toolbar (bug 1739965)
2022-09-07 11:48:27 +02:00
Calixte Denizet
90c69876ca Update some icons in the toolbar (bug 1739965) 2022-09-07 10:45:03 +02:00
Jonas Jenwald
af6aacfc0e
Merge pull request #15398 from Snuffleupagus/more-optional-chaining
Use more optional chaining in the code-base
2022-09-06 20:31:03 +02:00
Jonas Jenwald
95e3f5d495
Merge pull request #15402 from Snuffleupagus/rm-telemetry-tagged
Remove the "tagged" telemetry-reporting
2022-09-06 14:21:52 +02:00
Jonas Jenwald
c70ceecff4 Remove the "tagged" telemetry-reporting
Given that this is no longer being recorded in Firefox, it shouldn't be necessary to keep the associated code in the default viewer.
2022-09-06 13:00:44 +02:00
Jonas Jenwald
b4b9ce83ed
Merge pull request #15397 from Snuffleupagus/getEexecBlock-empty
Fallback to a standard font when a Type1 font program is empty (issue 15292)
2022-09-06 10:27:37 +02:00
Jonas Jenwald
38ee28b1d3 Use more optional chaining in the code-base
This patch updates a bunch of older code, that makes conditional function calls, to use optional chaining rather than `if`-blocks.

These mostly mechanical changes reduce the size of the `gulp mozcentral` build by a little over 1 kB.
2022-09-05 15:41:53 +02:00
Jonas Jenwald
947d390421 Fallback to a standard font when a Type1 font program is empty (issue 15292)
*Please note:* This is only a, hopefully generally helpful, work-around rather than a proper solution to issue 15292.

There's something that's "special" about the Type1 fonts in the referenced PDF document, since we don't manage to find any actual font programs and thus cannot render anything.
Given that it shouldn't make sense for a Type1 font program to ever be empty, since that means that there's no glyph-data to render, we simply fallback to a standard font to at least try and render *something* in these rare cases.
2022-09-05 12:07:19 +02:00
Jonas Jenwald
9578152ae4
Merge pull request #15392 from Snuffleupagus/issue-15352
Don't allow `adjustToUnicode` to extend a built-in /ToUnicode map (issue 15352)
2022-09-04 15:12:10 +02:00
calixteman
72375ed652
Merge pull request #15395 from calixteman/15340
Don't replace cr by a white space when the last char on the line is an ideographic char
2022-09-04 14:30:22 +02:00
Calixte Denizet
6c6f6fb2b8 Don't replace cr by a white space when the last char on the line is an ideographic char 2022-09-04 14:21:05 +02:00
Tim van der Meij
e3874dab7c
Merge pull request #15394 from Snuffleupagus/update-packages
Update packages and translations
2022-09-04 13:52:23 +02:00
Jonas Jenwald
a65cc8d26d Update l10n files 2022-09-04 10:16:40 +02:00
Jonas Jenwald
21042371e6 Update npm packages 2022-09-04 10:16:40 +02:00
Jonas Jenwald
12d60e0acf Don't allow adjustToUnicode to extend a built-in /ToUnicode map (issue 15352)
Given that the change in PR 13393 was slightly speculative, given the lack of test-cases, let's just revert part of that to fix the referenced issue.
Based on a quick look at old issues and existing test-cases, it seems that most (if not all) PDF documents that benefit from using the font-data in this way lack any /ToUnicode maps which should mean that they're unaffected by these changes.
2022-09-03 23:11:42 +02:00
Tim van der Meij
50d72fc111
Merge pull request #15377 from Snuffleupagus/SetOCGState
[api-minor] Add basic support for the `SetOCGState` action (issue 15372)
2022-09-03 13:26:06 +02:00
Tim van der Meij
d16f591183
Merge pull request #15390 from Snuffleupagus/rm-bower
Remove Bower support in `pdfjs-dist`
2022-09-03 13:21:28 +02:00
Jonas Jenwald
5b903a6e2d Remove Bower support in pdfjs-dist
Given that the official Bower website, since almost five years, has been advising users to utilize other tools it doesn't seem entirely necessary to keep including the `bower.json` file in the `pdfjs-dist` repository; see e.g. https://bower.io/blog/2017/how-to-migrate-away-from-bower/
2022-09-03 13:05:59 +02:00
Tim van der Meij
783c722661
Merge pull request #15360 from Snuffleupagus/Popup-IGNORE_TYPES
Properly ignore PopupAnnotations with custom `trigger`-elements
2022-09-03 12:56:38 +02:00
Tim van der Meij
41c14f84dd
Merge pull request #15388 from Snuffleupagus/rm-browserify
Remove the `browserify` example
2022-09-03 12:29:14 +02:00
Jonas Jenwald
2075800828 Remove the browserify example
This patch proposes removing the `browserify` example for the following reasons:
 - The last `browserify` release was almost two years ago, according to both https://github.com/browserify/browserify/releases and https://www.npmjs.com/package/browserify?activeTab=versions
 - The project no longer seems to be actively maintained, since so far this year there's only been *a single* (seemingly trivial) patch merged; see https://github.com/browserify/browserify/commits/master
 - Because of the previous points `browserify` doesn't support modern and up-to-date JavaScript features, as evident from e.g. issue 14731 and multiple issues found in https://github.com/browserify/browserify/issues
 - Our `browserify` example is most likely not very commonly used, judging by the very low volume of issues/PRs related to it. Looking at the `git` history of that example the only changes have been lint- or maintenance-related.[1]
 - Providing an example for a framework that's no longer actively maintained doesn't seem like a good idea in general, since we probably don't want to steer users towards using (possibly) older frameworks.
 - Given that we've never used `browserify` in the PDF.js project, it's also quite difficult to provide support for the example.

---
[1] It's interesting to compare with the `webpack` example, since that's generated both issues *and* also PRs (for missing features) from users.
2022-09-02 18:15:42 +02:00
calixteman
c503006b2e
Merge pull request #15386 from calixteman/text_cursor
[Editor] Change the cursor when we switch to FreeText mode (bug 1787297)
2022-09-02 17:58:00 +02:00
Calixte Denizet
1b14b06e4c [Editor] Change the cursor when we switch to FreeText mode (bug 1787297) 2022-09-02 15:17:24 +02:00
calixteman
51035194d9
Merge pull request #15385 from calixteman/editor_icons
Update editing icons (bug 1785248)
2022-09-02 13:28:12 +02:00
Calixte Denizet
ec165abfa1 Update editing icons (bug 1785248) 2022-09-02 12:42:25 +02:00
calixteman
eab411a379
Merge pull request #15378 from calixteman/editor_strings
[Editor] Update some strings (bug 1787299)
2022-09-02 09:36:02 +02:00
calixteman
3043423c82
Merge pull request #15381 from calixteman/rm_leftover
[Editor] Remove some useless code (#15373 follow-up)
2022-09-01 20:38:07 +02:00
Calixte Denizet
c4aa00bee1 [Editor] Remove some useless code (#15373 follow-up) 2022-09-01 19:34:30 +02:00
Calixte Denizet
b8fa789022 [Editor] Update some strings (bug 1787299) 2022-09-01 18:02:17 +02:00
Jonas Jenwald
cc4baa2fe9 [api-minor] Add basic support for the SetOCGState action (issue 15372)
Note that this patch implements the `SetOCGState`-handling in `PDFLinkService`, rather than as a new method in `OptionalContentConfig`[1], since this action is nothing but a series of `setVisibility`-calls and that it seems quite uncommon in real-world PDF documents.

The new functionality also required some tweaks in the `PDFLayerViewer`, to ensure that the `layersView` in the sidebar is updated correctly when the optional-content visibility changes from "outside" of `PDFLayerViewer`.

---
[1] We can obviously move this code into `OptionalContentConfig` instead, if deemed necessary, but for an initial implementation I figured that doing it this way might be acceptable.
2022-09-01 17:34:24 +02:00
calixteman
e9bdbe4574
Merge pull request #15373 from calixteman/copy_paste
[Editor] Use the global clipboard for the copy/paste/cut operations
2022-08-31 16:53:16 +02:00
Calixte Denizet
372d4d64e3 [Editor] Use the global clipboard for the copy/paste/cut operations
It slightly helps to reduce the code size and its complexity.
But the cool thing is that it allows to copy/paste some anntations from a pdf
to an other.
2022-08-31 16:32:19 +02:00
calixteman
54d3b64497
Merge pull request #15369 from calixteman/update_params
[Editor] Avoid to update default params too early
2022-08-31 11:18:08 +02:00
Calixte Denizet
e91d67563f [Editor] Avoid to update default params too early 2022-08-31 10:28:58 +02:00
Jonas Jenwald
1865bb6526
Merge pull request #15368 from Snuffleupagus/issue-15367
[api-minor] Support Named-actions in the outline (issue 15367)
2022-08-30 22:13:29 +02:00
Jonas Jenwald
216b86a082 [api-minor] Support Named-actions in the outline (issue 15367)
Apparently this is implemented in e.g. Adobe Reader, and the specification does support it, however it cannot be commonly used in real-world PDF documents since it took over ten years for this feature to be requested.
2022-08-30 18:47:45 +02:00
Jonas Jenwald
0ecf6458ee Properly ignore PopupAnnotations with custom trigger-elements
A number of Annotation-types are currently creating their own PopupAnnotations, since they need to use a custom `trigger`-element. However, because of where that check is currently implemented[1] we end up attaching empty/unused containers for those PopupAnnotations to the DOM[2]; see e.g. the `annotation-line.pdf` file in the test-suite for one example.

By instead moving the types-check into the `PopupAnnotationElement` constructor, we can completely skip those PopupAnnotations that are being explicitly handled elsewhere.
Note that I don't *believe* that this is a new issue, although I've not tried to bisect it, but this likely goes back quite some time (possibly even as far as PR 8228).

---
[1] In the `PopupAnnotationElement.render` method.

[2] Please note that the actual Popup-element *itself* isn't being attached/rendered here, just its container which by itself serves no purpose as far as I can tell.
2022-08-29 16:32:47 +02:00
Tim van der Meij
86370bd5c5
Merge pull request #15286 from Snuffleupagus/rm-deprecated
[api-major] Remove (most of) the remaining `deprecated` code
2022-08-28 19:21:45 +02:00
Tim van der Meij
7b7b54ce0f
Merge pull request #15259 from Snuffleupagus/rm-enhanceTextSelection
[api-major] Remove the `enhanceTextSelection` functionality (PR 15145 follow-up)
2022-08-28 19:13:33 +02:00
Jonas Jenwald
78f24e5535 [api-major] Remove (most of) the remaining deprecated code
There's three notable exceptions here:
 - The `saveDocument` one is converted into a permanent `warn`, since it still works when the `annotationStorage` is empty although it's (obviously) less efficient than `getData`.
 - The `fallbackWorkerSrc` functionality (for browsers), since just removing it would risk too much third-party breakage.
 - The SVG back-end, since a final decision is yet to be made. (It might be completely removed, or left as-is in an essentially "frozen" state.)
2022-08-28 15:05:00 +02:00
Jonas Jenwald
d3005603e1 Move the saveDocument method, within the PDFDocumentProxy/WorkerTransport classes
To improve discoverability, since these methods are very closely related, move `saveDocument` to just after `getData` instead.
2022-08-28 15:05:00 +02:00
Jonas Jenwald
571ce13dd6 [api-major] Remove the enhanceTextSelection functionality (PR 15145 follow-up)
For the `gulp mozcentral` command, this reduces the size of the *built* `pdf.js` file by `> 10` kB.
2022-08-28 15:04:47 +02:00
Tim van der Meij
3f8b5449e8
Merge pull request #15357 from timvandermeij/bump
Bump versions in `pdfjs.config`
2022-08-28 13:48:00 +02:00
Tim van der Meij
eba4da5802
Bump versions in pdfjs.config 2022-08-28 13:34:57 +02:00
Tim van der Meij
172ccdbe5b
Merge pull request #15356 from Snuffleupagus/Node-amend-compat-info
Update the Node.js `atob`/`btoa` compatibility info
2022-08-28 13:04:11 +02:00
Jonas Jenwald
ca823d1bbc Update the Node.js atob/btoa compatibility info
Given that Node.js has finally implemented native support for `atob`/`btoa`, it can't hurt to update the comments in `src/shared/compatibility.js` so that we don't forget to remove the polyfills once Node.js version `16` becomes the lowest supported LTS release; see
 - https://developer.mozilla.org/en-US/docs/Web/API/atob#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/btoa#browser_compatibility
2022-08-28 12:58:02 +02:00
Tim van der Meij
d62cce455f
Merge pull request #15349 from Snuffleupagus/bug-1787295
[editor] Remove the `editorNone` toolbar button (bug 1787295)
2022-08-27 14:04:06 +02:00
Tim van der Meij
c5b9e9aef8
Merge pull request #15351 from Snuffleupagus/bug-1785854
[api-minor][editor] Indicate, in the title, if the document has been edited (bug 1785854)
2022-08-27 13:52:07 +02:00
Tim van der Meij
d715094383
Merge pull request #15346 from Snuffleupagus/deprecated-imageLayer
[api-minor] Deprecate the `imageLayer` functionality
2022-08-27 13:16:31 +02:00
Tim van der Meij
4469453425
Merge pull request #15341 from Snuffleupagus/PasswordPrompt-cancel-button
Improve handling of the "Cancel"-button in the password dialog
2022-08-27 13:10:39 +02:00
Tim van der Meij
a1cc9238b0
Merge pull request #15343 from Snuffleupagus/AbortController-unconditional
Use `AbortController` unconditionally with the Fetch API
2022-08-27 13:08:26 +02:00
Tim van der Meij
cb8d56f988
Merge pull request #15344 from Snuffleupagus/prefer-array-find
Enable the `unicorn/prefer-array-find` ESLint plugin rule
2022-08-27 13:06:41 +02:00
Jonas Jenwald
4c63a91036
Merge pull request #15355 from Snuffleupagus/bug-1787456
Always focus the `viewerContainer` when entering PresentationMode (bug 1787456)
2022-08-27 11:18:19 +02:00
Jonas Jenwald
d93d21fdfd Always focus the viewerContainer when entering PresentationMode (bug 1787456)
This fixes the regression in [bug 1787456](https://bugzilla.mozilla.org/show_bug.cgi?id=1787456), assuming that it should be handled on the PDF.js side.
2022-08-26 21:42:06 +02:00
Jonas Jenwald
f2b5210b36
Merge pull request #15347 from federicobond/fix-types
Update types in PDFPageViewOptions to properly declare optional parameters
2022-08-26 20:48:12 +02:00
Jonas Jenwald
19182d5f25 [editor] Remove the editorNone toolbar button (bug 1787295) 2022-08-26 09:25:05 +02:00
Jonas Jenwald
151dfc9a25 [api-minor][editor] Indicate, in the title, if the document has been edited (bug 1785854)
Note that this patch prepends the document title with "* ", rather than only "*" as suggested in the bug, since there's nothing that says that a PDF document cannot specify a title[1] beginning with an asterisk. To reduce possible confusion, having a space between the "editing marker" and the actual document title thus cannot hurt as far as I'm concerned.

In order to notify the viewer when all `AnnotationEditor`s have been removed, we utilize the existing `onAnnotationEditor`-callback to allow the document title to be updated as necessary.

Finally, this patch makes the following (slightly unrelated) changes:
 - Rename the `AnnotationStorage.removeKey` method to just `AnnotationStorage.remove` instead. This is consistent with e.g. the `has`-method and should suffice to explain what it does.
 - Remove the `AnnotationStorage.hasAnnotationEditors` getter, since the viewer now tracks the necessary state internally. This avoids unnecessarily having to iterate through the `AnnotationStorage`-instance when saving/printing the document.

---
[1] Using either an /Info dictionary or a /Metadata stream.
2022-08-26 00:20:58 +02:00
Jonas Jenwald
76f665d57f
Merge pull request #15348 from Snuffleupagus/bug-1787296
[editor] Change the focus-outline to blue (bug 1787296)
2022-08-25 22:53:10 +02:00
Jonas Jenwald
a4bfa7d18b [editor] Change the focus-outline to blue (bug 1787296) 2022-08-25 22:40:20 +02:00
Federico Bond
df912e9ab6 Update types in PDFPageViewOptions to properly declare optional parameters 2022-08-25 13:36:05 -03:00
Jonas Jenwald
118da8e85d [api-minor] Deprecate the imageLayer functionality
This functionality has never been used anywhere in the PDF.js library/viewer itself, since it was added in 2013.
Furthermore this functionality is, and has always been, *completely untested* and also unmaintained.
Finally, there's (at least) one old issue about `appendImage` not returning the correct position; see issue 4182.

All-in-all, it seems that keeping very old, untested, unmaintained, and partially broken code around probably isn't what we want here.
(On the off-chance that any future a11y-work requires getting access to image-positions, it'd likely be much better to re-implement the necessary functionality from scratch and also make sure that it's properly tested from the beginning.)
2022-08-25 13:06:01 +02:00
Jonas Jenwald
3c8aeb445a Remove the CanvasGraphics.getCanvasPosition method
This old method, which is only used with the `imageLayer` functionality, is essentially just a re-implementation of the existing `Util.applyTransform` method.
2022-08-25 13:06:00 +02:00
Jonas Jenwald
723584dd4f Enable the unicorn/prefer-array-find ESLint plugin rule
Please find additional information here:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find#browser_compatibility
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-find.md
2022-08-24 16:46:26 +02:00
Jonas Jenwald
b0a73a9388 Use AbortController unconditionally with the Fetch API
Given the browsers that we currently support in the PDF.js project and the MDN compatibility data, see links below, it should no longer be necessary to check for the availability of `AbortController` before using it.
 - https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
 - https://developer.mozilla.org/en-US/docs/Web/API/AbortController#browser_compatibility
2022-08-24 12:13:09 +02:00
Jonas Jenwald
de14b82af9 Improve handling of the "Cancel"-button in the password dialog
The password dialog can be cancelled in three different ways:
 - By clicking on its "Cancel"-button.
 - By pressing the Escape-key.
 - By force-opening another dialog, although this shouldn't happen in practice.

Here the "Cancel"-button case is slightly special since it'll trigger `PasswordPrompt.#cancel` *twice*, first directly via the click and secondly via the "close" event on the `dialog`-element.
While this shouldn't, as far as I know, cause any bugs it's nonetheless inconsistent with the other cases outlined above. To improve this we can simply attempt to *close* the password dialog instead, and then rely on the "close" event to run the `PasswordPrompt.#cancel` method.
2022-08-22 11:17:08 +02:00
Tim van der Meij
14e8167df9
Merge pull request #15335 from Snuffleupagus/PasswordPrompt-activeCapability
Ensure that we don't try to re-open, or update the password-callback, when the password dialog is already open
2022-08-21 12:52:34 +02:00
Tim van der Meij
81a700079f
Merge pull request #15332 from Snuffleupagus/Babel-targets
[api-minor] Add the Babel `targets`-option to avoid transpiling code for unsupported browsers
2022-08-21 12:06:43 +02:00
Tim van der Meij
255cc8b9eb
Merge pull request #15338 from Snuffleupagus/update-packages
Update packages and translations
2022-08-21 11:45:46 +02:00
Jonas Jenwald
635db46b0d Update l10n files 2022-08-21 10:04:47 +02:00
Jonas Jenwald
1001ae5474 Update npm packages 2022-08-21 10:04:47 +02:00
Jonas Jenwald
6e31799948 [api-minor] Add the Babel targets-option to avoid transpiling code for unsupported browsers
Currently we simply use the Babel `preset-env` in the `legacy`-builds of the PDF.js library. This has the side-effect of transpiling the code for *very old* browsers/environments, including ones that we (since many years) no longer support which unnecessarily bloats the size of the `legacy`-builds.

For the CSS files we're only targeting *the supported browsers*, and it's thus possible to extend that to also apply to Babel.
One of the most significant changes, with this patch, is that we'll no longer polyfill `async`/`await` in the `legacy`-builds. However, this shouldn't be an issue given the browsers that we currently support in PDF.js; please refer to:
 - https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function#browser_compatibility
2022-08-19 22:19:43 +02:00
Jonas Jenwald
89840649d9 Ensure that we don't try to re-open, or update the password-callback, when the password dialog is already open
Currently in `disableWorker=true` mode it's possible that opening of password-protected PDF documents outright fails, if an *incorrect* password is entered. Apparently the event ordering is subtly different in the non-Worker case, which causes the password-callback to be updated *before* the dialog has been fully closed.
To avoid that we'll utilize a `PromiseCapability` to keep track of the state of the password dialog, such that we can delay both re-opening and (importantly) updating of the password-callback until doing so is safe.

This patch *may* also fix issue 15330, but it's impossible for me to tell.
2022-08-19 20:10:37 +02:00
calixteman
1a007164f7
Merge pull request #15329 from calixteman/1782564
[api-minor][Annotations] charLimit === 0 means unlimited (bug 1782564)
2022-08-19 12:54:47 +02:00
Calixte Denizet
c06c5f7cbd [Annotations] charLimit === 0 means unlimited (bug 1782564)
Changing the charLimit in JS had no impact, so this patch aims to fix
that and add an integration test for it.
2022-08-19 11:28:28 +02:00
Jonas Jenwald
8f74fe6e1b
Merge pull request #15327 from Snuffleupagus/bug-1785218
Correctly mimic the proper event-format in `AnnotationElement._setDefaultPropertiesFromJS` (bug 1785218)
2022-08-17 16:15:13 +02:00
Jonas Jenwald
5e126032ff Correctly mimic the proper event-format in AnnotationElement._setDefaultPropertiesFromJS (bug 1785218)
*This is a follow-up to PR 14869.*

In the old code we're accidentally "swallowing" part of the event-details, which explains why the annotationLayer didn't render.
One thing that made debugging a lot harder was the lack of error messages, from the viewer, and a few `PDFPageView`-methods were updated to improve this situation.
2022-08-17 15:44:27 +02:00
Jonas Jenwald
b05010c3eb
Merge pull request #15325 from Snuffleupagus/issue-15324
Ignoring "resize" events during printing (issue 15324)
2022-08-16 14:41:36 +02:00
Jonas Jenwald
f669e5dd34 Ignoring "resize" events during printing (issue 15324)
This is a quick work-around, to prevent the viewer from breaking as a result of https://bugzilla.mozilla.org/show_bug.cgi?id=774398
2022-08-16 13:51:35 +02:00
Jonas Jenwald
518115fddc
Merge pull request #15315 from Snuffleupagus/type1-parser-rm-closure
Remove the remaining closures in the `src/core/type1_parser.js` file
2022-08-15 18:56:31 +02:00
Jonas Jenwald
bf6593372b
Merge pull request #15318 from Snuffleupagus/worker-small-fixes
A couple of small `PDFWorker` changes
2022-08-15 18:55:29 +02:00
Jonas Jenwald
44f6b76365
Merge pull request #15319 from Snuffleupagus/bug-1784850
Refresh the viewer if the window resolution changes (bug 1784850)
2022-08-15 18:54:08 +02:00
Jonas Jenwald
4919dae294 Refresh the viewer if the window resolution changes (bug 1784850)
*Please note:* This probably fixes bug 1784850, however I don't have the necessary hardware to reproduce the situation described in https://bugzilla.mozilla.org/show_bug.cgi?id=1784850#c0

Unfortunately it doesn't, as far as I can tell, appear possible to detect *all* resolution changes with a single media query. Instead we have to update it, and its listener, on every resolution change as outlined in [this MDN example](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes).
2022-08-15 16:56:57 +02:00
Jonas Jenwald
c02d0aa2cb A couple of small PDFWorker changes
- Remove the `typeof Worker` check, since all browsers have had `Worker` support for many years now; see https://developer.mozilla.org/en-US/docs/Web/API/Worker#browser_compatibility
   Furthermore the `new Worker(...)` call is wrapped in try-catch, which means that we'll still fallback to "fake workers" if necessary.

 - Limit the `fallbackWorkerSrc` handling, in the `PDFWorker.workerSrc` getter, to only GENERIC builds since that's the only place where it's defined anyway.
2022-08-15 12:17:48 +02:00
Jonas Jenwald
6a2c2a646f Remove the remaining closures in the src/core/type1_parser.js file
Given that the code is written with JavaScript module-syntax, none of this functionality will "leak" outside of this file with these change.
By removing this closure the file-size is decreased, even for the *built* `pdf.worker.js` file, since there's now less overall indentation in the code.
2022-08-14 12:50:26 +02:00
Tim van der Meij
e6fe127433
Merge pull request #15313 from Snuffleupagus/move-binarySearchFirstItem
Move `binarySearchFirstItem` back to the `web/`-folder (PR 15237 follow-up)
2022-08-14 12:14:32 +02:00
Tim van der Meij
92edfb59f7
Merge pull request #15310 from Snuffleupagus/cff-parser-rm-closure
Remove the remaining closures in the `src/core/cff_parser.js` file
2022-08-14 11:53:00 +02:00
Jonas Jenwald
0024165f1f Move binarySearchFirstItem back to the web/-folder (PR 15237 follow-up)
This was moved into the `src/display/`-folder in PR 15110, for the initial editor-a11y patch. However, with the changes in PR 15237 we're again only using `binarySearchFirstItem` in the `web/`-folder and it thus seem reasonable to move it back there.
The primary reason for moving it back is that `binarySearchFirstItem` is currently exposed in the public API, and we always want to avoid that unless it's either PDF-related functionality or code that simply must be shared between the `src/`- and `web/`-folders. In this case, `binarySearchFirstItem` is a general helper function that doesn't really satisfy either of those alternatives.
2022-08-14 11:38:17 +02:00
Jonas Jenwald
2b66ed5fef
Merge pull request #15311 from Snuffleupagus/text-a11y-removed-element
Don't add `aria-owns` attributes for non-existent elements (PR 15237 follow-up)
2022-08-14 09:31:29 +02:00
Jonas Jenwald
6c4561f3d8 Don't add aria-owns attributes for non-existent elements (PR 15237 follow-up)
Currently when the `TextAccessibilityManager.enabled` method is called, we'll update `aria-owns` for any pre-existing elements. This obviously makes sense when e.g. zooming/rotating in the viewer, since the annotationLayer/annotationEditorLayer is kept in those cases.
However when the page is *fully* reset, e.g. as result of going out-of-view and thus being evicted from the cache, we still keep the `#textNodes`-Map around. This causes us to set the `aria-owns` attribute (in the textLayer) for an element that doesn't actually exist any more, which as far as I'm concerned seems incorrect. In this case the element will simply, as already implemented, be re-inserted when the annotationLayer/annotationEditorLayer renders again.
2022-08-13 21:52:38 +02:00
Jonas Jenwald
e5e756c0b4 Remove the remaining closures in the src/core/cff_parser.js file
Given that the code is written with JavaScript module-syntax, none of this functionality will "leak" outside of this file with these changes.
For e.g. the `gulp mozcentral` command the *built* `pdf.worker.js` file-size decreases `~2 kB` with this patch, and most of the improvement comes from having less overall indentation in the code.
2022-08-13 19:48:17 +02:00
Tim van der Meij
b040d64a3c
Merge pull request #15300 from Snuffleupagus/viewer-export-constants
[GENERIC viewer] Export some viewer constants in the default viewer (issue 15294)
2022-08-13 15:25:29 +02:00
Tim van der Meij
f212341d01
Merge pull request #15306 from Snuffleupagus/Type3-only-Path2D
Only compile Type3 glyphs when `Path2D` is supported
2022-08-13 15:23:11 +02:00
Tim van der Meij
c81903d72d
Merge pull request #15309 from Snuffleupagus/function-rm-closure
Remove the remaining closure in the `src/core/function.js` file
2022-08-13 15:05:17 +02:00
Jonas Jenwald
9dcfdb9578 Remove the remaining closure in the src/core/function.js file
Given that the code is written with JavaScript module-syntax, none of this functionality will "leak" outside of this file with these changes.
By removing this closure the file-size is decreased, even for the *built* `pdf.worker.js` file, since there's now less overall indentation in the code.
2022-08-13 12:52:36 +02:00
calixteman
3cf31a8b17
Merge pull request #15307 from calixteman/role_comment
[Annotation] Add an aria role comment for FreeText annotations
2022-08-12 16:22:37 +02:00
Calixte Denizet
2916910ea1 [Annotation] Add an aria role comment for FreeText annotations 2022-08-12 15:59:21 +02:00
calixteman
6b4c2464ad
Merge pull request #15237 from calixteman/annotation_a11y
[Annotations] Add some aria-owns in the text layer to link to annotations (bug 1780375)
2022-08-12 15:04:56 +02:00
Calixte Denizet
f316300113 [Annotations] Add some aria-owns in the text layer to link to annotations (bug 1780375)
This patch doesn't structurally change the text layer: it just adds some aria-owns
attributes to some spans.
The aria-owns attribute expect to have an element id, hence it's why it adds back an
id on the element rendering an annotation, but this id is built in using crypto.randomUUID
to avoid any potential issues with the hash in the url.
The elements in the annotation layer are moved into the DOM in order to have them in the
same "order" as they visually are.
The overall goal is to help screen readers to present to the user the annotations as
they visually are and as they come in the text flow.
It is clearly not perfect, but it should improve readability for some people with visual
disabilities.
2022-08-12 14:35:26 +02:00
Jonas Jenwald
e9e9fee833 Only compile Type3 glyphs when Path2D is supported
According to MDN `Path2D` is available in all browsers that we currently support, see https://developer.mozilla.org/en-US/docs/Web/API/Path2D#browser_compatibility
Hence only Node.js is currently lagging behind here, and requires that we keep the old code as a fallback in the `compileType3Glyph` function. However, there's an open PR in the `node-canvas` repository for adding `Path2D` support.

As far as I'm concerned, there's two possible solutions here:
 - We land this patch now, since it removes unnecessary code in e.g. the Firefox PDF Viewer, which means that compilation of Type3 glyphs will be disabled in Node.js until that PR is landed.[1]
   If users report bugs about Type3 glyphs looking "inconsistent" in Node.js and/or being slow to render, we could perhaps encourage them to upvote and otherwise help out getting that PR landed?

 - We wait for the mentioned PR to land *first*, before moving forward with this patch. Given that there's been no updates on that PR for almost two months, this alternative may possibly take a while.

---
[1] Note that Type3 fonts are first of all not very common in PDF documents, and secondly that compilation only applies specifically to Type3 glyphs that contain /ImageMask-data (i.e. not all Type3 fonts are affected).
2022-08-12 13:06:42 +02:00
Jonas Jenwald
b8bb1d67d4 [GENERIC viewer] Export some viewer constants in the default viewer (issue 15294)
This exports the same constants as the viewer components, but in the default viewer. To avoid bloating the global-scope the constants are added to a new `PDFViewerApplicationConstants` object[1], which also allows us to skip this in builds where it's not actually needed (e.g. the Firefox *built-in* PDF Viewer).

*Please note:* I'm not completely sold on this idea, and thus wouldn't mind the patch being rejected, since we probably don't want to export every single viewer constant this way. (And it may seem a bit arbitrary, to users, why some constants are exported and others are not.)

---
[1] Somewhat similar to the existing `PDFViewerApplicationOptions` structure.
2022-08-11 16:22:12 +02:00
Jonas Jenwald
69462e5e14 Export additional constants in the viewer components
In addition to the existing `LinkTarget` constant, used by the `PDFLinkService`-constructor, this patch exports the following constants in the viewer components:
 - `ScrollMode` and `SpreadMode`, since the `BaseViewer` has getters/setters which work with those constants.
 - `RenderingStates`, since that one may be helpful when using `PDFPageView` directly.
2022-08-11 16:22:07 +02:00
Jonas Jenwald
ab1297f053
Merge pull request #15299 from Snuffleupagus/getDocument-ArrayBuffer
Add *official* support for passing `ArrayBuffer`-data to `getDocument` (issue 15269)
2022-08-11 14:12:55 +02:00
Jonas Jenwald
dd95e4f851 Add *official* support for passing ArrayBuffer-data to getDocument (issue 15269)
While this has always worked, as a consequence of the implementation, it's never been officially supported.
In addition to adding basic unit-tests, this patch also introduces a couple of new JSDoc `@typedef`s in the API to avoid overly long lines.
2022-08-10 14:13:01 +02:00
Jonas Jenwald
e1e97c6edd
Merge pull request #15279 from Snuffleupagus/firefox-rm-README
Remove the `extensions/firefox/README.mozilla` file (bug 1778567 follow-up)
2022-08-10 11:13:00 +02:00
calixteman
cef2ac99e5
Merge pull request #15298 from calixteman/ink_min_size
[Editor] Ensure an ink editor has the minimal required size after having been pasted
2022-08-10 10:27:37 +02:00
calixteman
3eb11fafca
Merge pull request #15297 from calixteman/check_pointer_down
[Editor] Avoid creation of an editor on "wrong" clicks
2022-08-10 10:27:12 +02:00
Calixte Denizet
63361dcfc7 [Editor] Ensure an ink editor has the minimal required size after having been pasted 2022-08-10 10:15:23 +02:00
Jonas Jenwald
fa48e90e3c
Merge pull request #15296 from Snuffleupagus/toolbars-reset
Move the `reset`-calls to occur last in the toolbar-constructors
2022-08-10 10:14:23 +02:00
Calixte Denizet
71ca249d2b [Editor] Avoid creation of an editor on "wrong" clicks 2022-08-10 10:05:04 +02:00
Jonas Jenwald
047522a34a Move the reset-calls to occur last in the toolbar-constructors
By invoking the `reset` methods *last* in the `Toolbar`/`SecondaryToolbar`-constructors, we ensure that the "toolbarreset"/"secondarytoolbarreset"-events are actually handle when the viewer loads. Note that previously those events were dispatched *before* the relevant event-listeners had been attached.
With this small change we can avoid inconsistent initial toolbar-state, specifically in the case when the viewer is *reloaded* (since Firefox keeps the HTML-state on "soft" reloads).
2022-08-09 22:39:38 +02:00
Jonas Jenwald
2b0b8cd665 Add more private properties/methods in web/toolbar.js 2022-08-09 22:39:07 +02:00
calixteman
0079ce4ad0
Merge pull request #15295 from calixteman/disable_editing
[Editing] Disable buttons until the first page is rendered
2022-08-09 21:47:21 +02:00
Calixte Denizet
fbce8786d0 [Editing] Disable buttons until the first page is rendered 2022-08-09 20:35:35 +02:00
Jonas Jenwald
63708a1a5b Remove the extensions/firefox/README.mozilla file (bug 1778567 follow-up)
With the changes made in [bug 1778567](https://bugzilla.mozilla.org/show_bug.cgi?id=1778567), it no longer seems correct to overwrite the mozilla-central file.
2022-08-09 13:13:39 +02:00
calixteman
589f72e325
Merge pull request #15290 from calixteman/ots_issue
Fix OTS issue with empty index (#15289)
2022-08-08 23:36:52 +02:00
Calixte Denizet
04f78c935c Fix OTS issue with empty index (#15289) 2022-08-08 22:56:26 +02:00
Jonas Jenwald
40f9f7e909
Merge pull request #15287 from calixteman/inserthtml
[Editor] Remove use of innerHtml
2022-08-07 14:37:39 +02:00
Calixte Denizet
5e0ddfb0e6 [Editor] Remove use of innerHtml 2022-08-07 13:39:41 +02:00
Tim van der Meij
2363fc0e5e
Merge pull request #15284 from Snuffleupagus/update-packages
Update packages and translations
2022-08-07 12:42:03 +02:00
Jonas Jenwald
38cf588eee Update l10n files 2022-08-07 10:22:40 +02:00
Jonas Jenwald
887e893fc8 Update npm packages 2022-08-07 10:20:21 +02:00
Tim van der Meij
2a84a3078b
Merge pull request #15283 from Snuffleupagus/sort-PopupAnnotation
[api-minor] Sort PopupAnnotations already on the worker-thread (PR 11535 follow-up)
2022-08-06 15:07:09 +02:00
Tim van der Meij
d55903764e
Merge pull request #15281 from Snuffleupagus/getTransform
Remove `mozCurrentTransform`/`mozCurrentTransformInverse` usage
2022-08-06 14:34:03 +02:00
Jonas Jenwald
358a0607fe Remove mozCurrentTransform/mozCurrentTransformInverse usage
These canvas-context properties are Mozilla-specific, and has obviously never been implemented anywhere else. Currently they are in the process of being removed, see [bug 1782651](https://bugzilla.mozilla.org/show_bug.cgi?id=1782651) and [bug 1294360](https://bugzilla.mozilla.org/show_bug.cgi?id=1294360), which in practice means that in e.g. Firefox Nightly the `addContextCurrentTransform`-function is now being used in the *built-in* PDF Viewer (which was obviously never intended).

We should thus be able to replace these Mozilla-specific properties with `CanvasRenderingContext2D.getTransform()`, which is available in all browsers that we currently support: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getTransform#browser_compatibility
2022-08-06 14:24:57 +02:00
Tim van der Meij
0ebd1daf30
Merge pull request #15261 from Snuffleupagus/issue-15260
Don't include `images/toolbarButton-editorInk.svg` in the `gulp components` build (issue 15260)
2022-08-06 14:17:55 +02:00
Tim van der Meij
70bcaf63ba
Merge pull request #15282 from Snuffleupagus/prefer-spread
Enable the ESLint `prefer-spread` rule
2022-08-06 14:12:25 +02:00
Jonas Jenwald
876a02a504 [api-minor] Sort PopupAnnotations already on the worker-thread (PR 11535 follow-up)
By doing this in the worker-thread this code will only need to run *once*, whereas currently re-rendering of a page forces this to be repeated (e.g. after it's been scrolled out-of-view and then back into view again).
2022-08-06 11:42:45 +02:00
Jonas Jenwald
f6db7975c5 Enable the ESLint prefer-spread rule
Note that in a couple of spots the argument could be `undefined` and there we simply disable the rule instead.

Please refer to https://eslint.org/docs/latest/rules/prefer-spread
2022-08-06 10:17:00 +02:00
Jonas Jenwald
d6d4653d80
Merge pull request #15275 from calixteman/textbox
[Editor] Remove some a11y properties only useful when a FreeText editor is edited
2022-08-05 09:36:56 +02:00
Calixte Denizet
fce83f8656 [Editor] Remove some a11y properties only useful when a FreeText editor is edited 2022-08-04 15:28:25 +02:00
calixteman
e88c90e898
Merge pull request #15274 from calixteman/missing_annotation
[Editor] A pasted FreeText editor was missing when printing/saving
2022-08-04 13:10:23 +02:00
Calixte Denizet
3c8d8f0d02 [Editor] A pasted FreeText editor was missing when printing/saving
When a FreeText editor is pasted then it hasn't an editorDiv yet when added
to the layer, hence it's empty.
So this patch just move the call to addToAnnotationStorage to ensure we've
what we need.
2022-08-04 13:00:45 +02:00
calixteman
b985eaa98c
Merge pull request #15267 from calixteman/freetext_a11y
[Annotation] Add a div containing the text of a FreeText annotation (bug 1780375)
2022-08-04 11:49:29 +02:00
Calixte Denizet
31155740c3 [Annotation] Add a div containing the text of a FreeText annotation (bug 1780375)
An annotation doesn't have to be in the text flow, hence it's likely a bad idea
to insert its text in the text layer. But the text must be visible from a screen
reader point of view so it must somewhere in the DOM.
So with this patch, the text from a FreeText annotation is extracted and added in
a div in its HTML counterpart, and with the patch #15237 the text should be visible
and positioned relatively to the text flow.
2022-08-04 11:14:05 +02:00
Jonas Jenwald
5ad8bbe8cb
Merge pull request #15271 from calixteman/null_field
Skip unknown fields when calculating a value in using AFSimple_Calculate
2022-08-04 10:11:46 +02:00
Calixte Denizet
6916fabd51 Skip unknown fields when calculating a value in using AFSimple_Calculate 2022-08-03 23:40:09 +02:00
calixteman
8bad06f158
Merge pull request #15268 from calixteman/bug1777693
Fix a typo in firefox print service (bug 1777693)
2022-08-03 18:02:18 +02:00
Calixte Denizet
6c9e538f56 Fix a typo in firefox print service (bug 1777693) 2022-08-03 17:25:01 +02:00
Jonas Jenwald
4f6cd05a53
Merge pull request #15264 from calixteman/editing_telemetry
[Editor] Add some telemetry to know how often the editing features are used (bug 1782254)
2022-08-03 11:28:08 +02:00
Calixte Denizet
94f57e5dd7 [Editor] Add some telemetry to know how often the editing features are used (bug 1782254) 2022-08-03 09:54:27 +02:00
Jonas Jenwald
159f853e06
Merge pull request #15263 from Snuffleupagus/issue-15262
Always set a border-radius for RadioButton annotations (issue 15262)
2022-08-02 15:35:36 +02:00
Jonas Jenwald
899fc29eef Always set a border-radius for RadioButton annotations (issue 15262) 2022-08-02 13:58:20 +02:00
Jonas Jenwald
44f77c9e82 Don't include images/toolbarButton-editorInk.svg in the gulp components build (issue 15260)
Given that this image is intended specifically for the default viewer, we simply use the CSS preprocessor to remove the image reference in the `gulp components` build.
Considering that the issue only affects a CSS file, I don't believe that replacing the *just released* PDF.js version is actually necessary here.
2022-08-02 10:26:46 +02:00
Jonas Jenwald
803e7af595
Merge pull request #15253 from Snuffleupagus/update-Safari-compat
[api-minor] Update the minimum supported Safari version
2022-07-31 18:33:47 +02:00
Jonas Jenwald
ad11cea33c [api-minor] Update the minimum supported Safari version
The Ink-editor uses `ResizeObserver`, which is supported in all reasonably modern browsers; see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#browser_compatibility

With the exception of Safari, `ResizeObserver` is thus available in all of the browsers that the PDF.js library currently support. Rather than trying to e.g. add a polyfill, let's just bump the compatibility (slightly) to Safari 13.1 instead; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_13
2022-07-31 17:40:26 +02:00
Tim van der Meij
f9c593d66c
Merge pull request #15251 from Snuffleupagus/thumbnail-setImage-small
Ignore too small page-canvases in `PDFThumbnailView.setImage`
2022-07-31 14:29:15 +02:00
Tim van der Meij
7798252285
Merge pull request #15252 from timvandermeij/bump
Bump versions in `pdfjs.config`
2022-07-31 14:22:21 +02:00
Tim van der Meij
91e6830ec4
Bump versions in pdfjs.config 2022-07-31 14:16:06 +02:00
Jonas Jenwald
5b50a50559 Ignore too small page-canvases in PDFThumbnailView.setImage
It doesn't make sense to use a page-canvas that's *smaller* than the resulting thumbnail, since that causes the image to be upscaled which results in a blurry thumbnail. Note that this doesn't normally happen, unless a very small zoom-level is used in the viewer.
2022-07-31 13:59:56 +02:00
Tim van der Meij
b8aa9c6221
Merge pull request #15246 from Snuffleupagus/thumbnail-setImage-improvements
[api-minor] Improve `thumbnail` handling in documents that contain interactive forms
2022-07-31 11:42:55 +02:00
Tim van der Meij
77b3489987
Merge pull request #15247 from Snuffleupagus/css-more-cleanup
Misc. small CSS cleanup
2022-07-31 11:23:16 +02:00
Jonas Jenwald
37d77f29f7
Merge pull request #15248 from Snuffleupagus/update-l10n
Update l10n files
2022-07-31 10:25:40 +02:00
Jonas Jenwald
635bd12050 Update l10n files 2022-07-31 10:23:00 +02:00
Jonas Jenwald
7543a91086 [Firefox] Remove a couple of webkit CSS rules related to editing
Thanks to the CSS preprocessor, we can get rid of a couple of unnecessary CSS rules in the Firefox PDF Viewer.
2022-07-30 20:07:44 +02:00
Jonas Jenwald
4a38949886 Remove unnecessary color CSS property
This property is first of all unused, and secondly it contained a static value which means that it'd not have worked correctly in light/dark themes.
2022-07-30 19:53:34 +02:00
Jonas Jenwald
0c31320c12 [api-minor] Improve thumbnail handling in documents that contain interactive forms
To improve performance of the sidebar we use the page-canvases to generate the thumbnails whenever possible, since that avoids unnecessary re-rendering when the sidebar is open. This works generally well, however there's an old problem in PDF documents that contain interactive forms (when those are enabled): Note how the thumbnails become partially (or fully) blank, since those Annotations are not included in the OperatorList.[1]

We obviously want to keep using the `PDFThumbnailView.setImage`-method for most documents, however we need a way to skip it only for those pages that contain interactive forms.
As it turns out it's unfortunately not all that simple to tell, after the fact, from looking only at the OperatorList that some Annotations were skipped. While it might have been possible to try and infer that in the viewer, it'd not have been pretty considering that at the time when rendering finishes the annotationLayer has not yet been built.
The overall simplest solution that I could come up with, was instead to include a *summary* of the interactive form-state when doing the final "flushing" of the OperatorList and expose that information in the API.

---
[1] Some examples from our test-suite: `annotation-tx2.pdf` where the thumbnail is completely blank, and `bug1737260.pdf` where the thumbnail is missing the "buttons" found on the page.
2022-07-30 16:53:32 +02:00
Tim van der Meij
c7b71a3376
Merge pull request #15215 from Snuffleupagus/optional-content-initial
[api-minor] Improve how we disable `PDFThumbnailView.setImage` for documents with Optional Content
2022-07-30 12:04:23 +02:00
Jonas Jenwald
ee8fab929c
Merge pull request #15244 from calixteman/15241
[Editor] Add an editor in the annotation storage only when it's non-empty (#15241)
2022-07-29 20:58:53 +02:00
Calixte Denizet
e819834505 [Editor] Add an editor in the annotation storage only when it's non-empty (#15241) 2022-07-29 18:00:52 +02:00
Jonas Jenwald
cfdf940c05
Merge pull request #15242 from calixteman/ink_avoid_move
[Editor] Avoid to slightly move ink editor when undoing/redoing
2022-07-29 17:17:40 +02:00
Jonas Jenwald
6bb800a7e1
Merge pull request #15240 from Snuffleupagus/web-factory-object
[api-minor] Change the various factories, in the viewer, to accept Objects
2022-07-29 17:00:20 +02:00
Calixte Denizet
9a464b70c1 [Editor] Avoid to slightly move ink editor when undoing/redoing 2022-07-29 16:53:03 +02:00
Jonas Jenwald
2e059727a9 [api-minor] Change the various factories, in the viewer, to accept Objects
Currently all of these factories take a bunch of (randomly ordered) parameters, which first of all doesn't look that nice in the `PDFPageView`-class when some parameters are optional.
Furthermore, it also makes deprecation/removal of any existing parameter a *potentially* breaking change.
Finally, using an Object will provide a small amount of "documentation" at the call-site which isn't really the case with a bunch of "regular" parameters.

Note that all of the `viewer component` examples still work as-is with this patch, which is why I don't believe that we necessarily have to deprecate in the usual fashion.
2022-07-29 16:31:04 +02:00
Jonas Jenwald
80689c6444
Merge pull request #15238 from calixteman/bug1782186
Fix wrong order of arguments when calling the CipherTransform ctor (bug 1782186)
2022-07-29 13:22:25 +02:00
Calixte Denizet
d092a85b6c Fix wrong order of arguments when calling the CipherTransform ctor (bug 1782186) 2022-07-29 12:46:45 +02:00
Jonas Jenwald
0c5afe9269
Merge pull request #15232 from calixteman/15229
Fix text selection with hdpi screens (#15229)
2022-07-29 09:50:49 +02:00
Calixte Denizet
51c8e2f3ab Fix text selection with hdpi screens (#15229) 2022-07-28 19:44:13 +02:00
Jonas Jenwald
d7cc47d73a
Merge pull request #15235 from Snuffleupagus/annot-isUsingOwnCanvas
Ensure that the `isUsingOwnCanvas`-parameter is consistently included in operatorLists (PR 14247 follow-up)
2022-07-28 17:04:45 +02:00
Jonas Jenwald
de02d30b00
Merge pull request #15236 from Snuffleupagus/editor-test-opacity
Set `opacity` in the reference tests (PR 15219 follow-up)
2022-07-28 15:56:26 +02:00
Jonas Jenwald
2cad5cf45b Set opacity in the reference tests (PR 15219 follow-up)
Without these changes in the manifest, the affected test-cases fail to render correctly.
2022-07-28 14:35:09 +02:00
Jonas Jenwald
2fb083f3e2 Ensure that the isUsingOwnCanvas-parameter is consistently included in operatorLists (PR 14247 follow-up)
Currently some `OPS.beginAnnotation` arguments will contain a `Number` value for the `isUsingOwnCanvas`-parameter, or in some cases an `undefined` value, which is inconsistent from an API perspective.
2022-07-28 13:37:37 +02:00
Jonas Jenwald
b06d190451
Merge pull request #15217 from calixteman/15216
[Editor] Simplify the strings for the tools in the UI
2022-07-28 10:15:59 +02:00
Calixte Denizet
a85359b031 [Editor] Simplify the strings for the tools in the UI 2022-07-28 10:02:59 +02:00
calixteman
e515a88faf
Merge pull request #15234 from calixteman/reset_undo_queue
[Editor] Reset the queue when a command is added after having undone all the commands
2022-07-28 09:43:10 +02:00
Calixte Denizet
3c10c71a91 [Editor] Reset the queue when a command is added after having undone all the commands 2022-07-27 23:23:28 +02:00
calixteman
085dd0a6c5
Merge pull request #15233 from calixteman/lock_undo
[Editor] Avoid to add unexpected commands in the undo/redo queue when undoing/redoing (bug 1781790)
2022-07-27 20:10:26 +02:00
Calixte Denizet
759116f4c5 [Editor] Avoid to add unexpected commands in the undo/redo queue when undoing/redoing (bug 1781790)
We can undo/redo a command which will at some point add a command in the queue: typically
it can happening when redoing an addition.
So the idea is to lock the queue when undoing/redoing.
2022-07-27 19:12:06 +02:00
calixteman
89d1892959
Merge pull request #15219 from calixteman/editor_opacity
[Editor] Add the possibility to change line opacity in Ink editor
2022-07-27 18:57:37 +02:00
Calixte Denizet
7831a100b3 [Editor] Add the possibility to change line opacity in Ink editor 2022-07-27 18:46:25 +02:00
calixteman
45b9e8417d
Merge pull request #15231 from calixteman/bug1781763
[Editor] Don't set as active an editor which is not (bug 1781763)
2022-07-27 18:45:07 +02:00
calixteman
c9a4062c37
Merge pull request #15230 from calixteman/bug1781762
[Editor] Avoid editor creation/selection on right click (bug 1781762)
2022-07-27 18:27:55 +02:00
Calixte Denizet
ce4144eee4 [Editor] Avoid editor creation/selection on right click (bug 1781762) 2022-07-27 17:53:22 +02:00
Calixte Denizet
59580d8986 [Editor] Don't set as active an editor which is not (bug 1781763) 2022-07-27 14:46:36 +02:00
Jonas Jenwald
8ebd2d3dfd
Merge pull request #15221 from Snuffleupagus/issue-15220
Support images with /Filter-entries that contain Arrays (issue 15220)
2022-07-25 11:14:51 +02:00
calixteman
14a8b819dc
Merge pull request #15218 from calixteman/mac_ctrl
[Editor] Fix few keyboard shortcuts on mac
2022-07-25 09:50:45 +02:00
Jonas Jenwald
fc018ea9ea Support images with /Filter-entries that contain Arrays (issue 15220)
This patch "borrows" the code found in the `Parser.makeInlineImage`-method, to ensure that JBIG2 and JPX images can be rendered correctly.
2022-07-25 08:41:37 +02:00
Calixte Denizet
85f3e23e7f [Editor] Fix few keyboard shortcuts on mac 2022-07-24 22:22:27 +02:00
Jonas Jenwald
37dc0e7d6e Limit the PDFPageView._isStandalone handling to the GENERIC viewer
This code is completely unnecessary in e.g. the Firefox PDF Viewer.
2022-07-24 17:29:37 +02:00
Jonas Jenwald
3446f15bf3 Improve how we disable PDFThumbnailView.setImage for documents with Optional Content (PR 12170 follow-up)
Rather than always disable `PDFThumbnailView.setImage` as soon as user has changed the visibility of the Optional Content, we can utilize the new method added in the previous patch to improve thumbnail performance. Note in particular how, in the old code, even *resetting* of the Optional Content to its default state wouldn't enable `PDFThumbnailView.setImage` again.

While slightly unrelated, this patch also removes the `PDFThumbnailViewer._optionalContentConfigPromise`-property since it's completely unused.
2022-07-24 17:29:37 +02:00
Jonas Jenwald
ceb4f8a6ab [api-minor] Add a new method, in OptionalContentConfig, to detect the initial Optional Content visibility state
This will allow us to improve the `PDFThumbnailView.setImage` handling in the viewer, and thanks to the added caching this should be reasonbly efficient.
2022-07-24 17:29:37 +02:00
Jonas Jenwald
f3d76b42b3 Ensure that OptionalContentGroup.visible cannot be modified from the "outside"
Given that Optional Content visibility is only intended/supported to be updated via the `OptionalContentConfig.setVisibility`-method, this patch actually enforces that now.
Note that this will be used by the next patch in the series, and will help prevent inconsistent state in the `OptionalContentConfig`-class.

*Please note:* This patch also uncovered a pre-existing bug, related to iterating through the visibility groups in the constructor, for the `baseState === "OFF"` case.
2022-07-24 17:28:08 +02:00
Jonas Jenwald
2d6ebc5801 Convert the OptionalContentConfig to use *properly* private fields/methods
To ensure that this data cannot be directly changed from the outside, use private fields/methods now that those are available.
2022-07-24 13:40:59 +02:00
Tim van der Meij
9cc5260b68
Merge pull request #15214 from Snuffleupagus/update-packages
Update packages and translations
2022-07-24 12:17:47 +02:00
Jonas Jenwald
ca9172ddec Update l10n files 2022-07-24 08:56:47 +02:00
Jonas Jenwald
878e2f726a Update npm packages 2022-07-24 08:54:23 +02:00
Jonas Jenwald
bf00068731
Merge pull request #15211 from calixteman/selection
[Editor] Fix multi-selection on touch screens
2022-07-22 16:55:12 +02:00
Calixte Denizet
a118e268af [Editor] Fix multi-selection on touch screens 2022-07-22 16:11:58 +02:00
calixteman
71db08a139
Merge pull request #15188 from calixteman/touch
[Editor] Replace mouse events by pointer ones (bug 1779015)
2022-07-22 14:14:38 +02:00
Calixte Denizet
7b25b39a17 [Editor] Replace mouse events by pointer ones (bug 1779015)
The goal is to be able to edit a pdf on a touchscreen.
2022-07-22 13:46:39 +02:00
calixteman
185102bd69
Merge pull request #15210 from calixteman/ink_select
[Editor] Unselect correctly removed editors
2022-07-22 13:31:08 +02:00
Calixte Denizet
5bbe0d0782 [Editor] Unselect correctly removed editors
- After undoing a deletion of several editors, they appeared to be selected (they had a red border)
when in fact they were not, consequently, this patch aims to remove the selectedEditor class when
an editor is removed;
- Add a test with some ink editors.
2022-07-22 13:21:08 +02:00
calixteman
6138e16ce2
Merge pull request #15200 from calixteman/multiple_selection
[Editor] Add the ability to make multiple selections (bug 1779582)
2022-07-21 23:15:16 +02:00
Calixte Denizet
d6b9ca48a5 [Editor] Add the ability to make multiple selections (bug 1779582)
- several editors can be selected/unselected using ctrl+click;
- and then they can be copied, pasted, their properties can be changed.
2022-07-21 22:53:52 +02:00
calixteman
9fe4a667bd
Merge pull request #15206 from calixteman/simplify_command_manager
[Editor] Simplify the command manager
2022-07-21 22:13:49 +02:00
Tim van der Meij
e2f6ec83d6
Merge pull request #15183 from Snuffleupagus/rm-svgviewer-example
Remove the `svgviewer` example
2022-07-21 20:18:54 +02:00
Calixte Denizet
af41a5cb49 [Editor] Simplify the command manager
The previous version was maybe functional but definitely painful to maintain
(maybe more efficient... I don't know) so this patch aims to simplify it and
it adds some basic unit tests.
2022-07-21 18:44:41 +02:00
Jonas Jenwald
f4e60ae986 Limit even more SVG-specific code to the GENERIC viewer
Given that the SVG back-end is not defined anywhere except in GENERIC builds, we can remove a bit more unnecessary code in e.g. the Firefox PDF Viewer.
2022-07-21 10:03:02 +02:00
Jonas Jenwald
bf7eef7109 Remove the svgviewer example
Given that the SVG back-end is now deprecated, we probably don't need to keep this example around any more.
2022-07-21 09:59:10 +02:00
Jonas Jenwald
5e7eab4dd8
Merge pull request #15196 from calixteman/zindex
[Editor] Add a z-index in order to draw them in the right order
2022-07-21 09:38:12 +02:00
Jonas Jenwald
c78fbe5282
Merge pull request #15199 from mozilla/dependabot/npm_and_yarn/terser-5.14.2
Bump terser from 5.14.1 to 5.14.2
2022-07-21 09:17:41 +02:00
dependabot[bot]
a5b50d06bd
Bump terser from 5.14.1 to 5.14.2
Bumps [terser](https://github.com/terser/terser) from 5.14.1 to 5.14.2.
- [Release notes](https://github.com/terser/terser/releases)
- [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/terser/terser/commits)

---
updated-dependencies:
- dependency-name: terser
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-21 06:01:41 +00:00
Calixte Denizet
a7a5e98b7e [Editor] Add a z-index in order to draw them in the right order
The elements in the annotationEditor layer are rearranged to make them
more accessible, but we must draw them in the order they have been created,
hence this patch adds a z-index to the editors.
2022-07-20 15:47:43 +02:00
calixteman
408c10b5bb
Merge pull request #15195 from calixteman/empty_editor
[Editor] No need to click twice to create an editor when the last one is empty
2022-07-20 14:29:16 +02:00
Calixte Denizet
6d0676fd86 [Editor] No need to click twice to create an editor when the last one is empty 2022-07-20 14:15:00 +02:00
Jonas Jenwald
a9fc8792c8
Merge pull request #15192 from Snuffleupagus/issue-15139
Ignore invalid /CIDToGIDMap-entries when parsing fonts (issue 15139)
2022-07-20 12:45:04 +02:00
calixteman
f18a27bee9
Merge pull request #15186 from calixteman/freetext_commit
[Editor] Move the keyboard manager at the container level
2022-07-20 12:38:31 +02:00
Calixte Denizet
e1f28d3504 [Editor] Move the keyboard manager at the container level
- This way, the keyboard callbacks are called even if the page has not
the focus, hence the user doesn't have to guess that they have to click
on the page which is a bit painful especially in Ink mode.
- Add two keyboard shortcuts to commit a Freetext editor (ctrl+enter and
escape).
2022-07-20 12:24:30 +02:00
Jonas Jenwald
60bd9580e2 Ignore invalid /CIDToGIDMap-entries when parsing fonts (issue 15139)
In the referenced PDF document the fonts have /CIDToGIDMap-entries that cannot be loaded. Hence, only when `ignoreErrors` is set, we'll now ignore these corrupt /CIDToGIDMap-entries and fallback to simply assume that no such data is available.

Given that this is *clearly* a case of a corrupt PDF document, there's no guarantee that this will "fix" things in the general case since a /CIDToGIDMap may be *required* in order for some composite fonts to render correctly. However, attempting to render *something* is surely better than skipping a font altogether.
2022-07-20 11:58:44 +02:00
calixteman
7a4b72ed11
Merge pull request #15185 from calixteman/ink_translation
[Editor] Ink editor was too much translated after commit
2022-07-20 10:34:37 +02:00
calixteman
33d7a35515
Merge pull request #15187 from calixteman/rm_useless_ed
[Editor] Remove useless and potentially deleted editors
2022-07-20 10:04:22 +02:00
Calixte Denizet
964fb77fa5 [Editor] Remove useless and potentially deleted editors
After a deletion, a reference on a deleted editor can still be used
(for example in changing the font size just after having deleted all
editors).
2022-07-19 23:04:33 +02:00
Jonas Jenwald
f46895d750
Merge pull request #15110 from calixteman/editing_a11y
[Editor] Improve a11y for newly added element (#15109)
2022-07-19 20:02:53 +02:00
Jonas Jenwald
98f70d87f6
Merge pull request #15174 from Snuffleupagus/more-for-of
Use more `for...of` loops in the code-base
2022-07-19 19:04:47 +02:00
Calixte Denizet
624b26e1de [Editor] Improve a11y for newly added element (#15109)
- In the annotationEditorLayer, reorder the editors in the DOM according
  the position of the elements on the screen;
- add an aria-owns attribute on the "nearest" element in the text layer
  which points to the added editor.
2022-07-19 18:52:17 +02:00
calixteman
ad15532235
Merge pull request #15179 from calixteman/editor_cp
[Editor] Use serialized data when copying/pasting
2022-07-19 18:31:37 +02:00
calixteman
642676a3b7
Merge pull request #15184 from calixteman/rm_allowclick
[Editor] Simplify the way to create an editor on click
2022-07-19 17:56:07 +02:00
Calixte Denizet
3c17dbb43e [Editor] Use serialized data when copying/pasting
- in using the global clipboard, it'll be possible to copy from a
  pdf and paste in an other one;
- it'll allow to edit a previously created annotation;
- copy the editors in the current page.
2022-07-19 17:54:06 +02:00
Calixte Denizet
7024a53e79 [Editor] Simplify the way to create an editor on click
Previously, we had to set the #allowClick property by hand which was
a bit painful because it's easy to overlook one case or an other.
So with this patch a new editor (for now FreeText one only because the
Ink one is a bit different) is created on the first click if none is selected
on mousedown, else the first click will just commit the data and then the
second will creater a new editor.
2022-07-19 17:41:35 +02:00
Calixte Denizet
35671127d9 [Editor] Ink editor was too much translated after commit
The problem is clearly visible when the thickness is at max.
It's mainly because the thickness was not taken into account when
translating the div but it was when the line is drawn on the canvas.
2022-07-19 17:33:34 +02:00
Jonas Jenwald
37ebc28756 Use more for...of loops in the code-base
Note that these cases, which are all in older code, were found using the [`unicorn/no-for-loop`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-for-loop.md) ESLint plugin rule.
However, note that I've opted not to enable this rule by default since there's still *some* cases where I do think that it makes sense to allow "regular" for-loops.
2022-07-17 16:18:54 +02:00
Tim van der Meij
5bfba89b0a
Merge pull request #15173 from Snuffleupagus/deprecated-svg
[api-minor] Deprecate the SVG back-end
2022-07-17 12:47:58 +02:00
Jonas Jenwald
290aeaf755 Limit more SVG-specific code to the GENERIC viewer
Given that the SVG back-end is not defined anywhere except in GENERIC builds, we can remove a little bit more unnecessary code in e.g. the Firefox PDF Viewer.
2022-07-16 11:24:09 +02:00
Jonas Jenwald
90bf659b29 [api-minor] Deprecate the SVG back-end 2022-07-16 10:24:24 +02:00
Jonas Jenwald
de7d1d2167
Merge pull request #15170 from calixteman/js_rm_null
[JS] Embedded JS scripts can have some null chars
2022-07-15 17:11:29 +02:00
Jonas Jenwald
75b8647a32
Merge pull request #15169 from Snuffleupagus/loadFont-fontRef
Handle errors in the "Loading by ref" code-path in `PartialEvaluator.loadFont`
2022-07-15 16:40:56 +02:00
Jonas Jenwald
acd61a138e Handle errors in the "Loading by ref" code-path in PartialEvaluator.loadFont
Note how we currently throw a "raw" Error, which is problematical since all of the `PartialEvaluator.loadFont` call-sites expect a Promise to be returned. Furthermore, this also means that we don't benefit from the fallback code-path that now exists below.

*Please note:* Unfortunately I don't have a test-case that fails without this patch, since it's something I happened to notice when reading the code while working on another patch.
2022-07-15 16:33:36 +02:00
Calixte Denizet
5f0c95e70e [JS] Embedded JS scripts can have some null chars 2022-07-15 16:05:25 +02:00
calixteman
3256761ead
Merge pull request #15168 from calixteman/disable_canvas_acc
Disable canvas acceleration for linux tests
2022-07-15 14:43:30 +02:00
Calixte Denizet
ad62ae561c Disable canvas acceleration for linux tests 2022-07-15 13:31:37 +02:00
calixteman
41b2f52f70
Merge pull request #15157 from calixteman/1778484
Add unicode mapping in the font cmap to have correct chars when printing in pdf (bug 1778484)
2022-07-13 14:45:12 +02:00
Calixte Denizet
680c293c34 Add unicode mapping in the font cmap to have correct chars when printing in pdf (bug 1778484)
It aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1778484.
2022-07-13 14:38:27 +02:00
Jonas Jenwald
b4a3fd31c8
Merge pull request #15162 from Snuffleupagus/prefer-logical-operator-over-ternary
Enable the `unicorn/prefer-logical-operator-over-ternary` ESLint plugin rule
2022-07-13 09:50:04 +02:00
calixteman
1301b71b7c
Merge pull request #15163 from calixteman/prepare_touch
[Editor] Always have an ink editor (when in ink mode)
2022-07-12 19:35:32 +02:00
Calixte Denizet
2df2defa02 [Editor] Always have an ink editor (when in ink mode)
Previously it was created only on mouseover event but on a touch screen
there are no fingerover event...
The idea behind creating the ink editor on mouseover was to avoid to have
a canvas on each visible page.
So now, when the editor is created, the canvas has dimensions 1x1 and
only when the user starts drawing the dimensions are set to the page ones.
2022-07-12 19:18:37 +02:00
Jonas Jenwald
dcc73423e5 Enable the unicorn/prefer-logical-operator-over-ternary ESLint plugin rule
This leads to ever so slightly more compact code, and can in some cases remove the need for a temporary variable.

Please find additional information here:
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-logical-operator-over-ternary.md
2022-07-12 10:52:37 +02:00
calixteman
aa6512e70f
Merge pull request #15159 from calixteman/1778982
[Editor] Avoid to have the ink editor smaller than the resizer (bug 1778982)
2022-07-11 18:53:16 +02:00
Calixte Denizet
1b3c0f1799 [Editor] Avoid to have the ink editor smaller than the resizer (bug 1778982) 2022-07-11 17:00:34 +02:00
Jonas Jenwald
e572bc4e76
Merge pull request #15158 from timvandermeij/ttx
Update `ttx` from version 2.5 to version 3.19.0
2022-07-11 11:05:34 +02:00
Tim van der Meij
3d4476ac53
Update ttx from version 2.5 to version 3.19.0
The current version 2.5 is from September 2014, which is almost 8 years
old now. The new version 3.19.0 is from November 2017, which is still
almost 5 years old, but is a step forward towards eventually using the
most recent version. Note that we currently can't update any further;
see #11802 for the details.

Fortunately using this newer version only required a few changes:

- The `ttx` output regexes needed updating to ignore comments that `ttx`
  now puts after some XML nodes (`<!-- ... -->` and `/* ... */`).
- The `ttx` invocation now explicitly uses `python2` (except on Windows
  where this alias doesn't exist) since otherwise the font tests can't
  be run on modern systems anymore given that `python` is nowadays an
  alias for `python3`, and it now points at the new location of the
  `ttx.py` file since the `Tools` folder got removed.
- The note about needing a 32-bit Python 2.6 version is dropped since
  it's obsolete: this version (and also the existing one already) work
  just fine on a 64-bit Python 2.7 as well.
2022-07-10 21:18:36 +02:00
Jonas Jenwald
0205597bd0
Merge pull request #15154 from Snuffleupagus/xfa-rm-id
Replace element `id`s with custom attributes in the xfaLayer
2022-07-10 16:06:17 +02:00
Jonas Jenwald
4b7bf74da2 Replace element ids with custom attributes in the xfaLayer
We want to avoid adding regular `id`s to xfaLayer-elements, since that means that they become "linkable" through the URL hash in a way that's not supported/intended. This could end up clashing with "named destinations", and that could easily lead to bugs; see issue 11499 and PR 11503 for some context.

Rather than using `id`s, we'll instead use a *custom* `data-element-id` attribute such that it's still possible to access the DOM-elements directly if needed. *Please note:* This is basically the xfaLayer-equivalent of PR 15057.
2022-07-10 15:44:54 +02:00
Tim van der Meij
fb1340f74b
Merge pull request #15155 from Snuffleupagus/update-packages
Update packages and translations
2022-07-10 12:49:41 +02:00
Jonas Jenwald
e4a7264564 Update l10n files 2022-07-10 10:45:22 +02:00
Jonas Jenwald
dd10f6397f Update npm packages 2022-07-10 10:43:08 +02:00
Tim van der Meij
220f980e12
Merge pull request #15145 from Snuffleupagus/deprecated-enhanceTextSelection
[api-minor] Deprecate the `enhanceTextSelection` functionality
2022-07-09 12:38:41 +02:00
calixteman
2b6a67c5d0
Merge pull request #15153 from calixteman/1778692
[Annotation] A push button can have no action (bug 1778692)
2022-07-08 21:06:53 +02:00
Calixte Denizet
8f26ba5487 [Annotation] A push button can have no action (bug 1778692) 2022-07-08 15:39:56 +02:00
Jonas Jenwald
4b493c2c33
Merge pull request #15152 from Snuffleupagus/validate-Resources
Ensure that the /Resources-entry is actually a dictionary (issue 15150)
2022-07-08 13:24:47 +02:00
Jonas Jenwald
c2f7942aea Ensure that the /Resources-entry is actually a dictionary (issue 15150)
Prevent issues in *corrupt* PDF documents, if the /Resources-entry is not of the correct and expected type.
2022-07-08 12:43:43 +02:00
Jonas Jenwald
efbd429115
Merge pull request #15151 from calixteman/15149
[Editor] Remove useless and faulty code when destroying the global manager
2022-07-08 11:58:14 +02:00
Calixte Denizet
cec2172225 [Editor] Remove useless and faulty code when destroying the global manager 2022-07-08 11:49:19 +02:00
calixteman
b0a3c9e8cf
Merge pull request #15135 from calixteman/forced_colors
Use default colors only in forced-colors mode (bug 1778068)
2022-07-07 20:30:03 +02:00
calixteman
657edb3892
Merge pull request #15147 from calixteman/editor_size
[Editor] Avoid to resize and redraw the ink canvas when it's useless
2022-07-07 19:49:59 +02:00
Calixte Denizet
fe93742c8f Use default colors only in forced-colors mode (bug 1778068) 2022-07-07 19:36:03 +02:00
Jonas Jenwald
d6a75262d5
Merge pull request #15143 from bernatgy/typescript-compilation-fix
[jsdoc] failing typescript builds - wrong type
2022-07-07 19:27:53 +02:00
calixteman
32d8c55642
Merge pull request #15146 from calixteman/editing_cursor
[Editor] Change the cursor to a pen for the Ink editor
2022-07-07 18:43:41 +02:00
Calixte Denizet
9c4077ebc4 [Editor] Avoid to resize and redraw the ink canvas when it's useless
- and because of rounding errors it led to slightly resize again and again
the ink container;
- when zooming the size is changing but not the ratio, so in this case we
don't need to change the dimension of the container.
2022-07-07 18:39:20 +02:00
Calixte Denizet
edc9ad13bf [Editor] Change the cursor to a pen for the Ink editor 2022-07-07 18:23:59 +02:00
Bernát Gyovai
3d62f09fbd [jsdoc] failing typescript builds - wrong type
`HTMLSectionElement` is not part of the DOM, so the generated typescript definitions contain a non-existing type.

HTML Section elements have to be handled as simple `HTMLElements`.

fixing punctuation and lint problems

[jsdoc] failing typescript builds - wrong type
2022-07-07 17:03:46 +02:00
Jonas Jenwald
815c28da0e [api-minor] Deprecate the enhanceTextSelection functionality 2022-07-07 16:15:31 +02:00
calixteman
403ed07ad9
Merge pull request #15144 from calixteman/editing_delete
[Editor] Allow editors deletion on Backspace or Delete keys
2022-07-07 15:37:06 +02:00
Calixte Denizet
a4329d326c [Editor] Allow editors deletion on Backspace or Delete keys 2022-07-07 15:16:01 +02:00
Jonas Jenwald
7f160d49f9
Merge pull request #15142 from Snuffleupagus/fitCurve
[editor] Use the `fit-curve` package (issue 15004)
2022-07-07 14:03:14 +02:00
Jonas Jenwald
345bb18575 [editor] Use the fit-curve package (issue 15004)
Rather than including all of this external code in the PDF.js repository, we should be using the npm package instead.
Unfortunately this is slightly more complicated than you'd hope, since the `fit-curve` package (which is older) isn't directly compatible with modern JavaScript modules.
In particular, the following cases needed to be considered:
 - For the development viewer (i.e. `gulp server`) and the unit-tests, we thus need to build a fitCurve-bundle that can be directly `import`ed.
 - For the actual PDF.js build-targets, we can slightly reduce the sizes by depending on the "raw" `fit-curve` source-code.
 - For the Node.js unit-tests, the `fit-curve` package can be used as-is.
2022-07-07 10:43:43 +02:00
Jonas Jenwald
bde46632d4
Merge pull request #15130 from calixteman/context_menu
[Editor] Dispatch an event when some global states are changing (bug 1777695)
2022-07-05 22:40:12 +02:00
Calixte Denizet
ec0f9f6dcf [Editor] Dispatch an event when some global states are changing
- this way the context menu in Firefox can take into account what we
  have in the clipboard, if an editor is selected, ...
- when the user will click on a context menu item, an action will be
  triggered, hence this patch adds what is required to handle it;
- some tests will be added in the Firefox' patch.
2022-07-05 22:12:56 +02:00
Jonas Jenwald
45fafb2769
Merge pull request #15133 from Snuffleupagus/issue-14999
Improve text-selection for Type3 fonts with bogus /FontBBox-entries (issue 14999)
2022-07-05 22:00:28 +02:00
Jonas Jenwald
79cfc548fc Improve text-selection for Type3 fonts with bogus /FontBBox-entries (issue 14999)
This extends PR 13461, by also building a fallback bounding box for Type3 fonts that contain a much too small /FontBBox-entry.

*Please note:* While this patch improves things overall, copy-and-pasting still doesn't work perfectly for this document. In particular the lowercase letter "c" cannot be selected/copied, however this can be reproduced in both Adobe Reader and PDFium (in Google Chrome) too, which is caused by a lack of proper /ToUnicode-data in the PDF document.
2022-07-05 14:27:14 +02:00
Jonas Jenwald
a1ac1a61b7
Merge pull request #15124 from Snuffleupagus/private-setDimensions
Call `AnnotationLayer.setDimensions` as part of the `render`/`update`-methods (PR 15036 follow-up)
2022-07-04 14:05:47 +02:00
Jonas Jenwald
552ee9decd Call AnnotationLayer.setDimensions as part of the render/update-methods (PR 15036 follow-up)
Rather than forcing the user to *manually* call `setDimensions`, which is also breaking any existing third-party code, it seems that we can simply let the `AnnotationLayer.{render, update}`-methods handle that internally.

As far as I can tell, based on testing manually in the viewer *and* running the browser-tests, everything still appears to work correctly with this patch.
2022-07-04 12:27:20 +02:00
Jonas Jenwald
ca8b112e8c
Merge pull request #15125 from Snuffleupagus/FileAttachmentAnnotationElement-trigger
Fix the Popup-trigger for `FileAttachmentAnnotationElement` (PR 15036 follow-up)
2022-07-04 11:00:24 +02:00
Jonas Jenwald
fda0a87cb5
Merge pull request #15126 from calixteman/update_l10n_id
[Editor] Update the id for a l10n string
2022-07-04 10:59:26 +02:00
Calixte Denizet
ae2cf7e1e7 [Editor] Update the id for a l10n string 2022-07-04 10:18:42 +02:00
Jonas Jenwald
315f450b01 Fix the Popup-trigger for FileAttachmentAnnotationElement (PR 15036 follow-up)
After the changes in PR 15036, the trigger-element created in `FileAttachmentAnnotationElement.render` is now too small. This can be fixed by using the same approach as in PR 15065, and the patch can be tested using the `annotation-fileattachment.pdf` document in the test-suite.
2022-07-04 09:33:27 +02:00
Jonas Jenwald
03c6febc44
Merge pull request #15121 from Snuffleupagus/loadingBar-cleanup
[api-minor] Further modernize the `ProgressBar` class (PR 14918 follow-up)
2022-07-02 16:46:40 +02:00
Jonas Jenwald
845b7f06f9
Merge pull request #15123 from Snuffleupagus/editor-presentation-disable
[editor] Disable editing while PresentationMode is active
2022-07-02 16:39:38 +02:00
Jonas Jenwald
ff0ff75d22
Merge pull request #15122 from Snuffleupagus/editor-max-width
[editor] Tweak `@media` CSS rules to account for the new toolbar buttons
2022-07-02 16:38:21 +02:00
Jonas Jenwald
37b61f2228 [editor] Disable editing while PresentationMode is active 2022-07-01 16:52:17 +02:00
Jonas Jenwald
84ae9f9c58 [editor] Tweak @media CSS rules to account for the new toolbar buttons 2022-07-01 13:27:13 +02:00
Jonas Jenwald
d9ce17642f [api-minor] Further modernize the ProgressBar class (PR 14918 follow-up)
- Simplify how we look-up the DOM-element, which should also be a tiny bit more efficent.

 - Use private class-fields, rather than property-names prefixed with underscores.

 - Inline the `#updateBar` helper-method directly in the `percent`-setter, since having a separate method doesn't seem necessary in this case.

 - Set the `indeterminate`-class on the ProgressBar DOM-element, to simplify the code.

Finally, also (slightly) re-factors the `PDFViewerApplication.progress`-method to make it a bit smaller.
2022-07-01 10:31:25 +02:00
Jonas Jenwald
13c01b6d4a
Merge pull request #15115 from calixteman/editing_a11y_bis
[Editor] Handle correctly colors when saving a document in HCM
2022-06-30 10:31:22 +02:00
Calixte Denizet
9723c5d377 [Editor] Handle correctly colors when saving a document in HCM
- for example in Dusk theme (Windows 11), black appears to be white, so
  the user will draw something in white. But if they want to print or
  save the used color must be black.
- fix a bug with the color input which only accepts hex string colors;
- adjust outline color of the selected/hovered editors in HCM.
2022-06-30 09:56:34 +02:00
calixteman
a520fc9d9a
Merge pull request #15118 from calixteman/editor_selection
[Editor] Allow to select a freetext editor when in ink mode
2022-06-29 19:49:13 +02:00
Calixte Denizet
a694e360a4 [Editor] Allow to select a freetext editor when in ink mode
- and when in ink mode, change the toolbar active button when
  a freetext edited.
2022-06-29 19:35:40 +02:00
calixteman
2e83fa8e2d
Merge pull request #15117 from calixteman/freetext_resize
[Editor] Set the freetext editor dimensions when the changing the font size
2022-06-29 16:38:15 +02:00
Jonas Jenwald
8c15f5a639
Merge pull request #15116 from Snuffleupagus/pr-15113-followup
Fix the `annotationEditorMode`-compatibility for older browsers (PR 15113 follow-up)
2022-06-29 16:25:33 +02:00
Jonas Jenwald
63f2d0bb64 Fix the annotationEditorMode-compatibility for older browsers (PR 15113 follow-up) 2022-06-29 16:16:48 +02:00
Calixte Denizet
bc5b6cd08c [Editor] Set the freetext editor dimensions when the changing the font size 2022-06-29 16:11:11 +02:00
calixteman
ce63663282
Merge pull request #15111 from calixteman/1776914
Add a visible page border in HCM (bug 1776914)
2022-06-29 14:43:56 +02:00
Jonas Jenwald
e08b079691
Merge pull request #15113 from Snuffleupagus/annotationEditorMode-pref
[editor] Introduce a proper `annotationEditorMode` option/preference (PR 15075 follow-up)
2022-06-29 13:39:55 +02:00
Calixte Denizet
3e751679ba Add a visible page border in HCM (bug 1776914) 2022-06-29 11:52:19 +02:00
Jonas Jenwald
44a75c2a0f [editor] Slightly shorten the en-US freetext_default_content placeholder text
Now that it's possible to change the font-size, this placeholder string feels a little bit long (especially for larger font-sizes).

Given that Editing is not enabled/released yet, I hope that it should be fine to update this without changing the l10n-id.
2022-06-29 11:40:54 +02:00
Jonas Jenwald
f3ba02bc00 [editor] Remove the unused name-property from the editorParamsToolbars DOM elements
As far as I can tell, this is completely unused and can thus be removed.
2022-06-29 11:40:54 +02:00
Jonas Jenwald
4a4c6b9851 [editor] Introduce a proper annotationEditorMode option/preference (PR 15075 follow-up)
This replaces the boolean `annotationEditorEnabled` option/preference with a "proper" `annotationEditorMode` one. This way it's not only possible for the user to control if Editing is enabled/disabled, but also which *specific* Editing-mode should become enabled upon PDF document load.

Given that Editing is not enabled/released yet, I cannot imagine that changing the name and type of the option/preference should be an issue.
2022-06-29 11:35:58 +02:00
Jonas Jenwald
f1d4015508
Merge pull request #15039 from calixteman/params
[editor] Add some UI elements in order to set font size & color, and ink thickness & color
2022-06-28 13:25:04 +02:00
Calixte Denizet
1a3ef2a0aa [editor] Add some UI elements in order to set font size & color, and ink thickness & color 2022-06-28 12:05:04 +02:00
Jonas Jenwald
4e025e1f08
Merge pull request #15105 from calixteman/15094
Always flush the current item with MarkedContent stuff when getting text (#15094)
2022-06-25 18:24:33 +02:00
Jonas Jenwald
f208107276
Merge pull request #15104 from timvandermeij/updates
Update translations and dependencies to the most recent versions
2022-06-25 17:50:17 +02:00
Calixte Denizet
3789dab307 Always flush the current item with MarkedContent stuff when getting text (#15094) 2022-06-25 17:19:57 +02:00
Tim van der Meij
38daef065a
Update dependencies to the most recent versions
Note that even though Puppeteer got a major version bump the changelog
doesn't include compatibility changes that are relevant to us; please
see https://github.com/puppeteer/puppeteer/releases.
2022-06-25 16:28:44 +02:00
calixteman
23fcdabb37
Merge pull request #15088 from calixteman/editor_rotation
Support rotating editor layer
2022-06-25 16:18:07 +02:00
Tim van der Meij
f7d69aab15
Update translations to the most recent versions 2022-06-25 15:45:55 +02:00
Tim van der Meij
def1a30d3e
Merge pull request #15103 from timvandermeij/permissions
chore: Set permissions for GitHub actions
2022-06-25 15:39:19 +02:00
neilnaveen
83ecc3f46c
chore: Set permissions for GitHub actions
Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much.

- Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs

[Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)

Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
2022-06-25 15:32:33 +02:00
Tim van der Meij
8403bafbfc
Merge pull request #15100 from turrisxyz/Dependabot-GitHub-Actions
chore: Included githubactions in the dependabot config
2022-06-25 15:18:11 +02:00
Tim van der Meij
f93ab76fa8
Merge pull request #15099 from Snuffleupagus/layers-rm-id
Remove element `id`s from the layersView in the sidebar
2022-06-25 14:58:18 +02:00
Tim van der Meij
b8a7cf7aed
Merge pull request #15101 from Snuffleupagus/browsertest-use-viewer-css
Use the *built* `components/pdf_viewer.css` file in the reference tests
2022-06-25 14:53:04 +02:00
Jonas Jenwald
c0f65657a2 Use the *built* components/pdf_viewer.css file in the reference tests
Currently we're loading the `web/annotation_layer_builder.css` and `web/xfa_layer_builder.css` files *directly* during the reference tests.
This becomes a problem is we want to reduce duplication in the CSS-files, e.g. by placing *common* rules in the `web/pdf_viewer.css` file.

Given that `gulp components` is already being utilized when running tests, we can thus use that to instead depend on the *entire* viewer-components CSS-file in the reference tests.
2022-06-25 09:54:05 +02:00
naveen
12c76d35a5 chore: Included githubactions in the dependabot config
This should help with keeping the GitHub actions updated on new releases. This will also help with keeping it secure.

Dependabot helps in keeping the supply chain secure https://docs.github.com/en/code-security/dependabot

GitHub actions up to date https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot

https://github.com/ossf/scorecard/blob/main/docs/checks.md#dependency-update-tool
Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com>
2022-06-25 01:30:04 +00:00
Jonas Jenwald
9748d3eb85 Remove element ids from the layersView in the sidebar
Similar to other recent patches, see e.g. PR 15057, we don't want to add these kind of `id`s to DOM-elements since they shouldn't become "linkable" through the URL hash.

*Please note:* This patch can be tested, in the viewer, with e.g. `bug1737260.pdf` from the test-suite.
2022-06-24 20:15:46 +02:00
Calixte Denizet
0c420f5135 Support rotating editor layer
- As in the annotation layer, use percent instead of pixels as unit;
- handle the rotation of the editor layer in allowing editing when rotation
  angle is not zero;
- the different editors are rotated counterclockwise in order to be usable
  when the main page is itself rotated;
- add support for saving/printing rotated editors.
2022-06-24 20:02:32 +02:00
Jonas Jenwald
cd35b9bfac
Merge pull request #15095 from Snuffleupagus/Annotation-OC
Add (basic) support for Optional Content in Annotations
2022-06-24 19:10:11 +02:00
Jonas Jenwald
8b8b4e0e6e
Merge pull request #15097 from calixteman/ut_fu
Fix unit test (#15093 follow-up)
2022-06-24 19:08:18 +02:00
Calixte Denizet
6e46226cd7 Fix unit test (#15093 follow-up) 2022-06-24 18:55:35 +02:00
calixteman
b5fea8ff14
Merge pull request #15093 from calixteman/issue15092
[JS] Update siblings when a field is updated after a calculation (#15092)
2022-06-24 16:17:59 +02:00
Jonas Jenwald
c48dc251e0 Add (basic) support for Optional Content in Annotations
Given that Annotations can also have an `OC`-entry, we need to take that into account when generating their operatorLists.

Note that in order to simplify the patch the `getOperatorList`-methods, for the Annotation-classes, were converted to be `async`.
2022-06-24 15:19:56 +02:00
Calixte Denizet
a334a21a1d [JS] Update siblings when a field is updated after a calculation (#15092) 2022-06-24 14:23:06 +02:00
Jonas Jenwald
3fab4af949
Merge pull request #15043 from Snuffleupagus/PrintAnnotationStorage
[api-minor] Introduce a `PrintAnnotationStorage` with *frozen* serializable data
2022-06-24 09:30:07 +02:00
calixteman
eace7e4c63
Merge pull request #15089 from calixteman/editor_overlap
Correctly order added annotations when saving or printing
2022-06-23 18:29:27 +02:00
Calixte Denizet
e49d039853 Correctly order added annotations when saving or printing
- the annotations must be rendered in the same order as the chronological one.
- fix a bug in document.js which avoids to read a saved pdf correctly in Acrobat:
  there is no need to reset the xref state: it's done in worker.js once everything
  has been saved.
2022-06-23 17:39:12 +02:00
Jonas Jenwald
1cc7cecc7b [api-minor] Introduce a PrintAnnotationStorage with *frozen* serializable data
Given that printing is triggered *synchronously* in browsers, it's thus possible for scripting (in PDF documents) to modify the Annotation-data while printing is currently ongoing.
To work-around that we add a new printing-specific `AnnotationStorage`, where the serializable data is *frozen* upon initialization, which the viewer can thus create/utilize during printing.
2022-06-23 17:06:46 +02:00
calixteman
c5dc082da4
Merge pull request #15082 from calixteman/print_freetext
[Editor] Add support for printing newly added FreeText annotations
2022-06-22 16:19:42 +02:00
Calixte Denizet
30c63eb0ec [Editor] Add support for printing newly added FreeText annotations 2022-06-22 13:26:09 +02:00
Jonas Jenwald
d72a85fa46
Merge pull request #15081 from Snuffleupagus/typedef-import-IPDFXfaLayerFactory
Fix (obvious) typo in typedef-import of `IPDFXfaLayerFactory` (PR 14373 follow-up)
2022-06-22 11:15:23 +02:00
Jonas Jenwald
d7c9a0a793 Fix (obvious) typo in typedef-import of IPDFXfaLayerFactory (PR 14373 follow-up)
This only affects the viewer-components TypeScript definitions, and not any actual code.
2022-06-22 11:06:11 +02:00
Jonas Jenwald
eca939d904
Merge pull request #15076 from Snuffleupagus/prefer-array-index-of
Enable the `prefer-array-index-of` ESLint plugin rule
2022-06-21 18:57:51 +02:00
calixteman
c7a18bd773
Merge pull request #15047 from calixteman/editor_printing
[Editor] Add support for printing newly added Ink annotations
2022-06-21 18:33:13 +02:00
Calixte Denizet
f27c8c4471 [Editor] Add support for printing newly added Ink annotations 2022-06-21 18:21:49 +02:00
calixteman
8d466f5dac
Merge pull request #15060 from calixteman/annotation_rotation
Rotate annotations based on the MK::R value (bug 1675139)
2022-06-21 18:03:09 +02:00
Calixte Denizet
cdc58b7a52 Rotate annotations based on the MK::R value (bug 1675139)
- it aims to fix: https://bugzilla.mozilla.org/show_bug.cgi?id=1675139;
- An annotation can be rotated (counterclockwise);
- the rotation can be set in using JS.
2022-06-21 17:57:26 +02:00
Jonas Jenwald
1c9a702f73 Enable the prefer-array-index-of ESLint plugin rule
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-index-of.md
2022-06-21 16:54:32 +02:00
Jonas Jenwald
05cab5c17d
Merge pull request #15075 from Snuffleupagus/issue-15049
[editor] Support disabling of editing when `pdfjs.enablePermissions` is set (issue 15049)
2022-06-21 15:59:39 +02:00
Jonas Jenwald
db6f675baa
Merge pull request #15069 from Snuffleupagus/annotationLayer-dimensions
Ensure that the annotationLayer has the correct dimensions (PR 15036 follow-up)
2022-06-21 15:57:21 +02:00
Jonas Jenwald
35a6a508ee [editor] Support disabling of editing when pdfjs.enablePermissions is set (issue 15049)
For encrypted PDF documents without the required permissions set, this patch adds support for disabling of Annotation-editing. However, please note that it also requires that the `pdfjs.enablePermissions` preference is set to `true` (since PDF document permissions could be seen as user hostile).[1]

As I started looking at the issue, it soon became clear that *only* trying to fix the issue without slightly re-factor the surrounding code would be somewhat difficult.
The following is an overview of the changes in this patch; sorry about the size/scope of this!

 - Use a new `AnnotationEditorUIManager`-instance *for each* PDF document opened in the GENERIC viewer, to prevent user-added Annotations from "leaking" from one document into the next.

 - Re-factor the `BaseViewer.#initializePermissions`-method, to simplify handling of temporarily disabled modes (e.g. for both Annotation-rendering and Annotation-editing).

 - When editing is enabled, let the Editor-buttons be `disabled` until the document has loaded. This way we avoid the buttons becoming clickable temporarily, for PDF documents that use permissions.

 - Slightly re-factor how the Editor-buttons are shown/hidden in the viewer, and reset the toolbar-state when a new PDF document is opened.

 - Flip the order of the Editor-buttons and the pre-exising toolbarButtons in the "toolbarViewerRight"-div. (To help reduce the size, a little bit, for the PR that adds new Editor-toolbars.)

 - Enable editing by default in the development viewer, i.e. `gulp server`, since having to (repeatedly) do that manually becomes annoying after a while.

 - Finally, support disabling of editing when `pdfjs.enablePermissions` is set; fixes issue 15049.

---

[1] Either manually with `about:config`, or using e.g. a [Group Policy](https://github.com/mozilla/policy-templates).
2022-06-21 11:54:09 +02:00
calixteman
6ee538e0ba
Merge pull request #15074 from calixteman/ink3
Only activate ink editor if none is selected
2022-06-20 22:45:36 +02:00
Jonas Jenwald
b00641d873
Merge pull request #15071 from calixteman/popup_area_test
Add an outline around popup trigger areas in ref-tests
2022-06-20 22:28:39 +02:00
Calixte Denizet
c44ab94d28 Only activate ink editor if none is selected 2022-06-20 22:24:04 +02:00
Jonas Jenwald
aa3fc5844a
Merge pull request #15062 from Snuffleupagus/save-newRefs
Simplify the `newRefs` computation in the "SaveDocument"-handler in the worker-thread
2022-06-20 22:18:43 +02:00
Calixte Denizet
fd209d9685 Add an outline around popup trigger areas in ref-tests
- The goal is to avoid any future regressions.
2022-06-20 21:23:30 +02:00
Jonas Jenwald
7cce3fb6ff Ensure that the annotationLayer has the correct dimensions (PR 15036 follow-up)
Note how the "page"-div, "canvasWrapper"-div, and `textLayer`-div all have *integer* dimensions (rounded down) rather than using the "raw" viewport-dimensions.
Hence it seems reasonable that the same should apply to the "annotationLayer"-div, now that it's explicit dimensions set.
2022-06-20 09:38:46 +02:00
Jonas Jenwald
8d154d7f6a
Merge pull request #15064 from calixteman/rescale_followup
Avoid having overflowing sections (#15036 follow-up)
2022-06-20 09:33:13 +02:00
Jonas Jenwald
ef6142a6c7
Merge pull request #15065 from calixteman/15063
Popup trigger area must filled its parent (fix #15063)
2022-06-20 09:26:19 +02:00
Calixte Denizet
2ff65dd514 Popup trigger area must filled its parent (fix #15063) 2022-06-19 22:44:58 +02:00
Calixte Denizet
af47a0b7e0 Avoid having overflowing sections (#15036 follow-up) 2022-06-19 22:09:02 +02:00
Jonas Jenwald
57c10ac213 Simplify the newRefs computation in the "SaveDocument"-handler in the worker-thread
- Let the `Page.save`-method filter out "empty" entries, similar to the `Page._parsedAnnotations`-getter, since that on its own already simplifies the "SaveDocument"-handler a tiny bit.

 - The existing `reduce` and `concat` construction isn't exactly a wonder of readability :-)
   Thanks to modern JavaScript features it should be possible to replace all of this with `Array.prototype.flat()` instead, which at least to me feels a lot easier to understand.
2022-06-19 18:21:51 +02:00
Tim van der Meij
45de73bd00
Merge pull request #15059 from Snuffleupagus/rm-some-concat
Reduce unnecessary usage of `Array.prototype.concat()`
2022-06-19 14:36:14 +02:00
Jonas Jenwald
c21f4faaf8 Reduce unnecessary usage of Array.prototype.concat()
There are obviously cases where using `concat` makes perfect sense, since that method doesn't change any of the existing Arrays; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat

However, in a few cases throughout the code-base that's not an issue and using `concat` only leads to unnecessary intermediate allocations. With modern JavaScript we can thus replace those with a combination of `push` and spread-syntax, which wasn't originally possible when the code was written.
2022-06-19 13:40:52 +02:00
Tim van der Meij
f516bb2174
Merge pull request #15058 from Snuffleupagus/rm-baseviewerinit-event
[api-minor] Remove the "baseviewerinit" event since it's unused (PR 14324 follow-up)
2022-06-19 13:21:39 +02:00
calixteman
54777b42c2
Merge pull request #15036 from calixteman/remove_scale
[api-minor] Get rid of CSS transform on each annotation in the annotation layer
2022-06-19 11:36:13 +02:00
Jonas Jenwald
caaa78f7da [api-minor] Remove the "baseviewerinit" event since it's unused (PR 14324 follow-up)
Given that neither the viewer or the examples listen for this event, it seems unnecessary to keep dispatching it.
2022-06-19 09:57:05 +02:00
Calixte Denizet
e2db9bacef Get rid of CSS transform on each annotation in the annotation layer
- each annotation has its coordinates/dimensions expressed in percentage,
  hence it's correctly positioned whatever the scale factor is;
- the font sizes are expressed in percentage too and the main font size
  is scaled thanks a css var (--scale-factor);
- the rotation is now applied on the div annotationLayer;
- this patch improve the rendering of some strings where the glyph spacing
  was not correct (it's a Firefox bug);
- it helps to simplify the code and it should slightly improve the update of
  page (on zoom or rotation).
2022-06-18 17:54:59 +02:00
calixteman
6dc8d1f532
Merge pull request #15057 from Snuffleupagus/issue-15056
Replace element `id`s with custom attributes for Widget-annotations (issue 15056)
2022-06-18 17:47:17 +02:00
Jonas Jenwald
03757d82b7 Replace element ids with custom attributes for Widget-annotations (issue 15056)
We want to avoid adding regular `id`s to Annotation-elements, since that means that they become "linkable" through the URL hash in a way that's not supported/intended. This could end up clashing with "named destinations", and that could easily lead to bugs; see issue 11499 and PR 11503 for some context.

Rather than using `id`s, we'll instead use a *custom* `data-element-id` attribute such that it's still possible to access the Annotation-elements directly.
Unfortunately these changes required updating most of the integration-tests, and to reduce the amount of repeated code a couple of helper functions were added.
2022-06-18 16:43:05 +02:00
Tim van der Meij
3ca8d2c4f9
Merge pull request #15052 from Snuffleupagus/mv-defaultUrl-option
Simplify setting the `defaultUrl`-option in the CHROME viewer (PR 12470 follow-up)
2022-06-18 11:29:21 +02:00
Tim van der Meij
80af3a0d07
Merge pull request #15048 from Snuffleupagus/mv-renderer-option
Only define the `renderer`-option in the GENERIC viewer
2022-06-18 11:26:43 +02:00
Jonas Jenwald
77aa86e275 Stop defining the defaultUrl-option in the MOZCENTRAL viewer
This option is not used, nor has it ever been used, in the *built-in* Firefox PDF Viewer. Hence we can define it only for the environments where it makes sense instead.
2022-06-18 09:43:35 +02:00
Jonas Jenwald
abcc32ade0 Simplify setting the defaultUrl-option in the CHROME viewer (PR 12470 follow-up)
This should really have been done as part of PR 12470, since it's now possible to directly set the `defaultUrl`-option without having to fallback to `var`-usage.
2022-06-18 09:43:23 +02:00
Jonas Jenwald
be2dfe45f9
Merge pull request #15035 from Snuffleupagus/prefer-modern-dom-apis-2
Use modern DOM methods a bit more (PR 15031 follow-up)
2022-06-17 19:37:43 +02:00
calixteman
31e3427559
Merge pull request #15054 from calixteman/15053
[JS] Hide field borders and buttons (#15053)
2022-06-17 17:58:52 +02:00
Calixte Denizet
7e3941da9d [JS] Hide field borders and buttons (#15053)
- Since the border belongs to the section containing the HTML
  counterpart of an annotation, this section must be hidden when
  a JS action requires it;
- it wasn't possible to hide a button in using JS.
2022-06-17 17:36:38 +02:00
Marco Castelluccio
b9f5a70ded
Merge pull request #15051 from Maxim-Mazurok/patch-1
Fix "Good Beginner Bugs" link
2022-06-17 09:45:12 +02:00
Maxim Mazurok
bd5e1a9540
Fix "Good Beginner Bugs" link
Seems like the label was changed and the link needs to be updated
2022-06-17 11:33:07 +10:00
calixteman
b8688128e3
Merge pull request #15050 from calixteman/make_ink_better
[Editor] - Add the ability to directly draw after selecting ink tool
2022-06-16 20:34:56 +02:00
Calixte Denizet
e7dc1ef4f3 [Editor] - Add the ability to directly draw after selecting ink tool
- Right now, we must select the tool, then click to select a page and
  click to start drawing and it's a bit painful;
- so just create a new ink editor when we're hovering a page without one.
2022-06-16 19:53:07 +02:00
Jonas Jenwald
a19feac217 Reduce some duplication for AppOptions that use compatibilityParams
We can check for a relevant `compatibilityParams`-entry directly in `AppOptions.{get, getAll}` instead, which removes some unnecessary duplication.
2022-06-16 16:51:33 +02:00
Jonas Jenwald
df79b18a31 Only define the renderer-option in the GENERIC viewer
Given that the SVG back-end is not defined anywhere except in GENERIC builds, we can remove a little bit of unnecessary code in e.g. the Firefox PDF Viewer.
2022-06-16 16:11:47 +02:00
Jonas Jenwald
c3d0858062
Merge pull request #15046 from Snuffleupagus/issue-15044
Add basic support for non-embedded ArialUnicodeMS fonts (issue 15044)
2022-06-15 11:27:19 +02:00
Jonas Jenwald
64cce1269e Add basic support for non-embedded ArialUnicodeMS fonts (issue 15044)
This appears to be a Microsoft-specific version of the regular Arial font, hence we simply map this to Helvetica in the same way that we treat many other Arial-named fonts.
2022-06-15 10:37:20 +02:00
Jonas Jenwald
89cebcb6f9
Merge pull request #15034 from Snuffleupagus/issue-15033
Extend `getGlyphMapForStandardFonts` with some Hebrew entries (issue 15033)
2022-06-13 11:35:34 +02:00
Jonas Jenwald
4902ad8923 Use modern DOM methods a bit more (PR 15031 follow-up)
Apparently the ESLint rule added in PR 15031 wasn't able to catch all cases that can be converted, which is probably not all that surprising given how some of these call-sites look.

 - Use `Element.prepend()` to insert nodes before all other ones in the element, rather than using `firstChild` with `insertBefore`-calls; see https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend

 - Fix one *incorrect* `insertBefore` call, in the AnnotationLayer-code.
   Initially the patch simply changed that to an `Element.before()`-call, however that broke one of the integration-tests. It turns out that the `index` may try to access a non-existent select-child, which triggers undefined behaviour; note the warning in https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore#parameters
2022-06-13 10:47:37 +02:00
Jonas Jenwald
2dca14028d Extend getGlyphMapForStandardFonts with some Hebrew entries (issue 15033)
This only adds the minimum entries required in order to render the referenced document correctly, rather than trying to support "all" Hebrew glyphs, to ensure that all lines in `getGlyphMapForStandardFonts` are covered by tests.
2022-06-13 10:08:39 +02:00
Tim van der Meij
1a6ae5f034
Merge pull request #15031 from Snuffleupagus/prefer-modern-dom-apis
Enable the `unicorn/prefer-modern-dom-apis` ESLint plugin rule
2022-06-12 20:36:40 +02:00
Tim van der Meij
0e1e265c61
Merge pull request #15030 from Snuffleupagus/update-packages
Update packages and translations
2022-06-12 20:16:11 +02:00
Tim van der Meij
720f77c7cd
Merge pull request #15028 from Snuffleupagus/update-compat
[api-minor] Update the minimum supported browsers/environments
2022-06-12 20:12:33 +02:00
Tim van der Meij
26ae50e449
Merge pull request #15023 from Snuffleupagus/prefer-array-flat
Enable the `unicorn/prefer-array-flat` and `unicorn/prefer-array-flat-map` ESLint plugin rules
2022-06-12 20:10:52 +02:00
Jonas Jenwald
4d39898823 Enable the unicorn/prefer-modern-dom-apis ESLint plugin rule
This rule will help enforce slightly shorter code, and according to MDN both `Element.replaceWith()` and `Element.before()` are available in all browsers that we currently support.

Please find additional information here:
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-modern-dom-apis.md
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceWith
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/before
2022-06-12 20:05:05 +02:00
Jonas Jenwald
0c65926d5b
Merge pull request #15029 from Snuffleupagus/prefer-dom-node-append
Enable the `unicorn/prefer-dom-node-append` ESLint plugin rule
2022-06-12 19:58:37 +02:00
Jonas Jenwald
17d2380824 Update l10n files 2022-06-12 14:05:41 +02:00
Jonas Jenwald
f052a12968 Update npm packages 2022-06-12 14:02:31 +02:00
Jonas Jenwald
8129815538 Enable the unicorn/prefer-dom-node-append ESLint plugin rule
This rule will help enforce slightly shorter code, especially since you can insert multiple elements at once, and according to MDN `Element.append()` is available in all browsers that we currently support.

Please find additional information here:
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/append
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-append.md
2022-06-12 13:07:03 +02:00
Jonas Jenwald
2f0ed3a9ca [api-minor] Update the minimum supported browsers/environments
*Please note:* The dates below are still a little ways off, however that obviously won't affect the existing PDF.js releases. Hence I think that we can make these changes now, since by the time of the *next* official PDF.js release they'll likely match up pretty well.[1]

While we "support" some (by now) fairly old browsers, that essentially means that the library (and viewer) will load and that the basic functionality will work as intended.[2]
However, in older browsers, some functionality may not be available and generally we'll ask users to update to a modern browser when bugs (specific to old browsers) are reported.[3]

Since we've previously settled on only supporting browsers/environments that are approximately *three years old*, this patch updates the minimum supported browsers/environments as follows:
 - Chrome 76, which was released on 2019-07-30; see https://en.wikipedia.org/wiki/Google_Chrome_version_history
 - Firefox ESR (as before); see https://wiki.mozilla.org/Release_Management/Calendar
 - Safari 13, which was released on 2019-09-19; see https://en.wikipedia.org/wiki/Safari_version_history#Safari_13
 - Node.js 14, which was release on 2020-04-21 (all older versions have reached EOL); see https://en.wikipedia.org/wiki/Node.js#Releases

---
[1] Given that the releases usually happen every two to three months.

[2] Assuming that a `legacy/`-build is being used, of course.

[3] In general it's never a good idea to use old/outdated browsers, since those may contain *known* security vulnerabilities.
2022-06-11 16:50:01 +02:00
Jonas Jenwald
d7122becaf
Merge pull request #15027 from Snuffleupagus/parseFloat-fixes
Remove superfluous trailing arguments from `parseFloat`-calls (PR 14978 follow-up)
2022-06-11 15:25:24 +02:00
Jonas Jenwald
4b2526ebf2 Remove superfluous trailing arguments from parseFloat-calls (PR 14978 follow-up)
Fixes two recent "Code scanning alerts" on GitHub, which likely happened because these calls originally used `parseInt` instead (during initial development).
2022-06-11 15:11:34 +02:00
Jonas Jenwald
7f4b1c2149
Merge pull request #15026 from Snuffleupagus/rm-unused-annotation-ops
[api-minor] Stop using the `beginAnnotations`/`endAnnotations` operators (PR 14998 follow-up)
2022-06-11 15:04:51 +02:00
Jonas Jenwald
bbf857d635 [api-minor] Stop using the beginAnnotations/endAnnotations operators (PR 14998 follow-up)
After the changes in PR 14998, these operators are now no-ops in the `src/display/canvas.js` code and should no longer be necessary.
Given that `beginAnnotations`/`endAnnotations` are not in the PDF specification, but are rather *custom* PDF.js operators, it seems reasonable to stop using them now that they've become no-ops.
2022-06-11 14:21:26 +02:00
Marco Castelluccio
b5fb6cdb96
Merge pull request #15022 from Snuffleupagus/editorNone-icon-tweak
Tweak the `editorNone` icon to circumvent the "duplicated files"-check
2022-06-11 11:34:21 +02:00
Jonas Jenwald
010d996b74 Enable the unicorn/prefer-array-flat and unicorn/prefer-array-flat-map ESLint plugin rules
These rules will help enforce shorter and more readable code, and according to MDN these Array-methods are available in all browsers/environments that we currently support:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap#browser_compatibility

Please find additional information about these ESLint rules here:
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-flat.md
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-flat-map.md
2022-06-11 11:33:43 +02:00
Jonas Jenwald
1465471b10 Tweak the editorNone icon to circumvent the "duplicated files"-check
The update in https://bugzilla.mozilla.org/show_bug.cgi?id=1773794 failed, because the `editorNone` icon is identical to a pre-existing one. Given that all of the editor-icons are simply placeholders for now, we can just make a tiny change to the SVG-paths to prevent these kind of problems.
2022-06-11 11:17:08 +02:00
Tim van der Meij
a57a4bc6c2
Merge pull request #15018 from Snuffleupagus/issue-15016
Expose `TextLayerRenderTask` in the TypeScript definitions (issue 15016, PR 14013 follow-up)
2022-06-10 22:18:35 +02:00
Tim van der Meij
f0b5aee6b8
Merge pull request #15014 from Snuffleupagus/prefer-at
Enable the `unicorn/prefer-at` ESLint plugin rule (PR 15008 follow-up)
2022-06-10 22:12:35 +02:00
Jonas Jenwald
e046b811b7 Expose TextLayerRenderTask in the TypeScript definitions (issue 15016, PR 14013 follow-up)
While `TextLayerRenderTask` apparently makes sense in TypeScript environments, given that it's being returned by the `renderTextLayer`-function in the API, we really don't want to extend the *public* API by simply exporting the class directly in `src/pdf.js` since it should never be called/initialized manually.
Hence we follow the same pattern as in PR 14013, and add some very basic unit-tests to ensure that `renderTextLayer` always returns a `TextLayerRenderTask`-instance as expected.
2022-06-10 22:12:32 +02:00
calixteman
6e6d94ab8d
Merge pull request #15020 from calixteman/1773680
Add an empty entry in combo list when nothing is selected (bug 1773680)
2022-06-10 19:18:31 +02:00
Calixte Denizet
bfe816d0d2 Add an empty entry in combo list when nothing is selected (bug 1773680)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1773680
- the empty is removed once something is selected.
2022-06-10 18:45:02 +02:00
Jonas Jenwald
d45ce8d6a3
Merge pull request #15015 from jerry1100/fix-container-type
Extend TextLayerRenderParameters.container type to include HTMLElement.
2022-06-10 17:05:47 +02:00
jerry1100
b716e82d18 Extend TextLayerRenderParameters.container type to include HTMLElement.
In PR #14717, the type was changed from a HTMLElement to a DocumentFragment.
This broke TypeScript projects that use a HTMLElement container.

To remedy this, we extend the type of container to also include HTMLElement.
2022-06-10 06:50:47 -07:00
calixteman
808a55e42b
Merge pull request #15019 from mozilla/revert-15003-mc
Revert "Change the name of the generated pdf.sandbox.external for mozilla-central"
2022-06-10 11:35:14 +02:00
calixteman
c8f6cb9fcf
Revert "Change the name of the generated pdf.sandbox.external for mozilla-central" 2022-06-10 11:34:28 +02:00
Jonas Jenwald
9ac4536693 Enable the unicorn/prefer-at ESLint plugin rule (PR 15008 follow-up)
Please find additional information here:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-at.md
2022-06-09 21:21:19 +02:00
calixteman
5d88233fbb
Merge pull request #15006 from calixteman/ink2
[editor] Add support for saving newly added Ink
2022-06-09 21:13:53 +02:00
calixteman
61a65344a3
Merge pull request #14989 from calixteman/ink1
[editor] Add an Ink editor
2022-06-09 21:13:06 +02:00
Calixte Denizet
c161a86ba1 [editor] Add an Ink editor
- Approximate the drawn curve by a set of Bezier curves in using
  js code from https://github.com/soswow/fit-curves.
  The code has been slightly modified in order to make the linter
  happy.
2022-06-09 19:35:59 +02:00
Jonas Jenwald
1eaef6645d
Merge pull request #15013 from Snuffleupagus/issue-15012
Render PopupAnnotations even if they have missing or empty /Rect-entries (issue 15012, PR 14439 follow-up)
2022-06-09 16:51:31 +02:00
Jonas Jenwald
6371a7605d Force-install npm packages to try and fix the repeated GitHub Action failures 2022-06-09 15:10:58 +02:00
Jonas Jenwald
3d244cb6a8 Render PopupAnnotations even if they have missing or empty /Rect-entries (issue 15012, PR 14439 follow-up)
This only applies to *corrupt* PDF documents, where Annotations are missing the required /Rect-entry. Rendering PopupAnnotations unconditionally shouldn't be a problem, since we're not using a `BaseSVGFactory`-instance in that case.
2022-06-09 15:10:54 +02:00
calixteman
a1bc5a8fe2
Merge pull request #15011 from Snuffleupagus/misc-review-comments
Fix a couple of old review comments
2022-06-09 13:52:51 +02:00
Jonas Jenwald
66bbc0e7ee Call WidgetAnnotation._getTextWidth correctly from the ChoiceWidgetAnnotation-class (PR 14720 follow-up)
In the "no fontSize available" code-path, in the `ChoiceWidgetAnnotation._getAppearance` method, we don't provide the necessary second argument when calling the `_getTextWidth`-method which will cause errors to be thrown.
2022-06-09 10:11:01 +02:00
Jonas Jenwald
b5cad9be03 Fix a bug in the ColorConverters.CMYK_HTML method (PR 12631 follow-up)
Because of a small oversight, this method accidentally handled the intermediate array incorrectly.
2022-06-09 10:03:36 +02:00
Jonas Jenwald
7a89f4a789 Set the MIME type correctly when downloading fonts in debugger.js (PR 5366 follow-up)
Because of a capitalization error, the MIME type wasn't actually being set correctly. However, please note that downloading of font files still worked correctly which is probably why this has gone unnoticed since 2014.
2022-06-09 09:52:28 +02:00
Jonas Jenwald
14e6d8a802
Merge pull request #15008 from Snuffleupagus/Array-at
Polyfill `Array.prototype.at` with core-js (PR 14976 follow-up)
2022-06-08 22:26:08 +02:00
Calixte Denizet
36aae436bf [editor] Add support for saving newly added Ink 2022-06-08 22:16:01 +02:00
Jonas Jenwald
9e24a1660e Polyfill Array.prototype.at with core-js (PR 14976 follow-up)
This Array-method is a fairly new addition to the ECMAScript specification, hence we need a polyfill to avoid the library/viewer breaking in older browsers.

Please find additional information at:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at#browser_compatibility
2022-06-08 22:10:59 +02:00
calixteman
2fbf14ace8
Merge pull request #14978 from calixteman/editor2
[editor] Add support for saving a newly added FreeText
2022-06-08 15:51:03 +02:00
Calixte Denizet
7773b3f5be [edition] Add support for saving a newly added FreeText 2022-06-08 14:34:09 +02:00
Jonas Jenwald
c8b8db6a17
Merge pull request #15003 from calixteman/mc
Change the name of the generated pdf.sandbox.external for mozilla-central
2022-06-08 10:44:10 +02:00
Calixte Denizet
7b37af7eb4 Change the name of the generated pdf.sandbox.external for mozilla-central
This patch is blocking https://phabricator.services.mozilla.com/D148600.
2022-06-08 10:36:38 +02:00
Jonas Jenwald
7761d2bf95
Merge pull request #15001 from marco-c/canvas_presentational
Set "presentation" role for page canvases (issue 14437)
2022-06-07 20:03:38 +02:00
Jonas Jenwald
ae9ad1d858
Merge pull request #15000 from calixteman/1724918
Outline fields which are required (bug 1724918)
2022-06-07 19:35:13 +02:00
Marco Castelluccio
8c9678158e Set "presentation" role for page canvases (issue 14437) 2022-06-07 18:56:30 +02:00
Calixte Denizet
2dd0c861bf Outline fields which are required (bug 1724918)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1724918;

- it applies for both Acroform and XFA.
2022-06-07 17:02:11 +02:00
Jonas Jenwald
c25429be44
Merge pull request #14998 from calixteman/14105
Reset all the canvas states after rendering each annotations (#14105)
2022-06-07 16:07:45 +02:00
Calixte Denizet
96d0d22d66 Reset all the canvas states after rendering each annotations (#14105)
- each annotation must be rendered independently of the others. So
  after having rendered each annotation, the canvas states are reset
  in order to have something clean to render the next one.
2022-06-07 14:59:02 +02:00
Tim van der Meij
135b9fbcfb
Merge pull request #14994 from Snuffleupagus/parseJbig2-conditional
Conditionally bundle `gulp image_decoders`-specific code in `src/core/jbig2.js` (PR 9729 follow-up)
2022-06-06 12:28:53 +02:00
calixteman
1816b5e926
Merge pull request #14993 from Snuffleupagus/editor-AnnotationStorage-hash
[editor] Update the `AnnotationStorage.hash`-getter to support editing
2022-06-05 18:48:29 +02:00
Jonas Jenwald
e82ad79eb9 Conditionally bundle gulp image_decoders-specific code in src/core/jbig2.js (PR 9729 follow-up)
This method/function was added only for the `gulp image_decoders`-builds, and is completely unused elsewhere (e.g. in the Firefox PDF Viewer).
While this only reduces the size of the *built* `pdf.worker.js` file by a little over 1 kB, it can't hurt to remove completely unused code from the "normal" builds.
2022-06-05 15:38:28 +02:00
Jonas Jenwald
51c47acb41 [editor] Update the AnnotationStorage.hash-getter to support editing
While calling `JSON.stringify(...)` on a class-instance obviously "works" (as in it doesn't throw), since it's really just an Object, it doesn't really make much sense in the context of the `AnnotationStorage.hash`-getter.

Also, access the *inverse* Viewport-transform correctly in `FreeTextEditor.serialize` to prevent errors being thrown when that method is invoked.

Finally, slightly updates the `AnnotationStorage.serializable`-getter to improve consistency within the class.
2022-06-05 14:05:44 +02:00
Jonas Jenwald
87fdb0eb42
Merge pull request #14992 from Snuffleupagus/issue-14990
Lookup image-data correctly in `paintImageMaskXObjectGroup` (issue 14990)
2022-06-05 13:29:56 +02:00
Jonas Jenwald
59dd4ea2b0 Lookup image-data correctly in paintImageMaskXObjectGroup (issue 14990)
*This fixes a regression from PR 14754.*

We didn't lookup the image-data correctly, with the result that we tried to render some ImageMasks using a string rather than the intended TypedArray. To make matters worse, this code-path was apparently not *properly* covered by existing test-cases.
2022-06-05 12:39:23 +02:00
calixteman
193a28431c
Merge pull request #14991 from Snuffleupagus/editor-XFA-disable
[editor] Disable the editor-buttons in XFA documents
2022-06-05 12:03:05 +02:00
Tim van der Meij
37f7995dde
Merge pull request #14984 from Snuffleupagus/dialog-polyfill-CSS
Bundle the `<dialog>` polyfill-CSS in the GENERIC `legacy/`-viewer (PR 14710 follow-up)
2022-06-05 11:18:18 +02:00
Jonas Jenwald
d34e7fff01 [editor] Disable the editor-buttons in XFA documents
Given the differences between XFA documents and "normal" PDF documents, we don't support editing of the former ones. Hence, when a XFA-document is opened, we temporarily disable the editor-buttons.
2022-06-05 10:00:08 +02:00
Jonas Jenwald
9b22483e00
Merge pull request #14985 from Snuffleupagus/editor-FreeText-followup
[editor] A couple of small FreeText-related fixes (PR 14976 follow-up)
2022-06-04 23:23:52 +02:00
Jonas Jenwald
a25d92fb17
Merge pull request #14988 from Snuffleupagus/rm-singlefile-comment
Remove mention of `gulp singlefile`-command from `examples/node/getinfo.js`
2022-06-04 23:20:29 +02:00
Jonas Jenwald
dd58671589 Remove mention of gulp singlefile-command from examples/node/getinfo.js
This comment should've been removed in PR 9385, but better late than never I suppose.
2022-06-04 23:10:58 +02:00
Jonas Jenwald
51bf928061 [editor] A couple of small FreeText-related fixes (PR 14976 follow-up)
- Ensure that the modified-warning won't be displayed, when navigating away from the viewer, if the user has added custom Annotations and then *removed all* of them.
 - Ensure that the *initial* editor-buttons state, i.e. the `toggled`-class, is correctly displayed in the toolbar when then viewer loads.
 - Tweak the CSS-classes for the editor-buttons, such that they use the correct focus/hover-rules (similar to the sidebar-buttons).
 - Remove a no longer accurate comment from the `BaseViewer.annotationEditorMode`-setter.
 - Address a couple of *smaller* outstanding review comments, including some re-formatting changes, from PR 14976.
2022-06-04 21:48:11 +02:00
calixteman
c8ef87197c
Merge pull request #14976 from calixteman/editor1
[editor] Add a FreeText editor (#14970)
2022-06-04 19:02:20 +02:00
Calixte Denizet
be1aa11986 [edition] Add a FreeText editor (#14970)
- add a basic UI to edit some text in a pdf;
- an editor can be moved, suppressed, cut, copied, pasted, selected;
- add an undo/redo manager.
2022-06-04 18:20:11 +02:00
Jonas Jenwald
bb8f5ec20b Bundle the <dialog> polyfill-CSS in the GENERIC legacy/-viewer (PR 14710 follow-up)
In PR 14710 we only included the JavaScript-part of the polyfill, however we probably need to include the CSS as well to reduce the risk of problems in older browsers.

With the recent CSS-related improvements in the `preprocess`-function we could probably have included this conditionally in the `viewer.css` file. However, considering that the `<dialog>` polyfill-code is only invoked when actually needed it seemed most appropriate/correct to lazy-load the polyfill-CSS as well.
2022-06-04 18:11:35 +02:00
Jonas Jenwald
1953967681
Merge pull request #14980 from Snuffleupagus/preprocessCSS-comments-2
Handle CSS-comments better in the preprocess-function (PR 14963 follow-up)
2022-06-02 16:52:48 +02:00
Jonas Jenwald
397f2e63d0 Handle CSS-comments better in the preprocess-function (PR 14963 follow-up)
This fixes another oversight, please see the updated tests.
2022-06-02 16:06:47 +02:00
Jonas Jenwald
1ac33c960d
Merge pull request #14968 from Snuffleupagus/api-release-data
A small memory-usage improvement for PDF documents opened from TypedArray-data
2022-05-29 18:35:12 +02:00
Jonas Jenwald
7e852851fd A small memory-usage improvement for PDF documents opened from TypedArray-data
This patch contains a small optimization specifically for the case when `getDocument` is called with TypedArray-data. In that case we'll still hold onto that data, which could obviously be large, even after the "GetDocRequest"-message has been sent to the worker-thread.

In practice this will most likely not affect memory usage in any noticeable way, since the application calling `getDocument` will probably also be keeping a reference to the TypedArray-data. However, it seems like a good idea to ensure that the PDF.js API *itself* won't unnecessarily keep this data alive.
2022-05-29 16:37:18 +02:00
Tim van der Meij
3fdf2ba4e3
Merge pull request #14583 from calixteman/buttons
[Annotations] Show buttons even if they've no actions
2022-05-29 14:13:11 +02:00
Tim van der Meij
839fb002eb
Merge pull request #14967 from Snuffleupagus/update-packages
Update packages and translations
2022-05-29 14:03:37 +02:00
Tim van der Meij
a0eca3e34f
Merge pull request #14962 from Snuffleupagus/sidebar-more-visibleView
Improve the `PDFSidebar` implementation
2022-05-29 13:43:54 +02:00
Tim van der Meij
a43a30bb7b
Merge pull request #14964 from Snuffleupagus/onOpenWithData-contentDispositionFilename
Ensure that the `contentDispositionFilename` is always respected, when setting the document title (PR 13014 follow-up)
2022-05-29 13:26:23 +02:00
Tim van der Meij
3e67d97f81
Merge pull request #14963 from Snuffleupagus/preprocessCSS-comments
Handle CSS-comments correctly in the `preprocess`-function (PR 14886 follow-up)
2022-05-29 13:22:22 +02:00
Jonas Jenwald
0d3a5d7a9e
Merge pull request #14966 from tamuratak/use_globalthis
Use globalThis for webpack's output.globalObject instead of this
2022-05-29 11:31:15 +02:00
Jonas Jenwald
db029e17b3 Update l10n files 2022-05-29 09:48:14 +02:00
Jonas Jenwald
a7d2d8d929 Update npm packages 2022-05-29 09:37:24 +02:00
Takashi Tamura
10932e3f9d Use globalThis for webpack's output.globalObject instead of this. Close #14915.
That allows us to import pdfjs-dist/build/pdf.js dynamically from modules.

- https://webpack.js.org/configuration/output/#outputglobalobject
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
2022-05-29 11:28:17 +09:00
Calixte Denizet
66b513fc00 [Annotations] Show buttons even if they've no actions
- it's a regression from PR #14247:
 - before the PR, the button was rendered on the canvas whatever its status was;
 - after the PR, the button image has been moved in an other canvas so when the button is not renderable
   (because it has no actions) then the image is not added the HTML element.
- the buttons in the pdf in bug 1737260 or in the pdf in #14308 were not visible
- make the button always renderable but don't add the link element if it's useless.
2022-05-28 23:50:50 +02:00
calixteman
9bdf27e8e0
Merge pull request #14936 from calixteman/input_font_size
Set the text fields font size based on their height
2022-05-28 18:32:45 +02:00
Calixte Denizet
9d82106d20 Set the text fields font size based on their height
- right now we're using the font size from the pdf itself but we use an other font
  in the annotation layer. So this size doesn't really make sense and leads to bad
  rendering (see pdf in #14928);
- use a sans-serif font for the fields containing text (fix issue #14736);
- remove useless padding in text-based fields (fix issue #14301);
- text fields allow/disallow scrolling bars (see bit 24 in Ff entry), so use this
  value to hide/show scrollbars in annotation layer.
2022-05-28 18:00:39 +02:00
calixteman
5b3fdee5f5
Merge pull request #14965 from calixteman/1771477
Support Hangul syllables when searching some text (bug 1771477)
2022-05-28 17:52:27 +02:00
Calixte Denizet
c7afce4210 Support Hangul syllables when searching some text (bug 1771477)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1771477;
- hangul contains some syllables which are decomposed when using NFD, hence
  the text must be correctly shifted in case it contains some of them.
2022-05-28 16:50:03 +02:00
Jonas Jenwald
d80035b716
Merge pull request #14959 from Snuffleupagus/pageColors-thumbnails
Support custom `pageColors` in the thumbnails (PR 14874)
2022-05-28 15:46:06 +02:00
Jonas Jenwald
0599ce77ff Ensure that the contentDispositionFilename is always respected, when setting the document title (PR 13014 follow-up)
Currently, when range-requests and/or streaming are not supported or for documents opened from `data`-URLs, we'll manually set the `contentDispositionFilename` (assuming it exists and is valid) from the `onOpenWithData`-callback in `PDFViewerApplication.initPassiveLoading`.
However, because of a small oversight in `PDFViewerApplication._initializeMetadata`, this *cached* `contentDispositionFilename` would be ignored and we'd only attempt to use the one returned by `PDFDocumentProxy.getMetadata` in the API (which in the cases outlined above will always be empty).

Also, to ensure that the document properties dialog always displays the *correct* fileName we'll now lookup it using the same exact method as in the viewer itself (via a new callback-function).
2022-05-28 12:39:49 +02:00
Jonas Jenwald
65fe0130f4 Handle CSS-comments correctly in the preprocess-function (PR 14886 follow-up)
I overlooked this in PR 14886, sorry about that!
2022-05-28 08:41:25 +02:00
Jonas Jenwald
c0e7a454a1 Convert the PDFSidebar class to use private methods 2022-05-27 11:36:01 +02:00
Jonas Jenwald
d289da76a7 Re-factor the PDFSidebar.{setInitialView, switchView} methods (PR 10502 follow-up)
This removes the internal `_switchView`-method, since looking at all of this again it feels simpler to instead track the initial event dispatching.
2022-05-27 11:33:01 +02:00
Jonas Jenwald
13fda7caeb Remove the view-specific getters in the PDFSidebar class
With the exception of `isThumbnailViewVisible`, these getters are completely unused. Generally speaking, using the `visibleView`-getter directly works just as well and seems (at least to me) to be overall preferable considering how our classes are usually implemented.
2022-05-26 14:27:51 +02:00
Tim van der Meij
e6a0a953e8
Merge pull request #14957 from Snuffleupagus/docStyle
Introduce a viewer constant for `document.documentElement.style`
2022-05-26 13:04:05 +02:00
Jonas Jenwald
9871761949 Support custom pageColors in the thumbnails (PR 14874)
Currently, when non-standard `pageColors` are specified, the thumbnails will look inconsistent depending on how they're created.
The thumbnails that are created by downsizing the *page* canvases will obviously use the `pageColors` as intended, however the thumbnails which are rendered *directly* will always use the default colors.
2022-05-26 10:07:27 +02:00
Jonas Jenwald
ca244d9bca Introduce a viewer constant for document.documentElement.style
Over time, as we've been introducing JavaScript code to modify CSS variables, we've been adding shorthand properties to various classes to reduce unnecessary repetition when accessing the document-styles.
Rather than repeating this in multiple places, it seems overall simpler to just introduce a constant and re-use that throughout the viewer instead.
2022-05-25 09:55:54 +02:00
Jonas Jenwald
5b02c685d6
Merge pull request #14955 from Snuffleupagus/issue-14953
Skip bogus `d1` operators in Type3-glyphs (issue 14953)
2022-05-24 13:45:34 +02:00
Jonas Jenwald
5a2899c57e Skip bogus d1 operators in Type3-glyphs (issue 14953)
In the `src/display/canvas.js` code the `d1` operator will be used to set the clipping region, and it obviously cannot be empty since that prevents the Type3-glyph from rendering.

Also, the patch removes an outdated comment; refer to PR 12718.
2022-05-24 12:20:31 +02:00
calixteman
61012b931c
Merge pull request #14950 from calixteman/1766987
[JS] Format all the fields if any when the document is open (bug 1766987)
2022-05-22 16:56:53 +02:00
Calixte Denizet
9407adc416 [JS] Format all the fields if any when the document is open (bug 1766987)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1766987.
2022-05-22 15:50:42 +02:00
Jonas Jenwald
8fcdad022b
Merge pull request #14948 from Pldi23/drag&drop_not_work_from_mail
Set 'dropEffect' based on 'effectAllowed' for drag-and-drop in the viewer (issue 14942)
2022-05-22 15:34:15 +02:00
Dmitry_Platonov
55da67e9aa Set 'dropEffect' based on 'effectAllowed' for drag-and-drop in the viewer (issue 14942). See https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed 2022-05-22 14:57:55 +02:00
Tim van der Meij
42a6217427
Merge pull request #14926 from Snuffleupagus/rm-sourceEventType
Remove the `sourceEventType` from the viewer (bug 1757771 follow-up)
2022-05-21 12:34:54 +02:00
Jonas Jenwald
5b67202851
Merge pull request #14929 from calixteman/14928
Display background when printing or saving a text widget (issue #14928)
2022-05-20 18:11:10 +02:00
Jonas Jenwald
bf211eeef5
Merge pull request #14947 from IsaacLK/master
Twitter should be capitalized.
2022-05-20 18:03:37 +02:00
IsaacLK
e003e82c98
Twitter should be capitalized. 2022-05-20 09:36:10 -04:00
calixteman
3c877f9520
Merge pull request #14945 from calixteman/devicepixels
Allow to have float numbers when getting image information in reftest-analyzer
2022-05-20 13:55:23 +02:00
Calixte Denizet
0a66e1f5ea Allow to have float numbers when getting image information in reftest-analyzer
- outputScale can be e.g. 1.5 in real life.
2022-05-20 13:02:22 +02:00
Calixte Denizet
60498c67e4 Display background when printing or saving a text widget (issue #14928) 2022-05-19 16:41:54 +02:00
Jonas Jenwald
8a349801dc [Firefox viewer] Stop using FirefoxCom.requestAsync in the DownloadManager
After the changes in https://bugzilla.mozilla.org/show_bug.cgi?id=1757771, that simplified the MOZCENTRAL downloading code, the `ChromeActions.download`-method will no longer invoke the `sendResponse`-callback.
Hence it should no longer be necessary for the `DownloadManager`, in the MOZCENTRAL viewer, to use `FirefoxCom.requestAsync` since no response is ever provided.[1] For the allocated BlobURLs, they should (hopefully) be released when navigating away from the viewer.

---
[1] Note that that was *already* the case, for one of the previous code-paths in the `ChromeActions.download`-method.
2022-05-15 18:18:37 +02:00
Jonas Jenwald
4f1cd6a9c2 Remove the sourceEventType from the viewer (bug 1757771 follow-up)
After the changes in https://bugzilla.mozilla.org/show_bug.cgi?id=1757771, that simplified the MOZCENTRAL downloading code, the `sourceEventType` is now completely unused and should thus be removed (in my opinion).

Furthermore, with these changes, we also no longer need a *separate* internal "save"-event and can instead just use the older "download"-event everywhere.
2022-05-15 18:18:37 +02:00
Jonas Jenwald
60e9065bf6
Merge pull request #14898 from calixteman/progress
[api-minor] Use a CSS transform to update the progress bar instead of changing the width (bug 1768481)
2022-05-15 18:18:08 +02:00
Calixte Denizet
e94b9d1d7f Use a CSS transform to update the progress bar instead of changing the width (bug 1768481)
- it isn't a fix for bug 1768481 but just a tiny improvement to refresh the progress bar on the compositor thread.
2022-05-15 17:30:37 +02:00
Jonas Jenwald
63441e8f1e
Merge pull request #14921 from Snuffleupagus/issue-14917
Adjust the heuristics for handling of incomplete path operators (issue 14917)
2022-05-15 15:02:52 +02:00
Tim van der Meij
c06384054d
Merge pull request #14920 from Snuffleupagus/update-packages
Update packages and translations
2022-05-15 11:37:56 +02:00
Jonas Jenwald
5a774b7ed3 Adjust the heuristics for handling of incomplete path operators (issue 14917)
This limits the heuristics for handling of incomplete path operators, see PR 9838, to only apply to *sequences* of such operators. In practice a couple of invalid path operators are (hopefully) unlikely to completely break rendering, whereas a sequence of them will easily lead to fairly chaotic rendering artifacts.
2022-05-15 11:24:39 +02:00
Jonas Jenwald
54080b6884 Update l10n files 2022-05-15 09:12:37 +02:00
Jonas Jenwald
5320316f73 Update npm packages 2022-05-15 09:07:35 +02:00
Tim van der Meij
46e4a305eb
Merge pull request #14919 from timvandermeij/bump
Bump versions in `pdfjs.config`
2022-05-14 14:47:27 +02:00
Tim van der Meij
bfb0880523
Bump versions in pdfjs.config 2022-05-14 14:45:59 +02:00
Tim van der Meij
eaaa8b4ade
Merge pull request #14918 from Snuffleupagus/ProgressBar-modernize
[api-minor] Modernize and simplify the `ProgressBar` class
2022-05-14 14:15:13 +02:00
Jonas Jenwald
1f3da032b4 [api-minor] Modernize and simplify the ProgressBar class
The original `ProgressBar`-functionality is very old, and could thus do with some general clean-up.
In particular, while it currently accepts various options those have never really been used in either the default viewer or in any examples. The sort of "styling" that these options provided are *much better*, not to mention simpler, done directly with CSS rules.

As part of these changes, the "progress" is now updated using CSS variables rather than by directly modifying the `style` of DOM elements. This should hopefully simplify future changes to this code, see e.g. PR 14898.

Finally, this also fixes a couple of other small things in the "mobile viewer" example.
2022-05-14 13:49:10 +02:00
Tim van der Meij
b5f2bd8bfd
Merge pull request #14910 from Snuffleupagus/adjustScaleWidth-animationStarted
Ensure that setting the width of the zoom dropdown works correctly (PR 14028 follow-up)
2022-05-14 13:29:15 +02:00
Jonas Jenwald
efe3cb2982 Remove unnecessary clean-up in Toolbar.#adjustScaleWidth
While zeroing the temporary `canvas` makes sense, manually clearing the canvas and its context doesn't really accomplish anything since those are tied to the scope of the method.
2022-05-13 17:20:35 +02:00
Jonas Jenwald
3dd8b9cccf Ensure that setting the width of the zoom dropdown works correctly (PR 14028 follow-up)
We need to wait for UI rendering to start *before* getting the CSS variable values, since otherwise the values will be `NaN`.
This is only an issue if the viewer is completely hidden during loading, e.g. in a `display: none` iframe-element.
2022-05-13 17:10:42 +02:00
Jonas Jenwald
96b125fb72
Merge pull request #14911 from Snuffleupagus/more-TypedArray-fill
Use `TypedArray.prototype.fill()` a bit more in the code-base
2022-05-13 13:47:17 +02:00
Jonas Jenwald
d540df0582 Use TypedArray.prototype.fill() a bit more in the code-base
Please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill, which is implemented in all browsers that we currently support.
2022-05-13 12:42:51 +02:00
Tim van der Meij
fbc7981c98
Merge pull request #14894 from Snuffleupagus/rm-mozOpaque
Try to remove the `mozOpaque` canvas-property (PR 6551 follow-up)
2022-05-12 22:03:05 +02:00
Jonas Jenwald
ed70ec8726
Merge pull request #14899 from Snuffleupagus/issue-14896
[api-minor] Include line endings in Line/Polyline Annotation-data (issue 14896)
2022-05-12 11:29:17 +02:00
Jonas Jenwald
6bcc5b615d [api-minor] Include line endings in Line/Polyline Annotation-data (issue 14896)
Please refer to:
 - https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2109792
 - https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2096489
 - https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2096447

Note that we still won't attempt to use the /LE-data when creating fallback appearance streams, as mentioned in PR 13448, since custom line endings aren't common enough to warrant the added complexity.
Finally, note that according to the PDF specification we should *potentially* also take the line endings into account for FreeText Annotations. However, in that case their use is conditional on other parameters that we currently don't support.
2022-05-12 11:08:30 +02:00
Jonas Jenwald
8dc836d105
Merge pull request #14904 from Snuffleupagus/preprocess-blank-lines
Avoid the `preprocess`-function adding consecutive blank lines
2022-05-12 10:07:52 +02:00
Jonas Jenwald
ec6575db00 Avoid the preprocess-function adding consecutive blank lines
When pre-processor blocks are being removed, since they don't apply to the current build target, we may currently end up with consecutive blank lines.
While this is obviously not a big issue, it's nonetheless undesirable and we can adjust the `writeLine` function to prevent that.
2022-05-11 14:21:16 +02:00
Jonas Jenwald
9ceceaeeb5
Merge pull request #14903 from Snuffleupagus/issue-14902
Update the `preprocess`-function to avoid adding trailing new-lines (issue 14902)
2022-05-11 12:52:07 +02:00
Jonas Jenwald
527251d62b Update the preprocess-function to avoid adding trailing new-lines (issue 14902)
*This is a follow-up to PR 14886, which "broke" this.*

In addition to fixing the issue, using an Array and `join`-ing it at the end may also be a tiny bit more efficient than using a growing string.
2022-05-11 12:36:00 +02:00
Jonas Jenwald
af5789125f Try to remove the mozOpaque canvas-property (PR 6551 follow-up)
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/mozOpaque, the `mozOpaque` canvas-property is not only non-standard (obviously) but it's also been deprecated.
Instead it's recommended to use `alpha = false` when getting the canvas-context, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#contextattributes, which all of our affected code is already doing.
2022-05-09 13:03:08 +02:00
Jonas Jenwald
38c82357b2
Merge pull request #14890 from calixteman/14889
[JS] Formatted value has to be a string when neither null nor undefined
2022-05-08 17:25:29 +02:00
Calixte Denizet
ab3958d6e8 [JS] Formatted value has to be a string when neither null nor undefined 2022-05-08 16:43:57 +02:00
Tim van der Meij
72943ae630
Merge pull request #14886 from Snuffleupagus/preprocessCSS-refactor
Use the regular `preprocess`-function for the CSS files as well
2022-05-08 13:53:14 +02:00
Tim van der Meij
753abc383e
Merge pull request #14888 from Snuffleupagus/attachmentsCount-zero
Try to fix dispatching of "attachmentsloaded"-events, when the document contains no "regular" attachments (PR 8788, 12163 follow-up)
2022-05-08 13:44:14 +02:00
Tim van der Meij
7111a172df
Merge pull request #14885 from Snuffleupagus/mozcentral-rm-unbindEvents
Stop bundling `PDFViewerApplication.{unbindEvents, unbindWindowEvents}` in MOZCENTRAL builds
2022-05-08 13:35:22 +02:00
Jonas Jenwald
3d9b2c9cd5
Merge pull request #14887 from Snuffleupagus/pageColors-followup
Ignore `pageColors` when the background/foreground is identical (PR 14874 follow-up)
2022-05-08 12:58:55 +02:00
Jonas Jenwald
dacea52966 Try to fix dispatching of "attachmentsloaded"-events, when the document contains no "regular" attachments (PR 8788, 12163 follow-up)
*This patch can be tested, in the viewer, using the `annotation-fileattachment.pdf` document from the test-suite.*

It seems that the code to delay dispatching of the "attachmentsloaded"-event, when `attachmentsCount === 0`, is now effectively broken.[1]
Rather than only using an arbitrary timeout, the new code will instead wait for an "annotationlayerrendered"-event and only *fallback* to using a timeout.

---
[1] The timing of the annotationLayer-rendering changed slightly in PR 14247, and the old code in `PDFAttachmentViewer` wasn't good enough to handle that.
2022-05-08 12:12:49 +02:00
Jonas Jenwald
472a1f9c91 Ignore pageColors when the background/foreground is identical (PR 14874 follow-up)
If the computed background/foreground colors are identical, the `canvas` would be rendered mostly blank with only images visible. Hence it seems reasonable to also ignore the `pageColors`-option in this case.

Also, the patch tries to *briefly* outline the various cases in which we ignore the `pageColors`-option in a comment.
2022-05-08 11:40:50 +02:00
Jonas Jenwald
39251c5789 Re-order the names of the new pageColors options/preferences (PR 14874 follow-up)
Given that the new API-option is an Object named `pageColors`, with `background`/`foreground` keys, it occurred to me that it'd be slightly more consistent if the options/preferences names fully reflected that.
2022-05-08 11:15:04 +02:00
Jonas Jenwald
80910f44e5 Stop bundling the openFile-buttons in the CHROME build
This is, for all intents and purposes, equivalent to PR 14833 and slightly reduces the size of the `gulp chromium` output.
2022-05-07 22:45:56 +02:00
Jonas Jenwald
d1f13a6af3 Use the regular preprocess-function for the CSS files as well
An old shortcoming of the `preprocessCSS`-function is its complete lack of support for our "normal" defines, which makes it very difficult to have build-specific CSS rules. Recently we've started using specially crafted comments to remove CSS rules from the MOZCENTRAL build, but (ab)using the `preprocessCSS`-function in this way really doesn't feel great.
However, it turns out to be surprisingly simple to instead use the "regular" `preprocess`-function for the CSS files as well. The only special-handling that's still necessary is the helper-function for dealing with CSS-imports, but apart from that everything seems to just work.

One reason, as far as I can tell, for having a separate `preprocessCSS`-function was likely that we originally used *lots* of vendor-prefixed CSS rules in our CSS files. With improvements over the years, especially thanks to Autoprefixer and PostCSS, we've been able to remove *almost* all non-standard CSS rules and the need for special-casing the CSS parsing has mostly vanished.

*Please note:* As part of testing this patch I've diffed the output of `gulp generic`, `gulp mozcentral`, and `gulp chromium` against the `master`-branch to check that there was no obvious breakage.
2022-05-07 22:45:52 +02:00
Jonas Jenwald
ed8b172d12 Stop bundling PDFViewerApplication.{unbindEvents, unbindWindowEvents} in MOZCENTRAL builds
These methods are completely unused in the Firefox PDF Viewer, and were only added to supplement the `PDFViewerApplication.{bindEvents, bindWindowEvents}`-methods since third-party implementations may apparently need to remove event listeners (see PR 8525).
However, in the MOZCENTRAL build that's just dead code and this patch reduces the size of the *built* `web/viewer.js`-file by `~3.5` kB.
2022-05-07 15:51:32 +02:00
Tim van der Meij
f8838eb794
Merge pull request #14882 from Snuffleupagus/issue-14881
Add support for TrueType format 12 `cmap`s (issue 14881)
2022-05-07 11:45:54 +02:00
Tim van der Meij
0a34b3bb81
Merge pull request #14884 from Snuffleupagus/fileattachmentannotation-event
Simplify the "fileattachmentannotation"-event handling a little bit
2022-05-07 11:35:40 +02:00
Tim van der Meij
82353cf728
Merge pull request #14880 from Snuffleupagus/CSS--viewer-container-height
Introduce a `--viewer-container-height` CSS variable to simplify the code
2022-05-07 11:25:32 +02:00
Tim van der Meij
be67ec4a10
Merge pull request #14877 from Snuffleupagus/PresentationMode-spreadMode
Add (basic) support for Spread modes in PresentationMode (issue 14749)
2022-05-07 11:19:20 +02:00
Jonas Jenwald
7f40ef41a5 Simplify the "fileattachmentannotation"-event handling a little bit
*This patch can be tested, in the viewer, using the `annotation-fileattachment.pdf` document from the test-suite.*

Note how the `FileSpec`-implementation already uses `stringToPDFString` during the filename lookup, see cfac6fa511/src/core/file_spec.js (L70)
Hence there's no reason to repeat that again in the `FileAttachmentAnnotationElement`-constructor, and we can thus simplify the "fileattachmentannotation"-event handling a little bit.
2022-05-06 20:55:18 +02:00
Jonas Jenwald
9817230ef8 Introduce a --viewer-container-height CSS variable to simplify the code
This new CSS variable will allow us to simplify a couple of different viewer components, since we no longer need to use JavaScript-based hacks and can directly set the CSS rules instead. In particular:

 - The `BaseViewer`-handling, used as part of the code that will center pages *vertically* in PresentationMode, can be simplified.
   By using CSS to control the height of the "dummy"-page we avoid unnecessarily invalidating the scale-value, which can reduce *some* unneeded re-rendering while PresentationMode is active.

 - The `SecondaryToolbar.#setMaxHeight`-method, and its associated parameters, are no longer necessary and can be completely removed.

Note that in order for things to work correctly in general, the new `--viewer-container-height` CSS variable must potentially be updated on any window-based "resize"-event (even when there's no zooming). While this is currently only done in the default viewer, that shouldn't be an issue since neither PresentationMode nor Toolbar-functionality is included in the "viewer components".
2022-05-06 13:45:39 +02:00
Jonas Jenwald
6e7e9d83d8 Add support for TrueType format 12 cmaps (issue 14881)
This is, as far as I can tell, the first case we've seen of a format 12 `cmap`.
Please see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html
2022-05-06 11:11:38 +02:00
calixteman
cfac6fa511
Merge pull request #14874 from calixteman/colors
[api-minor] Improve pdf reading in high contrast mode
2022-05-05 21:48:19 +02:00
Calixte Denizet
c8afd6ce8c [api-minor] Improve pdf reading in high contrast mode
- Use Canvas & CanvasText color when they don't have their default value
  as background and foreground colors.
- The colors used to draw (stroke/fill) in a pdf are replaced by the bg/fg
  ones according to their luminance.
2022-05-05 16:34:51 +02:00
Jonas Jenwald
4fffab4ad3 Add (basic) support for Spread modes in PresentationMode (issue 14749)
After recent changes, adding *basic* Spread mode support in PresentationMode has now become reasonably straightforward.

However, documents with *varying* page sizes are non-trivial to handle and would require re-writing (or at least re-factoring) a bunch of the zooming-code.
Hence this PR *purposely* only allow Spread modes to be used, in PresentationMode, for documents where all pages have exactly the same size. While this obviously isn't a fully complete solution, it will however cover the vast majority of all documents and should hopefully be deemed good enough for now.
2022-05-05 11:53:09 +02:00
Jonas Jenwald
54410d5e41 Simplify the signature of BaseViewer._scrollIntoView and make the method private
In PR 14112 usage of this *internal* method was reduced, and it thus can't hurt to clean-up things a little bit more.
Note in particular that we can simplify the call-sites by directly passing in the already available `PDFPageView`-instance, since the `id`-property those contain can replace the previous `pageNumber`-parameter[1].

Given that the method name has always been prefixed with an underscore it was thus never intended to be "public", hence we can now enforce that with modern ECMAScript features.

---
[1] There's already a bunch of other spots, throughout the viewer-code, where we assume that the `PDFPageView.id`-property contains proper page *numbers* (and not e.g. indices); note how we initialize the `PDFPageView`-instances in the `BaseViewer.setDocument`-method.
2022-05-05 11:27:00 +02:00
Tim van der Meij
7d6d6f9151
Merge pull request #14871 from Snuffleupagus/ensurePageViewVisible-PresentationMode-refactor
Re-factor the PresentationMode handling in `BaseViewer.#ensurePageViewVisible`
2022-05-04 22:41:29 +02:00
Tim van der Meij
899e4d58d6
Merge pull request #14870 from Snuffleupagus/isNodeJS-cleanup
Only bundle the `src/display/node_utils.js` file in GENERIC-builds
2022-05-04 22:38:21 +02:00
Tim van der Meij
8b8a09e52f
Merge pull request #14873 from Snuffleupagus/AnnotationStorage-hash
Replace the `AnnotationStorage.lastModified`-getter with a proper hash-method
2022-05-04 22:33:49 +02:00
Jonas Jenwald
8267fd8a52 Replace the AnnotationStorage.lastModified-getter with a proper hash-method
The current `lastModified`-getter, which only contains a time-stamp, is a fairly crude way of detecting if the stored data has actually been changed. In particular, when the `getRawValue`-method is used, the `lastModified`-getter doesn't cope with data being modified from the "outside".

To fix these issues[1], and to prevent any future bugs in this code, this patch introduces a new `AnnotationStorage.hash`-getter which computes a hash of the currently stored data. To simplify things this re-uses the existing `MurmurHash3_64`-implementation, which required moving that file into the `src/shared/`-folder, since its performance should be good enough here.

---
[1] Given how the `AnnotationStorage.lastModified`-getter was used, this would have been limited to *printing* of forms.
2022-05-04 15:21:30 +02:00
Jonas Jenwald
8135d7ccf6
Merge pull request #14869 from calixteman/14862
[JS] Fix few bugs present in the pdf for issue #14862
2022-05-03 18:31:31 +02:00
Calixte Denizet
6b866a5efa Add a small delay when typing in some integration tests to avoid intermittent failures 2022-05-03 16:25:29 +02:00
Calixte Denizet
094ff38da0 [JS] Fix few bugs present in the pdf for issue #14862
- since resetForm function reset a field value a calculateNow is consequently triggered.
  But the calculate callback can itself call resetForm, hence an infinite recursive loop.
  So basically, prevent calculeNow to be triggered by itself.
- in Firefox, the letters entered in some fields were duplicated: "AaBb" instead of "AB".
  It was mainly because beforeInput was triggering a Keystroke which was itself triggering
  an input value update and then the input event was triggered.
  So in order to avoid that, beforeInput calls preventDefault and then it's up to the JS to
  handle the event.
- fields have a property valueAsString which returns the value as a string. In the
  implementation it was wrongly used to store the formatted value of a field (2€ when the user
  entered 2). So this patch implements correctly valueAsString.
- non-rendered fields can be updated in using JS but when they're, they must take some properties
  in the annotationStorage. It was implemented for field values, but it wasn't for
  display, colors, ...
- it fixes #14862 and #14705.
2022-05-03 15:48:44 +02:00
Jonas Jenwald
aad4c6538f Re-factor the PresentationMode handling in BaseViewer.#ensurePageViewVisible
Given that we're (ab)using spread-modes in order to ensure that pages are centered *vertically* in PresentationMode, this re-factoring simplifies the code slightly.
Furthermore, in the event that we *possibly* want to try and support spread-modes in PresentationMode[1] this re-factoring will also prevent future duplication.

---
[1] Note that I'm not particularly keen on doing that, since documents with varying page sizes will be annoying to handle.
2022-05-03 13:25:34 +02:00
Jonas Jenwald
d4fe4fd97b Simplify a couple of isNodeJS-dependent getDocument default values
Given that the `isNodeJS`-constant will, after PR 14858, *always* be `false` in non-GENERIC builds we can simplify a couple of `getDocument`-parameter default values slightly.
The old format, with inline `PDFJSDev`-checks, wasn't exactly a wonder of readability; which was my fault.
2022-05-03 11:36:10 +02:00
Jonas Jenwald
7df47c289f Only bundle the src/display/node_utils.js file in GENERIC-builds
This first of all simplifies the file, since we no longer need dummy-classes and can instead *directly* define the actual classes.
Furthermore, and more importantly, this means that we no longer need to bundle this code in e.g. MOZCENTRAL-builds which reduces the size of *built* `pdf.js` file slightly.
2022-05-03 11:34:35 +02:00
Jonas Jenwald
da4f7dfcd0
Merge pull request #14866 from Snuffleupagus/Type3-release-Uint8Arrays
Immediately release the temporary `Uint8Array`s used during Type3-compilation
2022-05-02 15:09:59 +02:00
Jonas Jenwald
67719af9df Immediately release the temporary Uint8Arrays used during Type3-compilation
Given that the `compileType3Glyph` function *returns* a function, see `drawOutline`, we'll thus keep the surrounding scope alive. Hence it shouldn't hurt to *explicitly* mark the temporary `Uint8Array`s, used during parsing, as no longer needed. Given the current `MAX_SIZE_TO_COMPILE`-value these `Uint8Array`s may be approximately two mega-bytes large *for every* Type3-glyph.
2022-05-02 13:25:48 +02:00
Jonas Jenwald
db12492584
Merge pull request #14865 from Snuffleupagus/issue-14864
Support encoded dest-strings in /GoTo destination dictionaries (issue 14864)
2022-05-02 13:00:11 +02:00
Jonas Jenwald
85b7e60425
Merge pull request #14863 from calixteman/update-quickjs
Update quickjs to revision 2788d71e823b522b178db3b3660ce93689534e6d
2022-05-02 11:46:07 +02:00
Jonas Jenwald
df5a4fd0a7 Support encoded dest-strings in /GoTo destination dictionaries (issue 14864)
Interestingly enough this appears to be the very first case of *encoded* dest-strings, in /GoTo destination dictionaries, that we've actually come across. What's really fascinating is that it's less than a week after issue 14847, given that these issues are *somewhat* similar.
2022-05-02 10:14:32 +02:00
Calixte Denizet
2dba91e0ed Update quickjs to revision 2788d71e823b522b178db3b3660ce93689534e6d
- The date parser in quickjs is not optimal so use the navigator one.
2022-05-01 15:53:50 +02:00
Tim van der Meij
397f71424c
Merge pull request #14861 from timvandermeij/es-module-shims
Pin the `es-module-shims` dependency to version 1.4.7
2022-05-01 14:32:18 +02:00
Tim van der Meij
5ec8c3c191
Merge pull request #14858 from Snuffleupagus/Type3-Path2D
Use `Path2D`, if available, when rendering Type3-fonts (bug 810214)
2022-05-01 14:29:56 +02:00
Tim van der Meij
3af52dacb5
Pin the es-module-shims dependency to version 1.4.7
Unfortunately newer versions either caused breakage when running the
unit tests manually in a browser or when serving the development viewer.
Given that we hope to use native import maps soon and this dependency
will then be removed anyway, let's pin it for the time being.
2022-05-01 14:05:30 +02:00
Jonas Jenwald
e658acffbc Slightly re-factor the compileType3Glyph function
This moves the `COMPILE_TYPE3_GLYPHS`/`MAX_SIZE_TO_COMPILE`-checks into the `compileType3Glyph` function itself, which allows for some simplification at the call-site.
These changes also mean that the `COMPILE_TYPE3_GLYPHS`-check is now done *once* per Type3-glyph, rather than everytime that the glyph is being rendered.
2022-05-01 13:56:35 +02:00
Jonas Jenwald
c2488c7864 Use Path2D, if available, when rendering Type3-fonts (bug 810214)
Note that in order to avoid unnecessary allocations we build the `Path2D`-object *inline* during parsing, rather than iterating through the complete `outlines`-Array at the end.

This patch was tested using the PDF file from bug 810214, i.e. https://bug810214.bmoattachments.org/attachment.cgi?id=9254990, with the following manifest file:
```
[
    {  "id": "bug810214",
       "file": "../web/pdfs/bug810214.pdf",
       "md5": "2b7243178f5dd5fd3edc7b6649e4bdf3",
       "rounds": 100,
       "lastPage": 25,
       "type": "eq"
    }
]

```

which gave the following results when comparing this patch against the `master` branch:
 - Overall
```
-- Grouped By browser, stat --
browser | stat         | Count | Baseline(ms) | Current(ms) | +/- |     %  | Result(P<.05)
------- | ------------ | ----- | ------------ | ----------- | --- | ------ | -------------
firefox | Overall      |  2500 |          123 |          78 | -44 | -36.25 |        faster
firefox | Page Request |  2500 |            2 |           2 |   0 |   9.11 |        slower
firefox | Rendering    |  2500 |          121 |          76 | -45 | -36.93 |        faster
```

 - Page-specific
```
-- Grouped By browser, page, stat --
browser | page | stat         | Count | Baseline(ms) | Current(ms) | +/- |     %  | Result(P<.05)
------- | ---- | ------------ | ----- | ------------ | ----------- | --- | ------ | -------------
firefox | 0    | Overall      |   100 |           36 |          35 |  -1 |  -2.89 |
firefox | 0    | Page Request |   100 |            2 |           2 |   0 |   7.33 |
firefox | 0    | Rendering    |   100 |           34 |          33 |  -1 |  -3.47 |
firefox | 1    | Overall      |   100 |          123 |          81 | -42 | -33.92 |        faster
firefox | 1    | Page Request |   100 |            2 |           2 |   0 |  -3.31 |
firefox | 1    | Rendering    |   100 |          121 |          79 | -42 | -34.44 |        faster
firefox | 2    | Overall      |   100 |          129 |          82 | -47 | -36.61 |        faster
firefox | 2    | Page Request |   100 |            2 |           2 |   0 |  24.84 |        slower
firefox | 2    | Rendering    |   100 |          127 |          80 | -47 | -37.33 |        faster
firefox | 3    | Overall      |   100 |          114 |          68 | -46 | -40.18 |        faster
firefox | 3    | Page Request |   100 |            2 |           2 |   0 |  15.63 |        slower
firefox | 3    | Rendering    |   100 |          112 |          66 | -46 | -41.07 |        faster
firefox | 4    | Overall      |   100 |          102 |          75 | -27 | -26.09 |        faster
firefox | 4    | Page Request |   100 |            2 |           2 |   0 |   9.62 |
firefox | 4    | Rendering    |   100 |          100 |          73 | -27 | -26.71 |        faster
firefox | 5    | Overall      |   100 |          103 |          77 | -26 | -25.15 |        faster
firefox | 5    | Page Request |   100 |            2 |           2 |   0 |  -6.86 |
firefox | 5    | Rendering    |   100 |          100 |          75 | -26 | -25.53 |        faster
firefox | 6    | Overall      |   100 |           48 |          37 | -11 | -22.56 |        faster
firefox | 6    | Page Request |   100 |            2 |           2 |   0 | -10.14 |
firefox | 6    | Rendering    |   100 |           46 |          35 | -11 | -23.16 |        faster
firefox | 7    | Overall      |   100 |          109 |          70 | -39 | -35.59 |        faster
firefox | 7    | Page Request |   100 |            2 |           2 |   0 |   5.29 |
firefox | 7    | Rendering    |   100 |          107 |          68 | -39 | -36.23 |        faster
firefox | 8    | Overall      |   100 |           39 |          31 |  -9 | -22.14 |        faster
firefox | 8    | Page Request |   100 |            2 |           2 |   0 |   1.72 |
firefox | 8    | Rendering    |   100 |           38 |          29 |  -9 | -23.38 |        faster
firefox | 9    | Overall      |   100 |          156 |          96 | -60 | -38.49 |        faster
firefox | 9    | Page Request |   100 |            1 |           2 |   0 |  13.61 |
firefox | 9    | Rendering    |   100 |          155 |          94 | -60 | -38.98 |        faster
firefox | 10   | Overall      |   100 |          173 |         105 | -68 | -39.20 |        faster
firefox | 10   | Page Request |   100 |            2 |           2 |   0 |  -8.81 |
firefox | 10   | Rendering    |   100 |          171 |         103 | -68 | -39.60 |        faster
firefox | 11   | Overall      |   100 |          152 |          89 | -64 | -41.88 |        faster
firefox | 11   | Page Request |   100 |            2 |           2 |   0 |   6.04 |
firefox | 11   | Rendering    |   100 |          150 |          87 | -64 | -42.47 |        faster
firefox | 12   | Overall      |   100 |          141 |          90 | -51 | -35.91 |        faster
firefox | 12   | Page Request |   100 |            2 |           2 |   0 |  17.37 |
firefox | 12   | Rendering    |   100 |          139 |          88 | -51 | -36.60 |        faster
firefox | 13   | Overall      |   100 |           97 |          61 | -36 | -36.79 |        faster
firefox | 13   | Page Request |   100 |            2 |           2 |   0 |  25.44 |        slower
firefox | 13   | Rendering    |   100 |           95 |          59 | -36 | -37.87 |        faster
firefox | 14   | Overall      |   100 |          118 |          82 | -36 | -30.33 |        faster
firefox | 14   | Page Request |   100 |            2 |           2 |   0 |   9.20 |
firefox | 14   | Rendering    |   100 |          117 |          80 | -36 | -30.95 |        faster
firefox | 15   | Overall      |   100 |          111 |          73 | -37 | -33.85 |        faster
firefox | 15   | Page Request |   100 |            2 |           2 |   0 |  13.25 |
firefox | 15   | Rendering    |   100 |          109 |          71 | -38 | -34.61 |        faster
firefox | 16   | Overall      |   100 |          145 |          88 | -57 | -39.19 |        faster
firefox | 16   | Page Request |   100 |            2 |           2 |   1 |  33.75 |        slower
firefox | 16   | Rendering    |   100 |          143 |          86 | -57 | -40.03 |        faster
firefox | 17   | Overall      |   100 |          171 |         126 | -45 | -26.27 |        faster
firefox | 17   | Page Request |   100 |            2 |           2 |   0 |  17.92 |        slower
firefox | 17   | Rendering    |   100 |          169 |         124 | -45 | -26.69 |        faster
firefox | 18   | Overall      |   100 |          126 |          78 | -47 | -37.71 |        faster
firefox | 18   | Page Request |   100 |            2 |           2 |   0 |   2.43 |
firefox | 18   | Rendering    |   100 |          124 |          76 | -48 | -38.43 |        faster
firefox | 19   | Overall      |   100 |           92 |          58 | -34 | -37.19 |        faster
firefox | 19   | Page Request |   100 |            2 |           2 |   0 |  12.74 |
firefox | 19   | Rendering    |   100 |           90 |          56 | -35 | -38.13 |        faster
firefox | 20   | Overall      |   100 |          178 |          96 | -82 | -46.18 |        faster
firefox | 20   | Page Request |   100 |            2 |           2 |   0 |  -2.23 |
firefox | 20   | Rendering    |   100 |          176 |          94 | -82 | -46.67 |        faster
firefox | 21   | Overall      |   100 |          181 |         102 | -79 | -43.77 |        faster
firefox | 21   | Page Request |   100 |            2 |           2 |   0 |  12.36 |        slower
firefox | 21   | Rendering    |   100 |          179 |          99 | -79 | -44.34 |        faster
firefox | 22   | Overall      |   100 |          140 |          84 | -55 | -39.59 |        faster
firefox | 22   | Page Request |   100 |            2 |           2 |   0 |  12.50 |
firefox | 22   | Rendering    |   100 |          138 |          82 | -55 | -40.25 |        faster
firefox | 23   | Overall      |   100 |          119 |          73 | -46 | -38.48 |        faster
firefox | 23   | Page Request |   100 |            2 |           2 |   1 |  35.71 |        slower
firefox | 23   | Rendering    |   100 |          117 |          71 | -46 | -39.48 |        faster
firefox | 24   | Overall      |   100 |          165 |          96 | -68 | -41.51 |        faster
firefox | 24   | Page Request |   100 |            2 |           2 |   0 |   2.81 |
firefox | 24   | Rendering    |   100 |          163 |          94 | -68 | -42.00 |        faster
```
2022-05-01 13:56:35 +02:00
Jonas Jenwald
4bd5d98d59
Merge pull request #14860 from timvandermeij/updates
Update dependencies and translations
2022-05-01 13:44:23 +02:00
Tim van der Meij
58fed00bc3
Update translations to the most recent versions 2022-05-01 13:10:20 +02:00
Tim van der Meij
dacd61fede
Update dependencies to the most recent versions
There are two notable changes here:

- `dommatrix` is a major version upgrade, but looking through the commit
  history of their `package.json` file at https://github.com/thednp/dommatrix/commits/master/package.json
  (due to the lack of a changelog) I couldn't find any breaking changes.
- `es-module-shims` is a regular update, but it was previously pinned
  for causing intermittent breakage when running the unit tests in a
  browser manually. Fortunately this cannot be reproduced anymore with
  the most recent version, so we can also put the caret back now.
2022-05-01 13:08:00 +02:00
Tim van der Meij
75ac897284
Merge pull request #14857 from Snuffleupagus/rm-webViewerOpenFileViaURL
Inline the `webViewerOpenFileViaURL` function in  `webViewerInitialized`
2022-04-30 12:21:25 +02:00
Tim van der Meij
e5e2941d53
Merge pull request #14854 from Snuffleupagus/viewer-rm-button-classes
Remove redundant class names from the button DOM-elements
2022-04-30 12:18:16 +02:00
calixteman
b10b8dad7d
Merge pull request #14853 from calixteman/white_lines
Use integer coordinates when drawing images (bug 1264608, issue #3351)
2022-04-29 18:15:03 +02:00
Jonas Jenwald
9268924a15 Only define the webViewerFileInputChange/webViewerOpenFile variables in GENERIC builds
There's no point in having these variables defined (implicitly) as `undefined` in e.g. the Firefox PDF Viewer.
By defining them with `var` and using ESList ignores, rather than `let`, we can move them into the relevant pre-processor block instead. Note that since the entire viewer-code is placed, by Webpack, in a top-level closure these variables will thus *not* become globally accessible.
2022-04-29 18:07:56 +02:00
Jonas Jenwald
7cce41c26d Inline the webViewerOpenFileViaURL function in webViewerInitialized
Given that `webViewerOpenFileViaURL` only has a single call-site, and also isn't a particularly large/complex function, it doesn't seem necessary for this to be a separate function and hence it's simply inlined instead.

Also, changes the "no valid build-target was set"-case to throw unconditionally since the only way that it could ever be hit is if there are bugs in the `gulpfile`-code.
2022-04-29 18:07:52 +02:00
Calixte Denizet
624d8a8e3e Use integer coordinates when drawing images (bug 1264608, issue #3351)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1264608;
- it's only a partial fix for #3351;
- some tiled images have some spurious white lines between the tiles.
  When the current transform is applyed the corners of an image can have
  some non-integer coordinates leading to some extra transparency added
  to handle that. So with this patch the current transform is applied on the
  point and on the dimensions in order to have at the end only integer values.
2022-04-29 16:01:34 +02:00
Jonas Jenwald
24d5d5d761
Merge pull request #14856 from Snuffleupagus/rm-forceClamped
[api-minor] Remove the `forceClamped`-functionality in the Streams (issue 14849)
2022-04-29 15:19:17 +02:00
Jonas Jenwald
fbf6dee8ee [api-minor] Remove the forceClamped-functionality in the Streams (issue 14849)
As it turns out, most of the code-paths in the `PDFImage`-class won't actually pass the TypedArray (containing the image-data) to the `ColorSpace`-code. Hence we *generally* don't need to force the image-data to be a `Uint8ClampedArray`, and can just as well directly use a `Uint8Array` instead.

In the following cases we're returning the data without any `ColorSpace`-parsing, and the exact TypedArray used shouldn't matter:
 - b72a448327/src/core/image.js (L714)
 - b72a448327/src/core/image.js (L751)

In the following cases the image-data is only used *internally*, and again the exact TypedArray used shouldn't matter:
 - b72a448327/src/core/image.js (L762) with the actual image-data being defined (as `Uint8ClampedArray`) further below
 - b72a448327/src/core/image.js (L837)

*Please note:* This is tagged `api-minor` because it's API-observable, given that *some* image/mask-data will now be returned as `Uint8Array` rather than using `Uint8ClampedArray` unconditionally. However, that seems like a small price to pay to (slightly) reduce memory usage during image-conversion.
2022-04-29 14:46:30 +02:00
Jonas Jenwald
1e24fe97f2 Remove unnecessary CSS classes when specifying button icons
Currently we're using *both* ids and classes when specifying the button icons, which seems completely unnecessary and only serves to bloat the CSS code.
In general you always need to be careful about CSS specificity, but in these cases that should not actually be a problem.

Also, while not a button, this patch makes a similar simplification for the `pageNumber`-input.
2022-04-29 09:40:03 +02:00
Jonas Jenwald
4f69d66ab2 Remove redundant class names from the button DOM-elements
Note how in the `viewer.html` file we're specifying class names for most buttons, despite that not really being necessary. First of all, in many cases those class names are *identical* to the element-ids. Secondly, looking through the CSS rules they are only ever used when specifying button icons.
All-in-all, we should be able to simplify the HTML-code and use the element-ids in the CSS rules instead. Obviously ids have a higher CSS specificity than classes, but given how the old classes were being used that shouldn't be a problem here.

Also, the patch generalizes the styling for buttons (e.g. `viewBookmark`) that are *actually* link-elements.

Finally, while slightly unrelated, this patch also removes a little bit of duplication when specifying the border for `toolbarField`s.
2022-04-29 09:36:35 +02:00
Tim van der Meij
b72a448327
Merge pull request #14835 from Snuffleupagus/CSS-cleanup-separators
Clean-up some CSS rules for the various toolbar separators
2022-04-27 14:32:23 +02:00
Tim van der Meij
5ca9f9bf86
Merge pull request #14833 from Snuffleupagus/mozcentral-rm-openFile-buttons
Stop bundling the openFile-buttons in the MOZCENTRAL build
2022-04-27 14:27:46 +02:00
Jonas Jenwald
694cb311c0
Merge pull request #14848 from Snuffleupagus/issue-14847
Support destinations in NameTrees with encoded keys (issue 14847)
2022-04-27 12:15:48 +02:00
Jonas Jenwald
71370d012b Support destinations in NameTrees with encoded keys (issue 14847)
Initially I considered updating the `NameOrNumberTree`-implementation to handle encoded keys, however that quickly became somewhat messy (especially in the `NameOrNumberTree.get`-method) since only NameTrees using string-keys.
Hence the easiest solution, as far as I'm concerned, was thus to just update the `Catalog.destinations`-getter instead. Please note that in the referenced PDF document the `Catalog.destination`-method will thus fallback to fetch all destinations, which should be fine since this is the very first case of encoded keys that we've seen.

Also changes the `NameOrNumberTree.getAll`-method to prevent a possible run-time error, although we've so far not seen such a case, for any non-Array Kids-entries found in a NameTree/NumberTree.

Finally, to improve overall consistency and to hopefully prevent future bugs, the patch also updates a couple of other `NameTree` call-sites to correctly handle encoded keys. (Note that the `Catalog.attachments`-getter was already doing this.)
2022-04-27 11:19:55 +02:00
Jonas Jenwald
981cd5bbfc
Merge pull request #14836 from calixteman/fix_integration
Don't use pref 'browser.download.improvements_to_download_panel' in Firefox (#14822)
2022-04-25 15:23:44 +02:00
Calixte Denizet
314fd83bba Don't use pref 'browser.download.improvements_to_download_panel' in Firefox (#14822) 2022-04-25 15:05:43 +02:00
Jonas Jenwald
3c10c66cd3 Remove unused CSS rules for toolbar buttons with textButton-classes
Searching through all of the files in the `web/`-folder has no *other* hits for the "textButton" string. Hence it's clear that there are no DOM elements actually using this class, and it's thus dead code.
2022-04-25 14:55:32 +02:00
Jonas Jenwald
f9262d29fc Clean-up some CSS rules for the various toolbar separators
This re-factors the various toolbar separators to *explicitly* specify both their dimensions and margins. Also, for the `horizontalToolbarSeparator`-class we can just set the `background-color` rather than using `border-top`.

Note that the `splitToolbarButtonSeparator`-class currently sets a number of unnecessary CSS rules, since as mentioned by the Firefox Devtools both the `display`- and `z-index`-properties are being ignored because `float` is used.

Finally, there's also no need to set a `z-index` for some of the `:hover`-rules. It's possible that this *was* necessary before the re-design, since the buttons had borders then.
2022-04-25 14:53:12 +02:00
Jonas Jenwald
b04c373362 Stop bundling the openFile-buttons in the MOZCENTRAL build
Note how both of the openFile-buttons are always hidden during viewer initialization in the MOZCENTRAL build, i.e. the *built-in* Firefox PDF Viewer. Despite that we still include HTML, CSS, and JavaScript code for these buttons in the build.

This patch *reduces* the size of the `gulp mozcentral` output by `1679` bytes, which isn't a lot but still cannot hurt.
2022-04-25 11:35:17 +02:00
Tim van der Meij
2be19e828f
Merge pull request #14831 from Snuffleupagus/incrementCachedImageMaskCount
Add a helper function for incrementing the `count` of cached ImageMasks
2022-04-24 11:47:07 +02:00
Tim van der Meij
41065d7825
Merge pull request #14829 from Snuffleupagus/rm-print-CSS
Remove unnecessary `print` CSS rules
2022-04-24 11:21:34 +02:00
Jonas Jenwald
e18edf38db Add a helper function for incrementing the count of cached ImageMasks
While working on PR 14825, I couldn't help noticing that the code to increment the `count` for cached ImageMasks was repeated multiple times. Hence it makes sense, as far as I'm concerned, to move this into a helper function instead.
2022-04-24 11:10:02 +02:00
Jonas Jenwald
925a7bc58a Remove unnecessary print CSS rules
These rules became unnecessary with PR 7697, over five years ago, since printing is now done from a `printContainer`-element rather than "directly" using the viewer.

Note how the *entire* `outerContainer`, which contains all of the DOM elements that were being manually hidden, is now being hidden during printing. Furthermore, note also how the print-canvases/images and their containers are using custom CSS-classes[1] rather than re-using the ones from the viewer.

---
[1] See the `printedPage` respectively `xfaPrintedPage` classes.
2022-04-23 14:32:00 +02:00
Tim van der Meij
752dee5caa
Merge pull request #14825 from Snuffleupagus/issue-14824
Ensure that worker-thread image caching doesn't break optional content (issue 14824)
2022-04-23 13:19:56 +02:00
Tim van der Meij
f9e54d9226
Merge pull request #14823 from Snuffleupagus/issue-14821
Ignore invalid /Encoding-entries when parsing fonts (issue 14821)
2022-04-23 13:19:26 +02:00
Tim van der Meij
18dd2866f7
Merge pull request #14827 from Snuffleupagus/toolbar-margin
Simplify setting of spacing at the left/right edges of the toolbar(s)
2022-04-23 13:11:16 +02:00
Tim van der Meij
1921c4612d
Merge pull request #14828 from Snuffleupagus/viewer-more-for-of
Use more `for...of` loops in the viewer
2022-04-23 13:09:32 +02:00
Jonas Jenwald
7e57469683 Use more for...of loops in the viewer
Note that the arrays that we're looping over here are by definition *dense*, hence there's no point in checking if each element actually exists first.
2022-04-23 12:48:54 +02:00
Jonas Jenwald
33ed743c48 Simplify setting of spacing at the left/right edges of the toolbar(s)
Rather than modifying the leading/trailing `margin` on the actual toolbar buttons, to achieve appropriate spacing at the left/right edges of the toolbar(s), it seems much more appropriate (and simpler) to just specify an explicit `padding` for the relevant toolbar containers.

Also, for toolbar buttons placed in `splitToolbarButton`-classes we can reduce some complexity around setting the `margin` (since it should always be zero now).

With these changes, we're thus able to get rid of a couple more `!important`-rules.
2022-04-22 18:15:28 +02:00
Jonas Jenwald
6c229dffb1 Ensure that worker-thread image caching doesn't break optional content (issue 14824)
Currently we only insert optionalContent-data into the operatorList the first time that an image is parsed, which will (in hindsight) obviously cause problems for cached images.
Hence we also need to insert the optionalContent-data in the various worker-thread image caches, such that it can be accessed in the fast-paths that are used to skip re-parsing of images.

In order to reduce the amount of repeated code, this patch also adds a new `OperatorList`-method that takes care of inserting the necessary data in the operatorList.
2022-04-22 14:49:16 +02:00
Jonas Jenwald
e723da7261 Ignore invalid /Encoding-entries when parsing fonts (issue 14821)
In the referenced PDF document the fonts have /Encoding-entries that are Streams (containing completely bogus data), which are thus obviously not valid here.
Hence, only when `ignoreErrors` is set, we'll now ignore these corrupt /Encoding-entries and fallback to the existing code to try and infer a usable encoding.

Given that this is *clearly* a case of corrupt PDF documents, there's no guarantee that this will "fix" all such cases, however it's the best that we do here and shouldn't really be worse than ignoring an entire font.
2022-04-22 11:49:03 +02:00
Tim van der Meij
f39219cd45
Merge pull request #14815 from Snuffleupagus/issue-14814
Ignore non-Stream /SMask-entries when parsing images (issue 14814)
2022-04-22 11:39:13 +02:00
Tim van der Meij
7ba71f56b4
Merge pull request #14818 from Sea-n/master
Use correct case for JavaScript
2022-04-22 11:31:55 +02:00
Tim van der Meij
ec28f0aa47
Merge pull request #14817 from Snuffleupagus/more-CSS-cleanup
Some more, small, CSS clean-up
2022-04-22 11:30:32 +02:00
Sean Wei
6bf978404e Use correct case for JavaScript 2022-04-21 23:56:28 +08:00
Jonas Jenwald
0f7e3213a1 Some more, small, CSS clean-up
- Remove a redundant `margin-top` rule for the `.dropdownToolbarButton`. After the (somewhat) recent UI-refresh all buttons now use `margin: 2px 1px;`, which renders the override unnecessary (and getting rid of an `!important`-rule can't hurt).

 - Combine two `.toggled::before` rules, since they're identical.
2022-04-21 15:41:30 +02:00
Jonas Jenwald
39d1bdde09 Ignore non-Stream /SMask-entries when parsing images (issue 14814)
This is similar to the pre-existing check used in the /Mask-case below, to handle *corrupt* PDF documents that include non-Stream /SMask-entries in images; please refer to the PDF specification:
https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#page=216

*Please note:* Adobe Reader also fails to render the image on the second page, and displays an error message.
2022-04-21 12:14:08 +02:00
Tim van der Meij
452a98b0e0
Merge pull request #14810 from Snuffleupagus/mozcentral-rm-errorWrapper-CSS
Stop bundling `errorWrapper` CSS rules in the MOZCENTRAL build
2022-04-20 19:50:57 +02:00
Tim van der Meij
5e8b2e5d25
Merge pull request #14794 from Snuffleupagus/BaseViewer-update-isInPresentationMode
Remove the PresentationMode special-case from `BaseViewer.update`
2022-04-20 19:46:53 +02:00
Jonas Jenwald
1d803451c3 Stop bundling errorWrapper CSS rules in the MOZCENTRAL build
Note that both the `errorWrapper` HTML and JavaScript code is being ignored in the MOZCENTRAL build, i.e. the *built-in* Firefox PDF Viewer, however the CSS rules are still being included.
That seems totally unnecessary, and while we currently don't have full build-target support in the CSS pre-processor we can actually improve things quite easily anyway. By (ab)using the existing CSS pre-processor, which will remove any non-Firefox CSS rules for the MOZCENTRAL build, it's possible to easily stop bundling any CSS rules by using comments that include a `-webkit`-string.

*Please note:* To easily test that this doesn't break the `errorWrapper` in GENERIC builds, try running e.g. `PDFViewerApplication._otherError("test");` in the web-console.
2022-04-20 14:35:09 +02:00
Jonas Jenwald
c91d2ac15a Remove the PresentationMode special-case from BaseViewer.update
This special-case was added because the original PresentationMode-implementation used some CSS-tricks to hide everything except the current page. With the changes in PR 14112, which added a PAGE scroll-mode, many of the old PresentationMode-specific hacks could thus be removed from both the JS and CSS code.

This patch is yet another (small) clean-up step, to reduce the number of PresentationMode special-cases used throughout the `BaseViewer`. Note in particular that `BaseViewer.update` now works just fine in PresentationMode[1], and that we only need to ensure that the active page won't *accidentally* change because of the PresentationMode-specific zooming that occurs during page-switching.

---
[1] In the event that we ever want to try and support spread-modes in PresentationMode, which I'm really not keen on doing since documents with varying page sizes will be annoying to handle, these changes would be necessary as well.
2022-04-20 12:17:00 +02:00
Tim van der Meij
9a8fa3201f
Merge pull request #14803 from Snuffleupagus/issue-14802
Add support for the /Catalog Base-URI when resolving URLs (issue 14802)
2022-04-19 21:41:24 +02:00
Tim van der Meij
c58ff7c301
Merge pull request #14801 from Snuffleupagus/findbar-simplify-button-styling
[GENERIC viewer] Simplify the styling of the previous/next findbar buttons
2022-04-19 21:29:41 +02:00
Tim van der Meij
5032e357d4
Merge pull request #14793 from Snuffleupagus/ensurePageViewVisible-spreads
Simplify spread-mode handling for the PAGE scroll-mode
2022-04-19 21:25:59 +02:00
Tim van der Meij
a115d17b43
Merge pull request #14795 from Snuffleupagus/CSS-reduce-duplication
Reduce more duplication in the CSS
2022-04-19 21:19:05 +02:00
Tim van der Meij
b34fb94c68
Merge pull request #14792 from Snuffleupagus/update-packages
Update packages and translations
2022-04-19 21:17:28 +02:00
Tim van der Meij
5f6ca2224e
Merge pull request #14790 from Snuffleupagus/rm-print-CSS
Remove some outdated CSS rules related to printing
2022-04-19 21:14:42 +02:00
Tim van der Meij
cf320f8fa3
Merge pull request #14788 from Snuffleupagus/debugger-separate-css
Move the `PDFBug`-related CSS from `viewer.css` and into its own file
2022-04-19 21:13:16 +02:00
Jonas Jenwald
5bc7339c1b Add support for the /Catalog Base-URI when resolving URLs (issue 14802)
As far as I can tell, this is actually the very first time that we've seen a PDF document with a Base-URI specified in the /Catalog; please refer to the specification:
https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2097122

To simplify the overall implementation, this new parameter is accessed via the existing `BasePdfManager.docBaseUrl`-getter and will thus override any user-specified `docBaseUrl` API-parameter.
2022-04-19 17:14:52 +02:00
Jonas Jenwald
fb90ef7b28 [GENERIC viewer] Simplify the styling of the previous/next findbar buttons
The styling of the previous/next-buttons and the findInput, with the elements being "glued" together, was supposed to mimic the styling used in the Firefox *browser* findbar. However, after the most recent re-styling of the Firefox browser UI these elements are now visually separated.
Hence it makes sense, as far as I'm concerned, to try and follow this styling for the findbar used in the GENERIC viewer. One benefit of doing this is that we get more consistent styling, since the buttons now look/behave identically in both the main toolbar and the findbar. Additionally this also simplifies the CSS a bit, since a lot of the existing findbar-specific rules can be removed.
2022-04-19 14:12:30 +02:00
Jonas Jenwald
32ae0e4867
Merge pull request #14799 from calixteman/12306-followup
Fix clipping issue with pattern (follow-up of #14797)
2022-04-18 13:17:17 +02:00
Calixte Denizet
c2aa03e194 Fix clipping issue with pattern (follow-up of #14797) 2022-04-18 12:41:14 +02:00
Jonas Jenwald
5bbed400f2
Merge pull request #14797 from calixteman/12306
Don't clip when the clip path is empty (issue #12306)
2022-04-18 11:18:32 +02:00
Jonas Jenwald
f82879205e
Merge pull request #14796 from calixteman/minmax
[api-minor] Simplify min/max computations in constructPath (bug 1135277)
2022-04-18 11:15:23 +02:00
Calixte Denizet
3d74d2c6cb Don't clip when the clip path is empty (issue #12306) 2022-04-18 10:33:44 +02:00
Calixte Denizet
4b7691baf6 Simplify min/max computations in constructPath (bug 1135277)
- most of the time the current transform is a scaling one (modulo translation),
  hence it's possible to avoid to apply the transform on each bbox and then apply
  it a posteriori;
- compute the bbox when it's possible in the worker.
2022-04-17 17:25:54 +02:00
Jonas Jenwald
1ea9740fdb Reduce more duplication in the CSS
This patch combines a couple of different CSS rules, thus reducing the overall size of the file.
2022-04-17 14:03:01 +02:00
calixteman
379125c37f
Merge pull request #14777 from calixteman/mask_perf
[api-minor] Improve performances with image masks (bug 857031)
2022-04-17 12:37:23 +02:00
Jonas Jenwald
03ec7a22f2 Simplify spread-mode handling for the PAGE scroll-mode
The spread-mode code in `BaseViewer.#ensurePageViewVisible`-method was initially copied from the `BaseViewer._updateSpreadMode`-method, which means that it's slightly more complicated than actually necessary.
In particular, in the PAGE scroll-mode there can only be *one* spread active at a time and we thus don't need to handle insertion of multiple spread-divs.
2022-04-17 10:58:14 +02:00
Jonas Jenwald
0c086467a9 Update l10n files 2022-04-17 10:25:20 +02:00
Jonas Jenwald
c727fde767 Fix (some) vulnerabilities reported by npm audit
This was done automatically, using the `npm audit fix` command.
2022-04-17 10:23:09 +02:00
Jonas Jenwald
bb6bb137cf Remove the web-streams-polyfill Babel-exclusion in gulpfile.js (PR 14560 follow-up)
Given that we're no longer, after PR 14560, bundling the `web-streams-polyfill`-code in the `legacy`-builds we shouldn't need to exclude it from Babel now.
2022-04-17 10:16:50 +02:00
Jonas Jenwald
49d1121f3c Update npm packages 2022-04-17 10:15:10 +02:00
Calixte Denizet
f62d961dfe Improve performances with image masks (bug 857031)
- it's the second part of the fix for https://bugzilla.mozilla.org/show_bug.cgi?id=857031;
- some image masks can be used several times but at different positions;
- an image need to be pre-process before to be rendered:
  * rescale it;
  * use the fill color/pattern.
- the two operations above are time consuming so we can cache the generated canvas;
- the cache key is based on the current transform matrix (without the translation part)
  and the current fill color when it isn't a pattern.
- the rendering of the pdf in the above bug is really faster than without this patch.
2022-04-16 20:48:39 +02:00
Jonas Jenwald
d7fd8d3883 Remove some outdated CSS rules related to printing
Given that no HTML element has used the `loadingBox`-id for many years, we obviously don't need to try and hide a non-existent element during printing.
Furthermore, we also shouldn't need to change the `overflow`-value for the `viewerContainer`-element during printing. Originally, many years ago now, we printed "directly" using the viewer and then this apparently made sense.
2022-04-16 16:03:17 +02:00
Jonas Jenwald
7023bac8d3 Move the PDFBug-related CSS from viewer.css and into its own file
Given that none of these CSS rules are used at all, unless debugging is enabled, it seems completely unnecessary to load them *unconditionally* for all users.[1]

Note that if *both* the `textLayer` and `pdfBug` debugging hash-parameters are specified simultaneously, we'll now load the `PDFBug`-file *twice* (since the code is simpler that way). However, given first of all that none of this is enabled by default and secondly that using those parameters together isn't helpful[2], potentially loading that file twice is hopefully not an issue.

For the `gulp mozcentral` target, the size of the *built* `viewer.css` file is reduced `> 3%` with this patch.

---
[1] For the Firefox built-in PDF Viewer, in order to even be able to access the `PDFBug` functionality, you need to first of all set `pdfjs.pdfBugEnabled = true` manually in `about:config`. Secondly, you then also need to append the `pdfBug=...` hash-parameter to the URL when *initially* loading the document.

[2] Note how the `textLayer`-settings are already, since essentially forever, overriding the highlighting-features of the "FontInspector"-tab.
2022-04-16 14:16:39 +02:00
Tim van der Meij
b73a6cc213
Merge pull request #14785 from Snuffleupagus/core-js-structuredClone-transfers
Update `core-js` to allow removing a `structuredClone` work-around
2022-04-16 12:36:44 +02:00
calixteman
681a9b8927
Merge pull request #14784 from calixteman/intersect
Improve performance of shared/utils.js::intersect (bug 1135277)
2022-04-15 22:38:19 +02:00
Calixte Denizet
7501fe6f30 Improve performance of shared/utils.js::intersect
- avoid to call normalizeRect which clones the rectangles: it's useless
  and time consuming;
- in profiling the pdf in bug 1135277, the time spent in intersect drops
  from ~1s to ~30ms.
2022-04-15 22:24:26 +02:00
Jonas Jenwald
b996e107c3 Update core-js to allow removing a structuredClone work-around
Because of a bug in previous `core-js` versions, which caused an Error to be thrown if its `structuredClone` polyfill was called with an *explicit* `null`/`undefined` transfer-parameter, the `LoopbackPort`-class contained a work-around.
In the latest `core-js` version this has been fixed, and we can thus simplify our code ever so slightly; please see https://github.com/zloirock/core-js/releases/tag/v3.22.0
2022-04-15 22:12:02 +02:00
Jonas Jenwald
fffce7910e
Merge pull request #14722 from Rob--W/scripting-manager-mousedown-grab-to-pan-conflict
PDFScriptingManager: Bind mousedown listener with capture=true
2022-04-15 11:59:18 +02:00
Tim van der Meij
3f5c31e203
Merge pull request #14780 from Snuffleupagus/rm-CSS-viewport-scale-factor
Replace the `--viewport-scale-factor` CSS variable
2022-04-14 21:12:29 +02:00
Tim van der Meij
c4a9fd635e
Merge pull request #14773 from Snuffleupagus/rm-dropdownToolbarButton-styling
Remove some `dropdownToolbarButton`-related CSS rules
2022-04-14 21:02:57 +02:00
Tim van der Meij
5ca26bcc05
Merge pull request #14772 from Snuffleupagus/rm-unneeded-CSS
Remove/simplify some CSS rules
2022-04-14 20:57:04 +02:00
Tim van der Meij
e9aedf2d91
Merge pull request #14771 from Snuffleupagus/dialog-backdrop-rm-user-select
Simplify the `dialog::backdrop` CSS rules (PR 14710 follow-up)
2022-04-14 20:54:22 +02:00
Tim van der Meij
97377085c1
Merge pull request #14770 from Snuffleupagus/sidebarContainer-transitionend
Always remove the `sidebarMoving` CSS class when the sidebar is closed
2022-04-14 20:47:49 +02:00
Tim van der Meij
c4336808fe
Merge pull request #14769 from Snuffleupagus/cleanup-media-840px
Remove unnecessary `@media` CSS rules (PR 8993 follow-up)
2022-04-14 20:41:59 +02:00
Jonas Jenwald
e67cd7fae0 Replace the --viewport-scale-factor CSS variable
This CSS variable is only used together with the `annotationCanvasMap`-functionality in the canvas-code, however its value can be *trivially* computed by using the older `--zoom-factor` CSS variable together with the `PixelsPerInch`-structure.
Rather than having *two different* CSS variables that are this closely linked, it seems better to simplify things by using just one CSS variable instead.
2022-04-14 12:43:57 +02:00
Jonas Jenwald
11b30c974e Remove some dropdownToolbarButton-related CSS rules
According to the CSS, there should be a visible "divider" after the "Page Width" zoom-option. However, this is being ignored in both Mozilla Firefox[1] and Google Chrome hence the rule is effectively useless now.
Furthermore, the "custom" zoom-option is already being `hidden` using the attribute (in the HTML code) and there should thus be no reason to duplicate this in the CSS as well.

---
[1] Support for *detailed* styling of `<select>`-elements was removed as part of the E10s project.
2022-04-12 16:05:23 +02:00
Jonas Jenwald
3752b8975b Reduce (some) duplication in the CSS rules for the sidebarViews
With just a couple of exceptions, for the `thumbnailView`, all of the sidebarViews share the same basic styling which thus allows for some simplification.
2022-04-12 13:51:50 +02:00
Jonas Jenwald
f788035a58 Remove unnecessary min-width CSS rules
- For the findbar/secondaryToolbar case, the `min-width` rule doesn't really make sense since it's way too small to be useful. Furthermore, the findbar is already specifying its own `min-width` and the secondaryToolbar will (thanks to its buttons) receive a correct/useful width.

 - The pageNumber-input already has an *explicit* `width` set, hence setting the `min-width` rule as well is completely unnecessary.

 - The treeItem-links are supposed to *compute* their `min-width`, and the static value was only added as a fallback for older browsers without `calc()` support.
2022-04-12 13:51:45 +02:00
Jonas Jenwald
93c5c6e5e9 Use background-color rather than background in a few CSS rules
In a couple of spots, mostly related to the debugging tools, we're unnecessarily using a somewhat "complex" `background`-format only to specify a solid color. This can be simplified by using `background-color` instead, and the patch also removes a `color`-rule that's being ignored anyway.
2022-04-12 12:41:34 +02:00
Jonas Jenwald
3aed103ce8 Simplify the dialog::backdrop CSS rules (PR 14710 follow-up)
After the changes in https://bugzilla.mozilla.org/show_bug.cgi?id=1761839, we no longer need this CSS work-around to prevent the entire `<dialog>` contents from becoming selected when the backdrop is clicked.
2022-04-12 12:41:29 +02:00
Jonas Jenwald
0fbe5832ab Always remove the sidebarMoving CSS class when the sidebar is closed
When the viewer becomes narrow enough that the sidebar is overlaying the document, which means that the `viewerContainer` is not moving when opening/closing the sidebar, we're currently not removing the `sidebarMoving` CSS class as intended.
While this doesn't cause any *visible* issues, it's nonetheless wrong and should be fixed.
2022-04-11 19:46:10 +02:00
Jonas Jenwald
0a83538e64 Remove unnecessary @media CSS rules (PR 8993 follow-up)
With the changes in PR 8993, a number of the `@media`-related CSS rules became unnecessary. However, it appears that some of these rule were *accidentally* left behind despite being unused now.
Note that previously, when opening the sidebar shifted the position of the main toolbar, we had to take both the sidebar opened *and* closed cases into account in these `@media` rules.
2022-04-11 10:08:48 +02:00
Tim van der Meij
143ba30bef
Merge pull request #14767 from Snuffleupagus/fileInput-refactor
[GENERIC viewer] Re-factor the `fileInput` initialization
2022-04-10 15:07:08 +02:00
Tim van der Meij
8f26e70cf1
Merge pull request #14765 from Snuffleupagus/requestFullscreen-Promise
Simplify handling of `requestFullscreen` errors in `PDFPresentationMode`
2022-04-10 15:01:08 +02:00
Tim van der Meij
cdb3481d6c
Merge pull request #14764 from apeltop/correct-typos
Correct typos
2022-04-10 14:55:08 +02:00
Jonas Jenwald
07ac5c337f [GENERIC viewer] Remove some, now unnecessary, checks used with fileInput
According to the MDN compatibility data, see below, all of these features have been supported for years and years in all browsers. Looking closely at the data, the most likely reason for adding these checks in the first place was for IE 9 compatibility (since we originally "supported" that browser).

 - https://developer.mozilla.org/en-US/docs/Web/API/File#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/FileReader#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/FileList#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/API/Blob#browser_compatibility
2022-04-10 12:50:35 +02:00
calixteman
2c135b02e0
Merge pull request #14766 from calixteman/mask2
Improve performance of applyMaskImageData
2022-04-09 22:48:28 +02:00
Calixte Denizet
687c9a8710 Improve performance of applyMaskImageData
- write some uint32 instead of uint8 to avoid the check before clamping;
- unroll the loop to write data in the buffer
- but keep a loop for the last element of a line: it likely doesn't hurt
  that much since it's executed only for one time for each line;
- I tested on a macbook with an Apple chip, and on Firefox nightly the new
  code is almost 3.5x faster than before (~1.8x with Chrome).
2022-04-09 22:19:02 +02:00
Jonas Jenwald
5390d2b377 [GENERIC viewer] Re-factor the fileInput initialization
*This is yet another installment in a never-ending series of patches that attempt to simplify and improve old code.*

The `fileInput`-element is used to support the "Open file"-button in the `GENERIC` viewer, however this is very old code.
Rather than creating the element dynamically in JavaScript, we can simply define it conditionally in the HTML code thanks to the pre-processor. Furthermore, the `fileInput`-element currently has a number of unnecessary CSS rules, since the element is *purposely* never made visibly.

Note that with these changes, the `fileInput`-element will now *always* have `display: none;` set. This shouldn't matter, since we can still trigger the `click`-event of the element just fine (via JavaScript) and this patch has been successfully tested in both Mozilla Firefox and Google Chrome.
2022-04-09 21:21:18 +02:00
calixteman
08e1abe68e
Merge pull request #14754 from calixteman/smask
Improve performance with image masks (bug 857031)
2022-04-09 20:04:51 +02:00
Calixte Denizet
040fcae5ab Improve performance with image masks (bug 857031)
- it aims to partially fix performance issue reported: https://bugzilla.mozilla.org/show_bug.cgi?id=857031;
- the idea is too avoid to use byte arrays but use ImageBitmap which are a way faster to draw:
  * an ImageBitmap is Transferable which means that it can be built in the worker instead of in the main thread:
    - this is achieved in using an OffscreenCanvas when it's available, there is a bug to enable them
      for pdf.js: https://bugzilla.mozilla.org/show_bug.cgi?id=1763330;
    - or in using createImageBitmap: in Firefox a task is sent to the main thread to build the bitmap so
      it's slightly slower than using an OffscreenCanvas.
  * it's transfered from the worker to the main thread by "reference";
  * the byte buffers used to create the image data have a very short lifetime and ergo the memory used is globally
    less than before.
- Use the localImageCache for the mask;
- Fix the pdf issue4436r.pdf: it was expected to have a binary stream for the image;
- Move the singlePixel trick from operator_list to image: this way we can use this trick even if it isn't in a set
  as defined in operator_list.
2022-04-09 18:26:26 +02:00
Jonas Jenwald
bde6d9ffba Re-factor how PDFPresentationMode, internally, tracks the current PresentationModeState
With the changes in the previous patch, we can simplify the state-tracking by using the `PresentationModeState`-values directly in the `PDFPresentationMode` class.
2022-04-09 12:20:11 +02:00
Jonas Jenwald
8d61b7c088 Simplify handling of requestFullscreen errors in PDFPresentationMode
Since quite some time the `Element.requestFullscreen()` method has been returning a Promise, see https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#return_value
Hence we can utilize that to detect failures to enter fullscreen-mode, and remove our old `setTimeout`-based hacks that were used for this purpose.

According to the MDN compatibility data, see https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#browser_compatibility, all browsers that we support have implemented this functionality. (Note that after PR 14606, we no longer support PresentationMode in Safari.)
2022-04-09 12:12:50 +02:00
apeltop
a97dd26389 Correct typos 2022-04-09 09:43:18 +09:00
Tim van der Meij
2b673a6941
Merge pull request #14750 from Snuffleupagus/rm-_getCurrentVisiblePage
Remove the `BaseViewer._getCurrentVisiblePage` helper method
2022-04-08 20:05:51 +02:00
Tim van der Meij
106b69a101
Merge pull request #14751 from Snuffleupagus/isLittleEndian-isEvalSupported
Re-factor the `isLittleEndian`/`isEvalSupported` caching
2022-04-08 20:02:23 +02:00
Jonas Jenwald
497c0610cd
Merge pull request #14761 from Snuffleupagus/viewer-more-optional-chaining
Use a bit more optional chaining in the viewer
2022-04-07 16:44:08 +02:00
Jonas Jenwald
bb25b6dec5 Use a bit more optional chaining in the viewer 2022-04-07 16:20:41 +02:00
Jonas Jenwald
a919959d83 Slightly simplify the Catalog._readMarkInfo method
We don't need to first check if the Dictionary contains the key, since trying to get a non-existent key simply returns `undefined` and we're already ensuring that the value is a boolean.
Furthermore, we shouldn't need to worry about the `Object.prototype` containing enumerable properties since the checks (in `src/core/worker.js`) done for `Array.prototype` *indirectly* also cover `Object`s. (Keep in mind that an `Array` is just a special kind of `Object` in JavaScript.)
2022-04-05 16:37:51 +02:00
Jonas Jenwald
1dc4713a0b Re-factor the isLittleEndian/isEvalSupported caching
This functionality is very old, hence we should be able to improve the caching a little bit with modern JavaScript features.
2022-04-05 16:01:01 +02:00
Jonas Jenwald
55838303c7 Tweak the pdfOpenParams parameter, in the "updateviewarea" event, in PresentationMode
The `pdfOpenParams` parameter has never really made sense in PresentationMode, since e.g. the zoom-value doesn't (generally) agree with the value chosen by the user prior to entering PresentationMode.
This has never mattered all that much, since the `viewBookmark`-button isn't visible in PresentationMode (nor is any other toolbar button for that matter). However, in the `PDFHistory`-implementation we're currently forced to handle this case specifically since we don't want to populate the browser history with nonsensical state.
Hence it makes overall sense, as far as I'm concerned, to tweak the "updateviewarea" event to include a *simplified* `pdfOpenParams` parameter when PresentationMode is active. Given that the `viewer components` don't include PresentationMode functionality, this change thus shouldn't matter for third-party users.
2022-04-05 14:13:20 +02:00
Jonas Jenwald
5ef294b3a7 Remove the BaseViewer._getCurrentVisiblePage helper method
This method was originally added specifically to work-around bugs/issues related to PresentationMode in Google Chrome. Note that prior to PR 14112 we were using some CSS hacks to only show the current page in PresentationMode, and that could lead to the `getVisibleElements` function not always finding the correct elements.
However, after the changes in PR 14112 we're now using the Page-scrolling mode in PresentationMode and consequently there'll only be *a single* page visible at a time. Hence then `BaseViewer._getCurrentVisiblePage` helper method should no longer be needed, and when testing (locally) in Google Chrome everything seems to work correctly now.
2022-04-05 13:32:09 +02:00
Jonas Jenwald
27e738dff9
Merge pull request #14663 from Snuffleupagus/issue-14525
[GENERIC viewer] Try to improve a11y, for search results, in the findbar (issue 14525)
2022-04-04 19:10:55 +02:00
calixteman
45553d60f8
Merge pull request #14739 from calixteman/14685_fw
Refactor some xfa*** getters in document.js
2022-04-03 21:14:17 +02:00
Calixte Denizet
f4fcb59a5e Refactor some xfa*** getters in document.js
- it's a follow-up of PR #14735.
2022-04-03 20:38:12 +02:00
Tim van der Meij
3e50e578c2
Merge pull request #14745 from Snuffleupagus/debugger-module
Convert `web/debugger.js` to a *basic* module
2022-04-03 14:51:51 +02:00
Tim van der Meij
94e51f9883
Merge pull request #14744 from timvandermeij/updates
Update GitHub Actions workflow steps/dependencies/translations to the most recent versions
2022-04-03 14:44:36 +02:00
Jonas Jenwald
8fa73dbfab Convert web/debugger.js to a *basic* module
The various functionality in `web/debugger.js` is currently *indirectly* added to the global scope, since that's how `var` works when it's used outside of any functions/closures.
Given how this functionality is being accessed/used, not just in the viewer but also in the API and textLayer, simply converting the entire file to a module isn't trivial[1]. However, we can at least export the `PDFBug`-part properly and then `import` that dynamically in the viewer.
Also, to improve the code a little bit, we're now *explicitly* exporting the necessary functionality globally.

According to MDN, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility, all the browsers that we now support have dynamic `imports` implementations.

---
[1] We could probably pass around references to the necessary functionality, but given how this is being used I'm just not sure it's worth the effort. Also, adding *official* support for these viewer-specific debugging tools in the API feels both unnecessary and unfortunate.
2022-04-03 14:30:26 +02:00
Tim van der Meij
312595eb47
Update translations to the most recent versions 2022-04-02 19:43:34 +02:00
Tim van der Meij
c04373dda2
Update dependencies to the most recent versions 2022-04-02 19:43:34 +02:00
Tim van der Meij
349fc51f2c
Update GitHub Actions workflow steps to the most recent versions 2022-04-02 16:21:43 +02:00
Tim van der Meij
7c8a92da77
Merge pull request #14742 from Snuffleupagus/debugger-loops
Replace most loops in `web/debugger.js` with `for...of` loops
2022-04-02 13:52:04 +02:00
Jonas Jenwald
bc1cde238d Replace most loops in web/debugger.js with for...of loops
This leads to *slightly* more compact code overall. Also, uses object shorthand notation to remove some now unnecessary `function`-strings.
2022-04-02 11:58:10 +02:00
Jonas Jenwald
38e9a46a85
Merge pull request #14738 from Snuffleupagus/xfa-datasets-decode
Decode non-ASCII values found in the xfa:datasets (PR 14735 follow-up)
2022-04-01 12:36:57 +02:00
Jonas Jenwald
f33ce5fc2d Decode non-ASCII values found in the xfa:datasets (PR 14735 follow-up)
*Please note:* This is possibly bad/wrong in general, but I figured that submitting it for review wouldn't hurt.

It seems that even Adobe Reader doesn't handle the non-ASCII characters that appear in some of the fields correctly, however it should be pretty easy to improve things on the PDF.js side.
2022-04-01 11:54:34 +02:00
Jonas Jenwald
b0ec83262b
Merge pull request #14734 from Snuffleupagus/setAttribute-string-conversion
Don't manually convert `setAttribute` values to strings (PR 14554 follow-up)
2022-04-01 11:38:02 +02:00
Jonas Jenwald
36a289d747
Merge pull request #14735 from calixteman/14685
[Annotations] Some annotations can have their values stored in the xfa:datasets
2022-04-01 11:30:16 +02:00
Calixte Denizet
0b597304c1 [Annotations] Some annotations can have their values stored in the xfa:datasets
- it aims to fix #14685;
- add a basic object to get values from the parsed datasets;
- these annotations don't have an appearance so we must create one when printing or saving.
2022-04-01 10:28:04 +02:00
Jonas Jenwald
966da4babe [GENERIC viewer] Try to improve a11y, for search results, in the findbar (issue 14525)
Note that it seemed necessary to re-factor the `findResultsCount` and `findMsg` element grouping, in the HTML/CSS code, in order those elements to be correctly announced by a11y software in Firefox.

The following MDN articles may be helpful here:
 - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid
 - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live
2022-03-31 23:12:56 +02:00
Jonas Jenwald
f1b17773c0 Don't manually convert setAttribute values to strings (PR 14554 follow-up)
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute#parameters, non-string values will be automatically converted into strings. I should probably have read that article more carefully, to avoid unnecessary churn in the code; sorry about that!
2022-03-31 17:26:28 +02:00
Jonas Jenwald
54d4d345d3
Merge pull request #14733 from Snuffleupagus/String-repeat
Use `String.prototype.repeat()` in a couple of spots
2022-03-30 16:34:10 +02:00
Jonas Jenwald
addb4cb12b Use String.prototype.repeat() in a couple of spots
Rather than using a temporary Array to manually create repeated strings, we can use `String.prototype.repeat()` instead.
The reason that we didn't use this from the start is most likely because some browsers, notably IE, didn't support this; note https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat#browser_compatibility
2022-03-30 15:42:40 +02:00
Jonas Jenwald
d6592b5e37
Merge pull request #14710 from Snuffleupagus/overlays-dialog
Convert the existing overlays to use `<dialog>` elements (issue 14698)
2022-03-30 11:47:36 +02:00
calixteman
4d4c67dd6e
Merge pull request #14720 from calixteman/12189
[Annotations] Add support for printing/saving choice list with multiple selections
2022-03-30 11:12:21 +02:00
Calixte Denizet
ad3fb71a02 [Annotations] Add support for printing/saving choice list with multiple selections
- it aims to fix issue #12189.
2022-03-29 18:59:44 +02:00
Jonas Jenwald
c9f262c480 Add a <dialog> polyfill for the generic-legacy build
Please note that this patch is purposely quite basic, e.g. it doesn't add the polyfill-CSS in order to simplify the build process, and things such as `::backdrop` thus isn't working.
However, this patch does ensure that older browsers can at least still *access* all of the previous overlays and that things like e.g. opening of password-protected documents respectively printing still works.
2022-03-28 11:36:31 +02:00
Jonas Jenwald
b3d58e1000 Try to improve a11y for the PasswordPrompt and PDFDocumentProperties dialogs
This will hopefully improve the a11y a little bit in these dialogs, however there's most definately more things that can be done here (by someone more knowledgeable about a11y).
2022-03-28 11:36:31 +02:00
Jonas Jenwald
923bd52cdb Re-factor the OverlayManager class to use a WeakMap internally
This way we're able to store the `<dialog>` elements directly, which removes the need to use manually specified name-strings thus simplifying both the `OverlayManager` itself and its calling code.
2022-03-28 11:36:31 +02:00
Jonas Jenwald
f0aa08b464 Convert the existing overlays to use <dialog> elements (issue 14698)
This replaces our *custom* overlays with standard `<dialog>` DOM elements, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog, thus simplifying the related CSS, HTML, and JavaScript code.

With these changes, some of the functionality of the `OverlayManager` class is now handled natively (e.g. `Esc` to close the dialog). However, since we still need to be able to prevent dialogs from overlaying one another, it still makes sense to keep this functionality (as far as I'm concerned).
2022-03-28 11:36:29 +02:00
Rob Wu
dc6e2ed6f8 PDFScriptingManager: Bind mousedown listener with capture=true
PDFScriptingManager uses the `mousedown` and `mouseup` listeners to keep
track of whether the mouse pointer is pressed in the `isDown` flag.
These listeners were registered to run during the bubbling phase of the
event dispatch, which can be interrupted if any of the previous event
listeners stopped the event propagation. An example of that is by
`GrabToPan` in web/grab_to_pan.js.

Since the mousedown (and mouseup) listeners of PDFScriptingManager are
free of side effects, and the intention is to always run them, it makes
most sense to register them with the capture flag.
2022-03-28 02:34:00 +02:00
Jonas Jenwald
0dd6bc9a85
Merge pull request #14703 from calixteman/14627
[text selection] Add the whitespaces present in the pdf in the text chunk
2022-03-27 15:20:19 +02:00
Calixte Denizet
18e79e3c0b [text selection] Add the whitespaces present in the pdf in the text chunk
- it aims to fix issue #14627;
- the basic idea of the recent text refactoring was to only consider the rendered visible whitespaces.
  But sometimes, the heuristics aren't correct and although some whitespaces are in the text stream
  they weren't in the text chunks because they were too small. Hence we added some exceptions, for example,
  we always add a whitespace when it is between two non-whitespace chars but only when in the same Tj.
  So basically, this patch removes the constraint to have the chars in the same Tj
  (in using a circular buffer to save the two last chars) but don't add a space when the visible space is really
  too small (hence `NOT_A_SPACE_FACTOR`).
2022-03-27 14:34:56 +02:00
Tim van der Meij
20d60d92ba
Merge pull request #14715 from Snuffleupagus/issue-13230
Avoid the `textLayer` becoming visible in high contrast mode (issue 13230)
2022-03-27 14:22:35 +02:00
Tim van der Meij
973b92060c
Merge pull request #14717 from Snuffleupagus/issue-14716
Change the type of the `container` property, in the `TextLayerRenderParameters` typedef (issue 14716)
2022-03-27 14:09:36 +02:00
Tim van der Meij
d4714b3043
Merge pull request #14693 from Snuffleupagus/CSS-dir-factor
Remove the remaining `dir`-dependent CSS rules
2022-03-27 14:07:24 +02:00
Jonas Jenwald
7f0589c74a Change the type of the container property, in the TextLayerRenderParameters typedef (issue 14716)
Given that the textLayer-code has been using a `DocumentFragment` ever since PR 3356 (back in 2013), simply updating the type of the `container` property should be fine.
This patch also tries to, ever so slightly, improve the grammar of a couple of other properties in the typedef.
2022-03-24 22:42:37 +01:00
Jonas Jenwald
fd6e2e2ab3 Avoid the textLayer becoming visible in high contrast mode (issue 13230)
Unfortunately this CSS property is not yet available in Firefox, see https://developer.mozilla.org/en-US/docs/Web/CSS/forced-color-adjust#browser_compatibility which is tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1591210, however this patch seems to work when testing in Google Chrome.

Given that we really cannot do any more on the PDF.js-side of things, until this CSS feature is actually implemented in Firefox, I figured that submitting this patch cannot hurt in order to get rid of an open issue.
2022-03-24 14:20:27 +01:00
Jonas Jenwald
f8d60da94e Remove the remaining dir-dependent CSS rules
After the recent round of patches, I figured that we'd gone as far as possible in replacing `dir`-dependent CSS rules for the viewer.
However, it occurred that me that we could actually use a bit of CSS-trickery to get rid of the remaining ones. More specifically, this was done by defining a CSS variable whose value depends on the document direction and then using that variable together with `calc()` in the affected rules.

*Please note:* I suppose that this could perhaps be seen as a bit too "magical", hence I understand if this patch is ultimately rejected, however this is probably the only simple way to get rid of the remaining `dir`-dependent CSS rules.
2022-03-23 22:05:23 +01:00
Tim van der Meij
db4f3adc5e
Merge pull request #14691 from Snuffleupagus/border-inline
Replace `dir`-dependent `border`-rules with logical properties
2022-03-23 20:43:15 +01:00
Tim van der Meij
a3e34002cb
Merge pull request #14699 from Snuffleupagus/getDocument-validation
Slightly improve validation of (some) parameters in `getDocument`
2022-03-23 20:41:05 +01:00
Tim van der Meij
30612d2f4e
Merge pull request #14704 from Snuffleupagus/OverlayManager-private
Convert the `OverlayManager` class to use private fields/methods
2022-03-23 20:38:05 +01:00
Jonas Jenwald
cd133dbcac Change OverlayManager.open to always error if the overlay is already active
The old code would allow an overlay to force close *itself*, before immediately re-opening itself, which actually isn't very helpful in practice since that won't re-run any overlay-specific initialization code.
Given how the overlays are being used this really shouldn't have caused any issues, but it's a bug that we should fix nonetheless.
2022-03-22 09:50:28 +01:00
Jonas Jenwald
bace0623e5 Convert the OverlayManager class to use private fields/methods 2022-03-21 16:01:32 +01:00
Jonas Jenwald
849de5a508 Slightly improve validation of (some) parameters in getDocument
There's a couple of `getDocument` parameters that should be numbers, but which are currently not *fully* validated to prevent issues elsewhere in the code-base.
Also, improves validation of the `ownerDocument` parameter since we currently accept more-or-less anything here.
2022-03-21 13:32:17 +01:00
Jonas Jenwald
477dc08b00 Replace dir-dependent border-rules with logical properties
*Please note:* This is the final step in a series of patches to simplify/modernize the viewer CSS, since the remaining `html[dir="rtl"]`-cases cannot be converted.

Rather than having to manually specify ltr/rtl-specific border-values in the CSS, we can use logical `border-inline-end`/`border-start-end-radius`/`border-end-end-radius` instead.
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we rely on the previously added PostCSS plugins in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/border-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/border-start-end-radius#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/border-end-end-radius#browser_compatibility
2022-03-20 12:45:37 +01:00
Tim van der Meij
feea2b78fa
Merge pull request #14690 from Snuffleupagus/inset-inline
Replace `dir`-dependent `left`/`right` with logical properties
2022-03-20 12:27:02 +01:00
Tim van der Meij
bb6505ee69
Merge pull request #14695 from Snuffleupagus/update-packages
Update packages and translations
2022-03-20 12:23:22 +01:00
Jonas Jenwald
579ff9459e Update l10n files 2022-03-20 10:59:15 +01:00
Jonas Jenwald
73d2ddac0d Update npm packages
Note that the Prettier update made it possible to move a couple of comments after `default:`-cases back to their original/intended positions, please see https://prettier.io/blog/2022/03/16/2.6.0.html
2022-03-20 10:59:13 +01:00
calixteman
f017f295ec
Merge pull request #14692 from calixteman/14672
[JS] - Parse a date in using the given format first and then try the default date parser
2022-03-19 17:37:10 +01:00
Calixte Denizet
f0b549c2a2 [JS] - Parse a date in using the given format first and then try the default date parser
- it aims to fix #14672.
2022-03-19 16:07:43 +01:00
Jonas Jenwald
9eed8c3576 Replace dir-dependent left/right with logical properties
*Please note:* This is another step in a series of patches to simplify/modernize the viewer CSS.

Rather than having to manually specify ltr/rtl-specific left/right-values in the CSS, we can use logical `inset-inline`/`inset-inline-start`/`inset-inline-end` instead.
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we rely on the previously added PostCSS plugins in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility
2022-03-19 14:44:01 +01:00
Tim van der Meij
6381738a65
Merge pull request #14671 from Snuffleupagus/float-inline
Replace `dir`-dependent `float` with logical properties
2022-03-19 14:12:34 +01:00
Jonas Jenwald
bc6ea6a878 Replace dir-dependent float with logical properties
*Please note:* This is another step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to manually specify ltr/rtl-specific float-values in the CSS, we can use logical `inline-start`/`inline-end` instead (and similar for some related left/right occurrences).
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we rely on PostCSS plugins in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/float#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility
2022-03-19 14:03:20 +01:00
Jonas Jenwald
502fd7c80d Stop polyfilling the CSS calc functionality
At this point in time, all browsers that we support have native support for CSS variables; please see https://developer.mozilla.org/en-US/docs/Web/CSS/calc()#browser_compatibility and https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support

We can also remove the hack introduced back in PR 11567, which was only necessary to work-around an IE 11 specific bug.
2022-03-19 14:03:19 +01:00
Tim van der Meij
079dea2274
Merge pull request #14670 from Snuffleupagus/postcss-logical
Replace `dir`-dependent `margin`/`margin-left`/`margin-right` with logical properties
2022-03-19 13:53:39 +01:00
Tim van der Meij
6f2bae680c
Merge pull request #14689 from Snuffleupagus/PDFFindController-private
Slightly simplify the `PDFFindController._extractText` method, and convert all "private" methods into proper ones
2022-03-19 13:42:13 +01:00
Tim van der Meij
5de6af4e64
Merge pull request #14683 from Snuffleupagus/sendTest-cleanup
[src/display/api.js] Simplify the `sendTest` function, used with Worker initialization (PR 14291 follow-up)
2022-03-19 13:38:05 +01:00
Jonas Jenwald
c99d558646 Replace dir-dependent margin/margin-left/margin-right with logical properties
*Please note:* This is another step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to manually specify ltr/rtl-specific margin-values in the CSS, we can use logical margin instead (and similar for some related left/right occurrences).
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we need to use a couple of PostCSS plugins (see below) in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility

---

 - https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-logical
 - https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class
2022-03-19 13:35:24 +01:00
Tim van der Meij
9b9ce07aa6
Merge pull request #14688 from Snuffleupagus/RefSet-RefSetCache-iterator
Add general iteration support in the `RefSet` and `RefSetCache` classes
2022-03-19 13:35:04 +01:00
Tim van der Meij
764ccd9d34
Merge pull request #14682 from Snuffleupagus/preprocessCSS-defines
[gulpfile.js] Use the regular `defines` in the `preprocessCSS` function
2022-03-19 13:29:49 +01:00
Jonas Jenwald
61a52e8043 Convert all "private" methods in PDFFindController into proper ones
Given that none of these methods are/were ever intended to be called manually, we can now enforce this with modern class-features.
2022-03-19 12:26:03 +01:00
Jonas Jenwald
cc1bca6268 Slightly simplify the PDFFindController._extractText method
Currently we're resolving the Promises in the `_extractTextPromises` Array with the page-index, despite that not really being necessary since the Promises in the Array are explicitly inserted in the correct order.
Furthermore, we can replace the standard `for`-loop with a `for...of`-loop which results in ever so slightly more compact code.
2022-03-19 12:13:29 +01:00
Jonas Jenwald
c0736647f9 Add general iteration support in the RefSet and RefSetCache classes
This patch removes the existing `forEach` methods, in favor of making the classes properly iterable instead. Given that the classes are using a `Set` respectively a `Map` internally, implementing this is very easy/efficient and allows us to simplify some existing code.
2022-03-18 14:27:34 +01:00
Jonas Jenwald
5180bafb8f [gulpfile.js] Use the regular defines in the preprocessCSS function
Rather than *manually* specifying a "mode", we can simply use the regular `defines` directly instead. To improve consistency, in the `external/builder/builder.js` file, a couple of parameters are also re-named.
2022-03-16 22:39:48 +01:00
Tim van der Meij
489e9ff7d3
Merge pull request #14675 from Snuffleupagus/build-dev-CSS
Build the `web/viewer.css` file used in the development viewer (i.e. `gulp server`)
2022-03-16 20:14:02 +01:00
Tim van der Meij
00eb942c93
Merge pull request #14678 from Snuffleupagus/PDFDocumentProperties-private
Convert the `PDFDocumentProperties` class to use private methods
2022-03-16 20:10:45 +01:00
Tim van der Meij
82770e0655
Merge pull request #14676 from Snuffleupagus/preprocessCSS-cleanup
Remove the custom `grab`/`grabbing` cursor image files
2022-03-16 20:06:55 +01:00
Jonas Jenwald
be2b1d5d2a [src/display/api.js] Simplify the sendTest function, used with Worker initialization (PR 14291 follow-up)
Given that we now only use Workers when `postMessage` transfers are supported, there's really no point in trying to send a "test" message *without* transfers present.
Hence, if `postMessage` transfers are not supported by the browser, we'll now fallback to "fake" Workers immediately instead. The comment about Opera is also removed, since it was originally added back in PR 983 and mentions Opera `11.60` [which was released in 2011](https://en.wikipedia.org/wiki/History_of_the_Opera_web_browser#Version_11).
2022-03-16 13:25:41 +01:00
Jonas Jenwald
d5c9be341d [src/display/api.js] Use private static class fields, rather than shadowed getter work-arounds (PR 13813, 13882 follow-up)
At the time private static class fields were to new, however that's no longer an issue and we can thus (ever so slightly) simplify the code.
2022-03-16 13:02:34 +01:00
Jonas Jenwald
ba8dae696a Convert the PDFDocumentProperties class to use private methods
Given that none of these methods were ever intended to be accessed directly from the outside, we can use modern ECMAScript features to ensure that they are indeed private.

This patch also makes `fieldData` private, to remove the old hack used to prevent it from being modified from the outside.
2022-03-15 18:17:06 +01:00
Jonas Jenwald
c5574864e1 Remove the -webkit-mask-image/-webkit-mask-image CSS rules
Given that we're now *building* the `web/viewer.css` file used in the development viewer, i.e. with `gulp server`, we no longer need to hard-code these `-webkit`-prefixed rules and can instead let Autoprefixer handle that for us.
2022-03-15 13:37:46 +01:00
Jonas Jenwald
e59c2dc308 Build the web/viewer.css file used in the development viewer (i.e. gulp server)
To allow using modern CSS features that currently only Mozilla Firefox supports[1], while still enabling development/testing in recent Google Chrome versions, we'll have to start building the `web/viewer.css` file with `gulp server` as well.

In my testing, building the development CSS (and copying the images) takes *less than* `200 ms` on average which is hopefully an acceptable overhead for this sort of feature.

---
[1] In particular `float`, with `inline-start`/`inline-end` values.
2022-03-15 13:37:44 +01:00
Jonas Jenwald
ee2896dd1e Remove the custom grab/grabbing cursor image files
According to the MDN compatibility data, see https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#browser_compatibility, all browsers that we now support should have these cursors available natively.
2022-03-14 14:36:38 +01:00
Jonas Jenwald
6776efe491 [gulpfile.js] Remove the cleanup parameter in preprocessCSS helper function
Every single call-site has always passed in `true` for this parameter, ever since the function was first added back in PR 8023. Hence the parameter appears to be completely unnecessary, which is why it's removed and the function is updated to *unconditionally* strip out any license headers (in the middle of the file).
2022-03-14 13:55:05 +01:00
Tim van der Meij
90c5e9882b
Merge pull request #14669 from Snuffleupagus/padding-inline
Replace `dir`-dependent `padding-left`/`padding-right`/`text-align` with logical properties
2022-03-13 20:51:07 +01:00
Tim van der Meij
dd4af1c60d
Merge pull request #14665 from Snuffleupagus/Preferences-private
Convert the `BasePreferences` class to use private fields
2022-03-13 20:45:29 +01:00
Tim van der Meij
48f49ff9f4
Merge pull request #14668 from Snuffleupagus/rm-addLinkAttributes-warn
Remove the `addLinkAttributes` warnings in the Annotation/XFA-layers (PR 14092 follow-up)
2022-03-13 20:40:22 +01:00
Tim van der Meij
f410403c4b
Merge pull request #14667 from Snuffleupagus/fieldObjects-test-Node
Enable the "gets fieldObjects" unit-test in Node.js (PR 14409 follow-up)
2022-03-13 20:39:01 +01:00
Jonas Jenwald
331f4e72de Replace dir-dependent padding-left/padding-right/text-align with logical properties
*Please note:* This is small first step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to *manually* specify ltr/rtl-specific padding-values in the CSS, we can use logical padding instead (and similar for text-align).
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Note that a number of logical CSS properties are new enough that we'll need to use PostCSS plugins, however the ones in this patch are natively supported in all browsers that we currently support:
 - https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/text-align#browser_compatibility
2022-03-13 14:36:11 +01:00
Jonas Jenwald
0c349c701f Remove the addLinkAttributes warnings in the Annotation/XFA-layers (PR 14092 follow-up)
These warnings have now been present in three releases, see PR 14092, hence it should (hopefully) be fine to remove them now.
2022-03-13 11:38:56 +01:00
Jonas Jenwald
fb345ee184 Enable the "gets fieldObjects" unit-test in Node.js (PR 14409 follow-up)
Apparently this unit-test works in Node.js now, hence it's *possible* that the reason it didn't work previously is that there were bugs in our old `structuredClone` polyfill.
2022-03-13 10:40:57 +01:00
Jonas Jenwald
3274972768 Revert Preferences to their previous values, when writing to storage failed
This patch fixes an old inconsistency, when using `BasePreferences.{reset, set}`, where the internal Preference values would be kept even if writing them to storage failed.
2022-03-12 17:25:45 +01:00
Jonas Jenwald
25d7420035 Convert the BasePreferences class to use private fields
Given that none of these fields were ever intended to be accessed directly from the *outside*, since that will lead to inconsistent/broken state, we can use modern ECMAScript features to ensure that they are indeed private.
2022-03-12 14:34:57 +01:00
Tim van der Meij
9e4aaf18f7
Merge pull request #14661 from tiziodcaio/gh_actions
Update Checkout to version 3
2022-03-11 21:11:18 +01:00
Tim van der Meij
790735eaf1
Merge pull request #14658 from Snuffleupagus/api-validate-cMapUrl-standardFontDataUrl
Validate the `cMapUrl`/`standardFontDataUrl` parameters in `getDocument`
2022-03-11 21:09:58 +01:00
Tim van der Meij
bcf453cf14
Merge pull request #14656 from Snuffleupagus/mv-isSameOrigin
Move the `isSameOrigin` helper function
2022-03-11 21:08:49 +01:00
Tim van der Meij
0d265a30ed
Merge pull request #14654 from Snuffleupagus/TestReporter-send-fetch
Replace XMLHttpRequest usage with the Fetch API in `send` (in `test/unit/testreporter.js`)
2022-03-11 21:05:36 +01:00
Jonas Jenwald
4318bc8f86
Merge pull request #14554 from Snuffleupagus/issue-14526
Try to improve a11y for the "button groups" in the SecondaryToolbar/Sidebar (issue 14526)
2022-03-11 20:46:47 +01:00
tiziodcaio
1a380b5736
Update Checkout to version 3
Uses node 16 as default
2022-03-11 14:35:06 +01:00
Jonas Jenwald
1b6e1eac92
Merge pull request #14620 from Snuffleupagus/Firefox-getStrings
Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer
2022-03-11 11:36:51 +01:00
Jonas Jenwald
a60b98412f Validate the cMapUrl/standardFontDataUrl parameters in getDocument
These changes make sense for two reasons:
 - Given that the parameters are potentially passed to the worker-thread, depending on the `useWorkerFetch` parameter, we need to prevent errors if the user provides values that aren't clonable.
 - By ensuring that the default values are indeed `null`, we'll trigger main-thread fetching (of CMaps and Standard fonts) as intended in the `PartialEvaluator` and thus potentially provide better Error messages.
2022-03-10 16:33:10 +01:00
Jonas Jenwald
537ed37835 Move the isSameOrigin helper function
This function is currently placed in the `src/shared/util.js` file, which means that the code is duplicated in both of the *built* `pdf.js` and `pdf.worker.js` files. Furthermore, it only has a single call-site which is also specific to the `GENERIC`-build of the PDF.js library.

Hence this helper function is instead moved into the `src/display/api.js` file, in such a way that it's conditionally defined but still can be unit-tested.
2022-03-10 13:51:09 +01:00
Jonas Jenwald
e08e3f4d37 Replace XMLHttpRequest usage with the Fetch API in send (in test/unit/testreporter.js)
Besides converting the `send` function to use the Fetch API, this patch also changes the method to return a `Promise` to get rid of the callback function. (Although, currently there's no call-site passing in a callback function.)
2022-03-10 12:55:08 +01:00
Jonas Jenwald
48c64c6c8d Bug 1757527 - Slightly reduce (repeated) message passing overhead when localizing the PDF Viewer 2022-03-10 10:20:34 +01:00
Tim van der Meij
ee39499a5a
Merge pull request #14651 from Snuffleupagus/Driver-inlineImages-fetch
Replace XMLHttpRequest usage with the Fetch API in `inlineImages` (in `test/driver.js`)
2022-03-09 20:47:38 +01:00
Tim van der Meij
fee1bc68e9
Merge pull request #14642 from Snuffleupagus/Driver-send-fetch
Replace XMLHttpRequest usage with the Fetch API in `Driver._send`
2022-03-09 20:43:12 +01:00
Tim van der Meij
e85bb0b599
Merge pull request #14645 from Snuffleupagus/Node-DOMMatrix-polyfill
[api-minor] Remove the, in `legacy` builds, bundled `DOMMatrix` polyfill
2022-03-09 20:38:26 +01:00
Tim van der Meij
55a931e454
Merge pull request #14648 from Snuffleupagus/PDFDocument-stream
Simplify the `PDFDocument` constructor
2022-03-09 20:36:49 +01:00
Tim van der Meij
23d1abee0b
Merge pull request #14640 from Snuffleupagus/update-TypeScript
Update TypeScript to version `4.6.2` and work-around stricter type checks
2022-03-09 20:35:24 +01:00
Jonas Jenwald
b3f4758183 Replace XMLHttpRequest usage with the Fetch API in inlineImages (in test/driver.js)
This is the final part in a series of patches that try to re-implement PR 14287 in smaller steps.

Besides converting `inlineImages` to use the Fetch API, this patch also combines the `inlineImages` and `resolveImages` functions since they are always used together.
2022-03-09 11:32:51 +01:00
Jonas Jenwald
6a78f20b17 Simplify the PDFDocument constructor
Originally the code in the `src/`-folder was shared between the main/worker-threads, and back then it probably made sense that the `PDFDocument` constructor accepted different arguments.
However, for many years we've not been passing anything *except* Streams to `PDFDocument` and we should thus be able to slightly simplify that code. Note that for e.g. unit-tests of this code, using either a `NullStream` or a `StringStream` works just fine.
2022-03-08 17:13:47 +01:00
Jonas Jenwald
157a71d404 [api-minor] Remove the, in legacy builds, bundled DOMMatrix polyfill
According to the MDN compatibility data, see https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix/DOMMatrix#browser_compatibility, all browsers that we support have native `DOMMatrix` implementations (since quite some time too).

Hence Node.js is the only environment that lack `DOMMatrix` support, which probably isn't that surprising given that it's browser functionality.
While the `DOMMatrix` polyfill isn't that large, it nonetheless seems completely unnecessary to bundle it in the `legacy` builds when it's not needed in browsers. However, we can avoid that by simply listing `dommatrix` as a dependency for the `pdfjs-dist` library.
2022-03-08 10:29:11 +01:00
Jonas Jenwald
19c2cc8689 Replace XMLHttpRequest usage with the Fetch API in Driver._send
This is another part in a series of patches that try to re-implement PR 14287 in smaller steps.

Besides converting `Driver._send` to use the Fetch API, this also changes the method to return a `Promise` to get rid of the callback function.
Please note that I *purposely* try to maintain the existing behaviour of re-sending the data on failure/unexpected response, including how/where the old callback function was invoked.
2022-03-07 16:00:52 +01:00
Jonas Jenwald
6f600befdd Update TypeScript to version 4.6.2 and work-around stricter type checks
I'm guessing that we're now running into the class-related improvements mentioned in https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/#target-es2022
To unblock this update, and any future ones, this patch simply tweaks the JSDocs to get `gulp typestest` to run without errors.
2022-03-07 11:55:17 +01:00
Tim van der Meij
3e593cfc1d
Merge pull request #14636 from Snuffleupagus/Driver-quit-fetch
Replace XMLHttpRequest usage with the Fetch API in `Driver._quit`
2022-03-06 18:26:55 +01:00
Jonas Jenwald
d65169d754 Try to improve a11y for the "button groups" in the SecondaryToolbar/Sidebar (issue 14526)
*Please note:* I don't really know anything about a11y, hence it's possible that this patch either doesn't work correctly or at least isn't a complete solution.

In both the SecondaryToolbar and the Sidebar we have "button groups" that functionally acts essentially like radio-buttons. Based on skimming through [this MDN article](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/radio_role) it thus appears that we should tag them as such, using `role="radiogroup"` and `role="radio"`, and then utilize the `aria-checked` attribute to indicate to a11y software which button is currently active.
2022-03-06 16:54:27 +01:00
Jonas Jenwald
c1f73b140f
Merge pull request #14637 from timvandermeij/web-private
Use proper private methods in `web/{pdf_cursor_tools,pdf_find_bar,secondary_toolbar}.js`
2022-03-06 16:47:33 +01:00
Tim van der Meij
a00308d5f3
Merge pull request #14638 from Snuffleupagus/reftest-analyzer-fetch
Replace XMLHttpRequest usage with the Fetch API in the reftest-analyzer
2022-03-06 16:37:31 +01:00
Tim van der Meij
6500aafd00
Use proper private methods in web/secondary_toolbar.js 2022-03-06 16:07:25 +01:00
Tim van der Meij
f33769db2d
Use proper private methods in web/pdf_find_bar.js 2022-03-06 16:07:07 +01:00
Tim van der Meij
a1d106dc5d
Use proper private methods in web/pdf_cursor_tools.js 2022-03-06 16:06:53 +01:00
Jonas Jenwald
90445679e8 Replace XMLHttpRequest usage with the Fetch API in the reftest-analyzer 2022-03-06 16:02:34 +01:00
Jonas Jenwald
65d5974192 Replace XMLHttpRequest usage with the Fetch API in Driver._quit
This is another step in what'll hopefully become a series of patches to implement PR 14287 in smaller steps.
2022-03-06 15:36:48 +01:00
Tim van der Meij
3ac2053d97
Merge pull request #14635 from Snuffleupagus/loadStyles-fetch
Replace XMLHttpRequest usage with the Fetch API in `loadStyles` (in `test/driver.js`)
2022-03-06 15:24:40 +01:00
Jonas Jenwald
62e0939ce2 Replace XMLHttpRequest usage with the Fetch API in loadStyles (in test/driver.js)
This is another small step in what'll hopefully become a series of patches to implement PR 14287 in smaller steps.
2022-03-06 13:57:42 +01:00
Tim van der Meij
f8f0f19642
Merge pull request #14633 from Snuffleupagus/update-packages
Update packages and translations
2022-03-06 13:34:17 +01:00
Tim van der Meij
7d53a40c91
Merge pull request #14634 from Snuffleupagus/Driver-run-fetch
Replace XMLHttpRequest usage with the Fetch API in `Driver.run`
2022-03-06 13:32:17 +01:00
Jonas Jenwald
151b140eac Replace XMLHttpRequest usage with the Fetch API in Driver.run
This is a first step in what'll hopefully become a series of patches to implement PR 14287 in smaller steps.
2022-03-06 12:47:12 +01:00
Jonas Jenwald
114d5e68af Update l10n files 2022-03-06 10:45:24 +01:00
Jonas Jenwald
b875f13b4f Update npm packages 2022-03-06 10:45:23 +01:00
Tim van der Meij
5242c38af5
Merge pull request #14628 from Snuffleupagus/issue-14626
When `stopAtErrors` is set, throw rather than warn when exceeding `maxImageSize` (issue 14626)
2022-03-05 13:09:36 +01:00
Tim van der Meij
5d12ac576b
Merge pull request #14631 from Snuffleupagus/typedef-fixes
Fix a couple of small typos in JSDoc `typedef` comments
2022-03-05 13:06:53 +01:00
Brendan Dahl
3b6d6893d9
Merge pull request #14629 from Snuffleupagus/issue-14618
Compute the loca table `endOffset`, of the "first" glyph, correctly (issue 14618)
2022-03-04 16:43:17 -08:00
Jonas Jenwald
939e6f0c4c Fix a couple of small typos in JSDoc typedef comments
While this doesn't affect the official API documentation, these cases should nonetheless be fixed.
2022-03-04 12:11:52 +01:00
Jonas Jenwald
1a7921dbf0 Compute the loca table endOffset, of the "first" glyph, correctly (issue 14618)
When there are *multiple* empty glyphs at the start of the data, ensure that the "first" glyph gets a correct `endOffset` to avoid skipping it during parsing in the `sanitizeGlyph` function.
2022-03-03 14:22:45 +01:00
Jonas Jenwald
d0d5c596fb When stopAtErrors is set, throw rather than warn when exceeding maxImageSize (issue 14626)
The situation described in issue 14626 seems like a fairly special case, and it thus seem reasonable that we simply follow the same pattern as elsewhere in the `PartialEvaluator` when the `stopAtErrors` API-option is being used.
2022-03-03 13:11:29 +01:00
Tim van der Meij
234aa9a50e
Merge pull request #14624 from Snuffleupagus/viewer-fallback-cleanup
Simplify the `fallback`-logic in the default viewer
2022-03-02 20:54:03 +01:00
Tim van der Meij
038c832719
Merge pull request #14623 from Snuffleupagus/viewer-deprecated-cleanup
Remove some deprecated code from the viewer
2022-03-02 20:46:27 +01:00
Tim van der Meij
636fc05843
Merge pull request #14617 from Snuffleupagus/rm-webkit-outer-spin-button
Remove the `-webkit-outer-spin-button` CSS rule
2022-03-02 20:40:37 +01:00
Tim van der Meij
b18cbaac39
Merge pull request #14615 from Snuffleupagus/rm-webkit-overflow-scrolling
Remove the `-webkit-overflow-scrolling: touch;` CSS rules (PR 4516 follow-up)
2022-03-02 20:39:21 +01:00
Brendan Dahl
85ff7b117e
Merge pull request #14536 from calixteman/thin_line
Fix some issues with lineWidth < 1 after transform (bug 1753075, bug 1743245, bug 1710019)
2022-03-02 09:46:15 -08:00
Jonas Jenwald
6d2863f80a Simplify the fallback-logic in the default viewer
After [bug 1705327](https://bugzilla.mozilla.org/show_bug.cgi?id=1705327) the `ChromeActions.fallback`-method is now just a stub[1], since the fallback bar was removed.
Hence there's no good reason, as far as I can tell, to keep this code in the viewer itself when it's completely unused.

---
[1] See https://searchfox.org/mozilla-central/rev/292d17c13daa61016fd082e2337297091d53a015/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#575-581
2022-03-02 13:30:45 +01:00
Jonas Jenwald
38d30f3be5 Remove the deprecated PDFFindController.executeCommand method
This *partially* reverts commit fa8c0ef6164c7abfd5236e97823102a89517f8a4, since it's now been included in two official releases.
2022-03-02 11:23:14 +01:00
Jonas Jenwald
f2c9a6bc24 Revert "[GENERIC viewer] Add fallback logic for the old PDFPageView.update method signature"
This reverts commit 846620438417c395f14f3cb60a02806c1b3bebc8, since it's now been included in three official releases.
2022-03-02 11:15:18 +01:00
Jonas Jenwald
fdd06fa393 Remove the -webkit-outer-spin-button CSS rule
Unfortunately simply using `appearance: textfield;`, or even `-webkit-appearance: textfield;`, doesn't actually hide the "spinner" in number-input elements in e.g. Google Chrome.
Hence we need to use a work-around with the `-webkit-inner-spin-button` rule, however in our CSS code we also have `-webkit-outer-spin-button` currently. According to both [the MDN compatibility data](https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-outer-spin-button#browser_compatibility) and also manual testing in Google Chrome Beta 99, the `-webkit-outer-spin-button` rule is no longer necessary and we can thus clean-up the CSS a tiny bit.
2022-02-28 12:16:32 +01:00
Jonas Jenwald
047a971093 Remove the -webkit-overflow-scrolling: touch; CSS rules (PR 4516 follow-up)
This was added in PR 4516 specifically for Safari on iOS devices, but according to MDN it should no longer be necessary now; see https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-overflow-scrolling#browser_compatibility

According to the MDN compatibility data, this CSS feature:
 - Was never implemented anywhere *except* for Safari on iOS.
 - Was never standardized and thus never existed in an *unprefixed* version.
 - Has now been removed, starting with Safari version 13.

Given that [the FAQ](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support) already lists Safari as "Mostly" supported, and that the default viewer is written primarily for Mozilla Firefox, it ought to be fine to remove these CSS rules now.
2022-02-27 22:09:19 +01:00
Tim van der Meij
2cc98dcdaa
Merge pull request #14614 from timvandermeij/bump
Bump versions in `pdfjs.config`
2022-02-27 19:29:51 +01:00
Tim van der Meij
dc7368ff5c
Bump versions in pdfjs.config 2022-02-27 19:24:24 +01:00
Calixte Denizet
46369e4aa5 Fix some issues with lineWidth < 1 after transform (bug 1753075, bug 1743245, bug 1710019)
- it aims to fix:
   - https://bugzilla.mozilla.org/show_bug.cgi?id=1753075;
   - https://bugzilla.mozilla.org/show_bug.cgi?id=1743245;
   - https://bugzilla.mozilla.org/show_bug.cgi?id=1710019;
   - issue #13211;
   - issue #14521.
 - previously we were trying to adjust lineWidth to have something correct after the current transform is applied but this approach was not correct because finally the pixel is rescaled with the same factors in both directions.
  And sometimes those factors must be different (see bug 1753075).
 - So the idea of this patch is to apply a scale matrix to the current transform just before setting lineWidth and stroking. This scale matrix is computed in order to ensure that after transform, a pixel will have its two thickness greater than 1.
2022-02-25 18:37:34 +01:00
924 changed files with 119209 additions and 87742 deletions

View File

@ -1,6 +1,6 @@
root = true root = true
[*.{js,jsm,json,html,css,pdf.link}] [*.{js,jsm,mjs,json,html,css,pdf.link}]
charset = utf-8 charset = utf-8
end_of_line = lf end_of_line = lf
indent_size = 2 indent_size = 2

View File

@ -3,12 +3,10 @@ l10n/
docs/ docs/
node_modules/ node_modules/
external/bcmaps/ external/bcmaps/
external/webL10n/
external/builder/fixtures/ external/builder/fixtures/
external/builder/fixtures_esprima/ external/builder/fixtures_esprima/
external/quickjs/ external/quickjs/
src/shared/cffStandardStrings.js
src/shared/fonts_utils.js
test/tmp/ test/tmp/
test/pdfs/ test/pdfs/
web/locale/
*~/ *~/

View File

@ -22,21 +22,27 @@
"browser": true, "browser": true,
"es2022": true, "es2022": true,
"worker": true, "worker": true,
"amd": true,
}, },
"globals": { "globals": {
"PDFJSDev": false, "PDFJSDev": "readonly",
"exports": false, "__non_webpack_import__": "readonly",
"structuredClone": false,
"SystemJS": false,
}, },
"rules": { "rules": {
// Plugins // Plugins
"import/export": "error",
"import/exports-last": "error",
"import/extensions": ["error", "always", { "ignorePackages": true, }], "import/extensions": ["error", "always", { "ignorePackages": true, }],
"import/first": "error",
"import/named": "error",
"import/no-cycle": "error",
"import/no-empty-named-blocks": "error",
"import/no-commonjs": "error",
"import/no-mutable-exports": "error",
"import/no-self-import": "error",
"import/no-unresolved": ["error", { "import/no-unresolved": ["error", {
"ignore": ["pdfjs", "pdfjs-lib", "pdfjs-web"] "ignore": ["display", "pdfjs", "pdfjs-lib", "pdfjs-web", "web", "fluent-bundle", "fluent-dom"],
}], }],
"mozilla/avoid-removeChild": "error", "mozilla/avoid-removeChild": "error",
"mozilla/use-includes-instead-of-indexOf": "error", "mozilla/use-includes-instead-of-indexOf": "error",
@ -47,12 +53,32 @@
}], }],
"unicorn/no-abusive-eslint-disable": "error", "unicorn/no-abusive-eslint-disable": "error",
"unicorn/no-array-push-push": "error", "unicorn/no-array-push-push": "error",
"unicorn/no-new-buffer": "error",
"unicorn/no-instanceof-array": "error", "unicorn/no-instanceof-array": "error",
"unicorn/no-invalid-remove-event-listener": "error",
"unicorn/no-new-buffer": "error",
"unicorn/no-typeof-undefined": ["error", {
"checkGlobalVariables": false,
}],
"unicorn/no-useless-promise-resolve-reject": "error",
"unicorn/no-useless-spread": "error", "unicorn/no-useless-spread": "error",
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-flat": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-array-index-of": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-at": "error",
"unicorn/prefer-date-now": "error", "unicorn/prefer-date-now": "error",
"unicorn/prefer-dom-node-append": "error",
"unicorn/prefer-dom-node-remove": "error", "unicorn/prefer-dom-node-remove": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-modern-dom-apis": "error",
"unicorn/prefer-modern-math-apis": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/prefer-optional-catch-binding": "error",
"unicorn/prefer-regexp-test": "error",
"unicorn/prefer-string-replace-all": "error",
"unicorn/prefer-string-starts-ends-with": "error", "unicorn/prefer-string-starts-ends-with": "error",
"unicorn/prefer-ternary": ["error", "only-single-line"],
// Possible errors // Possible errors
"for-direction": "error", "for-direction": "error",
@ -114,10 +140,12 @@
"no-implied-eval": "error", "no-implied-eval": "error",
"no-iterator": "error", "no-iterator": "error",
"no-lone-blocks": "error", "no-lone-blocks": "error",
"no-lonely-if": "error",
"no-multi-str": "error", "no-multi-str": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-new": "error", "no-new": "error",
"no-new-func": "error",
"no-new-symbol": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error", "no-octal-escape": "error",
"no-octal": "error", "no-octal": "error",
"no-redeclare": "error", "no-redeclare": "error",
@ -133,6 +161,7 @@
"no-useless-escape": "error", "no-useless-escape": "error",
"no-useless-return": "error", "no-useless-return": "error",
"prefer-promise-reject-errors": "error", "prefer-promise-reject-errors": "error",
"prefer-spread": "error",
"wrap-iife": ["error", "any"], "wrap-iife": ["error", "any"],
"yoda": ["error", "never", { "yoda": ["error", "never", {
"exceptRange": true, "exceptRange": true,
@ -149,7 +178,7 @@
"no-undef-init": "error", "no-undef-init": "error",
"no-undef": ["error", { "typeof": true, }], "no-undef": ["error", { "typeof": true, }],
"no-unused-vars": ["error", { "no-unused-vars": ["error", {
"vars": "local", "vars": "all",
"args": "none", "args": "none",
}], }],
"no-use-before-define": ["error", { "no-use-before-define": ["error", {
@ -214,9 +243,9 @@
}], }],
// ECMAScript 6 // ECMAScript 6
"arrow-body-style": ["error", "as-needed"],
"constructor-super": "error", "constructor-super": "error",
"no-class-assign": "error", "no-class-assign": "error",
"no-confusing-arrow": "error",
"no-const-assign": "error", "no-const-assign": "error",
"no-dupe-class-members": "error", "no-dupe-class-members": "error",
"no-duplicate-imports": "error", "no-duplicate-imports": "error",
@ -229,6 +258,7 @@
"avoidQuotes": true, "avoidQuotes": true,
}], }],
"prefer-const": "error", "prefer-const": "error",
"require-yield": "error",
"sort-imports": ["error", { "sort-imports": ["error", {
"ignoreCase": true, "ignoreCase": true,
}], }],

6
.git-blame-ignore-revs Normal file
View File

@ -0,0 +1,6 @@
# Auto-format `.js` files with ESLint/Prettier
de36b2aabab2b7fd647d9591f959c4540129541d
# Auto-format `.css` files with Stylelint/Prettier
8aa2718d225ad701a5b8a2788b42d221f1e4327d
# Auto-format `.json` files with Prettier
29de9bdce6c9785574994fda0e51533d796a9bb4

2
.gitattributes vendored
View File

@ -4,7 +4,7 @@
*.css text eol=lf *.css text eol=lf
*.html text eol=lf *.html text eol=lf
*.md text eol=lf *.md text eol=lf
*.properties text eol=lf *.ftl text eol=lf
*.yml text eol=lf *.yml text eol=lf
*.json text eol=lf *.json text eol=lf
*.config text eol=lf *.config text eol=lf

1
.github/CODEOWNERS vendored Normal file
View File

@ -0,0 +1 @@
l10n/en-US/*.ftl @mozilla/pdfjs-l10n

8
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"

27
.github/fluent_linter_config.yml vendored Normal file
View File

@ -0,0 +1,27 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# See https://github.com/mozilla-l10n/moz-fluent-linter/blob/main/src/fluent_linter/config.yml
# for details
---
ID01:
enabled: true
exclusions:
messages: []
files: []
ID02:
enabled: true
min_length: 9
exclusions:
messages: []
files: []
CO01:
enabled: true
brands:
- Firefox
- Mozilla
exclusions:
files: []
messages: []

1
.github/requirements.txt vendored Normal file
View File

@ -0,0 +1 @@
moz-fluent-linter==0.4.*

View File

@ -1,18 +1,28 @@
name: CI name: CI
on: [push, pull_request] on: [push, pull_request]
permissions:
contents: read
jobs: jobs:
test: test:
name: Test name: Test
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [18, lts/*, latest]
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v4
- name: Use Node.js 16 LTS
uses: actions/setup-node@v2
with: with:
node-version: '16' fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Gulp - name: Install Gulp
run: npm install -g gulp-cli run: npm install -g gulp-cli
@ -20,5 +30,8 @@ jobs:
- name: Install other dependencies - name: Install other dependencies
run: npm install run: npm install
- name: Run tests - name: Run external tests
run: gulp ci-test run: gulp externaltest
- name: Run CLI unit tests
run: gulp unittestcli

View File

@ -1,13 +1,14 @@
name: CodeQL name: CodeQL
on: [push, pull_request] on: [push, pull_request]
permissions:
contents: read
jobs: jobs:
analyze: analyze:
name: Analyze name: Analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
actions: read
contents: read
security-events: write security-events: write
strategy: strategy:
@ -17,16 +18,18 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v3
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
queries: security-and-quality queries: security-and-quality
- name: Autobuild CodeQL - name: Autobuild CodeQL
uses: github/codeql-action/autobuild@v1 uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL analysis - name: Perform CodeQL analysis
uses: github/codeql-action/analyze@v1 uses: github/codeql-action/analyze@v3

42
.github/workflows/fluent_linter.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: Lint Fluent Reference Files
on:
push:
paths:
- 'l10n/en-US/**.ftl'
- '.github/fluent_linter_config.yml'
- '.github/workflows/fluent_linter.yml'
branches:
- master
pull_request:
paths:
- 'l10n/en-US/**.ftl'
- '.github/fluent_linter_config.yml'
- '.github/workflows/fluent_linter.yml'
branches:
- master
workflow_dispatch:
permissions:
contents: read
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Use Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install Fluent dependencies
run: |
pip install -r .github/requirements.txt
- name: Lint Fluent reference files
run: |
moz-fluent-lint ./l10n/en-US --config .github/fluent_linter_config.yml

64
.github/workflows/font_tests.yml vendored Normal file
View File

@ -0,0 +1,64 @@
name: Font tests
on:
push:
paths:
- 'gulpfile.mjs'
- 'src/**'
- 'test/test.mjs'
- 'test/font/**'
- '.github/workflows/font_tests.yml'
branches:
- master
pull_request:
paths:
- 'gulpfile.mjs'
- 'src/**'
- 'test/test.mjs'
- 'test/font/**'
- '.github/workflows/font_tests.yml'
branches:
- master
workflow_dispatch:
permissions:
contents: read
jobs:
test:
name: Test
strategy:
fail-fast: false
matrix:
node-version: [lts/*]
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Gulp
run: npm install -g gulp-cli
- name: Install other dependencies
run: npm install
- name: Use Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install Fonttools
run: pip install fonttools
- name: Run font tests
run: gulp fonttest --headless

37
.github/workflows/lint.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: Lint
on: [push, pull_request]
permissions:
contents: read
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [lts/*]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Gulp
run: npm install -g gulp-cli
- name: Install other dependencies
run: npm install
- name: Run lint
run: gulp lint
- name: Run lint-chromium
run: gulp lint-chromium

72
.github/workflows/publish_website.yml vendored Normal file
View File

@ -0,0 +1,72 @@
name: Publish website
on:
push:
branches:
- master
permissions:
contents: read
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [lts/*]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Gulp
run: npm install -g gulp-cli
- name: Install other dependencies
run: npm install
- name: Build the website
run: gulp web
- name: Archive the website
shell: sh
run: |
chmod -c -R +rX "$INPUT_PATH" | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done
tar \
--dereference --hard-dereference \
--directory "$INPUT_PATH" \
-cvf "$RUNNER_TEMP/website.tar" \
--exclude=.git \
--exclude=.github \
.
env:
INPUT_PATH: build/gh-pages
- name: Upload the website
uses: actions/upload-artifact@v4
with:
name: github-pages
path: ${{ runner.temp }}/website.tar
retention-days: 1
if-no-files-found: error
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build
permissions:
pages: write # Required to deploy to GitHub Pages.
id-token: write # Required to verify that the deployment originates from this workflow.
steps:
- name: Deploy the website
uses: actions/deploy-pages@v4

34
.github/workflows/types_tests.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Types tests
on: [push, pull_request]
permissions:
contents: read
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [lts/*]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Gulp
run: npm install -g gulp-cli
- name: Install other dependencies
run: npm install
- name: Run types tests
run: gulp typestest

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "test/ttx/fonttools-code"]
path = test/ttx/fonttools-code
url = https://github.com/behdad/fonttools.git

12
.prettierignore Normal file
View File

@ -0,0 +1,12 @@
build/
l10n/
docs/
node_modules/
external/bcmaps/
external/builder/fixtures/
external/builder/fixtures_esprima/
external/quickjs/
test/tmp/
test/pdfs/
web/locale/
*~/

View File

@ -5,5 +5,14 @@
"semi": true, "semi": true,
"tabWidth": 2, "tabWidth": 2,
"trailingComma": "es5", "trailingComma": "es5",
"useTabs": false "useTabs": false,
"overrides": [
{
files: ["tsconfig.json"],
options: {
parser: "json",
},
},
]
} }

View File

@ -3,12 +3,10 @@ l10n/
docs/ docs/
node_modules/ node_modules/
external/bcmaps/ external/bcmaps/
external/webL10n/
external/builder/fixtures/ external/builder/fixtures/
external/builder/fixtures_esprima/ external/builder/fixtures_esprima/
external/quickjs/ external/quickjs/
src/shared/cffStandardStrings.js
src/shared/fonts_utils.js
test/tmp/ test/tmp/
test/pdfs/ test/pdfs/
web/locale/
*~/ *~/

View File

@ -3,16 +3,23 @@
"stylelint-prettier" "stylelint-prettier"
], ],
"extends": [
"stylelint-prettier/recommended"
],
"rules": { "rules": {
"prettier/prettier": true,
"alpha-value-notation": "number",
"block-no-empty": true, "block-no-empty": true,
"color-function-notation": "modern",
"color-hex-length": "short",
"color-no-invalid-hex": true,
"declaration-block-no-duplicate-properties": true,
"declaration-block-no-redundant-longhand-properties": true,
"declaration-property-value-disallowed-list": {
"float": ["inline-start", "inline-end"]
},
"length-zero-no-unit": [true, { "length-zero-no-unit": [true, {
ignore: ["custom-properties"] ignore: ["custom-properties"]
}], }],
"selector-pseudo-element-colon-notation": "double",
"shorthand-property-no-redundant-values": true, "shorthand-property-no-redundant-values": true,
}, },
} }

View File

@ -14,7 +14,7 @@ get involved, visit:
+ [Issue Reporting Guide](https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md) + [Issue Reporting Guide](https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md)
+ [Code Contribution Guide](https://github.com/mozilla/pdf.js/wiki/Contributing) + [Code Contribution Guide](https://github.com/mozilla/pdf.js/wiki/Contributing)
+ [Frequently Asked Questions](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions) + [Frequently Asked Questions](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions)
+ [Good Beginner Bugs](https://github.com/mozilla/pdf.js/issues?direction=desc&labels=5-good-beginner-bug&page=1&sort=created&state=open) + [Good Beginner Bugs](https://github.com/mozilla/pdf.js/issues?direction=desc&labels=good-beginner-bug&page=1&sort=created&state=open)
+ [Projects](https://github.com/mozilla/pdf.js/projects) + [Projects](https://github.com/mozilla/pdf.js/projects)
Feel free to stop by our [Matrix room](https://chat.mozilla.org/#/room/#pdfjs:mozilla.org) for questions or guidance. Feel free to stop by our [Matrix room](https://chat.mozilla.org/#/room/#pdfjs:mozilla.org) for questions or guidance.
@ -23,9 +23,8 @@ Feel free to stop by our [Matrix room](https://chat.mozilla.org/#/room/#pdfjs:mo
### Online demo ### Online demo
Please note that the "Modern browsers" version assumes native support for Please note that the "Modern browsers" version assumes native support for the
features such as `async`/`await`, optional chaining, nullish coalescing, latest JavaScript features; please also see [this wiki page](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support).
and private `class` fields/methods.
+ Modern browsers: https://mozilla.github.io/pdf.js/web/viewer.html + Modern browsers: https://mozilla.github.io/pdf.js/web/viewer.html
@ -54,14 +53,19 @@ To get a local copy of the current code, clone it using git:
Next, install Node.js via the [official package](https://nodejs.org) or via Next, install Node.js via the [official package](https://nodejs.org) or via
[nvm](https://github.com/creationix/nvm). You need to install the gulp package [nvm](https://github.com/creationix/nvm). You need to install the gulp package
globally (see also [gulp's getting started](https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md#getting-started)): globally (see also [gulp's getting started](https://github.com/gulpjs/gulp/tree/master/docs/getting-started)):
$ npm install -g gulp-cli $ npm install -g gulp-cli@^2.3.0
If you prefer to not install `gulp-cli` globally, you have to prefix all the `gulp` commands with `npx` (for example, `npx gulp server` instead of `gulp server`).
If everything worked out, install all dependencies for PDF.js: If everything worked out, install all dependencies for PDF.js:
$ npm install $ npm install
> [!NOTE]
> On MacOS M1/M2 you may see some `node-gyp`-related errors when running `npm install`. This is because one of our dependencies, `"canvas"`, does not provide pre-built binaries for this platform and instead `npm` will try to build it from source. Please make sure to first install the necessary native dependencies using `brew`: https://github.com/Automattic/node-canvas#compiling.
Finally, you need to start a local web server as some browsers do not allow opening Finally, you need to start a local web server as some browsers do not allow opening
PDF files using a `file://` URL. Run: PDF files using a `file://` URL. Run:
@ -71,7 +75,7 @@ and then you can open:
+ http://localhost:8888/web/viewer.html + http://localhost:8888/web/viewer.html
Please keep in mind that this requires a modern and fully up-to-date browser; refer to [Building PDF.js](https://github.com/mozilla/pdf.js/blob/master/README.md#building-pdfjs) for non-development usage of the PDF.js library. Please keep in mind that this assumes the latest version of Mozilla Firefox; refer to [Building PDF.js](https://github.com/mozilla/pdf.js/blob/master/README.md#building-pdfjs) for non-development usage of the PDF.js library.
It is also possible to view all test PDF files on the right side by opening: It is also possible to view all test PDF files on the right side by opening:
@ -140,7 +144,3 @@ Talk to us on Matrix:
File an issue: File an issue:
+ https://github.com/mozilla/pdf.js/issues/new + https://github.com/mozilla/pdf.js/issues/new
Follow us on twitter: @pdfjs
+ https://twitter.com/pdfjs

View File

@ -83,17 +83,17 @@ var scaledViewport = page.getViewport({ scale: scale, });
The example demonstrates how promises can be used to handle errors during loading. The example demonstrates how promises can be used to handle errors during loading.
It also demonstrates how to wait until a page is loaded and rendered. It also demonstrates how to wait until a page is loaded and rendered.
<script async src="//jsfiddle.net/pdfjs/9engc9mw/embed/js,html,css,result/"></script> <script async src="//jsfiddle.net/pdfjs/9engc9mw/embed/html,css,result/"></script>
### Hello World using base64 encoded PDF ### Hello World using base64 encoded PDF
The PDF.js can accept any decoded base64 data as an array. The PDF.js can accept any decoded base64 data as an array.
<script async src="//jsfiddle.net/pdfjs/cq0asLqz/embed/js,html,css,result/"></script> <script async src="//jsfiddle.net/pdfjs/cq0asLqz/embed/html,css,result/"></script>
### Previous/Next example ### Previous/Next example
The same canvas cannot be used to perform to draw two pages at the same time -- The same canvas cannot be used to perform to draw two pages at the same time --
the example demonstrates how to wait on previous operation to be complete. the example demonstrates how to wait on previous operation to be complete.
<script async src="//jsfiddle.net/pdfjs/wagvs9Lf/embed/js,html,css,result/"></script> <script async src="//jsfiddle.net/pdfjs/wagvs9Lf/embed/html,css,result/"></script>

View File

@ -37,16 +37,18 @@ Before downloading PDF.js please take a moment to understand the different layer
## Download ## Download
Please refer to [this wiki page](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support) for information about supported browsers.
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<h3>Prebuilt</h3> <h3>Prebuilt (modern browsers)</h3>
<p> <p>
Includes the generic build of PDF.js and the viewer. Includes the generic build of PDF.js and the viewer.
</p> </p>
<a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-dist.zip">Stable (vSTABLE_VERSION)</a> <a type="button" class="btn btn-primary" href="https://github.com/mozilla/pdf.js/releases/download/vSTABLE_VERSION/pdfjs-STABLE_VERSION-dist.zip">Stable (vSTABLE_VERSION)</a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<h3>Prebuilt (for older browsers)</h3> <h3>Prebuilt (older browsers)</h3>
<p> <p>
Includes the generic build of PDF.js and the viewer. Includes the generic build of PDF.js and the viewer.
</p> </p>
@ -106,8 +108,7 @@ Note that we only mention the most relevant files and folders.
│   ├── display/ - display layer │   ├── display/ - display layer
│   ├── shared/ - shared code between the core and display layers │   ├── shared/ - shared code between the core and display layers
│   ├── interfaces.js - interface definitions for the core/display layers │   ├── interfaces.js - interface definitions for the core/display layers
│   ├── pdf.*.js - wrapper files for bundling │   └── pdf.*.js - wrapper files for bundling
│   └── worker_loader.js - used for developer builds to load worker files
├── test/ - unit, font, reference, and integration tests ├── test/ - unit, font, reference, and integration tests
├── web/ - viewer layer ├── web/ - viewer layer
├── LICENSE ├── LICENSE

View File

@ -1 +0,0 @@
node_modules/

View File

@ -1,26 +0,0 @@
## Overview
Example to demonstrate PDF.js library usage with Browserify.
## Getting started
Build project and install the example dependencies:
$ gulp dist-install
$ cd examples/browserify
$ npm install
To build Browserify bundles, run `gulp build`. If you are running
a web server, you can observe the build results at
http://localhost:8888/examples/browserify/index.html
See main.js, worker.js and gulpfile.js files. Please notice that PDF.js
packaging requires packaging of the main application and PDF.js worker code,
and the `workerSrc` path shall be set to the latter file. The pdf.worker.js file
shall be excluded from the main bundle.
Alternatives to the gulp commands (without compression) are:
$ mkdir -p ../../build/browserify
$ node_modules/.bin/browserify main.js -u ./node_modules/pdfjs-dist/build/pdf.worker.js -o ../../build/browserify/main.bundle.js
$ node_modules/.bin/browserify worker.js -o ../../build/browserify/pdf.worker.bundle.js

View File

@ -1,40 +0,0 @@
const gulp = require("gulp");
const browserify = require("browserify");
const streamify = require("gulp-streamify");
const rename = require("gulp-rename");
const uglify = require("gulp-uglify");
const source = require("vinyl-source-stream");
const OUTPUT_PATH = "../../build/browserify";
const TMP_FILE_PREFIX = "../../build/browserify_";
gulp.task("build-bundle", function () {
return browserify("main.js", { output: TMP_FILE_PREFIX + "main.tmp" })
.ignore(require.resolve("pdfjs-dist/build/pdf.worker")) // Reducing size
.bundle()
.pipe(source(TMP_FILE_PREFIX + "main.tmp"))
.pipe(streamify(uglify()))
.pipe(rename("main.bundle.js"))
.pipe(gulp.dest(OUTPUT_PATH));
});
gulp.task("build-worker", function () {
// We can create our own viewer (see worker.js) or use already defined one.
const workerSrc = require.resolve("pdfjs-dist/build/pdf.worker.entry");
return browserify(workerSrc, { output: TMP_FILE_PREFIX + "worker.tmp" })
.bundle()
.pipe(source(TMP_FILE_PREFIX + "worker.tmp"))
.pipe(
streamify(
uglify({
compress: {
sequences: false, // Chrome has issue with the generated code if true
},
})
)
)
.pipe(rename("pdf.worker.bundle.js"))
.pipe(gulp.dest(OUTPUT_PATH));
});
gulp.task("build", gulp.series("build-bundle", "build-worker"));

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>browserify example</title>
<script src="../../build/browserify/main.bundle.js"></script>
</head>
<body>
<canvas id="theCanvas"></canvas>
</body>
</html>

View File

@ -1,35 +0,0 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
// Hello world example for browserify.
const pdfjsLib = require("pdfjs-dist");
const pdfPath = "../learning/helloworld.pdf";
// Setting worker path to worker bundle.
pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../build/browserify/pdf.worker.bundle.js";
// Loading a document.
const loadingTask = pdfjsLib.getDocument(pdfPath);
loadingTask.promise
.then(function (pdfDocument) {
// Request a first page
return pdfDocument.getPage(1).then(function (pdfPage) {
// Display page on the existing canvas with 100% scale.
const viewport = pdfPage.getViewport({ scale: 1.0 });
const canvas = document.getElementById("theCanvas");
canvas.width = viewport.width;
canvas.height = viewport.height;
const ctx = canvas.getContext("2d");
const renderTask = pdfPage.render({
canvasContext: ctx,
viewport,
});
return renderTask.promise;
});
})
.catch(function (reason) {
console.error("Error: " + reason);
});

View File

@ -1,16 +0,0 @@
{
"name": "browserify-pdf.js-example",
"version": "0.1.0",
"devDependencies": {
"browserify": "^13.0.0",
"gulp": "^3.9.1",
"gulp-rename": "^1.2.2",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "^1.5.3",
"pdfjs-dist": "../../node_modules/pdfjs-dist",
"vinyl-source-stream": "^1.1.0"
},
"scripts": {
"build": "gulp build"
}
}

View File

@ -1,9 +0,0 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
// Hello world example for browserify: worker bundle.
(typeof window !== "undefined"
? window
: {}
).pdfjsWorker = require("pdfjs-dist/build/pdf.worker");

View File

@ -31,13 +31,13 @@ limitations under the License.
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css"> <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script> <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script>
</head> </head>
<body tabindex="1"> <body tabindex="1">
<div id="pageContainer" class="pdfViewer singlePageView"></div> <div id="pageContainer" class="pdfViewer singlePageView"></div>
<script src="pageviewer.js"></script> <script src="pageviewer.mjs" type="module"></script>
</body> </body>
</html> </html>

View File

@ -1,74 +0,0 @@
/* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFPageView) {
// eslint-disable-next-line no-alert
alert("Please build the pdfjs-dist library using\n `gulp dist-install`");
}
// The workerSrc property shall be specified.
//
pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../node_modules/pdfjs-dist/build/pdf.worker.js";
// Some PDFs need external cmaps.
//
const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
const CMAP_PACKED = true;
const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
const PAGE_TO_VIEW = 1;
const SCALE = 1.0;
const ENABLE_XFA = true;
const container = document.getElementById("pageContainer");
const eventBus = new pdfjsViewer.EventBus();
// Loading document.
const loadingTask = pdfjsLib.getDocument({
url: DEFAULT_URL,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA,
});
(async function () {
const pdfDocument = await loadingTask.promise;
// Document loaded, retrieving the page.
const pdfPage = await pdfDocument.getPage(PAGE_TO_VIEW);
// Creating the page view with default parameters.
const pdfPageView = new pdfjsViewer.PDFPageView({
container,
id: PAGE_TO_VIEW,
scale: SCALE,
defaultViewport: pdfPage.getViewport({ scale: SCALE }),
eventBus,
// We can enable text/annotation/xfa/struct-layers, as needed.
textLayerFactory: !pdfDocument.isPureXfa
? new pdfjsViewer.DefaultTextLayerFactory()
: null,
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
xfaLayerFactory: pdfDocument.isPureXfa
? new pdfjsViewer.DefaultXfaLayerFactory()
: null,
structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
});
// Associate the actual page with the view, and draw it.
pdfPageView.setPdfPage(pdfPage);
return pdfPageView.draw();
})();

View File

@ -13,9 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
"use strict"; if (!pdfjsLib.getDocument || !pdfjsViewer.PDFPageView) {
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
alert("Please build the pdfjs-dist library using\n `gulp dist-install`"); alert("Please build the pdfjs-dist library using\n `gulp dist-install`");
} }
@ -23,7 +21,7 @@ if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../node_modules/pdfjs-dist/build/pdf.worker.js"; "../../node_modules/pdfjs-dist/build/pdf.worker.mjs";
// Some PDFs need external cmaps. // Some PDFs need external cmaps.
// //
@ -31,40 +29,35 @@ const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
const CMAP_PACKED = true; const CMAP_PACKED = true;
const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
const PAGE_TO_VIEW = 1;
const SCALE = 1.0;
const container = document.getElementById("viewerContainer"); const ENABLE_XFA = true;
const container = document.getElementById("pageContainer");
const eventBus = new pdfjsViewer.EventBus(); const eventBus = new pdfjsViewer.EventBus();
// (Optionally) enable hyperlinks within PDF files.
const pdfLinkService = new pdfjsViewer.PDFLinkService({
eventBus,
});
const pdfViewer = new pdfjsViewer.PDFViewer({
container,
eventBus,
linkService: pdfLinkService,
renderer: "svg",
textLayerMode: 0,
});
pdfLinkService.setViewer(pdfViewer);
eventBus.on("pagesinit", function () {
// We can use pdfViewer now, e.g. let's change default scale.
pdfViewer.currentScaleValue = "page-width";
});
// Loading document. // Loading document.
const loadingTask = pdfjsLib.getDocument({ const loadingTask = pdfjsLib.getDocument({
url: DEFAULT_URL, url: DEFAULT_URL,
cMapUrl: CMAP_URL, cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA,
}); });
loadingTask.promise.then(function (pdfDocument) {
// Document loaded, specifying document for the viewer and
// the (optional) linkService.
pdfViewer.setDocument(pdfDocument);
pdfLinkService.setDocument(pdfDocument, null); const pdfDocument = await loadingTask.promise;
// Document loaded, retrieving the page.
const pdfPage = await pdfDocument.getPage(PAGE_TO_VIEW);
// Creating the page view with default parameters.
const pdfPageView = new pdfjsViewer.PDFPageView({
container,
id: PAGE_TO_VIEW,
scale: SCALE,
defaultViewport: pdfPage.getViewport({ scale: SCALE }),
eventBus,
}); });
// Associate the actual page with the view, and draw it.
pdfPageView.setPdfPage(pdfPage);
pdfPageView.draw();

View File

@ -37,8 +37,8 @@ limitations under the License.
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css"> <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script> <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script>
</head> </head>
<body tabindex="1"> <body tabindex="1">
@ -46,6 +46,6 @@ limitations under the License.
<div id="viewer" class="pdfViewer"></div> <div id="viewer" class="pdfViewer"></div>
</div> </div>
<script src="simpleviewer.js"></script> <script src="simpleviewer.mjs" type="module"></script>
</body> </body>
</html> </html>

View File

@ -13,8 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
"use strict";
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) { if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
alert("Please build the pdfjs-dist library using\n `gulp dist-install`"); alert("Please build the pdfjs-dist library using\n `gulp dist-install`");
@ -23,7 +21,7 @@ if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../node_modules/pdfjs-dist/build/pdf.worker.js"; "../../node_modules/pdfjs-dist/build/pdf.worker.mjs";
// Some PDFs need external cmaps. // Some PDFs need external cmaps.
// //
@ -37,7 +35,10 @@ const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
const ENABLE_XFA = true; const ENABLE_XFA = true;
const SEARCH_FOR = ""; // try "Mozilla"; const SEARCH_FOR = ""; // try "Mozilla";
const SANDBOX_BUNDLE_SRC = "../../node_modules/pdfjs-dist/build/pdf.sandbox.js"; const SANDBOX_BUNDLE_SRC = new URL(
"../../node_modules/pdfjs-dist/build/pdf.sandbox.mjs",
window.location
);
const container = document.getElementById("viewerContainer"); const container = document.getElementById("viewerContainer");
@ -66,7 +67,6 @@ const pdfViewer = new pdfjsViewer.PDFViewer({
linkService: pdfLinkService, linkService: pdfLinkService,
findController: pdfFindController, findController: pdfFindController,
scriptingManager: pdfScriptingManager, scriptingManager: pdfScriptingManager,
enableScripting: true, // Only necessary in PDF.js version 2.10.377 and below.
}); });
pdfLinkService.setViewer(pdfViewer); pdfLinkService.setViewer(pdfViewer);
pdfScriptingManager.setViewer(pdfViewer); pdfScriptingManager.setViewer(pdfViewer);
@ -77,12 +77,8 @@ eventBus.on("pagesinit", function () {
// We can try searching for things. // We can try searching for things.
if (SEARCH_FOR) { if (SEARCH_FOR) {
if (!pdfFindController._onFind) {
pdfFindController.executeCommand("find", { query: SEARCH_FOR });
} else {
eventBus.dispatch("find", { type: "", query: SEARCH_FOR }); eventBus.dispatch("find", { type: "", query: SEARCH_FOR });
} }
}
}); });
// Loading document. // Loading document.
@ -92,11 +88,10 @@ const loadingTask = pdfjsLib.getDocument({
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA, enableXfa: ENABLE_XFA,
}); });
(async function () {
const pdfDocument = await loadingTask.promise; const pdfDocument = await loadingTask.promise;
// Document loaded, specifying document for the viewer and // Document loaded, specifying document for the viewer and
// the (optional) linkService. // the (optional) linkService.
pdfViewer.setDocument(pdfDocument); pdfViewer.setDocument(pdfDocument);
pdfLinkService.setDocument(pdfDocument, null); pdfLinkService.setDocument(pdfDocument, null);
})();

View File

@ -37,8 +37,8 @@ limitations under the License.
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css"> <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script> <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script>
</head> </head>
<body tabindex="1"> <body tabindex="1">
@ -46,6 +46,6 @@ limitations under the License.
<div id="viewer" class="pdfViewer"></div> <div id="viewer" class="pdfViewer"></div>
</div> </div>
<script src="singlepageviewer.js"></script> <script src="singlepageviewer.mjs" type="module"></script>
</body> </body>
</html> </html>

View File

@ -13,8 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
"use strict";
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFSinglePageViewer) { if (!pdfjsLib.getDocument || !pdfjsViewer.PDFSinglePageViewer) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
alert("Please build the pdfjs-dist library using\n `gulp dist-install`"); alert("Please build the pdfjs-dist library using\n `gulp dist-install`");
@ -23,7 +21,7 @@ if (!pdfjsLib.getDocument || !pdfjsViewer.PDFSinglePageViewer) {
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../node_modules/pdfjs-dist/build/pdf.worker.js"; "../../node_modules/pdfjs-dist/build/pdf.worker.mjs";
// Some PDFs need external cmaps. // Some PDFs need external cmaps.
// //
@ -37,7 +35,10 @@ const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
const ENABLE_XFA = true; const ENABLE_XFA = true;
const SEARCH_FOR = ""; // try "Mozilla"; const SEARCH_FOR = ""; // try "Mozilla";
const SANDBOX_BUNDLE_SRC = "../../node_modules/pdfjs-dist/build/pdf.sandbox.js"; const SANDBOX_BUNDLE_SRC = new URL(
"../../node_modules/pdfjs-dist/build/pdf.sandbox.mjs",
window.location
);
const container = document.getElementById("viewerContainer"); const container = document.getElementById("viewerContainer");
@ -66,7 +67,6 @@ const pdfSinglePageViewer = new pdfjsViewer.PDFSinglePageViewer({
linkService: pdfLinkService, linkService: pdfLinkService,
findController: pdfFindController, findController: pdfFindController,
scriptingManager: pdfScriptingManager, scriptingManager: pdfScriptingManager,
enableScripting: true, // Only necessary in PDF.js version 2.10.377 and below.
}); });
pdfLinkService.setViewer(pdfSinglePageViewer); pdfLinkService.setViewer(pdfSinglePageViewer);
pdfScriptingManager.setViewer(pdfSinglePageViewer); pdfScriptingManager.setViewer(pdfSinglePageViewer);
@ -77,12 +77,8 @@ eventBus.on("pagesinit", function () {
// We can try searching for things. // We can try searching for things.
if (SEARCH_FOR) { if (SEARCH_FOR) {
if (!pdfFindController._onFind) {
pdfFindController.executeCommand("find", { query: SEARCH_FOR });
} else {
eventBus.dispatch("find", { type: "", query: SEARCH_FOR }); eventBus.dispatch("find", { type: "", query: SEARCH_FOR });
} }
}
}); });
// Loading document. // Loading document.
@ -92,10 +88,10 @@ const loadingTask = pdfjsLib.getDocument({
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA, enableXfa: ENABLE_XFA,
}); });
loadingTask.promise.then(function (pdfDocument) {
const pdfDocument = await loadingTask.promise;
// Document loaded, specifying document for the viewer and // Document loaded, specifying document for the viewer and
// the (optional) linkService. // the (optional) linkService.
pdfSinglePageViewer.setDocument(pdfDocument); pdfSinglePageViewer.setDocument(pdfDocument);
pdfLinkService.setDocument(pdfDocument, null); pdfLinkService.setDocument(pdfDocument, null);
});

View File

@ -29,12 +29,12 @@ limitations under the License.
} }
</style> </style>
<script src="../../node_modules/pdfjs-dist/image_decoders/pdf.image_decoders.js"></script> <script src="../../node_modules/pdfjs-dist/image_decoders/pdf.image_decoders.mjs" type="module"></script>
</head> </head>
<body tabindex="1"> <body tabindex="1">
<canvas id="jpegCanvas" width="0" height="0"></canvas> <canvas id="jpegCanvas" width="0" height="0"></canvas>
<script src="jpeg_viewer.js"></script> <script src="jpeg_viewer.mjs" type="module"></script>
</body> </body>
</html> </html>

View File

@ -1,63 +0,0 @@
/* Copyright 2018 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";
if (!pdfjsImageDecoders.JpegImage) {
// eslint-disable-next-line no-alert
alert("Please build the pdfjs-dist library using `gulp dist-install`");
}
const JPEG_IMAGE = "fish.jpg";
const jpegCanvas = document.getElementById("jpegCanvas");
const jpegCtx = jpegCanvas.getContext("2d");
(async function () {
// Load the image data, and convert it to a Uint8Array.
//
const response = await fetch(JPEG_IMAGE);
if (!response.ok) {
throw new Error(response.statusText);
}
const typedArrayImage = new Uint8Array(await response.arrayBuffer());
// Parse the image data using `JpegImage`.
//
const jpegImage = new pdfjsImageDecoders.JpegImage();
jpegImage.parse(typedArrayImage);
const width = jpegImage.width,
height = jpegImage.height;
const jpegData = jpegImage.getData({
width,
height,
forceRGB: true,
});
// Render the JPEG image on a <canvas>.
//
const imageData = jpegCtx.createImageData(width, height);
const imageBytes = imageData.data;
for (let j = 0, k = 0, jj = width * height * 4; j < jj; ) {
imageBytes[j++] = jpegData[k++];
imageBytes[j++] = jpegData[k++];
imageBytes[j++] = jpegData[k++];
imageBytes[j++] = 255;
}
jpegCanvas.width = width;
jpegCanvas.height = height;
jpegCtx.putImageData(imageData, 0, 0);
})();

View File

@ -0,0 +1,59 @@
/* Copyright 2018 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
if (!pdfjsImageDecoders.JpegImage) {
// eslint-disable-next-line no-alert
alert("Please build the pdfjs-dist library using `gulp dist-install`");
}
const JPEG_IMAGE = "fish.jpg";
const jpegCanvas = document.getElementById("jpegCanvas");
const jpegCtx = jpegCanvas.getContext("2d");
// Load the image data, and convert it to a Uint8Array.
//
const response = await fetch(JPEG_IMAGE);
if (!response.ok) {
throw new Error(response.statusText);
}
const typedArrayImage = new Uint8Array(await response.arrayBuffer());
// Parse the image data using `JpegImage`.
//
const jpegImage = new pdfjsImageDecoders.JpegImage();
jpegImage.parse(typedArrayImage);
const width = jpegImage.width,
height = jpegImage.height;
const jpegData = jpegImage.getData({
width,
height,
forceRGB: true,
});
// Render the JPEG image on a <canvas>.
//
const imageData = jpegCtx.createImageData(width, height);
const imageBytes = imageData.data;
for (let j = 0, k = 0, jj = width * height * 4; j < jj; ) {
imageBytes[j++] = jpegData[k++];
imageBytes[j++] = jpegData[k++];
imageBytes[j++] = jpegData[k++];
imageBytes[j++] = 255;
}
jpegCanvas.width = width;
jpegCanvas.height = height;
jpegCtx.putImageData(imageData, 0, 0);

View File

@ -10,9 +10,9 @@
<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas> <canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script id="script"> <script id="script" type="module">
// //
// If absolute URL from the remote server is provided, configure the CORS // If absolute URL from the remote server is provided, configure the CORS
// header on that server. // header on that server.
@ -23,13 +23,12 @@
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js'; '../../node_modules/pdfjs-dist/build/pdf.worker.mjs';
// //
// Asynchronous download PDF // Asynchronous download PDF
// //
const loadingTask = pdfjsLib.getDocument(url); const loadingTask = pdfjsLib.getDocument(url);
(async () => {
const pdf = await loadingTask.promise; const pdf = await loadingTask.promise;
// //
// Fetch the first page // Fetch the first page
@ -64,7 +63,6 @@
viewport, viewport,
}; };
page.render(renderContext); page.render(renderContext);
})();
</script> </script>
<hr> <hr>

View File

@ -10,9 +10,9 @@
<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas> <canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script id="script"> <script id="script" type="module">
// atob() is used to convert base64 encoded PDF to binary-like data. // atob() is used to convert base64 encoded PDF to binary-like data.
// (See also https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/ // (See also https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/
// Base64_encoding_and_decoding.) // Base64_encoding_and_decoding.)
@ -35,12 +35,11 @@
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js'; '../../node_modules/pdfjs-dist/build/pdf.worker.mjs';
// Opening PDF by passing its binary data as a string. It is still preferable // Opening PDF by passing its binary data as a string. It is still preferable
// to use Uint8Array, but string or array-like structure will work too. // to use Uint8Array, but string or array-like structure will work too.
var loadingTask = pdfjsLib.getDocument({ data: pdfData, }); var loadingTask = pdfjsLib.getDocument({ data: pdfData, });
(async function() {
var pdf = await loadingTask.promise; var pdf = await loadingTask.promise;
// Fetch the first page. // Fetch the first page.
var page = await pdf.getPage(1); var page = await pdf.getPage(1);
@ -69,7 +68,6 @@
viewport, viewport,
}; };
page.render(renderContext); page.render(renderContext);
})();
</script> </script>
<hr> <hr>

View File

@ -19,9 +19,9 @@
<canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas> <canvas id="the-canvas" style="border: 1px solid black; direction: ltr;"></canvas>
</div> </div>
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script id="script"> <script id="script" type="module">
// //
// If absolute URL from the remote server is provided, configure the CORS // If absolute URL from the remote server is provided, configure the CORS
// header on that server. // header on that server.
@ -34,7 +34,7 @@
// shall be specified. // shall be specified.
// //
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../node_modules/pdfjs-dist/build/pdf.worker.js'; '../../node_modules/pdfjs-dist/build/pdf.worker.mjs';
var pdfDoc = null, var pdfDoc = null,
pageNum = 1, pageNum = 1,
@ -90,7 +90,7 @@
/** /**
* If another page rendering in progress, waits until the rendering is * If another page rendering in progress, waits until the rendering is
* finised. Otherwise, executes rendering immediately. * finished. Otherwise, executes rendering immediately.
*/ */
function queueRenderPage(num) { function queueRenderPage(num) {
if (pageRendering) { if (pageRendering) {
@ -128,13 +128,11 @@
* Asynchronously downloads PDF. * Asynchronously downloads PDF.
*/ */
var loadingTask = pdfjsLib.getDocument(url); var loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(function(pdfDoc_) { pdfDoc = await loadingTask.promise;
pdfDoc = pdfDoc_;
document.getElementById('page_count').textContent = pdfDoc.numPages; document.getElementById('page_count').textContent = pdfDoc.numPages;
// Initial/first page rendering // Initial/first page rendering
renderPage(pageNum); renderPage(pageNum);
});
</script> </script>
</body> </body>

View File

@ -26,12 +26,12 @@ html {
} }
header { header {
background-color: rgba(244, 244, 244, 1); background-color: rgb(244 244 244 / 1);
} }
header h1 { header h1 {
border-bottom: 1px solid rgba(216, 216, 216, 1); border-bottom: 1px solid rgb(216 216 216 / 1);
color: rgba(133, 133, 133, 1); color: rgb(133 133 133 / 1);
font-size: 23px; font-size: 23px;
font-style: italic; font-style: italic;
font-weight: normal; font-weight: normal;
@ -44,7 +44,7 @@ header h1 {
body { body {
background: url(images/document_bg.png); background: url(images/document_bg.png);
color: rgba(255, 255, 255, 1); color: rgb(255 255 255 / 1);
font-family: sans-serif; font-family: sans-serif;
font-size: 10px; font-size: 10px;
height: 100%; height: 100%;
@ -71,7 +71,7 @@ footer {
left: 0; left: 0;
right: 0; right: 0;
z-index: 1; z-index: 1;
box-shadow: 0 -0.2rem 0.5rem rgba(50, 50, 50, 0.75); box-shadow: 0 -0.2rem 0.5rem rgb(50 50 50 / 0.75);
} }
.toolbarButton { .toolbarButton {
@ -81,7 +81,7 @@ footer {
border-width: 0; border-width: 0;
background-position: center center; background-position: center center;
background-repeat: no-repeat; background-repeat: no-repeat;
background-color: rgba(0, 0, 0, 0); background-color: rgb(0 0 0 / 0);
} }
.toolbarButton.pageUp { .toolbarButton.pageUp {
@ -110,9 +110,9 @@ footer {
left: 36%; left: 36%;
text-align: center; text-align: center;
border: 0; border: 0;
background-color: rgba(0, 0, 0, 0); background-color: rgb(0 0 0 / 0);
font-size: 1.2rem; font-size: 1.2rem;
color: rgba(255, 255, 255, 1); color: rgb(255 255 255 / 1);
background-image: url(images/div_line_left.png), background-image: url(images/div_line_left.png),
url(images/div_line_right.png); url(images/div_line_right.png);
background-repeat: no-repeat; background-repeat: no-repeat;
@ -153,10 +153,7 @@ footer {
position: absolute; position: absolute;
overflow: auto; overflow: auto;
width: 100%; width: 100%;
top: 5rem; inset: 5rem 0 4rem;
bottom: 4rem;
left: 0;
right: 0;
} }
canvas { canvas {
@ -187,41 +184,47 @@ canvas {
} }
#loadingBar { #loadingBar {
/* Define this variable here, and not in :root, to avoid reflowing the
entire viewer when updating progress (see issue 15958). */
--progressBar-percent: 0%;
position: relative; position: relative;
height: 0.6rem; height: 0.6rem;
background-color: rgba(51, 51, 51, 1); background-color: rgb(51 51 51 / 1);
border-bottom: 1px solid rgba(51, 51, 51, 1); border-bottom: 1px solid rgb(51 51 51 / 1);
margin-top: 5rem;
} }
#loadingBar .progress { #loadingBar .progress {
position: absolute; position: absolute;
left: 0; left: 0;
width: 0; width: 100%;
transform: scaleX(var(--progressBar-percent));
transform-origin: 0 0;
height: 100%; height: 100%;
background-color: rgba(221, 221, 221, 1); background-color: rgb(221 221 221 / 1);
overflow: hidden; overflow: hidden;
transition: width 200ms; transition: transform 200ms;
} }
@keyframes progressIndeterminate { @keyframes progressIndeterminate {
0% { 0% {
left: 0; transform: translateX(0%);
} }
50% { 50% {
left: 100%; transform: translateX(100%);
} }
100% { 100% {
left: 100%; transform: translateX(100%);
} }
} }
#loadingBar .progress.indeterminate { #loadingBar.indeterminate .progress {
background-color: rgba(153, 153, 153, 1); transform: none;
background-color: rgb(153 153 153 / 1);
transition: none; transition: none;
} }
#loadingBar .indeterminate .glimmer { #loadingBar.indeterminate .progress .glimmer {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
@ -229,39 +232,11 @@ canvas {
width: 5rem; width: 5rem;
background-image: linear-gradient( background-image: linear-gradient(
to right, to right,
rgba(153, 153, 153, 1) 0%, rgb(153 153 153 / 1) 0%,
rgba(255, 255, 255, 1) 50%, rgb(255 255 255 / 1) 50%,
rgba(153, 153, 153, 1) 100% rgb(153 153 153 / 1) 100%
); );
background-size: 100% 100%; background-size: 100% 100%;
background-repeat: no-repeat; background-repeat: no-repeat;
animation: progressIndeterminate 2s linear infinite; animation: progressIndeterminate 2s linear infinite;
} }
#errorWrapper {
background: none repeat scroll 0 0 rgba(255, 85, 85, 1);
color: rgba(255, 255, 255, 1);
left: 0;
position: absolute;
right: 0;
top: 3.2rem;
z-index: 1000;
padding: 0.3rem;
font-size: 0.8em;
}
#errorMessageLeft {
float: left;
}
#errorMessageRight {
float: right;
}
#errorMoreInfo {
background-color: rgba(255, 255, 255, 1);
color: rgba(0, 0, 0, 1);
padding: 0.3rem;
margin: 0.3rem;
width: 98%;
}

View File

@ -24,8 +24,8 @@ limitations under the License.
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css"> <link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
<link rel="stylesheet" type="text/css" href="viewer.css"> <link rel="stylesheet" type="text/css" href="viewer.css">
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script> <script src="../../node_modules/pdfjs-dist/web/pdf_viewer.mjs" type="module"></script>
</head> </head>
<body> <body>
@ -42,25 +42,6 @@ limitations under the License.
<div class="glimmer"></div> <div class="glimmer"></div>
</div> </div>
<div id="errorWrapper" hidden="true">
<div id="errorMessageLeft">
<span id="errorMessage"></span>
<button id="errorShowMore">
More Information
</button>
<button id="errorShowLess">
Less Information
</button>
</div>
<div id="errorMessageRight">
<button id="errorClose">
Close
</button>
</div>
<div class="clearBoth"></div>
<textarea id="errorMoreInfo" hidden="true" readonly="readonly"></textarea>
</div>
<footer> <footer>
<button class="toolbarButton pageUp" title="Previous Page" id="previous"></button> <button class="toolbarButton pageUp" title="Previous Page" id="previous"></button>
<button class="toolbarButton pageDown" title="Next Page" id="next"></button> <button class="toolbarButton pageDown" title="Next Page" id="next"></button>
@ -71,6 +52,6 @@ limitations under the License.
<button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn"></button> <button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn"></button>
</footer> </footer>
<script src="viewer.js"></script> <script src="viewer.mjs" type="module"></script>
</body> </body>
</html> </html>

View File

@ -13,21 +13,19 @@
* limitations under the License. * limitations under the License.
*/ */
"use strict";
if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) { if (!pdfjsLib.getDocument || !pdfjsViewer.PDFViewer) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
alert("Please build the pdfjs-dist library using\n `gulp dist-install`"); alert("Please build the pdfjs-dist library using\n `gulp dist-install`");
} }
const USE_ONLY_CSS_ZOOM = true; const MAX_CANVAS_PIXELS = 0; // CSS-only zooming.
const TEXT_LAYER_MODE = 0; // DISABLE const TEXT_LAYER_MODE = 0; // DISABLE
const MAX_IMAGE_SIZE = 1024 * 1024; const MAX_IMAGE_SIZE = 1024 * 1024;
const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/"; const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
const CMAP_PACKED = true; const CMAP_PACKED = true;
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../node_modules/pdfjs-dist/build/pdf.worker.js"; "../../node_modules/pdfjs-dist/build/pdf.worker.mjs";
const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf"; const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
const DEFAULT_SCALE_DELTA = 1.1; const DEFAULT_SCALE_DELTA = 1.1;
@ -82,46 +80,24 @@ const PDFViewerApplication = {
self.pdfDocument = pdfDocument; self.pdfDocument = pdfDocument;
self.pdfViewer.setDocument(pdfDocument); self.pdfViewer.setDocument(pdfDocument);
self.pdfLinkService.setDocument(pdfDocument); self.pdfLinkService.setDocument(pdfDocument);
self.pdfHistory.initialize({ fingerprint: pdfDocument.fingerprint }); self.pdfHistory.initialize({
fingerprint: pdfDocument.fingerprints[0],
});
self.loadingBar.hide(); self.loadingBar.hide();
self.setTitleUsingMetadata(pdfDocument); self.setTitleUsingMetadata(pdfDocument);
}, },
function (exception) { function (reason) {
const message = exception && exception.message; let key = "pdfjs-loading-error";
const l10n = self.l10n; if (reason instanceof pdfjsLib.InvalidPDFException) {
let loadingErrorMessage; key = "pdfjs-invalid-file-error";
} else if (reason instanceof pdfjsLib.MissingPDFException) {
if (exception instanceof pdfjsLib.InvalidPDFException) { key = "pdfjs-missing-file-error";
// change error message also for other builds } else if (reason instanceof pdfjsLib.UnexpectedResponseException) {
loadingErrorMessage = l10n.get( key = "pdfjs-unexpected-response-error";
"invalid_file_error",
null,
"Invalid or corrupted PDF file."
);
} else if (exception instanceof pdfjsLib.MissingPDFException) {
// special message for missing PDFs
loadingErrorMessage = l10n.get(
"missing_file_error",
null,
"Missing PDF file."
);
} else if (exception instanceof pdfjsLib.UnexpectedResponseException) {
loadingErrorMessage = l10n.get(
"unexpected_response_error",
null,
"Unexpected server response."
);
} else {
loadingErrorMessage = l10n.get(
"loading_error",
null,
"An error occurred while loading the PDF."
);
} }
self.l10n.get(key).then(msg => {
loadingErrorMessage.then(function (msg) { self.error(msg, { message: reason?.message });
self.error(msg, { message });
}); });
self.loadingBar.hide(); self.loadingBar.hide();
} }
@ -134,9 +110,6 @@ const PDFViewerApplication = {
* destruction is completed. * destruction is completed.
*/ */
close() { close() {
const errorWrapper = document.getElementById("errorWrapper");
errorWrapper.hidden = true;
if (!this.pdfLoadingTask) { if (!this.pdfLoadingTask) {
return Promise.resolve(); return Promise.resolve();
} }
@ -159,9 +132,12 @@ const PDFViewerApplication = {
}, },
get loadingBar() { get loadingBar() {
const bar = new pdfjsViewer.ProgressBar("#loadingBar", {}); const bar = document.getElementById("loadingBar");
return pdfjsLib.shadow(
return pdfjsLib.shadow(this, "loadingBar", bar); this,
"loadingBar",
new pdfjsViewer.ProgressBar(bar)
);
}, },
setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) { setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
@ -169,7 +145,7 @@ const PDFViewerApplication = {
let title = pdfjsLib.getFilenameFromUrl(url) || url; let title = pdfjsLib.getFilenameFromUrl(url) || url;
try { try {
title = decodeURIComponent(title); title = decodeURIComponent(title);
} catch (e) { } catch {
// decodeURIComponent may throw URIError, // decodeURIComponent may throw URIError,
// fall back to using the unprocessed url in that case // fall back to using the unprocessed url in that case
} }
@ -187,7 +163,7 @@ const PDFViewerApplication = {
// Provides some basic debug information // Provides some basic debug information
console.log( console.log(
"PDF " + "PDF " +
pdfDocument.fingerprint + pdfDocument.fingerprints[0] +
" [" + " [" +
info.PDFFormatVersion + info.PDFFormatVersion +
" " + " " +
@ -226,79 +202,25 @@ const PDFViewerApplication = {
}, },
error: function pdfViewError(message, moreInfo) { error: function pdfViewError(message, moreInfo) {
const l10n = this.l10n;
const moreInfoText = [ const moreInfoText = [
l10n.get( `PDF.js v${pdfjsLib.version || "?"} (build: ${pdfjsLib.build || "?"})`,
"error_version_info",
{ version: pdfjsLib.version || "?", build: pdfjsLib.build || "?" },
"PDF.js v{{version}} (build: {{build}})"
),
]; ];
if (moreInfo) { if (moreInfo) {
moreInfoText.push( moreInfoText.push(`Message: ${moreInfo.message}`);
l10n.get(
"error_message",
{ message: moreInfo.message },
"Message: {{message}}"
)
);
if (moreInfo.stack) { if (moreInfo.stack) {
moreInfoText.push( moreInfoText.push(`Stack: ${moreInfo.stack}`);
l10n.get("error_stack", { stack: moreInfo.stack }, "Stack: {{stack}}")
);
} else { } else {
if (moreInfo.filename) { if (moreInfo.filename) {
moreInfoText.push( moreInfoText.push(`File: ${moreInfo.filename}`);
l10n.get(
"error_file",
{ file: moreInfo.filename },
"File: {{file}}"
)
);
} }
if (moreInfo.lineNumber) { if (moreInfo.lineNumber) {
moreInfoText.push( moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
l10n.get(
"error_line",
{ line: moreInfo.lineNumber },
"Line: {{line}}"
)
);
} }
} }
} }
const errorWrapper = document.getElementById("errorWrapper"); console.error(`${message}\n\n${moreInfoText.join("\n")}`);
errorWrapper.hidden = false;
const errorMessage = document.getElementById("errorMessage");
errorMessage.textContent = message;
const closeButton = document.getElementById("errorClose");
closeButton.onclick = function () {
errorWrapper.hidden = true;
};
const errorMoreInfo = document.getElementById("errorMoreInfo");
const moreInfoButton = document.getElementById("errorShowMore");
const lessInfoButton = document.getElementById("errorShowLess");
moreInfoButton.onclick = function () {
errorMoreInfo.hidden = false;
moreInfoButton.hidden = true;
lessInfoButton.hidden = false;
errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
};
lessInfoButton.onclick = function () {
errorMoreInfo.hidden = true;
moreInfoButton.hidden = false;
lessInfoButton.hidden = true;
};
moreInfoButton.hidden = false;
lessInfoButton.hidden = true;
Promise.all(moreInfoText).then(function (parts) {
errorMoreInfo.value = parts.join("\n");
});
}, },
progress: function pdfViewProgress(level) { progress: function pdfViewProgress(level) {
@ -350,7 +272,7 @@ const PDFViewerApplication = {
}); });
this.pdfLinkService = linkService; this.pdfLinkService = linkService;
this.l10n = pdfjsViewer.NullL10n; this.l10n = new pdfjsViewer.GenericL10n();
const container = document.getElementById("viewerContainer"); const container = document.getElementById("viewerContainer");
const pdfViewer = new pdfjsViewer.PDFViewer({ const pdfViewer = new pdfjsViewer.PDFViewer({
@ -358,7 +280,7 @@ const PDFViewerApplication = {
eventBus, eventBus,
linkService, linkService,
l10n: this.l10n, l10n: this.l10n,
useOnlyCssZoom: USE_ONLY_CSS_ZOOM, maxCanvasPixels: MAX_CANVAS_PIXELS,
textLayerMode: TEXT_LAYER_MODE, textLayerMode: TEXT_LAYER_MODE,
}); });
this.pdfViewer = pdfViewer; this.pdfViewer = pdfViewer;

View File

@ -1,276 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function xmlEncode(s) {
let i = 0,
ch;
s = String(s);
while (
i < s.length &&
(ch = s[i]) !== "&" &&
ch !== "<" &&
ch !== '"' &&
ch !== "\n" &&
ch !== "\r" &&
ch !== "\t"
) {
i++;
}
if (i >= s.length) {
return s;
}
let buf = s.substring(0, i);
while (i < s.length) {
ch = s[i++];
switch (ch) {
case "&":
buf += "&amp;";
break;
case "<":
buf += "&lt;";
break;
case '"':
buf += "&quot;";
break;
case "\n":
buf += "&#xA;";
break;
case "\r":
buf += "&#xD;";
break;
case "\t":
buf += "&#x9;";
break;
default:
buf += ch;
break;
}
}
return buf;
}
function DOMElement(name) {
this.nodeName = name;
this.childNodes = [];
this.attributes = {};
this.textContent = "";
if (name === "style") {
this.sheet = {
cssRules: [],
insertRule(rule) {
this.cssRules.push(rule);
},
};
}
}
DOMElement.prototype = {
getAttribute: function DOMElement_getAttribute(name) {
if (name in this.attributes) {
return this.attributes[name];
}
return null;
},
getAttributeNS: function DOMElement_getAttributeNS(NS, name) {
// Fast path
if (name in this.attributes) {
return this.attributes[name];
}
// Slow path - used by test/unit/display_svg_spec.js
// Assuming that there is only one matching attribute for a given name,
// across all namespaces.
if (NS) {
const suffix = ":" + name;
for (const fullName in this.attributes) {
if (fullName.slice(-suffix.length) === suffix) {
return this.attributes[fullName];
}
}
}
return null;
},
setAttribute: function DOMElement_setAttribute(name, value) {
this.attributes[name] = value || "";
},
setAttributeNS: function DOMElement_setAttributeNS(NS, name, value) {
this.setAttribute(name, value);
},
appendChild: function DOMElement_appendChild(element) {
const childNodes = this.childNodes;
if (!childNodes.includes(element)) {
childNodes.push(element);
}
},
hasChildNodes: function DOMElement_hasChildNodes() {
return this.childNodes.length !== 0;
},
cloneNode: function DOMElement_cloneNode() {
const newNode = new DOMElement(this.nodeName);
newNode.childNodes = this.childNodes;
newNode.attributes = this.attributes;
newNode.textContent = this.textContent;
return newNode;
},
// This method is offered for convenience. It is recommended to directly use
// getSerializer because that allows you to process the chunks as they come
// instead of requiring the whole image to fit in memory.
toString: function DOMElement_toString() {
const buf = [];
const serializer = this.getSerializer();
let chunk;
while ((chunk = serializer.getNext()) !== null) {
buf.push(chunk);
}
return buf.join("");
},
getSerializer: function DOMElement_getSerializer() {
return new DOMElementSerializer(this);
},
};
function DOMElementSerializer(node) {
this._node = node;
this._state = 0;
this._loopIndex = 0;
this._attributeKeys = null;
this._childSerializer = null;
}
DOMElementSerializer.prototype = {
/**
* Yields the next chunk in the serialization of the element.
*
* @returns {string|null} null if the element has fully been serialized.
*/
getNext: function DOMElementSerializer_getNext() {
const node = this._node;
switch (this._state) {
case 0: // Start opening tag.
++this._state;
return "<" + node.nodeName;
case 1: // Add SVG namespace if this is the root element.
++this._state;
if (node.nodeName === "svg:svg") {
return (
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
' xmlns:svg="http://www.w3.org/2000/svg"'
);
}
/* falls through */
case 2: // Initialize variables for looping over attributes.
++this._state;
this._loopIndex = 0;
this._attributeKeys = Object.keys(node.attributes);
/* falls through */
case 3: // Serialize any attributes and end opening tag.
if (this._loopIndex < this._attributeKeys.length) {
const name = this._attributeKeys[this._loopIndex++];
return " " + name + '="' + xmlEncode(node.attributes[name]) + '"';
}
++this._state;
return ">";
case 4: // Serialize textContent for tspan/style elements.
if (node.nodeName === "svg:tspan" || node.nodeName === "svg:style") {
this._state = 6;
return xmlEncode(node.textContent);
}
++this._state;
this._loopIndex = 0;
/* falls through */
case 5: // Serialize child nodes (only for non-tspan/style elements).
while (true) {
const value =
this._childSerializer && this._childSerializer.getNext();
if (value !== null) {
return value;
}
const nextChild = node.childNodes[this._loopIndex++];
if (nextChild) {
this._childSerializer = new DOMElementSerializer(nextChild);
} else {
this._childSerializer = null;
++this._state;
break;
}
}
/* falls through */
case 6: // Ending tag.
++this._state;
return "</" + node.nodeName + ">";
case 7: // Done.
return null;
default:
throw new Error("Unexpected serialization state: " + this._state);
}
},
};
const document = {
childNodes: [],
get currentScript() {
return { src: "" };
},
get documentElement() {
return this;
},
createElementNS(NS, element) {
const elObject = new DOMElement(element);
return elObject;
},
createElement(element) {
return this.createElementNS("", element);
},
getElementsByTagName(element) {
if (element === "head") {
return [this.head || (this.head = new DOMElement("head"))];
}
return [];
},
};
function Image() {
this._src = null;
this.onload = null;
}
Image.prototype = {
get src() {
return this._src;
},
set src(value) {
this._src = value;
if (this.onload) {
this.onload();
}
},
};
exports.document = document;
exports.Image = Image;
const exported_symbols = Object.keys(exports);
exports.setStubs = function (namespace) {
exported_symbols.forEach(function (key) {
console.assert(!(key in namespace), "property should not be set: " + key);
namespace[key] = exports[key];
});
};
exports.unsetStubs = function (namespace) {
exported_symbols.forEach(function (key) {
console.assert(key in namespace, "property should be set: " + key);
delete namespace[key];
});
};

View File

@ -3,12 +3,10 @@
// //
// Basic node example that prints document metadata and text content. // Basic node example that prints document metadata and text content.
// Requires single file built version of PDF.js -- please run
// `gulp singlefile` before running the example.
// //
// Run `gulp dist-install` to generate 'pdfjs-dist' npm package files. // Run `gulp dist-install` to generate 'pdfjs-dist' npm package files.
const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js"); import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
// Loading file from file system into typed array // Loading file from file system into typed array
const pdfPath = const pdfPath =
@ -16,7 +14,7 @@ const pdfPath =
// Will be using promises to load document, pages and misc data instead of // Will be using promises to load document, pages and misc data instead of
// callback. // callback.
const loadingTask = pdfjsLib.getDocument(pdfPath); const loadingTask = getDocument(pdfPath);
loadingTask.promise loadingTask.promise
.then(function (doc) { .then(function (doc) {
const numPages = doc.numPages; const numPages = doc.numPages;

View File

@ -13,13 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
const Canvas = require("canvas"); import { strict as assert } from "assert";
const assert = require("assert").strict; import Canvas from "canvas";
const fs = require("fs"); import fs from "fs";
import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
function NodeCanvasFactory() {} class NodeCanvasFactory {
NodeCanvasFactory.prototype = { create(width, height) {
create: function NodeCanvasFactory_create(width, height) {
assert(width > 0 && height > 0, "Invalid canvas size"); assert(width > 0 && height > 0, "Invalid canvas size");
const canvas = Canvas.createCanvas(width, height); const canvas = Canvas.createCanvas(width, height);
const context = canvas.getContext("2d"); const context = canvas.getContext("2d");
@ -27,16 +27,16 @@ NodeCanvasFactory.prototype = {
canvas, canvas,
context, context,
}; };
}, }
reset: function NodeCanvasFactory_reset(canvasAndContext, width, height) { reset(canvasAndContext, width, height) {
assert(canvasAndContext.canvas, "Canvas is not specified"); assert(canvasAndContext.canvas, "Canvas is not specified");
assert(width > 0 && height > 0, "Invalid canvas size"); assert(width > 0 && height > 0, "Invalid canvas size");
canvasAndContext.canvas.width = width; canvasAndContext.canvas.width = width;
canvasAndContext.canvas.height = height; canvasAndContext.canvas.height = height;
}, }
destroy: function NodeCanvasFactory_destroy(canvasAndContext) { destroy(canvasAndContext) {
assert(canvasAndContext.canvas, "Canvas is not specified"); assert(canvasAndContext.canvas, "Canvas is not specified");
// Zeroing the width and height cause Firefox to release graphics // Zeroing the width and height cause Firefox to release graphics
@ -45,10 +45,8 @@ NodeCanvasFactory.prototype = {
canvasAndContext.canvas.height = 0; canvasAndContext.canvas.height = 0;
canvasAndContext.canvas = null; canvasAndContext.canvas = null;
canvasAndContext.context = null; canvasAndContext.context = null;
}, }
}; }
const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");
// Some PDFs need external cmaps. // Some PDFs need external cmaps.
const CMAP_URL = "../../../node_modules/pdfjs-dist/cmaps/"; const CMAP_URL = "../../../node_modules/pdfjs-dist/cmaps/";
@ -58,20 +56,22 @@ const CMAP_PACKED = true;
const STANDARD_FONT_DATA_URL = const STANDARD_FONT_DATA_URL =
"../../../node_modules/pdfjs-dist/standard_fonts/"; "../../../node_modules/pdfjs-dist/standard_fonts/";
const canvasFactory = new NodeCanvasFactory();
// Loading file from file system into typed array. // Loading file from file system into typed array.
const pdfPath = const pdfPath =
process.argv[2] || "../../../web/compressed.tracemonkey-pldi-09.pdf"; process.argv[2] || "../../../web/compressed.tracemonkey-pldi-09.pdf";
const data = new Uint8Array(fs.readFileSync(pdfPath)); const data = new Uint8Array(fs.readFileSync(pdfPath));
// Load the PDF file. // Load the PDF file.
const loadingTask = pdfjsLib.getDocument({ const loadingTask = getDocument({
data, data,
cMapUrl: CMAP_URL, cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
standardFontDataUrl: STANDARD_FONT_DATA_URL, standardFontDataUrl: STANDARD_FONT_DATA_URL,
canvasFactory,
}); });
(async function () {
try { try {
const pdfDocument = await loadingTask.promise; const pdfDocument = await loadingTask.promise;
console.log("# PDF document loaded."); console.log("# PDF document loaded.");
@ -79,7 +79,6 @@ const loadingTask = pdfjsLib.getDocument({
const page = await pdfDocument.getPage(1); const page = await pdfDocument.getPage(1);
// Render the page on a Node canvas with 100% scale. // Render the page on a Node canvas with 100% scale.
const viewport = page.getViewport({ scale: 1.0 }); const viewport = page.getViewport({ scale: 1.0 });
const canvasFactory = new NodeCanvasFactory();
const canvasAndContext = canvasFactory.create( const canvasAndContext = canvasFactory.create(
viewport.width, viewport.width,
viewport.height viewport.height
@ -87,7 +86,6 @@ const loadingTask = pdfjsLib.getDocument({
const renderContext = { const renderContext = {
canvasContext: canvasAndContext.context, canvasContext: canvasAndContext.context,
viewport, viewport,
canvasFactory,
}; };
const renderTask = page.render(renderContext); const renderTask = page.render(renderContext);
@ -98,9 +96,7 @@ const loadingTask = pdfjsLib.getDocument({
if (error) { if (error) {
console.error("Error: " + error); console.error("Error: " + error);
} else { } else {
console.log( console.log("Finished converting first page of PDF file to a PNG image.");
"Finished converting first page of PDF file to a PNG image."
);
} }
}); });
// Release page resources. // Release page resources.
@ -108,4 +104,3 @@ const loadingTask = pdfjsLib.getDocument({
} catch (reason) { } catch (reason) {
console.log(reason); console.log(reason);
} }
})();

View File

@ -1,128 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
//
// Node tool to dump SVG output into a file.
//
const fs = require("fs");
const util = require("util");
const path = require("path");
const stream = require("stream");
// HACK few hacks to let PDF.js be loaded not as a module in global space.
require("./domstubs.js").setStubs(global);
// Run `gulp dist-install` to generate 'pdfjs-dist' npm package files.
const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");
// Some PDFs need external cmaps.
const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
const CMAP_PACKED = true;
// Loading file from file system into typed array
const pdfPath =
process.argv[2] || "../../web/compressed.tracemonkey-pldi-09.pdf";
const data = new Uint8Array(fs.readFileSync(pdfPath));
const outputDirectory = "./svgdump";
try {
// Note: This creates a directory only one level deep. If you want to create
// multiple subdirectories on the fly, use the mkdirp module from npm.
fs.mkdirSync(outputDirectory);
} catch (e) {
if (e.code !== "EEXIST") {
throw e;
}
}
// Dumps svg outputs to a folder called svgdump
function getFilePathForPage(pageNum) {
const name = path.basename(pdfPath, path.extname(pdfPath));
return path.join(outputDirectory, `${name}-${pageNum}.svg`);
}
/**
* A readable stream which offers a stream representing the serialization of a
* given DOM element (as defined by domstubs.js).
*
* @param {object} options
* @param {DOMElement} options.svgElement The element to serialize
*/
function ReadableSVGStream(options) {
if (!(this instanceof ReadableSVGStream)) {
return new ReadableSVGStream(options);
}
stream.Readable.call(this, options);
this.serializer = options.svgElement.getSerializer();
}
util.inherits(ReadableSVGStream, stream.Readable);
// Implements https://nodejs.org/api/stream.html#stream_readable_read_size_1
ReadableSVGStream.prototype._read = function () {
let chunk;
while ((chunk = this.serializer.getNext()) !== null) {
if (!this.push(chunk)) {
return;
}
}
this.push(null);
};
// Streams the SVG element to the given file path.
function writeSvgToFile(svgElement, filePath) {
let readableSvgStream = new ReadableSVGStream({
svgElement,
});
const writableStream = fs.createWriteStream(filePath);
return new Promise(function (resolve, reject) {
readableSvgStream.once("error", reject);
writableStream.once("error", reject);
writableStream.once("finish", resolve);
readableSvgStream.pipe(writableStream);
}).catch(function (err) {
readableSvgStream = null; // Explicitly null because of v8 bug 6512.
writableStream.end();
throw err;
});
}
// Will be using async/await to load document, pages and misc data.
const loadingTask = pdfjsLib.getDocument({
data,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
fontExtraProperties: true,
});
(async function () {
const doc = await loadingTask.promise;
const numPages = doc.numPages;
console.log("# Document Loaded");
console.log(`Number of Pages: ${numPages}`);
console.log();
for (let pageNum = 1; pageNum <= numPages; pageNum++) {
try {
const page = await doc.getPage(pageNum);
console.log(`# Page ${pageNum}`);
const viewport = page.getViewport({ scale: 1.0 });
console.log(`Size: ${viewport.width}x${viewport.height}`);
console.log();
const opList = await page.getOperatorList();
const svgGfx = new pdfjsLib.SVGGraphics(
page.commonObjs,
page.objs,
/* forceDataSchema = */ true
);
svgGfx.embedFonts = true;
const svg = await svgGfx.getSVG(opList, viewport);
await writeSvgToFile(svg, getFilePathForPage(pageNum));
// Release page resources.
page.cleanup();
} catch (err) {
console.log(`Error: ${err}`);
}
}
console.log("# End of Document");
})();

View File

@ -1,8 +0,0 @@
## PDF.js using SVG
This is a project for implementing alternate backend for PDF.js using Scalable Vector Graphics. This is still a WIP.
Take a look at [proposal](https://docs.google.com/document/d/1k4nPx1RrHbxXi94kSdvW5ay8KMkjwLmBEiCNupyzlwk/pub) for this project.
## Getting started
Take a look at src/display/svg.js to see the SVG rendering code.

View File

@ -1,51 +0,0 @@
<!DOCTYPE html>
<!--
Copyright 2014 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html dir="ltr" mozdisallowselectionprint>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="google" content="notranslate">
<title>PDF.js SVG viewer using built components</title>
<style>
body {
background-color: #808080;
margin: 0;
padding: 0;
}
#viewerContainer {
overflow: auto;
position: absolute;
width: 100%;
height: 100%;
}
</style>
<link rel="stylesheet" href="../../node_modules/pdfjs-dist/web/pdf_viewer.css">
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script>
<script src="../../node_modules/pdfjs-dist/web/pdf_viewer.js"></script>
</head>
<body tabindex="1">
<div id="viewerContainer">
<div id="viewer" class="pdfViewer"></div>
</div>
<script src="viewer.js"></script>
</body>
</html>

View File

@ -3,8 +3,8 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Text-only PDF.js example</title> <title>Text-only PDF.js example</title>
<script src="../../node_modules/pdfjs-dist/build/pdf.js"></script> <script src="../../node_modules/pdfjs-dist/build/pdf.mjs" type="module"></script>
<script src="pdf2svg.js"></script> <script src="pdf2svg.mjs" type="module"></script>
</head> </head>
<body> <body>
<p>Text-only PDF.js example</p> <p>Text-only PDF.js example</p>

View File

@ -19,7 +19,7 @@ const PAGE_SCALE = 1.5;
const SVG_NS = "http://www.w3.org/2000/svg"; const SVG_NS = "http://www.w3.org/2000/svg";
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../node_modules/pdfjs-dist/build/pdf.worker.js"; "../../node_modules/pdfjs-dist/build/pdf.worker.mjs";
function buildSVG(viewport, textContent) { function buildSVG(viewport, textContent) {
// Building SVG with size of the viewport (for simplicity) // Building SVG with size of the viewport (for simplicity)
@ -43,7 +43,7 @@ function buildSVG(viewport, textContent) {
text.setAttribute("transform", "matrix(" + tx.join(" ") + ")"); text.setAttribute("transform", "matrix(" + tx.join(" ") + ")");
text.setAttribute("font-family", style.fontFamily); text.setAttribute("font-family", style.fontFamily);
text.textContent = textItem.str; text.textContent = textItem.str;
svg.appendChild(text); svg.append(text);
}); });
return svg; return svg;
} }
@ -57,7 +57,7 @@ async function pageLoaded() {
const textContent = await page.getTextContent(); const textContent = await page.getTextContent();
// building SVG and adding that to the DOM // building SVG and adding that to the DOM
const svg = buildSVG(viewport, textContent); const svg = buildSVG(viewport, textContent);
document.getElementById("pageContainer").appendChild(svg); document.getElementById("pageContainer").append(svg);
// Release page resources. // Release page resources.
page.cleanup(); page.cleanup();
} }

View File

@ -27,12 +27,7 @@ otherwise the build is not guaranteed to work correctly.
## Worker loading ## Worker loading
If you are getting the `Setting up fake worker` warning, make sure you are If you are getting the `Setting up fake worker` warning, make sure you are
importing `pdfjs-dist/webpack` which is the zero-configuration method for importing `pdfjs-dist/webpack.mjs` which is the zero-configuration method for
Webpack users. You will need to install Webpack users. Installing `worker-loader` is no longer necessary.
[worker-loader](https://github.com/webpack-contrib/worker-loader) (version 3.0.0 or higher is required), as a
dependency in your project in order to use `pdfjs-dist/webpack` (configuring
`worker-loader` is not necessary; just installing it is sufficient).
import * as pdfjsLib from 'pdfjs-dist/webpack'; import * as pdfjsLib from 'pdfjs-dist/webpack.mjs';
For a full working example refer to [this repository](https://github.com/yurydelendik/pdfjs-react).

View File

@ -1,35 +0,0 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
// Hello world example for webpack.
const pdfjsLib = require("pdfjs-dist");
const pdfPath = "../learning/helloworld.pdf";
// Setting worker path to worker bundle.
pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../build/webpack/pdf.worker.bundle.js";
// Loading a document.
const loadingTask = pdfjsLib.getDocument(pdfPath);
loadingTask.promise
.then(function (pdfDocument) {
// Request a first page
return pdfDocument.getPage(1).then(function (pdfPage) {
// Display page on the existing canvas with 100% scale.
const viewport = pdfPage.getViewport({ scale: 1.0 });
const canvas = document.getElementById("theCanvas");
canvas.width = viewport.width;
canvas.height = viewport.height;
const ctx = canvas.getContext("2d");
const renderTask = pdfPage.render({
canvasContext: ctx,
viewport,
});
return renderTask.promise;
});
})
.catch(function (reason) {
console.error("Error: " + reason);
});

29
examples/webpack/main.mjs Normal file
View File

@ -0,0 +1,29 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
// Hello world example for webpack.
import * as pdfjsLib from "pdfjs-dist";
const pdfPath = "../learning/helloworld.pdf";
// Setting worker path to worker bundle.
pdfjsLib.GlobalWorkerOptions.workerSrc =
"../../build/webpack/pdf.worker.bundle.js";
// Loading a document.
const loadingTask = pdfjsLib.getDocument(pdfPath);
const pdfDocument = await loadingTask.promise;
// Request a first page
const pdfPage = await pdfDocument.getPage(1);
// Display page on the existing canvas with 100% scale.
const viewport = pdfPage.getViewport({ scale: 1.0 });
const canvas = document.getElementById("theCanvas");
canvas.width = viewport.width;
canvas.height = viewport.height;
const ctx = canvas.getContext("2d");
const renderTask = pdfPage.render({
canvasContext: ctx,
viewport,
});
await renderTask.promise;

View File

@ -1,12 +1,12 @@
{ {
"name": "webpack-pdf.js-example", "name": "webpack-pdf.js-example",
"version": "0.1.0", "version": "0.2.0",
"scripts": { "scripts": {
"build": "webpack" "build": "webpack"
}, },
"devDependencies": { "devDependencies": {
"webpack": "^5.11.1", "webpack": "^5.89.0",
"webpack-cli": "^4.3.1", "webpack-cli": "^5.1.4",
"pdfjs-dist": "../../node_modules/pdfjs-dist" "pdfjs-dist": "../../node_modules/pdfjs-dist"
} }
} }

View File

@ -1,11 +1,13 @@
/* eslint-disable import/no-commonjs */
const webpack = require("webpack"); // eslint-disable-line no-unused-vars const webpack = require("webpack"); // eslint-disable-line no-unused-vars
const path = require("path"); const path = require("path");
module.exports = { module.exports = {
context: __dirname, context: __dirname,
entry: { entry: {
main: "./main.js", main: "./main.mjs",
"pdf.worker": "pdfjs-dist/build/pdf.worker.entry", "pdf.worker": "pdfjs-dist/build/pdf.worker.mjs",
}, },
mode: "none", mode: "none",
output: { output: {

View File

@ -22,11 +22,7 @@ function getViewerURL(pdf_url) {
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url); return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url);
} }
if (CSS.supports("animation", "0s")) {
document.addEventListener("animationstart", onAnimationStart, true); document.addEventListener("animationstart", onAnimationStart, true);
} else {
document.addEventListener("webkitAnimationStart", onAnimationStart, true);
}
function onAnimationStart(event) { function onAnimationStart(event) {
if (event.animationName === "pdfjs-detected-object-or-embed") { if (event.animationName === "pdfjs-detected-object-or-embed") {
@ -132,7 +128,11 @@ function updateEmbedElement(elem) {
} }
elem.type = "text/html"; elem.type = "text/html";
elem.src = getEmbeddedViewerURL(elem.src); elem.src = getEmbeddedViewerURL(elem.src);
if (parentNode) { if (parentNode) {
// Suppress linter warning: insertBefore is preferable to
// nextSibling.before(elem) because nextSibling may be null.
// eslint-disable-next-line unicorn/prefer-modern-dom-apis
parentNode.insertBefore(elem, nextSibling); parentNode.insertBefore(elem, nextSibling);
} }
} }
@ -160,7 +160,7 @@ function updateObjectElement(elem) {
if (!iframe || !iframe.__inserted_by_pdfjs) { if (!iframe || !iframe.__inserted_by_pdfjs) {
iframe = createFullSizeIframe(); iframe = createFullSizeIframe();
elem.textContent = ""; elem.textContent = "";
elem.appendChild(iframe); elem.append(iframe);
iframe.__inserted_by_pdfjs = true; iframe.__inserted_by_pdfjs = true;
} }
iframe.src = getEmbeddedViewerURL(elem.data); iframe.src = getEmbeddedViewerURL(elem.data);

View File

@ -1,11 +1,6 @@
/** /**
* Detect creation of <embed> and <object> tags. * Detect creation of <embed> and <object> tags.
*/ */
@-webkit-keyframes pdfjs-detected-object-or-embed {
from {
/* empty */
}
}
@keyframes pdfjs-detected-object-or-embed { @keyframes pdfjs-detected-object-or-embed {
from { from {
/* empty */ /* empty */
@ -13,9 +8,6 @@
} }
object, object,
embed { embed {
-webkit-animation-delay: 0s !important;
-webkit-animation-name: pdfjs-detected-object-or-embed !important;
-webkit-animation-play-state: running !important;
animation-delay: 0s !important; animation-delay: 0s !important;
animation-name: pdfjs-detected-object-or-embed !important; animation-name: pdfjs-detected-object-or-embed !important;
animation-play-state: running !important; animation-play-state: running !important;

View File

@ -47,7 +47,7 @@ limitations under the License.
} }
var scheme = url.slice(0, schemeIndex).toLowerCase(); var scheme = url.slice(0, schemeIndex).toLowerCase();
if (schemes.includes(scheme)) { if (schemes.includes(scheme)) {
url = url.split("#")[0]; url = url.split("#", 1)[0];
if (url.charAt(schemeIndex) === ":") { if (url.charAt(schemeIndex) === ":") {
url = encodeURIComponent(url); url = encodeURIComponent(url);
} }
@ -95,8 +95,8 @@ limitations under the License.
url: CRX_BASE_URL + "*:*", url: CRX_BASE_URL + "*:*",
}, },
function (tabsFromLastSession) { function (tabsFromLastSession) {
for (var i = 0; i < tabsFromLastSession.length; ++i) { for (const { id } of tabsFromLastSession) {
chrome.tabs.reload(tabsFromLastSession[i].id); chrome.tabs.reload(id);
} }
} }
); );

View File

@ -1,4 +1,5 @@
{ {
"minimum_chrome_version": "88",
"manifest_version": 2, "manifest_version": 2,
"name": "PDF Viewer", "name": "PDF Viewer",
"version": "PDFJSSCRIPT_VERSION", "version": "PDFJSSCRIPT_VERSION",
@ -10,32 +11,30 @@
}, },
"permissions": [ "permissions": [
"fileBrowserHandler", "fileBrowserHandler",
"webRequest", "webRequestBlocking", "webRequest",
"webRequestBlocking",
"<all_urls>", "<all_urls>",
"tabs", "tabs",
"webNavigation", "webNavigation",
"storage" "storage"
], ],
"content_scripts": [{ "content_scripts": [
"matches": [ {
"http://*/*", "matches": ["http://*/*", "https://*/*", "ftp://*/*", "file://*/*"],
"https://*/*",
"ftp://*/*",
"file://*/*"
],
"run_at": "document_start", "run_at": "document_start",
"all_frames": true, "all_frames": true,
"css": ["contentstyle.css"], "css": ["contentstyle.css"],
"js": ["contentscript.js"] "js": ["contentscript.js"]
}], }
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"file_browser_handlers": [{ "file_browser_handlers": [
{
"id": "open-as-pdf", "id": "open-as-pdf",
"default_title": "Open with PDF Viewer", "default_title": "Open with PDF Viewer",
"file_filters": [ "file_filters": ["filesystem:*.pdf"]
"filesystem:*.pdf" }
] ],
}],
"storage": { "storage": {
"managed_schema": "preferences_schema.json" "managed_schema": "preferences_schema.json"
}, },

View File

@ -109,17 +109,10 @@ limitations under the License.
} }
// Migration code for https://github.com/mozilla/pdf.js/pull/9479. // Migration code for https://github.com/mozilla/pdf.js/pull/9479.
if (typeof items.disableTextLayer === "boolean") { if (typeof items.disableTextLayer === "boolean") {
var textLayerMode = 1;
if (items.disableTextLayer) { if (items.disableTextLayer) {
textLayerMode = 0;
} else if (items.enhanceTextSelection) {
textLayerMode = 2;
}
if (textLayerMode !== 1) {
// Overwrite if computed textLayerMode is not the default value (1).
storageSync.set( storageSync.set(
{ {
textLayerMode, textLayerMode: 0,
}, },
function () { function () {
if (!chrome.runtime.lastError) { if (!chrome.runtime.lastError) {

View File

@ -126,7 +126,6 @@ body {
<select> <select>
<option value="0">Disable text selection</option> <option value="0">Disable text selection</option>
<option value="1">Enable text selection</option> <option value="1">Enable text selection</option>
<option value="2">Enable enhanced mode (experimental)</option>
</select> </select>
</label> </label>
</div> </div>

View File

@ -155,7 +155,7 @@ function renderBooleanPref(shortDescription, description, prefName) {
storageArea.set(pref); storageArea.set(pref);
}; };
wrapper.querySelector("span").textContent = shortDescription; wrapper.querySelector("span").textContent = shortDescription;
document.getElementById("settings-boxes").appendChild(wrapper); document.getElementById("settings-boxes").append(wrapper);
function renderPreference(value) { function renderPreference(value) {
checkbox.checked = value; checkbox.checked = value;
@ -172,7 +172,7 @@ function renderEnumPref(shortDescription, prefName) {
storageArea.set(pref); storageArea.set(pref);
}; };
wrapper.querySelector("span").textContent = shortDescription; wrapper.querySelector("span").textContent = shortDescription;
document.getElementById("settings-boxes").appendChild(wrapper); document.getElementById("settings-boxes").append(wrapper);
function renderPreference(value) { function renderPreference(value) {
select.value = value; select.value = value;
@ -189,7 +189,7 @@ function renderDefaultZoomValue(shortDescription) {
}); });
}; };
wrapper.querySelector("span").textContent = shortDescription; wrapper.querySelector("span").textContent = shortDescription;
document.getElementById("settings-boxes").appendChild(wrapper); document.getElementById("settings-boxes").append(wrapper);
function renderPreference(value) { function renderPreference(value) {
value = value || "auto"; value = value || "auto";

View File

@ -20,7 +20,15 @@ limitations under the License.
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html"); var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");
function getViewerURL(pdf_url) { function getViewerURL(pdf_url) {
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url); // |pdf_url| may contain a fragment such as "#page=2". That should be passed
// as a fragment to the viewer, not encoded in pdf_url.
var hash = "";
var i = pdf_url.indexOf("#");
if (i > 0) {
hash = pdf_url.slice(i);
pdf_url = pdf_url.slice(0, i);
}
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url) + hash;
} }
/** /**
@ -54,8 +62,7 @@ function isPdfDownloadable(details) {
* @returns {undefined|{name: string, value: string}} The header, if found. * @returns {undefined|{name: string, value: string}} The header, if found.
*/ */
function getHeaderFromHeaders(headers, headerName) { function getHeaderFromHeaders(headers, headerName) {
for (var i = 0; i < headers.length; ++i) { for (const header of headers) {
var header = headers[i];
if (header.name.toLowerCase() === headerName) { if (header.name.toLowerCase() === headerName) {
return header; return header;
} }
@ -155,19 +162,7 @@ chrome.webRequest.onBeforeRequest.addListener(
return { redirectUrl: viewerUrl }; return { redirectUrl: viewerUrl };
}, },
{ {
urls: [ urls: ["file://*/*.pdf", "file://*/*.PDF"],
"file://*/*.pdf",
"file://*/*.PDF",
...// Duck-typing: MediaError.prototype.message was added in Chrome 59.
(MediaError.prototype.hasOwnProperty("message")
? []
: [
// Note: Chrome 59 has disabled ftp resource loading by default:
// https://www.chromestatus.com/feature/5709390967472128
"ftp://*/*.pdf",
"ftp://*/*.PDF",
]),
],
types: ["main_frame", "sub_frame"], types: ["main_frame", "sub_frame"],
}, },
["blocking"] ["blocking"]
@ -253,10 +248,3 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
} }
return undefined; return undefined;
}); });
// Remove keys from storage that were once part of the deleted feature-detect.js
chrome.storage.local.remove([
"featureDetectLastUA",
"webRequestRedirectUrl",
"extensionSupportsFTP",
]);

View File

@ -5,11 +5,7 @@
"title": "Theme", "title": "Theme",
"description": "The theme to use.\n0 = Use system theme.\n1 = Light theme.\n2 = Dark theme.", "description": "The theme to use.\n0 = Use system theme.\n1 = Light theme.\n2 = Dark theme.",
"type": "integer", "type": "integer",
"enum": [ "enum": [0, 1, 2],
0,
1,
2
],
"default": 2 "default": 2
}, },
"showPreviousViewOnLoad": { "showPreviousViewOnLoad": {
@ -21,13 +17,15 @@
"title": "View position on load", "title": "View position on load",
"description": "The position in the document upon load.\n -1 = Default (uses OpenAction if available, otherwise equal to `viewOnLoad = 0`).\n 0 = The last viewed page/position.\n 1 = The initial page/position.", "description": "The position in the document upon load.\n -1 = Default (uses OpenAction if available, otherwise equal to `viewOnLoad = 0`).\n 0 = The last viewed page/position.\n 1 = The initial page/position.",
"type": "integer", "type": "integer",
"enum": [ "enum": [-1, 0, 1],
-1,
0,
1
],
"default": 0 "default": 0
}, },
"defaultZoomDelay": {
"title": "Default zoom delay",
"description": "Delay (in ms) to wait before redrawing the canvas.",
"type": "integer",
"default": 400
},
"defaultZoomValue": { "defaultZoomValue": {
"title": "Default zoom level", "title": "Default zoom level",
"description": "Default zoom level of the viewer. Accepted values: 'auto', 'page-actual', 'page-width', 'page-height', 'page-fit', or a zoom level in percents.", "description": "Default zoom level of the viewer. Accepted values: 'auto', 'page-actual', 'page-width', 'page-height', 'page-fit', or a zoom level in percents.",
@ -39,13 +37,7 @@
"title": "Sidebar state on load", "title": "Sidebar state on load",
"description": "Controls the state of the sidebar upon load.\n -1 = Default (uses PageMode if available, otherwise the last position if available/enabled).\n 0 = Do not show sidebar.\n 1 = Show thumbnails in sidebar.\n 2 = Show document outline in sidebar.\n 3 = Show attachments in sidebar.", "description": "Controls the state of the sidebar upon load.\n -1 = Default (uses PageMode if available, otherwise the last position if available/enabled).\n 0 = Do not show sidebar.\n 1 = Show thumbnails in sidebar.\n 2 = Show document outline in sidebar.\n 3 = Show attachments in sidebar.",
"type": "integer", "type": "integer",
"enum": [ "enum": [-1, 0, 1, 2, 3],
-1,
0,
1,
2,
3
],
"default": -1 "default": -1
}, },
"enableHandToolOnLoad": { "enableHandToolOnLoad": {
@ -53,14 +45,15 @@
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"enableML": {
"type": "boolean",
"default": false
},
"cursorToolOnLoad": { "cursorToolOnLoad": {
"title": "Cursor tool on load", "title": "Cursor tool on load",
"description": "The cursor tool that is enabled upon load.\n 0 = Text selection tool.\n 1 = Hand tool.", "description": "The cursor tool that is enabled upon load.\n 0 = Text selection tool.\n 1 = Hand tool.",
"type": "integer", "type": "integer",
"enum": [ "enum": [0, 1],
0,
1
],
"default": 0 "default": 0
}, },
"pdfBugEnabled": { "pdfBugEnabled": {
@ -75,6 +68,22 @@
"description": "Whether to allow execution of active content (JavaScript) by PDF files.", "description": "Whether to allow execution of active content (JavaScript) by PDF files.",
"default": false "default": false
}, },
"enableHighlightEditor": {
"type": "boolean",
"default": false
},
"enableHighlightFloatingButton": {
"type": "boolean",
"default": false
},
"highlightEditorColors": {
"type": "string",
"default": "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F"
},
"enableStampEditor": {
"type": "boolean",
"default": true
},
"disableRange": { "disableRange": {
"title": "Disable range requests", "title": "Disable range requests",
"description": "Whether to disable range requests (not recommended).", "description": "Whether to disable range requests (not recommended).",
@ -102,37 +111,18 @@
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"enhanceTextSelection": {
"description": "DEPRECATED. Set textLayerMode to 2 to use the enhanced text selection layer by default.",
"type": "boolean",
"default": false
},
"textLayerMode": { "textLayerMode": {
"title": "Text layer mode", "title": "Text layer mode",
"description": "Controls if the text layer is enabled, and the selection mode that is used.\n 0 = Disabled.\n 1 = Enabled.\n 2 = (Experimental) Enabled, with enhanced text selection.", "description": "Controls if the text layer is enabled, and the selection mode that is used.\n 0 = Disabled.\n 1 = Enabled.",
"type": "integer", "type": "integer",
"enum": [ "enum": [0, 1],
0,
1,
2
],
"default": 1 "default": 1
}, },
"useOnlyCssZoom": {
"type": "boolean",
"default": false
},
"externalLinkTarget": { "externalLinkTarget": {
"title": "External links target window", "title": "External links target window",
"description": "Controls how external links will be opened.\n 0 = default.\n 1 = replaces current window.\n 2 = new window/tab.\n 3 = parent.\n 4 = in top window.", "description": "Controls how external links will be opened.\n 0 = default.\n 1 = replaces current window.\n 2 = new window/tab.\n 3 = parent.\n 4 = in top window.",
"type": "integer", "type": "integer",
"enum": [ "enum": [0, 1, 2, 3, 4],
0,
1,
2,
3,
4
],
"default": 0 "default": 0
}, },
"disablePageLabels": { "disablePageLabels": {
@ -152,14 +142,14 @@
}, },
"annotationMode": { "annotationMode": {
"type": "integer", "type": "integer",
"enum": [ "enum": [0, 1, 2, 3],
0,
1,
2,
3
],
"default": 2 "default": 2
}, },
"annotationEditorMode": {
"type": "integer",
"enum": [-1, 0, 3, 15],
"default": 0
},
"enablePermissions": { "enablePermissions": {
"type": "boolean", "type": "boolean",
"default": false "default": false
@ -188,26 +178,30 @@
"title": "Scroll mode on load", "title": "Scroll mode on load",
"description": "Controls how the viewer scrolls upon load.\n -1 = Default (uses the last position if available/enabled).\n 3 = Page scrolling.\n 0 = Vertical scrolling.\n 1 = Horizontal scrolling.\n 2 = Wrapped scrolling.", "description": "Controls how the viewer scrolls upon load.\n -1 = Default (uses the last position if available/enabled).\n 3 = Page scrolling.\n 0 = Vertical scrolling.\n 1 = Horizontal scrolling.\n 2 = Wrapped scrolling.",
"type": "integer", "type": "integer",
"enum": [ "enum": [-1, 0, 1, 2, 3],
-1,
0,
1,
2,
3
],
"default": -1 "default": -1
}, },
"spreadModeOnLoad": { "spreadModeOnLoad": {
"title": "Spread mode on load", "title": "Spread mode on load",
"description": "Whether the viewer should join pages into spreads upon load.\n -1 = Default (uses the last position if available/enabled).\n 0 = No spreads.\n 1 = Odd spreads.\n 2 = Even spreads.", "description": "Whether the viewer should join pages into spreads upon load.\n -1 = Default (uses the last position if available/enabled).\n 0 = No spreads.\n 1 = Odd spreads.\n 2 = Even spreads.",
"type": "integer", "type": "integer",
"enum": [ "enum": [-1, 0, 1, 2],
-1,
0,
1,
2
],
"default": -1 "default": -1
},
"forcePageColors": {
"description": "When enabled, the pdf rendering will use the high contrast mode colors",
"type": "boolean",
"default": false
},
"pageColorsBackground": {
"description": "The color is a string as defined in CSS. Its goal is to help improve readability in high contrast mode",
"type": "string",
"default": "Canvas"
},
"pageColorsForeground": {
"description": "The color is a string as defined in CSS. Its goal is to help improve readability in high contrast mode",
"type": "string",
"default": "CanvasText"
} }
} }
} }

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* import-globals-from pdfHandler.js */ /* import-globals-from pdfHandler.js */
/* exported saveReferer */
"use strict"; "use strict";
/** /**
@ -41,30 +42,18 @@ var g_requestHeaders = {};
// g_referrers[tabId][frameId] = referrer of PDF frame. // g_referrers[tabId][frameId] = referrer of PDF frame.
var g_referrers = {}; var g_referrers = {};
var extraInfoSpecWithHeaders; // = ['requestHeaders', 'extraHeaders']
(function () { (function () {
var requestFilter = { var requestFilter = {
urls: ["*://*/*"], urls: ["*://*/*"],
types: ["main_frame", "sub_frame"], types: ["main_frame", "sub_frame"],
}; };
function registerListener(extraInfoSpec) {
extraInfoSpecWithHeaders = extraInfoSpec;
// May throw if the given extraInfoSpec is unsupported.
chrome.webRequest.onSendHeaders.addListener( chrome.webRequest.onSendHeaders.addListener(
function (details) { function (details) {
g_requestHeaders[details.requestId] = details.requestHeaders; g_requestHeaders[details.requestId] = details.requestHeaders;
}, },
requestFilter, requestFilter,
extraInfoSpec ["requestHeaders", "extraHeaders"]
); );
}
try {
registerListener(["requestHeaders", "extraHeaders"]);
} catch (e) {
// "extraHeaders" is not supported in Chrome 71 and earlier.
registerListener(["requestHeaders"]);
}
chrome.webRequest.onBeforeRedirect.addListener(forgetHeaders, requestFilter); chrome.webRequest.onBeforeRedirect.addListener(forgetHeaders, requestFilter);
chrome.webRequest.onCompleted.addListener(forgetHeaders, requestFilter); chrome.webRequest.onCompleted.addListener(forgetHeaders, requestFilter);
chrome.webRequest.onErrorOccurred.addListener(forgetHeaders, requestFilter); chrome.webRequest.onErrorOccurred.addListener(forgetHeaders, requestFilter);
@ -125,7 +114,7 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
types: ["xmlhttprequest"], types: ["xmlhttprequest"],
tabId, tabId,
}, },
["blocking", ...extraInfoSpecWithHeaders] ["blocking", "requestHeaders", "extraHeaders"]
); );
} }
// Acknowledge the message, and include the latest referer for this frame. // Acknowledge the message, and include the latest referer for this frame.

View File

@ -70,12 +70,6 @@ limitations under the License.
var deduplication_id = getDeduplicationId(wasUpdated); var deduplication_id = getDeduplicationId(wasUpdated);
var extension_version = chrome.runtime.getManifest().version; var extension_version = chrome.runtime.getManifest().version;
if (window.Request && "mode" in Request.prototype) {
// fetch is supported in extensions since Chrome 42 (though the above
// feature-detection method detects Chrome 43+).
// Unlike XMLHttpRequest, fetch omits credentials such as cookies in the
// requests, which guarantees that the server cannot track the client
// via HTTP cookies.
fetch(LOG_URL, { fetch(LOG_URL, {
method: "POST", method: "POST",
headers: new Headers({ headers: new Headers({
@ -85,14 +79,11 @@ limitations under the License.
// Set mode=cors so that the above custom headers are included in the // Set mode=cors so that the above custom headers are included in the
// request. // request.
mode: "cors", mode: "cors",
// Omits credentials such as cookies in the requests, which guarantees
// that the server cannot track the client via HTTP cookies.
credentials: "omit",
cache: "no-store",
}); });
return;
}
var x = new XMLHttpRequest();
x.open("POST", LOG_URL);
x.setRequestHeader("Deduplication-Id", deduplication_id);
x.setRequestHeader("Extension-Version", extension_version);
x.send();
}); });
} }
@ -110,8 +101,7 @@ limitations under the License.
id = ""; id = "";
var buf = new Uint8Array(5); var buf = new Uint8Array(5);
crypto.getRandomValues(buf); crypto.getRandomValues(buf);
for (var i = 0; i < buf.length; ++i) { for (const c of buf) {
var c = buf[i];
id += (c >>> 4).toString(16) + (c & 0xf).toString(16); id += (c >>> 4).toString(16) + (c & 0xf).toString(16);
} }
localStorage.telemetryDeduplicationId = id; localStorage.telemetryDeduplicationId = id;

View File

@ -6,18 +6,11 @@
"plugin:mozilla/recommended", "plugin:mozilla/recommended",
], ],
"parserOptions": {
"sourceType": "script",
},
"plugins": [ "plugins": [
"mozilla" "mozilla"
], ],
"rules": { "rules": {
// Items different from the mozilla/recommended configuration.
"no-var": "off",
// Other rules mozilla/recommended hasn't enabled yet. // Other rules mozilla/recommended hasn't enabled yet.
"no-shadow": "error", "no-shadow": "error",
"arrow-body-style": ["error", "as-needed"], "arrow-body-style": ["error", "as-needed"],

View File

@ -1,5 +0,0 @@
This is the PDF.js project output, https://github.com/mozilla/pdf.js
Current extension version is: PDFJSSCRIPT_VERSION
Taken from upstream commit: PDFJSSCRIPT_COMMIT

View File

@ -13,10 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
"use strict"; export const PdfJsDefaultPreferences = Object.freeze(
var EXPORTED_SYMBOLS = ["PdfJsDefaultPreferences"];
var PdfJsDefaultPreferences = Object.freeze(
PDFJSDev.eval("DEFAULT_PREFERENCES") PDFJSDev.eval("DEFAULT_PREFERENCES")
); );

View File

@ -1,131 +0,0 @@
"use strict";
// Small subset of the webL10n API by Fabien Cazenave for PDF.js extension.
(function (window) {
var gLanguage = "";
var gExternalLocalizerServices = null;
var gReadyState = "loading";
// fetch an l10n objects
function getL10nData(key) {
var response = gExternalLocalizerServices.getStrings(key);
var data = JSON.parse(response);
if (!data) {
console.warn("[l10n] #" + key + " missing for [" + gLanguage + "]");
}
return data;
}
// replace {{arguments}} with their values
function substArguments(text, args) {
if (!args) {
return text;
}
return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function (all, name) {
return name in args ? args[name] : "{{" + name + "}}";
});
}
// translate a string
function translateString(key, args, fallback) {
var i = key.lastIndexOf(".");
var name, property;
if (i >= 0) {
name = key.substring(0, i);
property = key.substring(i + 1);
} else {
name = key;
property = "textContent";
}
var data = getL10nData(name);
var value = (data && data[property]) || fallback;
if (!value) {
return "{{" + key + "}}";
}
return substArguments(value, args);
}
// translate an HTML element
function translateElement(element) {
if (!element || !element.dataset) {
return;
}
// get the related l10n object
var key = element.dataset.l10nId;
var data = getL10nData(key);
if (!data) {
return;
}
// get arguments (if any)
// TODO: more flexible parser?
var args;
if (element.dataset.l10nArgs) {
try {
args = JSON.parse(element.dataset.l10nArgs);
} catch (e) {
console.warn("[l10n] could not parse arguments for #" + key + "");
}
}
// translate element
// TODO: security check?
for (var k in data) {
element[k] = substArguments(data[k], args);
}
}
// translate an HTML subtree
function translateFragment(element) {
element = element || document.querySelector("html");
// check all translatable children (= w/ a `data-l10n-id' attribute)
var children = element.querySelectorAll("*[data-l10n-id]");
var elementCount = children.length;
for (var i = 0; i < elementCount; i++) {
translateElement(children[i]);
}
// translate element itself if necessary
if (element.dataset.l10nId) {
translateElement(element);
}
}
// Public API
document.mozL10n = {
// get a localized string
get: translateString,
// get the document language
getLanguage() {
return gLanguage;
},
// get the direction (ltr|rtl) of the current language
getDirection() {
// http://www.w3.org/International/questions/qa-scripts
// Arabic, Hebrew, Farsi, Pashto, Urdu
var rtlList = ["ar", "he", "fa", "ps", "ur"];
// use the short language code for "full" codes like 'ar-sa' (issue 5440)
var shortCode = gLanguage.split("-")[0];
return rtlList.includes(shortCode) ? "rtl" : "ltr";
},
getReadyState() {
return gReadyState;
},
setExternalLocalizerServices(externalLocalizerServices) {
gExternalLocalizerServices = externalLocalizerServices;
gLanguage = gExternalLocalizerServices.getLocale();
gReadyState = "complete";
},
// translate an element or document fragment
translate: translateFragment,
};
})(this);

View File

@ -0,0 +1,253 @@
import { types as t, transformSync } from "@babel/core";
import fs from "fs";
import { join as joinPaths } from "path";
import vm from "vm";
const PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
const ROOT_PREFIX = "$ROOT/";
function isPDFJSPreprocessor(obj) {
return obj.type === "Identifier" && obj.name === PDFJS_PREPROCESSOR_NAME;
}
function evalWithDefines(code, defines) {
if (!code || !code.trim()) {
throw new Error("No JavaScript expression given");
}
return vm.runInNewContext(code, defines, { displayErrors: false });
}
function handlePreprocessorAction(ctx, actionName, args, path) {
try {
const arg = args[0];
switch (actionName) {
case "test":
if (!t.isStringLiteral(arg)) {
throw new Error("No code for testing is given");
}
return !!evalWithDefines(arg.value, ctx.defines);
case "eval":
if (!t.isStringLiteral(arg)) {
throw new Error("No code for eval is given");
}
const result = evalWithDefines(arg.value, ctx.defines);
if (
typeof result === "boolean" ||
typeof result === "string" ||
typeof result === "number" ||
typeof result === "object"
) {
return result;
}
break;
case "json":
if (!t.isStringLiteral(arg)) {
throw new Error("Path to JSON is not provided");
}
let jsonPath = arg.value;
if (jsonPath.startsWith(ROOT_PREFIX)) {
jsonPath = joinPaths(
ctx.rootPath,
jsonPath.substring(ROOT_PREFIX.length)
);
}
return JSON.parse(fs.readFileSync(jsonPath, "utf8"));
}
throw new Error("Unsupported action");
} catch (e) {
throw path.buildCodeFrameError(
"Could not process " +
PDFJS_PREPROCESSOR_NAME +
"." +
actionName +
": " +
e.message
);
}
}
function babelPluginPDFJSPreprocessor(babel, ctx) {
return {
name: "babel-plugin-pdfjs-preprocessor",
manipulateOptions({ parserOpts }) {
parserOpts.attachComment = false;
},
visitor: {
"ExportNamedDeclaration|ImportDeclaration": ({ node }) => {
if (node.source && ctx.map?.[node.source.value]) {
node.source.value = ctx.map[node.source.value];
}
},
"IfStatement|ConditionalExpression": {
exit(path) {
const { node } = path;
if (t.isBooleanLiteral(node.test)) {
// if (true) stmt1; => stmt1
// if (false) stmt1; else stmt2; => stmt2
if (node.test.value === true) {
path.replaceWith(node.consequent);
} else if (node.alternate) {
path.replaceWith(node.alternate);
} else {
path.remove(node);
}
}
},
},
UnaryExpression: {
exit(path) {
const { node } = path;
if (
node.operator === "typeof" &&
isPDFJSPreprocessor(node.argument)
) {
// typeof PDFJSDev => 'object'
path.replaceWith(t.stringLiteral("object"));
return;
}
if (node.operator === "!" && t.isBooleanLiteral(node.argument)) {
// !true => false, !false => true
path.replaceWith(t.booleanLiteral(!node.argument.value));
}
},
},
LogicalExpression: {
exit(path) {
const { node } = path;
if (!t.isBooleanLiteral(node.left)) {
return;
}
switch (node.operator) {
case "&&":
// true && expr => expr
// false && expr => false
path.replaceWith(
node.left.value === true ? node.right : node.left
);
break;
case "||":
// true || expr => true
// false || expr => expr
path.replaceWith(
node.left.value === true ? node.left : node.right
);
break;
}
},
},
BinaryExpression: {
exit(path) {
const { node } = path;
switch (node.operator) {
case "==":
case "===":
case "!=":
case "!==":
if (t.isLiteral(node.left) && t.isLiteral(node.right)) {
// folding == and != check that can be statically evaluated
const { confident, value } = path.evaluate();
if (confident) {
path.replaceWith(t.booleanLiteral(value));
}
}
}
},
},
CallExpression(path) {
const { node } = path;
if (
t.isMemberExpression(node.callee) &&
isPDFJSPreprocessor(node.callee.object) &&
t.isIdentifier(node.callee.property) &&
!node.callee.computed
) {
// PDFJSDev.xxxx(arg1, arg2, ...) => transform
const action = node.callee.property.name;
const result = handlePreprocessorAction(
ctx,
action,
node.arguments,
path
);
path.replaceWith(t.inherits(t.valueToNode(result), path.node));
}
if (t.isIdentifier(node.callee, { name: "__non_webpack_import__" })) {
if (node.arguments.length !== 1) {
throw new Error("Invalid `__non_webpack_import__` usage.");
}
// Replace it with a standard `import`-call and
// ensure that Webpack will leave it alone.
const source = node.arguments[0];
source.leadingComments = [
{
type: "CommentBlock",
value: "webpackIgnore: true",
},
];
path.replaceWith(t.importExpression(source));
}
},
BlockStatement: {
// Visit node in post-order so that recursive flattening
// of blocks works correctly.
exit(path) {
const { node } = path;
let subExpressionIndex = 0;
while (subExpressionIndex < node.body.length) {
switch (node.body[subExpressionIndex].type) {
case "EmptyStatement":
// Removing empty statements from the blocks.
node.body.splice(subExpressionIndex, 1);
continue;
case "BlockStatement":
// Block statements inside a block are flattened
// into the parent one.
const subChildren = node.body[subExpressionIndex].body;
node.body.splice(subExpressionIndex, 1, ...subChildren);
subExpressionIndex += Math.max(subChildren.length - 1, 0);
continue;
case "ReturnStatement":
case "ThrowStatement":
// Removing dead code after return or throw.
node.body.splice(
subExpressionIndex + 1,
node.body.length - subExpressionIndex - 1
);
break;
}
subExpressionIndex++;
}
},
},
Function: {
exit(path) {
if (!t.isBlockStatement(path.node.body)) {
// Arrow function with expression body
return;
}
const { body } = path.node.body;
if (
body.length > 0 &&
t.isReturnStatement(body.at(-1), { argument: null })
) {
// Function body ends with return without arg -- removing it.
body.pop();
}
},
},
},
};
}
function preprocessPDFJSCode(ctx, content) {
return transformSync(content, {
configFile: false,
plugins: [[babelPluginPDFJSPreprocessor, ctx]],
}).code;
}
export { babelPluginPDFJSPreprocessor, preprocessPDFJSCode };

View File

@ -1,8 +1,8 @@
"use strict"; import fs from "fs";
import path from "path";
import vm from "vm";
const fs = require("fs"), const AllWhitespaceRegexp = /^\s+$/g;
path = require("path"),
vm = require("vm");
/** /**
* A simple preprocessor that is based on the Firefox preprocessor * A simple preprocessor that is based on the Firefox preprocessor
@ -38,10 +38,32 @@ function preprocess(inFilename, outFilename, defines) {
return fs.realpathSync(inFilename) + ":" + lineNumber; return fs.realpathSync(inFilename) + ":" + lineNumber;
} }
function expandCssImports(content, baseUrl) {
return content.replaceAll(
/^\s*@import\s+url\(([^)]+)\);\s*$/gm,
function (all, url) {
if (defines.GECKOVIEW) {
switch (url) {
case "annotation_editor_layer_builder.css":
return "";
}
}
const file = path.join(path.dirname(baseUrl), url);
const imported = fs.readFileSync(file, "utf8").toString();
return expandCssImports(imported, file);
}
);
}
// TODO make this really read line by line. // TODO make this really read line by line.
const lines = fs.readFileSync(inFilename).toString().split("\n"); let content = fs.readFileSync(inFilename, "utf8").toString();
const totalLines = lines.length; // Handle CSS-imports first, when necessary.
let out = ""; if (/\.css$/i.test(inFilename)) {
content = expandCssImports(content, inFilename);
}
const lines = content.split("\n"),
totalLines = lines.length;
const out = [];
let i = 0; let i = 0;
function readLine() { function readLine() {
if (i < totalLines) { if (i < totalLines) {
@ -53,7 +75,13 @@ function preprocess(inFilename, outFilename, defines) {
typeof outFilename === "function" typeof outFilename === "function"
? outFilename ? outFilename
: function (line) { : function (line) {
out += line + "\n"; if (!line || AllWhitespaceRegexp.test(line)) {
const prevLine = out.at(-1);
if (!prevLine || AllWhitespaceRegexp.test(prevLine)) {
return; // Avoid adding consecutive blank lines.
}
}
out.push(line);
}; };
function evaluateCondition(code) { function evaluateCondition(code) {
if (!code || !code.trim()) { if (!code || !code.trim()) {
@ -97,7 +125,7 @@ function preprocess(inFilename, outFilename, defines) {
} }
} }
function expand(line) { function expand(line) {
line = line.replace(/__[\w]+__/g, function (variable) { line = line.replaceAll(/__[\w]+__/g, function (variable) {
variable = variable.substring(2, variable.length - 2); variable = variable.substring(2, variable.length - 2);
if (variable in defines) { if (variable in defines) {
return defines[variable]; return defines[variable];
@ -123,7 +151,7 @@ function preprocess(inFilename, outFilename, defines) {
let state = STATE_NONE; let state = STATE_NONE;
const stack = []; const stack = [];
const control = const control =
/^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/; /^(?:\/\/|\s*\/\*|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:\*\/|-->)?$)?/;
while ((line = readLine()) !== null) { while ((line = readLine()) !== null) {
++lineNumber; ++lineNumber;
@ -176,16 +204,19 @@ function preprocess(inFilename, outFilename, defines) {
} }
break; break;
} }
} else { } else if (state === STATE_NONE) {
if (state === STATE_NONE) {
writeLine(line); writeLine(line);
} else if ( } else if (
(state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) && (state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) &&
!stack.includes(STATE_IF_FALSE) && !stack.includes(STATE_IF_FALSE) &&
!stack.includes(STATE_ELSE_FALSE) !stack.includes(STATE_ELSE_FALSE)
) { ) {
writeLine(line.replace(/^\/\/|^<!--/g, " ").replace(/-->$/g, "")); writeLine(
} line
.replaceAll(/^\/\/|^<!--/g, " ")
.replaceAll(/(^\s*)\/\*/g, "$1 ")
.replaceAll(/\*\/$|-->$/g, "")
);
} }
} }
if (state !== STATE_NONE || stack.length !== 0) { if (state !== STATE_NONE || stack.length !== 0) {
@ -194,99 +225,8 @@ function preprocess(inFilename, outFilename, defines) {
); );
} }
if (typeof outFilename !== "function") { if (typeof outFilename !== "function") {
fs.writeFileSync(outFilename, out); fs.writeFileSync(outFilename, out.join("\n"));
} }
} }
exports.preprocess = preprocess;
function preprocessCSS(mode, source, destination) {
function hasPrefixedMozcentral(line) {
return /(^|\W)-(ms|o|webkit)-\w/.test(line);
}
function expandImports(content, baseUrl) { export { preprocess };
return content.replace(
/^\s*@import\s+url\(([^)]+)\);\s*$/gm,
function (all, url) {
const file = path.join(path.dirname(baseUrl), url);
const imported = fs.readFileSync(file, "utf8").toString();
return expandImports(imported, file);
}
);
}
function removePrefixed(content, hasPrefixedFilter) {
const lines = content.split(/\r?\n/g);
let i = 0;
while (i < lines.length) {
const line = lines[i];
if (!hasPrefixedFilter(line)) {
i++;
continue;
}
if (/\{\s*$/.test(line)) {
let bracketLevel = 1;
let j = i + 1;
while (j < lines.length && bracketLevel > 0) {
const checkBracket = /([{}])\s*$/.exec(lines[j]);
if (checkBracket) {
if (checkBracket[1] === "{") {
bracketLevel++;
} else if (!lines[j].includes("{")) {
bracketLevel--;
}
}
j++;
}
lines.splice(i, j - i);
} else if (/[};]\s*$/.test(line)) {
lines.splice(i, 1);
} else {
// multiline? skipping until next directive or bracket
do {
lines.splice(i, 1);
} while (
i < lines.length &&
!/\}\s*$/.test(lines[i]) &&
!lines[i].includes(":")
);
if (i < lines.length && /\S\s*}\s*$/.test(lines[i])) {
lines[i] = lines[i].substring(lines[i].indexOf("}"));
}
}
// collapse whitespaces
while (lines[i] === "" && lines[i - 1] === "") {
lines.splice(i, 1);
}
}
return lines.join("\n");
}
if (!mode) {
throw new Error("Invalid CSS preprocessor mode");
}
let content = fs.readFileSync(source, "utf8").toString();
content = expandImports(content, source);
if (mode === "mozcentral") {
content = removePrefixed(content, hasPrefixedMozcentral);
}
fs.writeFileSync(destination, content);
}
exports.preprocessCSS = preprocessCSS;
/**
* Merge two defines arrays. Values in the second param will override values in
* the first.
*/
function merge(defaults, defines) {
const ret = Object.create(null);
for (const key in defaults) {
ret[key] = defaults[key];
}
for (const key in defines) {
ret[key] = defines[key];
}
return ret;
}
exports.merge = merge;

View File

@ -0,0 +1,5 @@
/* Comment here... */
div {
margin: 0;
padding: 0;
}

View File

@ -0,0 +1,7 @@
/* Comment here... */
/*#if TRUE*/
/*div {*/
/* margin: 0;*/
/*padding: 0;*/
/*}*/
/*#endif*/

View File

@ -0,0 +1,3 @@
div {
margin: 0;
}

14
external/builder/fixtures/if-nested.css vendored Normal file
View File

@ -0,0 +1,14 @@
/*#if TRUE*/
div {
margin: 0;
/*#if FALSE*/
padding: 0;
/*#endif*/
}
/*#endif*/
/*#if FALSE*/
p {
margin: 0;
}
/*#endif*/

View File

@ -10,6 +10,6 @@ var i = true;
var j = false; var j = false;
var k = false; var k = false;
var l = true; var l = true;
var m = '1' === true; var m = false;
var n = false; var n = false;
var o = true; var o = true;

View File

@ -1,5 +1,4 @@
function f1() { function f1() {}
}
function f2() { function f2() {
return 1; return 1;
} }
@ -10,4 +9,13 @@ function f3() {
function f4() { function f4() {
var i = 0; var i = 0;
} }
var obj = {
method1() {},
method2() {}
};
class C {
method1() {}
method2() {}
}
var arrow1 = () => {};
var arrow2 = () => {};

View File

@ -23,3 +23,15 @@ function f4() {
var j = 0; var j = 0;
} }
var obj = {
method1() { return; var i = 0; },
method2() { return; },
};
class C {
method1() { return; var i = 0; }
method2() { return; }
}
var arrow1 = () => { return; var i = 0; };
var arrow2 = () => { return; };

View File

@ -3,11 +3,19 @@ var b = true;
var c = true; var c = true;
var d = false; var d = false;
var e = true; var e = true;
var f = 'text'; var f = "text";
var g = { var g = {
"obj": { "i": 1 }, obj: {
"j": 2 i: 1
},
j: 2
};
var h = {
test: "test"
}; };
var h = { 'test': 'test' };
var i = '0'; var i = '0';
var j = { "i": 1 }; var j = {
i: 1
};
var k = false;
var l = true;

View File

@ -8,3 +8,5 @@ var g = PDFJSDev.eval('OBJ');
var h = PDFJSDev.json('$ROOT/external/builder/fixtures_esprima/evals.json'); var h = PDFJSDev.json('$ROOT/external/builder/fixtures_esprima/evals.json');
var i = typeof PDFJSDev === 'undefined' ? PDFJSDev.eval('FALSE') : '0'; var i = typeof PDFJSDev === 'undefined' ? PDFJSDev.eval('FALSE') : '0';
var j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0'; var j = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('OBJ.obj') : '0';
var k = !PDFJSDev.test('TRUE');
var l = !PDFJSDev.test('FALSE');

View File

@ -1 +1 @@
{ 'test': 'test' } { "test": "test" }

View File

@ -7,11 +7,12 @@ if ('test') {
{ {
"1"; "1";
} }
;
{ {
"2"; "2";
} }
;
if ('1') { if ('1') {
"1"; "1";
} }
function f1() {
"1";
}

View File

@ -23,3 +23,12 @@ if (true && false) {
if (true && false || '1') { if (true && false || '1') {
"1"; "1";
} }
function f1() {
if (true) {
"1";
}
if (false) {
"2";
}
}

View File

@ -1,7 +1,4 @@
import { Test } from 'import-name'; import { Test } from "import-name";
import { Test2 } from './non-alias'; import { Test2 } from './non-alias';
export { export { Test3 } from "import-name";
Test3 await import( /*webpackIgnore: true*/"./non-alias");
} from 'import-name';
var Imp = require('import-name');
var Imp2 = require('./non-alias');

View File

@ -1,5 +1,4 @@
import { Test } from 'import-alias'; import { Test } from 'import-alias';
import { Test2 } from './non-alias'; import { Test2 } from './non-alias';
export { Test3 } from 'import-alias'; export { Test3 } from 'import-alias';
var Imp = require('import-alias'); await __non_webpack_import__("./non-alias");
var Imp2 = require('./non-alias');

View File

@ -1,348 +0,0 @@
"use strict";
const acorn = require("acorn");
const escodegen = require("@javascript-obfuscator/escodegen");
const vm = require("vm");
const fs = require("fs");
const path = require("path");
const PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
const ROOT_PREFIX = "$ROOT/";
const ACORN_ECMA_VERSION = 2022;
function isLiteral(obj, value) {
return obj.type === "Literal" && obj.value === value;
}
function isPDFJSPreprocessor(obj) {
return obj.type === "Identifier" && obj.name === PDFJS_PREPROCESSOR_NAME;
}
function evalWithDefines(code, defines, loc) {
if (!code || !code.trim()) {
throw new Error("No JavaScript expression given");
}
return vm.runInNewContext(code, defines, { displayErrors: false });
}
function handlePreprocessorAction(ctx, actionName, args, loc) {
try {
let arg;
switch (actionName) {
case "test":
arg = args[0];
if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") {
throw new Error("No code for testing is given");
}
const isTrue = !!evalWithDefines(arg.value, ctx.defines);
return { type: "Literal", value: isTrue, loc };
case "eval":
arg = args[0];
if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") {
throw new Error("No code for eval is given");
}
const result = evalWithDefines(arg.value, ctx.defines);
if (
typeof result === "boolean" ||
typeof result === "string" ||
typeof result === "number"
) {
return { type: "Literal", value: result, loc };
}
if (typeof result === "object") {
const parsedObj = acorn.parse("(" + JSON.stringify(result) + ")", {
ecmaVersion: ACORN_ECMA_VERSION,
});
parsedObj.body[0].expression.loc = loc;
return parsedObj.body[0].expression;
}
break;
case "json":
arg = args[0];
if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") {
throw new Error("Path to JSON is not provided");
}
let jsonPath = arg.value;
if (jsonPath.indexOf(ROOT_PREFIX) === 0) {
jsonPath = path.join(
ctx.rootPath,
jsonPath.substring(ROOT_PREFIX.length)
);
}
const jsonContent = fs.readFileSync(jsonPath).toString();
const parsedJSON = acorn.parse("(" + jsonContent + ")", {
ecmaVersion: ACORN_ECMA_VERSION,
});
parsedJSON.body[0].expression.loc = loc;
return parsedJSON.body[0].expression;
}
throw new Error("Unsupported action");
} catch (e) {
throw new Error(
"Could not process " +
PDFJS_PREPROCESSOR_NAME +
"." +
actionName +
" at " +
JSON.stringify(loc) +
"\n" +
e.name +
": " +
e.message
);
}
}
function postprocessNode(ctx, node) {
switch (node.type) {
case "ExportNamedDeclaration":
case "ImportDeclaration":
if (
node.source &&
node.source.type === "Literal" &&
ctx.map &&
ctx.map[node.source.value]
) {
const newValue = ctx.map[node.source.value];
node.source.value = node.source.raw = newValue;
}
break;
case "IfStatement":
if (isLiteral(node.test, true)) {
// if (true) stmt1; => stmt1
return node.consequent;
} else if (isLiteral(node.test, false)) {
// if (false) stmt1; else stmt2; => stmt2
return node.alternate || { type: "EmptyStatement", loc: node.loc };
}
break;
case "ConditionalExpression":
if (isLiteral(node.test, true)) {
// true ? stmt1 : stmt2 => stmt1
return node.consequent;
} else if (isLiteral(node.test, false)) {
// false ? stmt1 : stmt2 => stmt2
return node.alternate;
}
break;
case "UnaryExpression":
if (node.operator === "typeof" && isPDFJSPreprocessor(node.argument)) {
// typeof PDFJSDev => 'object'
return { type: "Literal", value: "object", loc: node.loc };
}
if (
node.operator === "!" &&
node.argument.type === "Literal" &&
typeof node.argument.value === "boolean"
) {
// !true => false, !false => true
return { type: "Literal", value: !node.argument.value, loc: node.loc };
}
break;
case "LogicalExpression":
switch (node.operator) {
case "&&":
if (isLiteral(node.left, true)) {
return node.right;
}
if (isLiteral(node.left, false)) {
return node.left;
}
break;
case "||":
if (isLiteral(node.left, true)) {
return node.left;
}
if (isLiteral(node.left, false)) {
return node.right;
}
break;
}
break;
case "BinaryExpression":
switch (node.operator) {
case "==":
case "===":
case "!=":
case "!==":
if (
node.left.type === "Literal" &&
node.right.type === "Literal" &&
typeof node.left.value === typeof node.right.value
) {
// folding two literals == and != check
switch (typeof node.left.value) {
case "string":
case "boolean":
case "number":
const equal = node.left.value === node.right.value;
return {
type: "Literal",
value: (node.operator[0] === "=") === equal,
loc: node.loc,
};
}
}
break;
}
break;
case "CallExpression":
if (
node.callee.type === "MemberExpression" &&
isPDFJSPreprocessor(node.callee.object) &&
node.callee.property.type === "Identifier"
) {
// PDFJSDev.xxxx(arg1, arg2, ...) => transform
const action = node.callee.property.name;
return handlePreprocessorAction(ctx, action, node.arguments, node.loc);
}
// require('string')
if (
node.callee.type === "Identifier" &&
node.callee.name === "require" &&
node.arguments.length === 1 &&
node.arguments[0].type === "Literal" &&
ctx.map &&
ctx.map[node.arguments[0].value]
) {
const requireName = node.arguments[0];
requireName.value = requireName.raw = ctx.map[requireName.value];
}
break;
case "BlockStatement":
let subExpressionIndex = 0;
while (subExpressionIndex < node.body.length) {
switch (node.body[subExpressionIndex].type) {
case "EmptyStatement":
// Removing empty statements from the blocks.
node.body.splice(subExpressionIndex, 1);
continue;
case "BlockStatement":
// Block statements inside a block are moved to the parent one.
const subChildren = node.body[subExpressionIndex].body;
Array.prototype.splice.apply(
node.body,
[subExpressionIndex, 1].concat(subChildren)
);
subExpressionIndex += Math.max(subChildren.length - 1, 0);
continue;
case "ReturnStatement":
case "ThrowStatement":
// Removing dead code after return or throw.
node.body.splice(
subExpressionIndex + 1,
node.body.length - subExpressionIndex - 1
);
break;
}
subExpressionIndex++;
}
break;
case "FunctionDeclaration":
case "FunctionExpression":
const block = node.body;
if (
block.body.length > 0 &&
block.body[block.body.length - 1].type === "ReturnStatement" &&
!block.body[block.body.length - 1].argument
) {
// Function body ends with return without arg -- removing it.
block.body.pop();
}
break;
}
return node;
}
function fixComments(ctx, node) {
if (!ctx.saveComments) {
return;
}
// Fixes double comments in the escodegen output.
delete node.trailingComments;
// Removes ESLint and other service comments.
if (node.leadingComments) {
const CopyrightRegExp = /\bcopyright\b/i;
const BlockCommentRegExp = /^\s*(globals|eslint|falls through)\b/;
const LineCommentRegExp = /^\s*eslint\b/;
let i = 0;
while (i < node.leadingComments.length) {
const type = node.leadingComments[i].type;
const value = node.leadingComments[i].value;
if (ctx.saveComments === "copyright") {
// Remove all comments, except Copyright notices and License headers.
if (!(type === "Block" && CopyrightRegExp.test(value))) {
node.leadingComments.splice(i, 1);
continue;
}
} else if (
(type === "Block" && BlockCommentRegExp.test(value)) ||
(type === "Line" && LineCommentRegExp.test(value))
) {
node.leadingComments.splice(i, 1);
continue;
}
i++;
}
}
}
function traverseTree(ctx, node) {
// generic node processing
for (const i in node) {
const child = node[i];
if (typeof child === "object" && child !== null && child.type) {
const result = traverseTree(ctx, child);
if (result !== child) {
node[i] = result;
}
} else if (Array.isArray(child)) {
child.forEach(function (childItem, index) {
if (
typeof childItem === "object" &&
childItem !== null &&
childItem.type
) {
const result = traverseTree(ctx, childItem);
if (result !== childItem) {
child[index] = result;
}
}
});
}
}
node = postprocessNode(ctx, node) || node;
fixComments(ctx, node);
return node;
}
function preprocessPDFJSCode(ctx, code) {
const format = ctx.format || {
indent: {
style: " ",
},
};
const parseOptions = {
ecmaVersion: ACORN_ECMA_VERSION,
locations: true,
sourceFile: ctx.sourceFile,
sourceType: "module",
};
const codegenOptions = {
format,
parse(input) {
return acorn.parse(input, { ecmaVersion: ACORN_ECMA_VERSION });
},
sourceMap: ctx.sourceMap,
sourceMapWithCode: ctx.sourceMap,
};
const syntax = acorn.parse(code, parseOptions);
traverseTree(ctx, syntax);
return escodegen.generate(syntax, codegenOptions);
}
exports.preprocessPDFJSCode = preprocessPDFJSCode;

View File

@ -1,8 +1,9 @@
"use strict"; import * as builder from "./builder.mjs";
import { fileURLToPath } from "url";
import fs from "fs";
import path from "path";
const builder = require("./builder.js"); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fs = require("fs");
const path = require("path");
let errors = 0; let errors = 0;
@ -21,7 +22,7 @@ files.forEach(function (expectationFilename) {
.readFileSync(expectationFilename) .readFileSync(expectationFilename)
.toString() .toString()
.trim() .trim()
.replace(/__filename/g, fs.realpathSync(inFilename)); .replaceAll("__filename", fs.realpathSync(inFilename));
const outLines = []; const outLines = [];
const outFilename = function (line) { const outFilename = function (line) {
@ -36,11 +37,17 @@ files.forEach(function (expectationFilename) {
builder.preprocess(inFilename, outFilename, defines); builder.preprocess(inFilename, outFilename, defines);
out = outLines.join("\n").trim(); out = outLines.join("\n").trim();
} catch (e) { } catch (e) {
out = ("Error: " + e.message).replace(/^/gm, "//"); out = ("Error: " + e.message).replaceAll(/^/gm, "//");
} }
if (out !== expectation) { if (out !== expectation) {
errors++; errors++;
// Allow regenerating the expected output using
// OVERWRITE=true node ./external/builder/test-fixtures.mjs
if (process.env.OVERWRITE) {
fs.writeFileSync(expectationFilename, out + "\n");
}
console.log("Assertion failed for " + inFilename); console.log("Assertion failed for " + inFilename);
console.log("--------------------------------------------------"); console.log("--------------------------------------------------");
console.log("EXPECTED:"); console.log("EXPECTED:");

View File

@ -1,8 +1,9 @@
"use strict"; import { fileURLToPath } from "url";
import fs from "fs";
import path from "path";
import { preprocessPDFJSCode } from "./babel-plugin-pdfjs-preprocessor.mjs";
const p2 = require("./preprocessor2.js"); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fs = require("fs");
const path = require("path");
let errors = 0; let errors = 0;
@ -21,7 +22,7 @@ files.forEach(function (expectationFilename) {
.readFileSync(expectationFilename) .readFileSync(expectationFilename)
.toString() .toString()
.trim() .trim()
.replace(/__filename/g, fs.realpathSync(inFilename)); .replaceAll("__filename", fs.realpathSync(inFilename));
const input = fs.readFileSync(inFilename).toString(); const input = fs.readFileSync(inFilename).toString();
const defines = { const defines = {
@ -40,13 +41,19 @@ files.forEach(function (expectationFilename) {
}; };
let out; let out;
try { try {
out = p2.preprocessPDFJSCode(ctx, input); out = preprocessPDFJSCode(ctx, input);
} catch (e) { } catch (e) {
out = ("Error: " + e.message).replace(/^/gm, "//"); out = ("Error: " + e.message).replaceAll(/^/gm, "//");
} }
if (out !== expectation) { if (out !== expectation) {
errors++; errors++;
// Allow regenerating the expected output using
// OVERWRITE=true node ./external/builder/test-fixtures_esprima.mjs
if (process.env.OVERWRITE) {
fs.writeFileSync(expectationFilename, out + "\n");
}
console.log("Assertion failed for " + inFilename); console.log("Assertion failed for " + inFilename);
console.log("--------------------------------------------------"); console.log("--------------------------------------------------");
console.log("EXPECTED:"); console.log("EXPECTED:");

View File

@ -13,10 +13,10 @@
* limitations under the License. * limitations under the License.
*/ */
const fs = require("fs"); import fs from "fs";
const path = require("path"); import { optimizeCMap } from "./optimize.mjs";
const parseAdobeCMap = require("./parse.js").parseAdobeCMap; import { parseAdobeCMap } from "./parse.mjs";
const optimizeCMap = require("./optimize.js").optimizeCMap; import path from "path";
function compressCmap(srcPath, destPath, verify) { function compressCmap(srcPath, destPath, verify) {
const content = fs.readFileSync(srcPath).toString(); const content = fs.readFileSync(srcPath).toString();
@ -215,11 +215,11 @@ function parseCMap(binaryData) {
}, },
readHexSigned(size) { readHexSigned(size) {
const num = this.readHexNumber(size); const num = this.readHexNumber(size);
const sign = fromHexDigit(num[num.length - 1]) & 1 ? 15 : 0; const sign = fromHexDigit(num.at(-1)) & 1 ? 15 : 0;
let c = 0; let c = 0;
let result = ""; let result = "";
for (let i = 0; i < num.length; i++) { for (const digit of num) {
c = (c << 4) | fromHexDigit(num[i]); c = (c << 4) | fromHexDigit(digit);
result += toHexDigit(sign ? (c >> 1) ^ sign : c >> 1); result += toHexDigit(sign ? (c >> 1) ^ sign : c >> 1);
c &= 1; c &= 1;
} }
@ -469,7 +469,7 @@ function incHex(a) {
return s; return s;
} }
exports.compressCmaps = function (src, dest, verify) { function compressCmaps(src, dest, verify) {
const files = fs.readdirSync(src).filter(function (fn) { const files = fs.readdirSync(src).filter(function (fn) {
return !fn.includes("."); // skipping files with the extension return !fn.includes("."); // skipping files with the extension
}); });
@ -489,4 +489,6 @@ exports.compressCmaps = function (src, dest, verify) {
"%" "%"
); );
}); });
}; }
export { compressCmaps };

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
exports.optimizeCMap = function (data) { function optimizeCMap(data) {
let i = 1; let i = 1;
while (i < data.body.length) { while (i < data.body.length) {
if (data.body[i - 1].type === data.body[i].type) { if (data.body[i - 1].type === data.body[i].type) {
@ -151,10 +151,7 @@ exports.optimizeCMap = function (data) {
const maxDistance = 100, const maxDistance = 100,
minItems = 10, minItems = 10,
itemsPerBucket = 50; itemsPerBucket = 50;
if ( if (subitems.length > minItems && codes.at(-1) - codes[0] > maxDistance) {
subitems.length > minItems &&
codes[codes.length - 1] - codes[0] > maxDistance
) {
const gapsCount = Math.max(2, (subitems.length / itemsPerBucket) | 0); const gapsCount = Math.max(2, (subitems.length / itemsPerBucket) | 0);
const gaps = []; const gaps = [];
for (let q = 0; q < gapsCount; q++) { for (let q = 0; q < gapsCount; q++) {
@ -196,20 +193,20 @@ exports.optimizeCMap = function (data) {
i++; i++;
data.body.splice(i, 0, newItem); data.body.splice(i, 0, newItem);
} }
for (let j = 0; j < subitems.length; j++) { for (const subitem of subitems) {
const code = subitems[j].code; const { code } = subitem;
let q = 0; let q = 0;
while (q < groups.length && groups[q] <= code) { while (q < groups.length && groups[q] <= code) {
q++; q++;
} }
buckets[q].push(subitems[j]); buckets[q].push(subitem);
} }
} }
} }
} }
i++; i++;
} }
}; }
function incHex(a) { function incHex(a) {
let c = 1, let c = 1,
@ -226,3 +223,5 @@ function incHex(a) {
} }
return s; return s;
} }
export { optimizeCMap };

View File

@ -13,13 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
exports.parseAdobeCMap = function (content) { function parseAdobeCMap(content) {
let m = /(\bbegincmap\b[\s\S]*?)\bendcmap\b/.exec(content); let m = /(\bbegincmap\b[\s\S]*?)\bendcmap\b/.exec(content);
if (!m) { if (!m) {
throw new Error("cmap was not found"); throw new Error("cmap was not found");
} }
const body = m[1].replace(/\r\n?/g, "\n"); const body = m[1].replaceAll(/\r\n?/g, "\n");
const result = { const result = {
type: 1, type: 1,
wmode: 0, wmode: 0,
@ -100,4 +100,6 @@ exports.parseAdobeCMap = function (content) {
} }
return result; return result;
}; }
export { parseAdobeCMap };

View File

@ -7,8 +7,8 @@ parsing and rendering PDFs.
This is a pre-built version of the PDF.js source code. It is automatically This is a pre-built version of the PDF.js source code. It is automatically
generated by the build scripts. generated by the build scripts.
For usage with older browsers or environments, without support for modern For usage with older browsers/environments, without native support for the
features such as `async`/`await`, optional chaining, nullish coalescing, latest JavaScript features, please see the `legacy/` folder.
and private `class` fields/methods; please see the `legacy/` folder. Please see [this wiki page](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support) for information about supported browsers/environments.
See https://github.com/mozilla/pdf.js for learning and contributing. See https://github.com/mozilla/pdf.js for learning and contributing.

View File

@ -0,0 +1 @@
export * from "../../types/web/pdf_viewer.component.js";

Some files were not shown because too many files have changed in this diff Show More