Commit Graph

9554 Commits

Author SHA1 Message Date
Jonas Jenwald
ede4d3c7c5 Merge pull request #8190 from Snuffleupagus/issue-8182
Try harder to find the next valid JPEG marker when decoding Scan data (issue 8182, issue 8189)
2017-03-27 17:20:41 +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
Yury Delendik
cd5acf501e Merge pull request #8195 from yurydelendik/babel
Enable babel on sources
2017-03-27 07:48:43 -05:00
Yury Delendik
25873e92f0 Enable babel translation to enable ES module support. 2017-03-27 07:25:09 -05:00
Tim van der Meij
0423bb69e9 Merge pull request #8198 from timvandermeij/pdf-to-png
Example for converting PDF to PNG using the Node canvas library
2017-03-26 20:34:49 +02:00
Mukul Mishra
f885e98d20
Example for converting PDF to PNG using the Node canvas library 2017-03-26 20:24:00 +02:00
Tim van der Meij
b6bf1a3eb8 Merge pull request #8196 from Snuffleupagus/evaluator-rm-redundant-xref
Remove unnecessary `xref` parameters from various method signatures in `PartialEvaluator`, since `this.xref` is already available in the relevant scope
2017-03-26 19:48:23 +02:00
Jonas Jenwald
e229c21ce1 Remove unnecessary xref parameters from various method signatures in PartialEvaluator, since this.xref is already available in the relevant scope
For reasons I don't pretend to understand, we're passing around `xref` arguments to a bunch of methods despite `this.xref` being available in `PartialEvaluator`.

This patch is a small first small step towards cleaning up the, often unwieldy, signatures of methods in `PartialEvaluator`.
2017-03-26 14:12:53 +02:00
Jonas Jenwald
e40fd63bd3 In src/core/evaluator.js, convert a couple of if (!someVariable) { error(...); } instances to assert(someVariable); instead
Rather than, in a number of places, basically duplicating the logic of `assert` we can simply utilize the function directly instead.
2017-03-26 13:53:13 +02:00
Yury Delendik
b7ba44b530 Merge pull request #8194 from Snuffleupagus/getTextContent-use-proper-handler
Use a proper `MessageHandler` for `PartialEvaluator.getTextContent` to avoid errors for fonts relying on built-in CMap files (PR 8064 follow-up)
2017-03-25 17:04:03 -05: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
Yury Delendik
68f2bf3bec Update worker-loader dependency 2017-03-23 18:27:38 -05:00
Jonas Jenwald
02370f952a Merge pull request #8184 from Rob--W/rethrow-missing-data-if-needed
Rethrow MissingDataException when needed
2017-03-22 18:21:21 +01:00
Rob Wu
49af56f730 Rethrow MissingDataException when needed
In core/document.js: `PDFDocument.prototype.parse` accesses a dictionary
property, which could throw if the underlying data is not yet available.

In core/obj.js: `get Catalog.prototype.metadata` calls
`stream.getBytes`, which can throw MissingDataException too when the
stream is a ChunkedStream.
2017-03-22 14:55:59 +01:00
Rob Wu
086021b21e Merge pull request #8183 from Snuffleupagus/documentInfo-MissingDataException
Ensure that `PDFDocument.documentInfo` doesn't fail during document load, when the entire XRef table hasn't been fetched yet (issue 8180)
2017-03-22 14:46:08 +01:00
Jonas Jenwald
8527d27eae Ensure that PDFDocument.documentInfo doesn't fail during document load, when the entire XRef table hasn't been fetched yet (issue 8180)
Similar to other `try-catch` statements in `/core` code, we must re-throw `MissingDataException` to prevent issues with missing data during document loading.
Note that I'm not sure if/how we can test this, which is why the patch doesn't include any test(s).

Fixes 8180.
2017-03-22 14:14:38 +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
cfc45e556c Merge pull request #8170 from Snuffleupagus/issue-8169
Try to recover when encountering JPEG markers with too short marker lengths (issue 8169)
2017-03-20 20:34:22 +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
Yury Delendik
b2ed788ea3 Merge pull request #8172 from Snuffleupagus/bug-1345294
Upstream the changes from bug 1345294 - nsIPrefBranch should have methods to get/set unicode strings
2017-03-20 09:38:07 -05:00
Jonas Jenwald
ebae24cacc Upstream the changes from bug 1345294 - nsIPrefBranch should have methods to get/set unicode strings
Note that in order to not break compatibility for the Firefox addon, the preprocessor is used.

Re: [bug 1345294](https://bugzilla.mozilla.org/show_bug.cgi?id=1345294) and also [this commit](https://hg.mozilla.org/mozilla-central/rev/5a8192a650e9).
2017-03-20 07:36:36 +01:00
Tim van der Meij
3ff872b796 Merge pull request #8174 from Snuffleupagus/eslint-yoda-follow-up
Adjust the `yoda` ESLint rule to apply to inequalities as well
2017-03-19 23:49:47 +01:00
Jonas Jenwald
da326a3137 Update l10n files 2017-03-19 13:46:11 +01:00
Jonas Jenwald
a7c19d9cbb Adjust the yoda ESLint rule to apply to inequalities as well
I happened to notice that some inequalities had the wrong order, and was surprised since I thought that the `yoda` rule should have caught that.
However, reading http://eslint.org/docs/rules/yoda#options a bit more closely than previously, it's quite obvious that the `onlyEquality` option does *exactly* what its name suggests. Hence I think that it makes sense to adjust the options such that only ranges are allowed instead.
2017-03-19 13:27:14 +01:00
Tim van der Meij
f0c45f0336 Merge pull request #8168 from Snuffleupagus/issue-8117
Normalize the `BBox` entry in Tiling Pattern dictionaries (issue 8117)
2017-03-16 23:29:44 +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
Yury Delendik
2b17188998 Merge pull request #8154 from mysterlune/pdfjslib_req_vs_window
Change to conditions that `pdfjsLib`
2017-03-13 10:47:37 -05:00
Tim van der Meij
14b91a479e Merge pull request #8156 from Snuffleupagus/findbar-missing-titles
Add (and adjust) a couple of findbar `title` attributes, in `viewer.html`, that doesn't agree with the `l10n/en-US/viewer.properties` file
2017-03-12 16:15:09 +01:00
Jonas Jenwald
fa341169a2 Add (and adjust) a couple of findbar title attributes, in viewer.html, that doesn't agree with the l10n/en-US/viewer.properties file
The point of this patch is to fix a couple of inconsistencies in `viewer.html`, compared to the locale files, such that the viewer would work correctly even without the `l10n/` files present.
*Note:* Since this isn't changing any of the locale files, we should *not* need to update any of the string names.

Looking through the history of the findbar code, it seems that the `findPrevious`/`findNext` buttons have never had a `title` set (note PR 2168, which was the initial findbar implementation).
Furthermore, the `placeholder` of the `findInput` didn't agree 100% with locale file either, so this is also adjusted.
2017-03-12 09:59:44 +01:00
River Lune
3aeef8402b Changing the order of logical conditions to prefer 'window' in the case where webpack is not used.
Updating brace style.

Updating to throw new error vs. throwing a string.
2017-03-11 19:28:45 -08: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
d471e3568d Merge pull request #8151 from Snuffleupagus/rm-toolbarButton-group-CSS
Remove unnecessary `.toolbarButton.group` CSS class
2017-03-10 22:27:57 +01:00
Jonas Jenwald
8f96909e97 Remove unnecessary .toolbarButton.group CSS class
I noticed that we have a `.toolbarButton.group` CSS class, which is currently applied to some buttons in the viewer. Since it attempts to adjust the `margin-right` property, I was initially a bit puzzled as to why there wasn't different rules for LTR/RTL locales.

However, checking the viewer with the DevTools inspector, in both LTR and RTL locales, I quickly found that the rule in question is *always* being overridden by other CSS rules.
It thus seem to me that while this rule was probably useful at some point, it has been dead for years and could now be removed.
2017-03-10 13:49:24 +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
Tim van der Meij
6908f1491d Merge pull request #8132 from timvandermeij/findbar-responsiveness
Viewer: enable find functionality for small devices
2017-03-09 23:03:20 +01:00
Jonas Jenwald
b151666c53
Viewer: consistently wrap find bar elements for small screen sizes
This patch ensures that the find bar is not extended to the window width
when element wrapping occurs on small screens.
2017-03-08 23:55:13 +01:00
Tim van der Meij
87a30a7ee1
Viewer: enable find functionality for small devices
The find functionality is currently not available for small devices
because the find dialog is not responsive. This patch fixes that.

To achieve this goal, the HTML is changed to always show the find
button. To prevent issues because of the addition of an extra button for
small views, the previous/next page buttons are hidden if the view
becomes small. These buttons are not useful anyway because on small
devices navigation is usually done via scrolling. The find functionality
is much more useful to have in this case. Moreover, we wrap the existing
elements into separate `div`s so that the browser can position the
elements itself when the view becomes smaller and logically connected
elements stay together when this happens.

In the CSS, extra rules for the find bar have been added to ensure that
the dialog's doorhanger is always below the find button. All findbar
`div`s are forced to be 32 pixels high to prevent the find message text
being aligned under the checkboxes. Finally, the find message is only
visible when there is actually text to display. This prevents wrapping
issues because, by default, the label has padding and margin even if
there is no text.
2017-03-08 23:54:28 +01:00
Jonas Jenwald
c79e5b3f17
Viewer: replace find label with placeholder/tooltip
This is common in the rest of the UI and helps us prevent responsiveness
issues for different length strings in different locales.
2017-03-08 23:54:14 +01:00
Tim van der Meij
a544a3b4a4 Merge pull request #8138 from Snuffleupagus/bug-1345253
Get rid of `element.removeChild(element.firstChild)` usage (bug 1345253)
2017-03-08 22:29:53 +01:00
Jonas Jenwald
468ed1b9a1 Ensure that the outlineWithDeepNesting CSS class is removed when resetting PDFOutlineViewer, to prevent incorrect alignment if a new document is opened 2017-03-08 17:41:11 +01:00
Jonas Jenwald
e07cb8638e Get rid of element.removeChild(element.firstChild) usage (bug 1345253)
Instead of just upstreaming the changes from [bug 1345253](https://bugzilla.mozilla.org/show_bug.cgi?id=1345253) as-is, it seemed better to simply get rid of the loops altogether and use the same approach as in `PDFViewer`/`PDFThumbnailViewer`.
2017-03-08 17:29:50 +01:00
Jason O. Jensen
d230784ac3 Handle cff fonts with erroneous stackSize 2017-03-06 19:28:46 -05:00
Tim van der Meij
754c4bd0ab Merge pull request #8130 from Snuffleupagus/gulp-lib-rm-web-compatibility
Don't include `web/compatibility.js` in the output for `gulp lib` (PR 8120 follow-up)
2017-03-04 21:27:28 +01:00
Jonas Jenwald
af44ef15f7 Don't include web/compatibility.js in the output for gulp lib (PR 8120 follow-up)
First of all, `compatibility.js` is already available in `lib/shared/compatibility.js`. Second of all, as can be seen in 9142301f35 (diff-9432ebaa58e10ab02874fcb86f689caa), the `lib/web/compatibility.js` file cannot work since the `require` statement isn't compatible with the output of `gulp lib`.
2017-03-04 18:34:28 +01:00
Tim van der Meij
4e3e97be8e Merge pull request #8129 from Snuffleupagus/getInheritedPageProp-undefined
Return `undefined` instead of `Dict.empty` from `Page.getInheritedPageProp` for non-existent properties to prevent possible future bugs
2017-03-04 16:18:24 +01:00
Yury Delendik
c290561488 Merge pull request #8120 from yurydelendik/lib
Publishes processed sources into pdfjs-dist/lib
2017-03-04 08:48:36 -06:00
Jonas Jenwald
9bed87f5dc Return undefined instead of Dict.empty from Page.getInheritedPageProp for non-existent properties to prevent possible future bugs
*This is something that I noticed while working on PR 8126, which is (more) fallout from PR 6065.*

In general, it's actually *not* correct to return `Dict.empty` as the default value for non-existent properties. Please note that a prior PR, see https://github.com/mozilla/pdf.js/pull/5957#issuecomment-103112698, asked for that behaviour but I don't think that's right.

Obviously for properties that are (or should) be `Dict`s it makes sense, however certain properties can be e.g. Strings or Arrays instead. In the latter case, returning `Dict.empty` is just plain wrong, and it's quite fascinating that this hasn't caused any errors in practice. (The existing validation in the various getters has actually saved us here.)

Also, when looking at this code again, it seemed unnecessary to duplicate the `MAX_LOOP_COUNT` check since we could just return immediately instead.
2017-03-04 13:08:39 +01:00