Commit Graph

13217 Commits

Author SHA1 Message Date
Jonas Jenwald
09f79ffa92 Attempt to handle collapsed outline items, in the default viewer, according to the specification (issue 12704, PR 10890 follow-up)
This patch *attempts* to actually implement what's described for the `Count`-entry in the PDF specification, see https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.2095911, which I mostly ignored back in PR 10890 since it seemed unnecessarily complicated[1].

Besides issue 12704, I've also tested a couple of other documents (e.g. the PDF specification) and these changes don't *seem* to break anything else; additional testing would be helpful though!

---
[1] At the time, all PDF documents that I tested worked even with a very simple approach and I thus hoped that it'd would suffice.
2020-12-09 20:48:36 +01:00
Brendan Dahl
b194c820bf
Merge pull request #12634 from calixteman/aform
JS -- Add aform functions
2020-12-07 11:35:23 -08:00
Calixte Denizet
0f899edfc8 JS -- Add aform functions
* These functions aren't in the PDF specs but seems to be widely used
 * So the specs for these functions are:
   * http://www.sfu.ca/~wcs/ForGraham/Aladdin%20stuff/Acrobat%20Reader%205.0/Contents/MacOS/JavaScripts/AForm.js
   * pdfium source code
2020-12-07 19:37:34 +01:00
Tim van der Meij
d784af3f38
Merge pull request #12696 from timvandermeij/annotation-quadpoints
Fix non-standard quadpoints orders for annotations
2020-12-06 16:52:33 +01:00
Tim van der Meij
3df72c3fac
Merge pull request #12695 from Snuffleupagus/sandbox-build
Various clean-up and improvements related to `pdf.sandbox.js` building, and the related default-viewer functionality
2020-12-06 16:51:41 +01:00
Tim van der Meij
012e15f7a3
Fix non-standard quadpoints orders for annotations
This change requires us to use valid quadpoints arrays in the existing
unit tests too due to the normalization.
2020-12-06 16:02:41 +01:00
Jonas Jenwald
b2dfb55136 Re-factor the scripting getter in GENERIC-builds, since using the same sandbox for *multiple* PDF documents seems highly questionable
Similar to the previous patch, the GENERIC default viewer is capable of opening more than *one* PDF document and we should ensure that we handle that case correctly.
2020-12-06 14:21:49 +01:00
Jonas Jenwald
1e007f9285 Actually remove a scripting-instance, and its global events, upon document closing
I was actually quite surprised to find that, despite the various `scripting`-getters implementing `destroySandbox` methods, there were no attempts at actually cleaning-up either the "sandbox" or removing the globally registered event listeners.
2020-12-06 14:20:43 +01:00
Jonas Jenwald
f4d8a427f0 Ensure that the *correct* PDF document is still active after *every* asynchronous API-call in PDFViewerApplication._initializeJavaScript
This patch also changes the method to skip *all* data fetching when "enableScripting" isn't active. Finally, simplifies some event-data accesses in the "updateFromSandbox" listener.
2020-12-06 14:18:10 +01:00
Jonas Jenwald
1f2f8c907b Tweak the "filesize" handling in PDFViewerApplication._initializeJavaScript
Another possible option here could be to use the `contentLength`, when it exists, and then using e.g. a custom event to always update the "filesize" in the sandbox "after the fact" with the result of the `getDownloadInfo`-call.
2020-12-06 13:08:36 +01:00
Jonas Jenwald
bfdb39a1e6 Stop re-fetching the metadata unconditionally in PDFViewerApplication._initializeJavaScript
We can easily avoid unnecessary API-calls here, since most of the time the `metadata` will already be available here. In the *rare* case that it's not available, we can simply wait for the existing `getMetadata`-call to resolve.
2020-12-06 12:42:56 +01:00
Jonas Jenwald
f8ea83609f Dispatch a metadataloaded event once the PDFViewerApplication._initializeMetadata method is done
This will be useful in the following patch, and note that there's also an old issue (see 5765) which asked for such an event. However, given that the use-case wasn't *clearly* specified, and that we didn't have an internal use for it at the time it wasn't implemented.

Also, ensure that all of the metadata-related properties are actually reset when the document is closed.
2020-12-06 12:30:33 +01:00
Jonas Jenwald
c549069ebd Replace the testMode parameter in src/pdf.sandbox.js with a constant, set using the pre-processor
This simplifies not just this code, but the unit-tests as well, and should be sufficient as far as I can tell.
Note also that currently, in the *built* `pdf.sandbox.js` file, there's even a line reading `testMode = testMode && false;` because of an accidentally flipped pre-processor statement.

Finally, in the `scripting_spec.js` unit-test, defines `sandboxBundleSrc` at the top of the file to make it easier to find and/or change it when necessary.
2020-12-05 23:04:34 +01:00
Jonas Jenwald
c39f1aedb2 Re-implement working dev-sandbox/watch-dev-sandbox gulp-tasks
Compared to the, previously removed, `sandbox`/`watch-sandbox` gulp-tasks, these ones should work even when run against an non-existent/empty `build`-folder.

Also, to ensure that the development viewer actually works out-of-the-box, `gulp server` will now also include `gulp watch-dev-sandbox` to remove the need to *manually* invoke the build-tasks.

Finally, this patch also removes the `web/devcom.js` file since it shouldn't actually be needed, assuming that the "sandbox"-loading code in the `web/genericcom.js` file is actually *correctly* implemented.
2020-12-05 23:04:34 +01:00
Jonas Jenwald
13d7244529 Re-factor how the pdf.sandbox.js file is built (PR 12604 follow-up)
The way that the `pdf.sandbox.js` building was implemented feels all kinds of inconsistent/wrong, and it "sticks out" quite a bit when compared to the rest of the `gulpfile.js`. This patch thus attempts to improve the current situation slightly, to hopefully make future maintenance easier.

One thing that strikes you, pretty immediately, when looking at PR 12604 is that the two new `gulp`-tasks added (i.e. `sandbox` and `watch-sandbox`) don't even work!?
The reason for this is that they implicitly dependent upon the result of the `buildnumber`-task, which isn't listed as a dependency. (Try running `gulp clean` *first*, and invoking any of the new `gulp`-tasks will inevitably fail.)

Furthermore, there's another (potentially big) problem with the implementation of e.g. the `gulp sandbox` task, since it doesn't actually wait for all building to complete before the task is considered as "done". This has the potential to cause all sorts of subtle bugs elsewhere, and the fact that things even "work" as-is can probably be attributed mostly to luck.

Unfortunately there's no *perfect* way to improve things here, since the `pdf.sandbox.js` file depends on including the `pdf.scripting.js` file as a string, however I firmly believe that improvements are still possible here.
To that end, this patch updates all relevant build-targets to create a *temporary* `pdf.scripting.js` file as part of the setup in the `gulp`-tasks, and then reads that file during the `pdf.sandbox.js` building.
This at least allows us to bring all of this "sandbox"-build code much more in-line with the existing build-system.
2020-12-05 23:04:32 +01:00
Jonas Jenwald
1f29d27474 Change how we're passing pdf.sandbox.js-specific options to createWebpackConfig in gulpfile.js
Given the somewhat "specialized" nature of the `pdf.sandbox.js` building, it ought to be possible to re-factor how some of the options are handled.
Note in particular that the `gulp-strip-comments` dependency seems somewhat unncessary, since the *main* source of comments are just the default license header. Hence I seems much more reasonable to simply not include that to begin with, rather than removing it after the fact (the few remaining Webpack-related should be few/small enough to not really matter much in practice).

This way we're able to further reduce the special-casing related to the `pdf.sandbox.js`-building, which will make future changes/maintenance easier by bringing this code more in-line with existing patterns in `gulpfile.js`.

(If we really want to reduce the filesize, we might want to consider always minifying the `GENERIC`-build of the `pdf.sandbox.js` file.)
2020-12-05 22:44:48 +01:00
Tim van der Meij
e3b6a9fb23
Implement quadpoints rendering for link annotations
Each quadrilateral needs to have its own link element, so the first
quadrilateral can use the already created element, but the next
quadrilaterals need to clone that element.
2020-12-05 21:39:38 +01:00
Tim van der Meij
7be4a14d87
Move documentation of the render methods to the AnnotationElement class
Not only does this reduce boilerplate since the documentation is the
same for all annotation classes, it also wasn't correct for the
annotation types that support quadpoints since they return an array of
section elements instead of a single one.
2020-12-05 20:16:40 +01:00
Tim van der Meij
cb422a80b0
Move quadrilateral rendering logic into a method on the AnnotationElement class
Doing so avoids some code duplication.
2020-12-05 20:07:17 +01:00
Tim van der Meij
0273080031
Move quadrilateral creation logic to the constructor of the AnnotationElement class
Using an object for the various constructor options makes extensions
easier and makes the code self-documenting.
2020-12-05 20:01:07 +01:00
Jonas Jenwald
d742e3cde8 Actually utilize the PDF.js build-system fully when bundling the pdf.sandbox.js file
There's no good reason, as far as I can tell, to use search-and-replace to include the *stringified* `pdf.scripting.js` file in the built `pdf.sandbox.js` file. Instead we could, and even should, utilize the existing `PDFJSDev.eval(...)`-functionality, which is not only simpler but will also be more efficient as well (no need for a regular expression).
2020-12-05 11:15:11 +01:00
Jonas Jenwald
715b8aa389 Move, and rename, the src/scripting_api/quickjs-sandbox.js file to src/pdf.sandbox.js
The current location feels somewhat strange, and also inconsistent with the existing way that bundling is done.

Finally, add the version/build numbers at the top of the *built* `pdf.sandbox.js` files, since all other built files include that information given that it's often helpful to be able to easily determine the *exact* version.
2020-12-05 11:15:11 +01:00
Tim van der Meij
54ca67d628
Merge pull request #12693 from Snuffleupagus/mv-ColorConverters
[Regression] Prevent the *built* `pdf.scripting.js`/`pdf.sandbox.js` files from accidentally including most of the main-thread code (PR 12631 follow-up)
2020-12-04 20:49:39 +01:00
Jonas Jenwald
155c17c99a [Regression] Prevent the *built* pdf.scripting.js/pdf.sandbox.js files from accidentally including most of the main-thread code (PR 12631 follow-up)
*This is a recent regression, which I stumbled upon while working on cleaning-up the gulpfile related to `pdf.sandbox.js` building.*

By placing the `ColorConverters` functionality in the `src/display/display_utils.js` file, you end up including a *significant* chunk of the `pdf.js` file in the built `pdf.scripting.js`/`pdf.sandbox.js` files.
Given that I cannot imagine that this was actually intended, since it inflates the built files with unnecessary/unused code, this moves `ColorConverters` to a new file instead (thus breaking the dependencies).

To hopefully reduce the risk future bugs, along these lines, a big comment is also placed at the top of the new file.
Finally, the `ColorConverters` is converted to a class with static methods, since this felt slightly cleaner overall.
2020-12-04 14:17:26 +01:00
calixteman
c1f41df4ad
Merge pull request #12685 from calixteman/12684
Fix issue #12684: replace bitwise ORs by ORs
2020-12-03 14:45:56 +01:00
Calixte Denizet
d4f4b43d29 Fix issue #12684: replace bitwise ORs by ORs 2020-12-02 23:02:11 +01:00
Tim van der Meij
a618b02e62
Merge pull request #12682 from Snuffleupagus/findbar-notFound
[Generic viewer] Re-factor how the `notFound` appearance is set on the "findInput" in the `PDFFindBar`
2020-12-02 22:00:41 +01:00
Tim van der Meij
7a60824f2e
Merge pull request #12681 from Snuffleupagus/pr-8808-update-test
Update the link for the "pr8808" test-case (issue 12680)
2020-12-02 21:53:24 +01:00
Tim van der Meij
7325382db3
Merge pull request #12679 from Snuffleupagus/pr-12666-followup
Fix the `treeitem-expanded`/`treeitem-collapsed` images in dark-mode (PR 12666 follow-up)
2020-12-02 21:51:02 +01:00
Jonas Jenwald
313ee28436 [Generic viewer] Re-factor how the notFound appearance is set on the "findInput" in the PDFFindBar
Rather than having two slightly different ways of setting the pending/notFound appearance on the "findInput", we can simply use "data-status" in both cases since they're obviously mutually exclusive.
2020-12-02 15:23:20 +01:00
Jonas Jenwald
dc84c8a02a Update the link for the "pr8808" test-case (issue 12680)
This seems like a very minor issue, since in general we can't really help if domains are blocked from certain networks, however in this particular case I suppose that using the Internet Archive should work.
2020-12-02 15:06:09 +01:00
Jonas Jenwald
488a81a7bc Fix the treeitem-expanded/treeitem-collapsed images in dark-mode (PR 12666 follow-up)
I completely missed updating these in PR 12666; sorry about that!
2020-12-02 11:48:32 +01:00
Brendan Dahl
956fcab967
Merge pull request #12631 from calixteman/app
JS -- Implement app object
2020-12-01 16:50:16 -08:00
Tim van der Meij
db6b67c072
Merge pull request #12673 from calixteman/split
Split underline, strikeout, squiggly annotions div into multiple divs
2020-12-01 23:45:13 +01:00
Tim van der Meij
b43b5caf83
Merge pull request #12666 from Snuffleupagus/rm-dark-images
Use the same SVG images, in the default viewer, regardless of the CSS theme
2020-12-01 23:31:20 +01:00
Calixte Denizet
830070ca41 Split underline, strikeout, squiggly annotions div into multiple divs
* Follow up of #12505
 * Fix bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1679696
2020-12-01 16:04:48 +01:00
Jonas Jenwald
f2ec546cbb Use the same SVG images, in the default viewer, regardless of the CSS theme
As mentioned in https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support, PDF.js version `2.6.347` is the last release with IE 11/Edge support.
Hence we should now be able to reduce unnecessary duplication in the default viewer image resources, note the files in the `web/images/` folder with a `-dark` suffix, by using only *one* SVG-image for each icon and letting the `background-color` depend on the CSS theme instead.

For the `gulp mozcentral` build-target, the resulting `web/images/` folder is reduced from `43 997` to `28 566` bytes (~35 percent).

*Please note:* I don't really know if this implementation is necessarily the *best* solution, but it seems to work well enough in e.g. Firefox Nightly and Google Chrome Beta as far as my testing goes.
2020-12-01 11:45:09 +01:00
Tim van der Meij
43550be484
Merge pull request #12665 from Snuffleupagus/update-packages
Update packages and translations
2020-11-29 15:35:43 +01:00
Jonas Jenwald
c42029489e Run gulp lint --fix, to account for changes in Prettier version 2.2.1
Please refer to https://github.com/prettier/prettier/blob/master/CHANGELOG.md#221 for additional details.
2020-11-29 10:01:46 +01:00
Jonas Jenwald
cd2e6d803a Update l10n files 2020-11-29 09:50:36 +01:00
Jonas Jenwald
58f865404c Fix (some) vulnerabilities reported by npm audit
This was done automatically, using the `npm audit fix` command.
2020-11-29 09:47:33 +01:00
Jonas Jenwald
e15c63abc7 Update npm packages 2020-11-29 09:43:20 +01:00
Tim van der Meij
e072f1db6b
Merge pull request #12652 from calixteman/quickjs_followup
Add a README about quickjs-eval.js file (build and license)
2020-11-25 21:58:03 +01:00
Tim van der Meij
256068556d
Merge pull request #12662 from Snuffleupagus/issue-12402
Check the top-level /Pages dictionary when finding the trailer in `XRef.indexObjects` (issue 12402)
2020-11-25 21:54:41 +01:00
Tim van der Meij
1bde38af38
Merge pull request #12655 from calixteman/12654
Parenthesis in names are not escaped when saving
2020-11-25 21:51:17 +01:00
Tim van der Meij
672e2f1832
Merge pull request #12656 from mozilla/dependabot/npm_and_yarn/highlight.js-9.18.5
Bump highlight.js from 9.13.1 to 9.18.5
2020-11-25 21:28:45 +01:00
Jonas Jenwald
8a132f584d Check the top-level /Pages dictionary when finding the trailer in XRef.indexObjects (issue 12402)
In addition to the existing /Root and /Pages validation, also check that the /Pages-entry actually is a dictionary and that it has a valid /Count-entry.
This way we can avoid picking a trailer candidate which e.g. the `Catalog.numPages` getter will just end up rejecting, thus breaking PDF document loading completely.
2020-11-25 15:14:53 +01:00
Calixte Denizet
18b525de2e Parenthesis in names are not escaped when saving 2020-11-25 12:28:12 +01:00
dependabot[bot]
b6fdade6c6
Bump highlight.js from 9.13.1 to 9.18.5
Bumps [highlight.js](https://github.com/highlightjs/highlight.js) from 9.13.1 to 9.18.5.
- [Release notes](https://github.com/highlightjs/highlight.js/releases)
- [Changelog](https://github.com/highlightjs/highlight.js/blob/9.18.5/CHANGES.md)
- [Commits](https://github.com/highlightjs/highlight.js/compare/9.13.1...9.18.5)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-24 23:29:33 +00:00
Calixte Denizet
8413a5865a Add a README about quickjs-eval.js file (build and license) 2020-11-24 13:54:04 +01:00