Commit Graph

12852 Commits

Author SHA1 Message Date
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
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
Tim van der Meij
0f4fc12c5e
Merge pull request #12268 from Snuffleupagus/numPages-padding
Reduce the leading padding for the `numPages` span (PR 11077 follow-up)
2020-08-23 21:07:08 +02:00
Jani Pehkonen
e7febbf0f7 Accent positioning in Type1 seac glyphs
In `display/canvas.js` the accent offsets must be multiplied by `fontSize` to make the offsets large enough. Another problem is in `core/type1_parser.js` when the Type1 command `seac` is handled. There is an error in the Adobe Type1 spec. See chapter 6 in Type1 Font Format Supplement, which provides an errata: The arguments of `seac` specify the offset of the left side bearing (LSB) points, not the offset of origins. This can be fixed in `core/type1_parser.js` by adding the difference of the LSB values.
2020-08-23 21:01:25 +03:00
Jonas Jenwald
7762205c52 Reduce the leading padding for the numPages span (PR 11077 follow-up)
Currently there's enough leading padding that the `numPages` span feels somewhat "disconnected" from the `pageNumber` input, which seems unfortunate when they contain related state.
2020-08-23 16:21:07 +02:00
Tim van der Meij
7df8aa34a5
Merge pull request #12263 from timvandermeij/acroform-fixes
Fix AcroForm printing/saving edge cases
2020-08-23 13:37:30 +02:00
Tim van der Meij
73bc8e1d9f
Include forms/print reference tests for the document from #12233
In addition to the unit tests these reference tests make sure that this
document, that triggered some edge cases in our code, can be rendered
and printed successfully now.
2020-08-23 13:00:02 +02:00
Tim van der Meij
a8efc0296b
Obtain the export values for choice widgets from the normal appearance
The down appearance (`D`) is optional and not available in the document
from #12233, so the checkboxes are never saved/printed as checked
because the checked appearance is based on the export value that is
missing because the `D` entry is not available.

Instead, we should use the normal appearance (`N`) since that one is
required and therefore always available.

Finally, the /Off appearance is optional according to section 12.7.4.2.3
of the specification, so that needs to be taken into account to match
the specification and to fix reference test failures for the
`annotation-button-widget-print` test. That is a file that doesn't
specify an /Off appearance in the normal appearance dictionary.
2020-08-23 13:00:02 +02:00
Tim van der Meij
1b82ad8fff
Decode widget form values consistently
The helper method `_decodeFormValue` is used to ensure that it happens
in one place. Note that form values are field values, display values
and export values.
2020-08-23 13:00:01 +02:00
Tim van der Meij
3398e69aef
Merge pull request #12267 from Snuffleupagus/update-packages
Update packages and translations
2020-08-23 12:31:57 +02:00
Jonas Jenwald
ba8c5bde5f Update l10n files 2020-08-23 10:10:38 +02:00
Jonas Jenwald
cb27999681 Update npm packages 2020-08-23 10:08:45 +02:00
Tim van der Meij
364b9cc802
Merge pull request #12265 from Snuffleupagus/issue-12262
Don't warn when navigating away from a modified form, if printing has occurred (issue 12262)
2020-08-22 20:59:52 +02:00
Jonas Jenwald
fa02808f76 Mark the setModified method, on AnnotationStorage, as "private" (PR 12241 follow-up)
Since it shouldn't be called manually, we can just mark it as "private".
2020-08-22 20:04:25 +02:00
Jonas Jenwald
1f5021d76a Prevent errors if PDFDocumentProxy.saveDocument is called without the annotationStorage parameter (PR 12241 follow-up)
Obviously it doesn't make sense to call that method without providing an `AnnotationStorage`-instance, however we should ensure that doing so won't cause errors.
Hence we need to check that `annotationStorage` is actually defined, before attempting to call its `resetModified` method.
2020-08-22 18:09:17 +02:00
Jonas Jenwald
f2e3d6c819 Don't warn when navigating away from a modified form, if printing has occurred (issue 12262)
This solution is obviously *not* perfect, since printing being cancelled will thus remove the warning as well. However, a similar problem already exists for saving, since the user may cancel that one as well.

All-in-all, since way cannot really detect with absolute certainty that either saving or printing actually finished, this seems good enough for now.
2020-08-22 17:49:56 +02:00
Tim van der Meij
9d7609d255
Merge pull request #12261 from Snuffleupagus/renderInteractiveForms-defaults
Also enable `renderInteractiveForms` by default in the viewer components (PR 12201 follow-up)
2020-08-22 16:48:42 +02:00
Tim van der Meij
36e149800e
Unconditionally set the field value for choice widgets in the annotation storage
This commit makes the following improvements:

- The code is similar to the other interactive form widgets now, with a
  clear note for the only difference.
- Calling `getOrCreateValue` unconditionally ensures that choice widgets
  always have a value in the annotation storage. Previously we only
  inserted a value in the annotation storage when an option matched or
  when a selection was changed. However, this causes breakage when
  saving/printing because comboboxes, which we don't fully support yet
  but are rendered, might not have a value in storage at all. Their
  field value might not match any option since it allows the user to
  enter a custom value.
- Calling `getOrCreateValue` unconditionally ensures that forms with
  choice widgets no longer always trigger a warning when the user
  navigates away from the page. This fixes
  https://github.com/mozilla/pdf.js/pull/12241#discussion_r474279654
2020-08-22 16:01:33 +02:00
Jonas Jenwald
a8de614a9f Also enable renderInteractiveForms by default in the viewer components (PR 12201 follow-up)
Given that `renderInteractiveForms` is now enabled by default in "full" viewer, it seems reasonable to enable it by default in the viewer components as well.
Especially considering that it's simple to disable, when creating the affected components, for anyone implementing their own viewer.
2020-08-22 14:24:04 +02:00
Tim van der Meij
5fed7112a2
Use the export value instead of the display value for choice widget option selection
The export value is used when the document is saved, so it should also
be used when the document is opened to determine which choice widget
option is selected. The display value is, as the name implies, only to
be used for viewer display purposes and not for other logic.

This makes sure that in the document from #12233 the "Favourite colour"
choice widget is correctly initialized with "Red" instead of "Black"
because the field value is equal to the export value (always the case),
but not the display value (not always the case). Moreover, saving now
also correctly uses the export value and not the display value.
2020-08-22 14:11:41 +02:00
Tim van der Meij
37c5660394
Merge pull request #12260 from utopianknight/replace-menuArrow-icon
Replace menu dropdown icon
2020-08-22 13:28:41 +02:00
utopianknight
43a439643d Replaced menu dropdown icon 2020-08-22 12:10:51 +04:00
Tim van der Meij
1ff578cbd4
Merge pull request #12244 from yangjiang3973/fix-webpack
fix webpack config problem caused by breaking changes of worker-loader
2020-08-21 23:46:29 +02:00
Tim van der Meij
909c5af5ed
Merge pull request #12256 from escapewindow/12241-followup
#12241 followup - move event listener to PDFViewerApplication.load
2020-08-21 23:28:37 +02:00
Tim van der Meij
3c790936c1
Merge pull request #12247 from timvandermeij/acroform-choice-null
Improve the field value parsing for choice widgets to handle `null` values
2020-08-21 23:17:20 +02:00
Aki Sasaki
b1423336c3 #12241 followup - move event listener to PDFViewerApplication.load 2020-08-21 09:53:39 -07:00
Brendan Dahl
0d5ef5dd0a
Merge pull request #12248 from brendandahl/pdf-save-as
Support file save triggered from the Firefox integrated version.
2020-08-20 18:11:29 -07:00