Let the two annotation factories use static methods
This corresponds to how other factories are implemented.
This commit is contained in:
parent
af10f8b586
commit
4f02857394
@ -32,7 +32,7 @@ class AnnotationFactory {
|
||||
* @param {Object} idFactory
|
||||
* @returns {Annotation}
|
||||
*/
|
||||
create(xref, ref, pdfManager, idFactory) {
|
||||
static create(xref, ref, pdfManager, idFactory) {
|
||||
let dict = xref.fetchIfRef(ref);
|
||||
if (!isDict(dict)) {
|
||||
return;
|
||||
|
@ -316,10 +316,9 @@ var Page = (function PageClosure() {
|
||||
get annotations() {
|
||||
var annotations = [];
|
||||
var annotationRefs = this.getInheritedPageProp('Annots') || [];
|
||||
var annotationFactory = new AnnotationFactory();
|
||||
for (var i = 0, n = annotationRefs.length; i < n; ++i) {
|
||||
var annotationRef = annotationRefs[i];
|
||||
var annotation = annotationFactory.create(this.xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(this.xref, annotationRef,
|
||||
this.pdfManager,
|
||||
this.idFactory);
|
||||
if (annotation) {
|
||||
|
@ -38,7 +38,7 @@ class AnnotationElementFactory {
|
||||
* @param {AnnotationElementParameters} parameters
|
||||
* @returns {AnnotationElement}
|
||||
*/
|
||||
create(parameters) {
|
||||
static create(parameters) {
|
||||
let subtype = parameters.data.annotationType;
|
||||
|
||||
switch (subtype) {
|
||||
@ -974,14 +974,12 @@ class AnnotationLayer {
|
||||
* @memberof AnnotationLayer
|
||||
*/
|
||||
static render(parameters) {
|
||||
let annotationElementFactory = new AnnotationElementFactory();
|
||||
|
||||
for (let i = 0, ii = parameters.annotations.length; i < ii; i++) {
|
||||
let data = parameters.annotations[i];
|
||||
if (!data) {
|
||||
continue;
|
||||
}
|
||||
let element = annotationElementFactory.create({
|
||||
let element = AnnotationElementFactory.create({
|
||||
data,
|
||||
layer: parameters.div,
|
||||
page: parameters.page,
|
||||
|
@ -44,10 +44,9 @@ describe('annotation', function() {
|
||||
}
|
||||
IdFactoryMock.prototype = {};
|
||||
|
||||
var annotationFactory, pdfManagerMock, idFactoryMock;
|
||||
var pdfManagerMock, idFactoryMock;
|
||||
|
||||
beforeAll(function (done) {
|
||||
annotationFactory = new AnnotationFactory();
|
||||
pdfManagerMock = new PDFManagerMock({
|
||||
docBaseUrl: null,
|
||||
});
|
||||
@ -56,7 +55,6 @@ describe('annotation', function() {
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
annotationFactory = null;
|
||||
pdfManagerMock = null;
|
||||
idFactoryMock = null;
|
||||
});
|
||||
@ -72,7 +70,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -92,9 +90,9 @@ describe('annotation', function() {
|
||||
startObjId: 0,
|
||||
});
|
||||
|
||||
var annotation1 = annotationFactory.create(xref, annotationDict,
|
||||
var annotation1 = AnnotationFactory.create(xref, annotationDict,
|
||||
pdfManagerMock, idFactory);
|
||||
var annotation2 = annotationFactory.create(xref, annotationDict,
|
||||
var annotation2 = AnnotationFactory.create(xref, annotationDict,
|
||||
pdfManagerMock, idFactory);
|
||||
var data1 = annotation1.data, data2 = annotation2.data;
|
||||
expect(data1.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -113,7 +111,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toBeUndefined();
|
||||
@ -298,7 +296,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -326,7 +324,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -359,7 +357,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -389,7 +387,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -418,7 +416,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -450,7 +448,7 @@ describe('annotation', function() {
|
||||
docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf',
|
||||
});
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManager, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -479,7 +477,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -508,7 +506,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -548,7 +546,7 @@ describe('annotation', function() {
|
||||
docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf',
|
||||
});
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManager, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -583,7 +581,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock,
|
||||
idFactoryMock);
|
||||
var data = annotation.data;
|
||||
@ -635,7 +633,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -656,7 +654,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -679,7 +677,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, annotationRef,
|
||||
var annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -709,7 +707,7 @@ describe('annotation', function() {
|
||||
{ ref: annotationRef, data: annotationDict, }
|
||||
]);
|
||||
|
||||
let annotation = annotationFactory.create(xref, annotationRef,
|
||||
let annotation = AnnotationFactory.create(xref, annotationRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
let data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
||||
@ -742,7 +740,7 @@ describe('annotation', function() {
|
||||
{ ref: widgetRef, data: widgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, widgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, widgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -759,7 +757,7 @@ describe('annotation', function() {
|
||||
{ ref: widgetRef, data: widgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, widgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, widgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -783,7 +781,7 @@ describe('annotation', function() {
|
||||
{ ref: widgetRef, data: widgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, widgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, widgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -805,7 +803,7 @@ describe('annotation', function() {
|
||||
{ ref: widgetRef, data: widgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, widgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, widgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -837,7 +835,7 @@ describe('annotation', function() {
|
||||
{ ref: textWidgetRef, data: textWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, textWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, textWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -860,7 +858,7 @@ describe('annotation', function() {
|
||||
{ ref: textWidgetRef, data: textWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, textWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, textWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -884,7 +882,7 @@ describe('annotation', function() {
|
||||
{ ref: textWidgetRef, data: textWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, textWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, textWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -903,7 +901,7 @@ describe('annotation', function() {
|
||||
{ ref: textWidgetRef, data: textWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, textWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, textWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -920,7 +918,7 @@ describe('annotation', function() {
|
||||
{ ref: textWidgetRef, data: textWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, textWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, textWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -948,7 +946,7 @@ describe('annotation', function() {
|
||||
{ ref: textWidgetRef, data: textWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, textWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, textWidgetRef,
|
||||
pdfManagerMock,
|
||||
idFactoryMock);
|
||||
var data = annotation.data;
|
||||
@ -989,7 +987,7 @@ describe('annotation', function() {
|
||||
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, buttonWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, buttonWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1018,7 +1016,7 @@ describe('annotation', function() {
|
||||
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, buttonWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, buttonWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1044,7 +1042,7 @@ describe('annotation', function() {
|
||||
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, buttonWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, buttonWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1078,7 +1076,7 @@ describe('annotation', function() {
|
||||
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1113,7 +1111,7 @@ describe('annotation', function() {
|
||||
{ ref: optionOneRef, data: optionOneArr, },
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1145,7 +1143,7 @@ describe('annotation', function() {
|
||||
{ ref: optionBarRef, data: optionBarStr, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1173,7 +1171,7 @@ describe('annotation', function() {
|
||||
{ ref: choiceWidgetRef, data: choiceWidgetDict, },
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1191,7 +1189,7 @@ describe('annotation', function() {
|
||||
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1209,7 +1207,7 @@ describe('annotation', function() {
|
||||
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1223,7 +1221,7 @@ describe('annotation', function() {
|
||||
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1241,7 +1239,7 @@ describe('annotation', function() {
|
||||
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1261,7 +1259,7 @@ describe('annotation', function() {
|
||||
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, choiceWidgetRef,
|
||||
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
@ -1284,7 +1282,7 @@ describe('annotation', function() {
|
||||
{ ref: lineRef, data: lineDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, lineRef, pdfManagerMock,
|
||||
var annotation = AnnotationFactory.create(xref, lineRef, pdfManagerMock,
|
||||
idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.LINE);
|
||||
@ -1337,7 +1335,7 @@ describe('annotation', function() {
|
||||
fileSpecDict.assignXref(xref);
|
||||
fileAttachmentDict.assignXref(xref);
|
||||
|
||||
var annotation = annotationFactory.create(xref, fileAttachmentRef,
|
||||
var annotation = AnnotationFactory.create(xref, fileAttachmentRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.FILEATTACHMENT);
|
||||
@ -1366,7 +1364,7 @@ describe('annotation', function() {
|
||||
{ ref: popupRef, data: popupDict, }
|
||||
]);
|
||||
|
||||
var annotation = annotationFactory.create(xref, popupRef,
|
||||
var annotation = AnnotationFactory.create(xref, popupRef,
|
||||
pdfManagerMock, idFactoryMock);
|
||||
var data = annotation.data;
|
||||
expect(data.annotationType).toEqual(AnnotationType.POPUP);
|
||||
|
Loading…
Reference in New Issue
Block a user