Commit Graph

11240 Commits

Author SHA1 Message Date
Tim van der Meij
39846a6de3
Merge pull request #9935 from Snuffleupagus/builtInCMapCache-cleanup-regression
[Regression] Convert `Catalog.builtInCMapCache` into a `Map`, instead of an Object, to ensure that it's correctly reset (PR 8064 follow-up)
2018-07-29 16:07:45 +02:00
Jonas Jenwald
ec3728b540 Use the Linearization dictionary, if it exists, when fetching the first Page
Since PDF.js already supports range requests and streaming, not to mention chunked rendering, attempting to use the `Linearization` dictionary in `PDFDocument.getPage` probably isn't going to improve performance in any noticeable way.
Nonetheless, when `Linearization` data is available, it will allow looking up the first Page *directly* without having to descend into the `Pages` tree to find the correct object.
2018-07-28 22:23:36 +02:00
Jonas Jenwald
fbb25ff4e2 Move getPage, on the worker side, from Catalog and into PDFDocument instead
Addresses an existing TODO, and avoids having to pass in a `pageFactory` when creating `Catalog` instances.
2018-07-28 22:23:36 +02:00
Jonas Jenwald
81b471c781 [Regression] Convert Catalog.builtInCMapCache into a Map, instead of an Object, to ensure that it's correctly reset (PR 8064 follow-up)
With the `builtInCMapCache` being a simple Object, it unfortunately means that the `Catalog.cleanup` method isn't resetting it as intended.
By just replacing the `builtInCMapCache` with an empty Object, existing references to it will not actually be updated. The result is that e.g. `Page` instances still keeps references to, what should have been removed, CMap data.

To fix these problems, the `builtInCMapCache` is converted into a `Map` instead (since it can be easily reset).
2018-07-28 22:20:43 +02:00
Jonas Jenwald
08b05b9fda Validate the Preferences when fetching them from storage
When updating Preferences using the `set` method, the input is carefully validated. However, no validation is (currently) done when a `BasePreferences` instance is created, which probably isn't that great. Hence this patch that simply ignores, to not unnecessarily break loading of the viewer itself, any invalid Preferences.
2018-07-28 14:32:24 +02:00
Jonas Jenwald
780cbadcd7 Stop re-loading the Preferences in PDFViewerApplication.open, and remove the BasePreferences.reload method
Given that the various Preferences are currently, and have been for quite some time, only used when initializing `PDFViewerApplication` re-loading them when a new PDF file is opened in the viewer is essentially a no-op.

Furthermore, with the only usage of `BasePreferences.reload` now gone, the value of that method seems questionable at best. In the event that the functionality is actually needed again, similar to the `ViewHistory`, it'd probably make more sense to simply replace `PDFViewerApplication.preferences` with a new `BasePreferences` instance instead (using e.g. `DefaultExternalServices.createPreferences`).
2018-07-28 13:50:16 +02:00
bion
c31ddf7edc [api-minor] Include export value for checkboxes 2018-07-28 00:30:41 -07:00
Tim van der Meij
d6f378fbaf
Merge pull request #9933 from perlun/patch-1
README.md: suggest usage of https instead of git protocol
2018-07-28 00:09:24 +02:00
Per Lundberg
82f1d3c82a
README.md: suggest usage of https instead of git protocol
The `git` protocol is unencrypted which means other parties could potentially eavesdrop your traffic. `https` or `ssh` is often encouraged because of this. (For example, the Ruby package manager `bundler` prints a warning when `git` sources are being used.)
2018-07-27 23:26:59 +03:00
Jonas Jenwald
522040d130 Expose the Linearization status in the document properties dialog
This uses the same terminology, i.e. "Fast Web View", as is used by Adobe software.
2018-07-26 17:30:46 +02:00
Jonas Jenwald
928b89382e [api-minor] Add an IsLinearized property to the PDFDocument.documentInfo getter, to allow accessing the linearization status through the API (via PDFDocumentProxy.getMetadata)
There was a (somewhat) recent question on IRC about accessing the linearization status of a PDF document, and this patch contains a simple way to expose that through already existing API methods.
Please note that during setup/parsing in `PDFDocument` the linearization data is already being fetched and parsed, provided of course that it exists. Hence this patch will *not* cause any additional data to be loaded.
2018-07-26 15:54:19 +02:00
Jonas Jenwald
8a4466139b Simplify the DocumentInfoValidators definition
With this file now being a proper (ES6) module, it's no longer (technically) necessary for this structure to be lazily initialized. Considering its size, and simplicity, I therefore cannot see the harm in letting `DocumentInfoValidators` just be simple Object instead.

While I'm not aware of any bugs caused by the current code, it cannot hurt to add an `isDict` check in `PDFDocument.documentInfo` (since the current code assumes that `infoDict` being defined implies it also being a Dictionary).

Finally, the patch also converts a couple of `var` to `let`/`const`.
2018-07-26 15:54:01 +02:00
Jonas Jenwald
2d51bce941 Remove unnecessary stream.length check from PDFDocument.linearization
Note first of all that `PDFDocument` will be initialized with either a `Stream` or a `ChunkedStream`, and that both of these have `length` getters. Secondly, the `PDFDocument` constructor will assert that the `stream` has a non-zero (and positive) length. Hence there's no point in checking `stream.length` in the `linearization` getter.
2018-07-26 15:54:01 +02:00
Yury Delendik
51b0e60f9b
Merge pull request #9924 from ErikNijland/master
fix(browser): zlib is not available in browser
2018-07-26 08:35:52 -05:00
Jonas Jenwald
32bfa55d98 Attempt to estimate the minimum required buffer length when initializing StreamsSequenceStream instances
For most other `DecodeStream` based streams, we'll attempt to estimate the minimum `buffer` length based on the raw stream data. The purpose of this is to avoid having to unnecessarily re-size the `buffer`, thus reducing the number of *intermediate* allocations necessary when decoding the stream data.
However, currently no such optimization is attempted for `StreamsSequenceStream`, and given that they can often be quite large that seems unfortunate. To improve this, at least somewhat, this patch utilizes the raw sizes of the `StreamsSequenceStream` sub-streams to estimate the minimum required `buffer` length.

Most likely this patch won't have a huge effect on memory consumption, however for pathological cases it should help reduce peak memory usage slightly.
One example is the PDF file in issue 2813, where currently the `StreamsSequenceStream` instances would grow their `buffer`s as `2 MiB -> 4 MiB -> 8 MiB -> 16 MiB -> 32 MiB`. With this patch, the same stream `buffers`s grow as `8 MiB -> 16 MiB -> 32 MiB`, thus avoiding a total of `12 MiB` of *intermediate* allocations (since there's two `StreamsSequenceStream` used, for rendering/text-extraction).
2018-07-26 13:42:59 +02:00
Erik Nijland
26c734e493
fix(browser): zlib is not available in browser 2018-07-26 12:01:10 +02:00
Tim van der Meij
3f4c2d6733
Merge pull request #9917 from Snuffleupagus/Preference-getAll
Add a `BasePreferences.getAll` method and use it to fetch all Preferences at once in `PDFViewerApplication._readPreferences`; ensure that the `externalLinkTarget` option is correctly set when the viewer is embedded
2018-07-25 22:40:40 +02:00
Jonas Jenwald
34957ec8eb Add a BasePreferences.getAll method and use it to fetch all Preferences at once in PDFViewerApplication._readPreferences
Given that *all* Preferences are already fetched in `PDFViewerApplication._readPreferences`, the amount of boilerplate/duplication can be considerably reduced with the addition of a `BasePreferences.getAll` method.
2018-07-25 10:43:36 +02:00
Jonas Jenwald
c3433aea48 Remove a (now) unnecessary externalLinkTarget check in PDFViewerApplication._readPreferences
The only reason that this check ever existed in the first place, is that originally there was a global `PDFJS.openExternalLinkInNewWindow` option which was then subsumed by the (more generic) `PDFJS.externalLinkTarget` option. (The `externalLinkTarget` has since been moved into a `PDFLinkService` option, as part of PDF.js version `2.0`.)

Hence, during the period where both `PDFJS.openExternalLinkInNewWindow` and `PDFJS.externalLinkTarget` existed side-by-side, there was a need to allow the former one to override the latter one (for backward compatibility purposes). However, that's no longer the case, and this extra `externalLinkTarget` check can now be removed.
2018-07-25 10:43:36 +02:00
Jonas Jenwald
c6a0ae08f1 Ensure that the externalLinkTarget option is correctly set when the viewer is embedded (PR 9479 follow-up)
*This was a stupid error on my part; sorry about breaking this!*

With the current code, the value of the `externalLinkTarget` option is now (potentially) updated *after* the viewer components have been initialized. For the "viewer in iframe/object tag" case, the result is that the value of the `externalLinkTarget` option isn't adjusted as intended any more.
2018-07-25 10:43:36 +02:00
Tim van der Meij
5b17fe81dc
Merge pull request #9913 from Snuffleupagus/no-restricted-globals
Provide custom messages for the `no-restricted-globals` ESLint rule, and refactor the `.eslintrc` files (PR 9868 follow-up)
2018-07-24 23:39:12 +02:00
Jonas Jenwald
36b683ca55 Provide custom messages for the no-restricted-globals ESLint rule, and refactor the .eslintrc files (PR 9868 follow-up)
Without providing useful (custom) error messages for the `no-restricted-globals` rule, see https://eslint.org/docs/rules/no-restricted-globals, it's quite likely that the rule will be incorrectly disabled rather than the required globals being imported as intended.

To reduced duplication of the `no-restricted-globals` rule in multiple `.eslintrc` files, it's instead moved to the top-level `.eslintrc` file and disabled as needed on a folder/file basis outside of `/src` and `/web`.
2018-07-23 14:10:13 +02:00
Tim van der Meij
1aaeaf3338
Merge pull request #9904 from RonLek/master
Modified Examples to work without systemjs
2018-07-22 14:55:35 +02:00
Tim van der Meij
2ce489c16f
Merge pull request #9900 from Snuffleupagus/issue-8884
Prevent Metadata/XML parsing from breaking `PDFDocumentProxy.getMetadata` when no XML root document is found (issue 8884)
2018-07-22 14:42:30 +02:00
RonLek
8afc4ce258 Modified Examples to work without systemjs 2018-07-21 16:56:06 +05:30
Jonas Jenwald
8ec99b200c Prevent Metadata/XML parsing from breaking PDFDocumentProxy.getMetadata when no XML root document is found (issue 8884)
With the new XML parser, see PR 9573, the referenced PDF file now causes `getMetadata` to fail when incomplete XML tags are encountered. This provides a simple, and hopefully generally useful, work-around that may also help prevent future bugs.

(Without being able to reproduce nor even understand the other (non XML) errors mentioned in issue 8884, I'd say that this patch is enough to close that one as fixed.)
2018-07-18 11:37:40 +02:00
Tim van der Meij
7e13977669
Merge pull request #9898 from Snuffleupagus/rm-createPromiseCapability-waitOnEventOrTimeout
Change `waitOnEventOrTimeout`, in web/ui_utils.js, to return a regular `Promise` and remove the `createPromiseCapability` import
2018-07-16 22:55:53 +02:00
Jonas Jenwald
647fa74793 Change waitOnEventOrTimeout, in web/ui_utils.js, to return a regular Promise and remove the createPromiseCapability import
*Another small piece of clean-up of code I've previously written; follow-up to PR 8775.*

Importing `createPromiseCapability`, and then using it in just *one* spot, seems unnecessary since the `waitOnEventOrTimeout` function may just as well return a regular `Promise` directly.
2018-07-16 13:48:33 +02:00
Tim van der Meij
61db85ab64
Merge pull request #9886 from Snuffleupagus/bug-1473809
Prevent errors in `sanitizeTTProgram`, during parsing of CALL functions, when encountering invalid functions stack deltas (bug 1473809)
2018-07-15 17:23:52 +02:00
Tim van der Meij
b56081c5f8
Merge pull request #9887 from Snuffleupagus/rm-Util-inherit
Convert more code in the `/src` folder to use ES6 classes, such that `Util.inherit` can be removed
2018-07-14 23:58:38 +02:00
Tim van der Meij
1f245c247f
Merge pull request #9881 from Snuffleupagus/rm-instanceof-Array
Replace the remaining occurences of `instanceof Array` with `Array.isArray()`
2018-07-14 23:47:12 +02:00
Jonas Jenwald
8e76d26e5b Move the toRoman helper function out of the Util scope
Compared to all the other (static) methods in `Util`, the `toRoman` one looks slightly out of place. Even more so considering that `Util` is being exposed through `pdfjsLib`, where access to a Roman numerals conversion method doesn't make much sense.
2018-07-10 10:45:25 +02:00
Jonas Jenwald
c1c49badff Remove the, now unused, Util.inherit helper function 2018-07-10 10:29:47 +02:00
Jonas Jenwald
2b25deb84c Prevent errors in sanitizeTTProgram, during parsing of CALL functions, when encountering invalid functions stack deltas (bug 1473809)
*I was feeling bored; so this is a very quick, and somewhat naive, attempt at fixing the bug.*

The breaking error, i.e. `Error during font loading: invalid array length`, was thrown when attempting to re-size the `stack` to a *negative* length when parsing the CALL functions.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1473809.
2018-07-10 09:45:55 +02:00
Jonas Jenwald
bf6d45f85a Convert CMap and IdentityCMap to ES6 classes
Also changes `var` to `let`/`const` in code already touched in the patch.
2018-07-09 21:12:01 +02:00
Jonas Jenwald
b773b356af Convert NameOrNumberTree, NameTree, and NumberTree to ES6 classes
Also changes `var` to `let`/`const` in code already touched in the patch.
2018-07-09 21:12:01 +02:00
Jonas Jenwald
ba1af46709 Convert CompiledFont, TrueTypeCompiled, and Type2Compiled to ES6 classes
Also changes `var` to `let`/`const` in code already touched in the patch.
2018-07-09 21:12:01 +02:00
Jonas Jenwald
775763a091 Ensure that CompiledFont.compileGlyph always returns an Array (PR 6141 follow-up)
PR 6141 changed `CompiledFont.compileGlyph` to, in the general case, return an Array. However, that PR apparenly forgot to update the no-glyph, empty-glyph, and endchar-glyph code-path and a String was still being (incorrectly) returned.

Given the way that `FontFaceObject.getPathGenerator` (on the API side) is implemented, this shouldn't have caused any bugs despite the Worker possible returning unexpected data.
2018-07-09 21:12:01 +02:00
Tim van der Meij
646d81cd09
Merge pull request #9837 from timvandermeij/unreachable
Replace `NotImplementedException` with `unreachable`
2018-07-09 21:10:36 +02:00
Jonas Jenwald
61186698c3 Replace the remaining occurences of instanceof Array with Array.isArray()
*Follow-up to PRs 8864 and 8813.*

As explained in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray, `instanceof Array` can have inconsistent behavior. To ensure that only `Array.isArray` is used, an ESLint plugin/rule is added to enforce this.
2018-07-09 13:17:41 +02:00
Jonas Jenwald
200e3d6bd8 Update the various ESLint packages to their latest versions 2018-07-09 12:52:55 +02:00
Tim van der Meij
907c7f190b
Convert src/code/pdf_manager.js to ES6 classes/syntax 2018-07-08 16:43:46 +02:00
Tim van der Meij
31012570ea
Merge pull request #9868 from Snuffleupagus/url-polyfill
Stop exposing the `URL` polyfill in the global scope
2018-07-08 16:29:53 +02:00
Tim van der Meij
7e1f727685
Merge pull request #9877 from Snuffleupagus/scroll-spread-hide
Hide the Scroll/Spread mode buttons if the viewer is a `PDFSinglePageViewer` instance (PR 9858 follow-up)
2018-07-08 15:59:02 +02:00
Tim van der Meij
9c06338258
Merge pull request #9880 from timvandermeij/jp-JP-mac
Remove the `jp-JP-mac` locale
2018-07-08 15:47:23 +02:00
Tim van der Meij
8a6b7373a0
Remove the jp-JP-mac locale
It gives warnings when running `gulp locale`, in a previous patch it was
explicitly asked to remove it and there is quite a bit of discussion
about the validity of the locale at
https://bugzilla.mozilla.org/show_bug.cgi?id=418485. In short, let's
remove it to prevent these issues.
2018-07-08 15:40:38 +02:00
Tim van der Meij
9c613a3563
Merge pull request #9879 from timvandermeij/readme
Correct the instructions in the README file for `examples/mobile-viewer`
2018-07-08 15:37:32 +02:00
Tim van der Meij
1024615ecb
Correct the instructions in the README file for examples/mobile-viewer 2018-07-08 15:32:06 +02:00
Jonas Jenwald
d8c2bcc93a Temporarily disable the Spread mode buttons when horizontal scrolling is enabled
Given that the non-default Spread modes (currently) doesn't affect the page layout when horizontal scrolling is enabled, having the Spread buttons appear active when clicking them appears to do *nothing* is probably confusing rather than helpful to users.
2018-07-08 12:11:03 +02:00
Jonas Jenwald
36d6255866 Hide the Scroll/Spread mode buttons when the viewer is a PDFSinglePageViewer instance
If the current viewer is a `PDFSinglePageViewer` instance the Scroll/Spread modes are no-ops, hence displaying buttons that do *nothing* when clicked will probably do very little besides confuse users.
2018-07-08 12:08:48 +02:00