Commit Graph

11401 Commits

Author SHA1 Message Date
Jonas Jenwald
dd4620530d Change PDFSidebar.switchView to act as a wrapper for a "private" PDFSidebar._switchView method
The new "private" method will return a boolean, indicating if the `sidebarviewchanged` event was dispatched, thus allowing some simplification of the `PDFSidebar.setInitialView` method.
2019-02-02 10:21:16 +01:00
Tim van der Meij
291e62b41e
Merge pull request #10508 from Snuffleupagus/issue-8276
Do the final text scaling correctly in `flushTextContentItem` (issue 8276)
2019-01-29 22:46:36 +01:00
Jonas Jenwald
2b0b6178f7 Clean-up after the gets operatorList with JPEG image (issue 4888) unit-test
This unit-test wasn't destroying the `loadingTask` when complete, as it should have done.
2019-01-29 15:24:08 +01:00
Jonas Jenwald
6f94a05a29 Do the final text scaling correctly in flushTextContentItem (issue 8276)
It's necessary to take into account whether or not the text is vertical, to avoid either the textContent `width` or `height` becoming incorrect.
2019-01-29 15:24:04 +01:00
Tim van der Meij
55b12f5fd9
Merge pull request #10504 from Snuffleupagus/eslint-no-useless-catch
Enable the `no-useless-catch` ESLint rule
2019-01-28 22:37:14 +01:00
Jonas Jenwald
86472e9981 Enable the no-useless-catch ESLint rule
See https://eslint.org/docs/rules/no-useless-catch
2019-01-28 11:00:09 +01:00
Tim van der Meij
1f3e7700d2
Merge pull request #10499 from Snuffleupagus/renderTask-error-cleanup
Attempt to clean-up/restore pending rendering operations when errors occurs while a `RenderTask` runs (PR 10202 follow-up)
2019-01-27 15:12:59 +01:00
Tim van der Meij
d03d990e2e
Merge pull request #10501 from Snuffleupagus/getVisibleElements-avoid-unnecessary-backtrack
In `getVisibleElements`, check `firstVisibleElementInd` rather than `numViews` before backtracking (PR 10443 follow-up)
2019-01-27 15:06:13 +01:00
Jonas Jenwald
b50a512660 In getVisibleElements, check firstVisibleElementInd rather than numViews before backtracking (PR 10443 follow-up)
When `firstVisibleElementInd === 0`, regardless of the number of views, there's no reason to attempt to backtrack at all since it's never possible to find an element before the *first* one anyway.
2019-01-27 14:57:11 +01:00
Jonas Jenwald
5081063b9e Attempt to clean-up/restore pending rendering operations when errors occurs while a RenderTask runs (PR 10202 follow-up)
This piggybacks of the existing `cancel` functionality, to ensure that any pending operations are closed *and* that any temporary canvases are actually being removed.

Also simplifies `finishPaintTask` in `PDFPageView.draw` slightly, by converting it to an async function.
2019-01-26 16:02:51 +01:00
Tim van der Meij
40863eb275
Merge pull request #10489 from Snuffleupagus/single-page-scrollIntoView
Move more code/methods into `BaseViewer`, and simplify the `PDFSinglePageViewer._scrollIntoView` method slightly
2019-01-25 23:09:09 +01:00
Tim van der Meij
1eee1c5d2e
Merge pull request #10494 from Snuffleupagus/ColorSpace-isDefaultDecode
Reduce unnecessary duplication of the `isDefaultDecode` methods on `ColorSpace` instances
2019-01-25 22:43:28 +01:00
Jonas Jenwald
29f36d7a1b Reduce unnecessary duplication of the isDefaultDecode methods on ColorSpace instances
The recent PR 10482 made me realize that I missed an opportunity for simplification when doing the class conversion of this code in PR 10007.
2019-01-25 08:53:08 +01:00
Tim van der Meij
e2701d5422
Merge pull request #10482 from janpe2/indexed-decode
Implement Decode entry in Indexed images
2019-01-24 23:46:55 +01:00
Tim van der Meij
0d3c8d86a2
Merge pull request #10492 from Snuffleupagus/issue-10491
Ensure that `XRef.indexObjects` can handle object numbers with zero-padding (issue 10491)
2019-01-24 23:46:26 +01:00
Jonas Jenwald
41fbc71ef9 Ensure that XRef.indexObjects can handle object numbers with zero-padding (issue 10491)
All objects in the PDF document follow this pattern:
```
0000000001 0 obj
<<
% Some content here...
>>
endobj
0000000002 0 obj
<<
% More content here...
endobj

```
2019-01-24 22:37:18 +01:00
Jonas Jenwald
48e4adf770 Try to simplify the PDFSinglePageViewer._scrollIntoView method slightly, by unconditionally ensuring that rendering always occurs 2019-01-24 12:01:07 +01:00
Jonas Jenwald
06cda4c2e7 Move additional code/methods into BaseViewer and have the extending classes override/extend methods as necessary
This attempts to provide more "default" methods in the base class, in order to reduce unnecessary duplication and to improve self-documentation of the `BaseViewer` class slightly.
The following changes are made (in no particular order):
 - Have `BaseViewer` implement the `_scrollIntoView` method, and *extend* it as necessary in `PDFViewer`/`PDFSinglePageViewer`.
 - Simply inline the `BaseViewer._resizeBuffer` method, in `BaseViewer.update`, since there's only one call-site at this point.
 - Provide a default implementation of `_isScrollModeHorizontal` in `BaseViewer`, and have `PDFSinglePageViewer` override it.
 - Provide a default implementation of `_getVisiblePages`, and have `PDFViewer` extend it and `PDFSinglePageViewer` override it.
2019-01-24 10:31:06 +01:00
Tim van der Meij
9128335c4d
Merge pull request #10484 from Snuffleupagus/rm-mozcentral-streams
Stop bundling the `ReadableStream` polyfill in MOZCENTRAL builds (PR 10470 follow-up)
2019-01-23 22:30:42 +01:00
Tim van der Meij
f3da413ea5
Merge pull request #10483 from Snuffleupagus/mobile-viewer-PDFHistory-init
Update the `mobile-viewer` example to use the new `PDFHistory.initialize` format (PR 10423 follow-up)
2019-01-23 22:20:14 +01:00
Jonas Jenwald
249b199ff1 Stop bundling the ReadableStream polyfill in MOZCENTRAL builds (PR 10470 follow-up)
Based on the discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1521413, this patch simply removes the `ReadableStream` polyfill completely from MOZCENTRAL builds.

With this patch, the size of the `gulp mozcentral` build target is thus further reduced (building on PR 10470):

|       | `build/mozcentral`
|-------|-------------------
|master |   3 339 666
|patch  |   3 209 572
2019-01-23 20:33:20 +01:00
Jonas Jenwald
f06b2e4e9f Update the mobile-viewer example to use the new PDFHistory.initialize format (PR 10423 follow-up) 2019-01-23 15:27:19 +01:00
Jani Pehkonen
26121177ab Implement Decode entry in Indexed images 2019-01-22 22:51:04 +02:00
Brendan Dahl
d614cabfa0
Merge pull request #10480 from Snuffleupagus/debugger-FontInspector
[Regression] Fix the `FontInspector` in the PDFBug debugging tools
2019-01-22 10:02:58 -08:00
Jonas Jenwald
6a4dae927c [Regression] Fix the FontInspector in the PDFBug debugging tools
The `FontInspector` was completely broken by PR 10197, and trying to select a particular font (using the checkboxes) or clicking on a piece of text currently does nothing.
2019-01-22 13:22:36 +01:00
Tim van der Meij
f26129de26
Merge pull request #10474 from timvandermeij/updates
Update translations and packages
2019-01-20 16:40:25 +01:00
Tim van der Meij
810dbeb4e5
Update packages 2019-01-20 16:34:24 +01:00
Tim van der Meij
a84541b271
Update translations 2019-01-20 16:32:35 +01:00
Tim van der Meij
78eb73004f
Merge pull request #10473 from Snuffleupagus/array-from
Add an `Array.from` polyfill, using core-js, and remove some compatibility hacks from the `src/display/content_disposition.js` file
2019-01-20 14:41:39 +01:00
Jonas Jenwald
01d624f6a0 Add an Array.from polyfill, using core-js, and remove some compatibility hacks from the src/display/content_disposition.js file 2019-01-20 08:49:20 +01:00
Tim van der Meij
66acc7397f
Merge pull request #10470 from Snuffleupagus/mozcentral-streams
Try to, completely, avoid loading the `ReadableStream` polyfill in MOZCENTRAL builds
2019-01-19 21:22:18 +01:00
Tim van der Meij
a908702fad
Merge pull request #10471 from timvandermeij/metadata-unit-test
Implement a unit test for metadata parsing to ensure that it's not vulnerable to the billion laughs attack
2019-01-19 20:45:00 +01:00
Tim van der Meij
c4fe4087d3
Implement a unit test for metadata parsing to ensure that it's not vulnerable to the billion laughs attack 2019-01-19 19:54:08 +01:00
Tim van der Meij
269168d053
Merge pull request #10467 from Snuffleupagus/less-indexOf
Convert some usage of `indexOf` to `startsWith`/`includes` where applicable
2019-01-19 15:23:37 +01:00
Jonas Jenwald
480110625a Try to, completely, avoid loading the ReadableStream polyfill in MOZCENTRAL builds
With https://bugzilla.mozilla.org/show_bug.cgi?id=1505122 landing in Firefox 65, the native `ReadableStream` implementation is now enabled by default in Firefox.

Obviously it would be nice to simply stop bundling the polyfill in MOZCENTRAL builds altogether, however given that it's still possible to disable[1] `ReadableStream` this is probably not a good idea just yet.
Nonetheless, now that native support is available, it seems unnecessary (and wasteful) to keep bundling the polyfill twice[2] in MOZCENTRAL builds. Hence this patch, which contains a suggest approach for packing the polyfill in a *separate* file which is then *only* loaded if/when needed.

With this patch, the size of the `gulp mozcentral` build target is thus reduced accordingly:

|       | `build/mozcentral`
|-------|-------------------
|master |   3 461 089
|patch  |   3 340 268

Besides the PDF.js files taking up less space in Firefox this way, the additional benefit is that there's (by default) less code that needs to be loaded and parsed when the PDF Viewer is used which also cannot hurt.

---
[1] In `about:config`, by toggling the `javascript.options.streams` preference.

[2] Once in the `build/pdf.js` file, and once in the `build/pdf.worker.js` file.
2019-01-19 09:05:01 +01:00
Tim van der Meij
1bb5ca0588
Merge pull request #10466 from Snuffleupagus/BaseViewer-update
Move/refactor the code in the `BaseViewer.update` method to reduce duplication in the extending classes
2019-01-19 00:04:31 +01:00
Jonas Jenwald
24a688d6c6 Convert some usage of indexOf to startsWith/includes where applicable
In many cases in the code you don't actually care about the index itself, but rather just want to know if something exists in a String/Array or if a String starts in a particular way. With modern JavaScript functionality, it's thus possible to remove a number of existing `indexOf` cases.
2019-01-18 17:57:41 +01:00
Jonas Jenwald
343f488daa Move/refactor the code in the BaseViewer.update method to reduce duplication in the extending classes
Since most of the important rendering code is already (almost) identical between `PDFViewer.update` and `PDFSinglePageViewer.update`, it's possible to further reduce duplication by moving the code into `BaseViewer.update` instead.
2019-01-18 15:06:21 +01:00
Tim van der Meij
cdbc33ba06
Merge pull request #10457 from Snuffleupagus/metadata-tests
When parsing Metadata, attempt to remove "junk" before the first tag (PR 10398 follow-up)
2019-01-16 23:03:39 +01:00
Tim van der Meij
697b3d2f49
Merge pull request #10461 from Snuffleupagus/pr-10423
Avoid setting incorrect document URLs, in IE 11, when the browser history is updated (PR 10423 follow-up)
2019-01-16 22:51:50 +01:00
Tim van der Meij
f711df583a
Merge pull request #10462 from Snuffleupagus/pr-10152
Tweak the `DOMTokenList.toggle` polyfill (issue 10460)
2019-01-16 22:44:20 +01:00
Jonas Jenwald
68ad3e8e9d Tweak the DOMTokenList.toggle polyfill (issue 10460) 2019-01-16 20:15:44 +01:00
Jonas Jenwald
ffe798137f Avoid setting incorrect document URLs, in IE 11, when the browser history is updated (PR 10423 follow-up)
Apparently in IE 11 when `history.{pushState, replaceState}` is called, there's actually a difference between not providing the *third* argument vs providing it set implicitly to `undefined`. It appears that in IE 11 it's actually being stringified, rather than ignored, which seems completely wrong (obviously other browsers aren't affected, so no surprises there).

This is yet another reason why I think the feature itself was a really bad idea, since it now requires extra/duplicated code just to prevent weird/incorrect URL behaviour in crappy browsers.
2019-01-16 19:26:44 +01:00
Jonas Jenwald
9f45f8dfda When parsing Metadata, attempt to remove "junk" before the first tag (PR 10398 follow-up)
This will allow the Metadata to be successfully extracted from the PDF file in issue 10395.
Furthermore, this patch also fixes a bug in `Metadata.get` which causes the method to return `null` rather than an empty string or zero (since either ought to be allowed).
2019-01-16 12:44:27 +01:00
Jonas Jenwald
5d90224409 Add a unit-test for issue 10395 (PR 10398 follow-up) 2019-01-16 11:30:36 +01:00
Tim van der Meij
5cb00b7967
Merge pull request #10443 from Snuffleupagus/getVisibleElements-fixes
Prevent `TypeError: views[index] is undefined` being throw in `getVisibleElements` when the viewer, or all pages, are hidden
2019-01-13 15:41:48 +01:00
Tim van der Meij
5efc902fb8
Merge pull request #10447 from timvandermeij/bad-request
Handle malformed URIs as bad requests in the development webserver
2019-01-13 15:09:17 +01:00
Tim van der Meij
6279fc601a
Handle malformed URIs as bad requests in the development webserver
Fixes #10445 (found by Dhiraj Mishra).
2019-01-13 14:57:20 +01:00
Jonas Jenwald
b2235ec9c4 Add a unit-test to check that the sortByVisibility parameter, in getVisibleElements, works correctly 2019-01-13 11:34:38 +01:00
Jonas Jenwald
9743708a24 Prevent TypeError: views[index] is undefined being throw in getVisibleElements when the viewer, or all pages, are hidden
Previously a couple of different attempts at fixing this problem has been rejected, given how *crucial* this code is for the correct function of the viewer, since no one has thus far provided any evidence that the problem actually affects the default viewer[1] nor an example using the viewer components directly (without another library on top).
The fact that none of the prior patches contained even a *simple* unit-test probably contributed to the unwillingness of a reviewer to sign off on the suggested changes.

However, it turns out that it's possible to create a reduced test-case, using the default viewer, that demonstrates the error[2]. Since this utilizes a hidden `<iframe>`, please note that this error will thus affect Firefox as well.
Note that while errors are thrown when the hidden `<iframe>` loads, the default viewer doesn't break completely since rendering does start working once the `<iframe>` becomes visible (although the errors do break the initial Toolbar state).

Before making any changes here, I carefully read through not just the immediately relevant code but also the rendering code in the viewer (given it's dependence on `getVisibleElements`). After concluding that the changes should be safe in general, the default viewer was tested without any issues found. (The above being much easier with significant prior experience of working with the viewer code.)
Finally the patch also adds new unit-tests, one of which explicitly triggers the relevant code-path and will thus fail with the current `master` branch.

This patch also makes `PDFViewerApplication` slightly more robust against errors during document opening, to ensure that viewer/document initialization always completes as expected.
Please keep in mind that even though this patch prevents an error in `getVisibleElements`, it's still not possible to set the initial position/zoom level/sidebar view etc. when the viewer is hidden since rendering and scrolling is completely dependent[3] on being able to actually access the DOM elements.

---
[1] And hence the PDF Viewer that's built-in to Firefox.

[2] Copy the HTML code below and save it as `iframe.html`, and place the file in the `web/` folder. Then start the server, with `gulp server`, and navigate to http://localhost:8888/web/iframe.html

```html
<!DOCTYPE html>
<html>
  <head>
    <title>Iframe test</title>

    <script>
      window.onload = function() {
        const button = document.getElementById('button1');
        const frame = document.getElementById('frame1');

        button.addEventListener('click', function(evt) {
          frame.hidden = !frame.hidden;
        });
      };
    </script>
  </head>

  <body>
    <button id="button1">Toggle iframe</button>
    <br>
    <iframe id="frame1" width="800" height="600" src="http://localhost:8888/web/viewer.html" hidden="true"></iframe>
  </body>
</html>
```

[3] This is an old, pre-exisiting, issue that's not relevant to this patch as such (and it's already being tracked elsewhere).
2019-01-13 11:34:24 +01:00