Commit Graph

11504 Commits

Author SHA1 Message Date
Jonas Jenwald
d32321d84f Convert PDFObjects, in src/display/api.js, to an ES6 class
Also changes all occurrences of `var` to `const`, and marks internal properties/methods as "private".
2018-11-08 10:11:40 +01:00
Tim van der Meij
3e342554d1
Merge pull request #10228 from morille/patch-2
Don't detect nw.js as node.js
2018-11-07 23:51:01 +01:00
Tim van der Meij
744a693554
Merge pull request #10219 from Snuffleupagus/ps-parser-class
Convert `src/core/ps_parser.js` to use ES6 classes
2018-11-07 23:15:01 +01:00
Romain Petit
13b0ca6b2a Don't detect nw.js as node.js
nw.js is chrome plus nodejs.
It will succeed everywhere chrome succeeds, but fail in many cases where nodejs succeeds (see issue 9071).
So it's safer to consider it as a browser context rather than a nodejs context.

Make travis happy again

CS

Readability + Explanation

The relevant portion of the NW.js documentation:
http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context

Added full link to relevant doc.
2018-11-07 11:14:22 +01:00
Jonas Jenwald
a963d139dc Convert src/core/ps_parser.js to use ES6 classes
Besides being a fairly small and self-contained file, this code also shows a possible way of defining static constants on classes.
2018-11-03 17:43:06 +01:00
Tim van der Meij
45758dd2d5
Merge pull request #10217 from Snuffleupagus/findagain-position-reset
For repeated 'findagain' operations, attempt to reset the search position if the user has e.g. scrolled in the document (issue 4141)
2018-11-03 16:05:41 +01:00
Jonas Jenwald
d805d799ff For repeated 'findagain' operations, attempt to reset the search position if the user has e.g. scrolled in the document (issue 4141)
Currently we'll only attempt to start from the current page when a new search is done, however for 'findagain' operations we'll always continue from the last match position.
This could easily lead to confusing behaviour if the user has scrolled to a completely different part of the document. In an attempt to improve this somewhat, for repeated 'findagain' operations, we'll instead reset the position to the current page when it's *absolutely* certain that the user has scrolled.

Note that this required adding a new `BaseViewer` method, and exposing that through `PDFLinkService`, in order to check if a given page is visible.
In an attempt to avoid issues, in custom implementations of `PDFFindController`, the code checks for the existence of the `PDFLinkService.isPageVisible` method *before* using it.
2018-11-03 12:03:11 +01:00
Jonas Jenwald
d7941b4ce7 Add a helper method, in PDFFindController, to determine if matches need to be re-calculated when a new search operation occurs 2018-11-03 11:52:48 +01:00
Jonas Jenwald
af99d1dc08 Attempt to improve readability of PDFFindController.executeCommand by (slightly) refactoring the code responsible for calling PDFFindController._nextMatch
Unfortunately the `PDFFindController.executeCommand` method has now become a bit more complicated than one would like, but hopefully this small change will improve the structure somewhat (especially for subsequent patches).
2018-11-03 11:48:40 +01:00
Tim van der Meij
ec76aa531e
Merge pull request #10202 from Snuffleupagus/issue-10200
Attempt to clean-up/restore pending rendering operations on `RenderTask.cancel` (issue 10200)
2018-11-02 23:11:47 +01:00
Tim van der Meij
f6bc93402e
Merge pull request #10096 from Snuffleupagus/rm-attachDOMEventsToEventBus
Remove the `attachDOMEventsToEventBus` functionality, since `EventBus` instances are able to re-dispatch events to the DOM (PR 10019, bug 1492849 follow-up)
2018-11-01 23:27:26 +01:00
Jonas Jenwald
4b9d0a67d2 Inline the 'scalechanging' event dispatching in BaseViewer._setScaleUpdatePages
With only *one* event now being dispatched when the scale changes, in combination with there only being two call-sites, it doesn't seem necessary to keep the helper method for dispatching the 'scalechanging' event.
2018-10-31 23:32:39 +01:00
Jonas Jenwald
e2e9657ed0 Remove the attachDOMEventsToEventBus functionality, since EventBus instances are able to re-dispatch events to the DOM (PR 10019, bug 1492849 follow-up)
This also removes the old 'pagechange'/'scalechange'/'documentload' events.
2018-10-31 23:32:39 +01:00
Tim van der Meij
7053b5a146
Merge pull request #10203 from Snuffleupagus/canvasInRendering-WeakSet
Change `canvasInRendering` to a `WeakSet` instead of a `WeakMap`
2018-10-31 22:59:20 +01:00
Tim van der Meij
bb5f261c58
Merge pull request #10201 from Snuffleupagus/find-less-updatePage
Reduce the number of redundant `updatetextlayermatches` events dispatched when calculating matches in `PDFFindController`
2018-10-31 22:29:40 +01:00
Jonas Jenwald
f23dba1c10 Change canvasInRendering to a WeakSet instead of a WeakMap
Note how nowhere in the code `canvasInRendering.get()` is ever called, and that this structure is really only used to store references to `<canvas>` DOM elements.
The reason for this being a `WeakMap` is probably because at the time we weren't using `core-js` polyfills yet, and since there already existed a manually implemented `WeakMap` polyfill it was probably simpler to use that.
2018-10-31 18:15:23 +01:00
Jonas Jenwald
f77b463339 Attempt to clean-up/restore pending rendering operations on RenderTask.cancel (issue 10200)
Please note that, given the lack of a runnable example, I'm not totally sure if this first of all is enough to *completely* address the issue as filed and second of all if we actually want this new behaviour.
2018-10-31 16:22:17 +01:00
Jonas Jenwald
014b7a3147 Reduce the number of redundant updatetextlayermatches events dispatched when calculating matches in PDFFindController
Currently `PDFFindController._calculateMatch` is (indirectly) dispatching an `updatetextlayermatches` event for every *single* page of the document. For short documents, such as the `tracemonkey` file, this probably doesn't matter too much, but for documents with a couple of thousand pages it seems unfortunate.

It shouldn't be necessary, in general, to dispatch `updatetextlayermatches` events here, since that's already being taken care of in `PDFFindController._updateMatch` which is always called when a match has been found.
However, when `highlightAll` is set we still need to ensure that pages which finished rendered *before* searching begun are updated correctly.
2018-10-31 16:05:12 +01:00
Tim van der Meij
42b7bb4751
Merge pull request #10190 from Snuffleupagus/_getCurrentVisiblePage
Add a helper method for `_getVisiblePages`, in `BaseViewer`, for the case where only a single page is displayed in the viewer
2018-10-29 23:19:32 +01:00
Tim van der Meij
74b5d0b022
Merge pull request #10196 from Snuffleupagus/findbarclose-findagain-highlightAll
[Regression] Ensure that "Highlight All" is propagated to all pages for 'findagain' events where the findbar was previously closed (PR 10100 follow-up)
2018-10-29 23:12:37 +01:00
Jonas Jenwald
96abb4bbe7 [Regression] Ensure that "Highlight All" is propagated to all pages for 'findagain' events where the findbar was previously closed (PR 10100 follow-up)
**STR:**
1. Open the default viewer, with the `tracemonkey` file.
2. Open the findbar, and search for "trace".
3. Enable the "Highlight All" option.
4. Close the findbar.
5. Re-open the findbar, and click on the "findNext" button.
6. Scroll down to the *second* page of the document.

**ER:**
Since "Highlight All" is active, all matches on the *second* page should be highlighted.

**AR:**
No matches are highlighted on the *second* page.
2018-10-29 19:50:29 +01:00
Jonas Jenwald
2a79bcbe45 Add a helper method for _getVisiblePages, in BaseViewer, for the case where only a single page is displayed in the viewer
This is relevant for e.g. `PDFSinglePageViewer`, and `PDFViewer` with Presentation Mode active.
By moving this code to a helper method in `BaseViewer`, it's thus possible to reduce the amount of duplicate code that currently needed in `PDFViewer` and `PDFSinglePageViewer`.
2018-10-28 14:59:31 +01:00
Tim van der Meij
991a574c60
Merge pull request #10184 from Snuffleupagus/findbarclose-abort
Ensure that matches are not scrolled into after the findbar has been closed (PR 10100 follow-up)
2018-10-28 14:01:03 +01:00
Tim van der Meij
04ce2afd4a
Merge pull request #10182 from Snuffleupagus/TextLayerBuilder-rm-findController-checks
Small clean-up of the search related methods in `TextLayerBuilder`
2018-10-28 13:45:01 +01:00
Tim van der Meij
a77ac5fa23
Merge pull request #10185 from Snuffleupagus/find-less-normalization
Reduce the number of redundant text normalization operations in `PDFFindController`
2018-10-28 13:31:15 +01:00
Tim van der Meij
ed4ac1bc67
Merge pull request #10162 from janpe2/svg-normalize-bbox
Normalize BBox of form XObjects in SVG back-end
2018-10-28 13:18:48 +01:00
Tim van der Meij
c76c9878be
Merge pull request #10188 from timvandermeij/download-button
Hide the beta version button on the website if there is only a stable version
2018-10-27 21:01:13 +02:00
Tim van der Meij
2b5bc6bcec
Hide the beta version button on the website if there is only a stable version 2018-10-27 20:57:01 +02:00
Tim van der Meij
31bff2d950
Merge pull request #10187 from timvandermeij/bump
Bump versions in `pdfjs.config`
2018-10-27 17:02:11 +02:00
Tim van der Meij
7c6c56214f
Bump versions in pdfjs.config 2018-10-27 16:55:23 +02:00
Jonas Jenwald
5dc12f9a6d Only normalize the search query once, in `PDFFindController, for every page being searched
For a short document, such as e.g. the `tracemonkey` file, this repeated normalization won't matter much, but for documents with a couple of thousand pages it seems completely unnecessary (and wasteful) to keep repeating the normalization whenever for every single page.
2018-10-27 11:44:24 +02:00
Jonas Jenwald
84ae4f9a5e Only normalize the text-content once, in PDFFindController, and not on every new search operation
Currently the text-content is normalized every time that a new search operation is started, which seems completely useless considering that the "raw" text-content is never used for anything.
For a short document, such as e.g. the `tracemonkey` file, this repeated normalization won't matter much, but for documents with a couple of thousand pages it seems completely unnecessary (and wasteful) to keep repeating the normalization whenever e.g. a new search operation starts.
2018-10-26 20:23:32 +02:00
Jonas Jenwald
12d8b52c49 Move the normalize helper function out of PDFFindController
In the event that multiple instances of `PDFFindController` ever exists simultaneously, they will all be able to share just one `normalize` function in this way. Furthermore, the regular expression is now created lazily rather than at class construction time.
2018-10-26 18:22:32 +02:00
Jonas Jenwald
64d75c32bf Ensure that matches are not scrolled into after the findbar has been closed (PR 10100 follow-up)
Despite all highlighted matches being removed in response to the 'findbarclose' event, there's a risk that a match could still be scrolled into view *after* the findbar has been closed[1].
Hence we need to ensure that long running searches, particularily those happening in large and/or slow loading documents[2], are ignored as well.

---
[1] The match is hidden, as expected, but the document could still scroll unexpectedly.
[2] Large documents loaded with `disableAutoFetch = true` and `disableStream = true` set are particularily susceptible to this issue.
2018-10-26 12:43:12 +02:00
Jonas Jenwald
27b21f2558 Add a _updateAllPages helper method to PDFFindController in order to reduce the amount of event dispatching
Given that dispatching the 'updatetextlayermatches' event with `pageIndex = -1` set is now used to target the textLayers of *all* pages, there's no need to send individual events to every single page during `_nextMatch`. Since there can be an arbitrary number of pages in a document, this small/simple optimization seems too easy to ignore.
2018-10-26 11:50:44 +02:00
Jonas Jenwald
d73a71fb90 Small clean-up of the search related methods in TextLayerBuilder
This patch does four things:
 - Change the search related methods in `TextLayerBuilder` to be "private", since there're only called from within the class itself now.
 - Use `const` for local variables not intended to change in the search related methods in `TextLayerBuilder`.
 - Finally, removes most `this.findController` checks since they are redundant. Note how both `this._convertMatches` and `this._renderMatches` are *only* ever called, from `this._updateMatches`, when `this.findController` is actually defined. Hence there's really no need to repeat those checks all over the place, especially with all the relevant methods now being marked as "private".
 - Always initialize the `this._pageMatchesLength` property with an empty array, to simplify the code in `TextLayerBuilder`.
2018-10-25 21:38:25 +02:00
Tim van der Meij
dc98bf76eb
Merge pull request #10179 from ThomasdenH/patch-1
Change splice to pop in annotation tests
2018-10-24 23:45:22 +02:00
Thomas den Hollander
b157d8b478
Change splice to pop in annotation tests
This line in the annotation tests subtracts an array from a number. This is because `splice(-1, 1)` returns a one-element array, while `pop()` returns only the element itself.
2018-10-24 13:08:08 +02:00
Tim van der Meij
f31f4bea4f
Merge pull request #10176 from timvandermeij/updates
Update translations and packages
2018-10-24 00:23:45 +02:00
Tim van der Meij
0abddde2c7
Update packages
Webpack is pinned because versions higher than this cause the viewer not
to work (see https://github.com/mozilla/pdf.js/pull/10170#issuecomment-431697032).

Node.js is pinned for Travis CI because version 11 requires that we
update to Gulp 4.
2018-10-24 00:09:39 +02:00
Tim van der Meij
c74c357157
Update translations 2018-10-23 23:32:42 +02:00
Jani Pehkonen
9cd5f94f03 Normalize the BBox of form XObjects on the /core side 2018-10-22 14:17:05 +03:00
Tim van der Meij
aa728aaf94
Merge pull request #10168 from Snuffleupagus/PDFDataRangeTransport-class
Convert `PDFDataRangeTransport` to an ES6 class
2018-10-21 15:49:24 +02:00
Jonas Jenwald
5bb7f4b615 Convert PDFDataRangeTransport to an ES6 class 2018-10-20 17:15:27 +02:00
Tim van der Meij
d21892933d
Merge pull request #10161 from Snuffleupagus/DataLoaded-onProgress
Ensure that `onProgress` is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
2018-10-20 15:22:05 +02:00
Tim van der Meij
e63e2ef85e
Merge pull request #10167 from Snuffleupagus/pdfjsLib-more-exports
Export `CMapCompressionType` and `PermissionFlag` on the `pdfjsLib` object (issue 10148, PR 10033 follow-up)
2018-10-20 15:14:56 +02:00
Jonas Jenwald
54f9883c51 Export CMapCompressionType and PermissionFlag on the pdfjsLib object (issue 10148, PR 10033 follow-up)
`CMapCompressionType` makes a lot of sense to export, for anyone attempting to implement a custom `CMapReaderFactory`; fixes 10148.

`PermissionFlag` likewise needs to be exported, since otherwise the result of the `getPermissions` API method becomes difficult to interpret; follow-up to 10033.
2018-10-20 11:38:00 +02:00
Tim van der Meij
a0bc5c2df0
Merge pull request #10166 from timvandermeij/bump
Bump version numbers for stable and beta releases
2018-10-19 23:08:23 +02:00
Tim van der Meij
af33399ac9
Bump version numbers for stable and beta releases 2018-10-19 23:03:19 +02:00
Jonas Jenwald
327f2eb588 Ensure that onProgress is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired.

From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded).
This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense.

However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls.
The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread.

---
[1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
2018-10-16 13:51:12 +02:00