Commit Graph

10237 Commits

Author SHA1 Message Date
Yury Delendik
9bed695ebd Merge pull request #8540 from Rob--W/svg-oom
Reduce memory requirements of pdf2svg.js example to avoid OOM
2017-06-20 17:24:48 -05:00
Yury Delendik
18e1f3d29b Ensure canvas is really hidden when used with pdfjs-dist.
Avoids black background flickering in such examples as components/simpleviewer.html
2017-06-20 14:45:07 -05:00
Jonas Jenwald
054fe13920 Merge pull request #8537 from timvandermeij/es6-toolbar
Convert the toolbar to ES6 syntax
2017-06-20 10:19:06 +02:00
Rob Wu
0cc1735809 Reduce concurrent memory footprint of pdf2svg.js
Wait for the completion of writing the generated SVG file before
processing the next page. This is to enable the garbage collector to
garbage-collect the (potentially large) SVG string before trying to
allocate memory again for the next page.

Note that since the PDF-to-SVG conversion is now sequential instead of
parallel, the time to generate all pages increases.

Test case:
node --max_old_space_size=200 examples/node/pdf2svg.js /tmp/FatalProcessOutOfMemory.pdf

Before this patch:
- Node.js crashes due to OOM after processing 20 pages.

After this patch:
- Node.js is able to convert all 203 PDFs to SVG without crashing.
2017-06-19 21:53:11 +02:00
Rob Wu
849d8cfa24 Improve memory-efficiency of DOMElement_toString in domstubs
Test case:
Using the PDF file from https://github.com/mozilla/pdf.js/issues/8534
node --max_old_space_size=200 examples/node/pdf2svg.js /tmp/FatalProcessOutOfMemory.pdf

Before this patch:
Node.js crashes due to OOM after processing 10 pages.

After this patch:
Node.js crashes due to OOM after processing 19 pages.
2017-06-19 21:52:39 +02:00
Yury Delendik
679ffc84f6 Merge pull request #8544 from Rob--W/compatiblity-safari-strict-error
compatibility.js: Rename parameters in JURL
2017-06-19 10:34:33 -05:00
Rob Wu
f912f89e69 compatibility.js: Rename parameters in JURL 2017-06-19 17:03:41 +02:00
Yury Delendik
df4782dab7 Merge pull request #8543 from Rob--W/svg-domstubs-closePath
Add getAttributeNS to domstubs for SVG example
2017-06-19 09:58:18 -05:00
Rob Wu
4f22ba54bf Add getAttributeNS to domstubs for SVG example
The closePath method in src/display/svg.js relies on this.
2017-06-19 14:11:13 +02:00
Jonas Jenwald
b0bf69dd8c Update l10n files 2017-06-19 11:37:18 +02:00
Tim van der Meij
d4e0aa4031
Convert the toolbar to ES6 syntax 2017-06-18 22:20:13 +02:00
Tim van der Meij
db52e4fb73 Merge pull request #8536 from Snuffleupagus/refactor-ObjectLoader
Refactor `ObjectLoader` to use `Dict`s correctly, rather than abusing their internal properties
2017-06-18 22:17:40 +02:00
Tim van der Meij
a6311471a7 Merge pull request #8539 from Snuffleupagus/rm-load-currentScale-call
Remove a redundant `PDFViewer.currentScale` call from `PDFViewerApplication.load`
2017-06-18 22:00:39 +02:00
Jonas Jenwald
4aab3cef4a Remove a redundant PDFViewer.currentScale call from PDFViewerApplication.load
Since this call occurs *before* the `PDFViewer.setDocument` call, it won't actually cause any scale change.
Furthermore, moving it should not be necessary, since the `scale` is already used as the fallback case in `PDFViewerApplication.setInitialView` (provided it's non-zero, which isn't even the case in the default viewer).

Hence this patch should cause no functional changes at all, since it simply removes a piece of unnecessary code.
2017-06-18 14:34:29 +02:00
Tim van der Meij
8e9b4b5ff2 Merge pull request #8535 from Snuffleupagus/app-close-pageRotation-downloadComplete
Reset `pageRotation` and `downloadComplete` in `PDFViewerApplication.close`
2017-06-17 22:36:42 +02:00
Tim van der Meij
7215e9c52e Merge pull request #8525 from curiosity26/master
Allow for unbinding of events in web application
2017-06-17 22:32:16 +02:00
Jonas Jenwald
73234577e1 Rename map to _map inside of Dict, to make it clearer that it should be regarded as a "private" property 2017-06-17 17:32:00 +02:00
Mukul Mishra
0c13d0ff46 Adds Streams API in getTextContent to stream data.
This patch adds Streams API support in getTextContent
so that we can stream data in chunks instead of fetching
whole data from worker thread to main thread. This patch
supports Streams API without changing the core functionality
of getTextContent.

Enqueue textContent directly at getTextContent in partialEvaluator.

Adds desiredSize and ready property in streamSink.
2017-06-17 20:03:27 +05:30
Jonas Jenwald
e4d032c5c7 Reset pageRotation and downloadComplete in PDFViewerApplication.close
Currently, these properties are reset in what appears to be somewhat arbitrary locations (within the `load` and `open` methods respectively). The explanation is probably that both of these properties predates the existence of any centralized clean-up code in the viewer.

Hence I think that it makes sense to move the resetting of these properties to the `close` method, since that improves the overview of what's actually cleaned-up/reset when changing documents in the viewer.
2017-06-17 14:14:19 +02:00
Jonas Jenwald
3a20fd165f Refactor ObjectLoader to use Dicts correctly, rather than abusing their internal properties
The `ObjectLoader` currently takes an Object as input, despite actually working with `Dict`s internally. This means that at the (two) existing call-sites, we're passing in the "private" `Dict.map` property directly.

Doing this seems like an anti-pattern, and we could (and even should) simply provide the actual `Dict` when creating an `ObjectLoader` instance.
Accessing properties stored in the `Dict` is now done using the intended methods instead, in particular `getRaw` which (as the name suggests) doesn't do any de-referencing, thus maintaining the current functionality of the code.

The only functional change in this patch is that `ObjectLoader.load` will now ignore empty nodes, such that `ObjectLoader._walk` only needs to deal with nodes that are known to contain data. (This lets us skip, among other checks, meaningless `addChildren` function calls.)
2017-06-16 22:59:32 +02:00
Jonas Jenwald
f2fc9ee281 Slightly refactor and ES6-ify the code in ObjectLoader
This patch changes all `var` to `let`, and caches the array lengths in all loops. Also removes two unnecessary temporary variable assignments.
2017-06-16 22:59:32 +02:00
Yury Delendik
0c93dee0de Merge pull request #8515 from yurydelendik/bloborigin
Adds special case for origin of blob to the compatibility URL.
2017-06-16 11:21:45 -05:00
Yury Delendik
209751346c Merge pull request #8531 from Snuffleupagus/rm-updatePosition
Remove `PDFPageView.updatePosition` since it's not actually necessary
2017-06-15 12:09:35 -05:00
curiosity26
8326304271 Allow for unbinding of events in web application
Hold bound event listeners for later unbinding

ES6 styling

More ES6 styling and code cleanup

Remove 4 space indents and remove delete statements.
2017-06-15 09:58:54 -04:00
Jonas Jenwald
70d6550002 Remove PDFPageView.updatePosition since it's not actually necessary
This method is currently called from `PDFViewer._scrollUpdate` on *every* scroll event in the viewer.

However, I cannot see why this code is now necessary (assuming that it once was), since text-selection and searching still works *exactly* the same way with this patch as with the current `master`.

When `PDFPageView.updatePosition` is called, the page can be in either of these states:
 1. The page hasn't been rendered, in which case the `textLayer` property doesn't exist yet.
 2. The page is currently rendering, meaning that the `textLayer` property exists. Given that the `textContent` won't be fetched until the page has been successfully rendered, `TextLayerBuilder.render` will return immediately and effectively be a no-op (since there's nothing to render yet).
 3. The has been been rendered, and the `textLayer` is currently rendering.
 4. The page, and its `textLayer`, has been completely rendered. In this case, `TextLayerBuilder.render` will return immediately and effectively be a no-op.

Here, only the *third* case seem to require any further analysis:
When scrolling occurs while the `textLayer` is rendering, `TextLayerBuilder.render` will via a helper method call `TextLayerRenderTask.cancel` (in src/display/text_layer.js) to stop processing.
However, due to the run-to-completion nature of JavaScript, once `TextLayerRenderTask._render` has been invoked `appendText` will always run.[1]

So even though we cancel rendering of pending `textLayer`s during scrolling, via the repeated `TextLayerBuilder.render` calls from within the `PDFPageView.updatePosition` method, that does *not* prevent us from running the code inside of `TextLayerRenderTask._render` over and over for the *same* page; which all seems *very* inefficient to me.[2]

All this will thus have the effect of delaying the *actual* rendering of a `textLayer` ever so slightly while scrolling in the viewer. However, it does so at the expense of potentially hundreds of unnecessary `appendText` calls.[3]

Hence it seems to me that it's less resource intensive overall to simply let rendering of the `textLayer` complete, once it has started. Obviously, we still abort all rendering of a page, and its `textLayer`, when it's being destroyed (e.g. by being evicted from the page cache).

In case that there's any worry that the patch could affect e.g. highlighting of search results, please note that the existing code in `TextLayerBuilder.render` already calls `updateMatches` when the `TextLayerTask` resolves successfully.

*I'm sorry that this became quite long, but to try and summarize:*
`PDFPageView.updatePosition` doesn't actually do anything in *most* cases. In the one case where it matters, it seems that it's actually doing more harm than good; which is why I'm proposing that we just remove it.

---
[1] Although we may be able to skip the `render` call, provided that it happens *after* a `timeout` (as is the case in the default viewer).
[2] With current work being done to support streaming of `TextContent`, we'd also need to add just as many duplicate API calls to `PDFPageView.updatePosition`.
[3] The number of duplicate `appendText` calls is directly proportional not only to the scroll speed, but also to the number of pages in the document.
2017-06-15 13:25:37 +02:00
Yury Delendik
82f3145a5d Merge pull request #8522 from yurydelendik/weakmapfix
Fixes WeakMap polyfill (and improves PDFWorker port check).
2017-06-13 09:54:10 -05:00
Yury Delendik
631e6bebff Fixes WeakMap polyfill (and improves PDFWorker port check). 2017-06-13 09:36:58 -05:00
Yury Delendik
b44848b918 Adds special case for origin of blob to the compatibility URL. 2017-06-13 08:19:46 -05:00
Jonas Jenwald
e5ac64f81f Merge pull request #8519 from yurydelendik/issue8476
Preventing from using the same canvas for multiple render()
2017-06-13 13:39:36 +02:00
Yury Delendik
24f14d44cb Preventing from using the same canvas for multiple render() 2017-06-12 16:33:49 -05:00
Tim van der Meij
c26e497244 Merge pull request #8401 from yurydelendik/dist-install
Adds gulp dist-install command; using pdfjs-dist package in examples.
2017-06-12 22:59:09 +02:00
Jonas Jenwald
0ca6132ad2 Merge pull request #8517 from yurydelendik/global2.0
Additional check in globalScope detections
2017-06-12 19:47:35 +02:00
Yury Delendik
a18caa730d Adds gulp dist-install command; using pdfjs-dist package in examples. 2017-06-12 10:22:16 -05:00
Yury Delendik
db7a770542 Additional check in globalScope detections 2017-06-12 10:14:46 -05:00
Jonas Jenwald
c2641045e6 Update l10n files 2017-06-12 10:36:26 +02:00
Yury Delendik
08c6437196 Merge pull request #8510 from Snuffleupagus/zoom-dropdown-glitches
Prevent the Zoom dropdown from intermittently displaying an incorrect custom scale in Firefox (PR 8394 follow-up)
2017-06-10 08:03:03 -05:00
Jonas Jenwald
1766fe8184 Merge pull request #8508 from yurydelendik/issue8246
Fixes duplicate creation of PDFWorker for the same port.
2017-06-10 14:56:05 +02:00
Jonas Jenwald
75edb859ce Refactor the selectScaleOption function, in Toolbar._updateUIState, to prevent any possible future display glitches
Since the localization service is now asynchronous, depending on the load the browser is under, there's a small risk that the lookup of the 'page_scale_percent' string could be delayed slightly.
If the scale would change a couple of times in *very* quick succession, there's perhaps a *theoretical* possibility that the Zoom dropdown would display an incorrect value.

Consider the following, somewhat contrived, theoretical example of two zoom commands being executed *right* after one another:
```javascript
PDFViewerApplication.pdfViewer.currentScale = 1.23;
PDFViewerApplication.pdfViewer.currentScaleValue = 'page-width';
```

Only the `currentScale` call will currently trigger a l10n lookup in `selectScaleOption`. However, as far as I understand, there's no *guarantee* that the l10n string is resolved *before* `selectScaleOption` is called again as a result of the `currentScaleValue` call.

This thus has the possibility of putting the Zoom dropdown into an inconsistent state, since it's currently updated synchronously for one code-path and asynchronously for another.

To avoid these issues, I'm proposing that we *always* update the Zoom dropdown asynchronously, such that we can guarantee that the ordering is correct.
2017-06-10 14:05:52 +02:00
Jonas Jenwald
2971f522d4 Prevent the Zoom dropdown from intermittently displaying an incorrect custom scale in Firefox (PR 8394 follow-up)
After PR 8394, at least in Firefox, the Zoom dropdown now frequently displays an old custom scale instead of the correct one. To see this behaviour, the following STR works for me:
 1. Open https://mozilla.github.io/pdf.js/web/viewer.html.
 2. Zoom in, by clicking on the corresponding button in the toolbar.
 3. Run `PDFViewerApplication.pdfViewer.currentScaleValue` in the console.
 4. Compare what's displayed in the Zoom dropdown with what's printed in the console. (If no difference can be observed, try repeating steps 2 through 4 a couple of times.)

I really don't understand why this happens, but it seems that waiting until a custom scale has been set *before* selecting it fixes things in Firefox (and works fine in e.g. Chrome as well).
Note that this patch thus makes this particular piece of the code consistent with the state prior to PR 8394.
2017-06-10 14:04:53 +02:00
Yury Delendik
69c804a0f4 Fixes duplicate creation of PDFWorker for the same port. 2017-06-10 07:02:29 -05:00
Jonas Jenwald
f34d692758 Merge pull request #8441 from Snuffleupagus/issue-8330
Ensure that `TilingPattern`s have valid (non-zero) /BBox arrays (issue 8330)
2017-06-10 12:36:42 +02:00
Jonas Jenwald
e589834f13 Ensure that TilingPatterns have valid (non-zero) /BBox arrays (issue 8330)
Fixes 8330.
2017-06-09 21:41:48 +02:00
Jonas Jenwald
8b4a42e5b8 Only special-case OpenType fonts with CFF data if it's both a composite (i.e. Type0) font and also has a non-default CID to GID map (issue 8480)
*As mentioned the last time that I touched this particular part of the font code, I'm sincerely hope that this doesn't cause any regressions!*

However, the patch passes all tests added in PRs 5770, 6270, and 7904 (and obviously all other tests as well). Furthermore, I've manually checked all the issues/bugs referenced in those PRs without finding any issues.

Fixes 8480.
2017-06-09 21:15:39 +02:00
Yury Delendik
9342054502 Merge pull request #8430 from mukulmishra18/sendWithStream
Adds sendWithStream method in MessageHandler.
2017-06-09 12:02:12 -05:00
Jonas Jenwald
999e30723d Reduce the duplication slightly when detecting an OpenType font (in the Font constructor) 2017-06-09 18:26:57 +02:00
Tim van der Meij
e6f5b3e37e Merge pull request #8499 from Snuffleupagus/issue-8498
Prevent console errors when clicking to change page while in Presentation Mode (issue 8498)
2017-06-07 22:56:47 +02:00
Mukul Mishra
bbd9968f76 Added sendWithStream method in MessageHandler.
Adds functionality to accept Queueing Strategy in
sendWithStream method. Using Queueing Strategy we
can control the data that is enqueued into the sink,
and hence regulated the flow of chunks from worker
to main thread.

Adds capability in pull and cancel methods.
Adds ready and desiredSize property in streamSink.

Adds unit test for ReadableStream and sendWithStream.
2017-06-07 21:05:27 +05:30
Jonas Jenwald
3f2d5cfcc3 Prevent console errors when clicking to change page while in Presentation Mode (issue 8498)
The click handler used in Presentation Mode didn't check if the first/last page was already reached, which after PR 7529 now causes an unnecessary console error.
Hence we should simply use the already existing `_goToPreviousPage`/`_goToNextPage` methods instead, since they do the necessary bounds checking.

Fixes 8498.
2017-06-07 17:22:50 +02:00
Brendan Dahl
edd7d89fe5 Merge pull request #8467 from mozilla/bug1353029
Bug 1353029 - Pass PdfJs.enabled into child on change.
2017-06-05 11:44:22 -07:00
Brendan Dahl
5834ef6ff2 Bug 1353029 - Pass PdfJs.enabled into child on change. 2017-06-05 11:38:40 -07:00