|
|
@ -546,15 +546,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() { |
|
|
|
* object that represent the page text content. |
|
|
|
* object that represent the page text content. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
getTextContent: function PDFPageProxy_getTextContent() { |
|
|
|
getTextContent: function PDFPageProxy_getTextContent() { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
return this.transport.messageHandler.sendWithPromise('GetTextContent', { |
|
|
|
this.transport.messageHandler.send('GetTextContent', { |
|
|
|
pageIndex: this.pageNumber - 1 |
|
|
|
pageIndex: this.pageNumber - 1 |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
function textContentCallback(textContent) { |
|
|
|
|
|
|
|
resolve(textContent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Destroys resources allocated by the page. |
|
|
|
* Destroys resources allocated by the page. |
|
|
@ -682,7 +676,7 @@ var WorkerTransport = (function WorkerTransportClosure() { |
|
|
|
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
|
|
|
|
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
|
|
|
|
// typed array. Also, checking if we can use transfers.
|
|
|
|
// typed array. Also, checking if we can use transfers.
|
|
|
|
try { |
|
|
|
try { |
|
|
|
messageHandler.send('test', testObj, null, [testObj.buffer]); |
|
|
|
messageHandler.send('test', testObj, [testObj.buffer]); |
|
|
|
} catch (ex) { |
|
|
|
} catch (ex) { |
|
|
|
info('Cannot use postMessage transfers'); |
|
|
|
info('Cannot use postMessage transfers'); |
|
|
|
testObj[0] = 0; |
|
|
|
testObj[0] = 0; |
|
|
@ -707,7 +701,7 @@ var WorkerTransport = (function WorkerTransportClosure() { |
|
|
|
this.pageCache = []; |
|
|
|
this.pageCache = []; |
|
|
|
this.pageCapabilities = []; |
|
|
|
this.pageCapabilities = []; |
|
|
|
var self = this; |
|
|
|
var self = this; |
|
|
|
this.messageHandler.send('Terminate', null, function () { |
|
|
|
this.messageHandler.sendWithPromise('Terminate', null).then(function () { |
|
|
|
FontLoader.clear(); |
|
|
|
FontLoader.clear(); |
|
|
|
if (self.worker) { |
|
|
|
if (self.worker) { |
|
|
|
self.worker.terminate(); |
|
|
|
self.worker.terminate(); |
|
|
@ -934,9 +928,9 @@ var WorkerTransport = (function WorkerTransportClosure() { |
|
|
|
this.workerReadyCapability.reject(data); |
|
|
|
this.workerReadyCapability.reject(data); |
|
|
|
}, this); |
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
|
|
messageHandler.on('PageError', function transportError(data, intent) { |
|
|
|
messageHandler.on('PageError', function transportError(data) { |
|
|
|
var page = this.pageCache[data.pageNum - 1]; |
|
|
|
var page = this.pageCache[data.pageNum - 1]; |
|
|
|
var intentState = page.intentStates[intent]; |
|
|
|
var intentState = page.intentStates[data.intent]; |
|
|
|
if (intentState.displayReadyCapability.promise) { |
|
|
|
if (intentState.displayReadyCapability.promise) { |
|
|
|
intentState.displayReadyCapability.reject(data.error); |
|
|
|
intentState.displayReadyCapability.reject(data.error); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -944,40 +938,47 @@ var WorkerTransport = (function WorkerTransportClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
}, this); |
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
|
|
messageHandler.on('JpegDecode', function(data, deferred) { |
|
|
|
messageHandler.on('JpegDecode', function(data) { |
|
|
|
var imageUrl = data[0]; |
|
|
|
var imageUrl = data[0]; |
|
|
|
var components = data[1]; |
|
|
|
var components = data[1]; |
|
|
|
if (components != 3 && components != 1) { |
|
|
|
if (components != 3 && components != 1) { |
|
|
|
error('Only 3 component or 1 component can be returned'); |
|
|
|
return Promise.reject( |
|
|
|
|
|
|
|
new Error('Only 3 component or 1 component can be returned')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var img = new Image(); |
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
img.onload = (function messageHandler_onloadClosure() { |
|
|
|
var img = new Image(); |
|
|
|
var width = img.width; |
|
|
|
img.onload = function () { |
|
|
|
var height = img.height; |
|
|
|
var width = img.width; |
|
|
|
var size = width * height; |
|
|
|
var height = img.height; |
|
|
|
var rgbaLength = size * 4; |
|
|
|
var size = width * height; |
|
|
|
var buf = new Uint8Array(size * components); |
|
|
|
var rgbaLength = size * 4; |
|
|
|
var tmpCanvas = createScratchCanvas(width, height); |
|
|
|
var buf = new Uint8Array(size * components); |
|
|
|
var tmpCtx = tmpCanvas.getContext('2d'); |
|
|
|
var tmpCanvas = createScratchCanvas(width, height); |
|
|
|
tmpCtx.drawImage(img, 0, 0); |
|
|
|
var tmpCtx = tmpCanvas.getContext('2d'); |
|
|
|
var data = tmpCtx.getImageData(0, 0, width, height).data; |
|
|
|
tmpCtx.drawImage(img, 0, 0); |
|
|
|
var i, j; |
|
|
|
var data = tmpCtx.getImageData(0, 0, width, height).data; |
|
|
|
|
|
|
|
var i, j; |
|
|
|
if (components == 3) { |
|
|
|
|
|
|
|
for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) { |
|
|
|
if (components == 3) { |
|
|
|
buf[j] = data[i]; |
|
|
|
for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) { |
|
|
|
buf[j + 1] = data[i + 1]; |
|
|
|
buf[j] = data[i]; |
|
|
|
buf[j + 2] = data[i + 2]; |
|
|
|
buf[j + 1] = data[i + 1]; |
|
|
|
} |
|
|
|
buf[j + 2] = data[i + 2]; |
|
|
|
} else if (components == 1) { |
|
|
|
} |
|
|
|
for (i = 0, j = 0; i < rgbaLength; i += 4, j++) { |
|
|
|
} else if (components == 1) { |
|
|
|
buf[j] = data[i]; |
|
|
|
for (i = 0, j = 0; i < rgbaLength; i += 4, j++) { |
|
|
|
|
|
|
|
buf[j] = data[i]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
resolve({ data: buf, width: width, height: height}); |
|
|
|
deferred.resolve({ data: buf, width: width, height: height}); |
|
|
|
}; |
|
|
|
}).bind(this); |
|
|
|
img.onerror = function () { |
|
|
|
img.src = imageUrl; |
|
|
|
reject(new Error('JpegDecode failed to load image')); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
img.src = imageUrl; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -1019,13 +1020,7 @@ var WorkerTransport = (function WorkerTransportClosure() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) { |
|
|
|
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }); |
|
|
|
this.messageHandler.send('GetPageIndex', { ref: ref }, |
|
|
|
|
|
|
|
function (pageIndex) { |
|
|
|
|
|
|
|
resolve(pageIndex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) { |
|
|
|
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) { |
|
|
@ -1034,71 +1029,43 @@ var WorkerTransport = (function WorkerTransportClosure() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getDestinations: function WorkerTransport_getDestinations() { |
|
|
|
getDestinations: function WorkerTransport_getDestinations() { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
return this.messageHandler.sendWithPromise('GetDestinations', null); |
|
|
|
this.messageHandler.send('GetDestinations', null, |
|
|
|
|
|
|
|
function transportDestinations(destinations) { |
|
|
|
|
|
|
|
resolve(destinations); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getAttachments: function WorkerTransport_getAttachments() { |
|
|
|
getAttachments: function WorkerTransport_getAttachments() { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
return this.messageHandler.sendWithPromise('GetAttachments', null); |
|
|
|
this.messageHandler.send('GetAttachments', null, |
|
|
|
|
|
|
|
function transportAttachments(attachments) { |
|
|
|
|
|
|
|
resolve(attachments); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getJavaScript: function WorkerTransport_getJavaScript() { |
|
|
|
getJavaScript: function WorkerTransport_getJavaScript() { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
return this.messageHandler.sendWithPromise('GetJavaScript', null); |
|
|
|
this.messageHandler.send('GetJavaScript', null, |
|
|
|
|
|
|
|
function transportJavaScript(js) { |
|
|
|
|
|
|
|
resolve(js); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getOutline: function WorkerTransport_getOutline() { |
|
|
|
getOutline: function WorkerTransport_getOutline() { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
return this.messageHandler.sendWithPromise('GetOutline', null); |
|
|
|
this.messageHandler.send('GetOutline', null, |
|
|
|
|
|
|
|
function transportOutline(outline) { |
|
|
|
|
|
|
|
resolve(outline); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getMetadata: function WorkerTransport_getMetadata() { |
|
|
|
getMetadata: function WorkerTransport_getMetadata() { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
return this.messageHandler.sendWithPromise('GetMetadata', null). |
|
|
|
this.messageHandler.send('GetMetadata', null, |
|
|
|
then(function transportMetadata(results) { |
|
|
|
function transportMetadata(results) { |
|
|
|
return { |
|
|
|
resolve({ |
|
|
|
info: results[0], |
|
|
|
info: results[0], |
|
|
|
metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null) |
|
|
|
metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null) |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
startCleanup: function WorkerTransport_startCleanup() { |
|
|
|
startCleanup: function WorkerTransport_startCleanup() { |
|
|
|
this.messageHandler.send('Cleanup', null, |
|
|
|
this.messageHandler.sendWithPromise('Cleanup', null). |
|
|
|
function endCleanup() { |
|
|
|
then(function endCleanup() { |
|
|
|
for (var i = 0, ii = this.pageCache.length; i < ii; i++) { |
|
|
|
for (var i = 0, ii = this.pageCache.length; i < ii; i++) { |
|
|
|
var page = this.pageCache[i]; |
|
|
|
var page = this.pageCache[i]; |
|
|
|
if (page) { |
|
|
|
if (page) { |
|
|
|
page.destroy(); |
|
|
|
page.destroy(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
this.commonObjs.clear(); |
|
|
|
} |
|
|
|
FontLoader.clear(); |
|
|
|
this.commonObjs.clear(); |
|
|
|
}.bind(this) |
|
|
|
FontLoader.clear(); |
|
|
|
); |
|
|
|
}.bind(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
return WorkerTransport; |
|
|
|
return WorkerTransport; |
|
|
|