mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-03 04:47:21 +02:00
Compare commits
No commits in common. "6f052312d625224173db36d3e661657a89cf1865" and "04400c588f22626987ad9a699cdacaa2dc52922c" have entirely different histories.
6f052312d6
...
04400c588f
@ -303,11 +303,6 @@ export default [
|
|||||||
selector: "NewExpression[callee.name='Name']",
|
selector: "NewExpression[callee.name='Name']",
|
||||||
message: "Use `Name.get()` rather than `new Name()`.",
|
message: "Use `Name.get()` rather than `new Name()`.",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
selector: "NewExpression[callee.name='ObjectLoader']",
|
|
||||||
message:
|
|
||||||
"Use `ObjectLoader.load()` rather than `new ObjectLoader()`.",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
selector: "NewExpression[callee.name='Ref']",
|
selector: "NewExpression[callee.name='Ref']",
|
||||||
message: "Use `Ref.get()` rather than `new Ref()`.",
|
message: "Use `Ref.get()` rather than `new Ref()`.",
|
||||||
|
|||||||
@ -1158,12 +1158,15 @@ class Annotation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadResources(keys, appearance) {
|
loadResources(keys, appearance) {
|
||||||
const resources = await appearance.dict.getAsync("Resources");
|
return appearance.dict.getAsync("Resources").then(resources => {
|
||||||
if (resources) {
|
if (!resources) {
|
||||||
await ObjectLoader.load(resources, keys, resources.xref);
|
return undefined;
|
||||||
}
|
}
|
||||||
return resources;
|
|
||||||
|
const objectLoader = new ObjectLoader(resources, keys, resources.xref);
|
||||||
|
return objectLoader.load().then(() => resources);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOperatorList(evaluator, task, intent, annotationStorage) {
|
async getOperatorList(evaluator, task, intent, annotationStorage) {
|
||||||
|
|||||||
@ -417,7 +417,8 @@ class Page {
|
|||||||
// TODO: add async `_getInheritableProperty` and remove this.
|
// TODO: add async `_getInheritableProperty` and remove this.
|
||||||
await (this.resourcesPromise ??= this.pdfManager.ensure(this, "resources"));
|
await (this.resourcesPromise ??= this.pdfManager.ensure(this, "resources"));
|
||||||
|
|
||||||
await ObjectLoader.load(this.resources, keys, this.xref);
|
const objectLoader = new ObjectLoader(this.resources, keys, this.xref);
|
||||||
|
await objectLoader.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
async #getMergedResources(streamDict, keys) {
|
async #getMergedResources(streamDict, keys) {
|
||||||
@ -429,7 +430,8 @@ class Page {
|
|||||||
if (!(localResources instanceof Dict && localResources.size)) {
|
if (!(localResources instanceof Dict && localResources.size)) {
|
||||||
return this.resources;
|
return this.resources;
|
||||||
}
|
}
|
||||||
await ObjectLoader.load(localResources, keys, this.xref);
|
const objectLoader = new ObjectLoader(localResources, keys, this.xref);
|
||||||
|
await objectLoader.load();
|
||||||
|
|
||||||
return Dict.merge({
|
return Dict.merge({
|
||||||
xref: this.xref,
|
xref: this.xref,
|
||||||
@ -1252,7 +1254,8 @@ class PDFDocument {
|
|||||||
if (!(resources instanceof Dict)) {
|
if (!(resources instanceof Dict)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await ObjectLoader.load(resources, ["Font"], this.xref);
|
const objectLoader = new ObjectLoader(resources, ["Font"], this.xref);
|
||||||
|
await objectLoader.load();
|
||||||
|
|
||||||
const fontRes = resources.get("Font");
|
const fontRes = resources.get("Font");
|
||||||
if (!(fontRes instanceof Dict)) {
|
if (!(fontRes instanceof Dict)) {
|
||||||
|
|||||||
@ -54,16 +54,21 @@ function addChildren(node, nodesToVisit) {
|
|||||||
* entire PDF document object graph to be traversed.
|
* entire PDF document object graph to be traversed.
|
||||||
*/
|
*/
|
||||||
class ObjectLoader {
|
class ObjectLoader {
|
||||||
refSet = new RefSet();
|
|
||||||
|
|
||||||
constructor(dict, keys, xref) {
|
constructor(dict, keys, xref) {
|
||||||
this.dict = dict;
|
this.dict = dict;
|
||||||
this.keys = keys;
|
this.keys = keys;
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
|
this.refSet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
|
// Don't walk the graph if all the data is already loaded.
|
||||||
|
if (this.xref.stream.isDataLoaded) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const { keys, dict } = this;
|
const { keys, dict } = this;
|
||||||
|
this.refSet = new RefSet();
|
||||||
// Setup the initial nodes to visit.
|
// Setup the initial nodes to visit.
|
||||||
const nodesToVisit = [];
|
const nodesToVisit = [];
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
@ -73,12 +78,10 @@ class ObjectLoader {
|
|||||||
nodesToVisit.push(rawValue);
|
nodesToVisit.push(rawValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.#walk(nodesToVisit);
|
return this._walk(nodesToVisit);
|
||||||
|
|
||||||
this.refSet = null; // Everything is loaded, clear the cache.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async #walk(nodesToVisit) {
|
async _walk(nodesToVisit) {
|
||||||
const nodesToRevisit = [];
|
const nodesToRevisit = [];
|
||||||
const pendingRequests = [];
|
const pendingRequests = [];
|
||||||
// DFS walk of the object graph.
|
// DFS walk of the object graph.
|
||||||
@ -96,10 +99,11 @@ class ObjectLoader {
|
|||||||
currentNode = this.xref.fetch(currentNode);
|
currentNode = this.xref.fetch(currentNode);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (!(ex instanceof MissingDataException)) {
|
if (!(ex instanceof MissingDataException)) {
|
||||||
warn(`ObjectLoader.#walk - requesting all data: "${ex}".`);
|
warn(`ObjectLoader._walk - requesting all data: "${ex}".`);
|
||||||
|
this.refSet = null;
|
||||||
|
|
||||||
await this.xref.stream.manager.requestAllChunks();
|
const { manager } = this.xref.stream;
|
||||||
return;
|
return manager.requestAllChunks();
|
||||||
}
|
}
|
||||||
nodesToRevisit.push(currentNode);
|
nodesToRevisit.push(currentNode);
|
||||||
pendingRequests.push({ begin: ex.begin, end: ex.end });
|
pendingRequests.push({ begin: ex.begin, end: ex.end });
|
||||||
@ -135,18 +139,11 @@ class ObjectLoader {
|
|||||||
this.refSet.remove(node);
|
this.refSet.remove(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.#walk(nodesToRevisit);
|
return this._walk(nodesToRevisit);
|
||||||
}
|
}
|
||||||
}
|
// Everything is loaded.
|
||||||
|
this.refSet = null;
|
||||||
static async load(obj, keys, xref) {
|
return undefined;
|
||||||
// Don't walk the graph if all the data is already loaded.
|
|
||||||
if (xref.stream.isDataLoaded) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
|
||||||
const objLoader = new ObjectLoader(obj, keys, xref);
|
|
||||||
await objLoader.load();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user