mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 23:28:06 +02:00
Merge branch 'master' of git://github.com/mozilla/pdf.js.git into loadpdf-1
Conflicts: src/api.js
This commit is contained in:
commit
eb863b2298
20 changed files with 1548 additions and 227 deletions
51
src/api.js
51
src/api.js
|
@ -18,23 +18,18 @@
|
|||
* @return {Promise} A promise that is resolved with {PDFDocumentProxy} object.
|
||||
*/
|
||||
PDFJS.getDocument = function getDocument(source) {
|
||||
if (typeof source === 'string') {
|
||||
source = { url: source };
|
||||
} else if (isArrayBuffer(source)) {
|
||||
source = { data: source };
|
||||
} else if (typeof source !== 'object') {
|
||||
error('Invalid parameter in getDocument, need either Uint8Array, ' +
|
||||
'string or a parameter object');
|
||||
}
|
||||
var workerInitializedPromise, workerReadyPromise, transport;
|
||||
|
||||
if (!source.url && !source.data)
|
||||
error('Invalid parameter array, need either .data or .url');
|
||||
|
||||
var promise = new PDFJS.Promise();
|
||||
var transport = new WorkerTransport(promise);
|
||||
transport.fetchDocument(source);
|
||||
|
||||
return promise;
|
||||
workerInitializedPromise = new PDFJS.Promise();
|
||||
workerReadyPromise = new PDFJS.Promise();
|
||||
transport = new WorkerTransport(workerInitializedPromise, workerReadyPromise);
|
||||
workerInitializedPromise.then(function transportInitialized() {
|
||||
transport.fetchDocument(source);
|
||||
});
|
||||
return workerReadyPromise;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -203,7 +198,11 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
* {
|
||||
* canvasContext(required): A 2D context of a DOM Canvas object.,
|
||||
* textLayer(optional): An object that has beginLayout, endLayout, and
|
||||
* appendText functions.
|
||||
* appendText functions.,
|
||||
* continueCallback(optional): A function that will be called each time
|
||||
* the rendering is paused. To continue
|
||||
* rendering call the function that is the
|
||||
* first argument to the callback.
|
||||
* }.
|
||||
* @return {Promise} A promise that is resolved when the page finishes
|
||||
* rendering.
|
||||
|
@ -239,6 +238,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
else
|
||||
promise.resolve();
|
||||
};
|
||||
var continueCallback = params.continueCallback;
|
||||
|
||||
// Once the operatorList and fonts are loaded, do the actual rendering.
|
||||
this.displayReadyPromise.then(
|
||||
|
@ -251,7 +251,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
var gfx = new CanvasGraphics(params.canvasContext,
|
||||
this.objs, params.textLayer);
|
||||
try {
|
||||
this.display(gfx, params.viewport, complete);
|
||||
this.display(gfx, params.viewport, complete, continueCallback);
|
||||
} catch (e) {
|
||||
complete(e);
|
||||
}
|
||||
|
@ -309,7 +309,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
/**
|
||||
* For internal use only.
|
||||
*/
|
||||
display: function PDFPageProxy_display(gfx, viewport, callback) {
|
||||
display: function PDFPageProxy_display(gfx, viewport, callback,
|
||||
continueCallback) {
|
||||
var stats = this.stats;
|
||||
stats.time('Rendering');
|
||||
|
||||
|
@ -325,10 +326,16 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
stepper.nextBreakPoint = stepper.getNextBreakPoint();
|
||||
}
|
||||
|
||||
var continueWrapper;
|
||||
if (continueCallback)
|
||||
continueWrapper = function() { continueCallback(next); }
|
||||
else
|
||||
continueWrapper = next;
|
||||
|
||||
var self = this;
|
||||
function next() {
|
||||
startIdx =
|
||||
gfx.executeOperatorList(operatorList, startIdx, next, stepper);
|
||||
startIdx = gfx.executeOperatorList(operatorList, startIdx,
|
||||
continueWrapper, stepper);
|
||||
if (startIdx == length) {
|
||||
gfx.endDrawing();
|
||||
stats.timeEnd('Rendering');
|
||||
|
@ -336,7 +343,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
if (callback) callback();
|
||||
}
|
||||
}
|
||||
next();
|
||||
continueWrapper();
|
||||
},
|
||||
/**
|
||||
* @return {Promise} That is resolved with the a {string} that is the text
|
||||
|
@ -383,8 +390,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||
* For internal use only.
|
||||
*/
|
||||
var WorkerTransport = (function WorkerTransportClosure() {
|
||||
function WorkerTransport(promise) {
|
||||
this.workerReadyPromise = promise;
|
||||
function WorkerTransport(workerInitializedPromise, workerReadyPromise) {
|
||||
this.workerReadyPromise = workerReadyPromise;
|
||||
this.objs = new PDFObjects();
|
||||
|
||||
this.pageCache = [];
|
||||
|
@ -428,6 +435,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
globalScope.PDFJS.disableWorker = true;
|
||||
this.setupFakeWorker();
|
||||
}
|
||||
workerInitializedPromise.resolve();
|
||||
}.bind(this));
|
||||
|
||||
var testObj = new Uint8Array(1);
|
||||
|
@ -443,6 +451,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
// Thus, we fallback to a faked worker.
|
||||
globalScope.PDFJS.disableWorker = true;
|
||||
this.setupFakeWorker();
|
||||
workerInitializedPromise.resolve();
|
||||
}
|
||||
WorkerTransport.prototype = {
|
||||
destroy: function WorkerTransport_destroy() {
|
||||
|
|
|
@ -532,7 +532,7 @@ var FontLoader = {
|
|||
|
||||
// XXX we should have a time-out here too, and maybe fire
|
||||
// pdfjsFontLoadFailed?
|
||||
var src = '<!DOCTYPE HTML><html><head>';
|
||||
var src = '<!DOCTYPE HTML><html><head><meta charset="utf-8">';
|
||||
src += '<style type="text/css">';
|
||||
for (var i = 0, ii = rules.length; i < ii; ++i) {
|
||||
src += rules[i];
|
||||
|
|
1051
src/jbig2.js
Normal file
1051
src/jbig2.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -253,7 +253,8 @@ var Parser = (function ParserClosure() {
|
|||
return new RunLengthStream(stream);
|
||||
}
|
||||
if (name == 'JBIG2Decode') {
|
||||
error('JBIG2 image format is not currently supprted.');
|
||||
var bytes = stream.getBytes(length);
|
||||
return new Jbig2Stream(bytes, stream.dict);
|
||||
}
|
||||
warn('filter "' + name + '" not supported yet');
|
||||
return stream;
|
||||
|
|
|
@ -979,6 +979,50 @@ var JpxStream = (function JpxStreamClosure() {
|
|||
return JpxStream;
|
||||
})();
|
||||
|
||||
/**
|
||||
* For JBIG2's we use a library to decode these images and
|
||||
* the stream behaves like all the other DecodeStreams.
|
||||
*/
|
||||
var Jbig2Stream = (function Jbig2StreamClosure() {
|
||||
function Jbig2Stream(bytes, dict) {
|
||||
this.dict = dict;
|
||||
this.bytes = bytes;
|
||||
|
||||
DecodeStream.call(this);
|
||||
}
|
||||
|
||||
Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
|
||||
|
||||
Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
|
||||
if (this.bufferLength)
|
||||
return;
|
||||
|
||||
var jbig2Image = new Jbig2Image();
|
||||
|
||||
var chunks = [], decodeParams = this.dict.get('DecodeParms');
|
||||
if (decodeParams && decodeParams.has('JBIG2Globals')) {
|
||||
var globalsStream = decodeParams.get('JBIG2Globals');
|
||||
var globals = globalsStream.getBytes();
|
||||
chunks.push({data: globals, start: 0, end: globals.length});
|
||||
}
|
||||
chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
|
||||
var data = jbig2Image.parseChunks(chunks);
|
||||
var dataLength = data.length;
|
||||
|
||||
// JBIG2 had black as 1 and white as 0, inverting the colors
|
||||
for (var i = 0; i < dataLength; i++)
|
||||
data[i] ^= 0xFF;
|
||||
|
||||
this.buffer = data;
|
||||
this.bufferLength = dataLength;
|
||||
};
|
||||
Jbig2Stream.prototype.getChar = function Jbig2Stream_getChar() {
|
||||
error('internal error: getChar is not valid on Jbig2Stream');
|
||||
};
|
||||
|
||||
return Jbig2Stream;
|
||||
})();
|
||||
|
||||
var DecryptStream = (function DecryptStreamClosure() {
|
||||
function DecryptStream(str, decrypt) {
|
||||
this.str = str;
|
||||
|
|
|
@ -24,6 +24,7 @@ var files = [
|
|||
'stream.js',
|
||||
'worker.js',
|
||||
'jpx.js',
|
||||
'jbig2.js',
|
||||
'bidi.js',
|
||||
'../external/jpgjs/jpg.js'
|
||||
];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue