Commit Graph

1564 Commits

Author SHA1 Message Date
Jonas Jenwald
5565a6f8bf Slightly refactor the pages rotation handling code in the viewer
This changes both `PDFViewer` and `PDFThumbnailViewer` to return early in the `pagesRotation` setters if the rotation doesn't change.
It also fixes an existing issue, in `PDFViewer`, that would cause errors if the rotation changes *before* the scale has been set to a non-default value.

Finally, in preparation for subsequent patches, it also refactors the rotation code in `web/app.js` to update the thumbnails and trigger rendering with the new `rotationchanging` event.
2017-09-09 11:27:05 +02:00
Tim van der Meij
2a77f8b041
Provide checked styles for button widget annotations
Fixes #8875.
2017-09-07 00:25:45 +02:00
Tim van der Meij
1c9af00bee Merge pull request #8775 from Snuffleupagus/rewrite-PDFHistory-2
Re-write `PDFHistory` from scratch
2017-09-03 20:38:59 +02:00
Jonas Jenwald
cfb4955a92 Replace the isArray helper function with the native Array.isArray function
*Follow-up to PR 8813.*
2017-09-01 20:27:13 +02:00
Jonas Jenwald
11408da340 Replace the isInt helper function with the native Number.isInteger function
*Follow-up to PR 8643.*
2017-09-01 16:52:50 +02:00
Rob Wu
73273ccbe9 Add test for withCredentials option 2017-08-31 14:30:00 +02:00
Tim van der Meij
a4cc85fc5f Merge pull request #8828 from timvandermeij/es6-annotations
Improve the annotation code by converting to ES6 syntax and removing duplicate code
2017-08-31 00:02:07 +02:00
Jonas Jenwald
388851e37b Add a isDestsEqual helper function, to allow comparing explicit destinations, in pdf_history.js 2017-08-30 19:45:13 +02:00
Jonas Jenwald
0c4985546a Add a waitOnEventOrTimeout helper function that allows waiting for an event or a timeout, whichever occurs first 2017-08-30 19:45:13 +02:00
Yury Delendik
cd95b426c7 Disables fetch when ReadableStream is not available. 2017-08-30 10:53:59 -05:00
Mukul Mishra
3516a59384 Adds fetch stream logic for networking part of PDF.js 2017-08-29 22:56:48 +05:30
Jonas Jenwald
49b8cd5a6a Attempt to improve the EI detection heuristics, for inline images, in streams containing NUL bytes (issue 8823)
Since this patch will now treat (some) `NUL` bytes as "ASCII", the number of `followingBytes` checked are thus increased to (hopefully) reduce the risk of introducing new false positives.

Fixes 8823.
2017-08-27 12:48:28 +02:00
Tim van der Meij
4f02857394
Let the two annotation factories use static methods
This corresponds to how other factories are implemented.
2017-08-27 01:02:40 +02:00
Jonas Jenwald
42f2d36d1f Account for broken outlines/annotations, where the destination dictionary contains an invalid /Dest entry
According to the specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#page=377, a `Dest` entry in an outline item should *not* contain a dictionary.
Unsurprisingly there's PDF generators that completely ignore this, treating is an `A` entry instead.

The patch also adds a little bit more validation code in `Catalog.parseDestDictionary`.
2017-08-26 17:38:15 +02:00
Tim van der Meij
798e46da97 Merge pull request #8821 from Snuffleupagus/issue-8798-reduced-test
Replace the test-case for issue 8798 with a reduced one (PR 8800 follow-up)
2017-08-26 00:00:45 +02:00
Jonas Jenwald
88167b5e38 Merge pull request #8824 from Snuffleupagus/bug-1393476
Prevent an infinite loop in `XRef.readXRef` by keeping track of already parsed tables (bug 1393476)
2017-08-24 22:13:48 +02:00
Jonas Jenwald
4660cf8238 Prevent an infinite loop in XRef.readXRef by keeping track of already parsed tables (bug 1393476)
With this patch, not only is the infinite loop prevented, but we're also able to actually render the file (which e.g. Adobe Reader isn't able to).

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1393476.
2017-08-24 19:18:08 +02:00
Yury Delendik
e82811adb4 Merge pull request #8712 from mukulmishra18/node_stream
Adds node.js logic for networking tasks for PDF.js
2017-08-24 11:35:29 -05:00
Jonas Jenwald
4891b9c7e0 Replace the test-case for issue 8798 with a reduced one (PR 8800 follow-up)
*Re: issue 8798 and PR 8800.*

Big thanks to @THausherr for providing the test-case.
2017-08-24 17:43:05 +02:00
Mukul Mishra
d16709f5e4 Adds tests for node_stream 2017-08-24 12:46:44 +05:30
Tim van der Meij
e9ba54940d Merge pull request #8800 from Snuffleupagus/issue-8798
Try to recover if we reach the end of the stream when searching for the `EI` marker of an inline image (issue 8798)
2017-08-23 23:47:51 +02:00
Jonas Jenwald
ca936ee0c7 Merge pull request #8491 from janpe2/jbig2Halftone-2
JBIG2 halftone regions and pattern dictionaries
2017-08-23 00:13:43 +02:00
Jonas Jenwald
cb55506b95 Try to recover if we reach the end of the stream when searching for the EI marker of an inline image (issue 8798) 2017-08-22 09:33:13 +02:00
Rob Wu
d253889d97 __non_webpack_require__ -> require in SystemJS
When running browser tests, e.g. via `gulp unittest`, the test files are not
processed by babel, and neither by the "unittestcli" gulp target.

This commit copies the babelPluginReplaceNonWebPackRequire plugin from the
unittestcli target to the SystemJS config so that `__non_webpack_require__` is
replaced with `require` for all build targets, and adds a unit test to ensure
that this indeed works as expected.
2017-08-15 12:14:30 +02:00
Jani Pehkonen
9a581ee9ed Implement JBIG2 halftone regions and pattern dictionaries 2017-08-08 15:38:29 +03:00
Brendan Dahl
0bef50d56d Fix two cmap related issues.
In issue #8707, there's a char code mapped to a non-
existing glyph which shouldn't be drawn. However, we
saw it was missing and tried to then use the post table and
end up mapping it incorrectly.

This illuminated a problem with issue #5704 and bug
893730 where glyphs disappeared after above fix.  This was
from the cmap returning the wrong glyph id. Which in turn was
caused because the font had multiple of the same type of cmap
table and we were choosing the last one. Now, we instead
default to the first one. I'm unsure if we should instead be
merging the multiple cmaps, but using only the first one works.
2017-08-03 22:19:36 -07:00
Brendan Dahl
5b7f712ca7 Merge pull request #8627 from yurydelendik/issue-8591
Fallback on font widths if CFF data is broken
2017-08-02 10:53:14 -07:00
Tim van der Meij
ab820438ae
Move the XRefMock in the unit tests to a central location
This patch helps to avoid code duplication for this mock since more unit
tests are depending on it.
2017-07-29 15:16:19 +02:00
Apoorv Mishra
a129de7bd1 Add unit-tests for colorspace.js
Added unit-tests for DeviceGray, DeviceRGB and DeviceCMYK

Added unit-tests for CalGray

Added unit-tests for CalRGB

Removed redundant code

Added unit-tests for LabCS

Added unit-tests for IndexedCS

Update comment

Change lookup to Uint8Array as mentioned in pdf specs(these tests will pass after PR #8666 is merged).

Added unit-tests for AlternateCS

Resolved code-style issues

Fixed code-style issues

Addressed issues pointed out in https://github.com/mozilla/pdf.js/pull/8611#pullrequestreview-52865469
2017-07-28 14:24:56 +05:30
Yury Delendik
343b4dc2b6 Merge pull request #8617 from mukulmishra18/network-streaming
Adds Streams API support for networking task of PDF.js project.
2017-07-27 16:15:06 -05:00
Mukul Mishra
109106794d Adds Streams API support for networking task of PDF.js project.
network.js file moved to main thread and `PDFNetworkStream` implemented
at worker thread, that is used to ask for data whenever worker needs.
2017-07-28 02:32:30 +05:30
Yury Delendik
c830021b07 Fixes CFF data glyph widths 2017-07-25 12:29:51 -05:00
Jonas Jenwald
23ec6b16ca Add a fallback for non-embedded SegoeUISymbol font (issue 8697)
The PDF file uses a non-embedded SegoeUISymbol font, which is *not* a standard font (and is mainly used by Microsoft, see https://en.wikipedia.org/wiki/Segoe).

Fixes 8697.
2017-07-25 12:45:11 +02:00
Yury Delendik
bd8c12119a Merge pull request #8696 from mukulmishra18/sink-ready-rejection
Adds ready capability rejection logic for stream sink.
2017-07-24 16:40:30 -05:00
Mukul Mishra
568b0b6a42 Adds ready capability rejection logic for stream sink. 2017-07-25 02:07:38 +05:30
Jonas Jenwald
794b099385 Add a reduced test-case for issue 7696
Issue 7696 was one of the issues fixed by PR 8580. The other ones were all cases of missing glyphs, however in this particular one glyphs did render but every single one was incorrect.
Hence it probably cannot hurt to have a small, reduced, reference test for that PDF file as well.
2017-07-24 09:55:16 +02:00
Tim van der Meij
af71ea7a7d Merge pull request #8673 from Snuffleupagus/api-pageMode
[api-minor] Add support for PageMode in the API and viewer (issue 8657)
2017-07-23 13:17:07 +02:00
Tim van der Meij
7ded895d0c Merge pull request #8638 from Snuffleupagus/issue-4926-built-in-jpg
In `src/core/jpg.js`, ensure that the Adobe JPEG marker always takes precedence, even when the color transform code is zero
2017-07-22 17:25:09 +02:00
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
Jonas Jenwald
11e95712d4 Add support for the nativeImageDecoderSupport parameter, to force JPEG image decoding using src/core/jpg.js, when running the reference tests 2017-07-11 16:38:49 +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
Jonas Jenwald
ea71d23f74 Fix a stupid spelling error in the ASCII85Decode name in Parser.makeInlineImage (issue 8613)
This is a trivial follow-up to PR 5383, and it's a bit strange that this has been wrong since late 2014 without anyone noticing (maybe because inline images aren't too common).
So, apparently code works better if you actually spell correctly, who knew ;-)

Fixes 8613.
2017-07-05 19:43:09 +02:00
Jonas Jenwald
eff257b820 Merge pull request #8580 from brendandahl/missing-glyf
Fix how we detect and handle missing glyph data.
2017-07-04 12:16:07 +02:00
Brendan Dahl
efbbd8533f Only mask char codes of (3, 0) cmap tables in the range of 0xF000 to 0xF0FF. 2017-07-03 13:13:46 -07:00
Brendan Dahl
6d4f748fb1 Fix how we detect and handle missing glyph data. 2017-07-03 13:06:06 -07:00
Brendan Dahl
a8a8909d2d Fix missing notdef in expert encoding. 2017-06-29 12:12:39 -07:00
Brendan Dahl
f1f9d98519 Merge pull request #8507 from Snuffleupagus/issue-8480
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)
2017-06-23 13:36:58 -07:00
Rob Wu
fc6448d18c Move svg:clipPath generation from clip to endPath
In the PDF from issue 8527, the clip operator (W) shows up before a path
is defined. The current SVG backend however expects a path to exist
before generating a `<svg:clipPath>` element.
In the example, the path was defined after the clip, followed by a
endPath operator (n).
So this commit fixes the bug by moving the path generation logic from
clip to endPath.

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

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

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

test/pdfs/issue6413.pdf is the only file where "W" (a tline 55) is not
followed by "n". In fact, the "W" is the last operation of a series of
XObject painting operations, and removing it does not have any effect
on the rendered PDF (confirmed by looking at the output of PDF.js's
canvas backend, and ImageMagick's convert command).
2017-06-22 01:08:17 +02:00