Commit Graph

10870 Commits

Author SHA1 Message Date
Jonas Jenwald
e522b2d87e Remove the unused PDFViewerApplication.documentFingerprint property
This property isn't accessed anywhere in the `web/app.js` file, and is also not being reset in `PDFViewerApplication.close`. Hence it seems that it can simply be removed, especially since the fingerprint is already synchronously available through `PDFViewerApplication.pdfDocument.fingerprint` (provided that a document is loaded).
2018-06-30 12:19:02 +02:00
Tim van der Meij
99f8f2c275
Merge pull request #9853 from Snuffleupagus/re-render-after-cancel
Fix re-rendering, using the same canvas, when rendering was previously cancelled (PR 8519 follow-up)
2018-06-29 23:25:43 +02:00
Tim van der Meij
abda2b289e
Merge pull request #9852 from RonLek/master
Proper Error Handling for Build Numbers of Downloaded Sources (Non-Git repositories).
2018-06-29 23:12:03 +02:00
RonLek
efb8f54fa1 Error Handling for Downloaded Files 2018-06-29 21:52:10 +05:30
Tim van der Meij
6fa2c779b5
Merge pull request #9838 from Snuffleupagus/invalid-path-OPS
Error, rather than warn, once a number of invalid path operators are encountered in `EvaluatorPreprocessor.read` (bug 1443140)
2018-06-28 23:15:25 +02:00
Jonas Jenwald
bf0aca86d7 Fix re-rendering, using the same canvas, when rendering was previously cancelled (PR 8519 follow-up)
Currently if `RenderTask.cancel` is called *immediately* after rendering was started, then by the time that `InternalRenderTask.initializeGraphics` is called rendering will already have been cancelled.
However, we're still inserting the canvas into the `canvasInRendering` map, thus breaking any future attempts at re-rendering using the same canvas. Considering that `InternalRenderTask.cancel` always removes the canvas from the map, I cannot imagine that we'd ever want to re-add it *after* rendering was cancelled (it was likely just a simple oversight in PR 8519).

Fixes 9456.
2018-06-28 22:56:37 +02:00
Tim van der Meij
5e40f04153
Merge pull request #9849 from Snuffleupagus/rm-cloneObj
Replace the `cloneObj` helper function, in the viewer, with native `Object.assign` (PR 9795 follow-up)
2018-06-27 23:00:27 +02:00
Jonas Jenwald
3c622ef048 Replace the cloneObj helper function, in the viewer, with native Object.assign (PR 9795 follow-up) 2018-06-27 20:39:39 +02:00
Tim van der Meij
40d577d7dd
Merge pull request #9841 from Snuffleupagus/initial-position-misc-cleanup
Various (small) cleanup related to setting the initial document position on load
2018-06-26 23:31:45 +02:00
Tim van der Meij
14b69a4c1c
Merge pull request #9729 from Snuffleupagus/gulp-image_decoders
Add a `gulp image_decoders` command to package the image decoders (i.e. jpg.js, jpx.js, jbig2.js) separately, and publish them in pdfjs-dist
2018-06-26 23:27:32 +02:00
Jonas Jenwald
95a4fa25b9 Don't wait arbitrary long for all pages to be resolved before attempting to re-apply the initial position on load (PR 6318 follow-up)
With the current code, the location in the viewer could change *well* after the user has started to interact with the viewer (for very large and/or slow loading documents). Attempt to reduce the likelyhood of that happening, by adding an upper bound to the time spent waiting before attempting to re-apply the initial position.
2018-06-26 14:19:59 +02:00
Jonas Jenwald
3691f9cc78 Simplify the handling of the defaultZoomValue preference in PDFViewerApplication.load 2018-06-26 14:13:44 +02:00
Jonas Jenwald
5bbbbf152e Stop storing/using the 'exists' property of ViewHistory database entries
Rather than using a "special" property to check if a `ViewHistory` database entry existed on load, it seems that you could just as well check for the existence of one of the actually needed properties instead (here 'page' is used).

This way we can avoid storing what, more of less, amounts to useless state, which will help reduce the size of the `ViewHistory` database. Given that we don't directly, nor need to, validate the `ViewHistory` data but rely on other parts of the code-base to do so, the existance of an 'exists' property doesn't in and of itself really add much utility.

Finally, to simplify the implementation the 'exists' property won't be actively removed from the `ViewHistory` data. Instead we'll simply stop adding 'exists' when writing `ViewHistory` data, and rely on the existing pruning of old entries to eventually remove any remnants of 'exists' from storage.
2018-06-26 14:12:21 +02:00
Jonas Jenwald
253aae15fc Ensure that all entries above the current cacheSize is removed when initializing a ViewHistory instance
Note how, in the current code, only *one* old history entry would ever be removed. That would mean that if e.g. the `cacheSize` is reduced, it would potentially require loading of multiple files before the database would be correctly pruned.

Furthermore, in the case where the database was empty on load there's no need to attempt to shrink it, since trying to reduce the size of an *empty* array won't do much :-)
2018-06-26 14:07:52 +02:00
Tim van der Meij
66ffdc4c5b
Merge pull request #9839 from Snuffleupagus/page-stats-tests
Add unit-tests for `PDFPageProxy.stats` (PR 9245 follow-up)
2018-06-25 23:08:58 +02:00
Jonas Jenwald
74e9999044 Add unit-tests for PDFPageProxy.stats (PR 9245 follow-up)
This wasn't included in PR 9245, since all the API options were still global at that time.

Writing the unit-tests also uncovered an issue with `getOperatorList` not starting the "Page Request" timer.
2018-06-25 14:20:49 +02:00
Jonas Jenwald
7f21e38787 Error, rather than warn, once a number of invalid path operators are encountered in EvaluatorPreprocessor.read (bug 1443140)
Incomplete path operators, in particular, can result in fairly chaotic rendering artifacts, as can be observed on page four of the referenced PDF file.

The initial (naive) solution that was attempted, was to simply throw a `FormatError` as soon as any invalid (i.e. too short) operator was found and rely on the existing `ignoreErrors` code-paths. However, doing so would have caused regressions in some files; see the existing `issue2391-1` test-case, which was promoted to an `eq` test to help prevent future bugs.
Hence this patch, which adds special handling for invalid path operators since those may cause quite bad rendering artifacts.

You could, in all fairness, argue that the patch is a handwavy solution and I wouldn't object. However, given that this only concerns *corrupt* PDF files, the way that PDF viewers (PDF.js included) try to gracefully deal with those could probably be described as a best-effort solution anyway.

This patch also adjusts the existing `warn`/`info` messages to print the command name according to the PDF specification, rather than an internal PDF.js enumeration value. The former should be much more useful for debugging purposes.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1443140.
2018-06-24 16:05:08 +02:00
Tim van der Meij
e8b5088370
Merge pull request #9832 from Snuffleupagus/scrollMode-fixes
Fix a number of regressions/inefficiencies introduced by adding Scroll/Spread modes to the viewer (PR 9208 follow-up)
2018-06-23 21:09:55 +02:00
Tim van der Meij
a6830fd414
Merge pull request #9835 from Snuffleupagus/api-loadingParams-cleanup
Clean-up the `PDFDocumentProxy.loadingParams` method in the API, and the `locale` viewer option
2018-06-23 16:46:31 +02:00
Jonas Jenwald
c8384061cf Ensure that the locale viewer option is never defined in the (various) extension builds (PR 9493 follow-up) 2018-06-23 13:33:40 +02:00
Jonas Jenwald
275834ae66 Clean-up, and add JSDocs to, the PDFDocumentProxy.loadingParams method (PR 9830 follow-up) 2018-06-23 13:33:22 +02:00
Jonas Jenwald
bfbe2b411c Simplify the _setScale call when changing Scroll modes
Since the current page will be explicitly scrolled into view *directly* afterwards anyway (compare with e.g. the `pagesRotation` code), trying to maintain the current position when re-applying the zoom level during changing of Scroll modes is redundant.
2018-06-23 11:47:53 +02:00
Jonas Jenwald
d3cb5e7117 Don't attempt to modify the DOM and/or trigger rendering when changing Scroll/Spread modes without a PDF document being loaded 2018-06-23 10:30:22 +02:00
Jonas Jenwald
05f682cd4b [Regression] Ensure that pre-rendering of the next/previous page works correctly in Presentation Mode, when horizontal scrolling was enabled
Note how in `BaseViewer.forceRendering` the Scroll mode is used to determine how pre-rendering will work. Currently this is broken in Presentation Mode, if horizontal scrolling was enabled prior to entering fullscreen.

Furthermore, there's a few additional cases where the `this.scrollMode === ScrollMode.HORIZONTAL` check is pointless either in Presentation Mode or when a `PDFSinglePageViewer` instance is used.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
6a086fa0b9 Refactor setScrollMode/setSpreadMode, in the viewer classes, such that they are no-ops in PDFSinglePageViewer instances
Since the Scroll/Spread modes doesn't make (any) sense in `PDFSinglePageViewer` instances, the general structure of these methods can be improved to reflect that.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
8bd1244298 Move _updateScrollModeClasses from BaseViewer to PDFViewer
Given that this method is a no-op in `PDFSinglePageViewer`, similar to `_regroupSpreads`, let's improve the general code structure by simply moving the method.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
da52dff04b Add validation of the argument in the BaseViewer.{setScrollMode, setSpreadMode} methods
Since all the other "public" methods validate the arguments, these (new) ones really ought to do the same.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
9b0ed6f821 Remove all pages from the DOM at once, rather than using a loop, in PDFViewer._regroupSpreads
There's no good reason to iterate through an arbitrary number of DOM elements this way, since a document could contain thousands of pages, when everything can be easily removed at once; compare with e.g. `BaseViewer._resetView` and `PDFThumbnailViewer._resetView`.

Furthermore given that it's a `PDFViewer` instance, the `this.viewer` property can be accessed directly. Besides, `_setDocumentViewerElement` only exists as a helper method for `setDocument` in the base class and none of this code applies for `PDFSinglePageViewer` instances either.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
36111a1f40 [Regression] Remove instances of Element.classList.toggle() with *two* parameters, since browser support is limited
The Secondary Toolbar buttons for, not to mention the actual toggling of, Scroll/Spread modes are currently completely broken in older browsers (such as IE11).

As a follow-up, it'd probably be a good idea to try and find a *feature complete* `classList` polyfill that could be used instead, but this patch at least addresses the immediate regression.

Please refer to the compatibility information in https://developer.mozilla.org/en-US/docs/Web/API/Element/classList#Browser_compatibility
2018-06-23 10:16:04 +02:00
Tim van der Meij
34594a5b02
Merge pull request #9830 from EugeneSqr/9824
Removed safari compatibility check (issue #9824)
2018-06-23 02:21:06 +02:00
Tim van der Meij
98ea39f9d0
Merge pull request #9827 from Snuffleupagus/misc-corrupt-pdf-fixes
Fix various corrupt PDF files (issue 9252, issue 9418)
2018-06-21 22:35:00 +02:00
eugenesqr
331ac8ae74 removed safari compatibility check 2018-06-21 12:57:56 +03:00
Brendan Dahl
a278c5a8dc
Merge pull request #9795 from timvandermeij/object-assign
Replace `Util.extendObj` by `Object.assign`
2018-06-20 10:50:40 -07:00
Jonas Jenwald
56e3648b65 Add basic validation of the 'trailer' dictionary candidates in XRef.indexObjects (issue 9418)
This patch avoids choosing a (possible) 'trailer' dictionary that `XRef.parse` and/or the `Catalog` constructor/methods will reject anyway.
Since `XRef.indexObjects` is already parsing the entire PDF file, the extra dictionary look-ups added here shouldn't matter much. Besides, this is a fallback code-path that only applies to corrupt PDF files anyway.
2018-06-20 13:41:22 +02:00
Jonas Jenwald
346810e02a Add basic validation of the 'Root' dictionary in XRef.parse and try to recover when possible
Note that the `Catalog` constructor, and some of its methods, are already enforcing that the 'Root' dictionary is valid/well-formed. However, by doing additional validation already in `XRef.parse` there's a slightly larger chance that corrupt PDF files could be successfully parsed/rendered.
2018-06-20 13:41:22 +02:00
Jonas Jenwald
e84813e7cc Prevent hard errors if fetching the Encrypt dictionary fails in XRef.parse 2018-06-20 13:41:22 +02:00
Jonas Jenwald
30ad62a86a Use the correct startPos when repeating the search for 'endobj' operators in XRef.indexObjects (PR 9288 follow-up) 2018-06-20 13:41:22 +02:00
Jonas Jenwald
6bbcafcd26 Let Lexer.getNumber treat a single decimal point as zero (issue 9252)
This is consistent with the behaviour in Adobe Reader.
2018-06-20 13:41:21 +02:00
Jonas Jenwald
df4799a12a Ensure that line-breaks are *only* skipped after operators in Lexer.getNumber (PR 8359 follow-up)
With the current code line-breaks are accepted not just after an operator, but after a decimal point as well. When looking at this again, the latter case seems prone to cause false positives and might also interfere with subsequent patches.

Hence this is code is adjusted to actually do what the original commit message says, and nothing more.
2018-06-20 13:41:15 +02:00
Tim van der Meij
3b07147d98
Merge pull request #9821 from Snuffleupagus/onOpenWithURL-originalUrl
Set the correct document title when opening a new file in the `GENERIC` default viewer
2018-06-17 20:27:16 +02:00
Jonas Jenwald
3e4a159a45 Set the correct document title when opening a new file in the GENERIC default viewer 2018-06-17 13:55:53 +02:00
Jonas Jenwald
84920f39b2 Change the casing of the originalURL parameter, to originalUrl, in the onOpenWithURL method
The `onOpenWithURL` method, in `PDFViewerApplication.initPassiveLoading`, accepts a `originalURL` parameter which is then passed on to `PDFViewerApplication.open` as is. However, the latter method expects the name of the parameter to be `originalUrl` (note the casing), meaning that `getDocument` will fail in this case.

For consistency, and to avoid confusion, the renaming is done in `web/chromecom.js` as well.
2018-06-17 13:32:30 +02:00
Jonas Jenwald
5984c24415 Add a basic JpegImage example using the standalone image decoders
The image was "borrowed" from one of the examples found at https://github.com/notmasteryet/jpgjs/tree/master/images
2018-06-16 17:56:54 +02:00
Jonas Jenwald
303537bcb1 Add a gulp image_decoders command to allow packaging/distributing the image decoders (i.e. jpg.js, jpx.js, jbig2.js) separately from the main PDF.js library
Please note that the standalone `pdf.image_decoders.js` file will be including the complete `src/shared/util.js` file, despite only using parts of it.[1] This was done *purposely*, to not negatively impact the readability/maintainability of the core PDF.js code.

Furthermore, to ensure that the compatibility is the same in the regular PDF.js library *and* in the the standalone image decoders, `src/shared/compatibility.js` was included as well.

To (hopefully) prevent future complaints about the size of the built `pdf.image_decoders.js` file, a few existing async-related polyfills are being skipped (since all of the image decoders are completely synchronous).
Obviously this required adding a couple of pre-processor statements, but given that these are all limited to "compatibility" code, I think this might be OK!?

---
[1] However, please note that previous commits moved `PageViewport` and `MessageHandler` out of `src/shared/util.js` which reduced its size.
2018-06-16 17:56:54 +02:00
Jonas Jenwald
bfc88ead66 Expose a Jbig2Image.parse method, by re-instating the parseJbig2 function
The purpose of this patch is to hopefully provide *slightly* better user ergonomics, if/when the PDF.js image decoders are used standalone.

This implementation is (basically) reverting the changes in PR 9386, in conjunction with code from the `parse` method found at https://github.com/notmasteryet/jpgjs/blob/master/src/pdfjs.js
2018-06-16 17:56:54 +02:00
Jonas Jenwald
682672db8e Change the signature of the JpegImage constructor, to allow passing in various options directly 2018-06-16 17:56:54 +02:00
Tim van der Meij
620da6f4df
Merge pull request #9802 from Snuffleupagus/ColorSpace-PDFImage-Uint8ClampedArray
Update `ColorSpace` and `PDFImage` to use `Uint8ClampedArray`s and remove manual clamping/rounding
2018-06-16 17:55:10 +02:00
Tim van der Meij
280f20bf3c
Merge pull request #9809 from Snuffleupagus/getPathGenerator-ignoreErrors
Allow `FontFaceObject.getPathGenerator` to ignore non-embedded fonts during rendering
2018-06-16 16:37:52 +02:00
Tim van der Meij
5dacc8155c
Merge pull request #9819 from Snuffleupagus/viewerContainer-offset-small-window
Fix regression affecting the horizontal `viewerContainer` offset for small window widths (PR 9816 follow-up)
2018-06-16 00:19:41 +02:00
Brendan Dahl
7892122201
Merge pull request #9595 from Rob--W/crx-ftp-file
Disable ftp support in Chrome 59+, add file chooser at file
2018-06-15 14:48:19 -07:00