Compare commits

...

1135 commits

Author SHA1 Message Date
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
Tim van der Meij
1eb96d7ca9 Merge pull request #8128 from timvandermeij/csp-headers
Network: use the current location to prevent errors when using CSP headers
2017-03-04 00:01:50 +01:00
Yury Delendik
39e8ad24f7 Creates 'lib' for the 'dist' build target. 2017-03-03 16:37:58 -06:00
Yury Delendik
e7cc07cc11 Moves checkProblematicCharRanges to font_spec.js 2017-03-03 16:33:35 -06:00
Job van der Weiden
a05115d2ec
Network: use the current location to prevent errors when using CSP headers
When using content security headers to restrict connections to the same origin,
you may not make connections to `example.com`. This feature detection also
works with a request to the current location.
2017-03-03 23:18:51 +01:00
Jonas Jenwald
24e5b6ee6c Merge pull request #8126 from Snuffleupagus/issue-8125
Ensure that we don't ignore `0` values in `Page.getInheritedPageProp` (issue 8125)
2017-03-03 22:01:59 +01: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
Yury Delendik
d0d9843a0e Merge pull request #8087 from yurydelendik/pdf_viewer_req
Allows to pull pdf.js from pdf_viewer using require().
2017-02-28 20:51:18 -06:00
Tim van der Meij
522281c01d Merge pull request #8116 from Snuffleupagus/download_manager-preprocessor
Get rid of a couple `eslint-disable` statements in `web/download_manager.js` by instead relying on the preprocessor dead-code removal added in PR 7942
2017-02-28 22:03:47 +01:00
Tim van der Meij
b75d53a7fa Merge pull request #8115 from Snuffleupagus/CONTRIBUTING-rm-mailing-list
[CONTRIBUTING.md] Remove any mention of the mailing list, and the weekly meetings
2017-02-28 21:52:00 +01:00
Jonas Jenwald
37d596e00d Get rid of a couple eslint-disable statements in web/download_manager.js by instead relying on the preprocessor dead-code removal added in PR 7942 2017-02-28 12:41:43 +01:00
Jonas Jenwald
b0fbfc85f0 [CONTRIBUTING.md] Remove any mention of the mailing list, and the weekly meetings
Given that the mailing list has now been closed, see [bug 1340296](https://bugzilla.mozilla.org/show_bug.cgi?id=1340296), and that there's no weekly meetings any more, we probably shouldn't mention either of those in CONTRIBUTING.md.
Instead, let's just suggest the IRC channel as a means of communication here.
2017-02-28 12:12:57 +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
4e201d3787 Merge pull request #8072 from timvandermeij/annotation-append-operator-list
Annotations: move operator list addition logic to `src/core/document.js`
2017-02-27 22:50:57 +01:00
Tim van der Meij
0739f90707
Annotations: move operator list addition logic to src/core/document.js
Ideally, the `Annotation` class should not have anything to do with the
page's operator list. How annotations are added to the page's operator
list is logic that belongs in `src/core/document.js` instead where the
operator list is constructed.

Moreover, some comments have been added to clarify the intent of the
code.
2017-02-27 22:17:49 +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
Tim van der Meij
1da7123f37 Merge pull request #8106 from Snuffleupagus/ObjStm-Dict-objId
Ensure that `Dict`s found in Object Streams are assigned an `objId` in `XRef.fetch`
2017-02-27 21:41:02 +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
Jonas Jenwald
afc3cd2a81 Update l10n files 2017-02-26 13:46:58 +01: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
14cc6acb90 Ensure that Dicts found in Object Streams are assigned an objId in XRef.fetch
This fixes something that I noticed while working with the code in `Catalog.getPageDict` when debugging issue 8088.

Note that while I don't have an example where this patch really matters, given that e.g. `PartialEvaluator.hasBlendModes` depends on the `objId` to avoid cyclic references this patch could potentially help for some PDF files.
2017-02-25 10:20:19 +01:00
Brendan Dahl
54e86f441b Merge pull request #8109 from brendandahl/makeref
Add gulp task to generate refs.
2017-02-24 18:20:50 -08:00
Brendan Dahl
8be4db1c34 Add gulp task to generate refs. 2017-02-24 16:59:01 -08:00
Tim van der Meij
752510ffa0 Merge pull request #8107 from yurydelendik/init-via-port
Init PDFWorker via MesssagePort.
2017-02-25 00:13:33 +01:00
Tim van der Meij
59392fd544 Merge pull request #8102 from yurydelendik/mv-compatibilty
Move compatibility code to the shared/compatibility.js.
2017-02-24 22:47:49 +01:00
Tim van der Meij
912c952df7 Merge pull request #8105 from Snuffleupagus/issue-8088-2
Always check all Kids nodes, in `Catalog.getPageDict`, to avoid getting stuck in an empty node further down in the Pages tree (issue 8088)
2017-02-24 22:12:04 +01:00
Yury Delendik
51767d63fe Init PDFWorker via MesssagePort. 2017-02-24 13:33:18 -06: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
Yury Delendik
facefb0c79 Move compatibility code to the shared/compatibility.js. 2017-02-23 19:18:44 -06:00
Tim van der Meij
cada411af4 Merge pull request #8091 from timvandermeij/gulp-baseline
Gulp: migrate `baseline` target from `make.js`
2017-02-22 00:31:43 +01:00
Tim van der Meij
0f4e6fdb9d
Gulp: migrate baseline target from make.js 2017-02-21 23:50:57 +01:00
Tim van der Meij
72a0916101 Merge pull request #8081 from danielj41/ios-chrome--fix-broken-download-button
iOS Chrome: Fix broken download button
2017-02-20 23:20:03 +01:00
Daniel Johnson
4fc64ceb76 iOS Chrome: Fix broken download button
The download button in pdf.js doesn't work in iOS Chrome.

  - It appears to be an issue with URLs from URL.createObjectURL.
    The URL is correct, but iOS Chrome won't even load the URL
    when `a.click()` is called in `download_manager.js`. Even
    if you manually visit the URL, you get a blank page.

  - Fix this by detecting iOS Chrome and disabling createObjectURL.

The `download_manager.js` `download` method wasn't checking
`PDFJS.disableCreateObjectURL`, so check it there, too.

  - Move the navigator.msSaveBlob check earlier, so that
    this doesn't change IE10 / IE11 behavior.

  - Remove the !URL check since pdf.js has a URL polyfill
    now.
2017-02-20 11:30:53 -08:00
Yury Delendik
bc288141be Allows to pull pdf.js from pdf_viewer using require(). 2017-02-20 08:49:55 -06:00
Tim van der Meij
cf73f4bc2d Merge pull request #8024 from Rob--W/issue-6643-pdf-attachment-in-pdfjs
Open PDF attachments in the viewer instead of an unconditional download
2017-02-18 21:52:29 +01:00
Tim van der Meij
f99e4e46bc Merge pull request #8080 from Snuffleupagus/cmap-unit-test-travis
Enable running the `cmap` unit-tests on Travis by utilizing a `NodeCMapReaderFactory`
2017-02-18 21:27:15 +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
Brendan Dahl
425ad30912 Merge pull request #8071 from Snuffleupagus/bug-1337429
Always choose a (3, 1) cmap table for TrueType fonts that have an encoding specified, regardless of the Symbolic font flag (bug 1337429)
2017-02-16 15:13:46 -08:00
Brendan Dahl
63c472cec8 Remove mailing list information.
The mailing list has become a burden to maintain with all the spam it gets. We have IRC and github for discussion.
2017-02-16 13:36:12 -08:00
Jonas Jenwald
111419a64a Cache built-in binary CMap files in the worker (issue 4794) 2017-02-16 10:55:39 +01:00
Jonas Jenwald
769c1450b7 [api-minor] Refactor fetching of built-in CMaps to utilize a factory on the display side instead, to allow users of the API to provide a custom CMap loading factory (e.g. for use with Node.js)
Currently the built-in CMap files are loaded in `src/core/cmap.js` using `XMLHttpRequest` directly. For some environments that might be a problem, hence this patch refactors that to instead use a factory to load built-in CMaps on the main thread and message the data to the worker thread.

This is inspired by other recent work, e.g. the addition of the `CanvasFactory`, and to a large extent on the IRC discussion starting at http://logs.glob.uno/?c=mozilla%23pdfjs&s=12+Oct+2016&e=12+Oct+2016#c53010.
2017-02-16 10:55:35 +01:00
Tim van der Meij
8aad33e8a3 Merge pull request #8065 from timvandermeij/annotation-appearances
Annotations: refactor setting the normal appearance stream
2017-02-15 23:27:40 +01:00
Tim van der Meij
26fc79d51d
Annotations: refactor setting the normal appearance stream
Previously, we had a function called `getDefaultAppearance`. This name,
however, is misleading as the method gets the normal appearance (in the
`N` entry) and not the default appearance (in the `DA` entry). Moreover,
it was not entirely clear how it works just from reading the code. It
primarily lacks comments and explicit error case handling.

This patch improves the situation by fixing the issues mentioned above
and making this function a proper method of the `Annotation` class, just
like e.g., `setColor` and `setBorderStyle`.
2017-02-15 22:42:17 +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
fde609e810 Merge pull request #8070 from yurydelendik/new-node-js-check
New node.js check to protect from webpack.
2017-02-15 17:15:18 +01:00
Yury Delendik
fa0e559fe2 New node.js check to protect from webpack. 2017-02-14 15:00:52 -06:00
Yury Delendik
b509a3f83c Merge pull request #8067 from Snuffleupagus/gulp-mozcentral-pdfjschildbootstrap.js
Include the `pdfjschildbootstrap.js` file in the output for `gulp mozcentral` builds (PR 8023 follow-up)
2017-02-13 16:44:53 -06:00
Jonas Jenwald
2aaeb17037 Include the pdfjschildbootstrap.js file in the output for gulp mozcentral builds (PR 8023 follow-up)
*Yet another thing that I unfortunately missed during review of PR 8023.*

Note that previously, in `make.js` this file was being preprocessed, however as far as I can tell that wasn't actually necessary. Hence this patch just copies the file to the proper output directory.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1338395#c8.
2017-02-13 23:25:54 +01:00
Yury Delendik
41041c1576 Merge pull request #8063 from Snuffleupagus/issue-8061
Consume the current character when encountering illegal characters in `Lexer.getObject`, in order to prevent infinite loops during reading of streams (issue 8061)
2017-02-11 13:04:18 -06: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
Tim van der Meij
da08b801a5 Merge pull request #8062 from timvandermeij/readme
Improve the README by removing outdated information
2017-02-11 16:33:46 +01:00
Tim van der Meij
fd21ee59a6 Improve the README by removing outdated information 2017-02-11 16:27:34 +01:00
Jonas Jenwald
7be8bd9f96 Merge pull request #8060 from a0preetham/font_ascent_fix
Font ascent descent calculation fix
2017-02-11 13:32:04 +01:00
pmysore1
af8292058f Font ascent descent calculation fix 2017-02-11 01:25:05 -05:00
Tim van der Meij
466760efca Merge pull request #8056 from Snuffleupagus/ChildNode.remove
Use `ChildNode.remove` instead of `ChildNode.ParentNode.removeChild` in a couple of places (bug 1334831, issue 8008)
2017-02-10 23:17:17 +01:00
Yury Delendik
1549a46e3d Merge pull request #8058 from yurydelendik/fix-webpack-combined
Fixes pdf.combined.js for webpack
2017-02-10 13:40:53 -06:00
Yury Delendik
7d9941d870 Fixes pdf.combined.js for webpack. 2017-02-10 11:24:35 -06:00
Yury Delendik
f8879d984c Merge pull request #8054 from Snuffleupagus/gulp-mozcentral-locale-dest
Write the l10n files to the correct destination for `gulp mozcentral` builds (PR 8023 follow-up)
2017-02-10 09:46:34 -06:00
Jonas Jenwald
63f13773e7 Use ChildNode.remove instead of ChildNode.ParentNode.removeChild in a couple of places (bug 1334831, issue 8008)
Re: [bug 1334831](https://bugzilla.mozilla.org/show_bug.cgi?id=1334831) and issue 8008.

Note that according to the specification, see https://dom.spec.whatwg.org/#interface-childnode, the `remove` method shouldn't throw.
This is also consistent with e.g. the Firefox implementation, see http://searchfox.org/mozilla-central/rev/d3307f19d5dac31d7d36fc206b00b686de82eee4/dom/base/nsINode.cpp#1852.

Obviously this isn't supported in IE (because that would be too easy), however we can easily polyfill it to avoid having to WONTFIX the bug/issue.
2017-02-10 14:39:50 +01:00
Rob Wu
ba81b37b43 Merge pull request #8053 from Snuffleupagus/DEFAULT_URL-chromecom
[Chromium addon] Prevent errors that break the addon, caused by the `DEFAULT_URL` constant being replaced by a `defaultUrl` viewer configuration parameter (PR 8046 follow-up)
2017-02-10 12:47:50 +01:00
Jonas Jenwald
991c7c196d Write the l10n files to the correct destination for gulp mozcentral builds (PR 8023 follow-up)
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1338395#c2.
2017-02-10 11:46:14 +01:00
Jonas Jenwald
190c8398ba [Chromium addon] Prevent errors that break the addon, caused by the DEFAULT_URL constant being replaced by a defaultUrl viewer configuration parameter (PR 8046 follow-up)
I missed this during review, sorry about that!

Fixes 8051.
2017-02-10 10:46:44 +01:00
Yury Delendik
32856f0adb Merge pull request #8046 from yurydelendik/webpack
Replacing custom bundling with webpack 2
2017-02-09 16:04:54 -06:00
Tim van der Meij
573236e3ad Merge pull request #8043 from Rob--W/issue6696-auto-rotate-page
Allow automatic print rotation via the enablePrintAutoRotate preference
2017-02-08 23:57:28 +01:00
Yury Delendik
0759066be0 Saving old-style JS module name of dist libraries. 2017-02-08 16:48:37 -06:00
Yury Delendik
a048519fa1 Replace copyright headers; changes UMD to CommonJS. 2017-02-08 16:35:58 -06:00
Yury Delendik
eb4c88cd44 Replacing custom bundling with webpack2. 2017-02-08 16:32:15 -06:00
Rob Wu
ece44d36e8 Allow automatic print rotation via enablePrintAutoRotate 2017-02-08 12:39:24 +01:00
Rob Wu
f6548e463f Open PDF attachments in the viewer instead of download
If users want to download, they can quickly click on the Download button
in the newly opened viewer.

The blobUrl logic for Firefox relies on `disableCreateObjectURL` is
never false in Firefox. If the assumption is invalid, then PDF
attachments at the attachment view will not correctly be displayed,
because a data-URL will be generated and `?<filename>` is treated as
part of the data:-URL.
2017-02-08 11:21:34 +01:00
Tim van der Meij
35102c025a Merge pull request #8041 from timvandermeij/radio-button-value
Interactive forms: set the `buttonValue` for radio buttons that do not have a `fieldValue`
2017-02-08 00:35:48 +01:00
Tim van der Meij
9f05a5a211 Interactive forms: unit test for radio buttons without a field value 2017-02-07 23:44:31 +01:00
vkuryakov
4e181e59ef Interactive forms: values for radio buttons (issue #6995) 2017-02-07 23:42:40 +01:00
Rob Wu
775441b7c6 Refactor: configurable page rotation in print job
Determine the page rotation at the same place as where the page size is
determined. This allows us to implement custom print page rotation logic
in one place, in the future.
2017-02-07 23:42:36 +01:00
Tim van der Meij
1a2f3f95ca Merge pull request #8040 from timvandermeij/l10n-update
Update localization files
2017-02-07 23:30:26 +01:00
Tim van der Meij
dae71559da Update localization files 2017-02-07 23:14:06 +01:00
Yury Delendik
d7a113e766 Merge pull request #8039 from yurydelendik/examples
Moving interactive examples to jsfiddle.net
2017-02-07 13:16:39 -06:00
Yury Delendik
fd4428136b Moving interactive examples to jsfiddle.net 2017-02-07 13:11:18 -06:00
Jonas Jenwald
d7cb46dafc Merge pull request #8038 from yurydelendik/rm-sed
Moves sed processing into the preprocessing tasks and merging tasks.
2017-02-07 17:24:29 +01:00
Yury Delendik
a5ad2b166b Moves sed processing into the preprocessing tasks and merging tasks. 2017-02-07 08:53:33 -06:00
Yury Delendik
9b0e0954fb Merge pull request #8036 from mukulmishra18/node-canvas
[api-minor] Fixes behaviour of DOMCanvasFactory to return {canvas, context}.
2017-02-07 07:39:12 -06:00
Tim van der Meij
d3ae5b38ce Merge pull request #8035 from Snuffleupagus/api-disableNativeImageDecoder
[api-minor] Add a `getDocument` parameter that allows disabling of the `NativeImageDecoder` (e.g. for use with Node.js)
2017-02-06 23:37:02 +01:00
Mukul Mishra
41d092d04b Fixes behaviour of DOMCanvasFactory to return {canvas, context}. 2017-02-07 03:47:13 +05:30
Jonas Jenwald
9c34d0aa8c [api-minor] Add a getDocument parameter that allows disabling of the NativeImageDecoder (e.g. for use with Node.js)
Note that I initially tried to add this as a parameter to the `PDFPageProxy.render` method, such that it could be passed to `PartialEvaluator.getOperatorList`.
However, given all the different code-paths that call `getOperatorList` (there's a bunch only in `annotation.js`), this seemed to very quickly become unwieldy and thus difficult to maintain compared to simply using the existing `evaluatorOptions`.
2017-02-06 22:21:34 +01:00
Tim van der Meij
ec26a7e565 Merge pull request #8028 from Snuffleupagus/tests-prevent-console-errors
Prevent browser console errors during testing
2017-02-06 22:04:54 +01:00
Jonas Jenwald
3e5c6e4287 Merge pull request #8030 from timvandermeij/acroforms-example
Interactive forms: rewrite AcroForms example
2017-02-06 17:45:44 +01:00
Yury Delendik
d842c9c6b0 Merge pull request #8002 from mukulmishra18/refactor-canvas
[api-minor] Fix #7798: Refactor scratch canvas usage.
2017-02-06 07:45:41 -06:00
Rob Wu
c67edabcb3 Set title using logic similar as download name
The download method (and the PDF document properties) detect the
file name using `getPDFFileNameFromURL`. The title ought to also
display the PDF filename if available.
2017-02-06 00:48:46 +01:00
Rob Wu
228d253f30 Detect download filename based on full URL 2017-02-06 00:48:46 +01:00
Tim van der Meij
63fa26843b Interactive forms: rewrite AcroForms example
This patch lets the AcroForms example make use of the built-in interactive
forms functionality in PDF.js. This makes the example:

- much easier to understand;
- more feature-complete;
- in sync with the core when new functionality is added;
- similar to the other examples in terms of structure.
2017-02-05 23:44:32 +01:00
Tim van der Meij
66304f7c99 Merge pull request #8027 from Snuffleupagus/addon-remove-MOZ_CENTRAL
[Firefox addon] Remove the unused `MOZ_CENTRAL` constant
2017-02-05 22:09:18 +01:00
Mukul Mishra
32817633c9 Fix #7798: Refactor scratch canvas usage.
Fixes extra canvas create calls.
Fixes unnecessary call of `new DOMCanvasFactory`.
Fixes undefined error of DOMCanvasFactory.
Fixes failures in some of the tests.
Fixes expected behaviour.
Remove unused vars.
2017-02-05 20:19:47 +05:30
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
Tim van der Meij
cae8d97c4c Merge pull request #8025 from Snuffleupagus/eslint_brace-style_allowSingleLine_false
Adjust the `brace-style` ESLint rule to disallow single lines (and also enable `no-iterator`)
2017-02-04 22:23:01 +01:00
Jonas Jenwald
b898a453f0 [Firefox addon] Remove the unused MOZ_CENTRAL constant
The last (and only) usage of `MOZ_CENTRAL` was removed in PR 3036, so it's been unused for almost four years now.
If we need to have different code-paths for `FIREFOX`/`MOZCENTRAL` builds, the preprocessor should (and has) been used instead.
2017-02-04 17:51:40 +01:00
Jonas Jenwald
bc736fdc7d Adjust the brace-style ESLint rule to disallow single lines (and also enable no-iterator)
See http://eslint.org/docs/rules/brace-style.
Having the opening/closing braces on the same line can often make the code slightly more difficult to read, in particular for `if`/`else if` statements, compared to using new lines.

This patch also, for consistency with `mozilla-central`, enables the [`no-iterator`](http://eslint.org/docs/rules/no-iterator) rule. Note that this rule didn't require a single code change.
2017-02-04 15:53:08 +01:00
Jonas Jenwald
92e5fb099e Merge pull request #8023 from yurydelendik/mv-preprocessorbuild
Moves preprocessor stuff to the gulpfile.
2017-02-04 15:45:18 +01:00
Yury Delendik
2049cf01db Moves preprocessor stuff to the gulpfile. 2017-02-04 08:19:46 -06:00
Rob Wu
d9f90d595d [CRX] Recognize blob and data-URLs in the router
When a blob or data-URL is opened with the extension, viewer.html
rewrites the URL. But when the viewer is refreshed (e.g. F5), Chrome
would fail to display the viewer because the extension router was not
set up to recognize such URLs.

Now it is.
2017-02-04 01:20:17 +01:00
Rob Wu
5fdc908f02 Recognize file name in reference fragment in getPDFFileNameFromURL
The regular expression incorrectly marked a group as capturing.
For `http://example.com/#file.pdf`, the expected result is "file.pdf",
but instead "document.pdf" was returned.
2017-02-04 00:56:15 +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
Tim van der Meij
fe3b64d4ab Merge pull request #8016 from Snuffleupagus/remove-isStream-property
Remove the unused `isStream` property on various `Stream`s
2017-02-01 23:07:40 +01:00
Tim van der Meij
37ecb8e620 Merge pull request #7959 from Snuffleupagus/PDFSidebar-notifications
Display a notification on the `sidebarToggle` button for PDF documents with outline/attachments
2017-02-01 22:59:31 +01:00
Jonas Jenwald
f7d99ccc26 Remove the unused isStream property on various Streams
This property was added all the way back in PR 542, but hasn't actually been relied upon ever since PR 692.
Note that there's a `isStream()` utility function which replaced the property years ago, hence the `isStream` property is now dead code.
2017-02-01 11:38:11 +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
Jonas Jenwald
616e5fadff Display a notification on the sidebarToggle button for PDF documents with outline/attachments
A longstanding issue with the viewer is that you cannot tell if a PDF document includes an outline and/or attachments without actually opening the sidebar.
This patch contains a suggested solution for that, by displaying an hide-on-interaction notification on the `sidebarToggle` button (and the relevant sidebar view buttons). Note that this was inspired by e.g. the update notification that is displayed on the menu button in Firefox.

For an initial implementation, I've tried to do this in such a way that the notification isn't too distracting. Without being an UX expert, I don't think that we'd want something too in-your-face, in order to keep the viewer toolbars reasonable clean. (We probably do *not* want e.g. an entire notification bar in these situations, since that would take up unnecessary screen space and require actions from the user to close.)

However it's certainly possible that the current notification might simply be *too* inconspicuous to be truly helpful to users, but we could probably iterate on that if the feature itself is deemed useful.
2017-01-30 15:39:04 +01:00
Jonas Jenwald
3f320f0b11 Merge pull request #8006 from timvandermeij/mozFillRule
Remove usage of `mozFillRule`
2017-01-30 10:35:29 +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
8d684b5b3f Merge pull request #8003 from Snuffleupagus/move-EOF-isEOF
Move `EOF`/`isEOF` from core/parser.js to core/primitives.js
2017-01-29 22:16:25 +01:00
Jonas Jenwald
2b84fb79b4 Merge pull request #7995 from Snuffleupagus/addon-eslint_consistent-return
[Firefox addon] Enable the `consistent-return` ESLint rule (issue 7957)
2017-01-27 19:11:43 +01:00
Jonas Jenwald
7e1d92461a [Firefox addon] Enable the consistent-return ESLint rule (issue 7957)
See http://eslint.org/docs/rules/consistent-return; it appears that I overlooked this rule in PR 7982.

Also adds the http://eslint.org/docs/rules/no-nested-ternary rule, which didn't require any code changes, since that rule is being enforced in mozilla-central.

Re: issue 7957.
2017-01-27 19:04:08 +01:00
Jonas Jenwald
8823f6f5eb Merge pull request #7991 from Snuffleupagus/addon-eslint-quotes-double
[Firefox addon] Enforce double quotes, using ESLint, to avoid linting errors in mozilla-central (issue 7957)
2017-01-27 17:54:26 +01:00
Jonas Jenwald
50c2856097 Move EOF/isEOF from core/parser.js to core/primitives.js
Given the nature of `EOF` and `isEOF`, it seems to me that they really ought to be placed in `core/primitives.js` instead.

In general, it doesn't seem great to have to depend on the entire `core/parser.js` file for such simple primitives/helper functions.
In particular, while `core/ps_parser.js` is completely separate from `core/parser.js` with regards to its function, it still depends on the latter for just *one* primitive.

Note that compared to e.g. PR 7389, this will not reduce the number of dependencies for `core/ps_parser`, however the new dependency IMHO makes more sense.
2017-01-27 13:37:48 +01:00
Yury Delendik
e132fa976e Merge pull request #8001 from yurydelendik/v1.7.225
Release of 1.7.225
2017-01-26 14:55:22 -06:00
Yury Delendik
ad4960ab09 Release of 1.7.225 2017-01-26 14:54:47 -06:00
Yury Delendik
17d135fcfc Merge pull request #8000 from yurydelendik/version1.7
Version 1.7
2017-01-26 14:48:49 -06:00
Yury Delendik
5fdec9257a Version 1.7 2017-01-26 14:47:23 -06:00
Jonas Jenwald
e835774d9c Update l10n files 2017-01-26 21:24:30 +01:00
Jonas Jenwald
af42c266e7 Merge pull request #7987 from yurydelendik/noopener
[api-minor] Adds noopener and nofollow to rel attribute of hyperlinks.
2017-01-26 20:54:09 +01:00
Jonas Jenwald
a5d5b970af [Firefox addon] Enforce double quotes, using ESLint, to avoid linting errors in mozilla-central (issue 7957)
Given that this patch causes a lot of churn in the addon code, I wouldn't really mind if we ultimately decide against doing this and just add a rule exception in mozilla-central instead.[1]

---
[1] Note that I used the ESLint `--fix` option, hence writing this commit message actually took longer time than the creation of the patch :-)
2017-01-25 01:14:06 +01:00
Yury Delendik
e0a92a7f48 Merge pull request #7990 from Snuffleupagus/addon-remove-network.js
[Firefox addon] Stop bundling `src/core/network.js` into the `FIREFOX`/`MOZCENTRAL` builds (PR 7322 follow-up)
2017-01-24 09:54:14 -06:00
Tim van der Meij
2170eda9df Merge pull request #7971 from davehouse/remove_viewer_page_div_id
remove viewer page div id
2017-01-23 22:27:26 +01:00
Jonas Jenwald
f000417ce0 [Firefox addon] Stop bundling src/core/network.js into the FIREFOX/MOZCENTRAL builds (PR 7322 follow-up)
PR 7322 added the `PdfJsNetwork.jsm` file, instead of the general `src/core/network.js` file for the Firefox addon. However, `make.js` wasn't updated to actually stop including the now obsolete network file.
2017-01-23 22:23:17 +01:00
Yury Delendik
ca74e15a46 Merge pull request #7988 from Snuffleupagus/eslint-more-rules-2
Enable the `no-empty-pattern`/`no-floating-decimal`/`no-self-compare`/`no-delete-var`/`no-new-object` ESLint rules
2017-01-23 14:28:12 -06:00
Jonas Jenwald
f77c52291e Enable the no-empty-pattern/no-floating-decimal/no-self-compare/no-delete-var/no-new-object ESLint rules
The following rules required no code changes:
http://eslint.org/docs/rules/no-empty-pattern
http://eslint.org/docs/rules/no-floating-decimal
http://eslint.org/docs/rules/no-delete-var
http://eslint.org/docs/rules/no-new-object

There was just one change needed in order to enable:
http://eslint.org/docs/rules/no-self-compare; which I think helps readability a lot, since that comparison makes no sense until you realize that we push `NaN` onto the `stack` in some cases *and* furthermore that `NaN !== NaN`.
2017-01-23 20:30:50 +01:00
Yury Delendik
fc2d8c15e8 Adds noopener and nofollow to rel attribute of hyperlinks. 2017-01-23 10:34:27 -06:00
Yury Delendik
fd1affa78a Merge pull request #7982 from Snuffleupagus/addon-es6
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
2017-01-23 09:53:37 -06:00
Yury Delendik
857e360a42 Merge pull request #7977 from Snuffleupagus/paintedViewport-regression
Ensure that we use the *correct* `paintedViewport` in `PDFPageView.cssTransform`, to avoid visual glitches on quick rotations (PR 7738 follow-up)
2017-01-23 09:41:35 -06:00
Jonas Jenwald
a47fc2f8f3 Merge pull request #7985 from yurydelendik/ie9-doc-ready
Fixes IE9 document.readyState and input.type=number issues.
2017-01-23 16:37:23 +01:00
Yury Delendik
a9cf281723 Fixes IE9 document.readyState and input.type=number issues. 2017-01-23 09:23:13 -06:00
Dave House
52360694b0
Remove ids from viewer page and thumbnail divs
The id, and parsing it for the page number, is replaced by the
data-page-number attribute (added here for thumbnails).
2017-01-23 07:46:39 -07:00
Jonas Jenwald
9eb9065c79 Ensure that we use the *correct* paintedViewport in PDFPageView.cssTransform, to avoid visual glitches on quick rotations (PR 7738 follow-up)
*This fixes a regression from commit c9a0955c9c, i.e. PR 7738.*

Currently if you quickly rotate a document at least *twice*,[1] such that rendering of a page hasn't finished for the first rotation before the last rotation is triggered, the `cssTransform` method can fail to update the page correctly leading to it looking temporarily distorted.

The reason why things break is that previously we stored the `viewport` on the canvas DOM element, meaning that when it was accessed in `cssTransform` is was guaranteed to point to the `viewport` of the `zoomLayer` canvas.
Generally you want to avoid storing data on DOM elements this way, and during the `PDFPageView` refactoring needed to support SVG rendering, the previous `viewport` was instead stored directly on `PDFPageView`.
However, the problem is first of all that the `paintedViewport` only stores the *last* `viewport` computed, and second of all that there're no guarantees that it actually applies to the current `zoomLayer` canvas.
If a document is rotated slowly enough that rendering finishes *before* the next rotation then this problem doesn't exist, but for sufficiently quick rotations rendering will be cancelled at least once and the `paintedViewport` could thus be bogus.

The solution for the above problems is to ensure that we track the correct `viewport` for each DOM element (canvas or svg),[2] which seemed easist to do with a `WeakMap`.[3]

---
[1] I'm able to reproduce this using the `tracemonkey` file, but please note that for pages with few operations, i.e. that render very quickly, the effect may be hard to spot.

[2] One other possible solution that I briefly considered, was to wait until rendering finished before storing the current `viewport`. However, that would have caused issues with rotating a page before the *first* rendering operation had finished.

[3] This regression took me way longer to both figure out, and fix, than I'd like to admit :-)
2017-01-23 12:13:53 +01:00
Jonas Jenwald
3ec99f0e12 [Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*

This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.

The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.

One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.

Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.

Fixes the first bullet point of issue 7957.
2017-01-22 23:14:58 +01:00
Tim van der Meij
1948a53ebb Merge pull request #7973 from Snuffleupagus/eslint_spaced-comment
Enable the `spaced-comment` ESLint rule
2017-01-22 21:58:42 +01:00
Tim van der Meij
17dd2e6b20 Merge pull request #7979 from Snuffleupagus/eslint-more-rules
Enable the `no-unsafe-finally`/`no-octal`/`no-useless-call` ESLint rules
2017-01-22 20:53:26 +01:00
Jonas Jenwald
54d55e8b7a Merge pull request #7980 from mukulmishra18/lint-errors
Fix #7978: Fixes ESLint yoda rule for the URL polyfill.
2017-01-22 00:49:20 +01:00
Mukul Mishra
4e38200030 Fix #7978: Fixes ESLint yoda rule for the URL polyfill. 2017-01-21 22:47:28 +05:30
Jonas Jenwald
82ea7e6e6e Enable the no-unsafe-finally/no-octal/no-useless-call ESLint rules
http://eslint.org/docs/rules/no-unsafe-finally, there's just one violation which in this case can actually be ignored since there's nothing `return`ed there.
http://eslint.org/docs/rules/no-octal, there're no violations in the code-base.
http://eslint.org/docs/rules/no-useless-call, there's just one violation that needs to be fixed.
2017-01-21 17:15:57 +01:00
Tim van der Meij
f8e793f8c2 Merge pull request #7974 from Snuffleupagus/eslint_no-lone-blocks
Enable the `no-lone-blocks` ESLint rule
2017-01-19 22:35:38 +01:00
Jonas Jenwald
31684e6918 Enable the no-lone-blocks ESLint rule
http://eslint.org/docs/rules/no-lone-blocks

Note that we currently have no code that violates this rule in the source files, but it seems that the built files are possibly affected (see issue 7957).
2017-01-19 19:56:23 +01:00
Jonas Jenwald
4626fc8342 Enable the spaced-comment ESLint rule
Please see http://eslint.org/docs/rules/spaced-comment.

Note that the exceptions added for `line` comments are intended to still allow use of the old preprocessor without linting errors.
Also, I took the opportunity to improve the grammar slightly (w.r.t. capitalization and punctuation) for comments touched in the patch.
2017-01-19 16:41:59 +01:00
Tim van der Meij
a917443ae6 Merge pull request #7965 from Snuffleupagus/bug-1331081
[Bug 1331081] omit addEventListener/removeEventListener's third parameter when it's false
2017-01-17 22:26:26 +01:00
Jonas Jenwald
70c1a6b120 [Bug 1331081] omit addEventListener/removeEventListener's third parameter when it's false
Upstream changes from https://bugzilla.mozilla.org/show_bug.cgi?id=1331081; this patch also covers one file, `pdf_print_service.js`, that's not present in mozilla-central.

Fixes 7962.
2017-01-17 17:50:21 +01:00
Tim van der Meij
c1703e977d Merge pull request #7960 from Snuffleupagus/eslint_space-unary-ops
Adjust the `space-unary-ops` ESLint rule to comply with mozilla-central lint rules
2017-01-16 22:18:39 +01:00
Jonas Jenwald
0dff8f3600 Adjust the space-unary-ops ESLint rule to comply with mozilla-central lint rules
See http://eslint.org/docs/rules/space-unary-ops; a *very* small part of issue 7957.
2017-01-16 17:19:25 +01:00
Jonas Jenwald
c0a47fddcc Update l10n files 2017-01-16 09:54:50 +01:00
Yury Delendik
9b111c9157 Merge pull request #7956 from Snuffleupagus/bug-1330147
[Bug 1330147] removeObserver calls should not supply a third parameter
2017-01-13 08:06:18 -06:00
Jonas Jenwald
54a64863e2 [Bug 1330147] removeObserver calls should not supply a third parameter
*This is yet another very recent change that we were not notified about.*

Upstream changes from https://bugzilla.mozilla.org/show_bug.cgi?id=1330147, specifically https://hg.mozilla.org/mozilla-central/rev/8e0b7bc5fd71.
2017-01-13 11:34:26 +01:00
Yury Delendik
76b4c8fae1 Merge pull request #7954 from yurydelendik/bug1329182
[Bug 1329182] remove trailing newURI null parameters
2017-01-12 19:41:44 -06:00
Yury Delendik
1f424e561d [Bug 1329182] remove trailing newURI null parameters 2017-01-12 19:40:51 -06:00
Yury Delendik
b8cd14336e Merge pull request #7913 from Snuffleupagus/addon-minimum-firefox45
[Firefox addon] Change the minimum supported version to Firefox 45, i.e. the current ESR version, and remove no longer necessary fallback code
2017-01-12 15:12:27 -06: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
Yury Delendik
c0d7029039 Merge pull request #7951 from Snuffleupagus/FileAttachmentAnnotation-simplified-unittest
Rename `annotation_layer_spec.js` to `annotation_spec.js` to better describe what is actually tested, and simplify the `FileAttachmentAnnotation` unit-test to avoid having to use the entire API in the test
2017-01-12 12:27:26 -06: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
Yury Delendik
1af35a6d88 Merge pull request #7948 from Skaty/fix-bidi-fraction
Fix inverted calculation of RTL text percentage in bidi
2017-01-12 10:40:08 -06:00
Syed Abdullah
857a5da8f1 Fix inverted calculation of RTL text percentage in bidi. 2017-01-12 23:54:06 +08:00
Jonas Jenwald
00ab0abd4e Merge pull request #7945 from yurydelendik/mv-locale-cmaps
Moves locale and cmaps tasks to gulpfile.
2017-01-11 14:05:21 +01: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
Yury Delendik
f1abd834d8 Moves locale and cmaps tasks to gulpfile. 2017-01-10 11:50:38 -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
e5cea05881 Merge pull request #7944 from yurydelendik/rm-defpref
Removes Promise usage from preferences.js
2017-01-10 17:19:26 +01:00
Yury Delendik
cf7a9f99c8 Merge pull request #7943 from Snuffleupagus/fixtures-test-fixes
Various fixes for the `external/builder/test*.js` files
2017-01-10 08:58:37 -06:00
Yury Delendik
930a28d879 Better DOMContentLoaded handling. 2017-01-10 08:49:08 -06:00
Yury Delendik
ac2d4abf39 Removes web/default_preferences.js file. 2017-01-10 08:33:32 -06:00
Jonas Jenwald
3aa37ae8bc Add the external/builder/fixtures/ directory to .eslintignore, to avoid having to disable various lint rules locally
This is similar to the already existing exception for `external/builder/fixtures_esprima`.
2017-01-10 14:45:40 +01:00
Jonas Jenwald
fe9a561d45 Actually increment the errors counter on failures in test-fixtures.js/test_fixtures_esprima.js, so that the test runners won't incorrectly report that the tests passed 2017-01-10 14:45:36 +01:00
Jonas Jenwald
cf00516f04 Rename the external/builder/test*.js files to make it more obvious what they test
Currently you have to open the files to be certain which tests each one will run, which we can avoid by appending the directory names to the file names of the tests themselves.
2017-01-10 14:27:05 +01:00
Jonas Jenwald
ca0ebdfa56 Merge pull request #7942 from yurydelendik/rm-deadcode
Fixes preprocessor testing and adds deadcode removal.
2017-01-10 13:31:47 +01:00
Yury Delendik
77b7b84d1e Removes rest of 'no-else-return' comments. 2017-01-09 19:13:36 -06:00
Yury Delendik
6265bb6038 Fixes preprocessor testing and adds deadcode removal. 2017-01-09 19:05:36 -06:00
Tim van der Meij
f828f07ccd Merge pull request #7941 from Snuffleupagus/Page-idFactory
Replace direct lookup of `uniquePrefix`/`idCounters`, in `Page` instances, with an `idFactory` containing an `createObjId` method instead
2017-01-10 00:25:48 +01: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
Tim van der Meij
e259bc2c16 Merge pull request #7939 from yurydelendik/unittesttravis
Enables some unit tests on travis.
2017-01-09 23:14:17 +01:00
Tim van der Meij
098acb1269 Merge pull request #7935 from Snuffleupagus/eslint_no-else-return
Enable the `no-else-return` ESLint rule
2017-01-09 23:03:48 +01:00
Yury Delendik
c45300e06c Enables some unit tests on travis. 2017-01-09 15:43:45 -06:00
Jonas Jenwald
4046d67fde Enable the no-else-return ESLint rule
Using `else` after `return` is not necessary, and can often lead to unnecessarily cluttered code. By using the `no-else-return` rule in ESLint we can avoid this pattern, see http://eslint.org/docs/rules/no-else-return.
2017-01-09 20:27:39 +01:00
Yury Delendik
049d7fa277 Merge pull request #7934 from porlan1/master
Unit test files as modules
2017-01-09 11:27:31 -06:00
porlan1
d9e1cb7955 unit test files as UMD modules 2017-01-09 11:40:57 -05:00
Jonas Jenwald
15f75a5585 [Firefox addon] Remove the registerAddonHistogram fallback code for Firefox versions 36 (and below) from PdfJsTelemetry-addon.jsm
Given that the addon doesn't even work in Firefox versions prior to 38, this is just dead code that can now be removed.
2017-01-07 12:19:42 +01:00
Jonas Jenwald
9434c023ab [Firefox addon] Change the minimum supported version to Firefox 45, i.e. the current ESR version, and remove no longer necessary fallback code
According to https://wiki.mozilla.org/RapidRelease/Calendar#Past_branch_dates: The *last* ESR version of Firefox 38 was released in April this year, and since June the only available ESR version has been based on Firefox 45.

Now that Seamonkey has *finally* released a new version, i.e. 2.46 which should correspond to Firefox 49, there doesn't seem to be any reason to keep the fallback code around in the addon anymore.
2017-01-07 12:19:42 +01:00
Jonas Jenwald
aabfb7788a Merge pull request #7926 from Snuffleupagus/api-onPassword-abort/throw-Promise
[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)
2017-01-04 10:44:18 +01:00
Jonas Jenwald
14b8523314 Refactor the password handling so that it's stored in the PdfManagers, instead of in the XRef
We're already passing in a, currently unused, `PdfManager` instance when initializing the `XRef`. To avoid having to pass a single `password` parameter around, we could thus simply get the `password` through the `PdfManager` instance instead.
2017-01-03 20:29:52 +01: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
4e62562a36 Update l10n files 2017-01-02 13:26:09 +01:00
Jonas Jenwald
59afb4b9f0 Merge pull request #7920 from Snuffleupagus/bug-1157493-followup
Improve the handling of `Encoding` dictionary, with `Differences` array, in `PartialEvaluator_preEvaluateFont`
2016-12-29 10:52:31 +01:00
Jonas Jenwald
ddea9a6b04 Improve the handling of Encoding dictionary, with Differences array, in PartialEvaluator_preEvaluateFont
I recently happened to look at the code I wrote for PR 5964, which fixed [bug 1157493](https://bugzilla.mozilla.org/show_bug.cgi?id=1157493), and I quickly realized that the solution is way too simplistic.
The fact that only using the `length` of a `Differences` array worked seems more like a happy accident for a particular set of font data, but could just as easily be incorrect for other PDF files.

Note that in practice, the case where the `Encoding` entry is a regular `Dict` (and not a `Ref` or `Name`) is very rare, hence I don't think that we really need to worry about having to reparse this data.
Also, the performance of this code-block is quite a bit better by updating the `hash` with the data from the *entire* `Differences` array, instead of at every loop iteration.
2016-12-28 21:32:54 +01:00
Tim van der Meij
22f0a04df0 Merge pull request #7829 from Snuffleupagus/finishPaintTask-promise
Let `finishPaintTask` in pdf_page_view.js return a promise instead, to avoid having to throw in the `paintTask.promise` rejection handler, and don't reject the `PDFPageView_draw` promise when rendering is `cancelled`
2016-12-27 23:51:06 +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
Jonas Jenwald
33063a486e Update l10n files 2016-12-19 11:10:14 +01:00
Jonas Jenwald
73e0daed6c Let finishPaintTask in pdf_page_view.js return a promise instead, to avoid having to throw in the paintTask.promise rejection handler, and don't reject the PDFPageView_draw promise when rendering is cancelled
As mentioned on IRC yesterday, we currently throw even when rendering is `cancelled`, which is annoying when the devtools are active. Furthermore, since `cancelled` isn't really an error, rejecting the `PDFPageView_draw` promise seems somewhat strange in that case.
2016-12-17 22:29:48 +01:00
Tim van der Meij
017e9b98d1 Merge pull request #7898 from timvandermeij/acroforms-checkbox-radiobutton
Interactive forms: render button widget annotations (checkboxes and radio buttons)
2016-12-17 21:22:15 +01:00
Tim van der Meij
a428899b3c Button widget annotations: improve unit tests, simplify code and remove labels
Modern browsers support styling radio buttons and checkboxes with CSS.
This makes the implementation much easier, and the fallback for older
browsers is still decent.
2016-12-17 20:38:48 +01:00
Tim van der Meij
77148c7880 Button widget annotations: implement radio button value fetching according to the specification 2016-12-17 20:34:32 +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
Tim van der Meij
d0893b0c48 Merge pull request #7900 from Snuffleupagus/choiceWidget-Opt-indirect-objects
Ensure that we handle indirect objects in all types of `Opt` entries in `ChoiceWidget` annotation dictionaries
2016-12-17 20:29:43 +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
Tim van der Meij
a719b71e59 Merge pull request #7897 from Snuffleupagus/eslint-switch
Switch to using ESLint, instead of JSHint, for linting
2016-12-16 22:40:41 +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
b629be05bd Merge pull request #7886 from Snuffleupagus/viewer-async-initialization
Move the `Preferences` initialization/fetching code to the top of `PDFViewerApplication.initialize`, to enable using them when initializing e.g. the viewer components
2016-12-14 17:30:40 +01:00
Jonas Jenwald
a96b0f80dd Convert the only remaining consumer (in hand_tool.js) of the 'localized' event to use the localized Promise instead, and only re-dispatch the 'localized' event on the eventBus for GENERIC builds
Ideally we'd remove the 'localized' event from the `eventBus`, but for backwards compatibility we keep it in `GENERIC` builds.
Note that while we want to ensure that the direction attribute of the HTML is updated as soon as the `localized` Promise is resolved, we purposely wait until the viewer has been initialized to ensure that the 'localized' event will always be dispatched.
2016-12-14 16:19:10 +01:00
Jonas Jenwald
648024f5d0 Don't call bindEvents() until PDFViewerApplication has been initialized, and move binding of window event listeners to a helper method, to prevent errors if an event manages to arrive too soon
With `bindEvents()` now being called after the viewer has been initialized, we no longer need to have `PDFViewerApplication.initialized` checks in the event handler functions.
Furthermore by moving the `window.addEventListener`s to a helper method, `PDFViewerApplication.initialized` checks are no longer necessary in the event handlers, hence we thus address part of issue 7797 here as well.
2016-12-14 16:17:10 +01:00
Jonas Jenwald
849f5dde9d Move the Preferences initialization/fetching code to the top of PDFViewerApplication.initialize, to enable using them when initializing e.g. the viewer components
Note that in quick testing using `console.time/timeEnd`, both locally and with the Firefox addon, the total run time of the *entire* `PDFViewerApplication.initialize` function does not seem to change with this patch.
2016-12-14 16:15:53 +01:00
Jonas Jenwald
2c1436f6cb Refactor PDFViewerApplication.initialize into two methods, one that reads the Preferences and one that initializes the various viewer components 2016-12-14 16:13:20 +01:00
Tim van der Meij
7d8fa1385d Merge pull request #7890 from Snuffleupagus/pre-eslint-fixes
Fix a number of code style issues found by various ESLint rules, to make it easier to switch from JSHint to ESLint
2016-12-14 01:16:24 +01:00
Jonas Jenwald
28e50cfa21 Fix errors reported by the space-infix-ops ESLint rule
http://eslint.org/docs/rules/space-infix-ops
2016-12-12 20:36:00 +01:00
Jonas Jenwald
68bf47d55d Fix errors reported by the space-before-function-paren ESLint rule
http://eslint.org/docs/rules/space-before-function-paren
2016-12-12 20:35:59 +01:00
Jonas Jenwald
551eb263e3 Fix errors reported by the semi-spacing ESLint rule
http://eslint.org/docs/rules/semi-spacing
2016-12-12 20:35:58 +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
86ba634c97 Fix errors reported by the key-spacing ESLint rule
http://eslint.org/docs/rules/key-spacing
2016-12-12 20:35:55 +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
66d2637b3f Fix errors reported by the yoda ESLint rule
http://eslint.org/docs/rules/yoda
2016-12-12 20:35:52 +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
328e7397ea Fix errors reported by the no-extra-bind ESLint rule
http://eslint.org/docs/rules/no-extra-bind
2016-12-12 20:35:50 +01:00
Jonas Jenwald
25bf5db47e Fix errors reported by the no-extra-boolean-cast ESLint rule
http://eslint.org/docs/rules/no-extra-boolean-cast
2016-12-12 20:26:18 +01:00
Jonas Jenwald
fb5e756683 Fix errors reported by the no-cond-assign ESLint rule
http://eslint.org/docs/rules/no-cond-assign
2016-12-12 20:26:06 +01:00
Tim van der Meij
00a006e466 Merge pull request #7705 from Snuffleupagus/issue-2594
Move symbolic font glyphs to private use area if they don't have unicode mappings (issue 2594, bug 789074, bug 865644)
2016-12-10 21:30:28 +01:00
Tim van der Meij
47f03b619f Merge pull request #7873 from timvandermeij/mediabox-cropbox-indirect
Document: handle indirect objects in `MediaBox` and `CropBox` entries
2016-12-08 23:59:45 +01:00
Tim van der Meij
3800b5e463 Document: extract CropBox fetching and validation into a getter
This patch refactors the `CropBox` code to combine fetching and
validation code in a getter, like we already did for the `MediaBox`
property. Combined with variable name changes, this improves readability
of the code and makes the `view` getter simpler as well.
2016-12-08 22:44:53 +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
Tim van der Meij
407dee390a Merge pull request #7884 from Snuffleupagus/Parser-fetch-indirect-objects-in-filter-arrays
Ensure that we resolve indirect objects in `Filter` and `DecodeParms` arrays in `parser.js`
2016-12-08 21:59:34 +01:00
Jonas Jenwald
b4ac6bd2f6 Ensure that we resolve indirect objects in Filter and DecodeParms arrays in parser.js
I've not actually, thus far, come across a PDF file that this patch fixes. However, given the string of recent patches that has fixed issues with indirect objects in arrays, I think that it makes sense to proactively avoid any issues in this code.
2016-12-08 11:55:08 +01:00
Tim van der Meij
aaec490847 Merge pull request #7881 from Snuffleupagus/fixMetadata-constant-condition
Remove a misplaced `false` from a condition in `fixMetadata`, in `metadata.js`, since it currently short circuits the entire condition
2016-12-08 00:29:42 +01:00
Jonas Jenwald
77bcc9232e Remove a misplaced false from a condition in fixMetadata, in metadata.js, since it currently short circuits the entire condition
This looks to me like a simple oversight, which has existed ever since PR 1598 all the way back in 2012.
2016-12-07 22:51:46 +01:00
Jonas Jenwald
94ddd8f61d Merge pull request #7863 from timvandermeij/colorspace
Colorspace: refactoring to prevent unnecessary creation of intermediate arrays
2016-12-06 11:18:53 +01:00
Jonas Jenwald
caf81685cb Update l10n files 2016-12-05 10:10:17 +01:00
Tim van der Meij
fa6b9b7552 Merge pull request #7868 from Snuffleupagus/pageLabels-St-unit-test
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)
2016-12-04 20:45:52 +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
90d94815ad Colorspace: miscellaneous improvements
- Remove an unnecessary check and assignment.
- Clean up code regarding mode setting (no need for a member variable).
- Indent two methods correctly.
2016-12-02 16:47:39 +01:00
Tim van der Meij
c5c0a00dca Colorspace: reduce duplication in AlternateCS.getRgbBuffer 2016-12-02 16:42:22 +01:00
Tim van der Meij
ef653d952b Colorspace: optimize default color initialization
This patch avoids the creation of extra arrays when initializing an
array with default (zero) values. Doing this additionally makes the code
more readable by allocating enough space for the number of color
components.
2016-12-02 16:42: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
Jonas Jenwald
48ab6463df Merge pull request #7862 from yurydelendik/issue7861
Don't fail if mozL10n is not present.
2016-12-01 16:06:29 +01:00
Yury Delendik
7b6ba5e9fd Don't fail if mozL10n is not present. 2016-12-01 08:48:07 -06:00
Javier Infante
54fab606ee add basic unit-tests for murmurhash3.js 2016-12-01 02:21:05 +01:00
Tim van der Meij
8e8af62faf Merge pull request #7856 from Snuffleupagus/issue-7855
Ensure that `PartialEvaluator_extractWidths` is able to handle indirect objects in all kinds of "width" data (issue 7855)
2016-11-30 22:54:56 +01:00
Tim van der Meij
fb4c4ffb97 Merge pull request #7858 from Snuffleupagus/issue-7852
Make the keyboard shortcuts `Ctrl + Up/Down` behave as `Home/End` (issue 7852)
2016-11-30 22:20:28 +01:00
Jonas Jenwald
48696a8d06 Make the keyboard shortcuts Ctrl + Up/Down behave as Home/End (issue 7852)
It seems that for normal web pages, at least in Firefox, the keyboard shortcuts <kbd>Ctrl</kbd> + <kbd>Up</kbd>/<kbd>Down</kbd> are functionally equivalent to <kbd>Home</kbd>/<kbd>End</kbd>. This is obviously an edge-case, but can be easily implemented by using the same logic as we do for <kbd>Home</kbd>/<kbd>End</kbd>.

Fixes 7852.

*Please note:* I'm finding it slightly difficult to interpret issue 7852, and bug 1285719, since among other things: the title includes the word "reverse" with no other mention of it, and the STR makes reference to print preview which doesn't seem applicable to the PDF viewer.
However, compared to regular web pages in Firefox, I think the behavior of this patch makes sense here.
2016-11-30 17:42:52 +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
Jonas Jenwald
362d20b23a Update l10n files 2016-11-28 10:30:05 +01:00
Tim van der Meij
e6720ad558 Merge pull request #7853 from Snuffleupagus/jsdoc-parseDestDictionary
Fix the JSDoc comment for `Catalog.parseDestDictionary`
2016-11-27 16:21:03 +01:00
Jonas Jenwald
c6008b4d7c Fix the JSDoc comment for Catalog.parseDestDictionary 2016-11-27 11:18:18 +01:00
Tim van der Meij
ce416eb26e Merge pull request #7849 from timvandermeij/css-cleanup
Viewer: remove unused CSS rule
2016-11-24 23:51:27 +01:00
Tim van der Meij
14d7e2f29c Viewer: remove unused CSS rule
This appears to have been part of the first mock-up of the viewer, but
hasn't been used since.
2016-11-24 23:44:57 +01:00
Tim van der Meij
424fc2df4f Merge pull request #7846 from timvandermeij/bidi-types
Bidi: import Unicode types from the specification
2016-11-24 22:59:31 +01:00
Tim van der Meij
995be19378 Bidi: skip invalid Unicode character to make indexing work
For Arabic characters, the Unicode character codes are mapped to Unicode
character types using the character codes for indexing. However, the
character code 0x061D is undefined (and therefore invalid) in the
Unicode standard. The imported list does not contain this entry, but not
having it in the list breaks indexing for items after it. Therefore, put
an empty string on its position to make indexing work properly and issue
a warning in the unlikely event that we encounter this character.
2016-11-24 22:13:12 +01:00
Tim van der Meij
11839f018f Bidi: import Unicode types from the specification
Mention the specification in the comments for future reference. These
types have been imported from the CSV source.
2016-11-24 21:08:31 +01:00
Tim van der Meij
7c96da4373 Merge pull request #7845 from timvandermeij/dist-min
Make: include minified library files for the distribution target
2016-11-23 21:23:44 +01:00
Adhika Setya Pramudita
906b8ea907 Make: include minified library files for the distribution target
Fixes #5487.
2016-11-23 17:35:19 +01:00
Jonas Jenwald
ef7fd75a94 Merge pull request #7841 from timvandermeij/ios-range
Compatibility: disable range requests for iOS and refactor user agent detection
2016-11-22 22:53:36 +01:00
Tim van der Meij
cf3a7425b6 Compatibility: refactor user agent detection
This patch moves the user agent checks to the top of the file to reduce
duplication and to provide a clear overview of which user agent we are
detecting.

Moreover, we extract inline user agent checks as well and use existing
checks in more places. Finally, we fix the indenting in one place for
consistency.
2016-11-22 22:42:01 +01:00
Tim van der Meij
0b0e18f05c Compatibility: disable range request for iOS
Fixes #7815.
2016-11-22 22:19:20 +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
Jonas Jenwald
9d8fb02512 Merge pull request #7839 from Snuffleupagus/issue-7835
Correctly detect more cases of non-embedded Arial Black fonts (issue 7835)
2016-11-22 17:37:44 +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
Tim van der Meij
787d887a2f Merge pull request #7793 from Snuffleupagus/ViewHistory-storage-key-name
Rename the `ViewHistory` localStorage (and sessionStorage) key from `database` to `pdfjs.history`, and migrate existing data on read (issue 7760)
2016-11-21 21:16:44 +01:00
Jonas Jenwald
0af42f1ca7 Rename the ViewHistory localStorage (and sessionStorage) key from database to pdfjs.history, and migrate existing data on read (issue 7760)
For consistency, I also renamed the `FIREFOX/MOZCENTRAL` sessionStorage key, but given that sessionStorage is a lot less permanent than localStorage it didn't seem necessary to migrate any existing values.

Fixes 7760.
2016-11-21 21:03:37 +01:00
Jonas Jenwald
8a1ed8ab1f Update l10n files 2016-11-21 17:23:22 +01:00
Tim van der Meij
99b5416ba0 Merge pull request #7830 from Snuffleupagus/paintOnSvg-unsupported
Return a mock object in `paintOnSvg` when SVG rendering is not supported, to prevent `TypeError`s in the addons
2016-11-21 17:09:20 +01:00
Jonas Jenwald
9872660a95 Return a mock object in paintOnSvg when SVG rendering is not supported, to prevent TypeErrors in the addons
Currently if you try to enable SVG rendering in the addons, a `TypeError` is thrown by the browser since we have code that depends on what `paintOnCanvas`/`paintOnSvg` (should) return.
2016-11-19 13:32:17 +01:00
Yury Delendik
9c3419de94 Merge pull request #7826 from Snuffleupagus/PDFPageView_paintOnSvg-FIREFOX-prevent-unreachable-code-after-return-statement-warning
Prevent "unreachable code after return statement" warnings from `PDFPageView_paintOnSvg` in the addons
2016-11-18 14:20:47 -06:00
Jonas Jenwald
7272bb4894 Prevent "unreachable code after return statement" warnings from PDFPageView_paintOnSvg in the addons
Follow-up to PR 7738.
2016-11-18 21:18:27 +01:00
Tim van der Meij
eaf9bff4e4 Merge pull request #7738 from yurydelendik/svg-page
Adds SVG rendering capabilities to the main viewer.
2016-11-18 20:10:12 +01:00
Yury Delendik
f7d6f3a739 Adds SVG rendering capabilities to the PDFViewer. 2016-11-18 13:03:49 -06:00
Yury Delendik
c9a0955c9c Refactors PDFPageView_draw. 2016-11-18 12:57:11 -06:00
Yury Delendik
f6a8d9c4dd Merge pull request #7789 from yurydelendik/toolbar
Refactor toolbar.
2016-11-18 12:53:51 -06:00
Yury Delendik
a4402c84de Refactor toolbar (and secondary toolbar). 2016-11-18 12:51:15 -06:00
Tim van der Meij
043cea251d Merge pull request #7819 from Snuffleupagus/issue-7804
For commands with with too few arguments, clear out `args` if it's an Array instead of replacing it with `null` in `EvaluatorPreprocessor_read` (issue 7804)
2016-11-18 19:04:30 +01:00
Jonas Jenwald
7f678e3af1 Update l10n files 2016-11-17 12:03:31 +01:00
Jonas Jenwald
a930f9af15 For commands with with too few arguments, clear out args if it's an Array instead of replacing it with null in EvaluatorPreprocessor_read (issue 7804)
For `PartialEvaluator_getTextContent`, the same `args` Array should be re-used for every `EvaluatorPreprocessor_read` call. Hence we want to ensure that it's not accidentally replaced with `null` in `EvaluatorPreprocessor_read`, since otherwise corrupt PDF files (with too few arguments for certain commands) will cause errors in `PartialEvaluator_getTextContent`.

Perhaps a micro-optimization, but this patch also changes two `!args` comparisons to `args === null`, since that should be a tiny bit more efficient.
2016-11-16 10:20:29 +01:00
Jonas Jenwald
7f6a607ea5 Merge pull request #7803 from mukulmishra18/master
Fix #7701: additional check for http/https protocols to fix unsafe he…
2016-11-14 13:04:25 +01:00
Mukul Mishra
6ce2be98b7 Fix #7701: additional check for http/https protocols to fix unsafe header request.
add missing ! and removed trailing whitespaces.
2016-11-14 11:39:10 +05:30
Jonas Jenwald
7ec8adc712 Merge pull request #7801 from Snuffleupagus/preprocessor2-remove-comment-except-copyright
Enable removing of all comments (except for Copyright notices) when preprocessing code, and reduce the indentation level
2016-11-11 22:22:30 +01:00
Jonas Jenwald
4f1cccb138 Enable removing of all comments (except for Copyright notices) when preprocessing code, and reduce the indentation level 2016-11-11 22:05:17 +01:00
Jonas Jenwald
a139c75774 Merge pull request #7800 from Snuffleupagus/compatibility-Safari-regex
Replace the Safari detection in `checkRangeRequests` in compatibility.js with a regular expression
2016-11-11 17:57:29 +01:00
Jonas Jenwald
db2ce3ff64 Replace the Safari detection in checkRangeRequests in compatibility.js with a regular expression
According to e.g. issue 7754, it appears that the current `isSafari` check is failing in newer version of the browser. Despite the fact that checking the userAgent is an anti-pattern, which should be avoided, it's currently the simplest solution.
2016-11-11 17:15:24 +01:00
Jonas Jenwald
c23f124051 Merge pull request #7794 from Snuffleupagus/JavaScript-white-listed-actions
[api-minor] Add support for a couple of white-listed `JavaScript` actions that contains valid URLs (issue 3897, bug 843699)
2016-11-09 10:29:05 +01:00
Tim van der Meij
2f5170f28f Merge pull request #7792 from Snuffleupagus/bug-1315608
Make the `customScaleOption` disabled to prevent it being keyboard accessible (bug 1315608)
2016-11-08 21:55:51 +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
a97bc16fbc Make the customScaleOption disabled to prevent it being keyboard accessible (bug 1315608)
Given that the `customScaleOption` should already be hidden, provided that the browser supports that, this patch also prevents it from being accessible via the keyboard.
As far as my testing goes in various browsers, this doesn't seem to have any ill effects, and note that we're already explicitly ignoring the `custom` value in the `select` event handler.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1315608.
2016-11-08 12:04:55 +01:00
Jonas Jenwald
340c6638c5 Merge pull request #7781 from timvandermeij/viewer-responsiveness
Viewer: improve responsiveness and clean up CSS
2016-11-07 17:38:23 +01:00
Tim van der Meij
f95915fc73 Viewer: amend .sidebarOpen responsiveness rules with rules for
`.sidebarMoving`
2016-11-07 16:23:50 +01:00
Tim van der Meij
b428463ecc Merge pull request #7786 from SuriyaaKudoIsc/patch-3
Add HTTPS support for Demo
2016-11-05 15:45:08 +01:00
Suriyaa Kudo
1446e0e64f Add HTTPS support 2016-11-04 15:55:56 +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
Tim van der Meij
28ef012727 Viewer: improve responsiveness and clean up CSS
This patch resolves the responsiveness issues for the toolbar in the
viewer. Depending on the language (for example the Dutch language),
elements could overlap when the viewport size is reduced.

The main issue here is that the CSS rules are unnecessarily complex and
handle lots of different cases (LTR/RTL, displacements for specific
viewport widths, et cetera). By removing this complexity and letting the
browser handle the responsiveness, we not only get simpler CSS rules and
HTML mark-up, but the responsiveness issues are mostly fixed at the same
time. We no longer have to position the elements manually (by setting
their `left` attribute value) anymore.
2016-11-03 22:56:46 +01:00
Tim van der Meij
1d82521b4c Merge pull request #7782 from Snuffleupagus/page-labels-more-validation
Use `stringToPDFString` to sanitizing bad "Prefix" entries in Page Label dictionaries, and add more validation
2016-11-03 22:16:39 +01:00
Tim van der Meij
fe3c12bd16 Merge pull request #7778 from srslafazan/defensive-check-for-mousewheel-handler
Additional check to ensure pdfViewer object is defined before handleMouseWheel event accesses its property isInPresentationMode
2016-11-03 22:03:44 +01:00
Shain Lafazan
7fec8de502 Additional check to ensure pdfViewer object is defined before handleMouseWheel event accesses its property isInPresentationMode 2016-11-03 12:25:16 -07:00
Jonas Jenwald
0844a72b4d Add a bit more validation to Catalog_readPageLabels, to ensure that the Page Labels are well formed 2016-11-03 20:08:06 +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
Jonas Jenwald
9295114bdd Merge pull request #7774 from timvandermeij/lint
Improve lint coverage and correct code style violations
2016-11-01 16:53:51 +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
Tim van der Meij
978b214c92 Lint: do not ignore external/importL10n as it is one of our components 2016-11-01 14:43:38 +01:00
Tim van der Meij
c719762099 Lint: update .jshintignore
Remove folders that no longer exist and ignore folders with binary/PDF
files.
2016-11-01 14:39:35 +01:00
Tim van der Meij
29fc2f9908 Merge pull request #7773 from Snuffleupagus/update-swedish-l10n
[l10n] Add Swedish translations for a couple of new/changed localization IDs
2016-11-01 13:32:41 +01:00
Jonas Jenwald
40d2d3f569 [l10n] Add Swedish translations for a couple of new/changed localization IDs
I got tired of staring at a bunch of localization warnings every time that I open the console, hence this patch adds the missing translations to the Swedish locale.
2016-11-01 10:09:47 +01:00
Tim van der Meij
c8158dc672 Merge pull request #7771 from timvandermeij/l10n-updates
Localization updates
2016-10-31 23:44:55 +01:00
Tim van der Meij
775b294bb9 L10n: import upstream translations 2016-10-31 23:35:05 +01:00
Tim van der Meij
f8e29ad80f L10n: update the Dutch translation after recent string changes 2016-10-31 23:31:14 +01:00
Jonas Jenwald
077e644437 Fix a typo in the page_of_pages l10n ID for the en-US locale 2016-10-31 23:14:22 +01:00
Tim van der Meij
e9c63a2b32 Merge pull request #6945 from Snuffleupagus/page-labels-viewer
Add support for PageLabels in the viewer (issue 6902, bug 793632)
2016-10-31 22:59:56 +01:00
Yury Delendik
a740d69457 Merge pull request #7766 from Rob--W/printing-refactor-split-from-7721
Printing refactor split from 7721
2016-10-31 08:51:49 -05:00
Rob Wu
594592216c Refactor printing: startPrint -> performPrint
- Renamed startPrint to performPrint to emphasize that the method
  does not start the print process (preparing pages for the printer),
  but that it does the actual printing (sending pages off to the
  printer).

- Put performPrint in the PDFPrintService, so that it can be
  overridden if needed.
2016-10-30 12:03:24 +01:00
Rob Wu
d3b13e36d3 Refactor page printing logic on the web
- Move the global scratchCanvas to PDFPrintService. This is mainly to
  make it easier to reason about the state of scratchCanvas. In practice
  there is no difference because only one PDFPrintService instance can
  be instantiated at any given time.

- Move all logic of using the rendered page to one location.
  This makes it easier to replace the printing logic later, when I add
  special handling to out-of-process frames in the Chrome extension.
2016-10-30 12:03:24 +01:00
Rob Wu
0c21ebf9f3 Close overlay if print service was not initialized
Fixes #7720
2016-10-30 12:03:24 +01:00
Rob Wu
1c869906c8 Strictly manage lifetime of PDFPrintService
Make sure that the print service is stopped as soon as possible when
aborted, and that it is not possible for a (slow) promise to
accidentally wipe the state of a print job that was started later.
2016-10-30 12:03:24 +01:00
Tim van der Meij
1c3fb175dd Merge pull request #7757 from Snuffleupagus/setHash-remove-pageNumber-directly-after-hash
Remove/deprecate specifying a pageNumber directly after the hash symbol (#), to improve compatibility since other PDF viewers don't support this form (issue 7746)
2016-10-27 23:56:23 +02:00
Jonas Jenwald
87c2ff5483 Remove/deprecate specifying a pageNumber directly after the hash symbol (#), to improve compatibility since other PDF viewers don't support this form (issue 7746)
There's no mention of our `#{pagenum}` form in http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf, and Adobe Reader doesn't seem to support it either.
Hence this patch removes support for it in the extensions, but keeps it in the `GENERIC` build with a deprecation warning and a fallback to handle it as a destination.

Fixes 7746.
2016-10-27 23:25:53 +02:00
Yury Delendik
ab464df336 Import L10n files. 2016-10-27 16:16:27 -05:00
Tim van der Meij
abc417cee9 Merge pull request #7750 from Snuffleupagus/PDFLinkService_navigateTo-more-validation
Add more validation to `PDFLinkService_navigateTo`
2016-10-27 22:16:35 +02:00
Tim van der Meij
a28a71072d Merge pull request #7756 from timvandermeij/npm
Travis CI: use most recent version of NPM
2016-10-27 21:19:03 +02:00
Tim van der Meij
7c78b2f6c0 Travis CI: use most recent version of NPM 2016-10-27 21:10:19 +02:00
Tim van der Meij
e94c2945af Merge pull request #7749 from Snuffleupagus/PDFLinkService_setHash-dest-fallback
Avoid accidentally rejecting a named destination that looks like a decimal number or a boolean (PR 7341 follow-up)
2016-10-27 16:14:28 +02:00
Jonas Jenwald
81b9d553cf Add TeX-specific glyph names to glyphlist.js to improve both glyph mapping and text selection for mathematic fonts (issue 2594) 2016-10-26 16:39:58 +02:00
Brendan Dahl
8d036faf40 Move symbolic font glyphs to private use area if they don't have unicode mappings. 2016-10-26 16:39:21 +02:00
Jonas Jenwald
efb9619e53 Add PageLabels to PDFPageView and PDFThumbnailView 2016-10-26 13:30:37 +02:00
Jonas Jenwald
f461fd64aa Add support for PageLabels in the viewer
This patch implements the page label functionality in a similar way as Adobe Reader.
For documents with page labels, if a non-existent page label is entered we'll try to fallback to the page number instead.
The patch also includes a preference (`disablePageLabels`), to make it easy to opt-out of using page labels if the user/implementor so wishes.

The way that `get/set currentPageLabel` is implemented in `PDFViewer`, is as wrappers for the corresponding `get/set currentPageNumber` functions, since that seemed like the cleanest solution.
The page labels are purposely *only* added to the page controls in the viewer UI, and not stored in e.g. the `ViewHistory`. Since doing so would mean adding unnecessary code complexity, without any real added value, and would also mean delaying the inital loading of PDF documents.

Note that this patch will ignore page labels if they are identical to standard page numbering, since in this case displaying the page labels adds no value (but only UI noise). The reason for handling this case specially, is that in practice a surprising number of PDF files include "pointless" page labels.
2016-10-26 13:30:36 +02:00
Jonas Jenwald
23ec02bb93 Remove the "Page: " label and replace it with a tooltip
The following reasoning was used for deciding to remove the "Page: " label, and replace it with a tooltip, from the main toolbar:
 - We have no other visible labels in the *main* toolbar (e.g. the Zoom dropdown doesn't have a label, but only a tooltip).
 - We already hide the "Page: " label when the viewer is narrow.
 - The varying width of the "Page: " label in different locales is already causing issues for many languages, with overlap in the main toolbar as a result.
Trying to create responsive CSS styles that works well in all locales is already difficult, and if we add support for page labels that will only further compound the issues.
 - Some PDF viewers (e.g. Adobe Reader, pdfium in Chrome) doesn't show labels in the UI by default.
2016-10-26 13:30:26 +02:00
Jonas Jenwald
e1412de320 Add more validation to PDFLinkService_navigateTo
In some PDF files, the first element (i.e. the one containing either a `Ref` or a `Number` pointing to a page) of the explicit destination Array may be bogus.

One such example is actually the file `pdf.pdf` in the test-suite, where some destinations are incompletely specified. One such example being the `G1.998360` destination whose explicit destination Array contains `[null, /XYZ, 54, 488, null]`, i.e. the destination page is `null`.
Hence this patch adds a bit more validation for that case. It also adds an additional check to ensure that the resulting `pageNumber` is non-negative, and finally a couple more error messages for existing cases of malformed data.
2016-10-24 10:22:45 +02:00
Jonas Jenwald
d5e3b2fbf0 Update PDFOutlineViewer_bindLink to look more like LinkAnnotationElement_bindLink 2016-10-23 16:08:26 +02:00
Jonas Jenwald
47a1c7797e Update l10n files 2016-10-23 12:19:00 +02:00
Jonas Jenwald
901a2d41be Avoid accidentally rejecting a named destination that looks like a decimal number or a boolean (PR 7341 follow-up)
Without this patch, the following link does not work correctly: http://unesdoc.unesco.org/images/0013/001346/134685E.pdf#4.3
Compare the correct behaviour of this link: http://unesdoc.unesco.org/images/0013/001346/134685E.pdf#nameddest=4.3
2016-10-23 11:55:27 +02: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
7e392c0205 Merge pull request #7689 from Snuffleupagus/relative-URLs
[api-minor] Add support for relative URLs, in both annotations and the outline, by adding a `docBaseUrl` parameter to `PDFJS.getDocument` (bug 766086)
2016-10-19 22:51:09 +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
71a781ee5c Deprecate the isValidUrl utility function and replace it with createValidAbsoluteUrl/isValidProtocal functions instead, since the main URL validation is now done using the new URL constructor 2016-10-19 22:11:22 +02:00
Jonas Jenwald
42f07c6262 [api-minor] Use the new URL constructor when validating URLs in annotations and the outline, as a complement to only checking the protocol, and add a bit more validation to Catalog_parseDestDictionary
Note that this will automatically reject any relative URL.
To make the API more useful to consumers, URLs that are rejected will be available via the `unsafeUrl` property in the data object returned by `PDFPageProxy_getAnnotations`.

The patch also adds a bit more validation of the data for `Named` actions.
2016-10-19 22:11:17 +02:00
Jonas Jenwald
e64bc1fd13 Move parsing of destination dictionaries to a helper function
This not only reduces code duplication, but it also allow us to easily support the same kind of URLs we currently do for Link annotations in the Outline as well.
2016-10-18 16:14:07 +02:00
Tim van der Meij
6906623462 Merge pull request #7717 from jeenuv/display-double-click-tooltip
Explain double-click behaviour on tool tip
2016-10-18 13:52:31 +02:00
Tim van der Meij
1783f14511 Merge pull request #7732 from yurydelendik/svg-cgrp
Removes SVG this.cgrp usages.
2016-10-18 00:57:52 +02:00
Yury Delendik
1236b27993 Removes SVG this.cgrp usages. 2016-10-17 16:09:24 -05:00
Yury Delendik
273d2de6ec Merge pull request #7715 from timvandermeij/svg-groups
SVG: optimize and refactor group creation code
2016-10-17 10:10:47 -05:00
Tim van der Meij
960e344a8a Merge pull request #7730 from Snuffleupagus/jsdoc-typedef-property
Fix a couple of JSDoc `@typedef`s to use `@property` (instead of `@param`) to fix some missing documentation when running `gulp jsdoc`
2016-10-17 16:38:13 +02:00
Yury Delendik
1369997bbf Properly invoke 'gulp' in make.js and fail when it fails. 2016-10-17 08:47:05 -05:00
Yury Delendik
85db146525 Run 'firefox' and 'chromium' task in-sequences 2016-10-17 08:05:16 -05:00
Jonas Jenwald
2ce9da9b7a Fix a couple of JSDoc @typedefs to use @property (instead of @param) to fix some missing documentation when running gulp jsdoc 2016-10-17 13:04:55 +02:00
Jonas Jenwald
6678da379b Merge pull request #7728 from timvandermeij/gulp-port
Gulp: port the `all`, `extension` and `jsdoc` targets
2016-10-17 12:49:47 +02:00
Tim van der Meij
224e3a42a2 Gulp: port the all, extension and jsdoc targets
This requires the `run-sequence` dependency because Gulp does not have a
way to run sequences of tasks inside a Gulp task. Gulp 4.0 will have
support for this, but until that is released this is the recommended way
to implement it.
2016-10-16 22:17:25 +02:00
Jeenu Viswambharan
f2dcacd164 Explain double-click behaviour on tool tip
The outline toggle button has a feature where it can be double-clicked
to expand/collapse all items shown therein. Although this is described
in the FAQ, can go potentially unnoticed. This, however, being a useful
feature, advertise on the tool tip itself.

l10n translation for en-US and IDs updated.

Signed-off-by: Jeenu Viswambharan <jeenuv@gmail.com>
2016-10-16 09:22:48 +01:00
Tim van der Meij
426fc454de SVG: factor out initialization code into a private method
Each well-formed SVG image has the following structure:

SVG element
- Definitions element
- Root group
  - Other group 1
  - ...
  - Other group n

This patch factors out initialization code into a private method in such
as way that the creation of this structure is clear from the code. The
root group is the replacement for the parent group from before. We need
this group as we cannot apply the viewport transform on the SVG element
itself (this caused issues in Chrome). If other code appends groups to
the SVG image, in reality it is appending those groups to the root
group, but this detail is abstracted away by this patch.
2016-10-15 21:45:44 +02:00
Tim van der Meij
fa90573c4b SVG: optimize transform group creation
This patch ensures that we only create transformation groups when it is
actually required and that we re-use transform groups as much as possible.
It reduces the number of transform groups for the Tracemonkey paper from
2790 to 1271, thereby making the DOM much lighter and rendering/scrolling
smoother. Moreover, it simplifies the code and prevents duplication.

Finally, we issue a warning when an unimplemented graphic state is
encountered. Before, this was ignored silently, making debugging harder.
2016-10-15 21:43:12 +02:00
Tim van der Meij
de6c92a96d Examples: improve SVG viewer
This patch:

- resolves a warning in the console about missing character encoding;
- makes the viewer use the same background color and PDF file as the
  regular viewer;
- simplifies the example to bring it more in line with the other
  examples.
2016-10-15 21:08:24 +02:00
Tim van der Meij
2e20000b71 Merge pull request #7727 from Snuffleupagus/parser-stream-decodeParms
Let `Parser_makeFilter` pass in the `DecodeParms` data to various image `Stream`s, instead of re-fetching it in various `[...]Stream.prototype.ensureBuffer` methods
2016-10-15 20:04:17 +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
Jonas Jenwald
f209030b99 Merge pull request #7726 from Snuffleupagus/remove-remaining-preprocessor-statement-core-fonts
Remove a remaining old-style preprocessor from `src/core/fonts.js` (PR 7322 follow-up)
2016-10-15 13:46:23 +02:00
Jonas Jenwald
c8f83d6487 Let Parser_makeFilter pass in the DecodeParms data to various image Streams, instead of re-fetching it in various [...]Stream.prototype.ensureBuffer methods
In `Parser_filter` the `DecodeParms` data is fetched and passed to `Parser_makeFilter`, where we also make sure that a `Ref` is resolved to a direct object.
We can thus pass this along to the various image `Stream` constructors, to avoid the current situation where we lookup/resolve data that is already available.
Note also that we currently do *not* handle the case where `DecodeParms` is an Array entirely correct in the various image `Stream`s, and this patch fixes that for free.
2016-10-15 12:09:51 +02:00
Jonas Jenwald
1da59bec9b Remove a remaining old-style preprocessor from src/core/fonts.js (PR 7322 follow-up)
Note that this code was added *after* PR 7322 was opened, which thus explains why it was missed during rebasing.
2016-10-15 11:33:09 +02:00
Jonas Jenwald
c1a34ffbcd Merge pull request #7322 from yurydelendik/preproc2
Remove JS preprocessor code from the web/ and src/ files
2016-10-14 23:35:17 +02:00
Yury Delendik
0576c9c6c6 Replaces all preprocessor directives with PDFJSDev calls. 2016-10-14 10:57:53 -05:00
Yury Delendik
bf52ff156d Adds esprima-based preprocessor. 2016-10-14 08:33:22 -05:00
Jonas Jenwald
bc3bcebde2 Merge pull request #7722 from Rob--W/grab-to-pan-cssom-and-cleanup
Update to latest grab-to-pan version
2016-10-14 09:58:24 +02:00
Rob Wu
c7c6bf1ae8 Update to latest grab-to-pan version 2016-10-14 00:55:58 +02:00
Tim van der Meij
c457e6015d Merge pull request #7714 from cemerick/fix-non-numeric-TJ
Fix getTextContent evaluation to only apply TJ horizontal offsets using numeric items/args
2016-10-13 16:03:49 +02: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
8c5b925547 Merge pull request #7514 from Snuffleupagus/viewer-abort-rendering-on-close
Ensure that we cancel any pending rendering operations when the viewer is closed (issue 7274)
2016-10-11 23:48:51 +02:00
Jonas Jenwald
885ba83624 Add the number of textDivs to the textlayerrendered event, to avoid having to manually get that information in the event handler 2016-10-11 22:36:02 +02:00
Jonas Jenwald
3904be8889 Ensure that we cancel any pending textLayer rendering operations when the viewer is closed (issue 7274) 2016-10-11 22:01:22 +02:00
Jonas Jenwald
a824c6c4f6 Ensure that any pending rendering operations in PDFViewer/PDFThumbnailViewer are cancelled when the viewer is closed 2016-10-11 22:01:22 +02:00
Tim van der Meij
fb5aa58008 Merge pull request #7697 from yurydelendik/print-v2
Refactoring of printing code and mozPrintCallback polyfill
2016-10-11 21:22:07 +02:00
Yury Delendik
1a056caf88 Localization of the print dialog. 2016-10-11 10:08:13 -05:00
Yury Delendik
c09f634bb6 Removes mozPrintCallback polyfill, converts canvas to PNG. 2016-10-11 10:08:13 -05:00
Jonas Jenwald
d7148735ba Update l10n files 2016-10-09 12:11:53 +02:00
Yury Delendik
24a7a58da7 Moves mozPrintCallback specific code to firefox_printservice.js 2016-10-08 07:33:07 -05:00
Tim van der Meij
f8bd3d4473 Merge pull request #7694 from yurydelendik/print-ff
Disables Font Loading API for Firefox.
2016-10-06 23:17:12 +02:00
Yury Delendik
e336604ef1 Disables Font Loading API for Firefox. 2016-10-06 09:30:18 -05:00
Yury Delendik
e48f388d24 Merge pull request #7677 from yurydelendik/print
Bug 1302069 - Printing canvases at PDF document size.
2016-10-06 08:16:19 -05:00
Yury Delendik
29947b5a57 Printing canvases at PDF document size. 2016-10-06 07:51:45 -05: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
Tim van der Meij
d5d9f362aa Choice widget annotations: core and display layer implementation 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
Yury Delendik
b4a90121f0 Merge pull request #7692 from yurydelendik/v1.6.210
Release of 1.6.210
2016-10-04 12:21:07 -05:00
Yury Delendik
970cf8e891 Release of 1.6.210 2016-10-04 12:19:51 -05:00
Yury Delendik
4ce2356a59 Merge pull request #7691 from yurydelendik/version-1.6
Version 1.6
2016-10-04 12:14:18 -05:00
Yury Delendik
c1539f584a Version 1.6 2016-10-04 12:12:37 -05:00
Yury Delendik
d2a4974785 Merge pull request #7681 from Snuffleupagus/bug-1122280-unit-test
Add a unit-test for annotations where the `URI` action has an incorrect encoding (bug 1122280, PR 5999)
2016-09-30 08:28:23 -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
Tim van der Meij
1564dc311a Merge pull request #7618 from jeremypress/fix-enhanced-double-click
fixing #7590 by delaying div shrink after mouse up
2016-09-28 23:30:35 +02:00
Yury Delendik
869914529d Merge pull request #7656 from Snuffleupagus/issue-4090
Attempt to skip zero bytes at the end of Scan blocks when decoding JPEG images (issue 4090)
2016-09-28 11:43:38 -05:00
Yury Delendik
b4be1e91ab Merge pull request #7653 from staktrace/touch_swipe_presentation_mode
Add support for touch-swiping between pages in presentation mode (bug…
2016-09-28 11:30:37 -05:00
Kartikaya Gupta
ba9e8cb184 Add support for touch-swiping between pages in presentation mode (bug 1300878). 2016-09-28 11:35:25 -04: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
Tim van der Meij
a9a3396f3d Merge pull request #7181 from yurydelendik/mouse-wheel
Simplified wheel processing
2016-09-27 22:50:50 +02:00
Yury Delendik
223a18ccc8 Simplified wheel processing. 2016-09-27 15:27:42 -05:00
Tim van der Meij
7f381c8064 Merge pull request #7661 from Snuffleupagus/bug-956965
Respect the 'ColorTransform' entry in the image dictionary when decoding JPEG images (bug 956965, issue 6574)
2016-09-27 20:22:43 +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
3e77cf6b32 Prevent an infinite loop in XRef_fetchUncompressed for encrypted PDF files with indirect objects in the /Encrypt dictionary (issue 7665) 2016-09-25 00:18:47 +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
Tim van der Meij
7820f58c49 Merge pull request #7647 from Snuffleupagus/Annotation_appendToOperatorList-pass-in-forms
Ensure that `test/driver.js` actually takes the same `Annotation` code-path as the viewer when running `forms` tests (PR 7633 follow-up)
2016-09-21 21:09:44 +02:00
Yury Delendik
431af8cf85 Merge pull request #7652 from Snuffleupagus/resize-event-handler-prevent-error-before-eventBus-initialized
Prevent errors if the 'resize' event is fired before the `eventBus` has been initialized
2016-09-21 08:22:29 -05:00
Jonas Jenwald
1a2f142a14 Prevent errors if the 'resize' event is fired before the eventBus has been initialized
When opening a PDF file that triggers the browser fallback bar in the Firefox addon/built-in version, e.g. http://web.archive.org/web/20110918100215/http://www.irs.gov/pub/irs-pdf/f1040.pdf (with forms *disabled*), and then reloading the document an error can be thrown.
The reason is that displaying the fallback bar triggers 'resize' events, and they can arrive *before* the viewer has had a chance to run all the necessary initialization code.
2016-09-21 13:32:17 +02:00
Jonas Jenwald
5f16cbd2c0 When rendering forms, don't use element.value since it prevents the AnnotationLayer rasterizer (in test/driver.js) from parsing the elements correctly
Without this, the reference test images will have empty fields despite the viewer working as intended.
2016-09-21 12:33:04 +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
Jonas Jenwald
ded01356c7 Pass in the renderInteractiveForms parameter to Annotation_appendToOperatorList, in Page_getOperatorList, instead of to the Annotation constructor (PR 7633 follow-up)
When debugging issue 7643, I noticed that the `forms` tests currently doesn't look like the rendering in the viewer (with `renderInteractiveForms = true` set).
After scratching my head for a little while, I realized that PR 7633 make the implicit assumption that `Page_getOperatorList` (in `core/document.js`) is called *before* fetching the annotation with `PDFPageProxy_getAnnotations` (in `display/api.js`).

Hence this patch, that changes it so that we instead pass in the `renderInteractiveForms` parameter to `Annotation_appendToOperatorList` to ensure that it's always correctly set.
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
9e927ded93 Update l10n files 2016-09-20 12:51:52 +02:00
Tim van der Meij
c0e82dbc38 Merge pull request #7642 from Rob--W/crx-type-from-content-disposition-header
Deduct file type from content-disposition if needed
2016-09-19 01:20:58 +02:00
Tim van der Meij
ab1b4cec5d Merge pull request #7640 from timvandermeij/interactive-forms-rm-global
Interactive forms: remove global PDFJS usage
2016-09-19 01:02:44 +02:00
Tim van der Meij
2da2c45889 Interactive forms: remove global PDFJS usage 2016-09-19 00:12:42 +02:00
Tim van der Meij
2d287c867e Merge pull request #7645 from Snuffleupagus/TextWidgetAnnotation-double-rendering
Prevent rendering `TextWidgetAnnotation`s in both the `core`/`display` layer (issue 7643)
2016-09-18 22:49:32 +02:00
Jonas Jenwald
170871ab3d Prevent rendering TextWidgetAnnotations in both the core/display layer (issue 7643) 2016-09-18 15:42:22 +02:00
Rob Wu
ae74e1bbd6 Deduct file type from content-disposition
A user encountered a response that looks like:

URL: some gibberish
Headers:

    Content-Type: application/octet-stream
    Content-Disposition: attachment; filename="something.pdf"

In the Chrome extension, the "attachment" content disposition is almost
always ignored (i.e. the PDF Viewer will try to view it anyway). So we
need to fall back to the Content-Disposition header if the URL check is
inconclusive.
2016-09-17 22:34:18 -07: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
dbea302a6e Text widget annotations: do not render on canvas as well
If interactive forms are enabled, then the display layer takes care of
rendering the form elements. There is no need to draw them on the canvas
as well. This also leads to issues when values are prefilled, because
the text fields are transparent, so the contents that have been rendered
onto the canvas will be visible too.

We address this issue by passing the `renderInteractiveForms` parameter
to the render task and handling it when the page is rendered (i.e., when
the canvas is rendered).
2016-09-17 15:24:48 +02:00
Tim van der Meij
adf0972ca5 Text widget annotations: improve unit and reference tests
This patch improves the unit tests by testing the support for read-only
and multiline fields. Moreover, we add a reference test to ensure that
the text widgets are not only rendered, but also that their contents are
styled properly.

Finally, we perform minor improvements in `src/core/annotation.js`, for
example adding missing comments.
2016-09-17 15:24:48 +02:00
Tim van der Meij
f6965fadc0 Text widget annotations: support multiline and read-only fields
Moreover, this patch provides us with a framework for handling field
flags in general for all types of widget annotations.
2016-09-17 15:24:47 +02:00
Jonas Jenwald
aadcbe98c8 Replace empty CharStrings with '.notdef' in Type1Font_wrap to prevent OTS from rejecting the font (bug 1252420)
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1252420.
2016-09-17 14:39:10 +02:00
Jonas Jenwald
4acd31f51e Merge pull request #7550 from Snuffleupagus/Type1-toUnicode-builtInEncoding-fallback
For embedded Type1 fonts without included `ToUnicode`/`Encoding` data, attempt to improve text selection by using the `builtInEncoding` to amend the `toUnicode` map (issue 6901, issue 7182, issue 7217, bug 917796, bug 1242142)
2016-09-16 17:51:55 +02:00
Brendan Dahl
834a7ff329 Merge pull request #7636 from yurydelendik/rm-refresh
Drops unneeded HTTP refresh header for the extension.
2016-09-15 10:01:11 -07:00
Yury Delendik
503bf45eca Drops unneeded HTTP refresh header for the extension.
Some sites doing that by mistake. Aligning the extension functionality with behavior of other browsers/plugins..
2016-09-15 09:12:16 -05:00
Tim van der Meij
26da2d57ce Merge pull request #7632 from Snuffleupagus/more-efficient-expandTextDivs
[EnhanceTextSelection] Make `expandTextDivs` more efficient by updating all styles at once instead of piecewise
2016-09-15 16:01:07 +02:00
Tim van der Meij
3b94ecf563 Merge pull request #7634 from Snuffleupagus/remove-mozDash
Remove the deprecated `mozDash`/`mozDashOffset` canvas 2D context methods
2016-09-15 14:10:31 +02:00
Jonas Jenwald
8eaa2cbce3 Remove the deprecated mozDash/mozDashOffset canvas 2D context methods
According to [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash#Browser_compatibility) the standard versions of these methods have been supported since Firefox 27, which was released over two and a half years ago. (See the dates in https://wiki.mozilla.org/RapidRelease/Calendar#Past_branch_dates)

Furthermore the non-standard properties are now in the process of being removed, please see https://groups.google.com/forum/#!topic/mozilla.dev.platform/UIudMABegcY.
Hence I don't think that we need to keep the old `moz` prefixed ones as fallback any more.
2016-09-15 10:05:40 +02:00
Jonas Jenwald
cb5f9df0c8 [EnhanceTextSelection] Make expandTextDivs more efficient by updating all styles at once instead of piecewise
I intended to provide proper benchmarking results here, as outlined in https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes, but after wasting a couple of hours over the weekend getting weird results I gave up.
It appears that there's a lot of, i.e. way too much, variance between subsequent runs of `text` tests for the results to be meaningful.
(Previously I've only benchmarked `eq` tests, so I don't know if the `text` tests has never worked well or if it's a newer problem. For reference, please see the results of back-to-back benchmark runs on the current `master` with a *very* simple manifest file: [link here].)

Instead I used `console.time/timeEnd` in `appendText` and `expandTextDivs` to be able to compare the performance with/without the patch. The entire viewer was (skip-cache) reloaded between measurements, and the result are available here: [link here].
Given the troubles I've had with benchmarking, I've not yet computed any statistics on the results (e.g. mean, variance, confidence intervals, and so on).
However, just by looking at the data I think it's safe to say that this patch first of all doesn't seem to regress the current performance. Secondly it certainly looks *very* likely that this patch actually improves the performance, especially for the one-glyph-per-text-div case (cf. issue 7224).

Re: issue 7584.
2016-09-14 21:19:28 +02:00
Jonas Jenwald
a7c35025fe Merge pull request #7629 from timvandermeij/interactive-form-unit-tests
Text widget annotations: implement unit testing and sanitize data values
2016-09-13 16:52:30 +02:00
Tim van der Meij
323e86c442 Text widget annotations: implement unit testing and sanitize data values 2016-09-13 14:57:11 +02:00
Jonas Jenwald
356b321f6d Fallback to the StandardEncoding for Nonsymbolic fonts without /Encoding entry (issue 7580)
Even though this patch passes all tests (unit/font/reference) locally, including the new ones that I added in PR 7621, I'm still a bit nervous about modifying the code that choose the fallback encoding for fonts without an `/Encoding` entry.
Note that over the years this code has been changed on a number of occasions, see a possibly incomplete [list here], to deal with various cases of incorrect font data.

According to the PDF specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G8.1904184, it seems that we should fallback to the `StandardEncoding` for Nonsymbolic fonts.
There's obviously a risk that fixing this particular issue *could* break other PDF files for which we don't have tests. However I've tried to change the logic as little as possible in this patch, to hopefully reduce possible breakage.

Based on debugging numerous font issue, it seems that a lot of fonts actually set the Symbolic flag, even when they are in fact *not* Symbolic. Fonts actually marked as Nonsymbolic seem to be somewhat less common, which I hope should reduce the risk of the patch somewhat.

Fixes 7580.
2016-09-13 14:07:16 +02:00
Tim van der Meij
4d1592883d Merge pull request #7626 from yashsriv/lint-fix-url-polyfill
Fix lint warnings in URL polyfill
2016-09-12 21:15:47 +02:00
Yash Srivastav
4e428c7675
Fix lint warnings in URL polyfill 2016-09-12 20:34:51 +05:30
Tim van der Meij
03588ccbf7 Merge pull request #7623 from Snuffleupagus/jpx-error
Change `src/core/jpx.js` to use the `error` utility function instead of using `throw new Error`
2016-09-12 15:34:05 +02:00
Jonas Jenwald
230b1e3275 Merge pull request #7624 from Snuffleupagus/yury-fake-cloning
Adding "proper" message port for fake worker.
2016-09-12 12:41:33 +02:00
Yury Delendik
160b176109 Adding "proper" message port for fake worker. 2016-09-12 11:17:10 +02:00
Jonas Jenwald
f620f61887 Change src/core/jpx.js to use the error utility function instead of using throw new Error
Note that in `parseCodestream` I purposly left the `throw new Error` instances inside of the `try` block, since we don't want to throw any `Errors` while in recovery mode.
Finally somewhat unrelated to the rest of the patch, but I moved the `doNotRecover` variable declaration outside of the `try` block to avoid variable hoisting given that it's accessed inside the `catch` block.
2016-09-12 11:05:43 +02:00
Tim van der Meij
6b05cfd1b8 Merge pull request #7622 from timvandermeij/interactive-forms-text
Text widget annotations: implement maximum length and text alignment
2016-09-11 21:42:22 +02:00
Jonas Jenwald
325f7afcca For embedded Type1 fonts without included ToUnicode/Encoding data, attempt to improve text selection by using the builtInEncoding to amend the toUnicode map (issue 6901, issue 7182, issue 7217, bug 917796, bug 1242142)
Note that in order to prevent any possible issues, this patch does *not* try to amend the `toUnicode` data for Type1 fonts that contain either `ToUnicode` or `Encoding` entries in the font dictionary.

Fixes, or at least improves, issues/bugs such as e.g. 6658, 6901, 7182, 7217, bug 917796, bug 1242142.
2016-09-11 20:54:10 +02:00
Tim van der Meij
be485f59ab Text widget annotations: implement maximum length and text alignment
Moreover, we refactor the code a bit to extract code that is shared
between the two branches and we only apply text alignment (and create
the array) when it is actually defined, since it's optional and left is
already the default.
2016-09-11 20:49:00 +02:00
Tim van der Meij
bf6f5d1cc9 Merge pull request #7621 from Snuffleupagus/more-symbolic-fonts-without-included-encoding-tests
Add a couple more, mostly `text`, reference tests for non-embedded symbolic fonts without included encoding information
2016-09-11 20:44:30 +02:00
Jonas Jenwald
ae2cc9119b Add a couple more, mostly text, reference tests for non-embedded symbolic fonts without included encoding information
I've started to look into how we can fix issue 7580, but quickly became worried that fixing it could easily mean that we'd trade one fixed PDF file for a multitude of broken ones.

Hence I started going through the history of the code that choose the fallback encoding, and noticed that it has been changed a number of times over the years to deal with various cases of weirdness/errors in non-embedded fonts.
To my relief it turned out that almost all the PRs, please see a possibly incomplete [list here], that changed this code actually included `eq` test-cases.

However, in one case it appears that a PR missed to add a test-case. Furthermore since the fallback encoding may also be the only source for creating a `toUnicode` map, changing the encoding could possibly regress only the text-selection despite a PDF file still rendering correctly.
Therefore, this PR adds one new `eq` test, and also a number of additional `text` tests for PDF files already present in the test-suite.

Note that it's obviously possible that there's a certain overlap between the added tests, but I'd be *a whole lot* more concerned with causing regressions.
2016-09-11 16:38:39 +02:00
Jonas Jenwald
1fae435e88 Merge pull request #7546 from Snuffleupagus/issue-7544
Don't duplicate the first entry in the `charCodeToGlyphId` map for CIDFontType2 fonts with a `CIDToGIDMap` that already mapped the first entry to a non-zero `glyphId` (issue 7544)
2016-09-11 15:20:36 +02:00
Jeremy Press
e68f4f855f fixing 7590 by delaying div shrink after mouse up 2016-09-09 13:55:19 -07:00
Jonas Jenwald
0b75f63c03 Don't duplicate the first entry in the charCodeToGlyphId map for CIDFontType2 fonts with a CIDToGIDMap that already mapped the first entry to a non-zero glyphId (issue 7544)
Fixes 7544.
2016-09-09 22:33:41 +02:00
Tim van der Meij
b112f9f9f4 Merge pull request #7600 from Snuffleupagus/issue-7598
Check that Type1C fonts does not actually contain OpenType font files (issue 7598)
2016-09-09 22:02:58 +02:00
Tim van der Meij
22c7ff494a Merge pull request #7609 from Snuffleupagus/enhanceTextSelection-pref-hack
Add a `enhanceTextSelection` preference
2016-09-09 16:38:45 +02:00
Tim van der Meij
23a0264a15 Merge pull request #7619 from Snuffleupagus/SecondaryToolbar-setMaxHeight-events
Only update the `max-height` of the `SecondaryToolbar` when it's actually visible
2016-09-09 16:07:51 +02:00
Jonas Jenwald
be8a69a52c Ensure that we provide the source parameter when dispatching the button click events in SecondaryToolbar (PR 7313 follow-up) 2016-09-09 08:16:10 +02:00
Jonas Jenwald
6e126b31dc Only update the max-height of the SecondaryToolbar when it's actually visible
There's really no good reason to attempt to adjust the `max-height` of the `SecondaryToolbar` when it's not visible, so let's not do that anymore.
Also, we can listen for the `resize` event in `SecondaryToolbar`, to avoid having to manually call the `max-height` adjust function from various event handlers in `app.js`. Please note that by always adjusting the `max-height` when the toolbar is opened we no longer need the `localized` event, since it was mainly used to set a correct inital `max-height` value.
2016-09-09 08:16:09 +02:00
Jonas Jenwald
e12c48b73f Add a enhanceTextSelection preference
Please note that this is a hack, but I think that it should be OK for now to atleast get the preference landed. Refer to the code comment for further information.

Re: issue 7584 and PR 7586.
2016-09-08 10:22:01 +02:00
Jonas Jenwald
ca61ccc533 Merge pull request #7602 from timvandermeij/interactive-forms
Render interactive form (AcroForm) text widget annotations
2016-09-08 10:13:27 +02:00
Tim van der Meij
e281ce7c73 Enable regression testing for interactive forms 2016-09-07 16:50:44 +02:00
Tim van der Meij
e686db250c Render interactive form (AcroForm) text widget annotations
This patch is the first step towards implementing support for
interactive forms (AcroForms). It makes it possible to render text
widget annotations exactly like Adobe Reader/Acrobat.

Everything we implement for AcroForms is disabled by default using a
preference, mainly because it is not ready to use yet, but has to
implemented in many steps to avoid complexity. The preference allows us
to work with the code while not exposing the behavior by default. Mainly
storing entered values and printing them is still absent, which would be
minimal requirements for enabling this by default.
2016-09-07 15:37:28 +02:00
Jonas Jenwald
8dbb5a7c4a Merge pull request #7596 from timvandermeij/widget-annotation-cleanup
Improve the structure for widget annotations
2016-09-06 13:46:31 +02:00
Jonas Jenwald
44b75c01a1 Check that Type1C fonts does not actually contain OpenType font files (issue 7598)
This patch is yet another instalment in the (never ending) series of patches for PDF files that specify completely incorrect Type/Subtype for its fonts. In this case Type1/Type1C, when in fact OpenType would have been correct.

Fixes 7598.
2016-09-06 10:13:11 +02:00
Tim van der Meij
576f742047 Improve the structure for widget annotations
Currently, we only support text widget annotations (field type 'Tx')
partially. However, the current code does not make this entirely clear
and does not provide a warning when an unsupported field type is
encountered, making it harder to determine why rendering fails.

Moreover, in the display layer we make no distinction between the
various types of widget annotations, causing the code for text widget
annotations to also be executed for other types of widget annotations in
a fallback situation.

This patch improves the structure of the widget annotation code. In the
core layer, we use the same structure we use for non-widget annotations
in the factory and provide a clear warning when an unsupported type is
encountered. In the display layer, we do the same and split the
`WidgetAnnotationElement` class into two classes, namely
`TextWidgetAnnotationElement` for text widget annotations and
`WidgetAnnotationElement` for other unsupported annotations as a
fallback. From this it clear that we only support text widget
annotations and nothing else.
2016-09-06 00:26:05 +02:00
Tim van der Meij
b26af7ee24 Merge pull request #7595 from Snuffleupagus/api-reject-with-Error
In `display/api.js` ensure that we always reject with an `Error` in `JpegDecode`, and adjust a couple of other rejection sites as well
2016-09-05 17:14:44 +02:00
Jonas Jenwald
37998076c9 In display/api.js ensure that we always reject with an Error in JpegDecode, and adjust a couple of other rejection sites as well
In the case where the document was destroyed, we were rejecting the `Promise` in `JpegDecode` with a string instead of an `Error`. The patch also brings the wording more inline with other such rejections.

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

Finally, we can simplify the rejection handling in `WorkerTransport_getPageIndexByRef` somewhat. (Note that the only reason for using `catch` here is that since the promise is rejected on the worker side, the `reason` becomes a string instead of an `Error` which is why we "re-reject" on the display side.)
2016-09-05 16:35:32 +02:00
Jonas Jenwald
38c85039d1 Merge pull request #7588 from timvandermeij/text-layer-weakmap
Use a `WeakMap` in `src/display/text_layer.js`
2016-09-04 21:25:48 +02:00
Tim van der Meij
96593571eb Optimize scale calculation in text_layer.js
This patch avoids having to calculate the scale twice by saving it in
the properties object.

Moreover, we remove a temporary variable and place parentheses around a
calculation inside a string concatenation.
2016-09-04 20:19:31 +02:00
Tim van der Meij
7db1983d64 Merge pull request #7591 from Snuffleupagus/jpeg-error
Change `src/core/jpg.js` to use the `error` utility function instead of `throw`ing
2016-09-04 20:11:09 +02:00
Jonas Jenwald
a35773ec8c Change src/core/jpg.js to use the error utility function instead of throwing
This allows us to remove the `try/catch` statements used in `src/core/stream.js` when parsing JPEG images.
As far as I can tell, the only reason for the current usage of plain `throw` is that `jpg.js` originally was external code. Given that this code now lives in our repo, this patch brings the JPEG code more in line with e.g. `src/core/jpx.js` and `src/core/jbig2.js`.
2016-09-04 16:28:23 +02:00
Tim van der Meij
d03651efff Merge pull request #7407 from Snuffleupagus/issue-7406
Assign the `quantizationTables` after parsing the entire JPEG image, to prevent issues when the DQT (Define Quantization Tables) marker is encountered after SOF{n} (Start of Frame) markers (issue 7406)
2016-09-04 14:49:01 +02:00
Tim van der Meij
31f6180a08 Merge pull request #7592 from timvandermeij/revert
Revert the commits from pull request #7586 for causing addon issues
2016-09-03 20:42:21 +02:00
Tim van der Meij
eb2ba3287a Revert "Move the Preferences initialization/fetching code to the top of PDFViewerApplication.initialize, to enable using them when initializing the viewer components"
This reverts commit ffb876fdf4.
2016-09-03 20:27:01 +02:00
Tim van der Meij
a2525a8ba3 Revert "Add a enhanceTextSelection preference to the viewer"
This reverts commit 15e45d772f.
2016-09-03 20:26:46 +02:00
Tim van der Meij
b3818d5c36 Replace div.dataset with a WeakMap in text_layer.js
This patch improves performance by avoiding unnecessary type
conversions, which also help the JIT for optimizations.

Moreover, this patch fixes issues with the div expansion code where
`textScale` would be undefined in a division. Because of the `dataset`
usage, other comparisons evaluated to `true` while `false` would have
been correct. This makes the expansion mode now work correctly for cases
with, for example, each glyph in one div.

The polyfill for `WeakMap` has been provided by @yurydelendik.
2016-09-03 20:06:42 +02:00
Tim van der Meij
461a18a74a Merge pull request #7586 from Snuffleupagus/viewer-initialize-Preferences-earlier
Move the `Preferences` initialization/fetching code to the top of `PDFViewerApplication.initialize`, and add a `enhanceTextSelection` preference to the viewer
2016-09-03 18:55:24 +02:00
Tim van der Meij
b10add14f3 Refactor text_layer.js to pass the task as a parameter
We pass many parameters to `appendText` while we might as well pass the
`task` object that contains them. This saves a few lines of code and
makes the signature of `appendText` more clear. We do the same for
`expand`, which is useful for the next commit in which we replace
`div.dataset` with a `WeakMap`.

Furthermore, this patch adds a missing parameter to a comment block to
make it clear which parameters remain.
2016-09-02 20:46:36 +02:00
Jonas Jenwald
15e45d772f Add a enhanceTextSelection preference to the viewer 2016-09-02 14:38:51 +02:00
Jonas Jenwald
ffb876fdf4 Move the Preferences initialization/fetching code to the top of PDFViewerApplication.initialize, to enable using them when initializing the viewer components 2016-09-02 14:38:48 +02:00
Tim van der Meij
8522625da2 Merge pull request #7585 from timvandermeij/text-selection-code-fixes
Minor code style improvements after #7539
2016-09-01 18:48:04 +02:00
Tim van der Meij
7c961b6b7a Minor code style improvements after #7539 2016-09-01 18:07:12 +02:00
Tim van der Meij
6bb95e3129 Merge pull request #7539 from jeremypress/fairexpand
[api-minor] Expanding divs to improve selection
2016-09-01 17:43:31 +02:00
Tim van der Meij
61a576c41f Merge pull request #7583 from Snuffleupagus/Named-Action-GoToPage-select
Change the `GoToPage` Named Action to select the contents of the `pageNumber` input, rather than just focusing the element
2016-09-01 15:38:37 +02:00
Jonas Jenwald
0db76dc58c Change the GoToPage Named Action to select the contents of the pageNumber input, rather than just focusing the element
When clicking on the `pageNumber` input, or when using the keyboard shortcut <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>G</kbd>, the element isn't just focused but its contents is actually *selected* so that the user doesn't need to clear the input before entering a new `pageNumber`.
However, the `GoToPage` named action is only using `focus`, so let's change this to be consistent.

The following document can be used for testing: http://www2.informatik.uni-freiburg.de/~frank/ENG/beamer/example/Beamer-class-example1.pdf#zoom=page-fit

[screeenshot]
2016-09-01 13:48:49 +02:00
Jeremy Press
1ceeb4d17b added text enhancement regression tests 2016-08-31 09:54:52 -07:00
Jeremy Press
6faa84abdb Continuing fairexpand #6663
1. Expanding divs to improve text selection. (Yury)
2. Adding enhanceTextSelection as an option.
3. Moving feature functionality from text_layer_builder.js to text_layer.js.
4. Added expandTextDivs method to only load expanded divs on first click, and only show on subsequent clicks
2016-08-31 09:54:52 -07:00
Jonas Jenwald
3ac23200ba Add a reduced test-case for issue 7406
The PDF file contains an image that we're allowed to use, since it's just the PDF.js logo.
The logo image was simply inverted (so that it requires a /Decode entry in the image dictionary that triggers the use of `jpg.js` instead of the browser), converted to JPEG, and finally edited by hand to change the order of the DQT/SOF{n} markers.
2016-08-31 18:42:07 +02:00
Jonas Jenwald
1bbc694ac3 Assign the quantizationTables after parsing the entire JPEG image, to prevent issues when the DQT (Define Quantization Tables) marker is encountered after SOF{n} (Start of Frame) markers (issue 7406)
This is a tentative patch that fixes 7406.
2016-08-31 18:42:05 +02:00
Tim van der Meij
23b13d368e Merge pull request #7579 from Snuffleupagus/updateUIToolbar-correctly-disable-zoom-buttons
Ensure that the zoom buttons are disabled correctly if the `scale` is smaller/larger than `MIN_SCALE/MAX_SCALE` in `PDFViewerApplication._updateUIToolbar`
2016-08-31 15:33:49 +02:00
Jonas Jenwald
f3b7fa091d Ensure that the zoom buttons are disabled correctly if the scale is smaller/larger than MIN_SCALE/MAX_SCALE in PDFViewerApplication._updateUIToolbar
In the `zoom{In, Out}` functions in `PDFViewerApplication`, we prevent the zoom value from becoming smaller/larger than `MIN_SCALE/MAX_SCALE`.
However, if the user sets the zoom level through the hash parameter the zoom buttons might not be correctly disabled; try http://mozilla.github.io/pdf.js/web/viewer.html#zoom=10.

Note that this issue has been present since "forever", but given that the solution is so simple I think that we should just fix this. (I'm also fixing a stupid typo I previously made in the JSDoc comment.)
2016-08-31 13:28:38 +02:00
Yury Delendik
ffa99397ad Merge pull request #7387 from Snuffleupagus/issue-5808
Attempt to ignore multiple identical Tf (setFont) commands in `PartialEvaluator_getTextContent` (issue 5808)
2016-08-30 15:21:41 -05:00
Tim van der Meij
a75b020423 Merge pull request #7575 from timvandermeij/update-l10n
Update translations
2016-08-28 16:20:21 +02:00
Tim van der Meij
d1ca5c11ec Update translations 2016-08-28 16:14:03 +02:00
Tim van der Meij
b0a0bef267 Merge pull request #7440 from Snuffleupagus/bug-874482
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
2016-08-28 15:47:40 +02:00
Tim van der Meij
f520616e00 Merge pull request #7570 from Snuffleupagus/issue-7569
Create a fallback annotation `id` for entries in `Annots` dictionaries that are not indirect objects (issue 7569)
2016-08-28 00:23:59 +02:00
Tim van der Meij
fb6fde9d00 Merge pull request #7574 from timvandermeij/unit-test-font-cleanup
Remove unused globals from fonts unit test file
2016-08-27 23:29:06 +02:00
Tim van der Meij
b81d661556 Remove unused globals from fonts unit test file 2016-08-27 23:20:03 +02:00
Tim van der Meij
d944c320b4 Merge pull request #7540 from Snuffleupagus/ProblematicCharRanges-unit-test
Add a unit-test to check that `ProblematicCharRanges` contains valid entries
2016-08-27 23:14:55 +02:00
Tim van der Meij
8aa9b790be Merge pull request #7573 from Snuffleupagus/mobile-viewer-async-open/close
[mobile-viewer] Add an async `close` method to the example, and change `open` to also be async (issue 7571)
2016-08-27 22:45:42 +02:00
Jonas Jenwald
65e9ff68aa [mobile-viewer] Add an async close method to the example, and change open to also be async (issue 7571)
Since the `mobile-viewer` example is based on the old FirefoxOS/B2G PDF viewer, it didn't need to have the same kind of `open/close` methods as the default viewer.
However, now that it has been re-purposed as a simple `mobile-viewer` example, it seems like a good idea to ensure that it has proper asynchronous `open/close` methods.

Fixes 7571.
2016-08-27 12:57:34 +02:00
Jonas Jenwald
088ce6c009 Add a unit-test to check that ProblematicCharRanges contains valid entries
When adding new entries to `ProblematicCharRanges`, you have to be careful to not make any mistakes since that could cause glyph mapping issues.
Currently the existing reference tests should probably help catch any errors, but based on experience I think that having a unit-test which specifically checks `ProblematicCharRanges` would be both helpful and timesaving when modifying/reviewing changes to this code.

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

Fixes 7569.
2016-08-27 10:56:16 +02:00
Brendan Dahl
0e20d44fef Merge pull request #7563 from brendandahl/upstream-l10n
Upstream l10n changes from Bug 1259859.
2016-08-24 09:49:17 -07:00
Brendan Dahl
8cf32cde6c Upstream l10n changes from Bug 1259859. 2016-08-24 09:47:36 -07:00
Jonas Jenwald
e5baf7ec36 Merge pull request #7330 from Snuffleupagus/issue-7188
Try to prevent `CanvasGraphics_getSinglePixelWidth` from intermittently returning incorrect values in Firefox (issue 7188)
2016-08-22 20:36:54 +02:00
Jonas Jenwald
5379749d4b Try to prevent CanvasGraphics_getSinglePixelWidth from intermittently returning incorrect values in Firefox (issue 7188)
Fixes 7188.
2016-08-22 20:00:24 +02:00
Tim van der Meij
200c8575ab Merge pull request #7555 from Snuffleupagus/primitives-async-unit-tests
Add unit-tests for asynchronous methods in `primitives.js`
2016-08-22 13:29:40 +02:00
Jonas Jenwald
db1526c59e Add unit-tests for asynchronous methods in primitives.js
In PR 7520, I missed the fact that we currently have no unit-tests for `Dict_getAsync`.
2016-08-21 18:44:58 +02:00
Brendan Dahl
a9c37c242e Merge pull request #7521 from brendandahl/bug-1291709
Bug 1291709 - PdfjsChromeUtils.jsm leaks browser.xul windows.
2016-08-17 14:35:39 -07:00
Tim van der Meij
ef45085f10 Merge pull request #7548 from Rob--W/window-print-avoid-microtask
Avoid window.print in a microtask
2016-08-17 21:35:12 +02:00
Tim van der Meij
b4c8814fc9 Merge pull request #7534 from Snuffleupagus/isName-name-check
Add a parameter to the `isName` function that enables checking not just that something is a `Name`, but also that the actual `name` properties matches
2016-08-17 15:48:42 +02:00
Rob Wu
76d29759c5 Avoid window.print in a microtask 2016-08-17 05:52:27 -07:00
Jonas Jenwald
084fc517fe Merge pull request #7021 from Snuffleupagus/bug-1250079
Add a `recoveryMode` that suppresses errors from the `Parser`, and utilize it when searching for the main trailer in `XRef_indexObjects` (bug 1250079)
2016-08-17 13:46:09 +02:00
Jonas Jenwald
544d29f5cb Add a recoveryMode that suppresses errors from the Parser, and utilize it when searching for the main trailer in XRef_indexObjects (bug 1250079)
Instead of having `Parser_getObj` fail unconditionally for the referenced PDF file, this patch attempts to let searching for the main trailer continue even if there are errors.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1250079.
2016-08-17 12:37:35 +02:00
Jonas Jenwald
83ce6f0b6d Adjust the (applicable) existing isName callsites to use the new isName(v, name) version of the function 2016-08-10 11:15:08 +02:00
Jonas Jenwald
af636aae96 Add a parameter to the isName function that enables checking not just that something is a Name, but also that the actual name properties matches
This is similar to the existing `isCmd` and `isDict` functions, which already support similar kind of checks.
With the updated `isName` function, we'll be able to simplify many callsites from: `isName(someVariable) && someVariable.name === 'someName'` to: `isName(someVariable, 'someName')`.
2016-08-10 11:15:03 +02:00
Brendan Dahl
94089960c0 Merge pull request #7532 from Snuffleupagus/PDFViewer-remove-obsolete-onAfterDraw-comment
Remove an obsolete comment for `onAfterDraw` in pdf_viewer.js
2016-08-08 10:53:01 -07:00
Jonas Jenwald
31cd23a6df Remove an obsolete comment for onAfterDraw in pdf_viewer.js
With the viewer code now being split into various components/files, having an obsolete comment in `PDFViewer` that references thumbnails despite there being no other mentions of them in the entire file seems strange.

*Note:* This comment is simply a left-over from older versions of PDF.js, where the *entire* default viewer code was placed in just one file (and where we unconditionally created thumbnails, regardless whether they were visible or not).
2016-08-08 13:49:31 +02:00
Jonas Jenwald
076e25f1ca Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.

However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.

Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-08-07 16:20:18 +02:00
Xiliang Chen
6cb77d6580 fix outline may jump to previous page issue 2016-08-07 16:20:18 +02:00
Tim van der Meij
ca81f4df18 Merge pull request #7529 from Snuffleupagus/setCurrentPageNumber-warn-on-outOfBounds
Log an error when the value passed to `set currentPageNumber` is out of bounds (PR 7502 followup)
2016-08-07 14:43:31 +02:00
Jonas Jenwald
7706cfa9fe Log an error when the value passed to set currentPageNumber is out of bounds (PR 7502 followup)
With PR 7502 we no longer dispatch an event when the `val` is out of bounds, so to better communicate why nothing happens this patch logs an error in that case (similar to the logging of errors when trying to set an invalid scale).

The way that the default viewer is currently implemented, means that e.g. keyboard short-cuts could trigger the new error. Hence this patch also adds the necessary validation code, both to `app.js` and `pdf_link_service.js` to prevent unnecessary errors.
2016-08-07 14:24:09 +02:00
Tim van der Meij
ac7b675603 Merge pull request #7526 from Snuffleupagus/PDFViewer_pagesRotation-validation
Add validation of the `rotation` argument passed to `set pagesRotation` in `PDFViewer`
2016-08-06 13:20:11 +02:00
Jonas Jenwald
50aeb00adf Add validation of the rotation argument passed to set pagesRotation in PDFViewer
*Similar to the validation done when setting page/scale.*
2016-08-06 13:01:17 +02:00
Jonas Jenwald
3a1e794512 Update l10n files 2016-08-06 12:44:06 +02:00
Tim van der Meij
f16b2d468a Merge pull request #7520 from Snuffleupagus/primitives-more-unit-tests
Add more unit-tests for `primitives.js`
2016-08-04 14:30:56 +02:00
Brendan Dahl
815c3a822f Bug 1291709 - PdfjsChromeUtils.jsm leaks browser.xul windows. 2016-08-03 14:18:40 -07:00
Yury Delendik
39412e5ace Merge pull request #7519 from timvandermeij/remove-amo
Stop building the AMO extension
2016-08-03 15:12:51 -05:00
Jonas Jenwald
d70e07fb90 Add more unit-tests for primitives.js 2016-08-03 17:04:12 +02:00
Tim van der Meij
79db293c36 Stop building the AMO extension
The AMO extension is no longer supported as PDF.js is integrated in
Firefox. It was already removed from the bot's preview messages around a
year ago and has not been used or updated since.
2016-08-03 14:44:18 +02:00
Jonas Jenwald
77c6ed5389 Attempt to ignore multiple identical Tf (setFont) commands in PartialEvaluator_getTextContent (issue 5808)
This patch improves the performance of issue 5808, but I'm not sure if it's enough to call it fixed. On average, this patch reduces the number of textLayer div's by a factor of 3, and it also reduces the time spend in `getTextContent` by a factor of ~2.

The PDF file is generated by `Scribus PDF`, which for reasons I cannot understand is placing redundant `Tf` commands before *every* showText command.
Note how the PDF file also contains lots of (basically) identical fonts, but with slightly different names, which causes unnecessary font-switching. This causes some unnecessary breaking of textLayer div's, but this issue cannot be easily worked around.
2016-07-27 21:37:52 +02:00
Yury Delendik
19105f0669 Merge pull request #7511 from timvandermeij/b2g-example
Convert the B2G viewer from an extension to an example
2016-07-27 13:57:52 -05:00
Tim van der Meij
a20f814265 Refactor the mobile viewer example
This mostly removes B2G-specific code and adds the styles from the B2G
components.
2016-07-27 17:31:52 +02:00
Tim van der Meij
a9dd2ab0ab Move B2G viewer to the examples folder 2016-07-27 17:31:52 +02:00
Tim van der Meij
b25bc27498 Remove B2G extension building target 2016-07-27 17:31:52 +02:00
Tim van der Meij
df0d21701a Merge pull request #7510 from timvandermeij/b2g-fix
Remove `previousPageNumber` from the B2G viewer
2016-07-27 15:59:55 +02:00
Tim van der Meij
e65606d271 Remove previousPageNumber from the B2G viewer 2016-07-27 15:55:40 +02:00
Tim van der Meij
0925503ce7 Merge pull request #7502 from Snuffleupagus/pagechanging-outOfBounds
Remove the `previousPageNumber` parameter from the `pagechanging`/pagechange` events, and stop dispatching the events if the input is out of bounds
2016-07-27 15:35:31 +02:00
Yury Delendik
a02e2686b9 Merge pull request #7475 from Snuffleupagus/api-getTextContent-combineTextItems
[api-minor] Add a parameter to `PDFPageProxy_getTextContent` that controls whether `PartialEvaluator_getTextContent` will attempt to combine same line text items
2016-07-27 08:34:24 -05:00
Tim van der Meij
336b26a39d Merge pull request #7506 from Snuffleupagus/annotation-missing-subtype
Prevent errors when parsing Annotations with missing (or invalid) /Subtype entries (issue 7446)
2016-07-25 16:25:29 +02:00
Tim van der Meij
f4b2ad4ec2 Merge pull request #7505 from timvandermeij/travis-ci-update
Use the latest stable Node.js version on Travis CI and enable caching
2016-07-25 15:29:37 +02:00
Tim van der Meij
7bbc2f079a Use the latest stable Node.js version on Travis CI and enable caching 2016-07-25 15:17:30 +02:00
Jonas Jenwald
558a22cd02 Prevent errors when parsing Annotations with missing (or invalid) /Subtype entries (issue 7446)
Note that I used a separate warning message for this case, instead of utilizing the same one as in the unsupported subtype case, to more clearly indicate that the PDF file itself is to blame rather than PDF.js.

Fixes 7446.
2016-07-25 13:59:26 +02:00
Jonas Jenwald
b7cb44af88 Remove the previousPageNumber parameter from the pagechanging/pagechange` events, and stop dispatching the events if the input is out of bounds
This patch attempts to cleanup a couple of things:
 - Remove the `previousPageNumber` paramater. Prior to PR 7289, when the events were dispatched even when the active page didn't change, it made sense to be able to detect that in an event listener. However, now that's no longer the case, and furthermore other similar events (e.g. `scalechanging`/`scalechange`) don't include information about the previous state.

 - Don't dispatch the events when the value passed to `set currentPageNumber` is out of bounds. Given that the active page doesn't change in this case, again similar to PR 7289, I don't think that the events should actually be dispatched in this case.

 - Ensure that the value passed to `set currentPageNumber` is actually an integer, to avoid any issues (note how e.g. `set currentScale` has similar validation code).

Given that these changes could possibly affect the PDF.js `mochitest` integration tests in mozilla-central, in particular https://dxr.mozilla.org/mozilla-central/source/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js, I ran the tests locally with this patch applied to ensure that they still pass.
2016-07-25 10:08:53 +02:00
Brendan Dahl
5678486802 Merge pull request #7347 from Snuffleupagus/evaluator-more-Ref_toString
Slightly refactor the `fontRef` handling in `PartialEvaluator_loadFont` (issue 7403 and issue 7402)
2016-07-22 17:21:47 -07:00
Brendan Dahl
50d6e4f147 Merge pull request #7447 from Snuffleupagus/buildToUnicode-notdef
Ignore .notdef in the `differences` array when building a fallback `toUnicode` map in `PartialEvaluator_buildToUnicode` (issue 5256)
2016-07-22 14:33:32 -07:00
Jonas Jenwald
390c02a3e9 Attempt to cache fonts that are direct objects (i.e. Dicts), as opposed to Refs, to prevent re-rendering after cleanup from breaking (issue 7403 and issue 7402)
Fonts that are not referenced by `Ref`s are very uncommon in practice, but it can unfortunately happen. In this case, we're currently not caching them in the usual way, i.e. by `Ref`, which leads to failures when a page is rendered after `cleanup` has run.
The simplest solution would have been to remove the `font.translated` workaround, but since this would have meant loading these kind of fonts over and over, the patch attempts to be a bit clever about this situation.

Note that if we instead loaded fonts per *page*, instead of per document, this issue wouldn't have existed.
2016-07-21 16:04:07 +02:00
Jonas Jenwald
4fe891c5e7 Add a reduced test-case for issue 7403 2016-07-21 16:04:07 +02:00
Jonas Jenwald
2e9cd3ea64 Slightly refactor the fontRef handling in PartialEvaluator_loadFont (issue 7403 and issue 7402)
Originally, I was just going to change this code to use `Ref_toString` in a couple more places. When I started reading the code, I figured that it wouldn't hurt to clean up a couple of comments. While doing this, I noticed that the logic for the (rare) `isDict(fontRef)` case could do with a few improvements.

There should be no functional changes with this patch, but given the added reference checks, we will now avoid bogus `Ref`s when resolving font aliases. In practice, as issue 7403 shows, the current code can break certain PDF files even if it's very rare.

Note that the only thing that this patch will change, is the `font.loadedName` in the case where a `fontRef` is a reference *and* the font doesn't have a descriptor. Previously for `fontRef = Ref(4, 0)` we'd get `font.loadedName = 'g_d0_f4_0'`, and with this patch `font.loadedName = g_d0_f4R`, which is actually one character shorted in most cases. (Given that `Ref_toString` contains an optimization for the `gen === 0` case, which is by far the most common `gen` value.)

In the already existing fallback case, where the `fontName` is used to when creating the `font.loadedName`, we allow any alphanumeric character. Hence I don't see how (as mentioned above) e.g. `font.loadedName = g_d0_f4R` would be an issue here.
2016-07-21 16:03:33 +02:00
Tim van der Meij
10f9f11ec4 Merge pull request #7490 from Snuffleupagus/issue-7426
Don't map glyphs to the Lepcha Unicode block (issue 7426)
2016-07-21 14:39:19 +02:00
Jonas Jenwald
f297e4d17c [api-minor] Add a parameter to PDFPageProxy_getTextContent that controls whether PartialEvaluator_getTextContent will attempt to combine same line text items
From the discussion in issue 7445, it seems that there may be cases where an API consumer would want to get the text content as is, without combined text items.
2016-07-19 13:38:57 +02:00
Jonas Jenwald
9228a04061 Merge pull request #7493 from Snuffleupagus/issue-7492
Catch errors and continue parsing in `parseCMap` (issue 7492)
2016-07-19 10:31:26 +02:00
Jonas Jenwald
90d19de935 Catch errors and continue parsing in parseCMap (issue 7492)
After PR 7039, the PDF file in issue 7492 no longer renders at all, but note that text selection wasn't working correctly previously.

The problem with the PDF file in issue 7492 is that the `cMap`, in the `toUnicode` entry in the font, contains an invalid name:
```
/CMapName /-usr-share-fonts-truetype-Panton-Panton Family-Fontfabric - Panton.otf,000-UTF16 def
```
When we parse that line, things obviously break because there are spaces present in the wrong places.
To avoid that issue, the patch simply lets `parseCMap` continue when errors are encountered, to try and recover usable data. Note that by not aborting immediatly when an error is encountered, we are also able to fix the text selection.

Obviously, it could be argued that we should just immediatly reject a corrupt `cMap`. But given that they usually are correct, it seems that trying to recover as much data as possible from corrupt one can only be a good thing for both glyph mapping and text selection.

Fixes 7492.
2016-07-18 16:39:56 +02:00
Tim van der Meij
0da97ad2a0 Merge pull request #7485 from Snuffleupagus/resetCurrentPageView
Ensure that we don't reset the current page view if the user inputs an invalid page number (PR 7289 follow-up)
2016-07-17 19:49:11 +02:00
Tim van der Meij
3ab68f2e06 Merge pull request #7489 from ka7/spelling
trivial spelling fixes
2016-07-17 19:40:17 +02:00
Jonas Jenwald
64783c8b6e Don't map glyphs to the Lepcha Unicode block (issue 7426)
In the PDF file in the issue, some of the glyphs end up being mapped to the Lepcha Unicode block; see https://en.wikipedia.org/wiki/Lepcha_(Unicode_block).
This didn't use to matter, but after HarfBuzz updates that improved support for Lepcha fonts, in particular https://bugzilla.mozilla.org/show_bug.cgi?id=1249861, some glyphs are now moved horizontally.
To avoid that, this patch adds the Lepcha block to the list of Unicode ranges that we skip when building the glyph mapping.

Fixes 7426.
2016-07-17 16:53:36 +02:00
klemens
6f03f62327 trivial spelling fixes 2016-07-17 14:33:41 +02:00
Jonas Jenwald
11381cdb0f Update l10n files 2016-07-15 11:48:37 +02:00
Jonas Jenwald
9f34700e0d Ensure that we don't reset the current page view if the user inputs an invalid page number (PR 7289 follow-up)
After PR 7289, we'll now reset the current page view in cases where I don't think we should. To avoid this, this patch ensures that we'll not modify the position when the page number is out-of-bounds.

**STR:**
1. Open http://mozilla.github.io/pdf.js/web/viewer.html#page=1&zoom=auto,-98,696
2. Enter an invalid number, e.g. `1000`, in the `pageNumber` input.

**ER:**
The current position in the document shouldn't change, since the page number wasn't valid.

**AR:**
The document resets to the top of the page `1`.
2016-07-14 12:46:33 +02:00
Tim van der Meij
1695893526 Merge pull request #7478 from PeterDaveHelloKitchen/image-optimize
optimize png images using zopflipng
2016-07-10 13:46:54 +02:00
Peter Dave Hello
625d637297 optimize png images using zopflipng 2016-07-10 17:49:16 +08:00
Tim van der Meij
223adf4656 Merge pull request #7481 from Snuffleupagus/firefox-addon-remove-compatibility
[Firefox addon] Remove compatibility.js
2016-07-09 20:45:46 +02:00
Tim van der Meij
bd562bb39c Merge pull request #7480 from Snuffleupagus/remove-MozBlobBuilder-fallback
Remove the obsolete `MozBlobBuilder` fallback from the `createBlob` utility function
2016-07-09 20:40:24 +02:00
Jonas Jenwald
a69e862bc4 [Firefox addon] Remove compatibility.js
This was added in PR 4865, but hasn't been necessary for quite some time now (and the minimum version is currently Firefox 38 for the addon).
2016-07-09 17:59:06 +02:00
Jonas Jenwald
8f4ec669d0 Remove the obsolete MozBlobBuilder fallback from the createBlob utility function
`MozBlobBuilder` has been obsolete since Firefox 14, so there's no reason to keep this code around anymore.
2016-07-09 16:37:05 +02:00
Tim van der Meij
43613f19f9 Merge pull request #7466 from Snuffleupagus/PDFViewerApplication-open-remove-fallback-args
Remove handling of fallback arguments from `PDFViewerApplication.open`
2016-07-09 15:51:25 +02:00
Tim van der Meij
d728651455 Merge pull request #7479 from Snuffleupagus/recoverGlyphName-warn-to-info
Change the `warn` to `info` in `recoverGlyphName` to reduce the console spam
2016-07-09 15:34:59 +02:00
Jonas Jenwald
51e46fa1a7 Change the warn to info in recoverGlyphName to reduce the console spam
After PR 7441, where `recoverGlyphName` is used a lot more than before, many PDF files will generate a lot of warnings the console. For normal usage, compared to debugging/development, this is probably more annoying than helpful.
2016-07-09 12:08:41 +02:00
Yury Delendik
bca1aebeac Merge pull request #7458 from Snuffleupagus/updateUIToolbar
Consolidate updating of various Toolbar state (e.g. page and scale) in one method in `PDFViewerApplication`
2016-07-08 12:34:39 -05:00
Yury Delendik
b87676078c Merge pull request #7455 from Snuffleupagus/issue-7448
Ensure that the necessary src/* dependencies are loaded before the viewer, when it's run with `gulp server` (issue 7448)
2016-07-08 12:34:09 -05:00
Tim van der Meij
b6826a46a8 Merge pull request #7453 from simoncpu/master
Expose the text widget's maximum length.
2016-07-07 01:03:40 +02:00
Tim van der Meij
10cd37cfb2 Merge pull request #7473 from Snuffleupagus/links-mxr-to-dxr
Update `mxr.mozilla.org` links to point to `dxr.mozilla.org` instead
2016-07-06 22:26:38 +02:00
Brendan Dahl
1f3f4a8dd7 Merge pull request #7441 from Snuffleupagus/issue-7439
Fallback to attempt to recover standard glyph names when amending the `charCodeToGlyphId` with entries from the `differences` array in `type1FontGlyphMapping` (issue 7439)
2016-07-06 13:02:21 -07:00
Jonas Jenwald
87229a086f Update mxr.mozilla.org links to point to dxr.mozilla.org instead
Given that MXR has been officially retired, see https://groups.google.com/forum/#!topic/mozilla.dev.platform/_k-ditFrne4, we've got a couple of links that are no longer working.
2016-07-06 11:42:16 +02:00
Tim van der Meij
b9e903808f Merge pull request #7467 from Snuffleupagus/getAttachments-unit-test
Add a `getAttachments` unit-test for a PDF file that actually contains attachments
2016-07-04 20:33:56 +02:00
Jonas Jenwald
72c1df726e Add a getAttachments unit-test for a PDF file that actually contains attachments 2016-07-02 13:13:30 +02:00
Jonas Jenwald
cb6a7e5503 Remove handling of fallback arguments from PDFViewerApplication.open
The method signature was improved in PR 6546, which was included in the `1.2.109` release from last November.
Hence I think that we should now be able to remove the fallback code for the old method signature. Note that this patch now throws an `Error` in `GENERIC` builds, to clearly indicate that the `open` callsite must be modified.
2016-07-02 11:31:32 +02:00
Yury Delendik
f082407ab4 Merge pull request #7463 from Snuffleupagus/fix-bug-1268749-fallout
Add back moz-specific fullscreen support code for ´MOZCENTRAL` builds (bug 1268749, PR 7273 follow-up)
2016-07-01 08:09:08 -05:00
Jonas Jenwald
2f127df97b Add back moz-specific fullscreen support code for ´MOZCENTRAL` builds (bug 1268749, PR 7273 follow-up)
In PR 7273, we simplified the `MOZCENTRAL` specific check for fullscreen support. Unfortunately I've just, by coincidence, found out about https://bugzilla.mozilla.org/show_bug.cgi?id=1268749, which disabled the unprefixed fullscreen support in release versions of Firefox. If we do nothing, this will lead to Presentation Mode being unavailable in future Firefox releases.

This patch should fix things for now, and I'm afraid that we'll need to uplift it to Firefox 49 as well.
2016-07-01 14:11:58 +02:00
Yury Delendik
3cba2cb258 Fixes SeaMonkey version 2016-06-29 17:54:11 -05:00
Brendan Dahl
e2e657e44f Merge pull request #7390 from Snuffleupagus/issue-7180
Add upper-case `I` as a possible space replacement fallback in `Font.spaceWidth` to improve text-selection (issue 7180)
2016-06-29 15:11:19 -07:00
Jonas Jenwald
dd0fe10a52 Consolidate updating of various Toolbar state (e.g. page and scale) in one method in PDFViewerApplication
With the changes in PR 7289, we no longer dispatch a 'pagechanging' event on load. Since most PDF documents open on the first page, this means that the `previous` and `firstPage` buttons are no longer correctly disabled.
To avoid this, this patch moves the code that updates various UI toolbar state into one method, which is then called on document initialization and from the various existing event handling functions.
2016-06-29 22:36:45 +02:00
Jonas Jenwald
4342993a3f Ensure that the necessary src/* dependencies are loaded before the viewer, when it's run with gulp server (issue 7448)
Fixes 7448.
2016-06-29 15:19:28 +02:00
Simon Cornelius P. Umacob
d872fc90b9 Expose the text widget's maximum length. 2016-06-29 17:04:33 +08:00
Jonas Jenwald
bdd58ab1d2 Ignore .notdef in the differences array when building a fallback toUnicode map in PartialEvaluator_buildToUnicode (issue 5256)
Fixes 5256.
2016-06-27 16:20:23 +02:00
Jonas Jenwald
7866109af9 Fallback to attempt to recover standard glyph names when amending the charCodeToGlyphId with entries from the differences array in type1FontGlyphMapping (issue 7439)
Fixes 7439.
2016-06-25 14:54:34 +02:00
Tim van der Meij
e908b71309 Merge pull request #7438 from Snuffleupagus/README-addon-compat
Update README.md to only guarantee Firefox addon compatibility with the current ESR version
2016-06-25 14:10:39 +02:00
Jonas Jenwald
3b9042034b Update README.md to only guarantee Firefox addon compatibility with the current ESR version
To reduced the amount of compatibility code that we need to maintain in the addon, I think that we should be more explicit about which Firefox versions we intend to support. In the future, this should allow us to more quickly remove old compatibility code.
Furthermore, this patch also tries to be more explicit about the addon support for Seamonkey, by defining it in terms of the underlying Firefox version.
2016-06-25 08:59:59 +02:00
Yury Delendik
671f33a324 Merge pull request #7427 from Snuffleupagus/fonts-skip-mapping-ideographic-space
Skip mapping of glyphs to Unicode "Ideographic space" (issue 7416)
2016-06-24 10:57:55 -05:00
Yury Delendik
546e22397e Merge pull request #7437 from Snuffleupagus/addon-seamonkey-compat
[Firefox addon] Feature detect `originAttributes` to make it Seamonkey 2.40 compatible
2016-06-24 10:25:49 -05:00
Jonas Jenwald
9fbde18880 [Firefox addon] Feature detect originAttributes to make it Seamonkey 2.40 compatible
Fixes 7245.
2016-06-24 17:05:53 +02:00
Yury Delendik
98d9712308 Merge pull request #7409 from Snuffleupagus/upstream-bug-1242730
Upstream the changes from Bug 1242730 - Convert callsites to use channel.async0pen2() within browser/extensions/pdfjs (issue 7386)
2016-06-24 09:49:56 -05:00
Jonas Jenwald
2d8ed7ba18 Merge pull request #7430 from Rob--W/crx-rewrite-url-asap
Move Chromium URL rewrite to top of viewer.js
2016-06-24 09:05:12 +02:00
Rob Wu
de85278537 Move Chromium URL rewrite to top of viewer.js
Move the Chromium-specific URL rewriting code to the top of viewer.js
(before the PDF.js library) to make sure that the URL is as expected.

This ensures that variables that synchronously depends on the URL
(e.g. PDFViewerApplication.initialBookmark) are properly set.
2016-06-24 00:57:30 +02:00
Tim van der Meij
9a948f3190 Merge pull request #7428 from Snuffleupagus/importl10n-use-hg.mozilla.org
Unbreak the `importl10n` command by updating the links to point to hg.mozilla.org instead of mxr
2016-06-22 20:26:14 +02:00
Jonas Jenwald
2e42c19202 Update l10n files 2016-06-22 09:41:18 +02:00
Jonas Jenwald
bd0affab9c Unbreak the importl10n command by updating the links to point to hg.mozilla.org instead of mxr
Currently `importl10n` fails, since mxr.mozilla.org has been down for a while. Based on discussions in #developers, it isn't clear to me if/when it'll be available again.
Furthermore, I'm not sure why we're even getting the l10n files through a code search tool, rather than just using the official Mozilla repository directly.
2016-06-22 09:41:11 +02:00
Jonas Jenwald
c1ca268ef3 Skip mapping of glyphs to Unicode "Ideographic space" (issue 7416)
Fixes 7416, which is an IE specific issue.
2016-06-22 08:58:00 +02:00
Jonas Jenwald
6d7f6f1b86 Upstream the changes from Bug 1242730 - Convert callsites to use channel.async0pen2() within browser/extensions/pdfjs (issue 7386)
Please see https://bugzilla.mozilla.org/show_bug.cgi?id=1242730.

Fixes 7386.
2016-06-15 14:50:56 +02:00
Yury Delendik
a0a6e6d688 Merge pull request #7400 from Snuffleupagus/addon-minimum-firefox38
[Firefox addon] Change the minimum supported version to Firefox 38 and remove a bunch old no longer necessary fallback code
2016-06-15 13:27:33 +01:00
Jonas Jenwald
d3d3bb9695 [Firefox addon] Change the minimum supported version to Firefox 38 and remove a bunch old no longer necessary fallback code
From the discussion in issue 7386, it wasn't really clear if we can restrict addon support to Firefox `45` (i.e. the version that corresponds to the *current* ESR version).

However, we have a bunch of code for *very* old Firefox versions. Hence this patch changes the minimum supported version to Firefox `38` (which was released on `2015-05-12`, and correspond to the *previous* ESR version), and removes code that only applies to old Firefox versions.

Regardless what we end up deciding regarding addon support for previous Firefox versions, given the amount of code that even the Firefox `>= 38` condition lets us remove, I certainly think that there is value in doing this.
2016-06-15 09:54:41 +02:00
Jonas Jenwald
64a409b539 Merge pull request #7404 from Rob--W/crx-pdf-embed-object-fix-1
Force inline block display style for <object>.
2016-06-11 16:34:39 +02:00
Rob Wu
08ad551a01 Force inline block display style for <object>.
Test:
1. Build the Chrome extension and load it.
2. Visit https://robwu.nl/pdfjs/object-embed.html
3. Verify that all displayed blocks have the same width and
   height as the reference ("Expected dimension").
2016-06-11 15:54:16 +02:00
Tim van der Meij
f97d52182a Merge pull request #7341 from Snuffleupagus/getDestinationHash-Array
[api-minor] Improve handling of links that are using explicit destination arrays
2016-06-09 00:29:10 +02:00
Tim van der Meij
70b3eea4a3 Merge pull request #7389 from Snuffleupagus/move-isSpace
Move the `isSpace` utility function from core/parser.js to shared/util.js
2016-06-08 22:57:45 +02:00
Jonas Jenwald
6a0b047bfa Add upper-case I as a possible space replacement fallback in Font.spaceWidth to improve text-selection (issue 7180)
In fonts with only upper-case glyphs, that are also missing a space glyph, `get spaceWidth` won't be able to return anything useful.
By adding upper-case `I` as a fallback, we can thus improve text-selection in some PDF files.
Note that locally, the patch causes slight movement in a few existing `text` tests, but in my opinion this actually looks like slight improvements.

Fixes 7180.
2016-06-07 22:55:25 +02:00
Brendan Dahl
c4db4dd4ac Merge pull request #7361 from Snuffleupagus/bug-1146106
Attempt to recover valid `format 3` FDSelect data from broken CFF fonts (bug 1146106)
2016-06-07 11:47:51 -07:00
Jonas Jenwald
6260fc09a3 Attempt to recover valid format 3 FDSelect data from broken CFF fonts (bug 1146106)
According to the CFF specification, see http://partners.adobe.com/public/developer/en/font/5176.CFF.pdf#G3.46884, for `format 3` FDSelect data: "The first range must have a ‘first’ GID of 0".
Since the PDF file (attached in the bug) violates that part of the specification, this patch tries to recover valid FDSelect data to prevent OTS from rejecting the font.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1146106.
2016-06-06 18:20:52 +02:00
Jonas Jenwald
a36a946976 Move the isSpace utility function from core/parser.js to shared/util.js
Currently the `isSpace` utility function is a member of `Lexer`, which seems suboptimal, given that it's placed in `core/parser.js`. In practice, this means that in a number of `core/*.js` files we thus have an *otherwise* completely unnecessary dependency on `core/parser.js` for a one-line function.

Instead, this patch moves `isSpace` into `shared/util.js` which seems more appropriate for this kind of utility function. Not to mention that since all the affected `core/*.js` files already depends on `shared/util.js`, this doesn't incur any more file dependencies.
2016-06-06 09:11:33 +02:00
Rob Wu
bd47440e79 Merge pull request #7388 from Rob--W/crx-telemetry-7312-typo
Fix typo in telemetry.js, follow-up to #7370
2016-06-03 23:29:20 +02:00
Rob Wu
60438399e0 Fix typo in telemetry.js, follow-up to #7370 2016-06-03 23:28:01 +02:00
Yury Delendik
f0585f5d65 Merge pull request #7370 from Rob--W/crx-telemetry-7312
Add opt-out telemetry to the Chrome extension
2016-06-03 15:48:46 -05:00
Rob Wu
724308c57a Add opt-out telemetry to the Chrome extension
Privacy policy: https://github.com/Rob--W/pdfjs-telemetry#privacy-policy

Unit tests (offline):

```
node test/chromium/test-telemetry.js
```

Server tests (requires that Nginx is installed):

```
git clone https://github.com/Rob--W/pdfjs-telemetry.git
cd pdfjs-telemetry/
python testserver.py TestHttp TestHttps
```

Integration test (extension + server):

- Build the extension
- Edit build/chromium/telemetry.js and remove the check for
  chrome.runtime.id.
- Start Chrome (preferably a new profile):
  chromium --user-data-dir=/tmp/pdftest --no-first-run
- Open chrome://net-internals#events
- Visit chrome://extensions and enable Developer mode.
- Load unpacked extension, select build/chromium.
- Go to the chrome://net-internals tab and filter on pdfjs.robwu.nl.
- Click on URL_REQUEST and verify that the server replied with 204.
- Reload the extension.
- Verify that chrome://net-internals did not contain a new log request.
2016-06-03 20:36:57 +02:00
Yury Delendik
5a5bb99734 Merge pull request #7374 from Snuffleupagus/fix-getTextContent-setGState
Fix errors in `setGState` in `PartialEvaluator_getTextContent` that prevents text-selection from working properly
2016-06-03 11:54:41 -05:00
Jonas Jenwald
b02d560ae0 Fix errors in setGState in PartialEvaluator_getTextContent that prevents text-selection from working properly
Currently `setGState` is completely broken, and looking through the history of that code, it seems to me that this may never have worked correctly.
This patch fixes the text-selection in `extgstate.pdf` in the test-suite, which is also added as a `text` test.
2016-06-01 22:58:49 +02:00
Jonas Jenwald
7c7d239995 Update l10n files 2016-05-29 12:47:00 +02:00
Yury Delendik
5aefce6ba6 Merge pull request #5579 from jazzy-em/master
Added multiple term search functionality (with default phrase search)
2016-05-27 14:23:26 -05:00
Tim van der Meij
41f978c7c3 Merge pull request #7362 from bbodenmiller/patch-2
Github -> GitHub
2016-05-26 20:15:52 +02:00
Ben Bodenmiller
e0b9d49f2c Github -> GitHub 2016-05-26 11:11:50 -07:00
jazzy-em
0a347ec04d Added multiple term search functionality (with default phrase search) 2016-05-26 18:24:58 +05:00
Tim van der Meij
c55541f1f3 Merge pull request #7352 from Snuffleupagus/popup-annotation-inherit-parent-flags
Let non-viewable Popup Annotations inherit the parent's Annotation Flags if the parent is viewable
2016-05-25 23:57:33 +02:00
Jonas Jenwald
98fe094d18 Let non-viewable Popup Annotations inherit the parent's Annotation Flags if the parent is viewable
Fixes http://www.pdf-archive.com/2013/09/30/file2/file2.pdf.

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

Annoyingly the PDF specification doesn't, as far as I can find, mention anything about how this case should be handled, but this patch seem consistent with the actual behaviour in Adobe Reader.
2016-05-25 23:00:26 +02:00
Tim van der Meij
47b929be26 Merge pull request #7346 from Rob--W/crx-sync-storage
Support syncing of settings in Chrome extension
2016-05-25 01:50:39 +02:00
Rob Wu
0be8e72d6f Support syncing of settings in Chrome extension
Use chrome.storage.sync to store preferences instead of
chrome.storage.local, to allow settings to be synchronized if the user
chooses to sign in in Chrome and enables synchronization of extension
preferences.
2016-05-25 00:51:51 +02:00
Tim van der Meij
78359d8b03 Merge pull request #7353 from timvandermeij/chromium-regression
Resolve a regression in the Chromium extension's preferences handling
2016-05-25 00:43:50 +02:00
Tim van der Meij
fdfaa43f5e Resolve a regression in the Chromium extension's preferences handling
Commit df10513e10 unfortunately broke the options dialog of the Chromium extension because the logic required to work with the preference was not added. This patch adds the required logic to show the preference in the options dialog and to persist it to the preferences storage.

Verified using Chromium 50 on Arch Linux.
2016-05-25 00:32:32 +02:00
Tim van der Meij
6316ca0299 Merge pull request #7344 from Rob--W/crx-cleanup-compat-frame
Remove support for frames in old Chromium versions
2016-05-25 00:04:45 +02:00
Brendan Dahl
b86610ffdb Merge pull request #7300 from Snuffleupagus/bug-1068432
Prevent adding invalid values in `CFFDict_setByKey` (bug 1068432)
2016-05-24 12:12:38 -07:00
Jonas Jenwald
b354682dd6 [api-minor] Let LinkAnnotation/PDFLinkService_getDestinationHash return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.

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

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

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

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

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

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

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

Given that the `Catalog_getPageIndex` method isn't used in any hot part of the codebase, this extra check shouldn't be a problem.
(Note: in the standard viewer, it is only ever used from `PDFLinkService_navigateTo` if a destination needs to be resolved during document loading, which isn't common enough to be an issue IMHO.)
2016-05-21 14:13:41 +02:00
Tim van der Meij
db46829ef7 Merge pull request #7316 from timvandermeij/remove-unused
Remove unused variables
2016-05-21 14:07:33 +02:00
Tim van der Meij
7ac48ef4d5 Merge pull request #7340 from Snuffleupagus/unicode-unit-tests
Add basic unit-tests for unicode.js
2016-05-19 20:46:17 +02:00
Jonas Jenwald
c5c5a2a71f Add basic unit-tests for unicode.js
Re: issue 7261.
2016-05-19 19:45:45 +02:00
Tim van der Meij
f4e6afb74f Merge pull request #7337 from Snuffleupagus/combine-setTextMatrix
Attempt to combine text runs positioned with `setTextMatrix`
2016-05-18 23:05:36 +02:00
Jonas Jenwald
7ddb0bc718 Attempt to combine text runs positioned with setTextMatrix 2016-05-18 17:21:58 +02:00
Yury Delendik
8aa5901c20 Merge pull request #7332 from yurydelendik/fix-components
Fixes AMD name in web/the pdf_viewer.js.
2016-05-16 12:02:59 -05:00
Yury Delendik
185a1f45e7 Fixes AMD name in the web/pdf_viewer.js. 2016-05-16 12:01:29 -05:00
Yury Delendik
1c0433586e Merge pull request #7315 from McGiogen/bug-usestrict-compatibilityjs
Solving issue #7307, 'use strict' context in compatibility.js
2016-05-12 15:18:43 -05:00
Gioele Masini
1c96cb8862 Added context to compatibility.js to have 'use strict' directive in our context only 2016-05-12 10:04:51 +02:00
Yury Delendik
b261203018 Merge pull request #7317 from yurydelendik/move-defaultprefs
Moves DEFAULT_PREFENCES into JSON format.
2016-05-11 18:05:20 -05:00
Yury Delendik
df10513e10 Moves DEFAULT_PREFENCES into JSON format. 2016-05-11 17:58:17 -05:00
Jonas Jenwald
12a93971fe Merge pull request #7313 from timvandermeij/secondary-toolbar-class
Convert the secondary toolbar to a class
2016-05-11 23:22:18 +02:00
Tim van der Meij
f4ae277355 Convert the secondary toolbar to a class 2016-05-11 20:53:39 +02:00
Tim van der Meij
6a7012aaca Remove unused variables
These have been found using `gulp lint` in combination with the `unused:
true` parameter for JSHint. Unfortunately there are too many false
positives to enable this feature, but now that most globals have been
removed because of the conversion to UMD the results are much more
useful than before.
2016-05-11 16:11:13 +02:00
Tim van der Meij
c1c199d702 Merge pull request #7295 from Snuffleupagus/core-getArray
Use `Dict_getArray` in more places in `src/core/` to avoid issues when Arrays contain indirect objects
2016-05-10 23:21:54 +02:00
Rob Wu
9394fc133c Remove support for frames in old Chromium versions
Frames are only supported (via redirectUrl) in Chrome 35.0.1911.0+
2016-05-10 22:40:07 +02:00
Jonas Jenwald
69cf8c5fb3 Merge pull request #7289 from yurydelendik/double-pagechange
Disable pagechange event if page is not changing.
2016-05-10 16:38:55 +02:00
Jonas Jenwald
aa9ba43fa1 Merge pull request #7306 from yurydelendik/enable-debugger
Enables debugger only when needed.
2016-05-10 16:19:49 +02:00
Yury Delendik
a4c81c203b Enables debugger only when needed. 2016-05-09 18:18:43 -05:00
Tim van der Meij
8dcc727be1 Merge pull request #7244 from Rob--W/crx-pdf-embed-object-no-shadow-dom
Don't use shadow DOM for rendering <object>/<embed>
2016-05-09 23:59:28 +02:00
Tim van der Meij
d78f90390b Merge pull request #7305 from Rob--W/crx-delete-streamsPrivate
Remove streamsPrivate usage
2016-05-09 23:23:46 +02:00
Rob Wu
fc658a718c Remove streamsPrivate usage
This was only ever useful for the Opera extension because the API
requires a whitelisted extension ID. Opera ditched PDF.js from their
extension gallery, so we don't need to keep this in the tree.
2016-05-09 22:49:47 +02:00
Tim van der Meij
11914277d5 Merge pull request #7299 from Snuffleupagus/PDFPageView_draw-zoomLayer-prevent-error
Prevent intermittent "Node was not found" errors when removing the `zoomLayer` in `PDFPageView_draw`
2016-05-09 22:16:09 +02:00
Yury Delendik
dd828ea6f1 Merge pull request #7302 from Snuffleupagus/Parser_getObj-skip-over-endobj
Ignore 'endobj' commands inside of `ObjStm` streams (issue 5241, bug 898610, bug 1037816)
2016-05-09 11:03:14 -05:00
Jonas Jenwald
182d33800a Ignore 'endobj' commands inside of ObjStm streams (issue 5241, bug 898610, bug 1037816)
According to an example in the PDF specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#page=56, an `ObjStm` stream should not contain 'endobj' commands.

Fixes 5241.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=898610.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1037816.
2016-05-09 09:50:45 +02:00
Jonas Jenwald
b13b78388b Prevent intermittent "Node was not found" errors when removing the zoomLayer in PDFPageView_draw
I've seen the above error occasionally when the scale is updated many times in quick succession, but I've not been able to pinpoint exactly why it happens.
Since the error isn't caught, this means that the `pageViewDrawCallback` function doesn't run to completion.

Unfortunately, given the very intermittent nature of the issue, I haven't got any good STR for reliably reproducing this issue. However, I hope that this patch can be accepted anyway, since it's simple and should help prevent unnecessary errors.
2016-05-08 16:03:17 +02:00
Jonas Jenwald
5f59d079e0 Merge pull request #7301 from Rob--W/grab-to-pan-mouse-buttons
Update grab_to_pan.js
2016-05-08 09:46:32 +02:00
Rob Wu
057b4615ba Update grab_to_pan.js
See b81897bee4
2016-05-07 23:46:56 +02:00
Jonas Jenwald
c9b6de3b16 Prevent adding invalid values in CFFDict_setByKey (bug 1068432)
In the font in question, there are a couple of `topDict` entries that have invalid values (`0xF 0xF`, i.e. just eof markers without any actual numbers).
This causes the `parseFloatOperand` function, inside `CFFParser_parseDict`, to return `NaN`. Currently we pass this broken font onto the browser, which OTS unsurprisingly rejects.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1068432.
2016-05-07 21:09:58 +02:00
Jonas Jenwald
8b605b6980 Merge pull request #7298 from mortonfox/patch-1
Update link to CONTRIBUTING.md
2016-05-07 11:25:47 +02:00
Morton Fox
f697d83f59 Update link to CONTRIBUTING.md 2016-05-07 00:10:36 -04:00
Brendan Dahl
a682ccec2f Merge pull request #7285 from Snuffleupagus/split_font_unittests
Split the font_spec.js unit-tests into cff_parser_spec.js and type1_parser_spec.js
2016-05-05 13:45:27 -07:00
Jonas Jenwald
6111c17c8a Use Dict_getArray in more places in src/core/ to avoid issues when Arrays contain indirect objects
As evident from e.g. PRs 6485 and 7118, some bad PDF generators unfortunately create Arrays where *some* elements are indirect objects (i.e. `Ref`s). This seems to mostly affect Arrays that contain numbers, such as e.g. `Matrix/FontMatrix/BBox/FontBBox/Rect/Color/...`, and has manifested itself in PDF files that fail to render correctly (some elements are missing).

The problem in both the cases above, besides broken rendering, was that there were *no* errors/warnings that indicated what the problem was, making it difficult to pinpoint the issue.
Hence this patch, where I've audited all usages of `Dict_get` in `src/core/` files, and replaced it with `Dict_getArray` where appropriate to try and prevent unnecessary future bugs.
2016-05-05 19:42:57 +02:00
Yury Delendik
9f68e3f1bc Disable pagechange event if page is not changing. 2016-05-04 11:06:07 -05:00
Yury Delendik
8adddf031c Merge pull request #7242 from Snuffleupagus/bug-1194700
[Bug 1194700] Ensure that the `customScaleOption` is hidden in e10s
2016-05-03 07:06:43 -05:00
Jonas Jenwald
29c4a604af Split the font_spec.js unit-tests into cff_parser_spec.js and type1_parser_spec.js
Re: issue 7261.

Given the we have `gulp fonttest`, which tests the `fonts.js` functionality at a higher level, and that we have *a lot* of font specific reference tests, I'm not convinced that we *also* need unit-tests for it.
2016-05-03 09:37:36 +02:00
Tim van der Meij
9c95d089de Merge pull request #7281 from yurydelendik/static-warnings
Fixes some static analysis warnings and recommendations
2016-05-03 01:26:17 +02:00
Yury Delendik
32ce369d88 Fixes some static analysis warnings and recommendations
* Useless conditional
* Superfluous trailing arguments
* Useless assignment to local variable
* Misspelled identifier
* JSDoc tag for non-existent parameter
2016-05-02 17:34:58 -05:00
Tim van der Meij
d1799929c4 Merge pull request #7260 from yurydelendik/gulp-tests
Moves all testing into gulpfile.
2016-05-03 00:21:20 +02:00
Yury Delendik
7aff695969 Merge pull request #7279 from yurydelendik/cff-encodeint
Fixes unneed conversion to array in CFF encodeInteger.
2016-05-02 16:34:54 -05:00
Yury Delendik
4cde9984f9 Fixes unneed conversion to array in CFF encodeInteger. 2016-05-02 15:24:16 -05:00
Yury Delendik
fe6001363d Moves all testing into gulpfile. 2016-05-02 09:58:29 -05:00
Yury Delendik
d20002b6b1 Merge pull request #7273 from Snuffleupagus/issue-7270
Prevent "Prefixed Fullscreen API is deprecated." warnings in the MOZCENTRAL version (issue 7270)
2016-04-29 10:37:11 -05:00
Jonas Jenwald
9dd6017901 Prevent "Prefixed Fullscreen API is deprecated." warnings in the MOZCENTRAL version (issue 7270)
We're already, since quite some time, using the standard Fullscreen API provided that it's available in the browser. The warning is only caused by the code that checks if the Fullscreen API is supported.

This patch uses a simple preprocessor tag to avoid the warning, since I'm assuming that in general, we want to try and remain backwards compatible with the prefixed versions of the Fullscreen API.

Fixes 7270.
2016-04-29 17:28:24 +02:00
Yury Delendik
baa1493650 Merge pull request #7272 from yurydelendik/bug1268706
Adds post UI control change events.
2016-04-29 10:20:47 -05:00
Yury Delendik
4a2c76a34f Adds pre and post UI control change events. 2016-04-29 10:05:04 -05:00
Jonas Jenwald
4968ac7cea Merge pull request #7266 from yurydelendik/secondary
Removes circular dependency of secondary toolbar on app.js.
2016-04-29 11:18:59 +02:00
Yury Delendik
3cbaa9a499 Merge pull request #7268 from yurydelendik/components-samples
Better components examples.
2016-04-28 16:57:46 -05:00
Yury Delendik
eb3d1ca003 Removes circular dependency of secondary toolbar on app.js. 2016-04-28 15:04:09 -05:00
Yury Delendik
5f883d763f Better components examples. 2016-04-28 13:30:03 -05:00
Jonas Jenwald
61a4c740d2 Merge pull request #7254 from yurydelendik/eventbus
Introducing EventBus for the viewer UI.
2016-04-28 15:19:49 +02:00
Yury Delendik
3e6e294fd4 Refactors PDFFindBar and FirefoxCom find events. 2016-04-28 07:11:40 -05:00
Yury Delendik
7fd3db9977 Adds EventBus. 2016-04-28 06:57:24 -05:00
Yury Delendik
bd49973ee5 Merge pull request #7262 from yurydelendik/issue7231
Fixes weird loop in the bidi.js.
2016-04-27 17:18:57 -05:00
Yury Delendik
4016f9fd43 Fixes weird loop in the bidi.js.
Closes #7231.
2016-04-27 16:14:33 -05:00
Yury Delendik
4dc00b003d Merge pull request #7256 from timvandermeij/gulp-targets
Port the `publish` target to Gulp
2016-04-27 10:55:58 -05:00
Tim van der Meij
5166b46a1c Port the publish target to Gulp 2016-04-27 12:54:57 +02:00
Tim van der Meij
97b3a70df8 Merge pull request #7255 from timvandermeij/readme
Mention web application usage in README.md
2016-04-26 22:23:21 +02:00
Tim van der Meij
9c4bb83f7a Mention web application usage in README.md 2016-04-26 22:13:01 +02:00
Yury Delendik
11a2282b95 Merge pull request #7251 from yurydelendik/force-defines
Makes defines parameter non-optional in createBundle.
2016-04-26 08:04:04 -05:00
Yury Delendik
cca0e40aa2 Makes defines parameter non-optional in createBundle. 2016-04-26 07:54:07 -05:00
Tim van der Meij
f220db55be Merge pull request #7240 from yurydelendik/bundle
Moves bundle target/task to gulpfile.js
2016-04-26 01:00:00 +02:00
Yury Delendik
5568a19ee3 Moves bundle target/task to gulpfile.js 2016-04-24 08:37:39 -05:00
Yury Delendik
55581b162e Merge pull request #7202 from yurydelendik/firefox-deps
Refactors dependencies of PDFViewerApplication on external services
2016-04-24 08:32:17 -05:00
Yury Delendik
3132941948 Removes app.js dependency on mozPrintCallback_polyfill.js. 2016-04-24 08:25:55 -05:00
Yury Delendik
3b21b51716 Refactors preferences and PDF opening related chromecom code. 2016-04-24 08:25:55 -05:00
Yury Delendik
148102b626 Refactors firefoxcom dependency on app and l10n. 2016-04-24 08:25:55 -05:00
Yury Delendik
81fc46e666 Refactors FindController dependencies. 2016-04-24 08:25:55 -05:00
Rob Wu
b45e6a7cc9 Don't use shadow DOM for rendering <object>/<embed>
Multiple shadow roots are not supported any more in Chrome 51+
(https://crbug.com/603448#c6), so this patch changes the way that PDFs
are rendered in `<embed>` / `<object>` tags.

I used shadow roots because their content is not visible from the web
page, so the odds of conflicts were minimal. Now I have to render the
PDF frame directly in the page, which can be observed from the page
(unfortunately).

Now the following happens when an embedded PDF tag is detected:

- `<embed>` tags: The type and src attributes are updated.
- `<object>` tags: The type attribute is changed and the fallback
  content is set and displayed.
2016-04-23 23:52:22 +02:00
Jonas Jenwald
9d7d95ead4 [Bug 1194700] Ensure that the customScaleOption is hidden in e10s
When Firefox is run in e10s mode, which will soon be the default, the PDF.js zoom dropdown menu doesn't look right. This is apparently because the `<select>` DOM element is rendered in the parent, and that all the necessary style information isn't sent up from the child. See the discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=910022.

Besides this causing the PDF.js UI to *look* worse in e10s, notably it also means that the `customScaleOption` isn't hidden like it ought to be.
To work-around that, this patch utilizes the `hidden` attribute, since https://bugzilla.mozilla.org/show_bug.cgi?id=1242450 at least made that work in e10s.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1194700.
2016-04-23 15:57:51 +02:00
Yury Delendik
ff6669d930 Merge pull request #7241 from yurydelendik/server-importl10n-async
Makes importl10n and server async gulp functions.
2016-04-22 17:24:58 -05:00
Yury Delendik
76aa687548 Makes importl10n and server async gulp functions. 2016-04-22 17:23:25 -05:00
Yury Delendik
3d49879211 Merge pull request #7130 from nschloe/patch-1
Add element to text layer even if width === 0
2016-04-22 16:10:07 -05:00
Yury Delendik
f13119f237 Merge pull request #7237 from Snuffleupagus/issue-7232
Prevent accidentally overriding the `error` function in the `commonobj` messageHandler in api.js (issue 7232)
2016-04-22 12:49:01 -05:00
Jonas Jenwald
9ceeb21741 Prevent accidentally overriding the error function in the commonobj messageHandler in api.js (issue 7232)
This naming issue has been present since PR 3529, but at least I cannot find any issues/bugs that seem to have been caused by it, which is good.

The patch also removes an unnecessary `else` branch, since an already existing `break` means that it's redundant.

Fixes 7232.
2016-04-22 10:12:12 +02:00
Yury Delendik
ee4d8ef8f7 Merge pull request #7236 from yurydelendik/release1.5.188
Release of 1.5.188
2016-04-21 15:16:09 -05:00
Yury Delendik
e20a217177 Release of 1.5.188 2016-04-21 15:11:26 -05:00
Yury Delendik
0e2d50f8e6 Merge pull request #7235 from yurydelendik/version1.5
Version 1.5
2016-04-21 15:10:16 -05:00
Yury Delendik
c5f2cd6dd4 Version 1.5 2016-04-21 15:07:19 -05:00
Jonas Jenwald
4aac324558 Merge pull request #7209 from yurydelendik/getElementById
Moves all document.getElementById lookups into viewer.js
2016-04-21 21:55:37 +02:00
Yury Delendik
b6c74f2056 Moves all document.getElementById lookups into viewer.js 2016-04-21 11:39:11 -05:00
Yury Delendik
d5c000850a Merge pull request #7233 from Snuffleupagus/issue-7229
Adjust incorrect first obj number of "free" xref entry in `XRef_readXRefTable` (issue 7229)
2016-04-21 10:00:19 -05:00
Jonas Jenwald
293901d7e5 Add a (linked) test-case for issue 3248 2016-04-21 16:36:46 +02:00
Jonas Jenwald
e281ef15db Adjust incorrect first obj number of "free" xref entry in XRef_readXRefTable (issue 7229)
Fixes 7229.
2016-04-21 16:36:32 +02:00
Jonas Jenwald
2001953871 Merge pull request #7219 from timvandermeij/password-prompt-class
Convert the password prompt to a class
2016-04-21 15:19:34 +02:00
Tim van der Meij
2b7137ba0a Convert the password prompt to a class
Furthermore we introduce two new methods named `setCallback` and
`setReason` so external code does not change the properties of the class
directly. Finally we update various names of properties and methods to
be more self-explanatory.
2016-04-21 14:06:10 +02:00
Jonas Jenwald
990150ce61 Update l10n files 2016-04-19 13:32:25 +02:00
Yury Delendik
3228c9445c Merge pull request #7210 from Snuffleupagus/extract-PDFImage.resize
Split the two paths in `PDFImage.resize` into separate helper functions, placed in colorspace.js and image.js
2016-04-17 07:49:37 -05:00
Jonas Jenwald
19e0599f74 Split the two paths in PDFImage.resize into separate helper functions, placed in colorspace.js and image.js
Re: issue 6777.
2016-04-17 10:24:36 +02:00
Yury Delendik
0428fdf3ca Merge pull request #7211 from Snuffleupagus/crypto-tests-NEED_PASSWORD
Add a couple of `CipherTransformFactory` unit-tests for blank passwords, and move the `isDict` unit-tests to the correct file
2016-04-16 20:02:05 -05:00
Jonas Jenwald
b4a17323b6 Move isDict unit-tests from util_spec.js to primitives_spec.js
This patch moves the unit-test to the correct file, since the `isDict` function was moved PR 6683.
2016-04-16 20:32:46 +02:00
Jonas Jenwald
4523ae0b91 Add a couple of CipherTransformFactory unit-tests to check that blank passwords are correctly rejected 2016-04-16 20:24:55 +02:00
Tim van der Meij
a093d755b7 Merge pull request #7207 from timvandermeij/hand-tool-class
Convert the hand tool to a class
2016-04-16 19:32:58 +02:00
Tim van der Meij
b0aca31de8 Convert the hand tool to a class 2016-04-16 19:20:37 +02:00
Jonas Jenwald
7f90f5bfed Merge pull request #7206 from Snuffleupagus/viewer-expose-non-classes-on-PDFViewerApplication
Expose a few non-classes on `PDFViewerApplication`
2016-04-16 16:43:22 +02:00
Jonas Jenwald
9dfda2b908 Expose a few non-classes on PDFViewerApplication
With the recent PR 7172, which made the viewer modular, there's now a couple of modules that are no longer easily accessible (e.g. through the console).
This can make testing/debugging more difficult, and means that e.g. https://github.com/mozilla/pdf.js/wiki/Debugging-PDF.js#enabling no longer works in the generic viewer.

For now, as a simple solution, this patch just exposes those non-classes on `PDFViewerApplication` to ensure that they are available, and to avoid polluting the `window` scope.
2016-04-16 16:23:21 +02:00
Tim van der Meij
452c031af5 Merge pull request #7116 from Snuffleupagus/refactor-LinkAnnotation-tests
Refactor `LinkAnnotation` slightly, improve handling of the `GoToR` action, and add unit-tests
2016-04-16 15:46:41 +02:00
Tim van der Meij
ff65c8021f Merge pull request #7190 from Snuffleupagus/sidebarviewchanged-event
Dispatch a `sidebarviewchanged` event in `PDFSidebar` when the view changes
2016-04-16 14:58:50 +02:00
Ankit Aggarwal
6ceda3f290 web/viewer.js: Persist the state of sidebar
Persist the state of content sidebar while browsing away from viewer and
initializing the same on returning back to the viewer. The state is saved
in persistent store preferences and used upon viewer initialization.

Fixes #6935
2016-04-16 10:17:42 +02:00
Jonas Jenwald
5657d082c7 Dispatch a sidebarviewchanged event in PDFSidebar when the view changes
We cannot piggy-back on the `updateviewarea` event in order to update the stored sidebar state, since there're a number of cases where opening/switching the sidebar view won't fire a `updateviewarea` event.
Note that `updateviewarea` only fires when the position changes in the *viewer*, which means that it won't fire if e.g. the viewer is narrow, such that the sidebar overlays the document transparently; or when switching views, without the document position also changing.

This patch also moves the handling of `forceOpen` parameter in `PDFSidebar_switchView`, to prevent triggering back-to-back rendering and dispatching of events.
2016-04-16 10:10:28 +02:00
Jonas Jenwald
171f908b89 Add a couple of LinkAnnotation unit-tests
We currently don't have *any* unit-tests for `LinkAnnotation`s, so it seemed a good idea to add a few. These tests are taken from various actual PDF files.
2016-04-15 22:59:08 +02:00
Jonas Jenwald
f3f825cc71 Various improvements for GoToR actions
- Add support for the 'NewWindow' property.

 - Ensure that destinations are applied to the *remote* document, instead of the current one.

 - Handle the `F` entry being a standard string, instead of a dictionary.
2016-04-15 22:55:05 +02:00
Jonas Jenwald
b63ef7a8b6 Refactor LinkAnnotation slightly to add data.url/data.dest at the end
This patch also makes sure that all URLs are converted to the correct encoding.
2016-04-15 22:55:05 +02:00
Tim van der Meij
4a601ffc28 Merge pull request #7197 from prakashpalanisamy/remove-combineurl-test
Remove `combineUrl` and replace it with `new URL`. Issue #7183, for reference.
2016-04-15 22:44:07 +02:00
Prakash Palanisamy
a25c29d98d Remove combineUrl and replace it with new URL. 2016-04-15 21:33:10 +05:30
Jonas Jenwald
5c17df9f07 Merge pull request #7201 from Snuffleupagus/issue-7200
Ensure that the `params` parameter of the `PredictorStream` is a dictionary (issue 7200)
2016-04-15 16:59:54 +02:00
Jonas Jenwald
079b563e2d Ensure that the params parameter of the PredictorStream is a dictionary (issue 7200)
Fixes 7200.
2016-04-15 16:30:18 +02:00
Yury Delendik
e9dbb233aa Merge pull request #7191 from Snuffleupagus/export-DefaultAnnotationLayerFactory
Export the `DefaultAnnotationLayerFactory` to prevent the viewer components from breaking (PR 7172 followup)
2016-04-13 10:50:15 -05:00
Jonas Jenwald
c98f25145f Export the DefaultAnnotationLayerFactory to prevent the viewer components from breaking (PR 7172 followup) 2016-04-13 17:42:04 +02:00
Yury Delendik
6282ec24d1 Merge pull request #7172 from yurydelendik/umd-web
Introduces UMD headers to the web/ folder.
2016-04-13 10:23:23 -05:00
Yury Delendik
50fe8e7c75 Removes PDFView global and pagerender event support. 2016-04-13 10:11:43 -05:00
Yury Delendik
4165cedc9f Replace pdfjsLib with module that represents pdf.js. 2016-04-13 10:11:34 -05:00
Yury Delendik
006e8fb59d Introduces UMD headers to the web/ folder. 2016-04-13 10:09:48 -05:00
Yury Delendik
fa2f80d0fd Merge pull request #7189 from yurydelendik/webpack-browserify-love
Removing "entry-loader" dependency from webpack.
2016-04-13 08:42:11 -05:00
Yury Delendik
ae415f9e80 Removing "entry-loader" dependency from webpack. 2016-04-13 08:24:25 -05:00
Yury Delendik
b834b6899c Merge pull request #7185 from iloire/issue-7177-support-almondjs
Support almond.js #7177
2016-04-12 17:21:03 -05:00
Jonas Jenwald
127e6d7343 Merge pull request #7184 from yurydelendik/pad-mesh
[Bug 1260585] Stops bleeding of pattern edges for mesh.
2016-04-12 12:47:38 +02:00
Ivan Loire
1dfc49152a Support almond.js #7177 2016-04-12 09:32:07 +10:00
Yury Delendik
398e6acbc5 Stops bleeding of pattern edges for mesh. 2016-04-11 18:21:44 -05:00
Jonas Jenwald
be6754a1a0 Merge pull request #7176 from yurydelendik/smask-resume
Allow SMask be resumed after restore() and better transform after SMask
2016-04-11 15:57:40 +02:00
Yury Delendik
d76db416f4 Adds more SMask tests. 2016-04-11 08:02:06 -05:00
Yury Delendik
63f62a0e53 Finishing SMask at the end of operators list. 2016-04-11 08:02:06 -05:00
Yury Delendik
1485c1d1da Suspending/resuming SMask operation during setGState/restore. 2016-04-11 08:02:06 -05:00
Yury Delendik
b2828858ed Merge pull request #7178 from yurydelendik/rm-describe-test-hack
Removes hijack describe() hack from unit tests.
2016-04-11 07:58:41 -05:00
Yury Delendik
879340d741 Removes hijack describe() hack from unit tests. 2016-04-11 07:37:35 -05:00
Yury Delendik
44c63bca28 Merge pull request #7175 from Snuffleupagus/issue-6905-font_spec
Use `beforeAll`/`afterAll` in font_spec.js (issue 6905)
2016-04-11 07:20:45 -05:00
Yury Delendik
070f2d32ad Merge pull request #7171 from Snuffleupagus/remove-new-Name/Cmd
Remove the remaining usages of `new {Name,Cmd}` in favor of `{Name,Cmd}.get`
2016-04-11 07:17:30 -05:00
Jonas Jenwald
c4e21c93a2 Use beforeAll/afterAll in font_spec.js (issue 6905)
This patch fixes the only remaining point in issue 6905.
2016-04-10 16:09:11 +02:00
Tim van der Meij
5f925a561e Merge pull request #7174 from Snuffleupagus/issue-6905-crypto_spec
Use `beforeAll`/`afterAll` in `CipherTransformFactory` in crypto_spec.js (issue 6905)
2016-04-10 14:13:24 +02:00
Jonas Jenwald
b0ce83b372 Use beforeAll/afterAll in CipherTransformFactory in crypto_spec.js (issue 6905
This patch also adds/improves utility functions for checking if the passwords are correct/incorrect, and replaces `string2binary` with `stringToBytes`. Finally the patch does away with the `DictMock`, in favour of using actual `Dict`s.

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

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

Given the small size of the patch, I'm also tweaking a few comments and class names.
2016-04-08 12:14:05 +02:00
Yury Delendik
1c253e6e1d Merge pull request #7170 from Snuffleupagus/pr-7097-followup
Prevent the *entire* viewer from zooming, when quickly switching from scrolling to zooming using the mousewheel (PR 7097 followup)
2016-04-07 14:55:00 -05:00
Jonas Jenwald
514210814d Prevent the *entire* viewer from zooming, when quickly switching from scrolling to zooming using the mousewheel (PR 7097 followup)
This is a regression from PR 7097.

(Also, out of scope for this PR, but I think that a `setTimeout` value of `1000 ms` is too large. Switching from scrolling to zooming can fell sluggish, and give the impression that nothing happens.)
2016-04-07 21:04:52 +02:00
Brendan Dahl
f351eb23aa Merge pull request #7097 from prometheansacrifice/zoom-due-to-scroll-inertia
Prevents document zooming if still scrolling and meta keys pressed (Issue #7022)
2016-04-07 11:52:10 -07:00
Brendan Dahl
68e8f5fff5 Merge pull request #7126 from yurydelendik/rm-pdfjs-display
Move all PDFJS display/ usages into global.js file.
2016-04-07 11:47:58 -07:00
Yury Delendik
1e4886a15a Remove global window and navigator usages from the core code. 2016-04-07 13:46:07 -05:00
Yury Delendik
1e3e14e6b2 Exposes all functional members via lib exports and use them in viewer. 2016-04-07 13:46:07 -05:00
Yury Delendik
1d12aed5ca Move all PDFJS.xxx settings into display/global. 2016-04-07 13:46:07 -05:00
Tim van der Meij
bc8df673a6 Merge pull request #7164 from Snuffleupagus/issue-6905-dom_utils_spec
Use `beforeAll`/`afterAll` in `isExternalLinkTargetSet` in dom_utils_spec.js (issue 6905)
2016-04-07 20:39:01 +02:00
Yury Delendik
6123c0367f Merge pull request #7169 from yurydelendik/jspm-format
Specifies package format for jspm.
2016-04-07 11:58:07 -05:00
Yury Delendik
38c41d86c6 Specifies package format for jspm. 2016-04-07 11:52:56 -05:00
Manas
6878d7c6d3 Disables zooming when the stream of events that don't have meta/ctrl
keys active at the outset, for 1000ms
2016-04-07 22:18:46 +05:30
Jonas Jenwald
c6c5b8fab8 Use beforeAll/afterAll in isExternalLinkTargetSet in dom_utils_spec.js (issue 6905)
Re: issue 6905.
2016-04-07 14:00:40 +02:00
Tim van der Meij
911a2ca1c6 Merge pull request #7158 from timvandermeij/readme
Update Webpack and Browserify example README files
2016-04-06 18:44:31 +02:00
Tim van der Meij
b293d1caf5 Update Webpack and Browserify example README files
Previously the commands were not properly parsed as such by GitHub
because they need to be indented with four spaces.

Furthermore, address some minor textual nits.
2016-04-06 18:36:41 +02:00
Yury Delendik
6c9f418aae Merge pull request #7150 from yurydelendik/browserify
Initial browserify example.
2016-04-06 09:45:55 -05:00
Yury Delendik
47688b655a Merge pull request #7144 from yurydelendik/mv-viewer-2
Prepare viewer.js for async loading and module separation.
2016-04-06 09:40:59 -05:00
Yury Delendik
f9a0dc1188 Merge pull request #7114 from dhuseby/Bug_1237908
[Bug 1237908] Make pdf.js use the correct principal origin attributes when loading …
2016-04-06 09:38:11 -05:00
Dave Huseby
867a5ea1b0 Make pdf.js use the correct principal origin attributes when loading subresources. 2016-04-04 14:12:51 -07:00
Yury Delendik
d7d7935648 Initial browserify example. 2016-04-04 11:32:01 -05:00
Yury Delendik
2dd03e1785 Merge pull request #7148 from yurydelendik/force-cjs-path
Forces UMD header to have relative path and extension for CommonJS.
2016-04-02 11:59:29 -05:00
Yury Delendik
118b71925c Forces UMD header to have relative path and extension for CommonJS. 2016-04-02 11:10:36 -05:00
Yury Delendik
34aa915441 Merge pull request #7146 from Snuffleupagus/extract-CFFParser
Extract CFFParser and Type1Parser from fonts.js
2016-04-02 10:50:38 -05:00
Yury Delendik
055d642bf2 Merge pull request #7107 from Rob--W/worker-loading
Detect premature worker load error
2016-04-02 10:40:26 -05:00
Rob Wu
c8996f654f Detect and handle premature worker load error
Fall back to a fake worker if the worker fails to load or initialize,
e.g. due to a network error, a security error or simply a script error.
2016-04-02 11:06:15 +02:00
Jonas Jenwald
ef551e8266 Extract Type1Parser from fonts.js 2016-04-01 23:38:53 +02:00
Jonas Jenwald
b961e1d21b Extract CFFParser from fonts.js (issue 6777) 2016-04-01 22:32:39 +02:00
Yury Delendik
313b418a20 Prepare viewer.js for async loading and module separation. 2016-04-01 10:29:44 -05:00
Yury Delendik
b371785fbb Rename web/viewer.js -> web/app.js 2016-04-01 10:27:16 -05:00
Yury Delendik
a250c150ab Merge pull request #7134 from yurydelendik/circ-stream-colorspace
Refactors to remove stream.js dependency on colorspace.js
2016-04-01 08:23:24 -05:00
Yury Delendik
ff3ce973b8 Merge pull request #7106 from Snuffleupagus/issue-7101
Keep track of the character to glyph mapping in font_renderer.js, to prevent errors when different characters point to the same glyph (issue 7101)
2016-04-01 08:09:21 -05:00
Yury Delendik
35cbf74b12 Refactors to remove stream.js dependency on colorspace.js 2016-04-01 07:36:16 -05:00
Brendan Dahl
13d440df61 Merge pull request #7078 from Snuffleupagus/refactor-toFontChar-without-file
Refactor the building of `toFontChar` for non-embedded fonts
2016-03-31 10:43:11 -07:00
Brendan Dahl
8910cea7d6 Merge pull request #7066 from Snuffleupagus/Type1-headerBlockLength
Parse Type1 font files to determine the various `Length{n}` properties, instead of trusting the PDF file (issue 5686, issue 3928)
2016-03-31 09:25:16 -07:00
Jonas Jenwald
05cf709f8e Parse Type1 font files to determine the various Length{n} properties, instead of trusting the PDF file (issue 5686, issue 3928)
Fixes 5686.
Fixes 3928.
2016-03-31 11:08:12 +02:00
Jonas Jenwald
c40df8a393 Make Type1Font more class-like, by adding closure
*Note:* Ignoring whitespace should simplify reviewing a great deal.
2016-03-31 11:00:27 +02:00
Yury Delendik
447c48ea27 Merge pull request #7133 from Snuffleupagus/faster-unittests-beforeAll-afterAll
Faster unit-tests by using `beforeAll`/`afterAll` in api_spec.js
2016-03-30 09:28:16 -05:00
Jonas Jenwald
7163e1eff3 Faster unit-tests by using beforeAll/afterAll in api_spec.js
In the API unit-tests, we're currently loading the `basicapi.pdf` before every sub-test in `PDFDocument` and `Page`, which slows down the unit-tests quite a bit.
Locally this patch reduces the run time for `gulp unittest` by at least 40% for me.
2016-03-30 15:32:01 +02:00
Jonas Jenwald
17aaa125df Keep track of the character to glyph mapping in font_renderer.js, to prevent errors when different characters point to the same glyph (issue 7101)
Fixes 7101.
2016-03-30 11:33:04 +02:00
Yury Delendik
bec4891f5d Merge pull request #7102 from brendandahl/onerror
Log uncaught global errors.
2016-03-29 17:23:28 -05:00
Tim van der Meij
6d2b195857 Merge pull request #7128 from Snuffleupagus/issue-6204-unittest
Add unit-tests for destionations in /Names (NameTree) dictionaries where all entries are indirect objects
2016-03-29 22:44:22 +02:00
Nico Schlömer
7cb055307d Add element to text layer even if width === 0
Some browsers render certain special characters with width 0, others with strictly positive width. (For example, the Greek Delta, Δ, has width 0 in Google Chrome, and a positive width in Firefox.) The `if` clause in operation so far results in different text layer DOM trees for different browsers.

This commit fixes that by adding the elements independently of their width.
2016-03-29 19:32:51 +02:00
Brendan Dahl
4e2f70440f Merge pull request #6711 from yurydelendik/errors
Better errors capturing at the core and stop rendering on error.
2016-03-29 09:19:28 -07:00
Jonas Jenwald
ac772017b6 Add unit-tests for destionations in /Names (NameTree) dictionaries where all entries are indirect objects
Re: issue 6204 and PR 6208.
2016-03-29 17:55:05 +02:00
Yury Delendik
df0cbccfd8 Merge pull request #7129 from yurydelendik/jasmine
Updates Jasmine version.
2016-03-29 10:32:17 -05:00
Yury Delendik
0a700fa29d Updates Jasmine version. 2016-03-29 09:34:13 -05:00
Tim van der Meij
553928c26e Merge pull request #7118 from Snuffleupagus/issue-7115
Prevent failures in the Annotation code if the `Rect` array contains indirect objects (issue 7115)
2016-03-29 00:04:59 +02:00
Yury Delendik
27dd386248 Merge pull request #7122 from Snuffleupagus/issue-7117
Allow unit-tests to use linked PDF files, by having the `unittest` command download unavailable ones (issue 7117)
2016-03-28 10:19:17 -05:00
Jonas Jenwald
8f097abb46 Allow unit-tests to use linked PDF files, by having the unittest command download unavailable ones (issue 7117) 2016-03-27 13:17:55 +02:00
Jonas Jenwald
13d7a5070e Prevent failures in the Annotation code if the Rect array contains indirect objects (issue 7115)
Note that in the PDF files provided by the reporter, this issue was limited to `Rect` arrays in AcroForm entries (which we currently don't support).
However, since a bad PDF generator could create this problem in *any* kind of annotation, the reduced test-case included here uses a simple LinkAnnotation instead.

Fixes 7115.
2016-03-26 20:55:16 +01:00
Brendan Dahl
df7afcf004 Merge pull request #7053 from yurydelendik/rm-pdfjs-core
Removes global PDFJS usage from the src/core/.
2016-03-25 13:19:43 -07:00
Yury Delendik
c22c85f8ee Merge pull request #7113 from yurydelendik/disable-issue6961
Disables issue6961 test.
2016-03-25 13:12:36 -05:00
Yury Delendik
a505aa8e90 Disables issue6961 test. 2016-03-25 12:48:11 -05:00
Jonas Jenwald
b589add2b5 Update l10n files 2016-03-25 14:10:56 +01:00
Brendan Dahl
7aa864db3e Merge pull request #7108 from yurydelendik/frontWindow-null
Removes frontWindow usage from the stream converter.
2016-03-24 10:24:13 -07:00
Yury Delendik
2b246192e1 Removes frontWindow usage from the stream converter. 2016-03-24 11:47:34 -05:00
Tim van der Meij
da8e345d14 Merge pull request #7005 from tobytailor/master
Fixes insertion of blank pages during print if page sizes differ
2016-03-24 14:38:27 +01:00
Yury Delendik
2fa4dd6f40 Proxy global PDFJS.verbosity to properly configure shared/util. 2016-03-23 19:24:37 -05:00
Yury Delendik
a8e5912cb1 Moves shared/global to display/global 2016-03-23 19:24:37 -05:00
Yury Delendik
e372f3608b Makes WorkerMessageHandler non-global. 2016-03-23 19:24:37 -05:00
Yury Delendik
bda5e6235e Removes global PDFJS usage from the src/core/. 2016-03-23 19:24:37 -05:00
Tim van der Meij
e1ac5744d0 Merge pull request #7105 from fkaelberer/fkaelberer-issue-template
Add an ISSUE_TEMPLATE
2016-03-23 22:59:45 +01:00
fkaelberer
4eb9daf34a Add an ISSUE_TEMPLATE 2016-03-23 22:48:14 +01:00
Brendan Dahl
fb47490648 Log uncaught global errors. 2016-03-22 15:49:32 -07:00
Yury Delendik
54ee15d866 Merge pull request #7100 from yurydelendik/stream-wo-parser
Removes core/stream circular dependency on core/parser.
2016-03-22 15:08:12 -05:00
Yury Delendik
4a44a2c7dc Merge pull request #7098 from Snuffleupagus/uint32-checksums
Ensure that TrueType font tables have `uint32` checksums
2016-03-22 14:11:27 -05:00
Yury Delendik
6038c236b2 Removes core/stream circular dependency on core/parser. 2016-03-22 14:06:01 -05:00
Jonas Jenwald
d78fae0181 Ensure that TrueType font tables have uint32 checksums
According to "The table directory" under https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html#Directory, TrueType font tables should have `uint32` checksums.

This is something that I noticed, and was initially confused about, while debugging a TrueType issue.
As far as I can tell, the current (`int32`) checksums we use doesn't cause any issues in practice. However, I do think that this should be addressed to agree with the specification, and to reduce possible confusion when reading the font code.
2016-03-22 13:40:50 +01:00
Tobias Schneider
708895ffba Let print canvas height scale proportionally 2016-03-21 14:21:07 -07:00
Tobias Schneider
aeabd0db20 Fix insertion of blank pages during printing due to non-matching page sizes 2016-03-21 14:21:07 -07:00
Yury Delendik
21ed8ff71d Merge pull request #7039 from prometheansacrifice/async-cmap-factory
Refactors CMapFactory.create to make it async
2016-03-21 13:57:36 -05:00
Manas
f6d28ca323 Refactors CMapFactory.create to make it async 2016-03-21 23:08:19 +05:30
Tim van der Meij
7ad8f3a6f0 Merge pull request #7093 from Snuffleupagus/gulp-importl10n-dir-fix
Use the correct path when checking if a `/l10n` directory exists, to avoid errors during `gulp importl10n` (PR 7063 followup)
2016-03-20 22:12:30 +01:00
Jonas Jenwald
41e5fa3c7a Use the correct path when checking if a /l10n directory exists, to avoid errors during gulp importl10n (PR 7063 followup)
This is regression from PR 7063, causing `gulp importl10n` to fail:
```
$ gulp importl10n
[19:45:02] Using gulpfile c:\Users\Jonas\Git\pdfjs\gulpfile.js
[19:45:02] Starting 'importl10n'...

Downloading ach...
[19:45:02] 'importl10n' errored after 4.42 ms
[19:45:02] Error: EEXIST, file already exists 'c:\Users\Jonas\Git\pdfjs\l10n\ach
'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:747:18)
    at downloadLanguageFiles (c:\Users\Jonas\Git\pdfjs\external\importL10n\local
es.js:59:8)
    at next (c:\Users\Jonas\Git\pdfjs\external\importL10n\locales.js:90:5)
    at Object.downloadL10n (c:\Users\Jonas\Git\pdfjs\external\importL10n\locales
.js:91:5)
    at Gulp.<anonymous> (c:\Users\Jonas\Git\pdfjs\gulpfile.js:92:11)
    at module.exports (c:\Users\Jonas\Git\pdfjs\node_modules\gulp\node_modules\o
rchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (c:\Users\Jonas\Git\pdfjs\node_modules\gulp\no
de_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (c:\Users\Jonas\Git\pdfjs\node_modules\gulp\no
de_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (c:\Users\Jonas\Git\pdfjs\node_modules\gulp\node_
modules\orchestrator\index.js:134:8)
```
2016-03-20 20:02:43 +01:00
Brendan Dahl
56f5c3a5ff Merge pull request #7088 from Snuffleupagus/issue-6957
Pass the `PDFJS.postMessageTransfer` parameter to the worker, so that the `MessageHandler` can be setup correctly in `createDocumentHandler` (issue 6957)
2016-03-18 13:08:46 -07:00
Jonas Jenwald
91756f6e86 Pass the PDFJS.postMessageTransfer parameter to the worker, so that the MessageHandler can be setup correctly in createDocumentHandler (issue 6957)
This regressed in commit acdd49f480, i.e. PR 6571.

Fixes 6957.
2016-03-16 18:34:26 +01:00
Jonas Jenwald
122d473239 Merge pull request #7084 from timvandermeij/gulp-fix
Revert renaming `node make` to `gulp` for `mozcentral`
2016-03-14 10:25:11 +01:00
Tim van der Meij
2b6d7ba3ec Gulp: allow passing parameters and revert one node make renaming 2016-03-13 21:53:17 +01:00
Yury Delendik
c6d2b7f9d9 Merge pull request #6906 from KamiHQ/fix-printing
avoid apply transform twice for composite context
2016-03-11 08:26:59 -06:00
Yury Delendik
8ba413e761 Better errors capturing at the core and stop rendering on error. 2016-03-11 07:59:09 -06:00
Jonas Jenwald
cd2bd057ab Refactor the building of toFontChar for non-embedded fonts
Currently there's a lot of duplicate code for non-embedded `toFontChar`, which this patch simplifies by extracting the code into a helper function instead.
2016-03-10 21:25:39 +01:00
Tim van der Meij
4784863ef7 Merge pull request #7069 from Snuffleupagus/TrueType-recover-glyphNames
Convert `uniXXXX` glyph names to proper ones when building the `charCodeToGlyphId` map for TrueType fonts (bug 1132849, issue 6893, issue 6894)
2016-03-10 20:45:59 +01:00
Jonas Jenwald
dfe9015a43 Convert uniXXXX glyph names to proper ones when building the charCodeToGlyphId map for TrueType fonts (bug 1132849, issue 6893, issue 6894)
This patch adds a `getUnicodeForGlyph` helper function, which is used to recover Unicode values for non-standard glyph names.

Some PDF generators, e.g. Scribus PDF, use improper `uniXXXX` glyph names which breaks the glyph mapping. We can avoid this by converting them to "standard" glyph names instead.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1132849.
Fixes 6893.
Fixes 6894.
2016-03-09 19:37:15 +01:00
Tim van der Meij
147598417c Merge pull request #7046 from a0preetham/zero_descent_fix
fonts.js: bad metric overrides when values are zero
2016-03-09 12:14:03 +01:00
Yury Delendik
4065a21f8c Merge pull request #7029 from Snuffleupagus/PDFThumnailView-refactor-canvas-to-image
[PDFThumbnailView] Re-factor the `canvas` to `image` conversion such that we always render to a `canvas`, and then replace it with an `image` once rendering is done
2016-03-07 14:00:39 -06:00
Yury Delendik
b540d7d6dc Merge pull request #7063 from timvandermeij/gulp
Migrate `clean` and `importl10n` target to gulp
2016-03-07 13:29:29 -06:00
Tim van der Meij
96cca2b37a Migrate clean and importl10n target to gulp 2016-03-04 21:14:56 +01:00
Tim van der Meij
b8aaa24257 Convert all node make instances to gulp 2016-03-04 20:30:36 +01:00
Tim van der Meij
ec1cf28679 Merge pull request #7061 from yurydelendik/gulp
Introducing gulp
2016-03-04 19:25:52 +01:00
Yury Delendik
262d1e0863 Import L10n files. 2016-03-04 09:50:51 -06:00
Yury Delendik
9798e1007e Introducing gulp. 2016-03-04 09:36:46 -06:00
Preetham Mysore
be1e12dbcb Fix for descent calculation while reading font hhea headers 2016-03-03 08:51:41 -05:00
Tim van der Meij
51f6aba0a0 Merge pull request #7054 from timvandermeij/fix-typo
Correct a minor name issue in the outline viewer code
2016-03-02 22:58:05 +01:00
Tim van der Meij
f4bb23a66b Correct a minor name issue in the outline viewer code 2016-03-02 22:51:31 +01:00
Tim van der Meij
d302ac612e Merge pull request #6943 from Snuffleupagus/outline-styles
Add support for bold/italic styled outline items in the viewer
2016-03-02 22:42:03 +01:00
Yury Delendik
e1906035ca Merge pull request #7052 from yurydelendik/issue7048
Reverts back un-need change made at #6879.
2016-03-02 11:22:48 -06:00
Yury Delendik
a022f6f069 Reverts back un-need change made at #6879. 2016-03-02 09:57:33 -06:00
Jonas Jenwald
8402c79171 Merge pull request #7050 from brendandahl/issue4402
For CIDFontType2 use CID as glyph ID when missing CID to GID map.
2016-03-02 10:11:42 +01:00
Jonas Jenwald
9b126711cd Add support for bold/italic styled outline items in the viewer 2016-03-02 09:56:58 +01:00
Brendan Dahl
a6acf74b54 Merge pull request #7023 from brendandahl/issue6721
Only draw glyphs on canvas if they are in the font or the font file is missing.
2016-03-01 18:03:37 -08:00
Brendan Dahl
6e1d131384 For CIDFontType2 use CID as glyph ID when missing CID to GID map. 2016-03-01 17:05:33 -08:00
Brendan Dahl
6b1de4aa38 Merge pull request #7049 from Snuffleupagus/issue-7020
Avoid accidentally getting the entire font file in `readNameTable` (issue 7020)
2016-03-01 16:39:40 -08:00
Brendan Dahl
ff87f3fb86 Only draw glyphs on canvas if they are in the font or the font file is missing. 2016-03-01 13:24:58 -08:00
Jonas Jenwald
505f15f221 Avoid accidentally getting the entire font file in readNameTable (issue 7020)
In the PDF file in question, some of the 'name' table entries have `record.length === 0`. This becomes problematic in the non-unicode case, since `font.getBytes(0)` will fetch the *entire* stream.
Given that OTS rejects 'name' entries larger than `2^16`, this thus explain the sanitizer errors.

Fixes 7020.
2016-03-01 21:59:49 +01:00
Yury Delendik
22341c0761 Merge pull request #6879 from yurydelendik/streams
Makes PDF data reading Streams API friendly.
2016-03-01 09:10:52 -06:00
Tim van der Meij
4d9a3d4fb9 Merge pull request #7040 from Snuffleupagus/remove-PDFThumbnailViewer_ensureThumbnailVisible
Remove `PDFThumbnailViewer_ensureThumbnailVisible`
2016-02-28 20:06:56 +01:00
Jonas Jenwald
39cba5d25d Remove PDFThumbnailViewer_ensureThumbnailVisible
Functionality wise, `ensureThumbnailVisible` is essentially just a shorthand for `scrollThumbnailIntoView`. (And note that `PDFViewer` doesn't implement a `ensurePageVisible` method.)

The only remaining usage of `PDFThumbnailViewer_ensureThumbnailVisible` is inside `PDFPresentationMode`, which introduces an otherwise unnecessary `PDFThumbnailViewer` dependency there.

We're already relying on the `presentationmodechanged` event, in various files, to track the state of Presentation Mode. Thus we can simply listen for that event in `PDFSidebar` too, and update the thumbnails if necessary.
2016-02-28 18:21:59 +01:00
Jonas Jenwald
b5582e14a9 [PDFThumbnailView] Re-factor the canvas to image conversion such that we always render to a canvas, and then replace it with an image once rendering is done
*This is a follow-up to PRs 6299 and 6441.*

The patch also adds an option to `PDFThumbnailView`, that disables the canvas-to-image conversion entirely, which might be useful in the context of issue 7026.
2016-02-28 18:18:12 +01:00
Tim van der Meij
9ff6c83bb6 Merge pull request #7038 from Snuffleupagus/refactor-sidebar
Move the sidebar related code from viewer.js into `PDFSidebar`
2016-02-28 14:58:47 +01:00
Jonas Jenwald
67a1dfcfb5 Move the sidebar related code from viewer.js into PDFSidebar
The sidebar code has, except for minor fixes/additions (such as attachments), been largely untouch for years.
To avoid having a bunch of sidebar code sprinkled throughout viewer.js, this patch moves the sidebar code into a separate file (pdf_sidebar.js), similar to how most other functionality has been moved in the last few years.

Besides simply moving code around, this patch also has the added benefit that we now keep track of the sidebar state (not just opened/closed).
This now makes it possible to handle both `Preferences` *and* `ViewHistory` settings for the sidebar state in a cleaner way, preventing strange and confusing interactions between the two.
2016-02-27 14:13:09 +01:00
Jonas Jenwald
21f048234d Refactor how PDFOutlineView/PDFAttachmentView is initialized in viewer.js, rename the classes, and refactor their render methods
Changes `PDFOutlineView`/`PDFAttachmentView` to be initialized once, since we're always creating them, and refactor their `render` methods to instead pass in the `outline`/`attachments`.

For consistency with other "classes", the `PDFOutlineView`/`PDFAttachmentView` are renamed to `PDFOutlineViewer`/`PDFAttachmentViewer`.

Also, make sure that the outline/attachments are reset when the document is closed. Currently we keep the old ones around until the `getOutline`/`getAttachments` API calls are resolved for a new document.
2016-02-27 14:13:08 +01:00
Tim van der Meij
7cb3c365ca Merge pull request #7035 from Snuffleupagus/issue-7034
Ensure that `PDFFindController_reset` actually resets *all* state (issue 7034)
2016-02-27 13:58:14 +01:00
Tim van der Meij
915eac3d20 Merge pull request #7036 from Snuffleupagus/svg-example-set-cmap-url
[SVG] Specify the `PDFJS.cMapUrl`/`PDFJS.cMapPacked` parameters in the svgviewer example
2016-02-27 13:27:37 +01:00
Jonas Jenwald
4a6575643b [SVG] Specify the PDFJS.cMapUrl/PDFJS.cMapPacked parameters in the svgviewer example
Re: issue 7017.
This should prevent the error, but does not fix the broken rendering.

The rendering issues are caused by `svg.js` not supporting the various text rendering modes, in this case specifically "invisible" (as indicated in the console `Warning: Unimplemented method setTextRenderingMode`).

Compared to the canvas case, where we just ignore invisible text, a smarter solution is probably required for the SVG case. Since just ignoring invisible text in `svg.js` would mean that text-selection isn't possible.
2016-02-26 23:07:39 +01:00
Tim van der Meij
0c19d84911 Merge pull request #7031 from Snuffleupagus/outline-default-title
Add a default title for outline items, to prevent display issues if the title is missing
2016-02-26 22:37:51 +01:00
Jonas Jenwald
c7a44391cf Add a reset method to PDFFindbar, and use it to clear parts of the find UI when the document is closed 2016-02-26 18:35:45 +01:00
Jonas Jenwald
e7d039dbce Ensure that PDFFindController_reset actually resets *all* state (issue 7034)
To reduce code duplication, the initialization code now uses the `reset` method.
Also, this patch moves `charactersToNormalize` out of `PDFFindController`, since it seemed better suited to be a "constant".
2016-02-26 18:35:17 +01:00
Jonas Jenwald
9bcbd4d872 Add a default title for outline items, to prevent display issues if the title is missing
Open http://www.puolustusvoimat.fi/wcm/61ba4180411e702ea19ee9e364705c96/luonnonmuonaohjelmalumo1985.pdf?MOD=AJPERES#pagemode=bookmarks.

Note how the outline looks entirely empty, but hovering over it you'll see that there are entries present. There's two separate issues here, first of all the fact that you cannot visually make out the outline items, and secondly that the lack of text means that the clickable area becomes too small.

In Adobe Reader this issue is somewhat mitigated, since they use an icon for every item. For PDF.js, the easist way to address this seems to be making use of a default title.
This issue should be *very* rare in practice, but given the simplicity of the solution I think that we should fix this.
2016-02-26 12:46:46 +01:00
Tim van der Meij
2b813c0ca4 Merge pull request #7030 from Snuffleupagus/PDFThumbnailView-remove-hasImage
Remove the `hasImage` property from `PDFThumbnailView`
2016-02-25 23:17:48 +01:00
Jonas Jenwald
95aa8b0415 Remove the hasImage property from PDFThumbnailView
The `hasImage` property is a left-over from older thumbnail code, and has been made obsolete by `renderingState`.
Having two different properties tracking (basically) the same state is asking for trouble, since it's very easy to forget to update one of them, with annoying bugs as the result.
2016-02-25 17:04:11 +01:00
Jonas Jenwald
05917b65d5 Merge pull request #7016 from timvandermeij/annotations-missing-popup
Group popup creation code and apply it to more annotation types
2016-02-25 10:27:49 +01:00
Tim van der Meij
ad31e52a26 Group popup creation code and apply it to more annotation types 2016-02-25 00:35:45 +01:00
Jonas Jenwald
41efb92d3a Merge pull request #6988 from timvandermeij/fileattachment-annotation
Implement support for FileAttachment annotations
2016-02-24 12:58:06 +01:00
Tim van der Meij
0351c7eff4 Move the getFileName helper function to the core
This is required to be able to use it in the annotation display code,
where we now apply it to sanitize the filename of the FileAttachment
annotation. The PDF file from https://bugzilla.mozilla.org/show_bug.cgi?id=1230933 has shown that some PDF generators include the path of the file rather than the filename, which causes filenames with weird initial characters. PDF viewers handle this differently (for example Foxit Reader just replaces forward slashes with spaces), but we think it's better to only show the filename as intended.

Additionally we add unit tests for the `getFilenameFromUrl` helper
function.
2016-02-23 22:49:53 +01:00
Tim van der Meij
10902fd882 Implement unit and reference testing for FileAttachment annotations 2016-02-23 22:49:53 +01:00
Tim van der Meij
6a33dfd13a Implement support for FileAttachment annotations 2016-02-23 22:49:53 +01:00
Tim van der Meij
c53581f4e5 Merge pull request #7009 from KamiHQ/annotations-fix
[api-minor] Always expose data.title and data.contents for TextAnnotation
2016-02-22 22:59:38 +01:00
Tim van der Meij
ebe6fb2560 Merge pull request #7012 from KamiHQ/fix-annotation-popup
don't render highlight/underline/squiggly/strikeout annotations that doesn't have popup
2016-02-22 21:54:08 +01:00
Xiliang Chen
6762ff2fd6 don't render highlight/underline/squiggly/strikeout annotations that doesn't have popup 2016-02-22 13:10:20 +13:00
Xiliang Chen
266cedd960 always expose data.title and data.content 2016-02-19 13:50:25 +13:00
Brendan Dahl
0629fd0afa Merge pull request #7007 from Snuffleupagus/bug-1248959
[Addon] Catch errors in `getFindBar` (in PdfStreamConverter.jsm) to fix loading of PDF files in the bookmark sidebar (bug 1248959)
2016-02-18 16:18:15 -08:00
Yury Delendik
0d591719d9 Makes PDF data reading Streams API friendly. 2016-02-18 13:17:53 -06:00
Jonas Jenwald
f64113c927 [Addon] Catch errors in getFindBar (in PdfStreamConverter.jsm) to fix loading of PDF files in the bookmark sidebar (bug 1248959)
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1248959.
2016-02-18 13:59:18 +01:00
Jonas Jenwald
8cdb69634f Merge pull request #6984 from Snuffleupagus/issue-6066
Update `JpegImage.getData` to support `forceRGBoutput` for images with `numComponents === 1` (issue 6066)
2016-02-18 11:51:07 +01:00
Jonas Jenwald
a494e33776 Update JpegImage.getData to support forceRGBoutput for images with numComponents === 1 (issue 6066)
*A more robust solution for issue 6066.*

As a temporary work-around for (the upstream) [bug 1164199](https://bugzilla.mozilla.org/show_bug.cgi?id=1164199), we parsed *all* images in the Firefox addon during a short time.
Doing so uncovered an issue with our image handling (see 6066), for JPEG images with a `DeviceGray` ColorSpace *and* `bpc !== 1` (bits per component).

As long as we let the browser handle image decoding in this case, this isn't going to be an issue, but I do think that we should proactively fix this to avoid future issues if we change where the images are decoded (in `jpg.js` vs in browser).
Also, we currently don't seem to have a test-case for that kind of image data.
2016-02-18 10:12:37 +01:00
Tim van der Meij
9eedfc128c Merge pull request #6998 from Snuffleupagus/outline-styles-core
[api-minor] Change `getOutline` to actually return the RGB color of outline items
2016-02-16 23:31:55 +01:00
Jonas Jenwald
7cf9de2c17 [api-minor] Change getOutline to actually return the RGB color of outline items
Currently the `C` entry in an outline item is returned as is, which is neither particularly useful nor what the API documentation claims.

This patch also adds unit-tests for both the color handling, and the `F` entry (bold/italic flags).
2016-02-15 13:41:22 +01:00
Jonas Jenwald
45fea8808e Merge pull request #6985 from timvandermeij/xhtml-leftovers
Remove XHTML leftovers from the viewer HTML files
2016-02-14 15:32:45 +01:00
Tim van der Meij
05e080c802 Merge pull request #6987 from timvandermeij/readme
Remove Opera from the README file as they removed the extension
2016-02-14 14:09:48 +01:00
Tim van der Meij
eeeebe8061 Remove Opera from the README file as they removed the extension 2016-02-14 14:05:20 +01:00
Tim van der Meij
edb2eecdc8 Remove XHTML leftovers from the viewer HTML files 2016-02-14 13:23:34 +01:00
Jonas Jenwald
98db068079 Reduce the overall indentation level in Catalog_readDocumentOutline, by using early returns, in order to improve readability 2016-02-14 11:38:43 +01:00
Tim van der Meij
e9a1a47d28 Merge pull request #6982 from Snuffleupagus/evaluator-remove-getAll
Remove the only remaining `Dict_getAll` usage (in evaluator.js) and the method itself
2016-02-13 20:48:37 +01:00
Tim van der Meij
addc4a3ded Merge pull request #6856 from KamiHQ/remove-has-html
move hasHtml to AnnotationElement
2016-02-13 20:12:09 +01:00
Tim van der Meij
cd9d134af3 Merge pull request #6939 from LilyBin/uglifyjs
Use UglifyJS to minify files in minified target
2016-02-13 15:07:47 +01:00
Jonas Jenwald
1ee016b005 Remove Dict_getAll since it is now unused
`Dict_getAll` is problematic for a number of reasons. First of all, as issue 6961 shows, it can be really bad for performance, since it dereferences all indirect objects.
Second of all, all the derefencing can lead to data being unncessarily requested when ranged/chunked loading is used, thus unnecessarily delaying rendering.

Note: For cases where `Dict_getAll` was previously used, `Dict_getKeys` in combination with `Dict_get` can be used instead. This has the advantage that data isn't requested until it's actually needed.
2016-02-12 22:32:07 +01:00
Jonas Jenwald
93ea866f01 Remove getAll from EvaluatorPreprocessor_read
For the operators that we currently support, the arguments are not `Dict`s, which means that it's not really necessary to use `Dict_getAll` in `EvaluatorPreprocessor_read`.
Also, I do think that if/when we support operators that use `Dict`s as arguments, that should be dealt with in the corresponding `case` in `PartialEvaluator_getOperatorList` which handles the operator.

The only reason that I can find for using `Dict_getAll` like that, is that prior to PR 6550 we would just append certain (currently unsupported) operators without doing any further processing/checking. But as issue 6549 showed, that can lead to issues in practice, which is why it was changed.

In an effort to prevent possible issue with unsupported operators, this patch simply ignores operators with `Dict` arguments in `PartialEvaluator_getOperatorList`.
2016-02-12 22:31:50 +01:00
Jonas Jenwald
62b17ad36e Add a linked load test for issue 6549 2016-02-12 18:10:07 +01:00
Yury Delendik
2f145d8db4 Republish addon 2016-02-11 15:36:32 -06:00
Yury Delendik
2addcc7957 Republish addon 2016-02-11 15:21:15 -06:00
Jonas Jenwald
2d61652c75 Update l10n files 2016-02-11 14:33:03 +01:00
Tim van der Meij
1f49e7b194 Merge pull request #6975 from Snuffleupagus/ColorSpace-remove-getAll
Get rid of `getAll` usage in colorspace.js
2016-02-11 14:23:10 +01:00
Tim van der Meij
6133a993a9 Merge pull request #6972 from Snuffleupagus/loadType3Data-getKeys
Replace `getAll` with `getKeys` in `loadType3Data`
2016-02-11 14:15:31 +01:00
Tim van der Meij
72c05af37c Merge pull request #6973 from pra85/patch-1
Fix a typo in api.js
2016-02-11 14:10:45 +01:00
Jonas Jenwald
02a6b73492 Get rid of getAll usage in colorspace.js
For the `CalGray`/`CalRGB`/`Lab` colour spaces, we're currently using `getAll` to retrieve the parameters. However that's not really necessary, since we may just as well explicitly `get` the needed parameters instead.
2016-02-11 11:59:26 +01:00
Prayag Verma
049beac346 Fix a typo in api.js
`fulfills` misspelt as `fullfills`
2016-02-11 07:18:56 +05:30
Xiliang Chen
e42da0f5e9 move hasHtml to AnnotationElement 2016-02-11 13:58:17 +13:00
Tim van der Meij
acf74d40b1 Merge pull request #6941 from Rob--W/crx-allow-pdf-in-local-frames
Allow local PDF files to be viewed in local frames
2016-02-10 20:58:24 +01:00
Jonas Jenwald
f7f60197ce Replace getAll with getKeys in loadType3Data
Not only is `getAll` less efficient, but given that we actually need the keys here, using `getKeys` seems much more suitable.
2016-02-10 20:19:14 +01:00
Yury Delendik
33b57d7450 Merge pull request #6971 from Snuffleupagus/issue-6961
Replace `getAll` with `getKeys` in `PartialEvaluator_hasBlendModes` to speed up loading of badly generated PDF files (issue 6961)
2016-02-10 11:06:06 -06:00
Jonas Jenwald
07e1ad40a2 Replace getAll with getKeys in PartialEvaluator_hasBlendModes to speed up loading of badly generated PDF files (issue 6961)
Some bad PDF generators, in particular "Scribus PDF", duplicates resources *a lot* at various levels of the PDF files. This can lead to `PartialEvaluator_hasBlendModes` taking an unreasonable amount of time to complete.
The reason is that the current code is using `Dict_getAll`, which recursively dereferences *all* indirect objects, which can be really slow. This patch instead uses `Dict_getKeys`, and then manually looks up only the necessary indirect objects.

I've added the PDF file as a `load` test. The most important thing here is probably to ensure that the file remains available in the repo, and the comment should help reduced the chance of regressions. (Note that locally, the `load` test times out without this patch, but we cannot really assume that that always happens.)

Fixes 6961.
2016-02-10 17:21:38 +01:00
Rob Wu
0ec82d4a50 Allow local PDF files to be viewed in local frames
The Chrome extension enforces that local files cannot be embedded in
non-local web pages. The previous check was too strict (because the
origin of a file:-URL is "null"), and prevented local PDF from being
viewed in local files).

This patch fixes that problem, by querying the actual tab URL via the
background page.

Steps to verify:
1. Create a HTML file: `<iframe src=test.pdf width=100% height=100%>`
2. Build and load the extension.
3. Allow file access to the extension at `chrome://extensions`
4. Open the HTML file from a file:// URL.
5. VERIFY: The extension should attempt to load the PDF file.

6. Now open the following (replace ID with the extension ID, which you
   can find at `chrome://extensions`):
  `data:text/html,<iframe src="chrome-extension://ID/file:///test.pdf">`
7. VERIFY: The next error should be displayed:
   "Refused to load a local file in a non-local page for security reasons."
2016-02-10 14:52:54 +01:00
Tim van der Meij
03f12a10b5 Merge pull request #6954 from Snuffleupagus/setGState-fixes
Various `setGState` improvements
2016-02-10 00:38:31 +01:00
Tim van der Meij
02b161d432 Merge pull request #6933 from brendandahl/faster-decrypt
Make type 1 font program decryption faster.
2016-02-09 23:41:22 +01:00
Brendan Dahl
d7e5935f91 Merge pull request #6938 from yurydelendik/fix-ff-disableworker
Fix 'Ready' message sequence for Firefox ext disabled worker.
2016-02-09 10:50:12 -08:00
Tim van der Meij
a0aa781c39 Merge pull request #6913 from Rob--W/importScripts-work-around
Improve work-around for importScripts bug.
2016-02-04 19:51:26 +01:00
Rob Wu
097e273ca4 Improve work-around for importScripts bug.
Reverts "Hack to avoid intermidiate Chrome failures during tests."
(2b2c521213).

require.js uses importScript asynchronously, which activates the worker
GC bug in WebKit. This patch works around a bug in a way that is similar
in the upcoming (but not yet released) require.js 2.1.23

The advantage of the new work-around is that it allows the runtime to
garbage-collect idle Workers.

References:
- https://crbug.com/572225
- https://webkit.org/b/153317
2016-02-03 23:30:27 +01:00
Yury Delendik
4c59712606 Merge pull request #6904 from timvandermeij/cleanup-workers
Destroy workers when they are no longer needed in the unit tests
2016-02-03 14:46:22 -06:00
Jonas Jenwald
a1fe2cb443 Don't directly access the private map in setGState, and ensure that we avoid indirect objects
*This patch is based on something I noticed while debugging some of the PDF files in issue 6931.*

In a number of the cases in `setGState`, we're implicitly assuming that we're not dealing with indirect objects (i.e. `Ref`s). See e.g. the 'Font' case, or the various cases where we simply do `gStateObj.push([key, value]);` (since the code in `canvas.js` won't be able to deal with a `Ref` for those cases).

The reason that I didn't use `Dict_forEach` instead, is that it would re-introduce the unncessary closures that PR 5205 removed.
2016-02-03 17:13:42 +01:00
Jonas Jenwald
2d4a1aa0af Actually ignore no-op setGState (PR 5192 followup)
The intention of PR 5192 was to avoid adding empty `setGState` ops to the operatorList. But the patch accidentally used `>=`, which means that it's not actually working as intended, since empty arrays always have `length === 0`.
2016-02-03 17:13:02 +01:00
Yury Delendik
974433a7a7 Merge pull request #6953 from Snuffleupagus/smask-transferMap-upper-limit
Correct the upper bound used when building the `transferMap` for SMasks (PR 6723 followup)
2016-02-03 09:26:37 -06:00
Jonas Jenwald
4770b516fe Correct the upper bound used when building the transferMap for SMasks (PR 6723 followup)
Even though the currently known test-cases render correctly without this patch, that seems more like a lucky coincidence, given that there's no guarantee that `transferMap[255] === 0` for every possible transfer function.
2016-02-03 13:41:10 +01:00
Timothy Gu
e403f52722 Use UglifyJS to minify files in minified target
It is written in JavaScript, is less buggy, and compresses better.
2016-01-31 13:55:23 -08:00
Tim van der Meij
a4b90243d0 Merge pull request #6940 from Snuffleupagus/differences-fix-indirect-objects
Ensure that we don't modify the `Dict` data when the `Differences` array of a font contains indirect objects
2016-01-31 20:17:16 +01:00
Jonas Jenwald
992472fd38 Ensure that we don't modify the Dict data when the Differences array of a font contains indirect objects
This patch fixes an issue that I inadvertently introduced in PR 5815, where we accidentally modify the `Differences` array in the encoding dictionary for indirect objects.

Instead of this change, we could also have used the now existing `Dict_getArray`. However in this case I don't think that would have been a good idea, since it would mean iterating through the array *twice*.
2016-01-30 13:31:24 +01:00
Brendan Dahl
02331f6e33 Make type 1 font program decryption faster.
Discard the values first so we don't have to slice the array.
2016-01-29 11:10:30 -08:00
Yury Delendik
e36b04e1ff Fix 'Ready' message sequence for Firefox ext disabled worker. 2016-01-29 11:43:19 -06:00
Jonas Jenwald
e401804f13 Remove the 'oplist' rendering intent when getOperatorList has returned the complete OperatorList, and prevent errors in PDFPageProxy_destroy for the 'oplist' rendering intent 2016-01-29 12:34:26 +01:00
Tim van der Meij
5bcf4c1895 Destroy workers when they are no longer needed in the unit tests 2016-01-29 12:23:17 +01:00
Tim van der Meij
5d797e1a85 Merge pull request #6921 from Snuffleupagus/mandatory-deprecated
Always display `deprecated` messages, regardless of the verbosity setting
2016-01-29 12:12:08 +01:00
Yury Delendik
365bc99508 Merge pull request #6934 from jswalden/detach-terminology
Adjust a comment discussing transferred ArrayBuffers, to refer to those buffers being detached, not neutered
2016-01-28 17:11:39 -06:00
Jeff Walden
4691a4a1e4 Adjust a comment discussing transferred ArrayBuffers to refer to those buffers being detached, not neutered. This change makes the comment consistent with terminology used in the ECMAScript specification. 2016-01-28 14:52:07 -08:00
Yury Delendik
825a2225ab Merge pull request #6915 from yurydelendik/lookuptables
Refactor lookup hash tables/objects
2016-01-28 15:01:06 -06:00
Yury Delendik
2edf2792dc Replaces literal {} created lookup tables with Object.create 2016-01-28 12:18:38 -06:00
Yury Delendik
d6adf84159 Lazify OP_MAP. 2016-01-28 12:18:37 -06:00
Yury Delendik
1de90454b7 Lazify Metrics 2016-01-28 12:11:46 -06:00
Yury Delendik
55a201d92d Lazify NormalizedUnicodes 2016-01-28 11:56:42 -06:00
Yury Delendik
d0738d7e24 Lazify stdFontMap, serifFonts, GlyphMapForStandardFonts 2016-01-28 11:51:54 -06:00
Yury Delendik
1a9a665adf Refactor Encodings 2016-01-28 11:32:59 -06:00
Yury Delendik
4ef20de429 Lazify GlyphsUnicode. 2016-01-28 11:32:59 -06:00
Brendan Dahl
252b9d5910 Merge pull request #6753 from yurydelendik/cdn-worker
Wraps worker script if its cross-origin location is detected.
2016-01-27 13:21:10 -08:00
Yury Delendik
e44dada047 Publish 1.4.20 2016-01-27 10:32:58 -06:00
Yury Delendik
b15f335380 Merge pull request #6930 from Snuffleupagus/page-labels-standard-numbering
[api-minor] Change `getPageLabels` to always return the pageLabels, even if they are identical to standard page numbering
2016-01-27 09:31:52 -06:00
Jonas Jenwald
1140a34f5c [api-minor] Change getPageLabels to always return the pageLabels, even if they are identical to standard page numbering 2016-01-27 13:36:03 +01:00
Brendan Dahl
1f2910b2a2 Merge pull request #6928 from yurydelendik/url-check
Fixes URL polyfill check for MS Edge.
2016-01-26 17:50:30 -08:00
Yury Delendik
bc30c42758 Fixes URL polyfill check for MS Edge. 2016-01-26 16:49:44 -06:00
Yury Delendik
0558ffcbf9 Merge pull request #6922 from Snuffleupagus/issue-1536
Prevent failures in the "scanning for endstream" code, in `Parser_makeStream`, by handling the case where 'endstream' is split between contiguous chunks (issue 1536)
2016-01-26 10:06:51 -06:00
Jonas Jenwald
15ce96a6eb Prevent failures in the "scanning for endstream" code, in Parser_makeStream, by handling the case where 'endstream' is split between contiguous chunks (issue 1536) 2016-01-26 09:03:51 +01:00
Jonas Jenwald
472e793a27 Always display deprecated messages, regardless of the verbosity setting
Currently the `deprecated` message is using `warn`, meaning that it's possible to disable warnings about deprecated API usage through the `PDFJS.verbosity` setting.

I don't think that it should be possible to opt out of deprecation messages,[1] since it might mean that in a custom deployment of PDF.js these messages could be overlooked, leading to PDF.js being broken (seemingly without any warning) when updating to a future version.
Obviously this could be considered the responsibility of the people doing custom PDF.js implementations, but in order to reduce the support burden later on, it seems better to "annoy" people upfront.

Compared to various `info`/`warn`/`error` messages, `deprecated` messages should be very simple to get rid of -- just update the API usage and the message goes away!

---
[1] In e.g. Firefox it doesn't seem possible to prevent deprecation warnings from being displayed (in the Browser Console).
2016-01-25 12:38:34 +01:00
Yury Delendik
051a0746e1 Changes version of the stable release to 1.3.91 2016-01-24 12:35:05 -06:00
Brendan Dahl
117f105ef1 Merge pull request #6919 from brendandahl/update-links
Update beta and stable.
2016-01-22 10:45:14 -08:00
Brendan Dahl
0cb56968fa Update beta and stable. 2016-01-22 10:44:32 -08:00
Brendan Dahl
b14c55fb85 Merge pull request #6918 from brendandahl/v1.4
Bump version to 1.4
2016-01-22 10:37:23 -08:00
Brendan Dahl
c21dd49880 Bump version to 1.4 2016-01-22 10:36:38 -08:00
Brendan Dahl
059e826e20 Merge pull request #6916 from yurydelendik/hosted-viewer
Allow foriegn origin URLs only for hosted viewers.
2016-01-22 10:02:52 -08:00
Yury Delendik
7c89bdc8d6 Allow foriegn origin URLs only for hosted viewers. 2016-01-22 11:54:19 -06:00
Xiliang Chen
069f4b9bdf avoid apply transform twice for composite context 2016-01-21 14:25:39 +13:00
Tim van der Meij
58329f7f92 Merge pull request #6803 from Snuffleupagus/page-labels
[api-minor] Add support for PageLabels in the API
2016-01-20 22:05:48 +01:00
Yury Delendik
0aa373cdf3 Merge pull request #6891 from Snuffleupagus/issue-6889
Map missing glyphs to the `notdef` glyph for TrueType (3, 1) fonts regardless if the 'post' table is defined or not (issue 6889)
2016-01-20 13:14:47 -06:00
Yury Delendik
232748251a Merge pull request #6900 from Snuffleupagus/issue-6898
Set type="password" for the `PasswordPrompt` input dynamically, to prevent unnecessary warnings in Firefox for http:// documents (issue 6898)
2016-01-20 09:33:34 -06:00
Jonas Jenwald
4b94416277 Set type="password" for the PasswordPrompt input dynamically, to prevent unnecessary warnings in Firefox for http:// documents (issue 6898)
Fixes 6898.

Note that this doesn't prevent the warning for PDF files that *do* ask for a password, e.g. http://async5.org/moz/passwordOU.pdf, but it's not clear to me if/how we could avoid that.
2016-01-20 13:54:19 +01:00
Jonas Jenwald
85cf90643f [api-minor] Add support for PageLabels in the API 2016-01-19 22:49:04 +01:00
Jonas Jenwald
8ad18959d7 Add support for NumberTree 2016-01-19 22:47:45 +01:00
Tim van der Meij
1eea0db897 Merge pull request #6822 from Snuffleupagus/urls-in-outline
[api-minor] Add support for URLs in the document outline
2016-01-19 22:21:40 +01:00
Jonas Jenwald
0030a82dc3 [api-minor] Add support for URLs in the document outline
Re: issue 5089.
(Note that since there are other outline features that we currently don't support, e.g. bold/italic text and custom colours, I thus think we can keep the referenced issue open.)
2016-01-19 21:36:27 +01:00
Jonas Jenwald
d9e21a3523 Merge pull request #6895 from timvandermeij/issue-6854-final
Update links to point to the Internet Archive for issue2799 and issue5726
2016-01-18 21:00:14 +01:00
Tim van der Meij
ec066101d8 Merge pull request #6848 from Snuffleupagus/recover-missing-glyf-table
[TrueType] Recover from a missing "glyf" table by replacing it with dummy data, utilizing the existing code in `sanitizeGlyphLocations`
2016-01-18 20:28:52 +01:00
Tim van der Meij
10a55087b5 Update links to point to the Internet Archive for issue2799 and
issue5726

We remove yo01. The file is not available, it was introduced in
3529658ac5
along with another test file (so we should not need it) and it was
replaced in
6b2c6fc223,
so it was only in the repository for a very short time.
2016-01-18 15:53:07 +01:00
Jonas Jenwald
4855d4cc9f Map missing glyphs to the notdef glyph for TrueType (3, 1) fonts regardless if the 'post' table is defined or not (issue 6889) 2016-01-17 22:58:00 +01:00
Jonas Jenwald
e60fde73ca Merge pull request #6888 from timvandermeij/issue-6854-5
Update links to point to the Internet Archive for issue1597, issue2627 and kdchart
2016-01-17 17:15:45 +01:00
Tim van der Meij
57246c15c7 Update links to point to the Internet Archive for issue1597, issue2627 and kdchart 2016-01-17 14:36:17 +01:00
Tim van der Meij
5a9b0062f8 Merge pull request #6887 from Snuffleupagus/remove-issue2537.pdf.link
Remove 'issue2537.pdf.link', since it has been replaced with a reduced test-case
2016-01-17 14:11:43 +01:00
Jonas Jenwald
da75671199 Remove 'issue2537.pdf.link', since it has been replaced with a reduced test-case
In PR 4732, Yury replaced the linked test, but apparently the .link file stuck around despite not being needed anymore.

Re: PR 6854.
2016-01-17 14:04:00 +01:00
Tim van der Meij
d864bef160 Merge pull request #6886 from Snuffleupagus/issue-6854-11
Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue2829, issue2853, issue2881, issue3062, issue3999
2016-01-17 13:43:50 +01:00
Jonas Jenwald
f80a6efce3 Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue2829, issue2853, issue2881, issue3062, issue3999 2016-01-17 13:15:42 +01:00
Tim van der Meij
38b428bb01 Merge pull request #6885 from Snuffleupagus/issue-1155-reduced-test
Replace the linked test-case for issue 1155 with a reduced one
2016-01-16 20:46:54 +01:00
Jonas Jenwald
b4020047bc Replace the linked test-case for issue 1155 with a reduced one
As part of the link cleanup in issue 6854, obtaining this file through the Internet Archive didn't work.
However, given that the file was added in order to test an issue with `CropBox/MediaBox`, a reduced test-case should do just fine instead.

Please refer to issue 1155, and PR 1212.
2016-01-16 16:00:37 +01:00
Tim van der Meij
e54edd1128 Merge pull request #6883 from Snuffleupagus/issue-6854-10
Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue2129, issue2139, issue2386, issue2442, issue2531
2016-01-16 14:49:52 +01:00
Tim van der Meij
6d767001cd Merge pull request #6884 from Snuffleupagus/remove-tcpdf_033.pdf.link
Remove 'tcpdf_033.pdf.link', since it has been replaced with a reduced test-case
2016-01-16 14:34:05 +01:00
Jonas Jenwald
92fa439eac Remove 'tcpdf_033.pdf.link', since it has been replaced with a reduced test-case
In PR 1556 Brendan replaced the linked test, but apparently the `.link` file stuck around despite not being needed anymore.

Re: PR 6854.
2016-01-16 12:33:11 +01:00
Jonas Jenwald
2bdffdd7b0 Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue2129, issue2139, issue2386, issue2442, issue2531 2016-01-16 12:10:48 +01:00
Jonas Jenwald
b7fe79c026 Merge pull request #6881 from timvandermeij/issue-6854-4
Update links to point to the Internet Archive for issue3384, issue3848, issue3903, issue3925 and issue5592
2016-01-16 12:02:33 +01:00
Jonas Jenwald
e29d85e589 Merge pull request #6880 from timvandermeij/issue-6854-3
Update links to point to the Internet Archive for issue818, issue919, jai, liveprogramming and mao
2016-01-15 22:46:41 +01:00
Yury Delendik
1e45f2d4e1 Wraps worker script if its cross-origin location is detected. 2016-01-15 15:05:46 -06:00
Jonas Jenwald
d52495a9c8 [TrueType] Recover from a missing "glyf" table by replacing it with dummy data, utilizing the existing code in sanitizeGlyphLocations
It seems to be fairly common for OCR software to include incomplete TrueType fonts, notable missing the "glyf" table, in PDF files. Since we currently reject such fonts, the result is that text-selection/copying is broken.

This patch contains a suggested approach to try and use these kind of broken fonts, by using existing code in `sanitizeGlyphLocations` to replace a missing "glyf" table with dummy data.

Fixes 4684.
Fixes 6007.
Fixes 6829.
2016-01-15 21:44:59 +01:00
Tim van der Meij
4155dfeb19 Update links to point to the Internet Archive for issue3384, issue3848, issue3903, issue3925 and issue5592 2016-01-15 21:44:59 +01:00
Tim van der Meij
159eb6d46c Update links to point to the Internet Archive for issue818, issue919, jai, liveprogramming and mao 2016-01-15 21:26:37 +01:00
Tim van der Meij
e134947533 Merge pull request #6878 from Snuffleupagus/issue-6854-9
Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1878, issue1912, issue1936, issue1998, issue2006
2016-01-15 21:03:47 +01:00
Jonas Jenwald
223249fe2c Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1878, issue1912, issue1936, issue1998, issue2006 2016-01-15 18:22:03 +01:00
Tim van der Meij
7f821f5b78 Merge pull request #6876 from Snuffleupagus/issue-6854-8
Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1709, issue1721, issue1729, issue1796, issue1810
2016-01-15 16:38:45 +01:00
Tim van der Meij
d02217c3fd Merge pull request #6875 from Snuffleupagus/issue-6854-7
Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1466, issue1629, issue1658, issue1685, issue1687
2016-01-15 16:28:27 +01:00
Jonas Jenwald
b03703f20c Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1709, issue1721, issue1729, issue1796, issue1810 2016-01-15 13:55:56 +01:00
Jonas Jenwald
93088ce342 Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1466, issue1629, issue1658, issue1685, issue1687 2016-01-15 13:30:24 +01:00
Tim van der Meij
5336a5363f Merge pull request #6871 from Snuffleupagus/issue-6854-6
Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1233, issue1257, issue1309, issue1317, issue1419
2016-01-15 01:04:40 +01:00
Tim van der Meij
8e58c8bc3d Merge pull request #6869 from Snuffleupagus/issue-6854-5
Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1049, issue1096, issue1127, issue1133, issue1169
2016-01-15 00:50:05 +01:00
Tim van der Meij
e6ff1a4179 Merge pull request #6866 from Snuffleupagus/issue-6854-4
Issue 6854 - Update the link locations to point to the Internet Archive for tests: html5checker, hudsonsurvey, ichiji, issue1010, issue1015
2016-01-15 00:24:06 +01:00
Tim van der Meij
04677eea45 Merge pull request #6867 from brendandahl/disable-e10s
Disable e10s.
2016-01-14 23:56:44 +01:00
Tim van der Meij
f6a8dfb76a Merge pull request #6873 from Snuffleupagus/pr-6846-followup
Add an extra set of `//` to the comment for the URL polyfill, since the preprocessor eats one set, thus breaking the world (PR 6846 followup)
2016-01-14 23:09:37 +01:00
Jonas Jenwald
cca265352f Add an extra set of // to the comment for the URL polyfill, since the preprocessor eats one set, thus breaking the world (PR 6846 followup)
The Firefox addon currently fails with:
```
SyntaxError: missing ; before statement pdf.js:1692:12
TypeError: PDFJS.shadow is not a function viewer.js:6228:12
```
2016-01-14 22:43:34 +01:00
Brendan Dahl
794e1a3178 Merge pull request #6846 from brendandahl/url
Use URL constructor for combineURL.
2016-01-14 13:29:16 -08:00
Brendan Dahl
2d27cb1da6 Remove 'use strict'; causing failure and unused prefs. 2016-01-14 13:23:48 -08:00
Brendan Dahl
e362c3b8fc Use URL constructor for combineURL. 2016-01-14 11:36:36 -08:00
Jonas Jenwald
01bb6b4e98 Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1233, issue1257, issue1309, issue1317, issue1419 2016-01-14 17:24:26 +01:00
Tim van der Meij
8318c8203c Merge pull request #6311 from yurydelendik/clean_test_manifest
Cleans test manifest from absent files.
2016-01-14 17:13:16 +01:00
Jonas Jenwald
850fa35040 Issue 6854 - Update the link locations to point to the Internet Archive for tests: issue1049, issue1096, issue1127, issue1133, issue1169 2016-01-14 12:06:30 +01:00
Jonas Jenwald
ff79c56fa3 Merge pull request #6865 from timvandermeij/hmm
Update the linked test case hmm.pdf to point to the intended version
2016-01-14 11:48:32 +01:00
Brendan Dahl
ad8e43a185 Disable e10s. 2016-01-13 15:21:28 -08:00
Jonas Jenwald
86f97d8e64 Issue 6854 - Update the link locations to point to the Internet Archive for tests: html5checker, hudsonsurvey, ichiji, issue1010, issue1015 2016-01-13 18:11:35 +01:00
Yury Delendik
18f0531619 Cleans test manifest from absent files. 2016-01-13 09:40:21 -06:00
Jonas Jenwald
38645f5701 Merge pull request #6864 from timvandermeij/issue6854-2
Update links to point to the Internet Archive for ohkubo-SS04, pal-o47, pdf, piperine and preistabelle
2016-01-13 16:33:35 +01:00
Tim van der Meij
17b639bfc5 Update the linked test case hmm.pdf to point to the intended version
The test case was changed in 1faca19021 because the original file was not available anymore. However, its hash was also changed, meaning that we do not test the intended version anymore.

This patch makes sure that we test the intented version by reverting to
the original hash and using a link, also pointing to the Internet
Archive, with the original file.
2016-01-13 16:30:26 +01:00
Yury Delendik
51b59bc86f Merge pull request #6853 from Snuffleupagus/issue-3666-test-link
Update the link location for 'issue3666.pdf' to point to the Internet Archive
2016-01-13 08:49:40 -06:00
Tim van der Meij
c6ad1b573b Update links to point to the Internet Archive for ohkubo-SS04, pal-o47, pdf, piperine and preistabelle 2016-01-13 14:59:21 +01:00
Tim van der Meij
f3dd9bcc48 Merge pull request #6862 from Snuffleupagus/issue-6854-3
Issue 6854 - Update the link locations to point to the Internet Archive for tests: cable, fips197, fit11-talk, geothermal, hmm
2016-01-13 14:29:50 +01:00
Jonas Jenwald
239846f0d6 Issue 6854 - Update the link locations to point to the Internet Archive for tests: cable, fips197, fit11-talk, geothermal, hmm 2016-01-12 21:35:23 +01:00
Tim van der Meij
7e2f1f43e4 Merge pull request #6860 from Snuffleupagus/issue-6854-2
Issue 6854 - Update the link locations to point to the Internet Archive for tests: artofwar, bpl13210, bug766138, bug808084, bug887152
2016-01-12 16:34:00 +01:00
Jonas Jenwald
a20883ac79 Issue 6854 - Update the link locations to point to the Internet Archive for tests: artofwar, bpl13210, bug766138, bug808084, bug887152 2016-01-12 15:51:39 +01:00
Jonas Jenwald
596bf2b87b Merge pull request #6859 from timvandermeij/issue-6854-1
Update five linked test cases to point to the Internet Archive
2016-01-12 15:31:47 +01:00
Tim van der Meij
3df2b1141c Update five linked test cases to point to the Internet Archive 2016-01-12 15:00:36 +01:00
Tim van der Meij
2625ceca8d Merge pull request #6858 from Snuffleupagus/restore-aboutstacks
Issue 6854 - Re-enable testing of 'aboutstacks.pdf'
2016-01-12 14:30:48 +01:00
Jonas Jenwald
15e384c558 Issue 6854 - Re-enable testing of 'aboutstacks.pdf'
This test was disabled in PR 4732, because the file was no longer available. The motivation being that there were two other files which should be good replacements. However, one of those has since been replaced with a reduced test-case (which doesn't exercise the same code-path), and in the other one the error does not appear to be entirely identical.
Hence it seems reasonable to re-add the 'aboutstacks.pdf' test, since it was possible to find it on the Internet Archive (by searching using a different URL, compared to the current one).
2016-01-12 13:13:43 +01:00
Tim van der Meij
52caad6266 Merge pull request #6855 from Snuffleupagus/issue-6854-1
Issue 6854 - Update the link locations to point to the Internet Archive for tests: 20130226130259, JST2007-5, P020121130574743273239, SFAA_Japanese, TaroUTR50SortedList112
2016-01-12 00:52:34 +01:00
Jonas Jenwald
57097c54de Issue 6854 - Update the link locations to point to the Internet Archive for tests: 20130226130259, JST2007-5, P020121130574743273239, SFAA_Japanese, TaroUTR50SortedList112 2016-01-11 23:47:24 +01:00
Jonas Jenwald
c197e47742 Update the link location for 'issue3666.pdf' to point to the Internet Archive
Note that despite the new file having a different hash than the the current one, it does render *identically* and most importantly it uses *the same* JBIG2 functionality.

For reference, please see issue 3666 and PR 3738.
2016-01-11 21:27:00 +01:00
Brendan Dahl
3057b69e45 Merge pull request #6839 from Snuffleupagus/issue-6782
Check that CIDFontType0 fonts does not actually contain OpenType font files (issue 6782)
2016-01-11 08:56:48 -08:00
Tim van der Meij
30b8f41003 Merge pull request #6820 from Snuffleupagus/showText-shadingPattern
Apply Patterns, if necessary, when rendering text
2016-01-08 14:02:56 +01:00
Brendan Dahl
4a215f0892 Merge pull request #6825 from yurydelendik/pdfjsumd
Adds UMD header to pdf.js and pdf.worker.js files.
2016-01-07 15:07:58 -08:00
Tim van der Meij
944d1e6dc5 Merge pull request #6843 from timvandermeij/pr-6796-fixup
shading-pattern: Decreased `Shadings.SMALL_NUMBER`
2016-01-06 16:23:20 +01:00
Daan Sprenkels
90ec2c9294 shading-pattern: Decreased Shadings.SMALL_NUMBER
and added a test case for #6298
2016-01-06 15:26:40 +01:00
Tim van der Meij
3f19b3fee3 Merge pull request #6842 from Snuffleupagus/intelisa-updated-link
Update the link location for 'intelisa.pdf' to point to the Internet Archive
2016-01-06 15:12:06 +01:00
Jonas Jenwald
325abf5f8c Update the link location for 'intelisa.pdf' to point to the Internet Archive
Given the the file changes every now and then, this patch should ensure that we test the *intended* version.
2016-01-06 12:56:31 +01:00
Jonas Jenwald
896e390285 Check that CIDFontType0 fonts does not actually contain OpenType font files (issue 6782)
*This patch follows a similar idea as PR 5756.*

The patch is based on the nice debugging done by Brendan in the referenced issue 6782.
A better way to handle this, and similar issues, would probably be to completely ignore what the PDF file claims about font type/subtype, and just check the actual data. But until that kind of rewrite happens, this patch should help.

Fixes 6782.
2016-01-06 02:19:02 +01:00
Tim van der Meij
4399d01169 Merge pull request #6834 from Snuffleupagus/issue-6832
Strip `null` (\x00) characters from the URLs in LinkAnnotations (issue 6832)
2016-01-05 23:59:25 +01:00
Yury Delendik
96d8b8f8a0 Merge pull request #6837 from Snuffleupagus/issue-3694-fix-manifest
Fix a typo in the "file" entry for issue3694_reduced in test_manifest.json
2016-01-05 14:56:08 -06:00
Jonas Jenwald
0083f63dda Fix a typo in the "file" entry for issue3694_reduced in test_manifest.json
When generating new references locally on Windows, after PR 6724, I get the following output:
```
WARNING: Unable to open file for reading "Error: ENOENT, open 'c:\Users\Jonas\Git\pdfjs\test\pdfs\issue_3694_reduced.pdf'".
Unable to verify the checksum for the files that are used for testing.
Please re-download the files, or adjust the MD5 checksum in the manifest for the files listed above.

```

Compared to the name of the file (`issue3694_reduced.pdf`), you see that the manifest entry has a superfluous underscore in the "file" entry.
2016-01-05 21:23:00 +01:00
Yury Delendik
62ade3e373 Merge pull request #6724 from brendandahl/callsubr
Add validation for callsubr and callgsubr for type 2 charstrings.
2016-01-05 13:46:14 -06:00
Brendan Dahl
eb7c36beb6 Add validation for callsubr and callgsubr for type 2 charstrings. 2016-01-05 09:54:25 -08:00
Jonas Jenwald
97c10e9c08 Strip null (\x00) characters from the URLs in LinkAnnotations (issue 6832)
Apparently some PDF files can have annotations with `URI` entries ending with `null` characters, thus breaking the links.
To handle this edge-case of bad PDFs, this patch moves the already existing utility function from `ui_utils.js` into `util.js`, in order to fix those URLs.

Fixes 6832.
2016-01-04 21:55:20 +01:00
Jonas Jenwald
4e9ea35eee Merge pull request #6827 from timvandermeij/highlight-annotation
Implement support for Highlight annotations
2016-01-02 14:23:52 +01:00
Tim van der Meij
6ef7120a04 Implement support for Highlight annotations 2016-01-01 15:31:46 +01:00
Tim van der Meij
8ed369211a Merge pull request #6823 from timvandermeij/squiggly-annotation
Implement support for Squiggly annotations
2015-12-30 20:34:13 +01:00
Yury Delendik
f340dd5cd5 Adds pdfjs/main_loader module to better mirror pdfjs-dist/build/pdf. 2015-12-30 13:28:57 -06:00
Tim van der Meij
34918a6666 Implement support for Squiggly annotations 2015-12-30 19:37:04 +01:00
Jonas Jenwald
d956177482 Merge pull request #6819 from timvandermeij/strikeout-annotation
Implement support for StrikeOut annotations
2015-12-30 14:44:50 +01:00
Yury Delendik
cbbb9bb82d Adds UMD header to pdf.js and pdf.worker.js files. 2015-12-29 18:15:14 -06:00
Tim van der Meij
e8db825512 Merge pull request #6771 from yurydelendik/requirejs
Removes hardcoded module loading order
2015-12-30 00:37:32 +01:00
Yury Delendik
b8e7efaaa1 Merge pull request #6821 from yurydelendik/bug951051
Bug 951051 - Better crypto key length recovery.
2015-12-29 15:35:15 -06:00
Yury Delendik
c991480687 Better crypto key length recovery. 2015-12-29 15:10:38 -06:00
Jonas Jenwald
1d1f175826 Apply Patterns, if necessary, when rendering text
Currently we're not applying Patterns for text, but only for graphics.

This patch is unfortunately not a complete solution, but rather a step on the way, since there are still some PDF files where the Patterns look more like a solid colour, rather than the intended gradient.
I've been unable to fix these issues completely, and I've not managed to determine if the remaining issues are caused either by the pattern code, the canvas code, or perhaps both.

However, given that even this simple patch improves the current situation quite a bit, I figured that it couldn't hurt to submit it as-is.

 - Fixes 5804.
 - Fixes 6130.
 - Improves 3988 a lot, since the text is now visible. However, it looks like the text is *one* solid colour, instead of the correct gradient.
 - Improves 5432, since the text is no longer gray. (This file also suffers from the same problem as the previous one.)
2015-12-29 20:02:40 +01:00
Yury Delendik
2b2c521213 Hack to avoid intermidiate Chrome failures during tests.
Remove when https://code.google.com/p/chromium/issues/detail?id=572225 is fixed.
2015-12-29 09:20:53 -06:00
Yury Delendik
2f8ae38276 Use UMD headers to detect module loading order. 2015-12-29 09:20:53 -06:00
Yury Delendik
fc3282db56 Adds RequireJS to worker. 2015-12-29 09:20:52 -06:00
Yury Delendik
85e95d34ed Use RequireJS in the viewer, examples and tests. 2015-12-29 09:20:52 -06:00
Tim van der Meij
c5f4b9750e Implement support for StrikeOut annotations 2015-12-29 15:09:28 +01:00
Jonas Jenwald
b32cdf5836 Merge pull request #6813 from timvandermeij/underline-annotation
Implement support for Underline annotations
2015-12-28 23:48:31 +01:00
Jonas Jenwald
85589483d6 Merge pull request #6807 from timvandermeij/popup-annotation-hidden
Ensure that hidden popups do not use any space
2015-12-28 22:58:41 +01:00
Tim van der Meij
ae329afc03 Ensure that hidden popups do not use any space 2015-12-28 18:54:10 +01:00
Tim van der Meij
edf8ccc1d8 Merge pull request #6814 from Snuffleupagus/beginAnnotations-baseTransform
Ensure that the `baseTransform` is applied when rendering annotations
2015-12-28 18:32:50 +01:00
Jonas Jenwald
2f2ea6160b Ensure that the baseTransform is applied when rendering annotations
Fixes 3350.
Fixes 5946.
Fixes 6334.
Fixes 6722.
Probably fixes 3826 (since the PDF files are no longer available, I cannot confirm it).
2015-12-28 16:02:38 +01:00
Tim van der Meij
cd28dd34fe Implement support for Underline annotations 2015-12-28 00:33:41 +01:00
Jonas Jenwald
f17d6721e7 Merge pull request #6808 from timvandermeij/link-annotation-class
Rename and reorder link annotation CSS
2015-12-27 16:40:50 +01:00
Tim van der Meij
26379ddae2 Rename and reorder link annotation CSS 2015-12-27 15:51:58 +01:00
Tim van der Meij
ad4354c0bd Merge pull request #6805 from Snuffleupagus/issue-6804
Do not modify `data.rect` in `AnnotationElement_createContainer`, since that will corrupt the annotation position on subsequent calls
2015-12-27 14:36:45 +01:00
Jonas Jenwald
3c7088dc44 Do not modify data.rect in AnnotationElement_createContainer, since that will corrupt the annotation position on subsequent calls
Fixes 6804; this regressed in PR 6714.
2015-12-27 12:46:20 +01:00
Yury Delendik
17780dab31 Import l10n. 2015-12-26 22:37:07 -06:00
Jonas Jenwald
cba8a87f84 Merge pull request #6792 from timvandermeij/popup-annotation
Implement support for Popup annotations
2015-12-26 18:51:50 +01:00
Tim van der Meij
7d43971f54 Implement support for Popup annotations
Most code for Popup annotations is already present for Text annotations.
This patch extracts the popup creation logic from the Text annotation
code so it can be reused for Popup annotations.

Not only does this add support for Popup annotations, the Text
annotation code is also considerably easier. If a `Popup` entry is
available for a Text annotation, it will not be more than an image. The
popup will be handled by the Popup annotation. However, it is also
possible for Text annotations to not have a separate Popup annotation,
in which case the Text annotation handles the popup creation itself.
2015-12-25 13:17:21 +01:00
Tim van der Meij
05b9d3730a Merge pull request #6785 from yurydelendik/frameworks
Adds/modifies examples for node.js and webpack.
2015-12-21 22:44:58 +01:00
Yury Delendik
79c2f69c32 Adds/modifies examples for node.js and webpack. 2015-12-21 13:46:50 -06:00
Tim van der Meij
eb557d200f Merge pull request #6787 from Snuffleupagus/issue-4914-test-annotations
Change test-case `issue4914` to an `annotations` test
2015-12-21 16:17:51 +01:00
Jonas Jenwald
ae4ec2e347 Change test-case issue4914 to an annotations test
This PDF file (see issue 4914) originally regressed in PR 4318, and was subsequently fixed in PR 4915.

I added the PDF file as a (linked) test-case in PR 6481, in an effort to prevent regressions. Since we at that time didn't have the necessary framework in place, in order to correctly test annotations, this almost regressed *again* in PR https://github.com/mozilla/pdf.js/pull/6672#issuecomment-158689392.

In that PDF file, some of the annotations are both printable and hidden, and should definitely *not* be visible on normal display. Hence this patch, which adds the `annotations` flag to the manifest in order to ensure that those annotations won't be rendered when `intent === 'display'`.
2015-12-21 15:41:18 +01:00
Yury Delendik
9f23e115e0 Merge pull request #6780 from timvandermeij/annotation-regression-tests
Implement annotation layer regression testing
2015-12-21 07:15:23 -06:00
Tim van der Meij
b7217a2274 Implement annotation layer regression testing 2015-12-20 13:45:56 +01:00
Jonas Jenwald
cfc0cc80ee Merge pull request #6770 from timvandermeij/annotation-display-classes
Refactor annotation display layer code to use classes
2015-12-20 13:03:14 +01:00
Tim van der Meij
5b66ad626d Refactor annotation display layer code to use classes 2015-12-19 19:31:37 +01:00
Tim van der Meij
9228e1ffcf Merge pull request #6772 from Snuffleupagus/remove-s-in-AnnotationsLayerBuilder
Remove a superfluous "s" in `AnnotationsLayerBuilder` from files in web/
2015-12-18 21:06:46 +01:00
Yury Delendik
e45e7d0f3c Merge pull request #6778 from tonyjin/fix-isExternalLinkTargetSet
Fixing externalLinkTarget
2015-12-18 13:33:15 -06:00
Tony Jin
f9e2091c5a Fixing externalLinkTarget. isExternalLinkTargetSet was set to
wrong sharedUtil method.
2015-12-18 11:27:21 -08:00
Jonas Jenwald
3079dd937f Remove a superfluous "s" in AnnotationsLayerBuilder from files in web/
This patch makes the naming consistent with the `TextLayerBuilder`, and also the new `AnnotationLayer`, and should thus help reduce possible confusion when working with the code.
Please note that the files were renamed using `git mv`, in order to preserve blame.
2015-12-18 19:55:54 +01:00
Yury Delendik
42beb0c27b Merge pull request #6767 from tonyjin/strip-link-referrer
Strip referrer from link annotation.
2015-12-18 12:27:15 -06:00
Yury Delendik
65de3d6268 Merge pull request #6765 from timvandermeij/unused
Remove unused variables
2015-12-18 10:43:40 -06:00
Yury Delendik
49437c879d Republish the extension. 2015-12-18 10:33:12 -06:00
Yury Delendik
479d96eb24 Testing ability to auto-upgrade the addons. 2015-12-18 10:05:20 -06:00
Yury Delendik
e7311cdc6e Fixes versions in update.rdf. 2015-12-18 09:44:18 -06:00
Yury Delendik
d98105fdbd Fixes update extension github link. 2015-12-18 09:32:46 -06:00
Yury Delendik
b533f8a854 Merge pull request #6773 from yurydelendik/xpisign
Changing Firefox Addon ID
2015-12-18 09:13:18 -06:00
Yury Delendik
2fb9baf6f1 Changing Firefox Addon ID
.. to allow AMO publishing to the unlisted extensions for automatic signing.
2015-12-18 09:06:23 -06:00
Tony Jin
11f3deac56 Allow link rel to be customized. Defaults to 'noreferrer' 2015-12-17 10:36:53 -08:00
Brendan Dahl
a8d760d97f Merge pull request #6766 from brendandahl/1.3
Bump versions to 1.3.
2015-12-16 15:14:00 -08:00
Tim van der Meij
df81b832bb Remove unused variables 2015-12-16 23:52:16 +01:00
Brendan Dahl
0521c1a3be Bump versions to 1.3. 2015-12-16 14:42:25 -08:00
Jonas Jenwald
f01911fcd9 Merge pull request #6764 from yurydelendik/rm-umd
Collapses UMD headers in bundled files.
2015-12-16 22:46:25 +01:00
Yury Delendik
2f704f5957 Collapses UMD headers in bundled files. 2015-12-16 07:42:54 -06:00
Jonas Jenwald
0a21c8c365 Merge pull request #6762 from Snuffleupagus/fix-Uint32ArrayView-exports
Only export `Uint32ArrayView` when it's actually defined, to prevent breaking e.g. the Firefox addon/built-in version
2015-12-16 11:24:41 +01:00
Jonas Jenwald
d4c026980e Only export Uint32ArrayView when it's actually defined, to prevent breaking e.g. the Firefox addon/built-in version
*This is a follow-up to PR 6683.*
2015-12-16 11:15:36 +01:00
Brendan Dahl
f1c64b6a2a Merge pull request #6683 from yurydelendik/module-core
Adds UMD headers to core, display and shared files.
2015-12-15 17:10:21 -08:00
Tim van der Meij
a1aec826ea Merge pull request #6758 from KamiHQ/fix-text-widget
Fix incorrect position of text widget
2015-12-16 00:29:39 +01:00
Xiliang Chen
8bf17f5df8 Fix incorrect position of text widget 2015-12-16 11:21:01 +13:00
Yury Delendik
b084dc09ee Allows requirejs and node load fake worker files. 2015-12-15 13:24:39 -06:00
Yury Delendik
450edc95cc UMD validation and generation tools. 2015-12-15 13:24:39 -06:00
Yury Delendik
6b60c8f4db Adds UMD headers to core, display and shared files. 2015-12-15 13:24:39 -06:00
621 changed files with 51189 additions and 30827 deletions

View file

@ -3,15 +3,14 @@ l10n/
docs/ docs/
node_modules/ node_modules/
examples/ examples/
external/bcmaps/
external/webL10n/ external/webL10n/
external/shelljs/
external/jpgjs/
external/jasmine/
external/cmapscompress/ external/cmapscompress/
external/importL10n/ external/builder/fixtures/
shared/ external/builder/fixtures_esprima/
test/tmp/ test/tmp/
test/features/ test/features/
test/pdfs/
test/resources/ test/resources/
test/font/*_spec.js test/font/*_spec.js
*~/ *~/

136
.eslintrc Normal file
View file

@ -0,0 +1,136 @@
{
"parserOptions": {
"ecmaVersion": 5,
},
"env": {
"browser": true,
"es6": true,
"worker": true,
"amd": true,
},
globals: {
"PDFJSDev": false,
"exports": false,
"SystemJS": false,
},
"rules": {
// Possible errors
"no-cond-assign": ["error", "except-parens"],
"no-constant-condition": ["error", { "checkLoops": false, }],
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": ["error", { "allowEmptyCatch": true, }],
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
"no-extra-semi": "error",
"no-func-assign": "error",
"no-inner-declarations": ["error", "functions"],
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-obj-calls": "error",
"no-regex-spaces": "error",
"no-sparse-arrays": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"use-isnan": "error",
"valid-typeof": ["error", { "requireStringLiterals": true, }],
// Best Practices
"accessor-pairs": ["error", { "setWithoutGet": true, }],
"curly": ["error", "all"],
"eqeqeq": ["error", "always"],
"no-caller": "error",
"no-else-return": "error",
"no-empty-pattern": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-fallthrough": "error",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-implied-eval": "error",
"no-iterator": "error",
"no-lone-blocks": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-new": "error",
"no-octal-escape": "error",
"no-octal": "error",
"no-redeclare": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"wrap-iife": ["error", "any"],
"yoda": ["error", "never", { "onlyEquality": true, }],
// Strict Mode
"strict": ["error", "global"],
// Variables
"no-catch-shadow": "error",
"no-delete-var": "error",
"no-label-var": "error",
"no-shadow-restricted-names": "error",
"no-undef-init": "error",
"no-undef": ["error", { "typeof": true, }],
"no-unused-vars": ["error", {
"vars": "local",
"args": "none",
}],
// Stylistic Issues
"array-bracket-spacing": ["error", "never"],
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", {
"allowSingleLine": false,
}],
"comma-spacing": ["error", { "before": false, "after": true, }],
"comma-style": ["error", "last"],
"eol-last": "error",
"func-call-spacing": ["error", "never"],
"key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "strict", }],
"keyword-spacing": ["error", { "before": true, "after": true, }],
"linebreak-style": ["error", "unix"],
"max-len": ["error", 80],
"new-cap": ["error", { "newIsCap": true, "capIsNew": false, }],
"new-parens": "error",
"no-array-constructor": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 0, "maxBOF": 1, }],
"no-new-object": "error",
"no-tabs": "error",
"no-trailing-spaces": ["error", { "skipBlankLines": false, }],
"no-whitespace-before-property": "error",
"operator-linebreak": ["error", "after", { "overrides": { ":": "ignore", } }],
"quotes": ["error", "single"],
"semi-spacing": ["error", { "before": false, "after": true, }],
"semi": ["error", "always"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", { "anonymous": "ignore", "named": "never", }],
"space-in-parens": ["error", "never"],
"space-infix-ops": ["error", { "int32Hint": false }],
"space-unary-ops": ["error", { "words": true, "nonwords": false, }],
"spaced-comment": ["error", "always", {
"line": {
"exceptions": ["//", "#else", "#endif"],
"markers": ["#if", "#elif", "#include", "#expand", "#error"],
},
"block": {
"balanced": true,
}
}],
// ECMAScript 6
},
}

View file

@ -4,7 +4,7 @@ The issues are used to track both bugs filed by users and specific work items fo
If the issue is related to errors produced by a specific PDF, please always include the PDF by providing a URL where contributors can download it. Without a PDF for reproduction, such issues will be closed. We understand that many PDFs contain sensitive information, however having a PDF is essential to resolving the issue and building our regression testing suite. If possible, try creating a reduced example exhibiting the problem but not containing sensitive data. Also small PDFs are best suited for our regression testing. If an important issue only shows on sensitive PDFs, contributors might be willing to accept these PDFs via a secure exchange. If the issue is related to errors produced by a specific PDF, please always include the PDF by providing a URL where contributors can download it. Without a PDF for reproduction, such issues will be closed. We understand that many PDFs contain sensitive information, however having a PDF is essential to resolving the issue and building our regression testing suite. If possible, try creating a reduced example exhibiting the problem but not containing sensitive data. Also small PDFs are best suited for our regression testing. If an important issue only shows on sensitive PDFs, contributors might be willing to accept these PDFs via a secure exchange.
The issue tracking system is designed to record a single technical problem. A bug report is something where a developer/contributor can work on. The GitHub issue tracker is not a good place for general, not well thought out or unworkable ideas. Most likely a discussion-type issue will not be addressed for a long time or closed as invalid. The best place is our dev-pdf-js@lists.mozilla.org mailing list. You can subscribe to it using http://lists.mozilla.org or Google Groups. This way you will reach not only developers. As an alternative, you can join our weekly engineering meeting to discuss new ideas for the project. The issue tracking system is designed to record a single technical problem. A bug report is something where a developer/contributor can work on. The GitHub issue tracker is not a good place for general, not well thought out or unworkable ideas. Most likely a discussion-type issue will not be addressed for a long time or closed as invalid. The best place for general discussions is our #pdfjs IRC channel on irc.mozilla.org.
If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us on the IRC channel -- keep in mind that just code snippets won't help us troubleshoot the problem. If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us on the IRC channel -- keep in mind that just code snippets won't help us troubleshoot the problem.

17
.github/ISSUE_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,17 @@
Link to PDF file (or attach file here):
Configuration:
- Web browser and its version:
- Operating system and its version:
- PDF.js version:
- Is an extension:
Steps to reproduce the problem:
1.
2.
What is the expected behavior? (add screenshot)
What went wrong? (add screenshot)
Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):

View file

@ -1,26 +0,0 @@
{
// Environments
"browser": true,
"devel": true,
"worker": true,
// Enforcing
"maxlen": 80,
"quotmark": "single",
"trailing": true,
"curly": true,
"undef": true,
"noarg": true,
"nonbsp": true,
"eqeqeq": true,
// Relaxing
"boss": true,
"funcscope": true,
"globalstrict": true,
"loopfunc": true,
"maxerr": 1000,
"nonstandard": true,
"sub": true,
"validthis": true
}

View file

@ -1,3 +1,11 @@
language: node_js language: node_js
node_js: node_js:
- "0.12" - node
cache:
directories:
- node_modules
install:
- npm install -g npm@latest
- npm install -g gulp-cli
- npm install
- npm update

View file

@ -9,38 +9,39 @@ rendering PDFs.
## Contributing ## Contributing
PDF.js is an open source project and always looking for more contributors. To PDF.js is an open source project and always looking for more contributors. To
get involved checkout: get involved, visit:
+ [Issue Reporting Guide](https://github.com/mozilla/pdf.js/blob/master/CONTRIBUTING.md) + [Issue Reporting Guide](https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md)
+ [Code Contribution Guide](https://github.com/mozilla/pdf.js/wiki/Contributing) + [Code Contribution Guide](https://github.com/mozilla/pdf.js/wiki/Contributing)
+ [Frequently Asked Questions](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions) + [Frequently Asked Questions](https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions)
+ [Good Beginner Bugs](https://github.com/mozilla/pdf.js/issues?direction=desc&labels=5-good-beginner-bug&page=1&sort=created&state=open) + [Good Beginner Bugs](https://github.com/mozilla/pdf.js/issues?direction=desc&labels=5-good-beginner-bug&page=1&sort=created&state=open)
+ [Priorities](https://github.com/mozilla/pdf.js/milestones) + [Projects](https://github.com/mozilla/pdf.js/projects)
+ [Attend a Public Meeting](https://github.com/mozilla/pdf.js/wiki/Weekly-Public-Meetings)
For further questions or guidance feel free to stop by #pdfjs on Feel free to stop by #pdfjs on irc.mozilla.org for questions or guidance.
irc.mozilla.org.
## Getting Started ## Getting Started
### Online demo ### Online demo
+ http://mozilla.github.io/pdf.js/web/viewer.html + https://mozilla.github.io/pdf.js/web/viewer.html
### Browser Extensions ### Browser Extensions
#### Firefox and Seamonkey #### Firefox (and Seamonkey)
PDF.js is built into version 19+ of Firefox, however the extension is still available: PDF.js is built into version 19+ of Firefox, however one extension is still available:
+ [Development Version](http://mozilla.github.io/pdf.js/extensions/firefox/pdf.js.xpi) - This version is updated every time new code is merged into the PDF.js codebase. This should be quite stable but still might break from time to time. This version is also reported to work when installed as extension in Seamonkey 2.39. + [Development Version](http://mozilla.github.io/pdf.js/extensions/firefox/pdf.js.xpi) - This extension is mainly intended for developers/testers, and it is updated every time new code is merged into the PDF.js codebase. It should be quite stable, but might break from time to time.
#### Chrome and Opera + Please note that the extension is *not* guaranteed to be compatible with Firefox versions that are *older* than the current ESR version, see the [Release Calendar](https://wiki.mozilla.org/RapidRelease/Calendar#Past_branch_dates).
+ The extension should also work in Seamonkey, provided that it is based on a Firefox version as above (see [Which version of Firefox does SeaMonkey 2.x correspond with?](https://wiki.mozilla.org/SeaMonkey/FAQ#General)), but we do *not* guarantee compatibility.
#### Chrome
+ The official extension for Chrome can be installed from the [Chrome Web Store](https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm). + The official extension for Chrome can be installed from the [Chrome Web Store](https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm).
*This extension is maintained by [@Rob--W](https://github.com/Rob--W).* *This extension is maintained by [@Rob--W](https://github.com/Rob--W).*
+ Opera has also published an extension for their browser at the [Opera add-ons catalog](https://addons.opera.com/en/extensions/details/pdf-viewer/). + Build Your Own - Get the code as explained below and issue `gulp chromium`. Then open
+ Build Your Own - Get the code as explained below and issue `node make chromium`. Then open
Chrome, go to `Tools > Extension` and load the (unpackaged) extension from the Chrome, go to `Tools > Extension` and load the (unpackaged) extension from the
directory `build/chromium`. directory `build/chromium`.
@ -52,16 +53,19 @@ To get a local copy of the current code, clone it using git:
$ cd pdf.js $ cd pdf.js
Next, install Node.js via the [official package](http://nodejs.org) or via Next, install Node.js via the [official package](http://nodejs.org) or via
[nvm](https://github.com/creationix/nvm). If everything worked out, run [nvm](https://github.com/creationix/nvm). You need to install the gulp package
globally (see also [gulp's getting started](https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md#getting-started)):
$ npm install -g gulp-cli
If everything worked out, install all dependencies for PDF.js:
$ npm install $ npm install
to install all dependencies for PDF.js.
Finally you need to start a local web server as some browsers do not allow opening Finally you need to start a local web server as some browsers do not allow opening
PDF files using a file:// URL. Run PDF files using a file:// URL. Run
$ node make server $ gulp server
and then you can open and then you can open
@ -73,10 +77,10 @@ It is also possible to view all test PDF files on the right side by opening
## Building PDF.js ## Building PDF.js
In order to bundle all `src/` files into two productions scripts and build the generic In order to bundle all `src/` files into two production scripts and build the generic
viewer, issue: viewer, run:
$ node make generic $ gulp generic
This will generate `pdf.js` and `pdf.worker.js` in the `build/generic/build/` directory. This will generate `pdf.js` and `pdf.worker.js` in the `build/generic/build/` directory.
Both scripts are needed but only `pdf.js` needs to be included since `pdf.worker.js` will Both scripts are needed but only `pdf.js` needs to be included since `pdf.worker.js` will
@ -84,15 +88,21 @@ be loaded by `pdf.js`. If you want to support more browsers than Firefox you'll
to include `compatibility.js` from `build/generic/web/`. The PDF.js files are large and to include `compatibility.js` from `build/generic/web/`. The PDF.js files are large and
should be minified for production. should be minified for production.
## Using PDF.js in a web application
To use PDF.js in a web application you can choose to use a pre-built version of the library
or to build it from source. We supply pre-built versions for usage with NPM and Bower under
the `pdfjs-dist` name. For more information and examples please refer to the
[wiki page](https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website) on this subject.
## Learning ## Learning
You can play with the PDF.js API directly from your browser through the live You can play with the PDF.js API directly from your browser using the live
demos below: demos below:
+ [Hello world](http://mozilla.github.io/pdf.js/examples/learning/helloworld.html) + [Interactive examples](http://mozilla.github.io/pdf.js/examples/index.html#interactive-examples)
+ [Simple reader with prev/next page controls](http://mozilla.github.io/pdf.js/examples/learning/prevnext.html)
The repo contains a hello world example that you can run locally: The repository contains a hello world example that you can run locally:
+ [examples/helloworld/](https://github.com/mozilla/pdf.js/blob/master/examples/helloworld/) + [examples/helloworld/](https://github.com/mozilla/pdf.js/blob/master/examples/helloworld/)
@ -101,12 +111,7 @@ contributor Julian Viereck:
+ http://www.youtube.com/watch?v=Iv15UY-4Fg8 + http://www.youtube.com/watch?v=Iv15UY-4Fg8
You can read more about PDF.js here: More learning resources can be found at:
+ http://andreasgal.com/2011/06/15/pdf-js/
+ http://blog.mozilla.com/cjones/2011/06/15/overview-of-pdf-js-guts/
Even more learning resources can be found at:
+ https://github.com/mozilla/pdf.js/wiki/Additional-Learning-Resources + https://github.com/mozilla/pdf.js/wiki/Additional-Learning-Resources
@ -120,19 +125,10 @@ Talk to us on IRC:
+ #pdfjs on irc.mozilla.org + #pdfjs on irc.mozilla.org
Join our mailing list: File an issue:
+ dev-pdf-js@lists.mozilla.org + https://github.com/mozilla/pdf.js/issues/new
Subscribe either using lists.mozilla.org or Google Groups:
+ https://lists.mozilla.org/listinfo/dev-pdf-js
+ https://groups.google.com/group/mozilla.dev.pdf-js/topics
Follow us on twitter: @pdfjs Follow us on twitter: @pdfjs
+ http://twitter.com/#!/pdfjs + http://twitter.com/#!/pdfjs
Weekly Public Meetings
+ https://github.com/mozilla/pdf.js/wiki/Weekly-Public-Meetings

View file

@ -61,3 +61,25 @@ var viewport = page.getViewport(1);
var scale = desiredWidth / viewport.width; var scale = desiredWidth / viewport.width;
var scaledViewport = page.getViewport(scale); var scaledViewport = page.getViewport(scale);
``` ```
## Interactive examples
### Hello World with document load error handling
The example demonstrates how promises can be used to handle errors during loading.
It also demonstrates how to wait until page loaded and rendered.
<script async src="//jsfiddle.net/pdfjs/9engc9mw/embed/js,html,result/"></script>
### Hello World using base64 encoded PDF
The PDF.js can accept any decoded base64 data as an array.
<script async src="//jsfiddle.net/pdfjs/cq0asLqz/embed/js,html,result/"></script>
### Previous/Next example
The same canvas cannot be used to perform to draw two pages at the same time --
the example demonstrate how to wait on previous operation to be complete.
<script async src="//jsfiddle.net/pdfjs/wagvs9Lf/embed/js,html,result/"></script>

View file

@ -107,7 +107,7 @@ $ cd pdf.js
## Trying the Viewer ## Trying the Viewer
With the prebuilt or source version open `web/viewer.html` in a browser and the test pdf should load. Note: the worker is not enabled for file:// urls, so use a server. If you're using the source build and have node, you can run `node make server`. With the prebuilt or source version open `web/viewer.html` in a browser and the test pdf should load. Note: the worker is not enabled for file:// urls, so use a server. If you're using the source build and have node, you can run `gulp server`.
## More Information ## More Information

View file

@ -10,5 +10,5 @@ template: layout.jade
<p class="text-center"> <p class="text-center">
<a type="button" class="btn btn-lg btn-default" href="getting_started/#download">Download</a> <a type="button" class="btn btn-lg btn-default" href="getting_started/#download">Download</a>
<a type="button" class="btn btn-lg btn-default" href="web/viewer.html">Demo</a> <a type="button" class="btn btn-lg btn-default" href="web/viewer.html">Demo</a>
<a type="button" class="btn btn-lg btn-default" href="https://github.com/mozilla/pdf.js">Github Project</a> <a type="button" class="btn btn-lg btn-default" href="https://github.com/mozilla/pdf.js">GitHub Project</a>
</p> </p>

View file

@ -0,0 +1,11 @@
## Overview
Example to demonstrate PDF.js library usage for rendering files with AcroForms.
## Getting started
Build PDF.js using `gulp dist` and run `gulp server` to start a web server.
You can then work with the example at
http://localhost:8888/examples/acroforms/acroforms.html.
Refer to `acroforms.js` for the source code of the example.

View file

@ -0,0 +1,44 @@
<!DOCTYPE html>
<!--
Copyright 2017 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html dir="ltr">
<head>
<meta charset="utf-8">
<title>AcroForms example</title>
<link rel="stylesheet" href="../../build/dist/web/pdf_viewer.css">
<script src="../../build/dist/build/pdf.js"></script>
<script src="../../build/dist/web/pdf_viewer.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
.page {
position: relative;
}
</style>
</head>
<body>
<div id="pageContainer"></div>
<script src="acroforms.js"></script>
</body>
</html>

View file

@ -0,0 +1,49 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js';
var DEFAULT_URL = '../../test/pdfs/f1040.pdf';
var DEFAULT_SCALE = 1.0;
var container = document.getElementById('pageContainer');
// Fetch the PDF document from the URL using promises.
PDFJS.getDocument(DEFAULT_URL).then(function (doc) {
// Use a promise to fetch and render the next page.
var promise = Promise.resolve();
for (var i = 1; i <= doc.numPages; i++) {
promise = promise.then(function (pageNum) {
return doc.getPage(pageNum).then(function (pdfPage) {
// Create the page view.
var pdfPageView = new PDFJS.PDFPageView({
container: container,
id: pageNum,
scale: DEFAULT_SCALE,
defaultViewport: pdfPage.getViewport(DEFAULT_SCALE),
annotationLayerFactory: new PDFJS.DefaultAnnotationLayerFactory(),
renderInteractiveForms: true,
});
// Associate the actual page with the view and draw it.
pdfPageView.setPdfPage(pdfPage);
return pdfPageView.draw();
});
}.bind(null, i));
}
});

View file

@ -1,150 +0,0 @@
//
// Basic AcroForms input controls rendering
//
'use strict';
var formFields = {};
function setupForm(div, content, viewport) {
function bindInputItem(input, item) {
if (input.name in formFields) {
var value = formFields[input.name];
if (input.type == 'checkbox') {
input.checked = value;
} else if (!input.type || input.type == 'text') {
input.value = value;
}
}
input.onchange = function pageViewSetupInputOnBlur() {
if (input.type == 'checkbox') {
formFields[input.name] = input.checked;
} else if (!input.type || input.type == 'text') {
formFields[input.name] = input.value;
}
};
}
function createElementWithStyle(tagName, item) {
var element = document.createElement(tagName);
var rect = PDFJS.Util.normalizeRect(
viewport.convertToViewportRectangle(item.rect));
element.style.left = Math.floor(rect[0]) + 'px';
element.style.top = Math.floor(rect[1]) + 'px';
element.style.width = Math.ceil(rect[2] - rect[0]) + 'px';
element.style.height = Math.ceil(rect[3] - rect[1]) + 'px';
return element;
}
function assignFontStyle(element, item) {
var fontStyles = '';
if ('fontSize' in item) {
fontStyles += 'font-size: ' + Math.round(item.fontSize *
viewport.fontScale) + 'px;';
}
switch (item.textAlignment) {
case 0:
fontStyles += 'text-align: left;';
break;
case 1:
fontStyles += 'text-align: center;';
break;
case 2:
fontStyles += 'text-align: right;';
break;
}
element.setAttribute('style', element.getAttribute('style') + fontStyles);
}
content.getAnnotations().then(function(items) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
switch (item.subtype) {
case 'Widget':
if (item.fieldType != 'Tx' && item.fieldType != 'Btn' &&
item.fieldType != 'Ch') {
break;
}
var inputDiv = createElementWithStyle('div', item);
inputDiv.className = 'inputHint';
div.appendChild(inputDiv);
var input;
if (item.fieldType == 'Tx') {
input = createElementWithStyle('input', item);
}
if (item.fieldType == 'Btn') {
input = createElementWithStyle('input', item);
if (item.flags & 32768) {
input.type = 'radio';
// radio button is not supported
} else if (item.flags & 65536) {
input.type = 'button';
// pushbutton is not supported
} else {
input.type = 'checkbox';
}
}
if (item.fieldType == 'Ch') {
input = createElementWithStyle('select', item);
// select box is not supported
}
input.className = 'inputControl';
input.name = item.fullName;
input.title = item.alternativeText;
assignFontStyle(input, item);
bindInputItem(input, item);
div.appendChild(input);
break;
}
}
});
}
function renderPage(div, pdf, pageNumber, callback) {
pdf.getPage(pageNumber).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var pageDisplayWidth = viewport.width;
var pageDisplayHeight = viewport.height;
var pageDivHolder = document.createElement('div');
pageDivHolder.className = 'pdfpage';
pageDivHolder.style.width = pageDisplayWidth + 'px';
pageDivHolder.style.height = pageDisplayHeight + 'px';
div.appendChild(pageDivHolder);
// Prepare canvas using PDF page dimensions
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
canvas.width = pageDisplayWidth;
canvas.height = pageDisplayHeight;
pageDivHolder.appendChild(canvas);
// Render PDF page into canvas context
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext).promise.then(callback);
// Prepare and populate form elements layer
var formDiv = document.createElement('div');
pageDivHolder.appendChild(formDiv);
setupForm(formDiv, page, viewport);
});
}
// Fetch the PDF document from the URL using promices
PDFJS.getDocument(pdfWithFormsPath).then(function getPdfForm(pdf) {
// Rendering all pages starting from first
var viewer = document.getElementById('viewer');
var pageNumber = 1;
renderPage(viewer, pdf, pageNumber++, function pageRenderingComplete() {
if (pageNumber > pdf.numPages) {
return; // All pages rendered
}
// Continue rendering of the next page
renderPage(viewer, pdf, pageNumber++, pageRenderingComplete);
});
});

View file

@ -1,43 +0,0 @@
<!doctype html>
<html>
<head>
<!-- In production, only one script (pdf.js) is necessary -->
<!-- In production, change the content of PDFJS.workerSrc below -->
<script src="../../src/shared/util.js"></script>
<script src="../../src/display/api.js"></script>
<script src="../../src/display/metadata.js"></script>
<script src="../../src/display/canvas.js"></script>
<script src="../../src/display/webgl.js"></script>
<script src="../../src/display/pattern_helper.js"></script>
<script src="../../src/display/font_loader.js"></script>
<script src="../../src/display/dom_utils.js"></script>
<script src="../../src/display/annotation_layer.js"></script>
<script src="../../src/display/text_layer.js"></script>
<script>
// Specify the main script used to create a new PDF.JS web worker.
// In production, change this to point to the combined `pdf.js` file.
PDFJS.workerSrc = '../../src/worker_loader.js';
// Specify the PDF with AcroForm here
var pdfWithFormsPath = '../../test/pdfs/f1040.pdf';
</script>
<style>
.pdfpage { position:relative; top: 0; left: 0; border: solid 1px black; margin: 10px; }
.pdfpage > canvas { position: absolute; top: 0; left: 0; }
.pdfpage > div { position: absolute; top: 0; left: 0; }
.inputControl { background: transparent; border: 0px none; position: absolute; margin: auto; }
.inputControl[type='checkbox'] { margin: 0px; }
.inputHint { opacity: 0.2; background: #ccc; position: absolute; }
</style>
<script src="forms.js"></script>
</head>
<body>
<div id="viewer"></div>
</body>
</html>

1
examples/browserify/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules/

View file

@ -0,0 +1,26 @@
## Overview
Example to demonstrate PDF.js library usage with Browserify.
## Getting started
Build project and install the example dependencies:
$ gulp dist
$ cd examples/browserify
$ npm install
To build Browserify bundles, run `gulp build`. If you are running
a web server, you can observe the build results at
http://localhost:8888/examples/browserify/index.html
See main.js, worker.js and gulpfile.js files. Please notice that PDF.js
packaging requires packaging of the main application and PDF.js worker code,
and the `workerSrc` path shall be set to the latter file. The pdf.worker.js file
shall be excluded from the main bundle.
Alternatives to the gulp commands (without compression) are:
$ mkdir -p ../../build/browserify
$ node_modules/.bin/browserify main.js -u ./node_modules/pdfjs-dist/build/pdf.worker.js -o ../../build/browserify/main.bundle.js
$ node_modules/.bin/browserify worker.js -o ../../build/browserify/pdf.worker.bundle.js

View file

@ -0,0 +1,34 @@
var gulp = require('gulp');
var browserify = require('browserify');
var streamify = require('gulp-streamify');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var OUTPUT_PATH = '../../build/browserify';
var TMP_FILE_PREFIX = '../../build/browserify_';
gulp.task('build-bundle', function() {
return browserify('main.js', {output: TMP_FILE_PREFIX + 'main.tmp'})
.ignore(require.resolve('pdfjs-dist/build/pdf.worker')) // Reducing size
.bundle()
.pipe(source(TMP_FILE_PREFIX + 'main.tmp'))
.pipe(streamify(uglify()))
.pipe(rename('main.bundle.js'))
.pipe(gulp.dest(OUTPUT_PATH));
});
gulp.task('build-worker', function() {
// We can create our own viewer (see worker.js) or use already defined one.
var workerSrc = require.resolve('pdfjs-dist/build/pdf.worker.entry');
return browserify(workerSrc, {output: TMP_FILE_PREFIX + 'worker.tmp'})
.bundle()
.pipe(source(TMP_FILE_PREFIX + 'worker.tmp'))
.pipe(streamify(uglify({compress:{
sequences: false // Chrome has issue with the generated code if true
}})))
.pipe(rename('pdf.worker.bundle.js'))
.pipe(gulp.dest(OUTPUT_PATH));
});
gulp.task('build', ['build-bundle', 'build-worker']);

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>browserify example</title>
<script src="../../build/browserify/main.bundle.js"></script>
</head>
<body>
<canvas id="theCanvas"></canvas>
</body>
</html>

View file

@ -0,0 +1,35 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
// Hello world example for browserify.
require('pdfjs-dist');
var pdfPath = '../helloworld/helloworld.pdf';
// Setting worker path to worker bundle.
PDFJS.workerSrc = '../../build/browserify/pdf.worker.bundle.js';
// It is also possible to disable workers via `PDFJS.disableWorker = true`,
// however that might degrade the UI performance in web browsers.
// Loading a document.
var loadingTask = PDFJS.getDocument(pdfPath);
loadingTask.promise.then(function (pdfDocument) {
// Request a first page
return pdfDocument.getPage(1).then(function (pdfPage) {
// Display page on the existing canvas with 100% scale.
var viewport = pdfPage.getViewport(1.0);
var canvas = document.getElementById('theCanvas');
canvas.width = viewport.width;
canvas.height = viewport.height;
var ctx = canvas.getContext('2d');
var renderTask = pdfPage.render({
canvasContext: ctx,
viewport: viewport
});
return renderTask.promise;
});
}).catch(function (reason) {
console.error('Error: ' + reason);
});

View file

@ -0,0 +1,16 @@
{
"name": "browserify-pdf.js-example",
"version": "0.1.0",
"devDependencies": {
"browserify": "^13.0.0",
"gulp": "^3.9.1",
"gulp-rename": "^1.2.2",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "^1.5.3",
"pdfjs-dist": "../../build/dist",
"vinyl-source-stream": "^1.1.0"
},
"scripts": {
"build": "gulp build"
}
}

View file

@ -0,0 +1,7 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
// Hello world example for browserify: worker bundle.
(typeof window !== 'undefined' ? window : {}).pdfjsDistBuildPdfWorker =
require('pdfjs-dist/build/pdf.worker');

View file

@ -29,16 +29,14 @@ limitations under the License.
} }
</style> </style>
<link rel="stylesheet" href="../../build/components/pdf_viewer.css"> <link rel="stylesheet" href="../../build/dist/web/pdf_viewer.css">
<!-- for legacy browsers --> <script src="../../build/dist/build/pdf.js"></script>
<script src="../../build/components/compatibility.js"></script> <script src="../../build/dist/web/pdf_viewer.js"></script>
<script src="../../build/pdf.js"></script>
<script src="../../build/components/pdf_viewer.js"></script>
</head> </head>
<body tabindex="1"> <body tabindex="1">
<div id="pageContainer" class="pdfPage"></div> <div id="pageContainer" class="pdfViewer singlePageView"></div>
<script src="pageviewer.js"></script> <script src="pageviewer.js"></script>
</body> </body>

View file

@ -16,17 +16,17 @@
'use strict'; 'use strict';
if (!PDFJS.PDFViewer || !PDFJS.getDocument) { if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
alert('Please build the library and components using\n' + alert('Please build the pdfjs-dist library using\n' +
' `node make generic components`'); ' `gulp dist`');
} }
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
PDFJS.workerSrc = '../../build/pdf.worker.js'; PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js';
// Some PDFs need external cmaps. // Some PDFs need external cmaps.
// //
// PDFJS.cMapUrl = '../../external/bcmaps/'; // PDFJS.cMapUrl = '../../build/dist/cmaps/';
// PDFJS.cMapPacked = true; // PDFJS.cMapPacked = true;
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
@ -47,7 +47,7 @@ PDFJS.getDocument(DEFAULT_URL).then(function (pdfDocument) {
defaultViewport: pdfPage.getViewport(SCALE), defaultViewport: pdfPage.getViewport(SCALE),
// We can enable text/annotations layers, if needed // We can enable text/annotations layers, if needed
textLayerFactory: new PDFJS.DefaultTextLayerFactory(), textLayerFactory: new PDFJS.DefaultTextLayerFactory(),
annotationsLayerFactory: new PDFJS.DefaultAnnotationsLayerFactory() annotationLayerFactory: new PDFJS.DefaultAnnotationLayerFactory()
}); });
// Associates the actual page with the view, and drawing it // Associates the actual page with the view, and drawing it
pdfPageView.setPdfPage(pdfPage); pdfPageView.setPdfPage(pdfPage);

View file

@ -35,12 +35,10 @@ limitations under the License.
} }
</style> </style>
<link rel="stylesheet" href="../../build/components/pdf_viewer.css"> <link rel="stylesheet" href="../../build/dist/web/pdf_viewer.css">
<!-- for legacy browsers --> <script src="../../build/dist/build/pdf.js"></script>
<script src="../../build/components/compatibility.js"></script> <script src="../../build/dist/web/pdf_viewer.js"></script>
<script src="../../build/pdf.js"></script>
<script src="../../build/components/pdf_viewer.js"></script>
</head> </head>
<body tabindex="1"> <body tabindex="1">

View file

@ -16,20 +16,21 @@
'use strict'; 'use strict';
if (!PDFJS.PDFViewer || !PDFJS.getDocument) { if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
alert('Please build the library and components using\n' + alert('Please build the pdfjs-dist library using\n' +
' `node make generic components`'); ' `gulp dist`');
} }
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
PDFJS.workerSrc = '../../build/pdf.worker.js'; PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js';
// Some PDFs need external cmaps. // Some PDFs need external cmaps.
// //
// PDFJS.cMapUrl = '../../external/bcmaps/'; // PDFJS.cMapUrl = '../../build/dist/cmaps/';
// PDFJS.cMapPacked = true; // PDFJS.cMapPacked = true;
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf'; var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
var SEARCH_FOR = ''; // try 'Mozilla';
var container = document.getElementById('viewerContainer'); var container = document.getElementById('viewerContainer');
@ -42,9 +43,19 @@ var pdfViewer = new PDFJS.PDFViewer({
}); });
pdfLinkService.setViewer(pdfViewer); pdfLinkService.setViewer(pdfViewer);
// (Optionally) enable find controller.
var pdfFindController = new PDFJS.PDFFindController({
pdfViewer: pdfViewer
});
pdfViewer.setFindController(pdfFindController);
container.addEventListener('pagesinit', function () { container.addEventListener('pagesinit', function () {
// We can use pdfViewer now, e.g. let's change default scale. // We can use pdfViewer now, e.g. let's change default scale.
pdfViewer.currentScaleValue = 'page-width'; pdfViewer.currentScaleValue = 'page-width';
if (SEARCH_FOR) { // We can try search for things
pdfFindController.executeCommand('find', {query: SEARCH_FOR});
}
}); });
// Loading document. // Loading document.

View file

@ -8,7 +8,7 @@ simple and human-readable PDF.
Instead of simply opening `index.html` in a browser, you must serve the page Instead of simply opening `index.html` in a browser, you must serve the page
using a web server. This can be done on your local machine without an internet using a web server. This can be done on your local machine without an internet
connection. In the root directory of PDF.js, run `node make server` in a connection. In the root directory of PDF.js, run `gulp server` in a
terminal. The example can then be viewed using the following URL: terminal. The example can then be viewed using the following URL:
`http://localhost:8888/examples/helloworld/index.html` `http://localhost:8888/examples/helloworld/index.html`

View file

@ -1,34 +1,32 @@
//
// See README for overview
//
'use strict'; 'use strict';
// // In production, the bundled pdf.js shall be used instead of SystemJS.
// Fetch the PDF document from the URL using promises Promise.all([SystemJS.import('pdfjs/display/api'),
// SystemJS.import('pdfjs/display/global')])
PDFJS.getDocument('helloworld.pdf').then(function(pdf) { .then(function (modules) {
// Using promise to fetch the page var api = modules[0], global = modules[1];
pdf.getPage(1).then(function(page) { // In production, change this to point to the built `pdf.worker.js` file.
var scale = 1.5; global.PDFJS.workerSrc = '../../src/worker_loader.js';
var viewport = page.getViewport(scale);
// // Fetch the PDF document from the URL using promises.
// Prepare canvas using PDF page dimensions api.getDocument('helloworld.pdf').then(function (pdf) {
// // Fetch the page.
var canvas = document.getElementById('the-canvas'); pdf.getPage(1).then(function (page) {
var context = canvas.getContext('2d'); var scale = 1.5;
canvas.height = viewport.height; var viewport = page.getViewport(scale);
canvas.width = viewport.width;
// // Prepare canvas using PDF page dimensions.
// Render PDF page into canvas context var canvas = document.getElementById('the-canvas');
// var context = canvas.getContext('2d');
var renderContext = { canvas.height = viewport.height;
canvasContext: context, canvas.width = viewport.width;
viewport: viewport
}; // Render PDF page into canvas context.
page.render(renderContext); var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
}); });
}); });

View file

@ -2,25 +2,8 @@
<html> <html>
<head> <head>
<!-- In production, only one script (pdf.js) is necessary --> <script src="../../node_modules/systemjs/dist/system.js"></script>
<!-- In production, change the content of PDFJS.workerSrc below --> <script src="../../systemjs.config.js"></script>
<script src="../../src/shared/util.js"></script>
<script src="../../src/display/api.js"></script>
<script src="../../src/display/metadata.js"></script>
<script src="../../src/display/canvas.js"></script>
<script src="../../src/display/webgl.js"></script>
<script src="../../src/display/pattern_helper.js"></script>
<script src="../../src/display/font_loader.js"></script>
<script src="../../src/display/dom_utils.js"></script>
<script src="../../src/display/annotation_layer.js"></script>
<script src="../../src/display/text_layer.js"></script>
<script>
// Specify the main script used to create a new PDF.JS web worker.
// In production, leave this undefined or change it to point to the
// combined `pdf.worker.js` file.
PDFJS.workerSrc = '../../src/worker_loader.js';
</script>
<script src="hello.js"></script> <script src="hello.js"></script>
</head> </head>

View file

@ -13,7 +13,7 @@
<!-- for legacy browsers add compatibility.js --> <!-- for legacy browsers add compatibility.js -->
<!--<script src="../compatibility.js"></script>--> <!--<script src="../compatibility.js"></script>-->
<script src="../../build/pdf.js"></script> <script src="../../build/generic/build/pdf.js"></script>
<script id="script"> <script id="script">
// //
@ -32,7 +32,7 @@
// //
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
PDFJS.workerSrc = '../../build/pdf.worker.js'; PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js';
// //
// Asynchronous download PDF // Asynchronous download PDF

View file

@ -10,10 +10,7 @@
<canvas id="the-canvas" style="border:1px solid black"></canvas> <canvas id="the-canvas" style="border:1px solid black"></canvas>
<!-- for legacy browsers we need to use compatibility.js --> <script src="../../build/generic/build/pdf.js"></script>
<script src="../../web/compatibility.js"></script>
<script src="../../build/pdf.js"></script>
<script id="script"> <script id="script">
// atob() is used to convert base64 encoded PDF to binary-like data. // atob() is used to convert base64 encoded PDF to binary-like data.
@ -43,7 +40,7 @@
// //
// The workerSrc property shall be specified. // The workerSrc property shall be specified.
// //
PDFJS.workerSrc = '../../build/pdf.worker.js'; PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js';
// Opening PDF by passing its binary data as a string. It is still preferable // Opening PDF by passing its binary data as a string. It is still preferable
// to use Uint8Array, but string or array-like structure will work too. // to use Uint8Array, but string or array-like structure will work too.

View file

@ -22,7 +22,7 @@
<!-- for legacy browsers add compatibility.js --> <!-- for legacy browsers add compatibility.js -->
<!--<script src="../compatibility.js"></script>--> <!--<script src="../compatibility.js"></script>-->
<script src="../../build/pdf.js"></script> <script src="../../build/generic/build/pdf.js"></script>
<script id="script"> <script id="script">
// //
@ -44,7 +44,7 @@
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property // pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
// shall be specified. // shall be specified.
// //
// PDFJS.workerSrc = '../../build/pdf.worker.js'; // PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js';
var pdfDoc = null, var pdfDoc = null,
pageNum = 1, pageNum = 1,

View file

@ -0,0 +1,11 @@
## Overview
Example to demonstrate PDF.js library usage with a viewer optimized for mobile usage.
## Getting started
Build PDF.js using `gulp dist` and run `gulp server` to start a web server.
You can then work with the mobile viewer at
http://localhost:8888/examples/mobile-viewer/viewer.html.
Refer to `viewer.js` for the source code of the mobile viewer.

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 395 B

View file

Before

Width:  |  Height:  |  Size: 640 B

After

Width:  |  Height:  |  Size: 640 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

Before

Width:  |  Height:  |  Size: 564 B

After

Width:  |  Height:  |  Size: 564 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View file

@ -1,4 +1,4 @@
/* Copyright 2012 Mozilla Foundation /* Copyright 2016 Mozilla Foundation
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,6 +25,23 @@ html {
font-size: 10px; font-size: 10px;
} }
header {
background-color: #f4f4f4;
}
header h1 {
border-bottom: 1px solid #d8d8d8;
color: #858585;
font-size: 23px;
font-style: italic;
font-weight: normal;
overflow: hidden;
padding: 10px;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
}
body { body {
background: url(images/document_bg.png); background: url(images/document_bg.png);
color: #fff; color: #fff;
@ -57,7 +74,6 @@ footer {
box-shadow: 0 -0.2rem 0.5rem rgba(50, 50, 50, 0.75); box-shadow: 0 -0.2rem 0.5rem rgba(50, 50, 50, 0.75);
} }
.toolbarButton { .toolbarButton {
display: block; display: block;
padding: 0; padding: 0;

View file

@ -0,0 +1,76 @@
<!DOCTYPE html>
<!--
Copyright 2016 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>PDF.js viewer</title>
<link rel="stylesheet" href="../../build/dist/web/pdf_viewer.css">
<link rel="stylesheet" type="text/css" href="viewer.css">
<script src="../../build/dist/build/pdf.js"></script>
<script src="../../build/dist/web/pdf_viewer.js"></script>
<script src="viewer.js"></script>
</head>
<body>
<header>
<h1 id="title"></h1>
</header>
<div id="viewerContainer">
<div id="viewer" class="pdfViewer"></div>
</div>
<div id="loadingBar">
<div class="progress"></div>
<div class="glimmer"></div>
</div>
<div id="errorWrapper" hidden="true">
<div id="errorMessageLeft">
<span id="errorMessage"></span>
<button id="errorShowMore">
More Information
</button>
<button id="errorShowLess">
Less Information
</button>
</div>
<div id="errorMessageRight">
<button id="errorClose">
Close
</button>
</div>
<div class="clearBoth"></div>
<textarea id="errorMoreInfo" hidden="true" readonly="readonly"></textarea>
</div>
<footer>
<button class="toolbarButton pageUp" title="Previous Page" id="previous"></button>
<button class="toolbarButton pageDown" title="Next Page" id="next"></button>
<input type="number" id="pageNumber" class="toolbarField pageNumber" value="1" size="4" min="1">
<button class="toolbarButton zoomOut" title="Zoom Out" id="zoomOut"></button>
<button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn"></button>
</footer>
</body>
</html>

View file

@ -1,4 +1,4 @@
/* Copyright 2014 Mozilla Foundation /* Copyright 2016 Mozilla Foundation
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -12,49 +12,71 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFJS */
/* globals PDFJS, Promise */
'use strict'; 'use strict';
if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
alert('Please build the pdfjs-dist library using\n' +
' `gulp dist`');
}
PDFJS.useOnlyCssZoom = true; PDFJS.useOnlyCssZoom = true;
PDFJS.disableTextLayer = true; PDFJS.disableTextLayer = true;
PDFJS.maxImageSize = 1024 * 1024; PDFJS.maxImageSize = 1024 * 1024;
PDFJS.workerSrc = '../pdfjs-components/build/pdf.worker.js'; PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js';
PDFJS.cMapUrl = '../pdfjs-components/cmaps/'; PDFJS.cMapUrl = '../../build/dist/cmaps/';
PDFJS.cMapPacked = true; PDFJS.cMapPacked = true;
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
var DEFAULT_SCALE_DELTA = 1.1; var DEFAULT_SCALE_DELTA = 1.1;
var MIN_SCALE = 0.25; var MIN_SCALE = 0.25;
var MAX_SCALE = 10.0; var MAX_SCALE = 10.0;
var DEFAULT_SCALE_VALUE = 'auto'; var DEFAULT_SCALE_VALUE = 'auto';
var PDFViewerApplication = { var PDFViewerApplication = {
pdfLoadingTask: null,
pdfDocument: null, pdfDocument: null,
pdfViewer: null, pdfViewer: null,
pdfHistory: null, pdfHistory: null,
pdfLinkService: null, pdfLinkService: null,
/**
* Opens PDF document specified by URL.
* @returns {Promise} - Returns the promise, which is resolved when document
* is opened.
*/
open: function (params) { open: function (params) {
var url = params.url, originalUrl = params.originalUrl; if (this.pdfLoadingTask) {
// We need to destroy already opened document
return this.close().then(function () {
// ... and repeat the open() call.
return this.open(params);
}.bind(this));
}
var url = params.url;
var self = this; var self = this;
this.setTitleUsingUrl(originalUrl); this.setTitleUsingUrl(url);
// Loading document. // Loading document.
var loadingTask = PDFJS.getDocument(url); var loadingTask = PDFJS.getDocument(url);
this.pdfLoadingTask = loadingTask;
loadingTask.onProgress = function (progressData) { loadingTask.onProgress = function (progressData) {
self.progress(progressData.loaded / progressData.total); self.progress(progressData.loaded / progressData.total);
}; };
loadingTask.then(function (pdfDocument) {
// Document loaded, specifying document for the viewer.
this.pdfDocument = pdfDocument;
this.pdfViewer.setDocument(pdfDocument);
this.pdfLinkService.setDocument(pdfDocument);
this.pdfHistory.initialize(pdfDocument.fingerprint);
this.loadingBar.hide(); return loadingTask.promise.then(function (pdfDocument) {
this.setTitleUsingMetadata(pdfDocument); // Document loaded, specifying document for the viewer.
}.bind(this), function (exception) { self.pdfDocument = pdfDocument;
self.pdfViewer.setDocument(pdfDocument);
self.pdfLinkService.setDocument(pdfDocument);
self.pdfHistory.initialize(pdfDocument.fingerprint);
self.loadingBar.hide();
self.setTitleUsingMetadata(pdfDocument);
}, function (exception) {
var message = exception && exception.message; var message = exception && exception.message;
var loadingErrorMessage = mozL10n.get('loading_error', null, var loadingErrorMessage = mozL10n.get('loading_error', null,
'An error occurred while loading the PDF.'); 'An error occurred while loading the PDF.');
@ -80,6 +102,32 @@ var PDFViewerApplication = {
}); });
}, },
/**
* Closes opened PDF document.
* @returns {Promise} - Returns the promise, which is resolved when all
* destruction is completed.
*/
close: function () {
var errorWrapper = document.getElementById('errorWrapper');
errorWrapper.setAttribute('hidden', 'true');
if (!this.pdfLoadingTask) {
return Promise.resolve();
}
var promise = this.pdfLoadingTask.destroy();
this.pdfLoadingTask = null;
if (this.pdfDocument) {
this.pdfDocument = null;
this.pdfViewer.setDocument(null);
this.pdfLinkService.setDocument(null, null);
}
return promise;
},
get loadingBar() { get loadingBar() {
var bar = new PDFJS.ProgressBar('#loadingBar', {}); var bar = new PDFJS.ProgressBar('#loadingBar', {});
@ -88,7 +136,7 @@ var PDFViewerApplication = {
setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) { setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
this.url = url; this.url = url;
var title = PDFJS.getFileName(url) || url; var title = PDFJS.getFilenameFromUrl(url) || url;
try { try {
title = decodeURIComponent(title); title = decodeURIComponent(title);
} catch (e) { } catch (e) {
@ -134,7 +182,7 @@ var PDFViewerApplication = {
setTitle: function pdfViewSetTitle(title) { setTitle: function pdfViewSetTitle(title) {
document.title = title; document.title = title;
document.getElementById('activityTitle').textContent = title; document.getElementById('title').textContent = title;
}, },
error: function pdfViewError(message, moreInfo) { error: function pdfViewError(message, moreInfo) {
@ -273,10 +321,11 @@ var PDFViewerApplication = {
document.getElementById('pageNumber').addEventListener('change', document.getElementById('pageNumber').addEventListener('change',
function() { function() {
// Handle the user inputting a floating point number.
PDFViewerApplication.page = (this.value | 0); PDFViewerApplication.page = (this.value | 0);
if (this.value !== (this.value | 0).toString()) { // Ensure that the page number input displays the correct value, even if the
// value entered by the user was invalid (e.g. a floating point number).
if (this.value !== PDFViewerApplication.page.toString()) {
this.value = PDFViewerApplication.page; this.value = PDFViewerApplication.page;
} }
}); });
@ -288,11 +337,9 @@ var PDFViewerApplication = {
container.addEventListener('pagechange', function (evt) { container.addEventListener('pagechange', function (evt) {
var page = evt.pageNumber; var page = evt.pageNumber;
if (evt.previousPageNumber !== page) {
document.getElementById('pageNumber').value = page;
}
var numPages = PDFViewerApplication.pagesCount; var numPages = PDFViewerApplication.pagesCount;
document.getElementById('pageNumber').value = page;
document.getElementById('previous').disabled = (page <= 1); document.getElementById('previous').disabled = (page <= 1);
document.getElementById('next').disabled = (page >= numPages); document.getElementById('next').disabled = (page >= numPages);
}, true); }, true);
@ -312,38 +359,9 @@ document.addEventListener('DOMContentLoaded', function () {
}); });
})(); })();
// Support of the new version of navigator.mozL10n -- in PDF.js older/custom // We need to delay opening until all HTML is loaded.
// version is used. PDFViewerApplication.animationStartedPromise.then(function () {
var mozL10n = { PDFViewerApplication.open({
get: function (id, args, fallback) { url: DEFAULT_URL
var s = (navigator.mozL10n && navigator.mozL10n.get(id)) || fallback;
s = s.replace(/\{\{\s*(\w+)\s*\}\}/g, function (all, key) {
return args[key] || '';
});
return s;
},
translate: function (fragment) {
if (navigator.mozL10n) {
navigator.mozL10n.translateFragment(fragment);
}
}
};
window.navigator.mozSetMessageHandler('activity', function(activity) {
var blob = activity.source.data.blob;
var fileURL = activity.source.data.url ||
activity.source.data.filename ||
' '; // if no url or filename, use a non-empty string
var url = URL.createObjectURL(blob);
// We need to delay opening until all HTML is loaded.
PDFViewerApplication.animationStartedPromise.then(function () {
PDFViewerApplication.open({url: url, originalUrl: fileURL});
var header = document.getElementById('header');
header.addEventListener('action', function() {
activity.postResult('close');
});
}); });
}); });

View file

@ -123,6 +123,10 @@ DOMElement.prototype = {
global.document = { global.document = {
childNodes : [], childNodes : [],
get currentScript() {
return { src: '' };
},
get documentElement() { get documentElement() {
return this; return this;
}, },

View file

@ -4,18 +4,16 @@
// //
// Basic node example that prints document metadata and text content. // Basic node example that prints document metadata and text content.
// Requires single file built version of PDF.js -- please run // Requires single file built version of PDF.js -- please run
// `node make singlefile` before running the example. // `gulp singlefile` before running the example.
// //
var fs = require('fs'); var fs = require('fs');
// HACK few hacks to let PDF.js be loaded not as a module in global space. // HACK adding DOMParser to read XMP metadata.
global.window = global;
global.navigator = { userAgent: "node" };
global.PDFJS = {};
global.DOMParser = require('./domparsermock.js').DOMParserMock; global.DOMParser = require('./domparsermock.js').DOMParserMock;
require('../../build/singlefile/build/pdf.combined.js'); // Run `gulp dist` to generate 'pdfjs-dist' npm package files.
var pdfjsLib = require('../../build/dist');
// Loading file from file system into typed array // Loading file from file system into typed array
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf'; var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
@ -23,7 +21,7 @@ var data = new Uint8Array(fs.readFileSync(pdfPath));
// Will be using promises to load document, pages and misc data instead of // Will be using promises to load document, pages and misc data instead of
// callback. // callback.
PDFJS.getDocument(data).then(function (doc) { pdfjsLib.getDocument(data).then(function (doc) {
var numPages = doc.numPages; var numPages = doc.numPages;
console.log('# Document Loaded'); console.log('# Document Loaded');
console.log('Number of Pages: ' + numPages); console.log('Number of Pages: ' + numPages);

View file

@ -8,14 +8,10 @@
var fs = require('fs'); var fs = require('fs');
// HACK few hacks to let PDF.js be loaded not as a module in global space. // HACK few hacks to let PDF.js be loaded not as a module in global space.
global.window = global;
global.navigator = { userAgent: 'node' };
global.PDFJS = {};
require('./domstubs.js'); require('./domstubs.js');
PDFJS.workerSrc = true; // Run `gulp dist` to generate 'pdfjs-dist' npm package files.
require('../../build/singlefile/build/pdf.combined.js'); var pdfjsLib = require('../../build/dist');
// Loading file from file system into typed array // Loading file from file system into typed array
var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf'; var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
@ -48,7 +44,7 @@ function getFileNameFromPath(path) {
// Will be using promises to load document, pages and misc data instead of // Will be using promises to load document, pages and misc data instead of
// callback. // callback.
PDFJS.getDocument(data).then(function (doc) { pdfjsLib.getDocument(data).then(function (doc) {
var numPages = doc.numPages; var numPages = doc.numPages;
console.log('# Document Loaded'); console.log('# Document Loaded');
console.log('Number of Pages: ' + numPages); console.log('Number of Pages: ' + numPages);
@ -63,7 +59,7 @@ PDFJS.getDocument(data).then(function (doc) {
console.log(); console.log();
return page.getOperatorList().then(function (opList) { return page.getOperatorList().then(function (opList) {
var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs); var svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
svgGfx.embedFonts = true; svgGfx.embedFonts = true;
return svgGfx.getSVG(opList, viewport).then(function (svg) { return svgGfx.getSVG(opList, viewport).then(function (svg) {
var svgDump = svg.toString(); var svgDump = svg.toString();

View file

@ -2,35 +2,25 @@
<html> <html>
<head> <head>
<!-- In production, only one script (pdf.js) is necessary --> <meta charset="utf-8">
<!-- In production, change the content of PDFJS.workerSrc below -->
<script src="../../src/shared/util.js"></script>
<script src="../../src/display/api.js"></script>
<script src="../../src/display/metadata.js"></script>
<script src="../../src/display/pattern_helper.js"></script>
<script src="../../src/display/font_loader.js"></script>
<script src="../../src/display/svg.js"></script>
<script> <title>PDF.js SVG viewer example</title>
// Specify the main script used to create a new PDF.JS web worker.
// In production, leave this undefined or change it to point to the <script src="../../node_modules/systemjs/dist/system.js"></script>
// combined `pdf.worker.js` file. <script src="../../systemjs.config.js"></script>
PDFJS.workerSrc = '../../src/worker_loader.js';
</script>
<script src="viewer.js"></script> <script src="viewer.js"></script>
<style> <style>
body { body {
background-color: gray; background-color: #404040;
} }
.pageContainer { .pageContainer {
border : 1px solid black; border: 1px solid #000;
margin : 5px auto; margin: 5px auto;
background-color : white; background-color: #FFF;
} }
</style> </style>
<title>SVG Viewer Example</title>
</head> </head>
<body> <body>

View file

@ -1,56 +1,55 @@
//
// See README for overview
//
'use strict'; 'use strict';
var DEFAULT_SCALE = 1.5;
// Parse query string to extract some parameters (it can fail for some input) // Parse query string to extract some parameters (it can fail for some input)
var query = document.location.href.replace(/^[^?]*(\?([^#]*))?(#.*)?/, '$2'); var query = document.location.href.replace(/^[^?]*(\?([^#]*))?(#.*)?/, '$2');
var queryParams = query ? JSON.parse('{' + query.split('&').map(function (a) { var queryParams = query ? JSON.parse('{' + query.split('&').map(function (a) {
return a.split('=').map(decodeURIComponent).map(JSON.stringify).join(': '); return a.split('=').map(decodeURIComponent).map(JSON.stringify).join(': ');
}).join(',') + '}') : {}; }).join(',') + '}') : {};
var url = queryParams.file || '../../test/pdfs/liveprogramming.pdf'; var url = queryParams.file || '../../web/compressed.tracemonkey-pldi-09.pdf';
var scale = +queryParams.scale || 1.5;
//
// Fetch the PDF document from the URL using promises
//
PDFJS.getDocument(url).then(function(pdf) {
var numPages = pdf.numPages;
// Using promise to fetch the page
// For testing only.
var MAX_NUM_PAGES = 50;
var ii = Math.min(MAX_NUM_PAGES, numPages);
function renderDocument(pdf, svgLib) {
var promise = Promise.resolve(); var promise = Promise.resolve();
for (var i = 1; i <= ii; i++) { for (var i = 1; i <= pdf.numPages; i++) {
var anchor = document.createElement('a');
anchor.setAttribute('name', 'page=' + i);
anchor.setAttribute('title', 'Page ' + i);
document.body.appendChild(anchor);
// Using promise to fetch and render the next page // Using promise to fetch and render the next page
promise = promise.then(function (pageNum, anchor) { promise = promise.then(function (pageNum) {
return pdf.getPage(pageNum).then(function (page) { return pdf.getPage(pageNum).then(function (page) {
var viewport = page.getViewport(scale); var viewport = page.getViewport(DEFAULT_SCALE);
var container = document.createElement('div'); var container = document.createElement('div');
container.id = 'pageContainer' + pageNum; container.id = 'pageContainer' + pageNum;
container.className = 'pageContainer'; container.className = 'pageContainer';
container.style.width = viewport.width + 'px'; container.style.width = viewport.width + 'px';
container.style.height = viewport.height + 'px'; container.style.height = viewport.height + 'px';
anchor.appendChild(container); document.body.appendChild(container);
return page.getOperatorList().then(function (opList) { return page.getOperatorList().then(function (opList) {
var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs); var svgGfx = new svgLib.SVGGraphics(page.commonObjs, page.objs);
return svgGfx.getSVG(opList, viewport).then(function (svg) { return svgGfx.getSVG(opList, viewport).then(function (svg) {
container.appendChild(svg); container.appendChild(svg);
}); });
}); });
}); });
}.bind(null, i, anchor)); }.bind(null, i));
} }
}
Promise.all([SystemJS.import('pdfjs/display/api'),
SystemJS.import('pdfjs/display/svg'),
SystemJS.import('pdfjs/display/global')])
.then(function (modules) {
var api = modules[0], svg = modules[1], global = modules[2];
// In production, change this to point to the built `pdf.worker.js` file.
global.PDFJS.workerSrc = '../../src/worker_loader.js';
// In production, change this to point to where the cMaps are placed.
global.PDFJS.cMapUrl = '../../external/bcmaps/';
global.PDFJS.cMapPacked = true;
// Fetch the PDF document from the URL using promises.
api.getDocument(url).then(function (doc) {
renderDocument(doc, svg);
});
}); });

View file

@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8">
<title>Text-only PDF.js example</title> <title>Text-only PDF.js example</title>
<script src="../../build/generic/build/pdf.js"></script> <script src="../../build/generic/build/pdf.js"></script>
<script src="pdf2svg.js"></script> <script src="pdf2svg.js"></script>

View file

@ -18,7 +18,7 @@ var PAGE_NUMBER = 1;
var PAGE_SCALE = 1.5; var PAGE_SCALE = 1.5;
var SVG_NS = 'http://www.w3.org/2000/svg'; var SVG_NS = 'http://www.w3.org/2000/svg';
PDFJS.workerSrc = '../../build/pdf.worker.js'; PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js';
function buildSVG(viewport, textContent) { function buildSVG(viewport, textContent) {
// Building SVG with size of the viewport (for simplicity) // Building SVG with size of the viewport (for simplicity)
@ -30,7 +30,7 @@ function buildSVG(viewport, textContent) {
// processing all items // processing all items
textContent.items.forEach(function (textItem) { textContent.items.forEach(function (textItem) {
// we have to take in account viewport transform, which incudes scale, // we have to take in account viewport transform, which includes scale,
// rotation and Y-axis flip, and not forgetting to flip text. // rotation and Y-axis flip, and not forgetting to flip text.
var tx = PDFJS.Util.transform( var tx = PDFJS.Util.transform(
PDFJS.Util.transform(viewport.transform, textItem.transform), PDFJS.Util.transform(viewport.transform, textItem.transform),
@ -63,7 +63,7 @@ function pageLoaded() {
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
if (typeof PDFJS === 'undefined') { if (typeof PDFJS === 'undefined') {
alert('Built version of PDF.js was not found.\n' + alert('Built version of PDF.js was not found.\n' +
'Please run `node make generic`.'); 'Please run `gulp generic`.');
return; return;
} }
pageLoaded(); pageLoaded();

1
examples/webpack/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules/

View file

@ -0,0 +1,19 @@
## Overview
Example to demonstrate PDF.js library usage with Webpack.
## Getting started
Build project and install the example dependencies:
$ gulp dist
$ cd examples/webpack
$ npm install
To build Webpack bundles, run `node_modules/.bin/webpack`. If you are running
a web server, you can observe the build results at
http://localhost:8888/examples/webpack/index.html
See main.js and webpack.config.js files. Please notice that PDF.js
packaging requires packaging of the main application and PDF.js worker code,
and the `workerSrc` path shall be set to the latter file.

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>webpack example</title>
<script src="../../build/webpack/main.bundle.js"></script>
</head>
<body>
<canvas id="theCanvas"></canvas>
</body>
</html>

35
examples/webpack/main.js Normal file
View file

@ -0,0 +1,35 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
// Hello world example for webpack.
var pdfjsLib = require('pdfjs-dist');
var pdfPath = '../helloworld/helloworld.pdf';
// Setting worker path to worker bundle.
pdfjsLib.PDFJS.workerSrc = '../../build/webpack/pdf.worker.bundle.js';
// It is also possible to disable workers via `PDFJS.disableWorker = true`,
// however that might degrade the UI performance in web browsers.
// Loading a document.
var loadingTask = pdfjsLib.getDocument(pdfPath);
loadingTask.promise.then(function (pdfDocument) {
// Request a first page
return pdfDocument.getPage(1).then(function (pdfPage) {
// Display page on the existing canvas with 100% scale.
var viewport = pdfPage.getViewport(1.0);
var canvas = document.getElementById('theCanvas');
canvas.width = viewport.width;
canvas.height = viewport.height;
var ctx = canvas.getContext('2d');
var renderTask = pdfPage.render({
canvasContext: ctx,
viewport: viewport
});
return renderTask.promise;
});
}).catch(function (reason) {
console.error('Error: ' + reason);
});

View file

@ -0,0 +1,8 @@
{
"name": "webpack-pdf.js-example",
"version": "0.1.0",
"devDependencies": {
"webpack": "~1.12.9",
"pdfjs-dist": "../../build/dist"
}
}

View file

@ -0,0 +1,23 @@
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: __dirname,
entry: {
'main': './main.js',
'pdf.worker': 'pdfjs-dist/build/pdf.worker.entry'
},
output: {
path: path.join(__dirname, '../../build/webpack'),
publicPath: '../../build/webpack/',
filename: '[name].bundle.js'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false
}
})
]
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 609 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

View file

@ -1,88 +0,0 @@
<!DOCTYPE html>
<!--
Copyright 2012 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>PDF.js viewer</title>
<script src="../pdfjs-components/build/pdf.js"></script>
<script src="../pdfjs-components/web/pdf_viewer.js"></script>
<script src="/shared/js/l10n.js"></script>
<!-- Localization -->
<meta name="defaultLanguage" content="en-US">
<meta name="availableLanguages" content="ach,af,ak,an,ar,as,ast,az,be,bg,bn-BD,bn-IN,br,bs,ca,cs,csb,cy,da,de,el,en-GB,en-ZA,eo,es-AR,es-CL,es-ES,es-MX,et,eu,fa,ff,fi,fr,fy-NL,ga-IE,gd,gl,gu-IN,he,hi-IN,hr,hu,hy-AM,id,is,it,ja,ka,kk,km,kn,ko,ku,lg,lij,lt,lv,mai,mk,ml,mn,mr,ms,my,nb-NO,nl,nn-NO,nso,oc,or,pa-IN,pl,pt-BR,pt-PT,rm,ro,ru,rw,sah,si,sk,sl,son,sq,sr,sv-SE,sw,ta,ta-LK,te,th,tl,tn,tr,uk,ur,vi,wo,xh,zh-CN,zh-TW,zu">
<link rel="localization" href="locale/{locale}/viewer.properties">
<script src="viewer.js"></script>
<!-- Web Components -->
<link rel="stylesheet" type="text/css" href="/shared/elements/gaia-theme/gaia-theme.css">
<script src="/shared/elements/config.js" defer></script>
<script src="/shared/elements/gaia-header/dist/gaia-header.js" defer></script>
<link rel="stylesheet" type="text/css" href="../pdfjs-components/web/pdf_viewer.css">
<link rel="stylesheet" type="text/css" href="viewer.css">
</head>
<body>
<section role="region" id="activityHeader" class="skin-organic theme-settings">
<gaia-header id="header" action="close">
<h1 id="activityTitle"></h1>
</gaia-header>
<footer id="open-toolbar">
<button class="toolbarButton pageUp" title="Previous Page" id="previous" data-l10n-id="previous"></button>
<button class="toolbarButton pageDown" title="Next Page" id="next" data-l10n-id="next"></button>
<input type="number" id="pageNumber" class="toolbarField pageNumber" value="1" size="4" min="1">
<button class="toolbarButton zoomOut" title="Zoom Out" id="zoomOut" data-l10n-id="zoom_out"></button>
<button class="toolbarButton zoomIn" title="Zoom In" id="zoomIn" data-l10n-id="zoom_in"></button>
</footer>
</section>
<div id="viewerContainer">
<div id="viewer" class="pdfViewer"></div>
</div>
<div id="loadingBar">
<div class="progress"></div>
<div class="glimmer"></div>
</div>
<div id="errorWrapper" hidden='true'>
<div id="errorMessageLeft">
<span id="errorMessage"></span>
<button id="errorShowMore" data-l10n-id="error_more_info">
More Information
</button>
<button id="errorShowLess" data-l10n-id="error_less_info" hidden='true'>
Less Information
</button>
</div>
<div id="errorMessageRight">
<button id="errorClose" data-l10n-id="error_close">
Close
</button>
</div>
<div class="clearBoth"></div>
<textarea id="errorMoreInfo" hidden='true' readonly="readonly"></textarea>
</div>
</body>
</html>

View file

@ -1,283 +0,0 @@
/**
* (c) 2013 Rob Wu <gwnRob@gmail.com>
* Released under the MIT license
* https://github.com/Rob--W/chrome-api/chrome.tabs.executeScriptInFrame
*
* Implements the chrome.tabs.executeScriptInFrame API.
* This API is similar to the chrome.tabs.executeScript method, except
* that it also recognizes the "frameId" property.
* This frameId can be obtained through the webNavigation or webRequest API.
*
* When an error occurs, chrome.runtime.lastError is set.
*
* Required permissions:
* webRequest
* webRequestBlocking
* Host permissions for the tab
*
* In addition, the following field must also be set in manifest.json:
* "web_accessible_resources": ["getFrameId"]
*/
/* globals chrome, console */
(function() {
/* jshint browser:true, maxlen:100 */
'use strict';
chrome.tabs.executeScriptInFrame = executeScript;
// This URL is used to communicate the frameId. The resource is never
// visited, so it should be a non-existent location. Do not use *, ", '
// or line breaks in the file name.
var URL_WHAT_IS_MY_FRAME_ID = chrome.extension.getURL('getFrameId');
// The callback will be called within ... ms:
// Don't set a too low value.
var MAXIMUM_RESPONSE_TIME_MS = 1000;
// Callbacks are stored here until they're invoked.
// Key = dummyUrl, value = callback function
var callbacks = {};
chrome.webRequest.onBeforeRequest.addListener(function showFrameId(details) {
// Positive integer frameId >= 0
// Since an image is used as a data transport, we add 1 to get a
// non-zero width.
var frameId = details.frameId + 1;
// Assume that the frameId fits in three bytes - which is a very
// reasonable assumption.
var width = String.fromCharCode(frameId & 0xFF, (frameId >> 8) & 0xFF);
// When frameId > 0xFFFF, use the height to convey the additional
// information. Again, add 1 to make sure that the height is non-zero.
var height = String.fromCharCode((frameId >> 16) + 1, 0);
// Convert data to base64 to avoid loss of bytes
var image = 'data:image/gif;base64,' + btoa(
// 4749 4638 3961 (GIF header)
'GIF89a' +
// Logical Screen Width (LSB)
width +
// Logical Screen Height (LSB)
height +
// "No Global Color Table follows"
'\x00' +
// Background color
'\xff' +
// No aspect information is given
'\x00' +
// (image descriptor)
// Image Separator
'\x2c' +
// Image Position (Left & Top)
'\x00\x00\x00\x00' +
// Image Width (LSB)
width +
// Image Height (LSB)
height +
// Local Color Table is not present
'\x00' +
// (End of image descriptor)
// Image data
'\x02\x02\x44\x01\x00' +
// GIF trailer
'\x3b'
);
return {redirectUrl: image};
}, {
urls: [URL_WHAT_IS_MY_FRAME_ID + '*'],
types: ['image']
}, ['blocking']);
chrome.runtime.onMessage.addListener(function(message, sender,
sendResponse) {
if (message && message.executeScriptCallback) {
var callback = callbacks[message.identifier];
if (callback) {
if (message.hello) {
clearTimeout(callback.timer);
return;
}
delete callbacks[message.identifier];
// Result within an array to be consistent with the
// chrome.tabs.executeScript API.
callback([message.evalResult]);
} else {
console.warn('Callback not found for response in tab ' +
sender.tab.id);
}
}
});
/**
* Execute content script in a specific frame.
*
* @param tabId {integer} required
* @param details.frameId {integer} required
* @param details.code {string} Code or file is required (not both)
* @param details.file {string} Code or file is required (not both)
* @param details.runAt {optional string} One of "document_start",
* "document_end", "document_idle"
* @param callback {optional function(optional result array)} When an error
* occurs, result
* is not set.
*/
function executeScript(tabId, details, callback) {
console.assert(typeof details === 'object',
'details must be an object (argument 0)');
var frameId = details.frameId;
console.assert(typeof tabId === 'number',
'details.tabId must be a number');
console.assert(typeof frameId === 'number',
'details.frameId must be a number');
var sourceType = ('code' in details ? 'code' : 'file');
console.assert(sourceType in details, 'No source code or file specified');
var sourceValue = details[sourceType];
console.assert(typeof sourceValue === 'string',
'details.' + sourceType + ' must be a string');
var runAt = details.runAt;
if (!callback) {
callback = function() {/* no-op*/};
}
console.assert(typeof callback === 'function',
'callback must be a function');
if (frameId === 0) {
// No need for heavy lifting if we want to inject the script
// in the main frame
var injectDetails = {
allFrames: false,
runAt: runAt
};
injectDetails[sourceType] = sourceValue;
chrome.tabs.executeScript(tabId, injectDetails, callback);
return;
}
var identifier = Math.random().toString(36);
if (sourceType === 'code') {
executeScriptInFrame();
} else { // sourceType === 'file'
(function() {
var x = new XMLHttpRequest();
x.open('GET', chrome.extension.getURL(sourceValue), true);
x.onload = function() {
sourceValue = x.responseText;
executeScriptInFrame();
};
x.onerror = function executeScriptResourceFetchError() {
var message = 'Failed to load file: "' + sourceValue + '".';
console.error('executeScript: ' + message);
chrome.runtime.lastError = chrome.extension.lastError =
{ message: message };
try {
callback();
} finally {
chrome.runtime.lastError = chrome.extension.lastError = undefined;
}
};
x.send();
})();
}
function executeScriptInFrame() {
callbacks[identifier] = callback;
chrome.tabs.executeScript(tabId, {
code: '(' + DETECT_FRAME + ')(' +
'window,' +
JSON.stringify(identifier) + ',' +
frameId + ',' +
JSON.stringify(sourceValue) + ')',
allFrames: true,
runAt: 'document_start'
}, function(results) {
if (results) {
callback.timer = setTimeout(executeScriptTimedOut,
MAXIMUM_RESPONSE_TIME_MS);
} else {
// Failed :(
delete callbacks[identifier];
callback();
}
});
}
function executeScriptTimedOut() {
var callback = callbacks[identifier];
if (!callback) {
return;
}
delete callbacks[identifier];
var message = 'Failed to execute script: Frame ' + frameId +
' not found in tab ' + tabId;
console.error('executeScript: ' + message);
chrome.runtime.lastError = chrome.extension.lastError =
{ message: message };
try {
callback();
} finally {
chrome.runtime.lastError = chrome.extension.lastError = undefined;
}
}
}
/**
* Code executed as a content script.
*/
var DETECT_FRAME = '' + function checkFrame(window, identifier, frameId,
code) {
var i;
if ('__executeScript_frameId__' in window) {
evalAsContentScript();
} else {
// Do NOT use new Image() because of http://crbug.com/245296
// in Chrome 27-29
i = window.document.createElement('img');
i.onload = function() {
window.__executeScript_frameId__ = (this.naturalWidth - 1) +
(this.naturalHeight - 1 << 16);
evalAsContentScript();
};
// Trigger webRequest event to get frameId
// (append extra characters to bust the cache)
i.src = 'URL_WHAT_IS_MY_FRAME_ID?' +
Math.random().toString(36).slice(-6);
}
for (i = 0 ; i < window.frames.length; ++i) {
try {
var frame = window.frames[i];
var scheme = frame.location.protocol;
if (scheme !== 'https:' && scheme !== 'http:' && scheme !== 'file:') {
checkFrame(frame, identifier, frameId, code);
}
} catch (e) {
// blocked by same origin policy, so it's not a javascript:/about:blank
// URL. chrome.tabs.executeScript will run the script for the frame.
}
}
function evalAsContentScript() {
if (window.__executeScript_frameId__ !== frameId) {
return;
}
// Send an early message to make sure that any blocking code
// in the evaluated code does not cause the time-out in the background
// page to be triggered
chrome.runtime.sendMessage({
executeScriptCallback: true,
hello: true,
identifier: identifier
});
var result = null;
try {
// jshint evil:true
result = window.eval(code);
} finally {
chrome.runtime.sendMessage({
executeScriptCallback: true,
evalResult: result,
identifier: identifier
});
}
}
}.toString().replace('URL_WHAT_IS_MY_FRAME_ID', URL_WHAT_IS_MY_FRAME_ID);
})();

View file

@ -23,31 +23,10 @@ function getViewerURL(pdf_url) {
return VIEWER_URL + '?file=' + encodeURIComponent(pdf_url); return VIEWER_URL + '?file=' + encodeURIComponent(pdf_url);
} }
// (un)prefixed property names if (CSS.supports('animation', '0s')) {
var createShadowRoot, shadowRoot; document.addEventListener('animationstart', onAnimationStart, true);
if (typeof Element.prototype.createShadowRoot !== 'undefined') { } else {
// Chrome 35+ document.addEventListener('webkitAnimationStart', onAnimationStart, true);
createShadowRoot = 'createShadowRoot';
shadowRoot = 'shadowRoot';
} else if (typeof Element.prototype.webkitCreateShadowRoot !== 'undefined') {
// Chrome 25 - 34
createShadowRoot = 'webkitCreateShadowRoot';
shadowRoot = 'webkitShadowRoot';
try {
document.createElement('embed').webkitCreateShadowRoot();
} catch (e) {
// Only supported since Chrome 33.
createShadowRoot = shadowRoot = '';
}
}
// Only observe the document if we can make use of Shadow DOM.
if (createShadowRoot) {
if (CSS.supports('animation', '0s')) {
document.addEventListener('animationstart', onAnimationStart, true);
} else {
document.addEventListener('webkitAnimationStart', onAnimationStart, true);
}
} }
function onAnimationStart(event) { function onAnimationStart(event) {
@ -57,10 +36,9 @@ function onAnimationStart(event) {
} }
// Called for every <object> or <embed> element in the page. // Called for every <object> or <embed> element in the page.
// It does not trigger any Mutation observers, but it may modify the // This may change the type, src/data attributes and/or the child nodes of the
// shadow DOM rooted under the given element. // element. This function only affects elements for the first call. Subsequent
// Calling this function multiple times for the same element is safe, i.e. // invocations have no effect.
// it has no side effects.
function watchObjectOrEmbed(elem) { function watchObjectOrEmbed(elem) {
var mimeType = elem.type; var mimeType = elem.type;
if (mimeType && 'application/pdf' !== mimeType.toLowerCase()) { if (mimeType && 'application/pdf' !== mimeType.toLowerCase()) {
@ -86,33 +64,35 @@ function watchObjectOrEmbed(elem) {
return; return;
} }
if (elem[shadowRoot]) { if (elem.__I_saw_this_element) {
// If the element already has a shadow root, assume that we've already
// seen this element.
return; return;
} }
elem[createShadowRoot](); elem.__I_saw_this_element = true;
var tagName = elem.tagName.toUpperCase();
var updateEmbedOrObject;
if (tagName === 'EMBED') {
updateEmbedOrObject = updateEmbedElement;
} else if (tagName === 'OBJECT') {
updateEmbedOrObject = updateObjectElement;
} else {
return;
}
var lastSrc;
var isUpdating = false;
function updateViewerFrame() { function updateViewerFrame() {
var path = elem[srcAttribute]; if (!isUpdating) {
if (!path) { isUpdating = true;
elem[shadowRoot].textContent = ''; try {
} else { if (lastSrc !== elem[srcAttribute]) {
elem[shadowRoot].innerHTML = updateEmbedOrObject(elem);
// Set display: inline-block; to the host element (<embed>/<object>) to lastSrc = elem[srcAttribute];
// ensure that the dimensions defined on the host element are applied to }
// the iframe (http://crbug.com/358648). } finally {
// The styles are declared in the shadow DOM to allow page authors to isUpdating = false;
// override these styles (e.g. .style.display = 'none';). }
'<style>\n' +
// Chrome 35+
':host { display: inline-block; }\n' +
// Chrome 33 and 34 (not 35+ because of http://crbug.com/351248)
'*:not(style):not(iframe) { display: inline-block; }\n' +
'iframe { width: 100%; height: 100%; border: 0; }\n' +
'</style>' +
'<iframe allowfullscreen></iframe>';
elem[shadowRoot].lastChild.src = getEmbeddedViewerURL(path);
} }
} }
@ -128,6 +108,97 @@ function watchObjectOrEmbed(elem) {
}); });
} }
// Display the PDF Viewer in an <embed>.
function updateEmbedElement(elem) {
if (elem.type === 'text/html' && elem.src.lastIndexOf(VIEWER_URL, 0) === 0) {
// The viewer is already shown.
return;
}
// The <embed> tag needs to be removed and re-inserted before any src changes
// are effective.
var parentNode = elem.parentNode;
var nextSibling = elem.nextSibling;
if (parentNode) {
parentNode.removeChild(elem);
}
elem.type = 'text/html';
elem.src = getEmbeddedViewerURL(elem.src);
if (parentNode) {
parentNode.insertBefore(elem, nextSibling);
}
}
// Display the PDF Viewer in an <object>.
function updateObjectElement(elem) {
// <object> elements are terrible. Experiments (in49.0.2623.75) show that the
// following happens:
// - When fallback content is shown (e.g. because the built-in PDF Viewer is
// disabled), updating the "data" attribute has no effect. Not surprising
// considering that HTMLObjectElement::m_useFallbackContent is not reset
// once it is set to true. Source:
// WebKit/Source/core/html/HTMLObjectElement.cpp#378 (rev 749fe30d676b6c14).
// - When the built-in PDF Viewer plugin is enabled, updating the "data"
// attribute reloads the content (provided that the type was correctly set).
// - When <object type=text/html data="chrome-extension://..."> is used
// (tested with a data-URL, data:text/html,<object...>, the extension's
// origin whitelist is not set up, so the viewer can't load the PDF file.
// - The content of the <object> tag may be affected by <param> tags.
//
// To make sure that our solution works for all cases, we will insert a frame
// as fallback content and force the <object> tag to render its fallback
// content.
var iframe = elem.firstElementChild;
if (!iframe || !iframe.__inserted_by_pdfjs) {
iframe = createFullSizeIframe();
elem.textContent = '';
elem.appendChild(iframe);
iframe.__inserted_by_pdfjs = true;
}
iframe.src = getEmbeddedViewerURL(elem.data);
// Some bogus content type that is not handled by any plugin.
elem.type = 'application/not-a-pee-dee-eff-type';
// Force the <object> to reload and render its fallback content.
elem.data += '';
// Usually the browser renders plugin content in this tag, which is completely
// oblivious of styles such as padding, but we insert and render child nodes,
// so force padding to be zero to avoid undesired dimension changes.
elem.style.padding = '0';
// <object> and <embed> elements have a "display:inline" style by default.
// Despite this property, when a plugin is loaded in the tag, the tag is
// treated like "display:inline-block". However, when the browser does not
// render plugin content, the <object> tag does not behave like that, and as
// a result the width and height is ignored.
// Force "display:inline-block" to make sure that the width/height as set by
// web pages is respected.
// (<embed> behaves as expected with the default display value, but setting it
// to display:inline-block doesn't hurt).
elem.style.display = 'inline-block';
}
// Create an <iframe> element without borders that takes the full width and
// height.
function createFullSizeIframe() {
var iframe = document.createElement('iframe');
iframe.style.background = 'none';
iframe.style.border = 'none';
iframe.style.borderRadius = 'none';
iframe.style.boxShadow = 'none';
iframe.style.cssFloat = 'none';
iframe.style.display = 'block';
iframe.style.height = '100%';
iframe.style.margin = '0';
iframe.style.maxHeight = 'none';
iframe.style.maxWidth = 'none';
iframe.style.position = 'static';
iframe.style.transform = 'none';
iframe.style.visibility = 'visible';
iframe.style.width = '100%';
return iframe;
}
// Get the viewer URL, provided that the path is a valid URL. // Get the viewer URL, provided that the path is a valid URL.
function getEmbeddedViewerURL(path) { function getEmbeddedViewerURL(path) {
var fragment = /^([^#]*)(#.*)?$/.exec(path); var fragment = /^([^#]*)(#.*)?$/.exec(path);

View file

@ -27,6 +27,8 @@ limitations under the License.
'ftp', 'ftp',
'file', 'file',
'chrome-extension', 'chrome-extension',
'blob',
'data',
// Chromium OS // Chromium OS
'filesystem', 'filesystem',
// Chromium OS, shorthand for filesystem:<origin>/external/ // Chromium OS, shorthand for filesystem:<origin>/external/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 622 B

After

Width:  |  Height:  |  Size: 594 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 712 B

After

Width:  |  Height:  |  Size: 679 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

@ -14,8 +14,7 @@
"<all_urls>", "<all_urls>",
"tabs", "tabs",
"webNavigation", "webNavigation",
"storage", "storage"
"streamsPrivate"
], ],
"content_scripts": [{ "content_scripts": [{
"matches": [ "matches": [
@ -37,9 +36,6 @@
"filesystem:*.pdf" "filesystem:*.pdf"
] ]
}], }],
"mime_types": [
"application/pdf"
],
"storage": { "storage": {
"managed_schema": "preferences_schema.json" "managed_schema": "preferences_schema.json"
}, },
@ -61,13 +57,14 @@
}, },
"incognito": "split", "incognito": "split",
"web_accessible_resources": [ "web_accessible_resources": [
"getFrameId",
"content/web/viewer.html", "content/web/viewer.html",
"http:/*", "http:/*",
"https:/*", "https:/*",
"ftp:/*", "ftp:/*",
"file:/*", "file:/*",
"chrome-extension:/*", "chrome-extension:/*",
"blob:*",
"data:*",
"filesystem:/*", "filesystem:/*",
"drive:*" "drive:*"
] ]

View file

@ -0,0 +1,70 @@
/*
Copyright 2016 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* eslint strict: ["error", "function"] */
/* globals chrome */
(function() {
'use strict';
var storageLocal = chrome.storage.local;
var storageSync = chrome.storage.sync;
if (!storageSync) {
// No sync storage area - nothing to migrate to.
return;
}
getStorageNames(function(storageKeys) {
storageLocal.get(storageKeys, function(values) {
if (!values || !Object.keys(values).length) {
// No local storage - nothing to migrate.
return;
}
migrateToSyncStorage(values);
});
});
function getStorageNames(callback) {
var x = new XMLHttpRequest();
var schema_location = chrome.runtime.getManifest().storage.managed_schema;
x.open('get', chrome.runtime.getURL(schema_location));
x.onload = function() {
var storageKeys = Object.keys(x.response.properties);
callback(storageKeys);
};
x.responseType = 'json';
x.send();
}
// Save |values| to storage.sync and delete the values with that key from
// storage.local.
function migrateToSyncStorage(values) {
storageSync.set(values, function() {
if (chrome.runtime.lastError) {
console.error('Failed to migrate settings due to an error: ' +
chrome.runtime.lastError.message);
return;
}
// Migration successful. Delete local settings.
storageLocal.remove(Object.keys(values), function() {
// In theory remove() could fail (e.g. if the browser's storage
// backend is corrupt), but since storageSync.set succeeded, consider
// the migration successful.
console.log(
'Successfully migrated preferences from local to sync storage.');
});
});
}
})();

View file

@ -80,6 +80,21 @@ body {
</div> </div>
</template> </template>
<template id="externalLinkTarget-template">
<div class="settings-row">
<label>
<span></span>
<select>
<option value="0">Default</option>
<option value="1">Current window/tab</option>
<option value="2">New window/tab</option>
<option value="3">Parent window/tab</option>
<option value="4">Top window/tab</option>
</select>
</label>
</div>
</template>
<script src="options.js"></script> <script src="options.js"></script>
</body> </body>
</html> </html>

View file

@ -13,12 +13,18 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* globals chrome, Promise */ /* globals chrome */
'use strict'; 'use strict';
var storageAreaName = chrome.storage.sync ? 'sync' : 'local';
var storageArea = chrome.storage[storageAreaName];
Promise.all([ Promise.all([
new Promise(function getManagedPrefs(resolve) { new Promise(function getManagedPrefs(resolve) {
if (!chrome.storage.managed) {
resolve({});
return;
}
// Get preferences as set by the system administrator. // Get preferences as set by the system administrator.
chrome.storage.managed.get(null, function(prefs) { chrome.storage.managed.get(null, function(prefs) {
// Managed storage may be disabled, e.g. in Opera. // Managed storage may be disabled, e.g. in Opera.
@ -26,7 +32,7 @@ Promise.all([
}); });
}), }),
new Promise(function getUserPrefs(resolve) { new Promise(function getUserPrefs(resolve) {
chrome.storage.local.get(null, function(prefs) { storageArea.get(null, function(prefs) {
resolve(prefs || {}); resolve(prefs || {});
}); });
}), }),
@ -74,6 +80,8 @@ Promise.all([
renderPreference = renderDefaultZoomValue(prefSchema.title); renderPreference = renderDefaultZoomValue(prefSchema.title);
} else if (prefName === 'sidebarViewOnLoad') { } else if (prefName === 'sidebarViewOnLoad') {
renderPreference = renderSidebarViewOnLoad(prefSchema.title); renderPreference = renderSidebarViewOnLoad(prefSchema.title);
} else if (prefName === 'externalLinkTarget') {
renderPreference = renderExternalLinkTarget(prefSchema.title);
} else { } else {
// Should NEVER be reached. Only happens if a new type of preference is // Should NEVER be reached. Only happens if a new type of preference is
// added to the storage manifest. // added to the storage manifest.
@ -91,7 +99,7 @@ Promise.all([
// Reset button to restore default settings. // Reset button to restore default settings.
document.getElementById('reset-button').onclick = function() { document.getElementById('reset-button').onclick = function() {
userPrefs = {}; userPrefs = {};
chrome.storage.local.remove(prefNames, function() { storageArea.remove(prefNames, function() {
renderedPrefNames.forEach(function(prefName) { renderedPrefNames.forEach(function(prefName) {
renderPreferenceFunctions[prefName](getPrefValue(prefName)); renderPreferenceFunctions[prefName](getPrefValue(prefName));
}); });
@ -100,7 +108,7 @@ Promise.all([
// Automatically update the UI when the preferences were changed elsewhere. // Automatically update the UI when the preferences were changed elsewhere.
chrome.storage.onChanged.addListener(function(changes, areaName) { chrome.storage.onChanged.addListener(function(changes, areaName) {
var prefs = areaName === 'local' ? userPrefs : var prefs = areaName === storageAreaName ? userPrefs :
areaName === 'managed' ? managedPrefs : null; areaName === 'managed' ? managedPrefs : null;
if (prefs) { if (prefs) {
renderedPrefNames.forEach(function(prefName) { renderedPrefNames.forEach(function(prefName) {
@ -134,7 +142,7 @@ function renderBooleanPref(shortDescription, description, prefName) {
checkbox.onchange = function() { checkbox.onchange = function() {
var pref = {}; var pref = {};
pref[prefName] = this.checked; pref[prefName] = this.checked;
chrome.storage.local.set(pref); storageArea.set(pref);
}; };
wrapper.querySelector('span').textContent = shortDescription; wrapper.querySelector('span').textContent = shortDescription;
document.getElementById('settings-boxes').appendChild(wrapper); document.getElementById('settings-boxes').appendChild(wrapper);
@ -149,7 +157,7 @@ function renderDefaultZoomValue(shortDescription) {
var wrapper = importTemplate('defaultZoomValue-template'); var wrapper = importTemplate('defaultZoomValue-template');
var select = wrapper.querySelector('select'); var select = wrapper.querySelector('select');
select.onchange = function() { select.onchange = function() {
chrome.storage.local.set({ storageArea.set({
defaultZoomValue: this.value defaultZoomValue: this.value
}); });
}; };
@ -178,7 +186,7 @@ function renderSidebarViewOnLoad(shortDescription) {
var wrapper = importTemplate('sidebarViewOnLoad-template'); var wrapper = importTemplate('sidebarViewOnLoad-template');
var select = wrapper.querySelector('select'); var select = wrapper.querySelector('select');
select.onchange = function() { select.onchange = function() {
chrome.storage.local.set({ storageArea.set({
sidebarViewOnLoad: parseInt(this.value) sidebarViewOnLoad: parseInt(this.value)
}); });
}; };
@ -190,3 +198,20 @@ function renderSidebarViewOnLoad(shortDescription) {
} }
return renderPreference; return renderPreference;
} }
function renderExternalLinkTarget(shortDescription) {
var wrapper = importTemplate('externalLinkTarget-template');
var select = wrapper.querySelector('select');
select.onchange = function() {
storageArea.set({
externalLinkTarget: parseInt(this.value)
});
};
wrapper.querySelector('span').textContent = shortDescription;
document.getElementById('settings-boxes').appendChild(wrapper);
function renderPreference(value) {
select.value = value;
}
return renderPreference;
}

View file

@ -1,285 +0,0 @@
/*
Copyright 2013 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* globals chrome, URL, getViewerURL, Features */
(function() {
'use strict';
if (!chrome.streamsPrivate) {
// Aww, PDF.js is still not whitelisted... See http://crbug.com/326949
console.warn('streamsPrivate not available, PDF from FTP or POST ' +
'requests will not be displayed using this extension! ' +
'See http://crbug.com/326949');
chrome.runtime.onMessage.addListener(function(message, sender,
sendResponse) {
if (message && message.action === 'getPDFStream') {
sendResponse();
}
});
return;
}
//
// Stream URL storage manager
//
// Hash map of "<tab id>": { "<pdf url>": ["<stream url>", ...], ... }
var urlToStream = {};
chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener(handleStream);
// Chrome before 27 does not support tabIds on stream events.
var streamSupportsTabId = true;
// "tabId" used for Chrome before 27.
var STREAM_NO_TABID = 0;
function hasStream(tabId, pdfUrl) {
var streams = urlToStream[streamSupportsTabId ? tabId : STREAM_NO_TABID];
return (streams && streams[pdfUrl] && streams[pdfUrl].length > 0);
}
/**
* Get stream URL for a given tabId and PDF url. The retrieved stream URL
* will be removed from the list.
* @return {object} An object with property url (= blob:-URL) and
* property contentLength (= expected size)
*/
function getStream(tabId, pdfUrl) {
if (!streamSupportsTabId) {
tabId = STREAM_NO_TABID;
}
if (hasStream(tabId, pdfUrl)) {
var streamInfo = urlToStream[tabId][pdfUrl].shift();
if (urlToStream[tabId][pdfUrl].length === 0) {
delete urlToStream[tabId][pdfUrl];
if (Object.keys(urlToStream[tabId]).length === 0) {
delete urlToStream[tabId];
}
}
return streamInfo;
}
}
function setStream(tabId, pdfUrl, streamUrl, expectedSize) {
tabId = tabId || STREAM_NO_TABID;
if (!urlToStream[tabId]) {
urlToStream[tabId] = {};
}
if (!urlToStream[tabId][pdfUrl]) {
urlToStream[tabId][pdfUrl] = [];
}
urlToStream[tabId][pdfUrl].push({
streamUrl: streamUrl,
contentLength: expectedSize
});
}
// http://crbug.com/276898 - the onExecuteMimeTypeHandler event is sometimes
// dispatched in the wrong incognito profile. To work around the bug, transfer
// the stream information from the incognito session when the bug is detected.
function transferStreamToIncognitoProfile(tabId, pdfUrl) {
if (chrome.extension.inIncognitoContext) {
console.log('Already within incognito profile. Aborted stream transfer.');
return;
}
var streamInfo = getStream(tabId, pdfUrl);
if (!streamInfo) {
return;
}
console.log('Attempting to transfer stream info to a different profile...');
var itemId = 'streamInfo:' + window.performance.now();
var items = {};
items[itemId] = {
tabId: tabId,
pdfUrl: pdfUrl,
streamUrl: streamInfo.streamUrl,
contentLength: streamInfo.contentLength
};
// The key will be removed whenever an incognito session is started,
// or when an incognito session is active.
chrome.storage.local.set(items, function() {
chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess) {
if (!isAllowedAccess) {
// If incognito is disabled, forget about the stream.
console.warn('Incognito is disabled, unexpected unknown stream.');
chrome.storage.local.remove(items);
}
});
});
}
if (chrome.extension.inIncognitoContext) {
var importStream = function(itemId, streamInfo) {
if (itemId.lastIndexOf('streamInfo:', 0) !== 0) {
return;
}
console.log('Importing stream info from non-incognito profile',
streamInfo);
handleStream('', streamInfo.pdfUrl, streamInfo.streamUrl,
streamInfo.tabId, streamInfo.contentLength);
chrome.storage.local.remove(itemId);
};
var handleStorageItems = function(items) {
Object.keys(items).forEach(function(itemId) {
var item = items[itemId];
if (item.oldValue && !item.newValue) {
return; // storage remove event
}
if (item.newValue) {
item = item.newValue; // storage setter event
}
importStream(itemId, item);
});
};
// Parse information that was set before the event pages were ready.
chrome.storage.local.get(null, handleStorageItems);
chrome.storage.onChanged.addListener(handleStorageItems);
}
// End of work-around for crbug 276898
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message && message.action === 'getPDFStream') {
var pdfUrl = message.data;
var streamInfo = getStream(sender.tab.id, pdfUrl) || {};
sendResponse({
streamUrl: streamInfo.streamUrl,
contentLength: streamInfo.contentLength,
extensionSupportsFTP: Features.extensionSupportsFTP
});
}
});
//
// PDF detection and activation of PDF viewer.
//
/**
* Callback for when we receive a stream
*
* @param mimeType {string} The mime type of the incoming stream
* @param pdfUrl {string} The full URL to the file
* @param streamUrl {string} The url pointing to the open stream
* @param tabId {number} The ID of the tab in which the stream has been opened
* (undefined before Chrome 27, http://crbug.com/225605)
* @param expectedSize {number} The expected content length of the stream.
* (added in Chrome 29, http://crbug.com/230346)
*/
function handleStream(mimeType, pdfUrl, streamUrl, tabId, expectedSize) {
if (typeof mimeType === 'object') {
// API change: argument list -> object, see crbug.com/345882
// documentation: chrome/common/extensions/api/streams_private.idl
var streamInfo = mimeType;
mimeType = streamInfo.mimeType;
pdfUrl = streamInfo.originalUrl;
streamUrl = streamInfo.streamUrl;
tabId = streamInfo.tabId;
expectedSize = streamInfo.expectedContentSize;
}
console.log('Intercepted ' + mimeType + ' in tab ' + tabId + ' with URL ' +
pdfUrl + '\nAvailable as: ' + streamUrl);
streamSupportsTabId = typeof tabId === 'number';
setStream(tabId, pdfUrl, streamUrl, expectedSize);
if (!tabId) { // Chrome doesn't set the tabId before v27
// PDF.js targets Chrome 28+ because of fatal bugs in incognito mode
// for older versions of Chrome. So, don't bother implementing a fallback.
// For those who are interested, either loop through all tabs, or use the
// webNavigation.onBeforeNavigate event to map pdfUrls to tab + frame IDs.
return;
}
// Check if the frame has already been rendered.
chrome.webNavigation.getAllFrames({
tabId: tabId
}, function(details) {
if (details) {
details = details.filter(function(frame) {
return (frame.url === pdfUrl);
});
if (details.length > 0) {
if (details.length !== 1) {
// (Rare case) Multiple frames with same URL.
// TODO(rob): Find a better way to handle this case
// (e.g. open in new tab).
console.warn('More than one frame found for tabId ' + tabId +
' with URL ' + pdfUrl + '. Using first frame.');
}
details = details[0];
details = {
tabId: tabId,
frameId: details.frameId,
url: details.url
};
handleWebNavigation(details);
} else {
console.warn('No webNavigation frames found for tabId ' + tabId);
}
} else {
console.warn('Unable to get frame information for tabId ' + tabId);
// This branch may occur when a new incognito session is launched.
// The event is dispatched in the non-incognito session while it should
// be dispatched in the incognito session. See http://crbug.com/276898
transferStreamToIncognitoProfile(tabId, pdfUrl);
}
});
}
/**
* This method is called when the chrome.streamsPrivate API has intercepted
* the PDF stream. This method detects such streams, finds the frame where
* the request was made, and loads the viewer in that frame.
*
* @param details {object}
* @param details.tabId {number} The ID of the tab
* @param details.url {string} The URL being navigated when the error
* occurred.
* @param details.frameId {number} 0 indicates the navigation happens in
* the tab content window; a positive value
* indicates navigation in a subframe.
*/
function handleWebNavigation(details) {
var tabId = details.tabId;
var frameId = details.frameId;
var pdfUrl = details.url;
if (!hasStream(tabId, pdfUrl)) {
console.log('No PDF stream found in tab ' + tabId + ' for ' + pdfUrl);
return;
}
var viewerUrl = getViewerURL(pdfUrl);
if (frameId === 0) { // Main frame
console.log('Going to render PDF Viewer in main frame for ' + pdfUrl);
chrome.tabs.update(tabId, {
url: viewerUrl
});
} else {
console.log('Going to render PDF Viewer in sub frame for ' + pdfUrl);
// Non-standard Chrome API. chrome.tabs.executeScriptInFrame and docs
// is available at https://github.com/Rob--W/chrome-api
chrome.tabs.executeScriptInFrame(tabId, {
frameId: frameId,
code: 'location.href = ' + JSON.stringify(viewerUrl) + ';'
}, function(result) {
if (!result) { // Did the tab disappear? Is the frame inaccessible?
console.warn('Frame not found, viewer not rendered in tab ' + tabId);
}
});
}
}
})();

View file

@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* eslint strict: ["error", "function"] */
/* globals chrome, getViewerURL */ /* globals chrome, getViewerURL */
(function() { (function() {

View file

@ -14,12 +14,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<script src="chrome.tabs.executeScriptInFrame.js"></script>
<script src="feature-detect.js"></script> <script src="feature-detect.js"></script>
<script src="options/migration.js"></script>
<script src="preserve-referer.js"></script> <script src="preserve-referer.js"></script>
<script src="pdfHandler.js"></script> <script src="pdfHandler.js"></script>
<script src="extension-router.js"></script> <script src="extension-router.js"></script>
<script src="pdfHandler-v2.js"></script>
<script src="pdfHandler-vcros.js"></script> <script src="pdfHandler-vcros.js"></script>
<script src="pageAction/background.js"></script> <script src="pageAction/background.js"></script>
<script src="suppress-update.js"></script> <script src="suppress-update.js"></script>
<script src="telemetry.js"></script>

View file

@ -54,7 +54,7 @@ function isPdfDownloadable(details) {
* @return {undefined|{name: string, value: string}} The header, if found. * @return {undefined|{name: string, value: string}} The header, if found.
*/ */
function getHeaderFromHeaders(headers, headerName) { function getHeaderFromHeaders(headers, headerName) {
for (var i=0; i<headers.length; ++i) { for (var i = 0; i < headers.length; ++i) {
var header = headers[i]; var header = headers[i];
if (header.name.toLowerCase() === headerName) { if (header.name.toLowerCase() === headerName) {
return header; return header;
@ -72,10 +72,20 @@ function getHeaderFromHeaders(headers, headerName) {
function isPdfFile(details) { function isPdfFile(details) {
var header = getHeaderFromHeaders(details.responseHeaders, 'content-type'); var header = getHeaderFromHeaders(details.responseHeaders, 'content-type');
if (header) { if (header) {
var headerValue = header.value.toLowerCase().split(';',1)[0].trim(); var headerValue = header.value.toLowerCase().split(';', 1)[0].trim();
return (headerValue === 'application/pdf' || if (headerValue === 'application/pdf') {
headerValue === 'application/octet-stream' && return true;
details.url.toLowerCase().indexOf('.pdf') > 0); }
if (headerValue === 'application/octet-stream') {
if (details.url.toLowerCase().indexOf('.pdf') > 0) {
return true;
}
var cdHeader =
getHeaderFromHeaders(details.responseHeaders, 'content-disposition');
if (cdHeader && /\.pdf(["']|$)/i.test(cdHeader.value)) {
return true;
}
}
} }
} }
@ -133,46 +143,8 @@ chrome.webRequest.onHeadersReceived.addListener(
url: viewerUrl url: viewerUrl
}); });
return { cancel: true }; return { cancel: true };
} else {
// Sub frame. Requires some more work...
// The navigation will be cancelled at the end of the webRequest cycle.
chrome.webNavigation.onErrorOccurred.addListener(function listener(nav) {
if (nav.tabId !== details.tabId || nav.frameId !== details.frameId) {
return;
}
chrome.webNavigation.onErrorOccurred.removeListener(listener);
// Locate frame and insert viewer
chrome.tabs.executeScriptInFrame(details.tabId, {
frameId: details.frameId,
code: 'location.href = ' + JSON.stringify(viewerUrl) + ';'
}, function(result) {
if (!result) {
console.warn('Frame not found! Opening viewer in new tab...');
chrome.tabs.create({
url: viewerUrl
});
}
});
}, {
url: [{ urlEquals: details.url.split('#', 1)[0] }]
});
// Prevent frame from rendering by using X-Frame-Options.
// Do not use { cancel: true }, because that makes the frame inaccessible
// to the content script that has to replace the frame's URL.
return {
responseHeaders: [{
name: 'X-Content-Type-Options',
value: 'nosniff'
}, {
name: 'X-Frame-Options',
value: 'deny'
}]
};
} }
console.warn('Child frames are not supported in ancient Chrome builds!');
// Immediately abort the request, because the frame that initiated the
// request will be replaced with the PDF Viewer (within a split second).
}, },
{ {
urls: [ urls: [
@ -180,7 +152,7 @@ chrome.webRequest.onHeadersReceived.addListener(
], ],
types: ['main_frame', 'sub_frame'] types: ['main_frame', 'sub_frame']
}, },
['blocking','responseHeaders']); ['blocking', 'responseHeaders']);
chrome.webRequest.onBeforeRequest.addListener( chrome.webRequest.onBeforeRequest.addListener(
function onBeforeRequestForFTP(details) { function onBeforeRequestForFTP(details) {
@ -252,6 +224,32 @@ chrome.extension.isAllowedFileSchemeAccess(function(isAllowedAccess) {
}); });
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message && message.action === 'getParentOrigin') {
// getParentOrigin is used to determine whether it is safe to embed a
// sensitive (local) file in a frame.
if (!sender.tab) {
sendResponse('');
return;
}
// TODO: This should be the URL of the parent frame, not the tab. But
// chrome-extension:-URLs are not visible in the webNavigation API
// (https://crbug.com/326768), so the next best thing is using the tab's URL
// for making security decisions.
var parentUrl = sender.tab.url;
if (!parentUrl) {
sendResponse('');
return;
}
if (parentUrl.lastIndexOf('file:', 0) === 0) {
sendResponse('file://');
return;
}
// The regexp should always match for valid URLs, but in case it doesn't,
// just give the full URL (e.g. data URLs).
var origin = /^[^:]+:\/\/[^/]+/.exec(parentUrl);
sendResponse(origin ? origin[1] : parentUrl);
return true;
}
if (message && message.action === 'isAllowedFileSchemeAccess') { if (message && message.action === 'isAllowedFileSchemeAccess') {
chrome.extension.isAllowedFileSchemeAccess(sendResponse); chrome.extension.isAllowedFileSchemeAccess(sendResponse);
return true; return true;

View file

@ -75,6 +75,51 @@
"useOnlyCssZoom": { "useOnlyCssZoom": {
"type": "boolean", "type": "boolean",
"default": false "default": false
},
"externalLinkTarget": {
"title": "External links target window",
"description": "Controls how external links will be opened.\n 0 = default.\n 1 = replaces current window.\n 2 = new window/tab.\n 3 = parent.\n 4 = in top window.",
"type": "integer",
"enum": [
0,
1,
2,
3,
4
],
"default": 0
},
"disablePageLabels": {
"type": "boolean",
"default": false
},
"disableTelemetry": {
"title": "Disable telemetry",
"type": "boolean",
"description": "Whether to prevent the extension from reporting the extension and browser version to the extension developers.",
"default": false
},
"enhanceTextSelection": {
"type": "boolean",
"default": false
},
"renderer": {
"type": "string",
"enum": [
"canvas",
"svg"
],
"default": "canvas"
},
"renderInteractiveForms": {
"type": "boolean",
"default": false
},
"enablePrintAutoRotate": {
"title": "Automatically rotate printed pages",
"description": "When enabled, pages whose orientation differ from the first page are rotated when printed.",
"type": "boolean",
"default": false
} }
} }
} }

View file

@ -0,0 +1,163 @@
/*
Copyright 2016 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* eslint strict: ["error", "function"] */
/* globals chrome, crypto, Headers, Request */
(function() {
'use strict';
// This module sends the browser and extension version to a server, to
// determine whether it is safe to drop support for old Chrome versions in
// future extension updates.
//
// The source code for the server is available at:
// https://github.com/Rob--W/pdfjs-telemetry
var LOG_URL = 'https://pdfjs.robwu.nl/logpdfjs';
// The minimum time to wait before sending a ping, so that we don't send too
// many requests even if the user restarts their browser very often.
// We want one ping a day, so a minimum delay of 12 hours should be OK.
var MINIMUM_TIME_BETWEEN_PING = 12 * 36E5;
if (chrome.extension.inIncognitoContext) {
// The extension uses incognito split mode, so there are two background
// pages. Only send telemetry when not in incognito mode.
return;
}
if (chrome.runtime.id !== 'oemmndcbldboiebfnladdacbdfmadadm') {
// Only send telemetry for the official PDF.js extension.
console.warn('Disabled telemetry because this is not an official build.');
return;
}
maybeSendPing();
setInterval(maybeSendPing, 36E5);
function maybeSendPing() {
getLoggingPref(function(didOptOut) {
if (didOptOut) {
// Respect the user's decision to not send statistics.
return;
}
if (!navigator.onLine) {
// No network available; Wait until the next scheduled ping opportunity.
// Even if onLine is true, the server may still be unreachable. But
// because it is impossible to tell whether a request failed due to the
// inability to connect, or a deliberate connection termination by the
// server, we don't validate the response and assume that the request
// succeeded. This ensures that the server cannot ask the client to
// send more pings.
return;
}
var lastTime = parseInt(localStorage.telemetryLastTime) || 0;
var wasUpdated = didUpdateSinceLastCheck();
if (!wasUpdated && Date.now() - lastTime < MINIMUM_TIME_BETWEEN_PING) {
return;
}
localStorage.telemetryLastTime = Date.now();
var deduplication_id = getDeduplicationId(wasUpdated);
var extension_version = chrome.runtime.getManifest().version;
if (window.Request && 'mode' in Request.prototype) {
// fetch is supported in extensions since Chrome 42 (though the above
// feature-detection method detects Chrome 43+).
// Unlike XMLHttpRequest, fetch omits credentials such as cookies in the
// requests, which guarantees that the server cannot track the client
// via HTTP cookies.
fetch(LOG_URL, {
method: 'POST',
headers: new Headers({
'Deduplication-Id': deduplication_id,
'Extension-Version': extension_version,
}),
// Set mode=cors so that the above custom headers are included in the
// request.
mode: 'cors',
});
return;
}
var x = new XMLHttpRequest();
x.open('POST', LOG_URL);
x.setRequestHeader('Deduplication-Id', deduplication_id);
x.setRequestHeader('Extension-Version', extension_version);
x.send();
});
}
/**
* Generate a 40-bit hexadecimal string (=10 letters, 1.1E12 possibilities).
* This is used by the server to discard duplicate entries of the same browser
* version when the log data is aggregated.
*/
function getDeduplicationId(wasUpdated) {
var id = localStorage.telemetryDeduplicationId;
// The ID is only used to deduplicate reports for the same browser version,
// so it is OK to change the ID if the browser is updated. By changing the
// ID, the server cannot track users for a long period even if it wants to.
if (!id || !/^[0-9a-f]{10}$/.test(id) || wasUpdated) {
id = '';
var buf = new Uint8Array(5);
crypto.getRandomValues(buf);
for (var i = 0; i < buf.length; ++i) {
var c = buf[i];
id += (c >>> 4).toString(16) + (c & 0xF).toString(16);
}
localStorage.telemetryDeduplicationId = id;
}
return id;
}
/**
* Returns whether the browser has received a major update since the last call
* to this function.
*/
function didUpdateSinceLastCheck() {
var chromeVersion = /Chrome\/(\d+)\./.exec(navigator.userAgent);
chromeVersion = chromeVersion && chromeVersion[1];
if (!chromeVersion || localStorage.telemetryLastVersion === chromeVersion) {
return false;
}
localStorage.telemetryLastVersion = chromeVersion;
return true;
}
/**
* Get the value of the telemetry preference. The callback is invoked with a
* boolean if a preference is found, and with the undefined value otherwise.
*/
function getLoggingPref(callback) {
// Try to look up the preference in the storage, in the following order:
var areas = ['sync', 'local', 'managed'];
next();
function next(result) {
var storageAreaName = areas.shift();
if (typeof result === 'boolean' || !storageAreaName) {
callback(result);
return;
}
if (!chrome.storage[storageAreaName]) {
next();
return;
}
chrome.storage[storageAreaName].get('disableTelemetry', function(items) {
next(items && items.disableTelemetry);
});
}
}
})();

Some files were not shown because too many files have changed in this diff Show more