Skip to content

Commit

Permalink
Merge pull request #7941 from Snuffleupagus/Page-idFactory
Browse files Browse the repository at this point in the history
Replace direct lookup of `uniquePrefix`/`idCounters`, in `Page` instances, with an `idFactory` containing an `createObjId` method instead
  • Loading branch information
timvandermeij authored Jan 9, 2017
2 parents e259bc2 + 642d862 commit f828f07
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 155 deletions.
9 changes: 3 additions & 6 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
* @param {XRef} xref
* @param {Object} ref
* @param {PDFManager} pdfManager
* @param {string} uniquePrefix
* @param {Object} idCounters
* @param {Object} idFactory
* @returns {Annotation}
*/
create: function AnnotationFactory_create(xref, ref, pdfManager,
uniquePrefix, idCounters) {
create: function AnnotationFactory_create(xref, ref, pdfManager, idFactory) {
var dict = xref.fetchIfRef(ref);
if (!isDict(dict)) {
return;
}
var id = isRef(ref) ? ref.toString() :
'annot_' + (uniquePrefix || '') + (++idCounters.obj);
var id = isRef(ref) ? ref.toString() : 'annot_' + idFactory.createObjId();

// Determine the annotation's subtype.
var subtype = dict.get('Subtype');
Expand Down
23 changes: 13 additions & 10 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ var Page = (function PageClosure() {
this.xref = xref;
this.ref = ref;
this.fontCache = fontCache;
this.uniquePrefix = 'p' + this.pageIndex + '_';
this.idCounters = {
obj: 0
};
this.evaluatorOptions = pdfManager.evaluatorOptions;
this.resourcesPromise = null;

var uniquePrefix = 'p' + this.pageIndex + '_';
var idCounters = {
obj: 0,
};
this.idFactory = {
createObjId: function () {
return uniquePrefix + (++idCounters.obj);
},
};
}

Page.prototype = {
Expand Down Expand Up @@ -240,8 +246,7 @@ var Page = (function PageClosure() {

var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
handler, this.pageIndex,
this.uniquePrefix,
this.idCounters,
this.idFactory,
this.fontCache,
this.evaluatorOptions);

Expand Down Expand Up @@ -308,8 +313,7 @@ var Page = (function PageClosure() {
var contentStream = data[0];
var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
handler, self.pageIndex,
self.uniquePrefix,
self.idCounters,
self.idFactory,
self.fontCache,
self.evaluatorOptions);

Expand Down Expand Up @@ -345,8 +349,7 @@ var Page = (function PageClosure() {
var annotationRef = annotationRefs[i];
var annotation = annotationFactory.create(this.xref, annotationRef,
this.pdfManager,
this.uniquePrefix,
this.idCounters);
this.idFactory);
if (annotation) {
annotations.push(annotation);
}
Expand Down
10 changes: 4 additions & 6 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
};

function PartialEvaluator(pdfManager, xref, handler, pageIndex,
uniquePrefix, idCounters, fontCache, options) {
idFactory, fontCache, options) {
this.pdfManager = pdfManager;
this.xref = xref;
this.handler = handler;
this.pageIndex = pageIndex;
this.uniquePrefix = uniquePrefix;
this.idCounters = idCounters;
this.idFactory = idFactory;
this.fontCache = fontCache;
this.options = options || DefaultPartialEvaluatorOptions;
}
Expand Down Expand Up @@ -391,8 +390,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {

// If there is no imageMask, create the PDFImage and a lot
// of image processing can be done here.
var uniquePrefix = (this.uniquePrefix || '');
var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
var objId = 'img_' + this.idFactory.createObjId();
operatorList.addDependency(objId);
args = [objId, w, h];

Expand Down Expand Up @@ -733,7 +731,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
this.fontCache.put(fontRef, fontCapability.promise);
} else {
if (!fontID) {
fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
fontID = this.idFactory.createObjId();
}
this.fontCache.put('id_' + fontID, fontCapability.promise);
}
Expand Down
Loading

0 comments on commit f828f07

Please sign in to comment.