1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Add a getDocId method to the idFactory, in Page instances, to avoid passing around PDFManager instances unnecessarily (PR 7941 follow-up)

This way we can avoid manually building a "document id" in multiple places in `evaluator.js`, and it also let's us avoid passing in an otherwise unnecessary `PDFManager` instance when creating a `PartialEvaluator`.
This commit is contained in:
Jonas Jenwald 2019-04-20 12:36:49 +02:00
parent 55d9b35d37
commit 34952b732e
7 changed files with 36 additions and 46 deletions

View file

@ -50,7 +50,7 @@ class AnnotationFactory {
if (!isDict(dict)) {
return;
}
let id = isRef(ref) ? ref.toString() : 'annot_' + idFactory.createObjId();
let id = isRef(ref) ? ref.toString() : `annot_${idFactory.createObjId()}`;
// Determine the annotation's subtype.
let subtype = dict.get('Subtype');

View file

@ -54,13 +54,15 @@ class Page {
this.evaluatorOptions = pdfManager.evaluatorOptions;
this.resourcesPromise = null;
const uniquePrefix = `p${this.pageIndex}_`;
const idCounters = {
obj: 0,
};
this.idFactory = {
createObjId() {
return uniquePrefix + (++idCounters.obj);
return `p${pageIndex}_${++idCounters.obj}`;
},
getDocId() {
return `g_${pdfManager.docId}`;
},
};
}
@ -195,7 +197,6 @@ class Page {
]);
const partialEvaluator = new PartialEvaluator({
pdfManager: this.pdfManager,
xref: this.xref,
handler,
pageIndex: this.pageIndex,
@ -270,7 +271,6 @@ class Page {
const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
return dataPromises.then(([contentStream]) => {
const partialEvaluator = new PartialEvaluator({
pdfManager: this.pdfManager,
xref: this.xref,
handler,
pageIndex: this.pageIndex,

View file

@ -61,10 +61,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
isEvalSupported: true,
};
function PartialEvaluator({ pdfManager, xref, handler, pageIndex, idFactory,
fontCache, builtInCMapCache, options = null,
function PartialEvaluator({ xref, handler, pageIndex, idFactory, fontCache,
builtInCMapCache, options = null,
pdfFunctionFactory, }) {
this.pdfManager = pdfManager;
this.xref = xref;
this.handler = handler;
this.pageIndex = pageIndex;
@ -372,13 +371,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
NativeImageDecoding.NONE : this.options.nativeImageDecoderSupport;
// If there is no imageMask, create the PDFImage and a lot
// of image processing can be done here.
let objId = 'img_' + this.idFactory.createObjId();
let objId = `img_${this.idFactory.createObjId()}`;
if (this.parsingType3Font) {
assert(nativeImageDecoderSupport === NativeImageDecoding.NONE,
'Type3 image resources should be completely decoded in the worker.');
objId = `g_${this.pdfManager.docId}_type3res_${objId}`;
objId = `${this.idFactory.getDocId()}_type3res_${objId}`;
}
if (nativeImageDecoderSupport !== NativeImageDecoding.NONE &&
@ -774,13 +773,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (!fontID) {
fontID = this.idFactory.createObjId();
}
this.fontCache.put('id_' + fontID, fontCapability.promise);
this.fontCache.put(`id_${fontID}`, fontCapability.promise);
}
assert(fontID, 'The "fontID" must be defined.');
// Keep track of each font we translated so the caller can
// load them asynchronously before calling display on a page.
font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
font.loadedName = `${this.idFactory.getDocId()}_f${fontID}`;
font.translated = fontCapability.promise;