diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 27113f8182777a..0b47488b6cb985 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -448,7 +448,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { let font = null; if (this.data.fontRefName) { - font = this.page.commonObjs.getData(this.data.fontRefName); + font = this.page.commonObjs.getSafely(this.data.fontRefName); } this._setTextStyle(element, font); } diff --git a/src/display/api.js b/src/display/api.js index 784fc30ff089dd..849c567dda622e 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1885,7 +1885,7 @@ class WorkerTransport { } const [id, type, exportedData] = data; - if (this.commonObjs.hasData(id)) { + if (this.commonObjs.has(id)) { return; } @@ -1937,7 +1937,7 @@ class WorkerTransport { const [id, pageIndex, type, imageData] = data; const pageProxy = this.pageCache[pageIndex]; - if (pageProxy.objs.hasData(id)) { + if (pageProxy.objs.has(id)) { return; } @@ -2257,34 +2257,31 @@ class PDFObjects { } /** - * Resolves the object `objId` with optional `data`. + * Returns the data of `objId` if the object exists, null otherwise. */ - resolve(objId, data) { - const obj = this._ensureObj(objId); - - obj.resolved = true; - obj.data = data; - obj.capability.resolve(data); + getSafely(objId) { + try { + return this.get(objId); + } catch (ex) { + warn(`PDFObjects.getSafely: "${ex && ex.message}".`); + } + return null; } - isResolved(objId) { + has(objId) { const obj = this._objs[objId]; return (obj ? obj.resolved : false); } - hasData(objId) { - return this.isResolved(objId); - } - /** - * Returns the data of `objId` if the object exists, null otherwise. + * Resolves the object `objId` with optional `data`. */ - getData(objId) { - const obj = this._objs[objId]; - if (!obj || !obj.resolved) { - return null; - } - return obj.data; + resolve(objId, data) { + const obj = this._ensureObj(objId); + + obj.resolved = true; + obj.data = data; + obj.capability.resolve(data); } clear() { diff --git a/src/display/canvas.js b/src/display/canvas.js index 2ea4ec31a2c2cc..af39bf7636bda9 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -810,7 +810,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { // If the promise isn't resolved yet, add the continueCallback // to the promise and bail out. - if (!objsPool.isResolved(depObjId)) { + if (!objsPool.has(depObjId)) { objsPool.get(depObjId, continueCallback); return i; }