Commit Graph

12877 Commits

Author SHA1 Message Date
Jonas Jenwald
54eeaba014 Update l10n files 2020-09-06 11:51:34 +02:00
Jonas Jenwald
0aef40f897 Update npm packages 2020-09-06 11:49:49 +02:00
Tim van der Meij
4caa14b4dc
Merge pull request #12326 from Snuffleupagus/bug-1661259
Revert "Download, rather than opening, PDF attachments in Firefox (bug 1661259, PR 12286 follow-up)"
2020-09-04 22:06:54 +02:00
Jonas Jenwald
a52e229ca6 Revert "Download, rather than opening, PDF attachments in Firefox (bug 1661259, PR 12286 follow-up)"
This reverts commit 2a0de0b66b.

I can no longer reproduce these issues locally, and if ad blockers are still interfering with this functionality we really ought to pursue a mozilla-central solution to the problem instead. (Also, I'm no longer getting an "Open with Firefox"-option in the "Open with"-dialog making the PDF attachments experience worse for all users.)
2020-09-04 12:07:34 +02:00
Tim van der Meij
05fede43f7
Merge pull request #12323 from timvandermeij/bump
Bump versions in `pdfjs.config`
2020-09-03 23:50:34 +02:00
Tim van der Meij
b30a34c98d
Bump versions in pdfjs.config 2020-09-03 23:43:50 +02:00
Tim van der Meij
3be9c65f04
Merge pull request #12321 from Snuffleupagus/BaseViewer-validate-viewer-option
Ensure that the `viewer` property, on `BaseViewer`-instances, is a valid div-element (issue 12320)
2020-09-03 22:11:23 +02:00
Jonas Jenwald
89f6bb0fc6 Ensure that the viewer property, on BaseViewer-instances, is a valid div-element (issue 12320)
This should help prevent future issues, caused by the user omitting the `viewer` option and/or providing an incorrect `container` option, when initializing a `BaseViewer`-instance.
2020-09-03 15:06:36 +02:00
Brendan Dahl
84da13b487
Merge pull request #12315 from emilio/more-resilient-print-callback
print: Make the firefox printing code able to fail and be re-invoked.
2020-09-02 14:13:36 -07:00
Emilio Cobos Álvarez
f4f4ec30f4
print: Make the firefox printing code able to fail and be re-invoked.
This fixes a set of issues described in Mozilla bug 1662426[1].

In particular, once the print callback fails once (because the printing
operation has been canceled in Gecko / replaced by a newer one, for example) it
can't be re-invoked.

This patch fixes it by properly cancelling the render task if it throws, or if
the print callback is called again while ongoing.

[1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1662426
2020-09-02 22:56:21 +02:00
Tim van der Meij
ed9ea8f9b2
Merge pull request #12310 from Snuffleupagus/issue-12308
Add support for /Print and /SaveAs named actions in the viewer (issue 12308)
2020-09-01 22:03:03 +02:00
Jonas Jenwald
695523712c Add support for /Print and /SaveAs named actions in the viewer (issue 12308)
All of the core/display functionality needed to support this already exists, we simply need to handle these named actions in the viewer and the buttons will "just" work.

Unfortunately there's not really any good way of testing this, but given the size and scope of the patch that's hopefully OK.
2020-09-01 09:24:38 +02:00
Tim van der Meij
60ffac0480
Merge pull request #12296 from Snuffleupagus/mergeSubDicts
Add support, in `Dict.merge`, for merging of "sub"-dictionaries
2020-08-31 23:29:44 +02:00
Tim van der Meij
c48fe10f75
Merge pull request #12301 from Snuffleupagus/stylelint
Add (basic) support for Stylelint, to allow linting of CSS files
2020-08-31 22:42:18 +02:00
Jonas Jenwald
784a420027 Add support, in Dict.merge, for merging of "sub"-dictionaries
This allows for merging of dictionaries one level deeper than previously. This could be useful e.g. for /Resources dictionaries, where you want to e.g. merge their respective /Font dictionaries (and other) together rather than picking just the first one.
2020-08-30 23:18:32 +02:00
Jonas Jenwald
8aa2718d22 Re-format all web/*.css files using Stylelint/Prettier
This was done automatically, using `gulp lint --fix`.
2020-08-30 21:49:08 +02:00
Jonas Jenwald
7b5a540a52 Add (basic) support for Stylelint, to allow linting of CSS files
This is *similar* to the existing linting for JavaScript files, but covers CSS files instead.
While there's a lot of rules that could potentially be used, the main advantage of using Stylelint is that it has Prettier integration which means that we can automatically enforce a *consistent* style for our CSS files as well.

As a proof of concept, this patch is purposely limited to:
 - Adding a simple rule, here `block-no-empty` is chosen; see https://stylelint.io/user-guide/rules/block-no-empty
 - Adding Prettier integration, to unify the style of our CSS files.

Please find additional information at https://stylelint.io/
2020-08-30 21:48:35 +02:00
Tim van der Meij
aa27e7fb8d
Merge pull request #12170 from Snuffleupagus/optional-content-viewer-2
[api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
2020-08-30 21:14:24 +02:00
Jonas Jenwald
66aabe3ec7 [api-minor] Add support for toggling of Optional Content in the viewer (issue 12096)
*Besides, obviously, adding viewer support:* This patch attempts to improve the general API for Optional Content Groups slightly, by adding a couple of new methods for interacting with the (more complex) data structures of `OptionalContentConfig`-instances. (Thus allowing us to mark some of the data as "private", given that it probably shouldn't be manipulated directly.)

By utilizing not just the "raw" Optional Content Groups, but the data from the `/Order` array when available, we can thus display the Layers in a proper tree-structure with collapsible headings for PDF documents that utilizes that feature.

Note that it's possible to reset all Optional Content Groups to their default visibility state, simply by double-clicking on the Layers-button in the sidebar.
(Currently that's indicated in the Layers-button tooltip, which is obviously easy to overlook, however it's probably the best we can do for now without adding more buttons, or even a dropdown-toolbar, to the sidebar.)

Also, the current Layers-button icons are a little rough around the edges, quite literally, but given that the viewer will soon have its UI modernized anyway they hopefully suffice in the meantime.

To give users *full* control of the visibility of the various Optional Content Groups, even those which according to the `/Order` array should not (by default) be toggleable in the UI, this patch will place those under a *custom* heading which:
 - Is collapsed by default, and placed at the bottom of the Layers-tree, to be a bit less obtrusive.
 - Uses a slightly different formatting, compared to the "regular" headings.
 - Is localizable.

Finally, note that the thumbnails are *purposely* always rendered with all Optional Content Groups at their default visibility state, since that seems the most useful and it's also consistent with other viewers.
To ensure that this works as intended, we'll thus disable the `PDFThumbnailView.setImage` functionality when the Optional Content Groups have been changed in the viewer. (This obviously means that we'll re-render thumbnails instead of using the rendered pages. However, this situation ought to be rare enough for this to not really be a problem.)
2020-08-30 16:28:40 +02:00
Jonas Jenwald
2393443e73 Include the /Order array, if available, when parsing the Optional Content configuration
The `/Order` array is used to improve the display of Optional Content groups in PDF viewers, and it allows a PDF document to e.g. specify that Optional Content groups should be displayed as a (collapsable) tree-structure rather than as just a list.

Note that not all available Optional Content groups must be present in the `/Order` array, and PDF viewers will often (by default) hide those toggles in the UI.
To allow us to improve the UX around toggling of Optional Content groups, in the default viewer, these hidden-by-default groups are thus appended to the parsed `/Order` array under a *custom* nesting level (with `name == null`).

Finally, the patch also slightly tweaks an `OptionalContentConfig` related JSDoc-comment in the API.
2020-08-30 16:28:40 +02:00
Jonas Jenwald
9ba5f9fa34 Create an OptionalContentConfig-instance once for each task, when running the reference test-suite
This avoids the need to make a round-trip to the worker-thread for *every* single page that's being tested, which should thus be more efficient.
2020-08-30 16:28:40 +02:00
Tim van der Meij
ef5a5c142a
Merge pull request #12299 from Snuffleupagus/progressBar-indeterminate
Update the indeterminate progressBar to the new design (PR 11077 follow-up)
2020-08-30 16:14:01 +02:00
Tim van der Meij
d1cc382383
Merge pull request #12300 from Snuffleupagus/findbar-hover
Fix various :hover effects in the findbar (PR 11077 follow-up)
2020-08-30 16:07:43 +02:00
Tim van der Meij
06b53d770a
Merge pull request #12259 from brendandahl/cmap-fix
Fix handling of symbolic fonts and unicode cmaps.
2020-08-30 16:01:24 +02:00
Tim van der Meij
d383193913
Merge pull request #12298 from Snuffleupagus/doorHanger-positions
Tweak the vertical positions of the `findbar` and `secondaryToolbar` (PR 11077 follow-up)
2020-08-30 15:53:22 +02:00
Jonas Jenwald
931f2cff1e Fix various :hover effects in the findbar (PR 11077 follow-up)
This patch:
 - Removes the :hover effect from the `findMsg` element, since it's a simple span and clicking it *obviously* does nothing.
 - Given the way that the checkboxes are visually hidden, with `opacity: 0;` and absolute positioning, they are unfortunately still focusable (fixed by adding `pointer-events: none;`). To reproduce this, in `master`: Place the mouse pointer over the upper left-hand corner of the "Highlight all"-option, and notice that the :hover effect vanishes and clicking toggles the "Match case"-option instead.
2020-08-29 15:44:51 +02:00
Jonas Jenwald
55e1dda52a Update the indeterminate progressBar to the new design (PR 11077 follow-up)
This special progressBar is only used in the (fortunately) rare case when a server doesn't provide a valid `Content-Length` header. Since this progressBar isn't normally seen, when testing the default viewer, it's certainly very easy to see why these CSS rules were missed during review.

Furthermore, this patch also makes a couple of *small* progressBar CSS tweaks not related to the colours.
2020-08-28 16:18:41 +02:00
Jonas Jenwald
16f5080bef Tweak the vertical positions of the findbar and secondaryToolbar (PR 11077 follow-up)
With the changes in PR 11077, these panels are no longer aligned exactly with the *center* of the corresponding toolbar buttons. This is especially noticeable for the `findbar` at narrow viewer width.
2020-08-28 13:04:10 +02:00
Brendan Dahl
45e8a31cc0 Fix handling of symbolic fonts and unicode cmaps.
In issue 12120, the font has a 1,0 cmap and is marked symbolic which
according to the spec means we should directly use the cmap instead of
the extra steps that are defined in 9.6.6.4.

However, just fixing that caused bug 1057544 to break. The font in bug
1057544 has a 0,1 cmap (Unicode 1.1) which we were not using, but is
easy to support. We're also easily able to support some of the other
unicode cmaps, so I added those as well.

There was also a second issue with bug 1057544, the cmap doesn't have
a mapping for the "quoteright" glyph, but it is defined in the post
table. To handle this, I've moved post table as a  fallback for any
font that has an encoding.
2020-08-27 14:33:11 -07:00
Tim van der Meij
eb3654e278
Merge pull request #12287 from calixteman/bug_1661226
Bug 1661226 - Push button are not rendered with renderInteractiveForms enabled
2020-08-27 23:04:57 +02:00
Tim van der Meij
6db8907d82
Merge pull request #12293 from Snuffleupagus/bug-1661259
Download, rather than opening, PDF attachments in Firefox (bug 1661259, PR 12286 follow-up)
2020-08-27 22:13:19 +02:00
Jonas Jenwald
2a0de0b66b Download, rather than opening, PDF attachments in Firefox (bug 1661259, PR 12286 follow-up)
Unfortunately the work-around implemented in PR 12286 didn't actually work in all cases, please refer to the previous commit messages.
To prevent opening of PDF attachments from being completely broken for some users, we'll simply force-download them for now in MOZCENTRAL-builds to unbreak things. (Given that the "Open with" dialog now features a "Open with Firefox"-option, this is less bad than it previously would've been.)
2020-08-27 16:30:15 +02:00
Jonas Jenwald
a23079c2dd Ensure that PDFAttachmentViewer._bindLink assigns the correct contentType when downloading PDF attachments
This should provide better filetype detection when downloading PDF attachments in the viewer.

Also, to avoid creating the "is PDF file" regular expression more than once it's extracted into a global constant instead.
2020-08-27 16:30:15 +02:00
Jonas Jenwald
de932573dd Revert "Use a link, rather than window.open, when opening PDF attachments in Firefox (bug 1661259)"
This reverts commit 1e5d4b6a80, since it unfortunately doesn't work in all situations.

Please note that I did *successfully* test the patch in a local Firefox build, obviously with an ad blocker installed.
However, I've now tested the *latest* Nightly-build with my default profile, and unfortunately I can still reproduce the bug there!?
2020-08-27 16:30:05 +02:00
Calixte Denizet
ba94f04ba3 Bug 1661226 - Push button are not rendered with renderInteractiveForms enabled 2020-08-27 10:45:14 +02:00
Tim van der Meij
a6f66891cc
Merge pull request #12286 from Snuffleupagus/bug-1661259
Use a link, rather than `window.open`, when opening PDF attachments in Firefox (bug 1661259)
2020-08-26 22:25:56 +02:00
Tim van der Meij
3e437ce63c
Merge pull request #12285 from Snuffleupagus/sourceEventType-optional
Ensure that the `sourceEventType` parameter is actually optional in `PDFViewerApplication.{download, save}` (PR 12248 follow-up)
2020-08-26 22:18:19 +02:00
Jonas Jenwald
1e5d4b6a80 Use a link, rather than window.open, when opening PDF attachments in Firefox (bug 1661259)
Unfortunately e.g. ad blockers can interfere with `window.open` calls, thus preventing PDF attachments from being opened/viewed. For the MOZCENTRAL-build, we can work-around this problem by using a (hidden) link instead.
2020-08-26 19:02:51 +02:00
Jonas Jenwald
77a1e531c2 Ensure that the sourceEventType parameter is actually optional in PDFViewerApplication.{download, save} (PR 12248 follow-up)
Without these changes, clicking on the "Open With Different Viewer"-button on the Firefox fallback bar won't actually do anything and the following is printed in the web-console:
```
Uncaught TypeError: (destructured parameter) is undefined
    download resource://pdf.js/web/viewer.js:956
    response resource://pdf.js/web/viewer.js:1054
    listener resource://pdf.js/web/viewer.js:11891
viewer.js:956:1
```

Furthermore, this patch also fixes `PDFViewerApplication.fallback` to pass in an explicit `sourceEventType` when triggering downloading. While this, on its own, would obviously have been sufficient to fix the bug described above, it seems wrong to outright break backwards compatibility of any older `PDFViewerApplication.download` calls.
2020-08-26 11:45:25 +02:00
Tim van der Meij
4ffdbe6ec9
Merge pull request #12271 from timvandermeij/acroform-type-detection
Improve AcroForm/XFA form type detection
2020-08-26 00:18:00 +02:00
Tim van der Meij
0f229d537f
Inline the setup method in the parse method in src/core/document.js
Now that the `parse` method is simplified we can inline the `setup`
method in the `parse` method since it's only two lines of code. This
avoids some indirection.
2020-08-25 23:28:55 +02:00
Tim van der Meij
280207c740
Redo the form type detection logic and include unit tests
Good form type detection is important to get reliable telemetry and to
only show the fallback bar if a form cannot be filled out by the user.

PDF.js only supports AcroForm data, so XFA data is explicitly unsupported
(tracked in issue #2373). However, the previous form type detection
couldn't separate AcroForm and XFA well enough, causing form type
telemetry to be incorrect sometimes and the fallback bar to be shown for
forms that could in fact be filled out by the user.

The solution in this commit is found by studying the specification and
the form documents that are available to us. In a nutshell the rules are:

- There is XFA data if the `XFA` entry is a non-empty array or stream.
- There is AcroForm data if the `Fields` entry is a non-empty array and
  it doesn't consist of only document signatures.

The document signatures part was not handled in the old code, causing a
document with only XFA data to also be marked as having AcroForm data.
Moreover, the old code didn't check all the data types.

Now that AcroForm and XFA can be distinguished, the viewer is configured
to only show the fallback bar for documents that only have XFA data. If
a document also has AcroForm data, the viewer can use that to render the
form. We have not found documents where the XFA data was necessary in
that case.

Finally, we include unit tests to ensure that all cases are covered and
move the form type detection out of the `parse` function so that it's
only executed if the document information is actually requested
(potentially making initial parsing a tiny bit faster).
2020-08-25 23:28:55 +02:00
Tim van der Meij
f0bf62ff54
Mark the catDict member as private in the Catalog class
Not only is `catDict` never accessed anymore outside of this file, it
should also never happen since it's internal to the catalog. If data
from it is needed elsewhere, the catalog should provide a getter for it
that can do basic data integrity checks and abstract away any
unnecessary details.
2020-08-25 23:28:55 +02:00
Tim van der Meij
f20f0bcc78
Move the AcroForm logic from the document to the catalog
The `AcroForm` entry is part of the catalog, not of the document, so its
logic should be placed there instead. The document should look in the
catalog to fetch it, and not have knowledge of `catDict`, which is a
member internal to the catalog.

Moreover, make the AcroForm member private on the document instance. It's
only used internally and was also never intended to be public. For users
it's exposed by the `getMetadata` API endpoint as `IsAcroFormPresent`.
Only a boolean is exposed, so we now also only store the boolean on the
document instance.

Finally, the annotation code needs access to the full AcroForm
dictionary, so it's updated to fetch the data from the catalog instead
of the document that now only holds the boolean.
2020-08-25 23:28:55 +02:00
Tim van der Meij
b41a2f4d5a
Move the collection logic from the document to the catalog
The `Collection` entry is part of the catalog, not of the document, so
its logic should be placed there instead. The document should look in the
catalog to fetch it, and not have knowledge of `catDict`, which is a
member internal to the catalog.

Moreover, remove the collection member from the document instance. It's
only used internally and was also never intended to be public. For users
it's exposed by the `getMetadata` API endpoint as `IsCollectionPresent`.
Moving this out of the `parse` function makes sure that the getter is
only executed if the document information is actually requested
(potentially making initial parsing a tiny bit faster).
2020-08-25 23:28:55 +02:00
Tim van der Meij
935d95b462
Move the version logic from the document to the catalog
The `Version` entry is part of the catalog, not of the document, so its
logic should be placed there instead. The document should look in the
catalog to fetch it, and not have knowledge of `catDict`, which is a
member internal to the catalog.

Moreover, make the version member private on the document instance. It's
only used internally and was also never intended to be public. For users
it's exposed by the `getMetadata` API endpoint as `PDFFormatVersion`.

Finally, clarify how the version from the header and the version from
the catalog are treated using a comment.
2020-08-25 23:28:55 +02:00
Tim van der Meij
525cc733d2
Merge pull request #12276 from Snuffleupagus/worker-ensure
Access the `XRef`/`Catalog` data correctly in the "GetStats"/"GetPageIndex" handlers in `src/core/worker.js`
2020-08-25 22:18:08 +02:00
Jonas Jenwald
bd16c363ce Access the Catalog data correctly in the "GetPageIndex" handler in src/core/worker.js
Even though the code obviously works as-is, given that we have unit-tests for it, it still feels incorrect to just *assume* that the `Catalog`-instance has all of its properties immediately available. Especially when (almost) all of the other handlers, in `src/core/worker.js`, protect their data accesses with appropriate `pdfManager.ensure` calls.
2020-08-25 12:14:14 +02:00
Jonas Jenwald
2e6e2c3b41 Access the XRef data correctly in the "GetStats" handler in src/core/worker.js
Even though the code obviously works as-is, given that we have unit-tests for it, it still feels incorrect to just *assume* that the `XRef`-instance has all of its properties immediately available. Especially when (almost) all of the other handlers, in `src/core/worker.js`, protect their data accesses with appropriate `pdfManager.ensure` calls.
2020-08-25 12:14:11 +02:00
Tim van der Meij
34cec29288
Merge pull request #12270 from janpe2/type1-accents
Accent positioning in Type1 `seac` glyphs
2020-08-24 21:55:33 +02:00