mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 23:58:07 +02:00
Merge upstream. Use new l10n.
This commit is contained in:
commit
080c3e79fc
15 changed files with 374 additions and 61 deletions
|
@ -8,10 +8,12 @@
|
|||
* e.g. No cross domain requests without CORS.
|
||||
*
|
||||
* @param {string|TypedAray} source Either a url to a PDF is located or a
|
||||
* typed array already populated with data.
|
||||
* typed array (Uint8Array) already populated with data.
|
||||
* @param {Object} headers An object containing the http headers like this:
|
||||
* { Authorization: "BASIC XXX" }.
|
||||
* @return {Promise} A promise that is resolved with {PDFDocumentProxy} object.
|
||||
*/
|
||||
PDFJS.getDocument = function getDocument(source) {
|
||||
PDFJS.getDocument = function getDocument(source, headers) {
|
||||
var promise = new PDFJS.Promise();
|
||||
var transport = new WorkerTransport(promise);
|
||||
if (typeof source === 'string') {
|
||||
|
@ -29,7 +31,8 @@ PDFJS.getDocument = function getDocument(source) {
|
|||
error: function getPDFError(e) {
|
||||
promise.reject('Unexpected server response of ' +
|
||||
e.target.status + '.');
|
||||
}
|
||||
},
|
||||
headers: headers
|
||||
},
|
||||
function getPDFLoad(data) {
|
||||
transport.sendData(data);
|
||||
|
|
12
src/core.js
12
src/core.js
|
@ -31,7 +31,19 @@ function getPdf(arg, callback) {
|
|||
params = { url: arg };
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', params.url);
|
||||
|
||||
var headers = params.headers;
|
||||
if (headers) {
|
||||
for (var property in headers) {
|
||||
if (typeof headers[property] === 'undefined')
|
||||
continue;
|
||||
|
||||
xhr.setRequestHeader(property, params.headers[property]);
|
||||
}
|
||||
}
|
||||
|
||||
xhr.mozResponseType = xhr.responseType = 'arraybuffer';
|
||||
var protocol = params.url.indexOf(':') < 0 ? window.location.protocol :
|
||||
params.url.substring(0, params.url.indexOf(':') + 1);
|
||||
|
|
|
@ -112,14 +112,33 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
};
|
||||
|
||||
function splitCombinedOperations(operations) {
|
||||
// Two operations can be combined together, trying to find which two
|
||||
// Two or more operations can be combined together, trying to find which
|
||||
// operations were concatenated.
|
||||
for (var i = operations.length - 1; i > 0; i--) {
|
||||
var op1 = operations.substring(0, i), op2 = operations.substring(i);
|
||||
if (op1 in OP_MAP && op2 in OP_MAP)
|
||||
return [op1, op2]; // operations found
|
||||
var result = [];
|
||||
var opIndex = 0;
|
||||
|
||||
if (!operations) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
while (opIndex < operations.length) {
|
||||
var currentOp = '';
|
||||
for (var op in OP_MAP) {
|
||||
if (op == operations.substr(opIndex, op.length) &&
|
||||
op.length > currentOp.length) {
|
||||
currentOp = op;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentOp.length > 0) {
|
||||
result.push(operations.substr(opIndex, currentOp.length));
|
||||
opIndex += currentOp.length;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PartialEvaluator.prototype = {
|
||||
|
@ -267,14 +286,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var patterns = resources.get('Pattern') || new Dict();
|
||||
var parser = new Parser(new Lexer(stream), false, xref);
|
||||
var res = resources;
|
||||
var hasNextObj = false, nextObj;
|
||||
var hasNextObj = false, nextObjs;
|
||||
var args = [], obj;
|
||||
var TILING_PATTERN = 1, SHADING_PATTERN = 2;
|
||||
|
||||
while (true) {
|
||||
if (hasNextObj) {
|
||||
obj = nextObj;
|
||||
hasNextObj = false;
|
||||
obj = nextObjs.pop();
|
||||
hasNextObj = (nextObjs.length > 0);
|
||||
} else {
|
||||
obj = parser.getObj();
|
||||
if (isEOF(obj))
|
||||
|
@ -290,9 +309,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
if (cmds) {
|
||||
cmd = cmds[0];
|
||||
fn = OP_MAP[cmd];
|
||||
// feeding other command on the next interation
|
||||
// feeding other command on the next iteration
|
||||
hasNextObj = true;
|
||||
nextObj = Cmd.get(cmds[1]);
|
||||
nextObjs = [];
|
||||
for (var idx = 1; idx < cmds.length; idx++) {
|
||||
nextObjs.push(Cmd.get(cmds[idx]));
|
||||
}
|
||||
}
|
||||
}
|
||||
assertWellFormed(fn, 'Unknown command "' + cmd + '"');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue