Commit Graph

10095 Commits

Author SHA1 Message Date
Tim van der Meij
2f2e539bc6 Merge pull request #8561 from Snuffleupagus/zoomLayer-canvas-hidden
Don't use a hidden canvas when constructing the `zoomLayer` in `PDFPageView.update`
2017-06-22 23:51:21 +02:00
Tim van der Meij
c6ee05f7e5 Merge pull request #8542 from Rob--W/svg-clipping
Move svg:clipPath generation from clip to endPath
2017-06-22 23:48:06 +02:00
Jonas Jenwald
426e26c63b Don't use a hidden canvas when constructing the zoomLayer in PDFPageView.update
*This is an existing issue that I noticed while testing PR 8552.*

When zooming or rotation occurs, we'll try to use the current canvas as a (CSS transformed) preview until the page has been completely re-drawn.
If you manage to change the scale (or rotation) *very* quickly, it's possible that `PDFPageView.update` can be called *before* a previous `render` operation has progressed far enough to remove the `hidden` property from the canvas.

The result is thus that a page may be *entirely* black during zooming or rotation, which doesn't look very good. This effect can be a bit difficult to spot, but it does manifest even in the default viewer.
2017-06-22 10:05:41 +02:00
Rob Wu
fc6448d18c Move svg:clipPath generation from clip to endPath
In the PDF from issue 8527, the clip operator (W) shows up before a path
is defined. The current SVG backend however expects a path to exist
before generating a `<svg:clipPath>` element.
In the example, the path was defined after the clip, followed by a
endPath operator (n).
So this commit fixes the bug by moving the path generation logic from
clip to endPath.

Our canvas backend appears to use similar logic:
`CanvasGraphics_endPath` calls `consumePath`, which in turn draws the
clip and resets the `pendingClip` state. The canvas backend calls
`consumePath` from multiple other places, so we probably need to check
whether doing so is also necessary for the SVG backend.

I scanned our corpus of PDF files in test/pdfs, and found that in every
instance (except for one), the "W" PDF operator (clip) is immediately
followed by "n" (endPath). The new test from this commit (clippath.pdf)
starts with "W", followed by a path definition and then "n".

    # Commands used to find some of the clipping commands:
    grep -ra '^W$' -C7 | less -S
    grep -ra '^W ' -C7 | less -S
    grep -ra ' W$' -C7 | less -S

test/pdfs/issue6413.pdf is the only file where "W" (a tline 55) is not
followed by "n". In fact, the "W" is the last operation of a series of
XObject painting operations, and removing it does not have any effect
on the rendered PDF (confirmed by looking at the output of PDF.js's
canvas backend, and ImageMagick's convert command).
2017-06-22 01:08:17 +02:00
Tim van der Meij
36fb3686cc Merge pull request #8556 from Snuffleupagus/app-remove-pageRotation
Stop tracking the rotation in `PDFViewerApplication` and directly use `PDFViewer.pagesRotation` instead
2017-06-22 00:03:58 +02:00
Jonas Jenwald
5ff4cd8f0d Merge pull request #8552 from yurydelendik/canvas-hidden
Ensure canvas is really hidden when used with pdfjs-dist.
2017-06-21 17:28:45 +02:00
Jonas Jenwald
83673a12d7 Stop tracking the rotation in PDFViewerApplication and directly use PDFViewer.pagesRotation instead
Part of the rotation handling code, in what's now `web/app.js`, hasn't really changed since before the viewer was split into multiple files/components.

Similar to other properties, such as current page/scale, we should probably avoid tracking state in multiple places. Hence I'm suggesting that we don't store the rotation in `PDFViewerApplication`, and access the value in `PDFViewer` instead.

Since `PDFViewerApplication.pageRotation` has existed for a very long time, a getter was added to avoid outright breaking third-party code that may depend on it.
2017-06-21 11:45:36 +02:00
Jonas Jenwald
735b58c3d5 Don't allow setting various properties, such as currentPageNumber/currentScale/currentScaleValue/pagesRotation, before {PDFViewer, PDFThumbnailViewer}.setDocument has been called
Currently a number of these properties do not work correctly if set *before* calling `setDocument`; please refer to the discussion starting in https://github.com/mozilla/pdf.js/pull/8539#issuecomment-309706629.

Rather than trying to have *some* of these methods working, but not others, it seems much more consistent to simply always require that `setDocument` has been called.
2017-06-21 11:37:33 +02:00
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