|
|
|
@ -387,7 +387,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
@@ -387,7 +387,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|
|
|
|
* @class |
|
|
|
|
*/ |
|
|
|
|
var PDFPageProxy = (function PDFPageProxyClosure() { |
|
|
|
|
function PDFPageProxy(pageInfo, transport) { |
|
|
|
|
function PDFPageProxy(pageIndex, pageInfo, transport) { |
|
|
|
|
this.pageIndex = pageIndex; |
|
|
|
|
this.pageInfo = pageInfo; |
|
|
|
|
this.transport = transport; |
|
|
|
|
this.stats = new StatTimer(); |
|
|
|
@ -403,7 +404,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
@@ -403,7 +404,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
|
|
* @return {number} Page number of the page. First page is 1. |
|
|
|
|
*/ |
|
|
|
|
get pageNumber() { |
|
|
|
|
return this.pageInfo.pageIndex + 1; |
|
|
|
|
return this.pageIndex + 1; |
|
|
|
|
}, |
|
|
|
|
/** |
|
|
|
|
* @return {number} The number of degrees the page is rotated clockwise. |
|
|
|
@ -443,14 +444,13 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
@@ -443,14 +444,13 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
|
|
* annotation objects. |
|
|
|
|
*/ |
|
|
|
|
getAnnotations: function PDFPageProxy_getAnnotations() { |
|
|
|
|
if (this.annotationsCapability) { |
|
|
|
|
return this.annotationsCapability.promise; |
|
|
|
|
if (this.annotationsPromise) { |
|
|
|
|
return this.annotationsPromise; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var capability = createPromiseCapability(); |
|
|
|
|
this.annotationsCapability = capability; |
|
|
|
|
this.transport.getAnnotations(this.pageInfo.pageIndex); |
|
|
|
|
return capability.promise; |
|
|
|
|
var promise = this.transport.getAnnotations(this.pageIndex); |
|
|
|
|
this.annotationsPromise = promise; |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
/** |
|
|
|
|
* Begins the process of rendering a page to the desired context. |
|
|
|
@ -546,15 +546,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
@@ -546,15 +546,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
|
|
* object that represent the page text content. |
|
|
|
|
*/ |
|
|
|
|
getTextContent: function PDFPageProxy_getTextContent() { |
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
|
this.transport.messageHandler.send('GetTextContent', { |
|
|
|
|
return this.transport.messageHandler.sendWithPromise('GetTextContent', { |
|
|
|
|
pageIndex: this.pageNumber - 1 |
|
|
|
|
}, |
|
|
|
|
function textContentCallback(textContent) { |
|
|
|
|
resolve(textContent); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}.bind(this)); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
/** |
|
|
|
|
* Destroys resources allocated by the page. |
|
|
|
@ -582,6 +576,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
@@ -582,6 +576,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
|
|
delete this.intentStates[intent]; |
|
|
|
|
}, this); |
|
|
|
|
this.objs.clear(); |
|
|
|
|
this.annotationsPromise = null; |
|
|
|
|
this.pendingDestroy = false; |
|
|
|
|
}, |
|
|
|
|
/** |
|
|
|
@ -637,7 +632,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -637,7 +632,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
this.commonObjs = new PDFObjects(); |
|
|
|
|
|
|
|
|
|
this.pageCache = []; |
|
|
|
|
this.pageCapabilities = []; |
|
|
|
|
this.pagePromises = []; |
|
|
|
|
this.downloadInfoCapability = createPromiseCapability(); |
|
|
|
|
this.passwordCallback = null; |
|
|
|
|
|
|
|
|
@ -682,7 +677,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -682,7 +677,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
|
|
|
|
|
// typed array. Also, checking if we can use transfers.
|
|
|
|
|
try { |
|
|
|
|
messageHandler.send('test', testObj, null, [testObj.buffer]); |
|
|
|
|
messageHandler.send('test', testObj, [testObj.buffer]); |
|
|
|
|
} catch (ex) { |
|
|
|
|
info('Cannot use postMessage transfers'); |
|
|
|
|
testObj[0] = 0; |
|
|
|
@ -705,9 +700,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -705,9 +700,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
WorkerTransport.prototype = { |
|
|
|
|
destroy: function WorkerTransport_destroy() { |
|
|
|
|
this.pageCache = []; |
|
|
|
|
this.pageCapabilities = []; |
|
|
|
|
this.pagePromises = []; |
|
|
|
|
var self = this; |
|
|
|
|
this.messageHandler.send('Terminate', null, function () { |
|
|
|
|
this.messageHandler.sendWithPromise('Terminate', null).then(function () { |
|
|
|
|
FontLoader.clear(); |
|
|
|
|
if (self.worker) { |
|
|
|
|
self.worker.terminate(); |
|
|
|
@ -827,20 +822,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -827,20 +822,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
this.downloadInfoCapability.resolve(data); |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('GetPage', function transportPage(data) { |
|
|
|
|
var pageInfo = data.pageInfo; |
|
|
|
|
var page = new PDFPageProxy(pageInfo, this); |
|
|
|
|
this.pageCache[pageInfo.pageIndex] = page; |
|
|
|
|
var promise = this.pageCapabilities[pageInfo.pageIndex]; |
|
|
|
|
promise.resolve(page); |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('GetAnnotations', function transportAnnotations(data) { |
|
|
|
|
var annotations = data.annotations; |
|
|
|
|
var promise = this.pageCache[data.pageIndex].annotationsCapability; |
|
|
|
|
promise.resolve(annotations); |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('StartRenderPage', function transportRender(data) { |
|
|
|
|
var page = this.pageCache[data.pageIndex]; |
|
|
|
|
|
|
|
|
@ -934,9 +915,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -934,9 +915,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
this.workerReadyCapability.reject(data); |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('PageError', function transportError(data, intent) { |
|
|
|
|
messageHandler.on('PageError', function transportError(data) { |
|
|
|
|
var page = this.pageCache[data.pageNum - 1]; |
|
|
|
|
var intentState = page.intentStates[intent]; |
|
|
|
|
var intentState = page.intentStates[data.intent]; |
|
|
|
|
if (intentState.displayReadyCapability.promise) { |
|
|
|
|
intentState.displayReadyCapability.reject(data.error); |
|
|
|
|
} else { |
|
|
|
@ -944,15 +925,17 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -944,15 +925,17 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
} |
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
messageHandler.on('JpegDecode', function(data, deferred) { |
|
|
|
|
messageHandler.on('JpegDecode', function(data) { |
|
|
|
|
var imageUrl = data[0]; |
|
|
|
|
var components = data[1]; |
|
|
|
|
if (components != 3 && components != 1) { |
|
|
|
|
error('Only 3 component or 1 component can be returned'); |
|
|
|
|
return Promise.reject( |
|
|
|
|
new Error('Only 3 components or 1 component can be returned')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
|
var img = new Image(); |
|
|
|
|
img.onload = (function messageHandler_onloadClosure() { |
|
|
|
|
img.onload = function () { |
|
|
|
|
var width = img.width; |
|
|
|
|
var height = img.height; |
|
|
|
|
var size = width * height; |
|
|
|
@ -975,10 +958,14 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -975,10 +958,14 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
buf[j] = data[i]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
deferred.resolve({ data: buf, width: width, height: height}); |
|
|
|
|
}).bind(this); |
|
|
|
|
resolve({ data: buf, width: width, height: height}); |
|
|
|
|
}; |
|
|
|
|
img.onerror = function () { |
|
|
|
|
reject(new Error('JpegDecode failed to load image')); |
|
|
|
|
}; |
|
|
|
|
img.src = imageUrl; |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
fetchDocument: function WorkerTransport_fetchDocument(source) { |
|
|
|
@ -1009,86 +996,58 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -1009,86 +996,58 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var pageIndex = pageNumber - 1; |
|
|
|
|
if (pageIndex in this.pageCapabilities) { |
|
|
|
|
return this.pageCapabilities[pageIndex].promise; |
|
|
|
|
} |
|
|
|
|
capability = createPromiseCapability(); |
|
|
|
|
this.pageCapabilities[pageIndex] = capability; |
|
|
|
|
this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex }); |
|
|
|
|
return capability.promise; |
|
|
|
|
if (pageIndex in this.pagePromises) { |
|
|
|
|
return this.pagePromises[pageIndex]; |
|
|
|
|
} |
|
|
|
|
var promise = this.messageHandler.sendWithPromise('GetPage', { |
|
|
|
|
pageIndex: pageIndex |
|
|
|
|
}).then(function (pageInfo) { |
|
|
|
|
var page = new PDFPageProxy(pageIndex, pageInfo, this); |
|
|
|
|
this.pageCache[pageIndex] = page; |
|
|
|
|
return page; |
|
|
|
|
}.bind(this)); |
|
|
|
|
this.pagePromises[pageIndex] = promise; |
|
|
|
|
return promise; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) { |
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
|
this.messageHandler.send('GetPageIndex', { ref: ref }, |
|
|
|
|
function (pageIndex) { |
|
|
|
|
resolve(pageIndex); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}.bind(this)); |
|
|
|
|
return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) { |
|
|
|
|
this.messageHandler.send('GetAnnotationsRequest', |
|
|
|
|
return this.messageHandler.sendWithPromise('GetAnnotations', |
|
|
|
|
{ pageIndex: pageIndex }); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getDestinations: function WorkerTransport_getDestinations() { |
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
|
this.messageHandler.send('GetDestinations', null, |
|
|
|
|
function transportDestinations(destinations) { |
|
|
|
|
resolve(destinations); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}.bind(this)); |
|
|
|
|
return this.messageHandler.sendWithPromise('GetDestinations', null); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getAttachments: function WorkerTransport_getAttachments() { |
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
|
this.messageHandler.send('GetAttachments', null, |
|
|
|
|
function transportAttachments(attachments) { |
|
|
|
|
resolve(attachments); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}.bind(this)); |
|
|
|
|
return this.messageHandler.sendWithPromise('GetAttachments', null); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getJavaScript: function WorkerTransport_getJavaScript() { |
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
|
this.messageHandler.send('GetJavaScript', null, |
|
|
|
|
function transportJavaScript(js) { |
|
|
|
|
resolve(js); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}.bind(this)); |
|
|
|
|
return this.messageHandler.sendWithPromise('GetJavaScript', null); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getOutline: function WorkerTransport_getOutline() { |
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
|
this.messageHandler.send('GetOutline', null, |
|
|
|
|
function transportOutline(outline) { |
|
|
|
|
resolve(outline); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}.bind(this)); |
|
|
|
|
return this.messageHandler.sendWithPromise('GetOutline', null); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getMetadata: function WorkerTransport_getMetadata() { |
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
|
this.messageHandler.send('GetMetadata', null, |
|
|
|
|
function transportMetadata(results) { |
|
|
|
|
resolve({ |
|
|
|
|
return this.messageHandler.sendWithPromise('GetMetadata', null). |
|
|
|
|
then(function transportMetadata(results) { |
|
|
|
|
return { |
|
|
|
|
info: results[0], |
|
|
|
|
metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null) |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}.bind(this)); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
startCleanup: function WorkerTransport_startCleanup() { |
|
|
|
|
this.messageHandler.send('Cleanup', null, |
|
|
|
|
function endCleanup() { |
|
|
|
|
this.messageHandler.sendWithPromise('Cleanup', null). |
|
|
|
|
then(function endCleanup() { |
|
|
|
|
for (var i = 0, ii = this.pageCache.length; i < ii; i++) { |
|
|
|
|
var page = this.pageCache[i]; |
|
|
|
|
if (page) { |
|
|
|
@ -1097,8 +1056,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
@@ -1097,8 +1056,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
|
|
} |
|
|
|
|
this.commonObjs.clear(); |
|
|
|
|
FontLoader.clear(); |
|
|
|
|
}.bind(this) |
|
|
|
|
); |
|
|
|
|
}.bind(this)); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
return WorkerTransport; |
|
|
|
|