Merge pull request #7570 from Snuffleupagus/issue-7569
Create a fallback annotation `id` for entries in `Annots` dictionaries that are not indirect objects (issue 7569)
This commit is contained in:
commit
f520616e00
@ -49,6 +49,7 @@ var warn = sharedUtil.warn;
|
|||||||
var Dict = corePrimitives.Dict;
|
var Dict = corePrimitives.Dict;
|
||||||
var isDict = corePrimitives.isDict;
|
var isDict = corePrimitives.isDict;
|
||||||
var isName = corePrimitives.isName;
|
var isName = corePrimitives.isName;
|
||||||
|
var isRef = corePrimitives.isRef;
|
||||||
var Stream = coreStream.Stream;
|
var Stream = coreStream.Stream;
|
||||||
var ColorSpace = coreColorSpace.ColorSpace;
|
var ColorSpace = coreColorSpace.ColorSpace;
|
||||||
var ObjectLoader = coreObj.ObjectLoader;
|
var ObjectLoader = coreObj.ObjectLoader;
|
||||||
@ -66,11 +67,14 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
|
|||||||
* @param {Object} ref
|
* @param {Object} ref
|
||||||
* @returns {Annotation}
|
* @returns {Annotation}
|
||||||
*/
|
*/
|
||||||
create: function AnnotationFactory_create(xref, ref) {
|
create: function AnnotationFactory_create(xref, ref,
|
||||||
|
uniquePrefix, idCounters) {
|
||||||
var dict = xref.fetchIfRef(ref);
|
var dict = xref.fetchIfRef(ref);
|
||||||
if (!isDict(dict)) {
|
if (!isDict(dict)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var id = isRef(ref) ? ref.toString() :
|
||||||
|
'annot_' + (uniquePrefix || '') + (++idCounters.obj);
|
||||||
|
|
||||||
// Determine the annotation's subtype.
|
// Determine the annotation's subtype.
|
||||||
var subtype = dict.get('Subtype');
|
var subtype = dict.get('Subtype');
|
||||||
@ -80,8 +84,9 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
|
|||||||
var parameters = {
|
var parameters = {
|
||||||
xref: xref,
|
xref: xref,
|
||||||
dict: dict,
|
dict: dict,
|
||||||
ref: ref,
|
ref: isRef(ref) ? ref : null,
|
||||||
subtype: subtype,
|
subtype: subtype,
|
||||||
|
id: id,
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (subtype) {
|
switch (subtype) {
|
||||||
@ -185,7 +190,7 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
|
|
||||||
// Expose public properties using a data object.
|
// Expose public properties using a data object.
|
||||||
this.data = {};
|
this.data = {};
|
||||||
this.data.id = params.ref.toString();
|
this.data.id = params.id;
|
||||||
this.data.subtype = params.subtype;
|
this.data.subtype = params.subtype;
|
||||||
this.data.annotationFlags = this.flags;
|
this.data.annotationFlags = this.flags;
|
||||||
this.data.rect = this.rectangle;
|
this.data.rect = this.rectangle;
|
||||||
|
@ -76,6 +76,7 @@ var Page = (function PageClosure() {
|
|||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
this.fontCache = fontCache;
|
this.fontCache = fontCache;
|
||||||
|
this.uniquePrefix = 'p' + this.pageIndex + '_';
|
||||||
this.idCounters = {
|
this.idCounters = {
|
||||||
obj: 0
|
obj: 0
|
||||||
};
|
};
|
||||||
@ -223,7 +224,7 @@ var Page = (function PageClosure() {
|
|||||||
|
|
||||||
var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
|
var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
|
||||||
handler, this.pageIndex,
|
handler, this.pageIndex,
|
||||||
'p' + this.pageIndex + '_',
|
this.uniquePrefix,
|
||||||
this.idCounters,
|
this.idCounters,
|
||||||
this.fontCache,
|
this.fontCache,
|
||||||
this.evaluatorOptions);
|
this.evaluatorOptions);
|
||||||
@ -290,7 +291,7 @@ var Page = (function PageClosure() {
|
|||||||
var contentStream = data[0];
|
var contentStream = data[0];
|
||||||
var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
|
var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
|
||||||
handler, self.pageIndex,
|
handler, self.pageIndex,
|
||||||
'p' + self.pageIndex + '_',
|
self.uniquePrefix,
|
||||||
self.idCounters,
|
self.idCounters,
|
||||||
self.fontCache,
|
self.fontCache,
|
||||||
self.evaluatorOptions);
|
self.evaluatorOptions);
|
||||||
@ -325,7 +326,9 @@ var Page = (function PageClosure() {
|
|||||||
var annotationFactory = new AnnotationFactory();
|
var annotationFactory = new AnnotationFactory();
|
||||||
for (var i = 0, n = annotationRefs.length; i < n; ++i) {
|
for (var i = 0, n = annotationRefs.length; i < n; ++i) {
|
||||||
var annotationRef = annotationRefs[i];
|
var annotationRef = annotationRefs[i];
|
||||||
var annotation = annotationFactory.create(this.xref, annotationRef);
|
var annotation = annotationFactory.create(this.xref, annotationRef,
|
||||||
|
this.uniquePrefix,
|
||||||
|
this.idCounters);
|
||||||
if (annotation) {
|
if (annotation) {
|
||||||
annotations.push(annotation);
|
annotations.push(annotation);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,29 @@
|
|||||||
/* globals expect, it, describe, Dict, Name, Annotation, AnnotationBorderStyle,
|
/* globals expect, it, describe, Dict, Name, Annotation, AnnotationBorderStyle,
|
||||||
AnnotationBorderStyleType, AnnotationType, AnnotationFlag, PDFJS,
|
AnnotationBorderStyleType, AnnotationType, AnnotationFlag, PDFJS,
|
||||||
beforeEach, afterEach, stringToBytes, AnnotationFactory, Ref,
|
beforeEach, afterEach, stringToBytes, AnnotationFactory, Ref, isRef,
|
||||||
beforeAll, afterAll */
|
beforeAll, afterAll */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('Annotation layer', function() {
|
describe('Annotation layer', function() {
|
||||||
function XrefMock(queue) {
|
function XRefMock(array) {
|
||||||
this.queue = queue || [];
|
this.map = Object.create(null);
|
||||||
}
|
for (var elem in array) {
|
||||||
XrefMock.prototype = {
|
var obj = array[elem];
|
||||||
fetchIfRef: function() {
|
var ref = obj.ref, data = obj.data;
|
||||||
return this.queue.shift();
|
this.map[ref.toString()] = data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
XRefMock.prototype = {
|
||||||
|
fetch: function (ref) {
|
||||||
|
return this.map[ref.toString()];
|
||||||
|
},
|
||||||
|
fetchIfRef: function (obj) {
|
||||||
|
if (!isRef(obj)) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
return this.fetch(obj);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var annotationFactory;
|
var annotationFactory;
|
||||||
@ -27,14 +38,54 @@ describe('Annotation layer', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('AnnotationFactory', function () {
|
describe('AnnotationFactory', function () {
|
||||||
|
it('should get id for annotation', function () {
|
||||||
|
var annotationDict = new Dict();
|
||||||
|
annotationDict.set('Type', Name.get('Annot'));
|
||||||
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
|
|
||||||
|
var annotationRef = new Ref(10, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
|
var data = annotation.data;
|
||||||
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
|
expect(data.id).toEqual('10R');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle, and get fallback id\'s for, annotations that are not ' +
|
||||||
|
'indirect objects (issue 7569)', function () {
|
||||||
|
var annotationDict = new Dict();
|
||||||
|
annotationDict.set('Type', Name.get('Annot'));
|
||||||
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
|
|
||||||
|
var xref = new XRefMock();
|
||||||
|
var uniquePrefix = 'p0_', idCounters = { obj: 0, };
|
||||||
|
|
||||||
|
var annotation1 = annotationFactory.create(xref, annotationDict,
|
||||||
|
uniquePrefix, idCounters);
|
||||||
|
var annotation2 = annotationFactory.create(xref, annotationDict,
|
||||||
|
uniquePrefix, idCounters);
|
||||||
|
var data1 = annotation1.data, data2 = annotation2.data;
|
||||||
|
expect(data1.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
expect(data2.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
|
expect(data1.id).toEqual('annot_p0_1');
|
||||||
|
expect(data2.id).toEqual('annot_p0_2');
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle missing /Subtype', function () {
|
it('should handle missing /Subtype', function () {
|
||||||
var annotationDict = new Dict();
|
var annotationDict = new Dict();
|
||||||
annotationDict.set('Type', Name.get('Annot'));
|
annotationDict.set('Type', Name.get('Annot'));
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(1, 0);
|
var annotationRef = new Ref(1, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toBeUndefined();
|
expect(data.annotationType).toBeUndefined();
|
||||||
});
|
});
|
||||||
@ -213,10 +264,12 @@ describe('Annotation layer', function() {
|
|||||||
annotationDict.set('Subtype', Name.get('Link'));
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
annotationDict.set('A', actionDict);
|
annotationDict.set('A', actionDict);
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(820, 0);
|
var annotationRef = new Ref(820, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
@ -236,10 +289,12 @@ describe('Annotation layer', function() {
|
|||||||
annotationDict.set('Subtype', Name.get('Link'));
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
annotationDict.set('A', actionDict);
|
annotationDict.set('A', actionDict);
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(353, 0);
|
var annotationRef = new Ref(353, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
@ -258,10 +313,12 @@ describe('Annotation layer', function() {
|
|||||||
annotationDict.set('Subtype', Name.get('Link'));
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
annotationDict.set('A', actionDict);
|
annotationDict.set('A', actionDict);
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(798, 0);
|
var annotationRef = new Ref(798, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
@ -283,10 +340,12 @@ describe('Annotation layer', function() {
|
|||||||
annotationDict.set('Subtype', Name.get('Link'));
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
annotationDict.set('A', actionDict);
|
annotationDict.set('A', actionDict);
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(489, 0);
|
var annotationRef = new Ref(489, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
@ -308,10 +367,12 @@ describe('Annotation layer', function() {
|
|||||||
annotationDict.set('Subtype', Name.get('Link'));
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
annotationDict.set('A', actionDict);
|
annotationDict.set('A', actionDict);
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(495, 0);
|
var annotationRef = new Ref(495, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
@ -333,10 +394,12 @@ describe('Annotation layer', function() {
|
|||||||
annotationDict.set('Subtype', Name.get('Link'));
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
annotationDict.set('A', actionDict);
|
annotationDict.set('A', actionDict);
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(489, 0);
|
var annotationRef = new Ref(489, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
@ -357,10 +420,12 @@ describe('Annotation layer', function() {
|
|||||||
annotationDict.set('Subtype', Name.get('Link'));
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
annotationDict.set('A', actionDict);
|
annotationDict.set('A', actionDict);
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(12, 0);
|
var annotationRef = new Ref(12, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
@ -374,10 +439,12 @@ describe('Annotation layer', function() {
|
|||||||
annotationDict.set('Subtype', Name.get('Link'));
|
annotationDict.set('Subtype', Name.get('Link'));
|
||||||
annotationDict.set('Dest', Name.get('LI0'));
|
annotationDict.set('Dest', Name.get('LI0'));
|
||||||
|
|
||||||
var xrefMock = new XrefMock([annotationDict]);
|
|
||||||
var annotationRef = new Ref(583, 0);
|
var annotationRef = new Ref(583, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: annotationRef, data: annotationDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var annotation = annotationFactory.create(xrefMock, annotationRef);
|
var annotation = annotationFactory.create(xref, annotationRef);
|
||||||
var data = annotation.data;
|
var data = annotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||||
|
|
||||||
@ -431,10 +498,12 @@ describe('Annotation layer', function() {
|
|||||||
popupDict.set('F', 25); // not viewable
|
popupDict.set('F', 25); // not viewable
|
||||||
popupDict.set('Parent', parentDict);
|
popupDict.set('Parent', parentDict);
|
||||||
|
|
||||||
var xrefMock = new XrefMock([popupDict]);
|
|
||||||
var popupRef = new Ref(13, 0);
|
var popupRef = new Ref(13, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: popupRef, data: popupDict, }
|
||||||
|
]);
|
||||||
|
|
||||||
var popupAnnotation = annotationFactory.create(xrefMock, popupRef);
|
var popupAnnotation = annotationFactory.create(xref, popupRef);
|
||||||
var data = popupAnnotation.data;
|
var data = popupAnnotation.data;
|
||||||
expect(data.annotationType).toEqual(AnnotationType.POPUP);
|
expect(data.annotationType).toEqual(AnnotationType.POPUP);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user