Commit Graph

15073 Commits

Author SHA1 Message Date
Tim van der Meij
2ac6c939a5
Merge pull request #14225 from Snuffleupagus/render-better-holes-check
Avoid doing unnecessary checks, when pre-rendering page layouts with "holes" (PR 14131 follow-up)
2021-11-03 19:48:37 +01:00
Brendan Dahl
039a7a670f Reset path bounding box tracking when starting a new path.
Starting a new path will wipe out any of the current subpaths in the
current graphics state, so we should reset the min/maxes.

This makes a number of the bounding boxes smaller and reduces the number
of composed pixels. For the smask tests in the corpus, the number of
composed pixesl goes from 19,872,109 to 19,676,905. The difference is much
larger on other PDFs though.
2021-11-03 11:46:52 -07:00
Tim van der Meij
c68dc03be6
Merge pull request #14221 from Snuffleupagus/pr-12870-followup
Use `BaseViewer.previousPage` more in the default viewer (PR 12870 follow-up)
2021-11-03 19:44:12 +01:00
Jonas Jenwald
ab5f4a3e5e Avoid doing unnecessary checks, when pre-rendering page layouts with "holes" (PR 14131 follow-up)
*Sometimes I'll hopefully learn to optimize my code directly when writing it, rather than having to do multiple clean-up passes; sorry about the churn here!*

For most page layouts there won't be any "holes" in the visible pages (or thumbnails), and in those cases it'd obviously be preferable not having to repeat any checks of already rendered pages.
Rather than only checking the "distance" between the first/last pages, we can instead compare the theoretical number of pages (between first/last) with the actually visible number of pages instead. This way, we're able to better detect the "holes"-case and can skip unnecessary parsing in the common case.
2021-11-03 09:40:39 +01:00
Brendan Dahl
60ab751bb6
Merge pull request #14217 from Snuffleupagus/bug-1732141
[Firefox] Handle errors if loading failed before the "supportsRangedLoading" message was sent (bug 1732141)
2021-11-02 13:32:17 -07:00
Jonas Jenwald
292a715c1c Use optional chaining to simplify PDFViewerApplication.store accesses in various event handlers
This way we no longer need the intermediate variables.
2021-11-02 12:00:57 +01:00
Jonas Jenwald
d6e8b8fbc1 Use BaseViewer.previousPage more in the default viewer (PR 12870 follow-up)
I missed this one spot in PR 12870, when converting the other cases in the "keydown" event handler. However, given that it only matters in PresentationMode and/or when "page-fit" zooming is enabled, this oversight shouldn't have had any user-observable impact (but we should fix it nonetheless).
2021-11-02 11:48:18 +01:00
Jonas Jenwald
f4e88b0a57 [Firefox] Handle errors if loading failed before the "supportsRangedLoading" message was sent (bug 1732141)
This is a follow-up to PR 10675, since there I completely overlooked that we also need to handle the case where a PDF document has *failed* to load when the "supportsRangedLoading" message is sent to the viewer.
2021-11-01 17:50:49 +01:00
Tim van der Meij
6a15973a1b
Merge pull request #14212 from Snuffleupagus/issue-10301-test
Add a RTL-text reference test (issue 10301)
2021-10-31 17:57:50 +01:00
Jonas Jenwald
8edec018fe Add a RTL-text reference test (issue 10301)
It seems that issue 10301 was fixed by PR 13424, by combining the spans, however given that we don't have a lot of test coverage for RTL-text I figured that adding a simple reference test wouldn't hurt (rather than just closing the issue as WORKSFORME).
2021-10-31 16:55:11 +01:00
Jonas Jenwald
8c70258065
Merge pull request #14182 from calixteman/richtext
Support rich content in markup annotation
2021-10-31 14:41:56 +01:00
Calixte Denizet
cf8dc750d6 Support rich content in markup annotation
- use the xfa parser but in the xhtml namespace.
2021-10-31 13:44:51 +01:00
Tim van der Meij
fe11711325
Merge pull request #14210 from Snuffleupagus/update-packages
Update packages and translations
2021-10-31 13:13:25 +01:00
Jonas Jenwald
822856e044 Update l10n files 2021-10-31 09:56:41 +01:00
Jonas Jenwald
48896adc27 Enable the ESLint no-unused-private-class-members rule
Given that we're now using private `class` fields/methods, enabling this new ESLint rule should help avoid adding dead code.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-unused-private-class-members
2021-10-31 09:52:07 +01:00
Jonas Jenwald
a8abdfb3bb Update npm packages 2021-10-31 09:38:18 +01:00
calixteman
2d8b6fda8f
Merge pull request #14207 from janekotovich/forms_version_popup
JS - Avoid a popup to ask for specific version of Acrobat
2021-10-30 05:45:31 -07:00
Tim van der Meij
ec1633c33c
Merge pull request #14201 from Snuffleupagus/bug-1219400
Use the correct border-style for Annotations, when a dash array is specified (bug 1219400)
2021-10-30 12:39:46 +02:00
Tim van der Meij
317e4dd146
Merge pull request #14204 from Snuffleupagus/rm-shadowViewer
Remove the `shadowViewer` used with Page scrolling
2021-10-30 12:37:30 +02:00
calixteman
2c0bbaf208
Merge pull request #14153 from catherinemds/xfa-link
Fix XFA links (bug 1735738)
2021-10-29 11:06:00 -07:00
Catherine
db0b3cda8b XFA - Fix xfaLink class to make links work (bug 1735738)
There were some links not working in some XFA files,I realized that the anchor tag that contains the link has an inline display and couldn't receive any height, solved this by adding a "position: absolute". Tested with two different files in Firefox Nightly and Chrome and now all links are working perfectly fine. Added reftest to avoid future regressions
2021-10-29 11:39:33 -04:00
Jane-Kotovich
12f89d2ab1 JS - Avoid a popup to ask for specific version of Acrobat
Embedded JS in PDF keep throwing alert reagdring specific version of Acrobat (Spanish and version 5.0 or greater).
This happens because:
- JS in pdf is enabled
- PDF contains some unsupported features (e.g. XFA)
Alert come when app.formVersion = undefined || app.formVersion < 5.0
In pdf.js we were using FORM_VERSION = undefined. After researching based on https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/pdfs/acrobatsdk_jsapiref.pdf\#G4.1993509 and Acrobat DC we decided to go with the larger number to avoid unnecessary popups.
Through investigation we realise that VIEWER_VERSION should have same value - a number.
Due to all that, we implemented 21.00720099 as a value for both FORMS_VERSION and VIEWER_VERSION
2021-10-29 23:09:59 +10:00
Jonas Jenwald
c18df2c61f Remove the shadowViewer used with Page scrolling
The only reason for using a `DocumentFragment` in the first place, originally added in PR 8724, was to prevent errors in the `PDFPageView`-constructor. However, we should be able to simply make its `container`-option *optional* instead, since it's not being used for anything else in the class.

Note that pre-rendering still works correctly in my testing, and given that the `BaseViewer` keeps references to all `PDFPageView`-instances (via its `_pages` Array) it also shouldn't be possible to "lose" any pages/canvases this way.
2021-10-28 13:48:15 +02:00
Tim van der Meij
0e7614df7f
Merge pull request #14180 from Snuffleupagus/bug-1627427
Handle ranges that "overflow" the last byte in `CMap.mapBfRange` (bug 1627427)
2021-10-27 20:06:09 +02:00
Tim van der Meij
6f3700b393
Merge pull request #14191 from Snuffleupagus/viewer-empty-pageLabels
Ignore pageLabels, in the viewer, when they're all empty
2021-10-27 20:01:45 +02:00
Tim van der Meij
f3a0a506c0
Merge pull request #14192 from Snuffleupagus/pr-14158-followup
[Regression] Prevent breaking errors when opening a new document in the GENERIC viewer (PR 14158 follow-up)
2021-10-27 19:58:25 +02:00
Jonas Jenwald
884caf602e Use the correct border-style for Annotations, when a dash array is specified (bug 1219400)
Even though we cannot use the dash array in the display layer, at least ensure that we use the correct border-style.
2021-10-27 13:20:21 +02:00
calixteman
74bc6d2625
Merge pull request #14189 from janekotovich/security_handler
[api-minor] Implement securityHandler in the scripting API (bug 1731578)
2021-10-27 03:40:16 -07:00
calixteman
f40bbe838e
Merge pull request #14199 from calixteman/it
Avoid to display download panel during integration tests
2021-10-27 03:20:17 -07:00
Calixte Denizet
a24322fdab Avoid to display download panel during integration tests
- it could be the cause of the failures in #14189;
  - and the patch in firefox to enable the pref landed very recently:
  https://hg.mozilla.org/mozilla-central/rev/3de56e38f3c87f33a1e7849701edb3c62bc472a5
2021-10-27 11:43:30 +02:00
Jonas Jenwald
390ddd9241
Merge pull request #14181 from PinRathod/simpleviewer_to_async
Converted simpleviewer.js to await/async
2021-10-26 20:31:04 +02:00
PinRathod
4c463c6099 Converted simpleviewer.js to await/async 2021-10-26 22:42:08 +05:30
Jane-Kotovich
91fc643ff9 [api-minor] Implement securityHandler in the scripting API (bug 1731578) 2021-10-26 23:42:04 +10:00
Jonas Jenwald
66c26d70d4 Ignore pageLabels, in the viewer, when they're all empty
Unfortunately there exist PDF documents where all pageLabels are empty strings, see e.g. http://www.cs.cornell.edu/~ragarwal/pubs/blk-switch.pdf (taken from an old issue), which result in the pageNumber-input being completely blank. That doesn't seem very helpful, and this patch simply extends the approach used to ignore pageLabels that are identical to standard page numbering.
2021-10-25 16:11:04 +02:00
Jonas Jenwald
2c779a8fbe [Regression] Prevent breaking errors when opening a new document in the GENERIC viewer (PR 14158 follow-up)
In the GENERIC viewer, e.g. when dragging-and-dropping a new PDF document which automatically opens the outline, there can now be breaking errors in the `{BaseViewer, PDFThumbnailViewer}.#getScrollAhead` methods since there's no visible pages/thumbs during loading; sorry about the breakage!
2021-10-25 14:27:24 +02:00
Jonas Jenwald
c85cd80b1b Remove unnecessary pageLabel length-check in the viewer
Given how the pageLabel array is defined, see 1ab9a6e36e/src/core/catalog.js (L627), it shouldn't be necessary to check the length in the viewer.
2021-10-25 13:25:34 +02:00
Jonas Jenwald
aa1b78684f Handle ranges that "overflow" the last byte in CMap.mapBfRange (bug 1627427) 2021-10-24 13:48:38 +02:00
Tim van der Meij
1ab9a6e36e
Merge pull request #14158 from Snuffleupagus/preRender-doc-limits
Improve pre-rendering at the start/end of the document
2021-10-24 13:43:02 +02:00
Jonas Jenwald
3dc738c4c8 Slightly simplify the isThumbnailViewEnabled check in PDFRenderingQueue.renderHighestPriority 2021-10-23 19:59:14 +02:00
Jonas Jenwald
91692a20d1 Skip the first/last visible pages pre-rendering page layouts with "holes" (PR 14131 follow-up)
This was a stupid oversight on my part, since the first/last visible pages have obviously already been rendered at the point when we're checking for any potential "holes" in the page layout.
While this will obviously not have any measurable effect on performance, we should nonetheless avoid doing completely unnecessary checks here.
2021-10-23 19:15:37 +02:00
Jonas Jenwald
24b7fb20ef Improve pre-rendering at the start/end of the document
This is a very old "issue", which has existed since essentially forever, and it affects all of the available scrollModes. However, in the recently added Page-mode it's particularily noticeable since we use a *simulated* scroll direction there.

When deciding what page(s) to pre-render, we only consider the current scroll direction. This works well in most cases, but can break down at the start/end of the document by trying to pre-render a page *outside* of the existing ones. To improve this, we'll thus *force* the scroll direction at the start/end of the document.

*Steps to reproduce:*

 0. Open the viewer, e.g. https://mozilla.github.io/pdf.js/web/viewer.html
 1. Enable vertical scrolling.
 2. Press the <kbd>End</kbd> key.
 3. Open the devtools and, using the DOM Inspector, notice how page 13 is *not* being pre-rendered.
2021-10-23 19:15:37 +02:00
Tim van der Meij
0aaa4e3dbe
Merge pull request #14156 from Snuffleupagus/escodegen-fork
Add support for modern ECMAScript `class` features
2021-10-23 19:12:44 +02:00
Tim van der Meij
e5d35a380a
Merge pull request #14178 from Snuffleupagus/update-browserslist
Update the `browserslist` database
2021-10-23 19:09:52 +02:00
Jonas Jenwald
2c27f54e4e Update the browserslist database
Following https://github.com/browserslist/browserslist#browsers-data-updating, since very recently warnings started to appear when running various gulp-tasks.
2021-10-23 10:07:18 +02:00
Jonas Jenwald
52372b9378
Merge pull request #14175 from brendandahl/smask-v2
Use a new method for handling soft masks.
2021-10-23 09:27:18 +02:00
Brendan Dahl
82681ea20c Track the clipping box and bounding box of the path.
This allows us to compose much smaller regions of soft
mask making them much faster. This should also allow
for further optimizations in the pattern code.

For example locally I see issue #6573 go from 55s
to 5s with this change.

Fixes #6573
2021-10-22 13:41:29 -07:00
Brendan Dahl
2d1f9ff7a3 Use a new method for handling soft masks.
The old method of handling soft masks had a number of issues where the temporary
drawing canvas and the suspended main canvas could get out of sync
(e.g. mismatched save/restores or clip state) or we could end up compositing at
the wrong time. A good example of things getting out sync is the reduced test
case in #9017.

To fix this I've changed two big things:

1) Duplicate all the needed graphics state from the temporary canvas to the
suspended main canvas. This ensure the canvases stay in sync so that when we
switch back to the main canvas the graphics state stack is the same
(e.g. transforms, clip paths).

2) Immediately composite after each drawing operation. This ensures that if
there's an active clip region that we'll still be able to composite the correct
portions of the canvas. Note: This solution could be avoided by using
getImageData and putImageData since those ignore clipping region, but this is
very very slow. Note2: I also think the old way of only compositing at the end
of the soft mask is incorrect and can lead to wrong colors if drawing over the
same region, but in practice this doesn't seem to matter much.

Fixes: #5781
Fixes: #5853
Fixes: #7267
Fixes: #7891
Fixes: #8403
Fixes: #8624
Fixes: #12798
Fixes: #13891
Fixes: #9017 (reduced test case)
Fixes: https://bugzilla.mozilla.org/show_bug.cgi?id=1703683
2021-10-22 13:41:21 -07:00
Jonas Jenwald
7216511fbf Convert TempImageFactory to a class, using static fields/methods
Please refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields
2021-10-22 22:01:19 +02:00
Jonas Jenwald
89785a23f3 Convert Metadata to use private class fields
Please refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields
2021-10-22 22:01:19 +02:00
Jonas Jenwald
00f8fab8a5 Add support for modern ECMAScript class features
With ESLint 8 we should now finally be able to start using modern `class` features, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields

However, while both ESLint and Acorn now support this, it unfortunately turns out that Escodegen (which we use during building) still lack the necessary support. Looking at https://github.com/estools/escodegen there's not been any updates since last year, and there's also open PRs adding support for these new `class` features.

To avoid blocking usage of these `class` features in the PDF.js code-base, in particular *private* fields/methods, this patch thus proposes that we (hopefully temporarily) switch to an `escodegen` fork that has the necessary support; please see https://www.npmjs.com/package/@javascript-obfuscator/escodegen

While I have no reason to doubt the security of the `escodegen` fork, this patch nonetheless pins the version number. Furthermore, I've also diffed the output of the two `.js`-files in this forked package against the original files without finding anything that looks immediately "dangerous".
2021-10-22 22:01:17 +02:00