Commit Graph

492 Commits

Author SHA1 Message Date
Yury Delendik
c830021b07 Fixes CFF data glyph widths 2017-07-25 12:29:51 -05:00
Mukul Mishra
568b0b6a42 Adds ready capability rejection logic for stream sink. 2017-07-25 02:07:38 +05:30
Jonas Jenwald
16c5d41c5b [api-minor] Add support for PageMode in the API (issue 8657)
Please refer to https://wwwimages2.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf#page=82.
2017-07-19 16:40:03 +02:00
Rob Wu
18566091aa Fix display_svg_spec tests.
- Mark the test as async, and don't swallow exceptions.
- Fix the DOMElement polyfill to behave closer to the actual getAttributeNS
  method, which excludes the namespace prefix.
2017-07-16 11:01:52 +02:00
Rob Wu
01f03fe393 Optimize PNG compression in SVG backend on Node.js
Use the environment's zlib implementation if available to get
reasonably-sized SVG files when an XObject image is converted to PNG.
The generated PNG is not optimal because we do not use a PNG predictor.
Futher, when our SVG backend is run in a browser, the generated PNG
images will still be unnecessarily large (though the use of blob:-URLs
when available should reduce the impact on memory usage). If we want to
optimize PNG images in browsers too, we can either try to use a DEFLATE
library such as pako, or re-use our XObject image painting logic in
src/display/canvas.js. This potential improvement is not implemented by
this commit

Tested with:

- Node.js 8.1.3 (uses zlib)
- Node.js 0.11.12 (uses zlib)
- Node.js 0.10.48 (falls back to inferior existing implementation).
- Chrome 59.0.3071.86
- Firefox 54.0

Tests:

Unit test on Node.js:

```
$ gulp lib
$ JASMINE_CONFIG_PATH=test/unit/clitests.json node ./node_modules/.bin/jasmine --filter=SVG
```

Unit test in browser: Run `gulp server` and open
http://localhost:8888/test/unit/unit_test.html?spec=SVGGraphics

To verify that the patch works as desired,

```
$ node examples/node/pdf2svg.js test/pdfs/xobject-image.pdf
$ du -b svgdump/xobject-image-1.svg
 # ^ Calculates the file size. Confirm that the size is small
 #   (784 instead of 80664 bytes).
```
2017-07-10 18:56:57 +02:00
Rob Wu
a488ff4f70 Put every test file on a separate lint in jasmine-boot.js 2017-07-10 18:45:47 +02:00
Yury Delendik
24f14d44cb Preventing from using the same canvas for multiple render() 2017-06-12 16:33:49 -05: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
efbd68efef Fix inconsistent spacing and trailing commas in objects in test/ files, so we can enable the comma-dangle and object-curly-spacing ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing

Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.

Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.

```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
     var window = createExtensionGlobal();
     telemetryScript.runInNewContext(window);
     window.chrome.runtime.getManifest = function() {
-     return { version: '1.0.1', };
+      return { version: '1.0.1', };
     };
     window.Date.test_now_value += 12 * 36E5;
     telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
     it('gets destinations, from /Dests dictionary', function(done) {
       var promise = doc.getDestinations();
       promise.then(function(data) {
-        expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
-                                          0, 841.89, null], });
+        expect(data).toEqual({
+          chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+        });
         done();
       }).catch(function (reason) {
         done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
     it('check compiled mul', function() {
       check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
       check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
-      check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+      check([0.5, 'mul'], [0, 1], [0, 1],
+            [{ input: [0.25], output: [0.125], }]);
       check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
-      check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+      check([0, 'exch', 'mul'], [0, 1], [0, 1],
+            [{ input: [0.25], output: [0], }]);
       check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
             [{ input: [0.25], output: [0.125], }]);
       check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 13:04:04 +02:00
Yury Delendik
bd288df909 Merge pull request #8396 from mukulmishra18/streams-lib
Adds streams-lib polyfill and exports ReadableStream from shared/util.
2017-05-31 08:42:48 -05:00
Yury Delendik
b66b705ed7 Using pre-built code for testing. 2017-05-30 22:06:21 +02:00
Jonas Jenwald
0ddf52aca5 Remove the special handling for nameddests that look like standard pageNumbers
PR 7341 added special handling for `nameddest`s that look like pageNumbers, to prevent issues since we previously *incorrectly* supported specifying a pageNumber directly in the hash; i.e. `#10` versus the correct `#page=10` format.

Since this behaviour wasn't correct, PR 7757 fixed and deprecated the old format, which means that we no longer need to maintain the `nameddest` hack in multiple files.
2017-05-20 11:29:29 +02:00
Mukul Mishra
c9f44f30e5 Adds streams-lib polyfill and exports ReadableStream from shared/util.
Added test for ReadableStream.

Adds ref-implementation license-header in streams-lib
and change gulp task to copy external/streams/ in build/
external/streams/ and build/dist/external/streams folder.

Adds README.md and LICENSE.md
2017-05-20 00:26:34 +05:30
chris.greening
cfc2f36f5c Adds additional parameter so background color of canvas can be set 2017-05-17 17:06:44 +01:00
Jonas Jenwald
bbe8c3d8ed Enable running a subset of the API unit-tests on Travis
Notably, this patch skips all canvas rendering tests in Node.js.
2017-05-12 11:48:27 +02:00
Jonas Jenwald
32baa6af7a Convert the DOMCMapReaderFactory to an ES6 class
Given that we only create *one* instance of this class per `getDocument` call, this shouldn't matter performance wise.
2017-05-11 20:15:19 +02:00
Jonas Jenwald
7a040c05d7 Wait until PDFDocumentLoadingTask.destroy is resolved before calling done in the API unit-tests
Try to ensure that everything, including workers, are properly destroyed before running the next test-case.
2017-05-11 12:17:54 +02:00
Yury Delendik
3adda80f97 Merge pull request #8358 from Snuffleupagus/PartialEvaluator-method-signatures
Change the signatures of the `PartialEvaluator` "constructor" and its `getOperatorList`/`getTextContent` methods to take parameter objects
2017-05-04 08:10:30 -05:00
Jonas Jenwald
3e20d30afc Change the signatures of the PartialEvaluator "constructor" and its getOperatorList/getTextContent methods to take parameter objects
Currently these methods accept a large number of parameters, which creates quite unwieldy call-sites. When invoking them, you have to remember not only what arguments to supply, but also the correct order, to avoid runtime errors.
Furthermore, since some of the parameters are optional, you also have to remember to pass e.g. `null` or `undefined` for those ones.
Also, adding new parameters to these methods (which happens occasionally), often becomes unnecessarily tedious (based on personal experience).

Please note that I do *not* think that we need/should convert *every* single method in `evaluator.js` (or elsewhere in `/core` files) to take parameter objects. However, in my opinion, once a method starts relying on approximately five parameter (or even more), passing them in individually becomes quite cumbersome.

With these changes, I obviously needed to update the `evaluator_spec.js` unit-tests. The main change there, except the new method signatures[1], is that it's now re-using *one* `PartialEvalutor` instance, since I couldn't see any compelling reason for creating a new one in every single test.

*Note:* If this patch is accepted, my intention is to (time permitting) see if it makes sense to convert additional methods in `evaluator.js` (and other `/core` files) in a similar fashion, but I figured that it'd be a good idea to limit the initial scope somewhat.

---

[1] A fun fact here, note how the `PartialEvaluator` signature used in `evaluator_spec.js` wasn't even correct in the current `master`.
2017-05-03 12:10:20 +02:00
Jonas Jenwald
40feca12c1 Ignore line-breaks between operator and digit in Lexer.getNumber
This is consistent with the behaviour in Adobe Reader (and PDFium), and it fixes the display of page 30 in https://bug1354114.bmoattachments.org/attachment.cgi?id=8855457 (taken from https://bugzilla.mozilla.org/show_bug.cgi?id=1354114).

The patch also makes the `error` message for invalid numbers slightly more useful, by including the charCode as well. (Having that information available would have reduced the time spent on debugging the PDF file above.)
2017-05-02 20:59:42 +02:00
Jonas Jenwald
7560f12a17 Enable the object-shorthand ESLint rule
Please see http://eslint.org/docs/rules/object-shorthand.

Unfortunately, based on commit 9276d1dcd9, it seems that we still need to maintain compatibility with old Node.js versions, hence certain files/directories that are executed in Node.js are currently exempt from this rule.

Furthermore, since the files specific to the Chromium extension are not run through Babel, the `/extensions/chromium/` directory is also exempt from this rule.
2017-04-30 11:13:34 +02:00
Tim van der Meij
35730148a7
Convert the files in the /test/unit folder to ES6 modules 2017-04-30 00:34:02 +02:00
Jonas Jenwald
ae04cf1c37 Enable running the ui_utils unit-tests on Travis
With the exception of just one test-case, all the current `ui_utils` unit-tests can run successfully on Node.js (since most of them doesn't rely on the DOM).

To get this working, I had to first of all add a new `LIB` build flag such that `gulp lib` produces a `web/pdfjs.js` file that is able to load `pdf.js` successfully.
Second of all, since neither `document` nor `navigator` is available in Node.js, `web/ui_utils.js` was adjusted slightly to avoid errors.
2017-04-25 13:37:56 +02:00
Jonas Jenwald
84472b30ee Change getPDFFileNameFromURL to ignore data: URLs for performance reasons (issue 8263)
The patch also changes the `defaultFilename` to use the ES6 default parameter notation, and fixes the formatting of the JSDoc comment.

Finally, since `getPDFFileNameFromURL` currently has no unit-tests, a few basic ones are added to avoid regressions.
2017-04-20 18:21:27 +02:00
Yury Delendik
30bee9fe0c Moves Uint32ArrayView and hasCanvasTypedArrays into compatibility.js. 2017-04-14 10:04:52 -05:00
Tim van der Meij
32e01cda96 Merge pull request #8228 from timvandermeij/line-annotations
Implement support for line annotations
2017-04-13 00:18:31 +02:00
Tim van der Meij
e15a2ec523
Annotations: implement support for line annotations
This patch implements support for line annotations. Other viewers only
show the popup annotation when hovering over the line, which may have
any orientation. To make this possible, we render an invisible line (SVG
element) over the line on the canvas that acts as the trigger for the
popup annotation. This invisible line has the same starting coordinates,
ending coordinates and width of the line on the canvas.
2017-04-12 23:05:25 +02:00
Yury Delendik
31f8875614 Merge pull request #8157 from Snuffleupagus/api-RenderTask-cancel-Error
[api-minor] Reject the `RenderTask` with an actual `Error`, instead of just a `string`, when rendering is cancelled
2017-04-04 09:38:47 -05:00
Jonas Jenwald
437104969d Improve the error handling when loading of built-in CMap files fail (PR 8064 follow-up)
I happened to notice that the error handling wasn't that great, which I missed previously since there were no unit-tests for failure to load built-in CMap files.
Hence this patch, which improves the error handling *and* adds tests.
2017-03-29 22:38:29 +02:00
Jonas Jenwald
5c0c122a7d Ensure that the XMLHttpRequest is opened before attempting to set the responseType in the DOMCMapReaderFactory, since IE fails otherwise (issue 8193)
I really cannot understand why this change is necessary, since modern browsers such as Firefox and Chrome work just fine with the old code.
Hence this is patch is yet another "hack" that's needed just because IE apparently cannot just work like you'd expect.

For consistency, the Node factory used in the CMap unit-tests is changed as well.

Fixes 8193.
2017-03-25 17:44:48 +01:00
Jonas Jenwald
e6db75b2ef Use the DOMCanvasFactory in the API unit-tests
There's still some work necessary if we want to be able to run (even a subset of) the API unit-tests on Travis.
However, this patch could be considered a small first step, since the relevant unit-tests will now rely on a `CanvasFactory` rather than using `document.createElement('canvas')` directly.
2017-03-13 18:58:26 +01:00
Jonas Jenwald
d37d271afa [api-minor] Reject the RenderTask with an actual Error, instead of just a string, when rendering is cancelled
This patch gets rid of the only case in the code-base where we're throwing a plain `string`, rather than an `Error`, which besides better/more consistent error handling also allows us to enable the [`no-throw-literal`](http://eslint.org/docs/rules/no-throw-literal) ESLint rule.
2017-03-13 18:58:21 +01:00
Jonas Jenwald
6d672c4ba6 [api-minor] Add a pdfjsNext parameter, and PDFJS_NEXT build flag, to allow backwards incompatible API changes 2017-03-13 18:43:43 +01:00
Tim van der Meij
fc5810c97a Merge pull request #8144 from timvandermeij/issue-8143
Widget annotations: do not crash if `Parent` is not a dictionary during field name construction (issue 8143)
2017-03-10 00:40:13 +01:00
Tim van der Meij
936d3c0698
Widget annotations: do not crash if Parent is not a dictionary
during field name construction (issue 8143)
2017-03-09 23:51:52 +01:00
Yury Delendik
39e8ad24f7 Creates 'lib' for the 'dist' build target. 2017-03-03 16:37:58 -06:00
Yury Delendik
e7cc07cc11 Moves checkProblematicCharRanges to font_spec.js 2017-03-03 16:33:35 -06:00
Jonas Jenwald
9163a6fba4 Merge pull request #8112 from Snuffleupagus/JS-action-newWindow
Support the `newWindow` flag in white-listed `app.launchURL` JavaScript actions (PR 7794 follow-up)
2017-03-01 21:24:34 +01:00
Tim van der Meij
25f772a255 Merge pull request #8050 from yurydelendik/systemjs
Replaces RequireJS to SystemJS.
2017-02-27 23:31:41 +01:00
Tim van der Meij
9db4240b85 Merge pull request #8110 from timvandermeij/interactive-forms-choice-inherit-options
Interactive forms: make choice widget options inheritable (issue 8094)
2017-02-27 22:14:25 +01:00
Jonas Jenwald
2a7e5b8a54 Support the newWindow flag in white-listed app.launchURL JavaScript actions (PR 7794 follow-up)
A simple follow-up to PR 7794, which let's us add support for the `newWindow` parameter; refer to https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf#G5.1507380.

The patch also fixes an embarrassing oversight regarding the placement of the case-insensitive flag, and also allows arbitrary white-space at the beginning of JS actions.
2017-02-27 15:58:28 +01:00
Yury Delendik
5b50e0d414 Replaces RequireJS to SystemJS. 2017-02-27 08:32:39 -06:00
Tim van der Meij
8990de8614
Interactive forms: make choice widget options inheritable (issue 8094)
Even though the PDF specification does not state that `Opt` fields are
inheritable, in practice there are PDF generators that let annotations
inherit the options from a parent.
2017-02-25 23:34:26 +01:00
Jonas Jenwald
9082f08e37 Enable running the cmap unit-tests on Travis by utilizing a NodeCMapReaderFactory 2017-02-17 23:15:36 +01:00
Jonas Jenwald
111419a64a Cache built-in binary CMap files in the worker (issue 4794) 2017-02-16 10:55:39 +01:00
Jonas Jenwald
769c1450b7 [api-minor] Refactor fetching of built-in CMaps to utilize a factory on the display side instead, to allow users of the API to provide a custom CMap loading factory (e.g. for use with Node.js)
Currently the built-in CMap files are loaded in `src/core/cmap.js` using `XMLHttpRequest` directly. For some environments that might be a problem, hence this patch refactors that to instead use a factory to load built-in CMaps on the main thread and message the data to the worker thread.

This is inspired by other recent work, e.g. the addition of the `CanvasFactory`, and to a large extent on the IRC discussion starting at http://logs.glob.uno/?c=mozilla%23pdfjs&s=12+Oct+2016&e=12+Oct+2016#c53010.
2017-02-16 10:55:35 +01:00
Tim van der Meij
9f05a5a211 Interactive forms: unit test for radio buttons without a field value 2017-02-07 23:44:31 +01:00
Jonas Jenwald
e416032b38 Prevent browser console errors during testing
The `Driver._cleanup` method is removing all stylesheets between test runs, which causes "TypeError: styleElement.parentNode is null" console errors in `FontLoader.clear`.

As can also be seen during various tests, some of the changes I made in PR 7972 unfortunately causes console errors.
It seems that I didn't test this properly, since it *should* have been obvious to me that while tests are triggered using Node.js, the files in question are run within the *browser*.
My apologies for not testing this thoroughly, and for causing unnecessary churn in the code!
2017-02-05 13:23:42 +01:00
Jonas Jenwald
bc736fdc7d Adjust the brace-style ESLint rule to disallow single lines (and also enable no-iterator)
See http://eslint.org/docs/rules/brace-style.
Having the opening/closing braces on the same line can often make the code slightly more difficult to read, in particular for `if`/`else if` statements, compared to using new lines.

This patch also, for consistency with `mozilla-central`, enables the [`no-iterator`](http://eslint.org/docs/rules/no-iterator) rule. Note that this rule didn't require a single code change.
2017-02-04 15:53:08 +01:00
Jonas Jenwald
52e0f51917 Enable the no-unused-vars ESLint rule
Please see http://eslint.org/docs/rules/no-unused-vars; note that this patch purposely uses the same rule options as in `mozilla-central`, such that it fixes part of issue 7957.

It wasn't, in my opinion, entirely straightforward to enable this rule compared to the already existing rules. In many cases a `var descriptiveName = ...` format was used (more or less) to document the code, and I choose to place the old variable name in a trailing comment to not lose that information.

I welcome feedback on these changes, since it wasn't always entirely easy to know what changes made the most sense in every situation.
2017-01-29 23:23:17 +01:00
Jonas Jenwald
e88c9c75db Simplify the FileAttachmentAnnotation unit-test to avoid having to use the entire API in the test
Every other unit-test in `annotation_spec.js` is already only testing the annotation code. Hence it seems unnecessarily convoluted to make use of the API here, when we can (fairly) simply provide the necessary data explicitly as in all the other annotation unit-test.
2017-01-12 19:10:37 +01:00
Jonas Jenwald
7c3a63bae0 Rename annotation_layer_spec.js to annotation_spec.js since the unit-tests only cover src/core/annotation.js functionality 2017-01-12 19:08:57 +01:00
Syed Abdullah
857a5da8f1 Fix inverted calculation of RTL text percentage in bidi. 2017-01-12 23:54:06 +08:00
Jonas Jenwald
642d8621ef Replace direct lookup of uniquePrefix/idCounters, in Page instances, with an idFactory containing an createObjId method instead
We're currently making use of `uniquePrefix`/`idCounters` in multiple files, to create unique object id's, and adding a new occurrence of them requires some care to ensure that an object id isn't accidentally reused.
Furthermore, having to pass around multiple parameters as we currently do seem like something you want to avoid.

Instead, this patch adds a factory which means that there's only *one* thing that needs to be passed around. And since it's now only necessary to call a method in order to obtain a unique object id, the details are thus abstracted away at the call-sites which avoids accidental reuse of object id's.

To test that this works as expected a very simple `Page` unit-test is added, and the existing `Annotation layer` tests are also adjusted slightly.
2017-01-09 23:16:25 +01:00
Yury Delendik
c45300e06c Enables some unit tests on travis. 2017-01-09 15:43:45 -06:00
porlan1
d9e1cb7955 unit test files as UMD modules 2017-01-09 11:40:57 -05:00
Jonas Jenwald
27513cd23b [api-minor] Ensure that the getDocument Promise is rejected if the loadingTask is destroyed, or an Error is thrown, inside of the onPassword callback (issue 7806)
This patch also removes the `UpdatePassword` message, in favour of using the `sendWithPromise` method of `MessageHandler`.
Furthermore, the patch also refactors the `BasePdfManager_updatePassword`/`BasePdfManager_passwordChanged` methods (in pdf_manager.js), and the `pdfManagerReady` function (in worker.js).
2017-01-03 20:29:46 +01:00
Tim van der Meij
a428899b3c Button widget annotations: improve unit tests, simplify code and remove labels
Modern browsers support styling radio buttons and checkboxes with CSS.
This makes the implementation much easier, and the fallback for older
browsers is still decent.
2016-12-17 20:38:48 +01:00
benweet
ba012c7a68 Button widget annotations: implement checkboxes and radio buttons 2016-12-17 20:31:30 +01:00
Jonas Jenwald
bd91f34513 Ensure that we handle indirect objects in all types of Opt entries in ChoiceWidget annotation dictionaries
I haven't got an example where the current code breaks, but given all the previous cases we've seen where PDF generators use indirect objects in Arrays it makes sense to fix this pro-actively.
I've modified the relevant unit-tests slightly, and they would *not* pass without the code changes in this patch.

*Note:* `Dict_getArray` only dereferences Array elements on the "top-level", to avoid recursion issues. Furthermore if you have to loop through the Array at the call-site anyway, then using `Dict_get` in combination with `XRef_fetchIfRef` is a tiny bit more efficient.
2016-12-17 13:44:20 +01:00
Jonas Jenwald
c850968fa7 Remove globals that are now unnecessary thanks to the use of various ESLint environments (e.g. Node, ShellJS, Jasmine) 2016-12-16 21:09:55 +01:00
Jonas Jenwald
2f3805efbc Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.*

ESLint has a number of advantageous properties, compared to JSHint. Among those are:
 - The ability to find subtle bugs, thanks to more rules (e.g. PR 7881).
 - Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint.
 - Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary).
 - The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage.
 - More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead.

By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want.
Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much.

I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations.

Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%).

A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible:
 - `comma-dangle`, controls trailing commas in Objects and Arrays (among others).
 - `object-curly-spacing`, controls spacing inside of Objects.
 - `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.)

Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed.

Useful links:
 - http://eslint.org/docs/user-guide/configuring
 - http://eslint.org/docs/rules/
2016-12-16 21:06:36 +01:00
Jonas Jenwald
28e50cfa21 Fix errors reported by the space-infix-ops ESLint rule
http://eslint.org/docs/rules/space-infix-ops
2016-12-12 20:36:00 +01:00
Jonas Jenwald
aae27e76bb Fix errors reported by the no-multiple-empty-lines ESLint rule
http://eslint.org/docs/rules/no-multiple-empty-lines
2016-12-12 20:35:58 +01:00
Jonas Jenwald
efbb1e9b1c Fix errors reported by the new-cap ESLint rule
http://eslint.org/docs/rules/new-cap
2016-12-12 20:35:57 +01:00
Jonas Jenwald
6606540fe4 Fix errors reported by the func-call-spacing ESLint rule
http://eslint.org/docs/rules/func-call-spacing
2016-12-12 20:35:54 +01:00
Jonas Jenwald
ad915f8af1 Fix errors reported by the comma-spacing ESLint rule
http://eslint.org/docs/rules/comma-spacing
2016-12-12 20:35:53 +01:00
Jonas Jenwald
e53ab844cc Fix errors reported by the no-useless-concat ESLint rule
http://eslint.org/docs/rules/no-useless-concat
2016-12-12 20:35:51 +01:00
Jonas Jenwald
e386af7b22 Adjust one of the Page Label unit-tests to use a PDF file where the "St" entry is both present and non-default (i.e. greater than one)
I just realized that none of our current unit-tests cover this particular part of the Page Label parsing code, hence this patch adjusts an existing test PDF to include a "St" entry in the Page Label dictionary.
2016-12-04 13:03:22 +01:00
Javier Infante
54fab606ee add basic unit-tests for murmurhash3.js 2016-12-01 02:21:05 +01:00
Sean Burke
f76cd2ce43 Expose the optional UserUnit entry as a page property 2016-11-22 09:18:19 -07:00
Jonas Jenwald
6d8a404a9c [api-minor] Add support for a couple of white-listed JavaScript actions that contains valid URLs (issue 3897, bug 843699)
By only allowing very specific type of `JavaScript` actions, and also utilizing the existing `URL` validation, this patch shouldn't pose too much risk.

Fixes one of the points in issue 3897 (with the PDF file taken from issue 3438).
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=843699 (probably, since that bug doesn't contain a test-case).
2016-11-08 16:48:27 +01:00
Jonas Jenwald
b4100ba651 Merge pull request #7698 from Snuffleupagus/bug-1308536
Ignore reserved commands when parsing operands in `CFFParser_parseDict`, instead of just rejecting the entire font (bug 1308536)
2016-11-03 23:53:14 +01:00
Jonas Jenwald
2d8d8b5e53 Use stringToPDFString to sanitizing bad "Prefix" entries in Page Label dictionaries
It seems that certain bad PDF generators can create badly encoded "Prefix" entries for Page Labels, one example being http://ukjewishfilm.org/wp-content/uploads/2015/09/Jewish-Film-Festival-Programme-ONLINE.pdf.

Unfortunately I didn't come across such a PDF file while adding the API support for Page Labels, but with them now being used in the viewer I just found this issue. With this patch, we now display the Page Labels in the same way as Adobe Reader.
2016-11-03 19:48:08 +01:00
Jonas Jenwald
9dc6463933 Ignore reserved commands when parsing operands in CFFParser_parseDict, instead of just rejecting the entire font (bug 1308536)
According to the CFF specification, see http://partners.adobe.com/public/developer/en/font/5176.CFF.pdf#page=11, certain commands are currently reserved.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1308536.
2016-11-03 12:50:40 +01:00
Tim van der Meij
9f8d67475e Merge pull request #7775 from timvandermeij/widget-annotation-name
Widget annotation: implement field name according to the specification
2016-11-02 22:43:17 +01:00
Tim van der Meij
1d96854019 Widget annotation: implement field name according to the specification
The original code is difficult to read and, more importantly, performs
actions that are not described in the specification. It replaces empty
names with a backtick and an index, but this behavior is not described
in the specification. While the specification is not entirely clear
about what should happen in this case, it does specify that the `T`
field is optional and that multiple field dictionaries may have the same
fully qualified name, so to achieve this it makes the most sense to
ignore missing `T` fields during construction of the field name. This is
the most specification-compliant solution and, judging by opened issue #6623, also the required and expected behavior.
2016-11-02 21:44:44 +01:00
Tim van der Meij
6e22b32372 Merge pull request #7745 from Snuffleupagus/Launch-actions
[api-minor] Add basic support for `Launch` actions (issue 1778, issue 3897, issue 6616)
2016-11-01 21:12:08 +01:00
Tim van der Meij
5194e68134 Lint: correct code style violations
Manual observations and working with other linting tools found these.
2016-11-01 15:04:21 +01:00
Jonas Jenwald
2b79782377 [api-minor] Add basic support for Launch actions (issue 1778, issue 3897, issue 6616)
In general we neither want, nor can, support arbitrary `Launch` actions. But in practice, all the cases we've seen so far just contains relative URLs to other PDF files. Building on PR 7689, we can thus at least support basic `Launch` actions.
2016-10-21 13:40:32 +02:00
Jonas Jenwald
d284cfd5eb [api-minor] Add support for relative URLs, in both annotations and the outline, by adding a docBaseUrl parameter to PDFJS.getDocument (bug 766086)
Note that in `FIREFOX/MOZCENTRAL/CHROME` builds of the standard viewer the `docBaseUrl` parameter will be set by default, since in that case it makes sense to use the current URL as a base.
For the `GENERIC` viewer, or the API itself, it doesn't make sense to try and set the `docBaseUrl` by default. However, custom deployments/implementations may still find the parameter useful.
2016-10-19 22:20:24 +02:00
Jonas Jenwald
42f07c6262 [api-minor] Use the new URL constructor when validating URLs in annotations and the outline, as a complement to only checking the protocol, and add a bit more validation to Catalog_parseDestDictionary
Note that this will automatically reject any relative URL.
To make the API more useful to consumers, URLs that are rejected will be available via the `unsafeUrl` property in the data object returned by `PDFPageProxy_getAnnotations`.

The patch also adds a bit more validation of the data for `Named` actions.
2016-10-19 22:11:17 +02:00
Jonas Jenwald
e64bc1fd13 Move parsing of destination dictionaries to a helper function
This not only reduces code duplication, but it also allow us to easily support the same kind of URLs we currently do for Link annotations in the Outline as well.
2016-10-18 16:14:07 +02:00
Tim van der Meij
9b3a91f365 Merge pull request #7671 from timvandermeij/interactive-forms-choice-fields
Interactive forms: render choice widget annotations
2016-10-05 23:27:45 +02:00
Tim van der Meij
f85f3243b1 Choice widget annotations: unit and reference testing 2016-10-05 21:25:29 +02:00
Jonas Jenwald
93830032ac Add a unit-test for annotations where the URI action has an incorrect encoding (bug 1122280, PR 5999) 2016-09-30 11:44:24 +02:00
Tim van der Meij
375229d6b9 Widget annotations: simplify field flag handling
Directly use the hexadecimal representation, just like the
`AnnotationFlags`, to avoid calculations and to improve readability.
This allows us to simplify the unit tests for text widget annotations as
well.
2016-09-21 21:11:37 +02:00
Tim van der Meij
6100ab4b18 Text widget annotations: implement comb support 2016-09-20 22:31:10 +02:00
Tim van der Meij
adf0972ca5 Text widget annotations: improve unit and reference tests
This patch improves the unit tests by testing the support for read-only
and multiline fields. Moreover, we add a reference test to ensure that
the text widgets are not only rendered, but also that their contents are
styled properly.

Finally, we perform minor improvements in `src/core/annotation.js`, for
example adding missing comments.
2016-09-17 15:24:48 +02:00
Tim van der Meij
323e86c442 Text widget annotations: implement unit testing and sanitize data values 2016-09-13 14:57:11 +02:00
Jonas Jenwald
37998076c9 In display/api.js ensure that we always reject with an Error in JpegDecode, and adjust a couple of other rejection sites as well
In the case where the document was destroyed, we were rejecting the `Promise` in `JpegDecode` with a string instead of an `Error`. The patch also brings the wording more inline with other such rejections.

Use the `isInt` utility function when validating the `pageNumber` parameter in `WorkerTransport_getPage`, to make it more obvious what's actually happening. There's also a couple more unit-tests added, to ensure that we always fail in the expected way.

Finally, we can simplify the rejection handling in `WorkerTransport_getPageIndexByRef` somewhat. (Note that the only reason for using `catch` here is that since the promise is rejected on the worker side, the `reason` becomes a string instead of an `Error` which is why we "re-reject" on the display side.)
2016-09-05 16:35:32 +02:00
Tim van der Meij
f520616e00 Merge pull request #7570 from Snuffleupagus/issue-7569
Create a fallback annotation `id` for entries in `Annots` dictionaries that are not indirect objects (issue 7569)
2016-08-28 00:23:59 +02:00
Tim van der Meij
b81d661556 Remove unused globals from fonts unit test file 2016-08-27 23:20:03 +02:00
Jonas Jenwald
088ce6c009 Add a unit-test to check that ProblematicCharRanges contains valid entries
When adding new entries to `ProblematicCharRanges`, you have to be careful to not make any mistakes since that could cause glyph mapping issues.
Currently the existing reference tests should probably help catch any errors, but based on experience I think that having a unit-test which specifically checks `ProblematicCharRanges` would be both helpful and timesaving when modifying/reviewing changes to this code.

Hence this patch which adds a function (and unit-test) that is used to validate the entries in `ProblematicCharRanges`, and also checks that we don't accidentally add more character ranges than the Private Use Area can actually contain.
The way that the validation code, and thus the unit-test, is implemented also means that we have an easy way to tell how much of the Private Use Area is potentially utilized by re-mapped characters.
2016-08-27 11:56:00 +02:00
Jonas Jenwald
78889646c8 Create a fallback annotation id for entries in Annots dictionaries that are not indirect objects (issue 7569)
According to the PDF specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#page=86, entries in `Annots` dictionaries should be indirect objects, but obviously there're PDF generators that ignore this.

Fixes 7569.
2016-08-27 10:56:16 +02:00
Jonas Jenwald
db1526c59e Add unit-tests for asynchronous methods in primitives.js
In PR 7520, I missed the fact that we currently have no unit-tests for `Dict_getAsync`.
2016-08-21 18:44:58 +02:00
Jonas Jenwald
af636aae96 Add a parameter to the isName function that enables checking not just that something is a Name, but also that the actual name properties matches
This is similar to the existing `isCmd` and `isDict` functions, which already support similar kind of checks.
With the updated `isName` function, we'll be able to simplify many callsites from: `isName(someVariable) && someVariable.name === 'someName'` to: `isName(someVariable, 'someName')`.
2016-08-10 11:15:03 +02:00
Jonas Jenwald
d70e07fb90 Add more unit-tests for primitives.js 2016-08-03 17:04:12 +02:00
Yury Delendik
a02e2686b9 Merge pull request #7475 from Snuffleupagus/api-getTextContent-combineTextItems
[api-minor] Add a parameter to `PDFPageProxy_getTextContent` that controls whether `PartialEvaluator_getTextContent` will attempt to combine same line text items
2016-07-27 08:34:24 -05:00
Jonas Jenwald
558a22cd02 Prevent errors when parsing Annotations with missing (or invalid) /Subtype entries (issue 7446)
Note that I used a separate warning message for this case, instead of utilizing the same one as in the unsupported subtype case, to more clearly indicate that the PDF file itself is to blame rather than PDF.js.

Fixes 7446.
2016-07-25 13:59:26 +02:00
Jonas Jenwald
f297e4d17c [api-minor] Add a parameter to PDFPageProxy_getTextContent that controls whether PartialEvaluator_getTextContent will attempt to combine same line text items
From the discussion in issue 7445, it seems that there may be cases where an API consumer would want to get the text content as is, without combined text items.
2016-07-19 13:38:57 +02:00
Jonas Jenwald
72c1df726e Add a getAttachments unit-test for a PDF file that actually contains attachments 2016-07-02 13:13:30 +02:00
Tim van der Meij
f97d52182a Merge pull request #7341 from Snuffleupagus/getDestinationHash-Array
[api-minor] Improve handling of links that are using explicit destination arrays
2016-06-09 00:29:10 +02:00
Jonas Jenwald
6260fc09a3 Attempt to recover valid format 3 FDSelect data from broken CFF fonts (bug 1146106)
According to the CFF specification, see http://partners.adobe.com/public/developer/en/font/5176.CFF.pdf#G3.46884, for `format 3` FDSelect data: "The first range must have a ‘first’ GID of 0".
Since the PDF file (attached in the bug) violates that part of the specification, this patch tries to recover valid FDSelect data to prevent OTS from rejecting the font.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1146106.
2016-06-06 18:20:52 +02:00
Jonas Jenwald
98fe094d18 Let non-viewable Popup Annotations inherit the parent's Annotation Flags if the parent is viewable
Fixes http://www.pdf-archive.com/2013/09/30/file2/file2.pdf.

Note how it's not possible to show the various Popup Annotations in the above document.
To fix that, this patch lets the Popup inherit the flags of the parent, in the special case where the parent is `viewable` *and* the Popup is not.
In general, I don't think that a Popup must have the same flags set as the parent. However, it seems very strange to have a `viewable` parent annotation, and then not being able to view the Popup.

Annoyingly the PDF specification doesn't, as far as I can find, mention anything about how this case should be handled, but this patch seem consistent with the actual behaviour in Adobe Reader.
2016-05-25 23:00:26 +02:00
Brendan Dahl
b86610ffdb Merge pull request #7300 from Snuffleupagus/bug-1068432
Prevent adding invalid values in `CFFDict_setByKey` (bug 1068432)
2016-05-24 12:12:38 -07:00
Jonas Jenwald
b354682dd6 [api-minor] Let LinkAnnotation/PDFLinkService_getDestinationHash return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.

Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.

With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.

*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.

 - First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.

 - Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.

 - Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".

---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-21 14:14:07 +02:00
Jonas Jenwald
01ab15a6f1 [api-minor] Let Catalog_getPageIndex check that the Ref actually points to a /Page dictionary
Currently the `getPageIndex` method will happily return `0`, even if the `Ref` parameter doesn't actually point to a proper /Page dictionary.
Having the API trust that the consumer is doing the right thing seems error-prone, hence this patch which adds a check for this case.

Given that the `Catalog_getPageIndex` method isn't used in any hot part of the codebase, this extra check shouldn't be a problem.
(Note: in the standard viewer, it is only ever used from `PDFLinkService_navigateTo` if a destination needs to be resolved during document loading, which isn't common enough to be an issue IMHO.)
2016-05-21 14:13:41 +02:00
Tim van der Meij
db46829ef7 Merge pull request #7316 from timvandermeij/remove-unused
Remove unused variables
2016-05-21 14:07:33 +02:00
Jonas Jenwald
c5c5a2a71f Add basic unit-tests for unicode.js
Re: issue 7261.
2016-05-19 19:45:45 +02:00
Tim van der Meij
6a7012aaca Remove unused variables
These have been found using `gulp lint` in combination with the `unused:
true` parameter for JSHint. Unfortunately there are too many false
positives to enable this feature, but now that most globals have been
removed because of the conversion to UMD the results are much more
useful than before.
2016-05-11 16:11:13 +02:00
Jonas Jenwald
c9b6de3b16 Prevent adding invalid values in CFFDict_setByKey (bug 1068432)
In the font in question, there are a couple of `topDict` entries that have invalid values (`0xF 0xF`, i.e. just eof markers without any actual numbers).
This causes the `parseFloatOperand` function, inside `CFFParser_parseDict`, to return `NaN`. Currently we pass this broken font onto the browser, which OTS unsurprisingly rejects.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1068432.
2016-05-07 21:09:58 +02:00
Jonas Jenwald
29c4a604af Split the font_spec.js unit-tests into cff_parser_spec.js and type1_parser_spec.js
Re: issue 7261.

Given the we have `gulp fonttest`, which tests the `fonts.js` functionality at a higher level, and that we have *a lot* of font specific reference tests, I'm not convinced that we *also* need unit-tests for it.
2016-05-03 09:37:36 +02:00
Yury Delendik
7fd3db9977 Adds EventBus. 2016-04-28 06:57:24 -05:00
Jonas Jenwald
b4a17323b6 Move isDict unit-tests from util_spec.js to primitives_spec.js
This patch moves the unit-test to the correct file, since the `isDict` function was moved PR 6683.
2016-04-16 20:32:46 +02:00
Jonas Jenwald
4523ae0b91 Add a couple of CipherTransformFactory unit-tests to check that blank passwords are correctly rejected 2016-04-16 20:24:55 +02:00
Jonas Jenwald
171f908b89 Add a couple of LinkAnnotation unit-tests
We currently don't have *any* unit-tests for `LinkAnnotation`s, so it seemed a good idea to add a few. These tests are taken from various actual PDF files.
2016-04-15 22:59:08 +02:00
Prakash Palanisamy
a25c29d98d Remove combineUrl and replace it with new URL. 2016-04-15 21:33:10 +05:30
Yury Delendik
6282ec24d1 Merge pull request #7172 from yurydelendik/umd-web
Introduces UMD headers to the web/ folder.
2016-04-13 10:23:23 -05:00
Yury Delendik
006e8fb59d Introduces UMD headers to the web/ folder. 2016-04-13 10:09:48 -05:00
Yury Delendik
879340d741 Removes hijack describe() hack from unit tests. 2016-04-11 07:37:35 -05:00
Yury Delendik
44c63bca28 Merge pull request #7175 from Snuffleupagus/issue-6905-font_spec
Use `beforeAll`/`afterAll` in font_spec.js (issue 6905)
2016-04-11 07:20:45 -05:00
Yury Delendik
070f2d32ad Merge pull request #7171 from Snuffleupagus/remove-new-Name/Cmd
Remove the remaining usages of `new {Name,Cmd}` in favor of `{Name,Cmd}.get`
2016-04-11 07:17:30 -05:00
Jonas Jenwald
c4e21c93a2 Use beforeAll/afterAll in font_spec.js (issue 6905)
This patch fixes the only remaining point in issue 6905.
2016-04-10 16:09:11 +02:00
Jonas Jenwald
b0ce83b372 Use beforeAll/afterAll in CipherTransformFactory in crypto_spec.js (issue 6905
This patch also adds/improves utility functions for checking if the passwords are correct/incorrect, and replaces `string2binary` with `stringToBytes`. Finally the patch does away with the `DictMock`, in favour of using actual `Dict`s.

Re: issue 6905.
2016-04-10 13:20:21 +02:00
Jonas Jenwald
f59c3a0644 Remove the remaining usages of new {Name,Cmd} in favor of {Name,Cmd}.get
Using `new {Name,Cmd}` should be avoided, since it creates a new object on *every* call, whereas `{Name,Cmd}.get` uses caches to only create *one* object regardless of how many times they are called.

Most of these are found in the unit-tests, where increased memory usage probably doesn't matter very much. But it still seems good to get rid of those cases, since no part of the codebase ought to advertise that usage.

Given the small size of the patch, I'm also tweaking a few comments and class names.
2016-04-08 12:14:05 +02:00
Jonas Jenwald
c6c5b8fab8 Use beforeAll/afterAll in isExternalLinkTargetSet in dom_utils_spec.js (issue 6905)
Re: issue 6905.
2016-04-07 14:00:40 +02:00
Jonas Jenwald
ef551e8266 Extract Type1Parser from fonts.js 2016-04-01 23:38:53 +02:00
Jonas Jenwald
b961e1d21b Extract CFFParser from fonts.js (issue 6777) 2016-04-01 22:32:39 +02:00
Jonas Jenwald
7163e1eff3 Faster unit-tests by using beforeAll/afterAll in api_spec.js
In the API unit-tests, we're currently loading the `basicapi.pdf` before every sub-test in `PDFDocument` and `Page`, which slows down the unit-tests quite a bit.
Locally this patch reduces the run time for `gulp unittest` by at least 40% for me.
2016-03-30 15:32:01 +02:00
Jonas Jenwald
ac772017b6 Add unit-tests for destionations in /Names (NameTree) dictionaries where all entries are indirect objects
Re: issue 6204 and PR 6208.
2016-03-29 17:55:05 +02:00
Yury Delendik
0a700fa29d Updates Jasmine version. 2016-03-29 09:34:13 -05:00
Yury Delendik
a8e5912cb1 Moves shared/global to display/global 2016-03-23 19:24:37 -05:00
Yury Delendik
bda5e6235e Removes global PDFJS usage from the src/core/. 2016-03-23 19:24:37 -05:00
Manas
f6d28ca323 Refactors CMapFactory.create to make it async 2016-03-21 23:08:19 +05:30
Yury Delendik
22341c0761 Merge pull request #6879 from yurydelendik/streams
Makes PDF data reading Streams API friendly.
2016-03-01 09:10:52 -06:00
Jonas Jenwald
41efb92d3a Merge pull request #6988 from timvandermeij/fileattachment-annotation
Implement support for FileAttachment annotations
2016-02-24 12:58:06 +01:00
Tim van der Meij
0351c7eff4 Move the getFileName helper function to the core
This is required to be able to use it in the annotation display code,
where we now apply it to sanitize the filename of the FileAttachment
annotation. The PDF file from https://bugzilla.mozilla.org/show_bug.cgi?id=1230933 has shown that some PDF generators include the path of the file rather than the filename, which causes filenames with weird initial characters. PDF viewers handle this differently (for example Foxit Reader just replaces forward slashes with spaces), but we think it's better to only show the filename as intended.

Additionally we add unit tests for the `getFilenameFromUrl` helper
function.
2016-02-23 22:49:53 +01:00
Tim van der Meij
10902fd882 Implement unit and reference testing for FileAttachment annotations 2016-02-23 22:49:53 +01:00
Yury Delendik
0d591719d9 Makes PDF data reading Streams API friendly. 2016-02-18 13:17:53 -06:00
Jonas Jenwald
7cf9de2c17 [api-minor] Change getOutline to actually return the RGB color of outline items
Currently the `C` entry in an outline item is returned as is, which is neither particularly useful nor what the API documentation claims.

This patch also adds unit-tests for both the color handling, and the `F` entry (bold/italic flags).
2016-02-15 13:41:22 +01:00
Jonas Jenwald
98db068079 Reduce the overall indentation level in Catalog_readDocumentOutline, by using early returns, in order to improve readability 2016-02-14 11:38:43 +01:00
Tim van der Meij
5bcf4c1895 Destroy workers when they are no longer needed in the unit tests 2016-01-29 12:23:17 +01:00
Jonas Jenwald
1140a34f5c [api-minor] Change getPageLabels to always return the pageLabels, even if they are identical to standard page numbering 2016-01-27 13:36:03 +01:00
Jonas Jenwald
85cf90643f [api-minor] Add support for PageLabels in the API 2016-01-19 22:49:04 +01:00
Jonas Jenwald
0030a82dc3 [api-minor] Add support for URLs in the document outline
Re: issue 5089.
(Note that since there are other outline features that we currently don't support, e.g. bold/italic text and custom colours, I thus think we can keep the referenced issue open.)
2016-01-19 21:36:27 +01:00
Tim van der Meij
4399d01169 Merge pull request #6834 from Snuffleupagus/issue-6832
Strip `null` (\x00) characters from the URLs in LinkAnnotations (issue 6832)
2016-01-05 23:59:25 +01:00
Brendan Dahl
eb7c36beb6 Add validation for callsubr and callgsubr for type 2 charstrings. 2016-01-05 09:54:25 -08:00
Jonas Jenwald
97c10e9c08 Strip null (\x00) characters from the URLs in LinkAnnotations (issue 6832)
Apparently some PDF files can have annotations with `URI` entries ending with `null` characters, thus breaking the links.
To handle this edge-case of bad PDFs, this patch moves the already existing utility function from `ui_utils.js` into `util.js`, in order to fix those URLs.

Fixes 6832.
2016-01-04 21:55:20 +01:00
Yury Delendik
85e95d34ed Use RequireJS in the viewer, examples and tests. 2015-12-29 09:20:52 -06:00
Yury Delendik
6b60c8f4db Adds UMD headers to core, display and shared files. 2015-12-15 13:24:39 -06:00
Tim van der Meij
91274d6d2d Rename annotation_helper.js to annotation_layer.js 2015-12-02 23:30:28 +01:00
Jonas Jenwald
995e1a45b8 Ensure that Lexer_getName does not fail if a Name contains in invalid usage of the NUMBER SIGN (#) (issue 6692)
*This is a regression from PR 3424.*

The PDF file in the referenced issue is using `Type3` fonts. In one of those, the `/CharProcs` dictionary contains an entry with the name `/#`. Before the changes to `Lexer_getName` in PR 3424, we were allowing certain invalid `Name` patterns containing the NUMBER SIGN (#).

It's unfortunate that this has been broken for close to two and a half years before the bug surfaced, but it should at least indicate that this is not a widespread issue.

Fixes 6692.
2015-11-28 11:59:09 +01:00
Tim van der Meij
5fcd779812 Merge pull request #6209 from Rob--W/parallel-rendering
Fix font rendering when rendering multiple PDFs in parallel
2015-11-25 22:51:15 +01:00
Jonas Jenwald
6dfe53b976 [api-minor] Add a parameter to PDFPageProxy_getTextContent that enables replacing of all whitespace with standard spaces in the textLayer (issue 6612)
This patch goes a bit further than issue 6612 requires, and replaces all kinds of whitespace with standard spaces.

When testing this locally, it actually seemed to slightly improve two existing test-cases (`tracemonkey-text` and `taro-text`).

Fixes 6612.
2015-11-25 17:28:40 +01:00
Rob Wu
07f2a43943 Add tests for parallel rendering 2015-11-25 17:22:51 +01:00
Yury Delendik
09772e1e15 Creates PDFWorker, separates fetchDocument from transport. 2015-11-24 13:27:22 -06:00
Jonas Jenwald
b05652ca97 [api-minor] Let getAnnotations fetch all annotations by default, unless an intent is specified
Currently `getAnnotations` will *only* fetch annotations that are either `viewable` or `printable`. This is "hidden" inside the `core.js` file, meaning that API consumers might be confused as to why they are not recieving *all* the annotations present for a page.

I thus think that the API should, by default, return *all* available annotations unless specifically told otherwise. In e.g. the default viewer, we obviously only want to display annotations that are `viewable`, hence this patch adds an `intent` parameter to `getAnnotations` that makes it possible to decide if only `viewable` or `printable` annotations should be fetched.
2015-11-22 15:51:37 +01:00
Tim van der Meij
0991c06395 Refactor annotation flags code
This patch makes it possible to set and get all possible flags that the PDF specification defines. Even though we do not support all possible annotation types and not all possible annotation flags yet, this general framework makes it easy to access all flags for each annotation such that annotation type implementations can use this information.

We add constants for all possible annotation flags such that we do not need to hardcode the flags in the code anymore. The `isViewable()` and `isPrintable()` methods are now easier to read. Additionally, unit tests have been added to ensure correct behavior.

This is another part of #5218.
2015-11-22 01:06:37 +01:00
Yury Delendik
56ccaea99b Move text layer building logic into src/display/text_layer.js 2015-11-19 10:50:27 -06:00
Yury Delendik
2f34fd46cb Move CustomStyle. 2015-11-19 10:47:17 -06:00
Manas
a2ba1b8189 Uses editorconfig to maintain consistent coding styles
Removes the following as they unnecessary
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
2015-11-14 07:32:18 +05:30
Jonas Jenwald
1c66d4a106 Add a totalLength getter to OperatorList, since the length is zero after flushing
In the `RenderPageRequest` handler in `worker.js`, we attempt to print an `info` message containing the rendering time and the length of the operator list. The latter is currently broken (and has been for quite some time), since the `length` of an `OperatorList` is reset when flushing occurs.
This patch attempts to rectify this, by adding a getter which keeps track of the total length.
2015-10-26 18:12:14 +01:00
Jonas Jenwald
25e55322c4 Improved get fingerprint unit-tests (PR 5124)
This patch adds a unit-test for the changes contained in PR 5124, and also improves the existing `get fingerprint` test slightly.
2015-10-24 14:18:36 +02:00
Yury Delendik
58c3ea0820 Adds thread abort capabilities. 2015-10-23 09:06:32 -05:00
Yury Delendik
59c13b32aa Adds destroy method to the document loading task.
Also renames PDFPageProxy.destroy method to cleanup.
2015-10-23 08:57:14 -05:00
Jonas Jenwald
e04113a35b Add unit-tests for the onPassword/onProgress callbacks of the API
The standard viewer implicitly depends on the `onPassword` and `onProgress` callbacks, in order to open password protected PDF files, respectively to report file loading progress. We currently have no unit-tests for this functionality, which seems unfortunate; hence this patch.

*Please note:* Rather than adding more unit-tests to `api_spec.js`, I slightly extended/reworked two existing tests. Specifically for the password test, this *does not* really change what we actually test, just how the test is done.
2015-10-21 00:01:52 +02:00
Jonas Jenwald
5987197bd5 Ensure that all getDocument unit-tests returns the expected data 2015-10-16 18:54:20 +02:00
Jonas Jenwald
34cbee9bd3 Add unit-tests for PR 6531 2015-10-16 18:54:18 +02:00
Jonas Jenwald
39b962e3b0 Add unit-tests for isExternalLinkTargetSet 2015-10-13 21:56:46 +02:00
Brendan Dahl
3eaeacfe19 Merge pull request #6476 from Snuffleupagus/PartialEvaluator_readToUnicode-cmap-length
Right-size the `map` array in PartialEvaluator_readToUnicode
2015-10-09 10:31:28 -07:00
Jonas Jenwald
e8ad6c9d13 Add a unit-test for bug 1020226
For reference, see PR 4902 and https://bugzilla.mozilla.org/show_bug.cgi?id=1020226.
2015-10-04 15:45:24 +02:00
Jonas Jenwald
ae255f8921 Slightly improved getPage unit-tests 2015-10-04 14:28:24 +02:00
Jonas Jenwald
8d831449ab Right-size the map array in PartialEvaluator_readToUnicode
We can avoid a lot of intermediate resizings, by directly allocating the required number of elements for the `map` array.
2015-09-24 13:08:53 +02:00
Jonas Jenwald
297984e2e9 Add unit-tests for removeNullCharacters (PR 6431 follow-up)
I overlooked that we already had existing unit-tests for `web/ui_utils.js`, so this PR adds a few tests for `removeNullCharacters` (see PR 6431).
2015-09-14 12:19:29 +02:00
Jonas Jenwald
c5c8b239e9 Add unit-tests for stringToPDFString
The other day I was looking as the utilily function `stringToPDFString`, and I noticed that it didn't have any unit-tests. This patch fixes that.
2015-09-10 12:25:40 +02:00
Yury Delendik
943efea876 Merge pull request #6404 from Snuffleupagus/linearization-unit-tests
Add unit-tests for Linearization dictionary parsing (PR 5023 follow-up)
2015-08-31 07:38:55 -05:00
Jonas Jenwald
0edb520a10 Add unit-tests for Linearization dictionary parsing (PR 5023 follow-up)
This should *really* have been part of 5023, but better late than never I suppose.
2015-08-30 14:06:11 +02:00
Jonas Jenwald
0dde08554d Add a unit-test for skipping paintXObject if Subtype === PS (PR 4861) 2015-08-29 20:43:22 +02:00
Tim van der Meij
d08895d659 Merge pull request #6236 from Rob--W/print-javascript-action
Detect scripted auto-print requests
2015-07-25 19:42:31 +02:00
Tim van der Meij
980aa10e04 Refactor annotation rectangle code and add unit tests
This patch refactors the code responsible for setting the annotation's rectangle. Its goal is to:

- Actually check that the input array is actually an array, and if so, that it contains exactly four elements.
- Only call `normalizeRect` if the input array is valid, i.e., we do not call it for the default rectangle anymore.

Unit tests are provided just like with the other patches in this series.
2015-07-20 22:01:47 +02:00
Rob Wu
c676ecb5a0 Detect scripted auto-print requests
Fixes #6106

To avoid future regressions, two new unit tests were added:
1. A new PDF based on the report from #6106, which contains an
   OpenAction of type JavaScript and a string "this.print({...}".
2. An existing PDF from https://bugzil.la/1001080 (from #4698).

Although it does not matter, since we don't execute the JavaScript code,
I have also changed "print(true)" to "print({})" since the print method
takes an object (not a boolean). See "Printing PDF documents", page 62:
http://adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_developer_guide.pdf
2015-07-20 18:25:02 +02:00
Tim van der Meij
465611a2ff More cleanup regarding annotation border styles 2015-07-17 21:51:24 +02:00
Jonas Jenwald
c718d1ab10 Ignore double negative in Lexer_getNumber (issue 6218)
Basic mathematics would suggest that a double negative should always become positive, but it appears that Adobe Reader simply ignores that case. Hence I think that it makes sense for us to do the same.

Fixes 6218.
2015-07-16 12:11:49 +02:00
Tim van der Meij
a2e9845093 Refactor annotation color handling and add unit tests 2015-07-15 18:49:19 +02:00
Jonas Jenwald
940bedf75f Add a unit-test that attempts to fetch a non-existent named destination
Doing this helped uncover an issue with the `getDestination` implementation.
Currently if a named destination doesn't exist, the method (in `obj.js`) may return `undefined` which leads to the promise being stuck in a pending state.
*Note:* returning `null` for this case is consistent with other methods, e.g. `getOutline` and `getAttachments`.
2015-07-07 22:05:08 +02:00
Brendan Dahl
98339f63a8 Merge pull request #5585 from timvandermeij/annotation-layer-borderstyle
Annotation border styles
2015-07-01 10:48:12 -07:00
Jonas Jenwald
38955d491f Further improvements of the getStats and getDownloadInfo unit tests
The patch adds a test to ensure that `getStats` returns the expected result after the page has been parsed, and cleans up the existing test a bit.
Also, since I'm touching the file anyway, I'm making a small adjustment of the `getDownloadInfo` test. (I have no idea why I didn't just write it like this initially.)
2015-06-25 23:00:26 +02:00
Jonas Jenwald
46a8485db4 Ignore paint form XObject when the name is missing (issue 4558)
Fixes 4558 (since the font issues already appear to be fixed).
2015-06-22 22:10:26 +02:00
Tim van der Meij
6007a57291 Add tests and documentation for the annotation border style class
This patch adds:
- Unit tests for the annotation border style class
- Regression test (self-made) for the annotation border style class
- Documentation generation using JSDoc
2015-06-17 22:28:08 +02:00
Jonas Jenwald
f59e20226c Slightly improved Crypto unit tests
Currently in the tests which check that incorrect passwords are rejected, we don't ensure that the exceptions thrown are the ones we expect. This patch improves the current situation, so that we actually can be sure that the code "fails" in the correct way.

*Note:* This patch also fixes some cases of weird indentation in the file.
2015-06-10 00:21:40 +02:00
Mike Corbin
4c9b65f0e1 Extract correct PDF format version from the catalog
The 'Version' field of the most recent document catalog, if present, is
intended to supersede the value in the file prologue.

This is significant for incrementally-built PDF documents and generators that
emit a low version in the prologue and later apply a format version based on
PDF features used, such as Apple's CoreGraphics/Quartz PDF backend.

Fixes the internal version variable, as well as the PDFFormatVersion reported
by the API and consumed by viewers.
2015-05-26 01:56:09 +01:00
Brendan Dahl
4824baf31c Merge pull request #5905 from timvandermeij/specialpowers
Remove SpecialPowers addon
2015-04-27 10:36:54 -07:00
Jonas Jenwald
7c7d05e7a3 Attempt to infer if a CMap file actually contains just a standard Identity-H/Identity-V map 2015-04-25 11:28:33 +02:00
Jonas Jenwald
36ac67583f Remove commented out code about |disableWorker| in the test suite
Since the tests have run with workers enabled for a long time, these comments are no longer relevant.
2015-04-04 13:32:44 +02:00
Tim van der Meij
75d8f70d06 Remove SpecialPowers addon 2015-04-03 20:17:20 +02:00
fkaelberer
a78bb6b946 Use binary search in getVisibleElements() 2015-03-01 17:41:20 +01:00
Collin Anderson
54e984c763 cleaned whitespace 2015-02-17 11:07:37 -05:00
Tim van der Meij
b215af30d3 Require destinations when they are needed and do not fetch all of them in advance 2014-10-06 22:26:18 +02:00
Jonas Jenwald
dc5b0d251f Improve the getData unit test
As a follow-up to PR #4795, this patch improves the `getData` unit test to ensure that the returned data is of the expected type and of the correct length.
2014-09-23 13:16:58 +02:00