[api-minor] Refactor/simplify the PDFObject
class
First of all, note how there's currently *two* methods for checking if a certain object exists, which seems completely unwarranted. Furthermore, the rarely used `getData` method was removed and its only callsite changed to use a combination of `PDFObjects.{has, get}` instead. Finally, the methods were rearranged slightly, to bring the most important ones (for an API user) to the top of the class.
This commit is contained in:
parent
d32321d84f
commit
60da2d882b
@ -447,8 +447,9 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||||||
element.style.display = 'table-cell';
|
element.style.display = 'table-cell';
|
||||||
|
|
||||||
let font = null;
|
let font = null;
|
||||||
if (this.data.fontRefName) {
|
if (this.data.fontRefName &&
|
||||||
font = this.page.commonObjs.getData(this.data.fontRefName);
|
this.page.commonObjs.has(this.data.fontRefName)) {
|
||||||
|
font = this.page.commonObjs.get(this.data.fontRefName);
|
||||||
}
|
}
|
||||||
this._setTextStyle(element, font);
|
this._setTextStyle(element, font);
|
||||||
}
|
}
|
||||||
|
@ -1885,7 +1885,7 @@ class WorkerTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [id, type, exportedData] = data;
|
const [id, type, exportedData] = data;
|
||||||
if (this.commonObjs.hasData(id)) {
|
if (this.commonObjs.has(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1937,7 +1937,7 @@ class WorkerTransport {
|
|||||||
|
|
||||||
const [id, pageIndex, type, imageData] = data;
|
const [id, pageIndex, type, imageData] = data;
|
||||||
const pageProxy = this.pageCache[pageIndex];
|
const pageProxy = this.pageCache[pageIndex];
|
||||||
if (pageProxy.objs.hasData(id)) {
|
if (pageProxy.objs.has(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2256,6 +2256,11 @@ class PDFObjects {
|
|||||||
return obj.data;
|
return obj.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has(objId) {
|
||||||
|
const obj = this._objs[objId];
|
||||||
|
return (obj ? obj.resolved : false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the object `objId` with optional `data`.
|
* Resolves the object `objId` with optional `data`.
|
||||||
*/
|
*/
|
||||||
@ -2267,26 +2272,6 @@ class PDFObjects {
|
|||||||
obj.capability.resolve(data);
|
obj.capability.resolve(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
isResolved(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.
|
|
||||||
*/
|
|
||||||
getData(objId) {
|
|
||||||
const obj = this._objs[objId];
|
|
||||||
if (!obj || !obj.resolved) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return obj.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this._objs = Object.create(null);
|
this._objs = Object.create(null);
|
||||||
}
|
}
|
||||||
|
@ -810,7 +810,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
|
|
||||||
// If the promise isn't resolved yet, add the continueCallback
|
// If the promise isn't resolved yet, add the continueCallback
|
||||||
// to the promise and bail out.
|
// to the promise and bail out.
|
||||||
if (!objsPool.isResolved(depObjId)) {
|
if (!objsPool.has(depObjId)) {
|
||||||
objsPool.get(depObjId, continueCallback);
|
objsPool.get(depObjId, continueCallback);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user