Commit Graph

2921 Commits

Author SHA1 Message Date
Jonas Jenwald
d6cd5355f0 Use Uint8ClampedArray, when returning data, and remove manual clamping in src/core/jpg.js (issue 4901)
This patch removes the `clamp0to255` helper function, as well as manual clamping code in `src/core/jpg.js`.
The adjusted constants in `_convertCmykToRgb` were taken from CMYK to RGB conversion code found in `src/core/colorspace.js`.

*Please note:* There will be some very slight movement in a number of existing test-cases, since `Uint8ClampedArray` appears to use `Math.round` (or equivalent) and the old code used (basically) `Math.floor`.
2017-08-14 16:19:57 +02:00
Jonas Jenwald
be36c60e0f Polyfill Uint8ClampedArray using core-js
https://github.com/zloirock/core-js
2017-08-14 16:19:55 +02:00
Tim van der Meij
903f372e3d Merge pull request #8762 from Snuffleupagus/evaluator-coded-isType3Font
Replace the `coded` property with `isType3Font` when building the font `properties` object in `PartialEvaluator.translateFont`
2017-08-08 22:02:28 +02:00
Tobias Schneider
da44d10af1 Fallback to plain object for globalScope. 2017-08-08 09:17:48 -07:00
Jonas Jenwald
093afd1212 Replace the coded property with isType3Font when building the font properties object in PartialEvaluator.translateFont
This appears to simply have been forgotten in the re-factoring in PR 4815, where the `coded` property was renamed to the *much* more descriptive `isType3Font` property.
2017-08-08 14:03:02 +02:00
Jonas Jenwald
4729e96fb7 Remove leftover args[0].code checks from the OPS.paintXObject cases in evaluator.js
From looking at blame, it seems that these checks became obsolete with PR 692 (which landed close to six years ago). Note how, after that PR, there's no longer anything being assigned to the `code` property of an Object.
2017-08-07 10:48:37 +02:00
Jonas Jenwald
ace9de6f7d Merge pull request #8747 from brendandahl/first-cmap
Fix two cmap related issues.
2017-08-04 14:11:12 +02:00
Jonas Jenwald
bbf5b4d706 Merge pull request #8745 from yurydelendik/cancel-stream
Properly cancel streams and guard at getTextContent.
2017-08-04 13:00:31 +02: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
Yury Delendik
a1dfbec532 Properly cancel streams and guard at getTextContent. 2017-08-03 16:36:46 -05:00
Yury Delendik
5b5781b45d Merge pull request #8738 from ChenMachluf/remove_workerPort_after_PDFWorker_destroy
Delete workerPort to PDFWorker cache after PDFWorker destroy
2017-08-03 15:49:40 -05:00
Yury Delendik
6beb925f0b Checks Edge support for streams. 2017-08-03 08:48:51 -05:00
Jonas Jenwald
e20d4a9c21 Merge pull request #8681 from brendandahl/glyph-ids
Fix several issues with glyph id mappings (issue 8668, bug 1383504)
2017-08-03 14:25:34 +02:00
Chen Machluf
9b1b160d4f remove PDFWorker from cache after detsroy 2017-08-02 23:48:42 +03: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
Mukul Mishra
00e026ebcd Reduces the amount of data send via GetDocRequest. 2017-07-30 00:00:03 +05:30
Tim van der Meij
783d42ec2b Merge pull request #8611 from apoorv-mishra/colorspace-tests
Add unit-tests for colorspace.js
2017-07-29 00:14:03 +02:00
Yury Delendik
01b47d9012 Use streams-lib as polyfill 2017-07-28 11:54:33 -05: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
Brendan Dahl
ac33358e1f Fix several issues with glyph id mappings.
The initial issue with #8255 was I added a missing glyphs
check to adjustMapping, but this caused us to skip re-mapping
a glyph if the fontCharCode was a missingGlyph which in turn
caused us to overwrite a valid glyph id with an invalid one. While
fixing this, I also added a warning if the private use area is full since
this also accidentally happened when I made a different mistake.

This brought to light a number of issues where we map
missing glyphs to notdef, but often the notdef is actually defined
and then ends up being drawn. Now the glyphs don't get
mapped in toFontChar and so they are not drawn by the canvas.

Fixing the above brought up another issue though in bug1050040.pdf.
In this PDF, the font fails to load by the browser and before we were still
drawing the glyphs because it looked like the font had them, but with the fixes
above the glyphs showed up as missing so we didn't attempt draw them. To
fix this, I now throw an error when the loca table is in really bad shape and
we fall back to trying to use a system font. We now also use this fall back if
there are any format errors during converting fonts.
2017-07-26 13:00:55 -07:00
Tim van der Meij
37ac8f8623 Merge pull request #8698 from Snuffleupagus/issue-8697
Add a fallback for non-embedded SegoeUISymbol font (issue 8697)
2017-07-25 22:35:52 +02:00
Tim van der Meij
44a5cec25e Merge pull request #8666 from apoorv-mishra/fix-colorspace
Fix TypeError that occurs in colorspace.js on accidentally passing an 'Array' instead of 'TypedArray'
2017-07-25 22:13:20 +02:00
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
Mukul Mishra
568b0b6a42 Adds ready capability rejection logic for stream sink. 2017-07-25 02:07:38 +05:30
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
e7cddcce28 Merge pull request #8684 from Snuffleupagus/rm-assert
Remove most `assert()` calls (issue 8506)
2017-07-22 19:42:24 +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
814fa1dee3 Remove most assert() calls (issue 8506)
This replaces `assert` calls with `throw new FormatError()`/`throw new Error()`.
In a few places, throwing an `Error` (which is what `assert` meant) isn't correct since the enclosing function is supposed to return a `Promise`, hence some cases were changed to `Promise.reject(...)` and similarily for `createPromiseCapability` instances.
2017-07-21 18:51:02 +02:00
Apoorv Mishra
d14956d4b8 Fix TypeError that occurs in colorspace.js on accidentally passing an 'Array' instead of 'TypedArray'
Fix TypeError that occurs in colorspace.js on accidentally passing an 'Array' instead of 'TypedArray'

Changed getRgbItem(...) to getRgbBuffer(...) since this.lookup has values in range[0, 255] whereas getRgbItem(...) expects those to be in range [0, 1]

Revert changes for IE9 compatibility
2017-07-21 01:15:05 +05:30
Jonas Jenwald
15f0963f51 Fix a typo, in the Catalog.numPages getter, than prevents shadowing from working correctly
Looking at the blame, it seems that this typo was present even before PR 700 (almost six years ago).
The result of using `'num'`, rather than the *correct* `'numPages'` string, is that the `Catalog.numPages` getter isn't actually being shadowed.
2017-07-20 12:35: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
Yury Delendik
ca3c08f12b Merge pull request #8620 from Rob--W/issue-8560-improve-png-compression
Improve compression of PNG images embedded in generated SVG files
2017-07-14 07:23:38 -05:00
Tim van der Meij
26be1df5f7 Merge pull request #8641 from Snuffleupagus/eslint-version-4-upgrade
Update ESLint (and eslint-plugin-mozilla) to the latest version
2017-07-14 14:17:42 +02:00
Jonas Jenwald
f2270252c7 Add Number.isNaN and Number.isInteger polyfills in compatibility.js, since the Streams polyfill relies on them
Without this, the Streams polyfill will fail in Internet Explorer when the code-paths containing these methods are used.
2017-07-13 12:02:14 +02:00
Jonas Jenwald
6f3565e638 Update ESLint (and eslint-plugin-mozilla) to the latest version 2017-07-12 13:14:25 +02:00
Jonas Jenwald
e2ea9b693c In src/core/jpg.js, ensure that the Adobe JPEG marker always takes precedence, even when the color transform code is zero
According to the PDF specification, please see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G6.2394361, if an Adobe JPEG marker is present it should always take precedence. This even seem to be consistent with the existing comment that is present in the code.
Hence it seems reasonable to interpret `transformCode === 0` as no color conversion being necessary.

Fixes the rendering of page 1 in `issue-4926` (from the test-suite), when the built-in `src/core/jpg.js` image decoder is used.
2017-07-11 17:08:30 +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
94f1dde07d Move DEFLATE logic in convertImgDataToPng
Move the DEFLATE logic in convertImgDataToPng to a separate function.
A later commit will introduce a more efficient deflate algorithm,
and fall back to the existing, naive algorithm if needed.
2017-07-10 18:45:47 +02:00
Rob Wu
742ed3d1c9 Remove __pdfjsdev_webpack__, use webpack options
`__pdfjsdev_webpack__` was used to skip evaluating part of an AST,
in order to not mangle some `require` symbols.
This commit removes `__pdfjsdev_webpack__`, and:

- Uses `__non_webpack_require__` when one wants the output to
  contain `require` instead of `__webpack_require__`.
- Adds options to the webpack config to prevent "polyfills" for
  some Node.js-specific APIs to be added.
- Use `// eslint-disable-next-line no-undef` instead of `/* globals ... */`
  for variables that are not meant to be used globally.
2017-07-09 16:35:48 +02:00
Yury Delendik
d028c26210 Removes error() 2017-07-07 09:40:24 -05: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
Yury Delendik
b3bac5100c Merge pull request #8596 from mukulmishra18/proper-read-result
Fixes wrong structure of fullReader.read() result.
2017-07-05 09:03:57 -05: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
9f5c1550ed Merge pull request #8592 from brendandahl/cmap-3-0
Only mask char codes of (3, 0) cmap tables in the range of 0xF000 to 0…
2017-07-03 17:58:28 -07: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
Mukul Mishra
308a83e5ca Fixes wrong structure of fullReader.read() result. 2017-07-01 15:52:47 +05:30