Commit Graph

1613 Commits

Author SHA1 Message Date
Jonas Jenwald
e589834f13 Ensure that TilingPatterns have valid (non-zero) /BBox arrays (issue 8330)
Fixes 8330.
2017-06-09 21:41:48 +02:00
Jonas Jenwald
8b4a42e5b8 Only special-case OpenType fonts with CFF data if it's both a composite (i.e. Type0) font and also has a non-default CID to GID map (issue 8480)
*As mentioned the last time that I touched this particular part of the font code, I'm sincerely hope that this doesn't cause any regressions!*

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

Fixes 8480.
2017-06-09 21:15:39 +02:00
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
4ce5e520fb Add different code-paths to {CMap, ToUnicodeMap}.charCodeOf depending on length, since Array.prototype.indexOf can be extremely inefficient for very large arrays (issue 8372)
Fixes 8372.
2017-05-24 19:47:04 +02:00
Jonas Jenwald
ac942ac657 Merge pull request #8437 from yurydelendik/default-ctx
Resets canvas 2d context to the default state.
2017-05-23 23:31:57 +02:00
Yury Delendik
a67198895f Resets canvas 2d context to the default state. 2017-05-23 15:10:30 -05:00
Jonas Jenwald
31c24ed631 Don't map glyphs to the HANGUL FILLER (0x3164) Unicode location (issue 8424)
*This patch follows a similar pattern as previous ones, by skipping certain problematic Unicode locations.*

According to http://searchfox.org/mozilla-central/rev/6c2dbacbba1d58b8679cee700fd0a54189e0cf1b/gfx/harfbuzz/src/hb-unicode-private.hh#136, it seems that the HANGUL FILLER (0x3164) location is "special".

Fixes 8424.
2017-05-23 16:12:45 +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
Yury Delendik
7b365b9372 Merge pull request #8366 from yurydelendik/rm-shelljs
Removes shelljs
2017-05-19 15:08:04 -05: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
Yury Delendik
65a1e836cf Removes shelljs 2017-05-19 07:53:05 -05:00
Yury Delendik
5dc8dcdc0f Merge pull request #8388 from Snuffleupagus/issue-8380
Cache JPEG images, just as we do for other image formats, in `evaluator.js` (issue 8380)
2017-05-17 17:25:51 -05:00
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
Yury Delendik
15425d5b9b Merge pull request #8400 from Snuffleupagus/ref-tests-wait-on-destroy
Wait for previous pdfDocument(s) to be destroyed before running the next reference test
2017-05-11 11:59:20 -05:00
Jonas Jenwald
b5775af716 Wait for previous pdfDocument(s) to be destroyed before running the next reference test
Refactors `Driver._cleanup` to return a `Promise` which is resolved once all opened documents have been destroyed.
This is then used in `Driver._nextTask` to ensure that we wait for everything to be cleaned up, such that the tests run sequentially.
2017-05-11 12:56:45 +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
Jonas Jenwald
0c2ebda31c Cache JPEG images, just as we do for other image formats, in evaluator.js (issue 8380)
For some reason, we're putting all kind of images *except* JPEG into the `imageCache` in `evaluator.js`.[1]
This means that in the PDF file in issue 8380, we'll keep sending the *same* two small images[2] to the main-thread and decoding them over and over. This is obviously hugely inefficient!

As can be seen from the discussion in the issue, the performance becomes *extremely* bad if the user has the addon "Adblock Plus" installed. However, even in a clean Firefox profile, the performance isn't that great.

This patch not only addresses the performance implications of the "Adblock Plus" addon together with that particular PDF file, but it *also* improves the rendering times considerably for *all* users.
Locally, with a clean profile, the rendering times are reduced from `~2000 ms` to `~500 ms` for my setup!

Obviously, the general structure of the PDF file and its operator sequence is still hugely inefficient, however I'd say that the performance with this patch is good enough to consider the issue (as it stands) resolved.[3]

Fixes 8380.

---
[1] Not technically true, since inline images are cached from `parser.js`, but whatever :-)

[2] The two JPEG images have dimensions 1x2, respectively 4x2.

[3] To make this even more efficient, a new state would have to be added to the `QueueOptimizer`. Given that PDF files this stupid fortunately aren't too common, I'm not convinced that it's worth doing.
2017-05-07 13:07:41 +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
Brendan Dahl
b06022895e Add no-default-browser-check to chrome runner. 2017-05-03 11:22:08 -07: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
165294a05f Merge pull request #8335 from Snuffleupagus/jbig2-decodeRefinement-subtract-offsets
Subtract the X/Y offsets when decoding refinement regions of JBIG2 images (issue 7145, 7308, 7401, 7850, 8270)
2017-04-28 23:13:07 +02:00
Tim van der Meij
ee86a81a50
Bots: disable the default browser test and enable E10s
The test runner is automated, so if the default browser test is
performed, the browser hangs waiting for user input it never gets.
Disable the test to fix that.

Moreover, enable E10s now that it is mature. This may help with the
performance of the test runner as well.
2017-04-27 20:39:57 +02:00
Jani Pehkonen
64deb6c700 Subtract the X/Y offsets when decoding refinement regions of JBIG2 images (issue 7145, 7308, 7401, 7850, 8270)
Please refer to the JBIG2 standard, see https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-T.88-200002-I!!PDF-E&type=items.
In particular, section "6.3.5.3 Fixed templates and adaptive templates" mentions that the offsets should be *subtracted*; where the offsets are defined according to "Table 6" under section "6.3.2 Input parameters".

Fixes 7145.
Fixes 7308.
Fixes 7401.
Fixes 7850.
Fixes 8270.
2017-04-26 16:06:15 +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
Yury Delendik
c4c44c1bbe Merge pull request #8240 from Snuffleupagus/api-stopAtErrors
[api-minor] Always allow e.g. rendering to continue even if there are errors, and add a `stopAtErrors` parameter to `getDocument` to opt-out of this behaviour (issue 6342, issue 3795, bug 1130815)
2017-04-13 10:58:49 -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
Jonas Jenwald
a39d636eb8 [api-minor] Always allow e.g. rendering to continue even if there are errors, and add a stopAtErrors parameter to getDocument to opt-out of this behaviour (issue 6342, issue 3795, bug 1130815)
Other PDF readers, e.g. Adobe Reader and PDFium (in Chrome), will attempt to render as much of a page as possible even if there are errors present.
Currently we just bail as soon the first error is hit, which means that we'll usually not render anything in these cases and just display a blank page instead.

NOTE: This patch changes the default behaviour of the PDF.js API to always attempt to recover as much data as possible, even when encountering errors during e.g. `getOperatorList`/`getTextContent`, which thus improve our handling of corrupt PDF files and allow the default viewer to handle errors slightly more gracefully.
In the event that an API consumer wishes to use the old behaviour, where we stop parsing as soon as an error is encountered, the `stopAtErrors` parameter can be set at `getDocument`.

Fixes, inasmuch it's possible since the PDF files are corrupt, e.g. issue 6342, issue 3795, and [bug 1130815](https://bugzilla.mozilla.org/show_bug.cgi?id=1130815) (and probably others too).
2017-04-11 08:59:22 +02:00
Jonas Jenwald
10e5f766a2 Merge pull request #8266 from brendandahl/issue6652
Normalize blend mode names.
2017-04-11 08:54:42 +02:00
Brendan Dahl
4969b2ad97 Normalize blend mode names. 2017-04-10 16:18:08 -07:00
Jonas Jenwald
9d62ff80ca Actually skip pages included in the skipPages array when running tests, rather than creating empty 1x1 canvases (issue 8241)
Considering how extremely simple this patch turned out to be, I'm almost worried that I completely misunderstood why the current code looks like it does...
2017-04-06 13:17:52 +02:00
Brendan Dahl
cdc79a4721 Don’t skip glyph 0 in cmap. 2017-04-05 15:17:38 -07: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
62eee8c782 Try harder to find the next valid JPEG marker when decoding Scan data (issue 8182, issue 8189)
Tentatively fixes 8182 and fixes 8189.
2017-03-27 15:55:21 +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
3705e5e459 Use a proper MessageHandler for PartialEvaluator.getTextContent to avoid errors for fonts relying on built-in CMap files (PR 8064 follow-up)
*My apologies for inadvertently breaking this in PR 8064; apparently we don't have any tests that cover this use-case :(*

Without this patch `getTextContent` will fail if called before `getOperatorList`, since loading of fonts during text-extraction may require fetching of built-in CMap files.

*Please note:* The `text` test added here, which uses an already existing PDF file, fails without this patch.
2017-03-24 17:39:33 +01:00
Jonas Jenwald
e2e13df4a5 Merge pull request #8164 from Snuffleupagus/issue-7828
Don't read past the EOI marker for JPEG images with non-default restart interval (issue 7828)
2017-03-20 22:17:28 +01:00
Jonas Jenwald
d6d0f778aa Don't read past the EOI marker for JPEG images with non-default restart interval (issue 7828)
*After browsing through (a version of) the JPEG specification, see https://www.w3.org/Graphics/JPEG/itu-t81.pdf, I hope that this patch makes sense.*

Note that while issue 7828 became a problem after PR 7661, it isn't really a regression from than PR. The explanation is rather that we're now relying on `core/jpg.js` instead of the Native Image decoder in more situations than before, which thus exposed an *existing* issue in our JPEG decoder.
Another factor also seems to be that in many JPEG images, the DRI (Define Restart Interval) marker isn't present, in which case this bug won't manifest either.

According to https://www.w3.org/Graphics/JPEG/itu-t81.pdf#page=89 (at the bottom of the page):
"NOTE – The final restart interval may be smaller than the size specified by the DRI marker segment, as it includes only the number of MCUs remaining in the scan."
Furthermore, according to https://www.w3.org/Graphics/JPEG/itu-t81.pdf#page=39 (in the middle of the page):
"[...] If restart is enabled and the restart interval is defined to be Ri, each entropy-coded segment except the last one shall contain Ri MCUs. The last one shall contain whatever number of MCUs completes the scan."

Based on the above, it thus seem to me that we should simply ensure that we're not attempting to continue to parse Scan data once we've found all MCUs (Minimum Coded Unit) of the image.

Fixes 7828.
2017-03-20 17:16:33 +01:00
Jonas Jenwald
be1a6f294f Try to recover when encountering JPEG markers with too short marker lengths (issue 8169)
The issue with the JPEG image in question, is that the COM (Comment) marker has an incorrect length entry.

Fixes 8169.
2017-03-20 17:05:51 +01:00
Jonas Jenwald
098a56270d Normalize the BBox entry in Tiling Pattern dictionaries (issue 8117)
According to the PDF specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G7.3982967, the `BBox` entry should have the form `[left, bottom, right, top]`.
Since some PDF generators apparently violates the specification, we normalize the `BBox` to ensure that the pattern is (correctly) rendered.

Fixes 8117.
2017-03-16 21:43:11 +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
Jonas Jenwald
224613a511 Merge pull request #8135 from jasonjensen/issue8097
Handle cff fonts with erroneous stackSize (issue 8097)
2017-03-11 09:55:00 +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
Jason O. Jensen
d230784ac3 Handle cff fonts with erroneous stackSize 2017-03-06 19:28:46 -05: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
4a0ff5dbf7 Ensure that we don't ignore 0 values in Page.getInheritedPageProp (issue 8125)
It appears that I accidentally broke this in PR 6065, sorry about that!

The issue in this particular PDF file is that there's `/Rotate` entries on different levels of the `/Pages` tree. We're supposed to use the `/Rotate` entry in the `/Page` dict (which is `0`), but because of an incorrect condition we instead ended up with the one from the `/Pages` dict (which is `180`).

Fixes 8125.
2017-03-03 12:27:40 +01: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
1ce295541c Always check all Kids nodes, in Catalog.getPageDict, to avoid getting stuck in an empty node further down in the Pages tree (issue 8088)
As discussed on IRC, we need to check all nodes at the *bottom* of the tree to ensure that we find the correct `Page` dict.
Furthermore, this patch also gets rid of the caching present in a previous version, since it's not clear if that really helps.

Note that this patch purposely adds an `eq` test, using a reduced test-case, so that we can be sure that the algorithm actually finds the correct `Page` dict for each `pageIndex`.

Fixes 8088.
2017-02-24 12:09:46 +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
Yury Delendik
cfaa621a05 Merge pull request #8064 from Snuffleupagus/fetchBuiltInCMap
[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)
2017-02-17 15:30:31 -06: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
Jonas Jenwald
ce072022c1 Always choose a (3, 1) cmap table for TrueType fonts that have an encoding specified, regardless of the Symbolic font flag (bug 1337429)
This patch basically reverts one aspect of TrueType (3, 1) cmap parsing to the state prior to PR 4259. After that PR, a number of regressions occurred in this particular code-path, which necessitated a number of follow-ups such as PRs 5703, 5743, and 6425.
The empirical data suggests, at least to me, that we should always prefer a (3, 1) cmap for TrueType fonts when they have an encoding, regardless of the Symbolic font flag.

Obviously this patch passes all unit/font/reference tests locally, and I made sure that all the PRs mentioned above landed with test-cases included.
However, in my opinion, there's still a very real possibility that this patch could potentially cause new regressions.

Given that the PDF file in bug 1337429 has been broken for almost *three* years before anyone noticed, and considering that the code-path in question has been the source of numerous regressions, I do *not* intend to request uplift of this patch to previous Firefox versions (assuming that it's even accepted).

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1337429.
2017-02-15 17:38:08 +01:00
Jonas Jenwald
23c62cc321 Consume the current character when encountering illegal characters in Lexer.getObject, in order to prevent infinite loops during reading of streams (issue 8061)
*Please note:* The rendering of the PDF file in issue 8061 first regressed in PR 7039, and then PR 7493 exacerbated the problem even further by causing an infinite loop.

In this particular case, when errors were encountered inside of the `Lexer.getObject` method *itself*, we didn't advance the stream position. This thus caused an inifinite loop in `parseCMap`, since the exact same character was then parsed over and over again.

Fixes 8061.
2017-02-11 19:32:48 +01:00
pmysore1
af8292058f Font ascent descent calculation fix 2017-02-11 01:25:05 -05: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
Tim van der Meij
6f0cf8c4cb Merge pull request #7972 from Snuffleupagus/eslint_no-unused-vars
Enable the `no-unused-vars` ESLint rule
2017-02-01 23:50:23 +01:00
Jonas Jenwald
c102232275 Append the contents of FileAttachment annotations to the attachments view of the sidebar, for easier access to the embedded files
Other PDF viewers, e.g. Adobe Reader, seem to append `FileAttachment`s to their attachments views.
One obvious difference in PDF.js is that we cannot append all the annotations on document load, since that would require parsing *every* page. Despite that, it still seems like a good idea to add `FileAttachment`s, since it's thus possible to access all the various types of attachments from a single place.

*Note:* With the previous patch we display a notification when a `FileAttachment` is added to the sidebar, which thus makes appending the contents of these annotations to the sidebar slightly more visible/useful.
2017-01-31 22:26:16 +01:00
Tim van der Meij
95732279b6 Remove usage of mozFillRule
The non-standard `mozFillRule` has been removed in Firefox 51 [1, 2].
Instead, a parameter of the standard methods should be used. Note that
this is supported in all major browsers for a long time now, so there
should be no need keeping this Firefox-specific code around.

[1] https://developer.mozilla.org/en-US/Firefox/Releases/51
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=826619
2017-01-29 23:24:44 +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
Tim van der Meij
1fda987a4c Merge pull request #7904 from Snuffleupagus/issue-7901
Further adjust the heuristics used to detect OpenType font files with CFF data, to ensure that all Type0 fonts are handled the same way regardless of font Subtype (issue 7901)
2017-01-12 21:55:57 +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
Yury Delendik
393740e2ae Merge pull request #7869 from PedroPachecoInf/master
Fixes issue #6071 - TIFF with 1 bit-depth
2017-01-10 12:37:26 -06:00
jazzchipc
493853031b Fixes issue #6071.
Corrects readBlockTiff() case for 1-bit depth and 1 color TIFF images incorporated in the PDF.

Adds reference test for PDF used to fix this issue.
2017-01-10 16:42:43 +00: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
Jonas Jenwald
e963971244 Further adjust the heuristics used to detect OpenType font files with CFF data, to ensure that all Type0 fonts are handled the same way regardless of font Subtype (issue 7901)
Changing this particular code makes me somewhat nervous about regressions, since PR 5770 necessitated the follow-up PR 6270.
However, the patch passes all tests added in those PRs (and obviously all other tests). Furthermore, I've manually checked all the issues/bugs referenced in PRs 5770 and 6270 without finding any issues.

**Please note:** This patch fixes *only* the font bug, not the SVG conversion, present on pages two and three of the PDF file in issue 7901.
2016-12-20 17:03:51 +01:00
Yury Delendik
3b3a179486 Merge pull request #7879 from rossj/highlight-fix
Make use of textAdvanceScale consistent during combineTextItems. Fix for #7878.
2016-12-19 09:18:13 -06: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
Tim van der Meij
0c9a06c020 Button widget annotations: implement reference testing
Moreover, ensure that the read-only state is respected and improve CSS
names.
2016-12-17 20:33:35 +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
Ross Johnson
4537590033 Consitently apply textAdvanceScale during building of textContentItems for improved highlighting. Fixes #7878. 2016-12-14 21:02:19 -06: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
c36468cbce Fix errors reported by the keyword-spacing ESLint rule
http://eslint.org/docs/rules/keyword-spacing
2016-12-12 20:35:56 +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
3820946301 Fix (most) errors reported by the no-multi-spaces ESLint rule
http://eslint.org/docs/rules/no-multi-spaces
2016-12-12 20:35:51 +01:00
Jonas Jenwald
9be3aee9c9 Add a parameter to Page_getInheritedPageProp to make it possible to fetch (and dereference) Arrays, and use that for the MediaBox/CropBox getters (issue 7872) 2016-12-08 22:03:42 +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
Tim van der Meij
46d2c892de Merge pull request #7857 from jabiinfante/murmurhash3-unit-tests
add basic unit-tests for murmurhash3.js
2016-12-01 16:34:04 +01:00
Javier Infante
54fab606ee add basic unit-tests for murmurhash3.js 2016-12-01 02:21:05 +01:00
Jonas Jenwald
c5b06cb40d Ensure that PartialEvaluator_extractWidths is able to handle indirect objects in all kinds of "width" data (issue 7855)
Fixes 7855.
2016-11-29 20:49:07 +01:00
Jonas Jenwald
451956c0b1 Merge pull request #7628 from Snuffleupagus/issue-7580
Fallback to the `StandardEncoding` for Nonsymbolic fonts without `/Encoding` entry (issue 7580)
2016-11-29 12:37:36 +01:00
Jonas Jenwald
013f69e65f Merge pull request #7700 from Snuffleupagus/non-embedded-NuptialScript
Improve rendering of non-embedded NuptialScript font
2016-11-29 11:00:21 +01:00
Tim van der Meij
9ff19985c0 Merge pull request #7832 from seanburke-wf/expose-userunit-on-page
Expose the optional UserUnit entry as a page property
2016-11-22 21:18:57 +01:00
Jonas Jenwald
3170a4c40a Improve rendering of non-embedded NuptialScript font
*This patch fixes something that I noticed while debugging https://bugzilla.mozilla.org/show_bug.cgi?id=1308536.*

The PDF file contains a font called "NuptialScript", which unfortunately is not embedded. Since that is a non-standard font we will not be able to render it entirely correct. However, by adding "NuptialScript" to the `getNonStdFontMap`, we can at least improve the rendering slightly by using an italic (serif) fallback font.
2016-11-22 17:56:17 +01:00
Sean Burke
f76cd2ce43 Expose the optional UserUnit entry as a page property 2016-11-22 09:18:19 -07:00
Jonas Jenwald
d3043167de Correctly detect more cases of non-embedded Arial Black fonts (issue 7835)
This patch adds support for non-embedded Arial Black fonts, that use a `Arial-Black...` format for the font names.
Also, this patch changes `canvas.js` such that we always render Arial Black fonts with the maximum weight, which actually improves a number of existing test-cases. This should thus explain the test "failures", which are clear improvements compared with e.g. Adobe Reader.

Fixes 7835.
2016-11-22 13:56:21 +01: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
Yury Delendik
ea5949f1fd Merge pull request #7668 from Snuffleupagus/issue-7665
Prevent an infinite loop in `XRef_fetchUncompressed` for encrypted PDF files with indirect objects in the /Encrypt dictionary (issue 7665)
2016-10-15 10:52:08 -05:00
Chas Emerick
85c52f1fd6 Fix getTextContent evaluation to only apply TJ horizontal offsets using numeric items/args
While the array argument to TJ should only contain strings and numbers, other
unfortunate items are found in PDFs in the wild, e.g.:

[(Grandes) 0.0 Tc
-250.0 (Client\350les,) 0.0 Tc
-250.0 (Financements) 0.0 Tc
-250.0 (et) 0.0 Tc
-250.0 (March\351s) ] TJ

getOperatorList already properly ignores any non-string, non-numeric values in
TJ arrays; without this patch to getTextContent, returned text items can have
NaN widths due to calculations being applied to those non-numeric values.
2016-10-13 08:08:31 -04: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
Yury Delendik
7b2a9ee4e0 Merge pull request #7670 from Snuffleupagus/Parser_makeFilter-maybeLength
Only skip parsing a stream in `Parser_makeFilter` when we know for sure that it is empty (PR 6372 follow-up)
2016-10-05 10:38:12 -05: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
Jonas Jenwald
54ee83eb12 Attempt to skip zero bytes at the end of Scan blocks when decoding JPEG images (issue 4090) 2016-09-28 16:31:02 +02:00
Jonas Jenwald
116ba19dd9 Respect the 'ColorTransform' entry in the image dictionary when decoding JPEG images (bug 956965, issue 6574)
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=956965.
Fixes 6574.
2016-09-26 21:55:43 +02:00
Jonas Jenwald
a22f0ae820 Only skip parsing a stream in Parser_makeFilter when we know for sure that it is empty (PR 6372 follow-up)
For PDF files with multiple `/Filter`s, where the `/Length` entry is zero, we fail to render the file correctly. The reason is that `maybeLength` is `null` for the every filter except the first, and `!maybeLength` is thus truthy.
Hence it seems that we should completely ignore the `/Length` entry and also explicitly check `maybeLength === 0`.

Note that I've not (yet) come across a PDF file with this issue in the wild, but given all the stupid things PDF generators do I wouldn't be surprised if such a file actually exists. In order to prevent a possible future bug, I'm submitting this patch which includes a hand-edited PDF file that we currently cannot render correctly (but e.g. Adobe Reader can).
2016-09-25 12:40:15 +02:00
Jonas Jenwald
4d2de9b47e Add a reduced load test for issue 7665 2016-09-25 00:19:42 +02:00
Jonas Jenwald
6c263c1994 Merge pull request #7649 from timvandermeij/interactive-forms-tx-comb
Text widget annotations: implement comb support
2016-09-22 11:36:30 +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
Jonas Jenwald
3a105e37f4 Ensure that test/driver.js actually takes the same Annotation code-path as the viewer when running forms tests (PR 7633 follow-up)
Unfortunately PR 7633 missed, and I didn't catch it during review, to update `test/driver.js` such that the `forms` tests takes the correct code-path.
This resultet in the `forms` reference test images looking better than they should, and more problematicly differing from the rendering in the viewer.

With this patch, the tests now correctly skip over any `Appearance` streams.
The `forms` tests now highlights quite clearly (e.g. look at `annotation-tx2.pdf`/`annotation-tx3.pdf`) that we cannot just skip the `Appearance` streams when rendering forms. Hence we're going to have to find a way to fix that *before* enabling forms by default, since both display *and* print would look completely wrong otherwise.
Finally, this patch also uncovers one more existing bug that still needs to be fixed, since the current `rasterizeAnnotationLayer` in `test/driver.js` isn't able to handle the contents of e.g. `<input>` and `<textarea>`.
2016-09-21 12:21:20 +02:00
Tim van der Meij
6100ab4b18 Text widget annotations: implement comb support 2016-09-20 22:31:10 +02:00
Brendan Dahl
15e1ae4e3f Merge pull request #7639 from Snuffleupagus/bug-1252420
Replace empty CharStrings with '.notdef' in `Type1Font_wrap` to prevent OTS from rejecting the font (bug 1252420)
2016-09-20 11:56:47 -07:00
Jonas Jenwald
170871ab3d Prevent rendering TextWidgetAnnotations in both the core/display layer (issue 7643) 2016-09-18 15:42:22 +02:00
Tim van der Meij
f062695d62 Merge pull request #7633 from timvandermeij/interactive-forms-tx-flags
Text widget annotations: support read-only/multiline fields and improve testing
2016-09-17 17:19:47 +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