|
|
|
@ -15,7 +15,7 @@
@@ -15,7 +15,7 @@
|
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
/* globals NotImplementedException, MissingDataException, Promise, Stream, |
|
|
|
|
PDFDocument, ChunkedStreamManager, LegacyPromise */ |
|
|
|
|
PDFDocument, ChunkedStreamManager, createPromiseCapability */ |
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
@ -84,8 +84,8 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
@@ -84,8 +84,8 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
|
|
|
|
|
function LocalPdfManager(data, password) { |
|
|
|
|
var stream = new Stream(data); |
|
|
|
|
this.pdfDocument = new PDFDocument(this, stream, password); |
|
|
|
|
this.loadedStream = new LegacyPromise(); |
|
|
|
|
this.loadedStream.resolve(stream); |
|
|
|
|
this._loadedStreamCapability = createPromiseCapability(); |
|
|
|
|
this._loadedStreamCapability.resolve(stream); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LocalPdfManager.prototype = Object.create(BasePdfManager.prototype); |
|
|
|
@ -93,28 +93,25 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
@@ -93,28 +93,25 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
|
|
|
|
|
|
|
|
|
|
LocalPdfManager.prototype.ensure = |
|
|
|
|
function LocalPdfManager_ensure(obj, prop, args) { |
|
|
|
|
var promise = new LegacyPromise(); |
|
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
|
try { |
|
|
|
|
var value = obj[prop]; |
|
|
|
|
var result; |
|
|
|
|
if (typeof(value) === 'function') { |
|
|
|
|
if (typeof value === 'function') { |
|
|
|
|
result = value.apply(obj, args); |
|
|
|
|
} else { |
|
|
|
|
result = value; |
|
|
|
|
} |
|
|
|
|
promise.resolve(result); |
|
|
|
|
resolve(result); |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e.stack); |
|
|
|
|
promise.reject(e); |
|
|
|
|
reject(e); |
|
|
|
|
} |
|
|
|
|
return promise; |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
LocalPdfManager.prototype.requestRange = |
|
|
|
|
function LocalPdfManager_requestRange(begin, end) { |
|
|
|
|
var promise = new LegacyPromise(); |
|
|
|
|
promise.resolve(); |
|
|
|
|
return promise; |
|
|
|
|
return Promise.resolve(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
LocalPdfManager.prototype.requestLoadedStream = |
|
|
|
@ -123,7 +120,7 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
@@ -123,7 +120,7 @@ var LocalPdfManager = (function LocalPdfManagerClosure() {
|
|
|
|
|
|
|
|
|
|
LocalPdfManager.prototype.onLoadedStream = |
|
|
|
|
function LocalPdfManager_getLoadedStream() { |
|
|
|
|
return this.loadedStream; |
|
|
|
|
return this._loadedStreamCapability.promise; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
LocalPdfManager.prototype.terminate = |
|
|
|
@ -159,42 +156,39 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
@@ -159,42 +156,39 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
|
|
|
|
|
|
|
|
|
NetworkPdfManager.prototype.ensure = |
|
|
|
|
function NetworkPdfManager_ensure(obj, prop, args) { |
|
|
|
|
var promise = new LegacyPromise(); |
|
|
|
|
this.ensureHelper(promise, obj, prop, args); |
|
|
|
|
return promise; |
|
|
|
|
}; |
|
|
|
|
var pdfManager = this; |
|
|
|
|
|
|
|
|
|
NetworkPdfManager.prototype.ensureHelper = |
|
|
|
|
function NetworkPdfManager_ensureHelper(promise, obj, prop, args) { |
|
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
|
function ensureHelper() { |
|
|
|
|
try { |
|
|
|
|
var result; |
|
|
|
|
var value = obj[prop]; |
|
|
|
|
if (typeof(value) === 'function') { |
|
|
|
|
if (typeof value === 'function') { |
|
|
|
|
result = value.apply(obj, args); |
|
|
|
|
} else { |
|
|
|
|
result = value; |
|
|
|
|
} |
|
|
|
|
promise.resolve(result); |
|
|
|
|
resolve(result); |
|
|
|
|
} catch(e) { |
|
|
|
|
if (!(e instanceof MissingDataException)) { |
|
|
|
|
console.log(e.stack); |
|
|
|
|
promise.reject(e); |
|
|
|
|
reject(e); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.streamManager.requestRange(e.begin, e.end, function() { |
|
|
|
|
this.ensureHelper(promise, obj, prop, args); |
|
|
|
|
}.bind(this)); |
|
|
|
|
pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ensureHelper(); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
NetworkPdfManager.prototype.requestRange = |
|
|
|
|
function NetworkPdfManager_requestRange(begin, end) { |
|
|
|
|
var promise = new LegacyPromise(); |
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
|
this.streamManager.requestRange(begin, end, function() { |
|
|
|
|
promise.resolve(); |
|
|
|
|
resolve(); |
|
|
|
|
}); |
|
|
|
|
return promise; |
|
|
|
|
}.bind(this)); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
NetworkPdfManager.prototype.requestLoadedStream = |
|
|
|
|