Merge pull request #7941 from Snuffleupagus/Page-idFactory

Replace direct lookup of `uniquePrefix`/`idCounters`, in `Page` instances, with an `idFactory` containing an `createObjId` method instead
This commit is contained in:
Tim van der Meij 2017-01-10 00:25:48 +01:00 committed by GitHub
commit f828f07ccd
7 changed files with 252 additions and 155 deletions

View File

@ -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');

View File

@ -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 = {
@ -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);
@ -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);
@ -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);
}

View File

@ -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;
}
@ -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];
@ -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);
}

View File

@ -17,21 +17,19 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/annotation_layer_spec', ['exports',
'pdfjs/core/primitives', 'pdfjs/core/annotation',
'pdfjs/core/stream', 'pdfjs/core/parser',
'pdfjs/shared/util', 'pdfjs/display/global'], factory);
'pdfjs/core/primitives', 'pdfjs/core/annotation', 'pdfjs/core/stream',
'pdfjs/core/parser', 'pdfjs/shared/util', 'pdfjs/display/global'],
factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/core/primitives.js'),
require('../../src/core/annotation.js'),
require('../../src/core/stream.js'),
require('../../src/core/parser.js'),
require('../../src/shared/util.js'),
require('../../src/display/global.js'));
require('../../src/core/annotation.js'),
require('../../src/core/stream.js'), require('../../src/core/parser.js'),
require('../../src/shared/util.js'),
require('../../src/display/global.js'));
} else {
factory((root.pdfjsTestUnitAnnotationLayerSpec = {}),
root.pdfjsCorePrimitives, root.pdfjsCoreAnnotation,
root.pdfjsCoreStream, root.pdfjsCoreParser,
root.pdfjsSharedUtil, root.pdfjsDisplayGlobal);
root.pdfjsCorePrimitives, root.pdfjsCoreAnnotation, root.pdfjsCoreStream,
root.pdfjsCoreParser, root.pdfjsSharedUtil, root.pdfjsDisplayGlobal);
}
}(this, function (exports, corePrimitives, coreAnnotation, coreStream,
coreParser, sharedUtil, displayGlobal) {
@ -80,19 +78,34 @@ describe('Annotation layer', function() {
}
PDFManagerMock.prototype = {};
var annotationFactory, pdfManagerMock;
function IdFactoryMock(params) {
var uniquePrefix = params.prefix || 'p0_';
var idCounters = {
obj: params.startObjId || 0,
};
return {
createObjId: function () {
return uniquePrefix + (++idCounters.obj);
},
};
}
IdFactoryMock.prototype = {};
var annotationFactory, pdfManagerMock, idFactoryMock;
beforeAll(function (done) {
annotationFactory = new AnnotationFactory();
pdfManagerMock = new PDFManagerMock({
docBaseUrl: null,
});
idFactoryMock = new IdFactoryMock({ });
done();
});
afterAll(function () {
annotationFactory = null;
pdfManagerMock = null;
idFactoryMock = null;
});
describe('AnnotationFactory', function () {
@ -107,7 +120,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -121,14 +134,15 @@ describe('Annotation layer', function() {
annotationDict.set('Subtype', Name.get('Link'));
var xref = new XRefMock();
var uniquePrefix = 'p0_', idCounters = { obj: 0, };
var idFactory = new IdFactoryMock({
prefix: 'p0_',
startObjId: 0,
});
var annotation1 = annotationFactory.create(xref, annotationDict,
pdfManagerMock,
uniquePrefix, idCounters);
pdfManagerMock, idFactory);
var annotation2 = annotationFactory.create(xref, annotationDict,
pdfManagerMock,
uniquePrefix, idCounters);
pdfManagerMock, idFactory);
var data1 = annotation1.data, data2 = annotation2.data;
expect(data1.annotationType).toEqual(AnnotationType.LINK);
expect(data2.annotationType).toEqual(AnnotationType.LINK);
@ -147,7 +161,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toBeUndefined();
});
@ -332,7 +346,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -360,7 +374,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -393,7 +407,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -423,7 +437,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -452,7 +466,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -484,7 +498,7 @@ describe('Annotation layer', function() {
});
var annotation = annotationFactory.create(xref, annotationRef,
pdfManager);
pdfManager, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -513,7 +527,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -543,7 +557,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -583,7 +597,7 @@ describe('Annotation layer', function() {
});
var annotation = annotationFactory.create(xref, annotationRef,
pdfManager);
pdfManager, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -617,7 +631,8 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock,
idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -665,7 +680,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -686,7 +701,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -709,7 +724,7 @@ describe('Annotation layer', function() {
]);
var annotation = annotationFactory.create(xref, annotationRef,
pdfManagerMock);
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -741,10 +756,11 @@ describe('Annotation layer', function() {
{ ref: widgetRef, data: widgetDict, }
]);
var widgetAnnotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock);
var data = widgetAnnotation.data;
var annotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldName).toEqual('');
});
@ -757,10 +773,11 @@ describe('Annotation layer', function() {
{ ref: widgetRef, data: widgetDict, }
]);
var widgetAnnotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock);
var data = widgetAnnotation.data;
var annotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldName).toEqual('foo');
});
@ -780,10 +797,11 @@ describe('Annotation layer', function() {
{ ref: widgetRef, data: widgetDict, }
]);
var widgetAnnotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock);
var data = widgetAnnotation.data;
var annotation = annotationFactory.create(xref, widgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldName).toEqual('foo.bar.baz');
});
});
@ -811,13 +829,16 @@ describe('Annotation layer', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock);
expect(textWidgetAnnotation.data.textAlignment).toEqual(null);
expect(textWidgetAnnotation.data.maxLen).toEqual(null);
expect(textWidgetAnnotation.data.readOnly).toEqual(false);
expect(textWidgetAnnotation.data.multiLine).toEqual(false);
expect(textWidgetAnnotation.data.comb).toEqual(false);
var annotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.textAlignment).toEqual(null);
expect(data.maxLen).toEqual(null);
expect(data.readOnly).toEqual(false);
expect(data.multiLine).toEqual(false);
expect(data.comb).toEqual(false);
});
it('should not set invalid text alignment, maximum length and flags',
@ -831,13 +852,16 @@ describe('Annotation layer', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock);
expect(textWidgetAnnotation.data.textAlignment).toEqual(null);
expect(textWidgetAnnotation.data.maxLen).toEqual(null);
expect(textWidgetAnnotation.data.readOnly).toEqual(false);
expect(textWidgetAnnotation.data.multiLine).toEqual(false);
expect(textWidgetAnnotation.data.comb).toEqual(false);
var annotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.textAlignment).toEqual(null);
expect(data.maxLen).toEqual(null);
expect(data.readOnly).toEqual(false);
expect(data.multiLine).toEqual(false);
expect(data.comb).toEqual(false);
});
it('should set valid text alignment, maximum length and flags',
@ -852,12 +876,15 @@ describe('Annotation layer', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock);
expect(textWidgetAnnotation.data.textAlignment).toEqual(1);
expect(textWidgetAnnotation.data.maxLen).toEqual(20);
expect(textWidgetAnnotation.data.readOnly).toEqual(true);
expect(textWidgetAnnotation.data.multiLine).toEqual(true);
var annotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.textAlignment).toEqual(1);
expect(data.maxLen).toEqual(20);
expect(data.readOnly).toEqual(true);
expect(data.multiLine).toEqual(true);
});
it('should reject comb fields without a maximum length', function() {
@ -868,9 +895,12 @@ describe('Annotation layer', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock);
expect(textWidgetAnnotation.data.comb).toEqual(false);
var annotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.comb).toEqual(false);
});
it('should accept comb fields with a maximum length', function() {
@ -882,9 +912,12 @@ describe('Annotation layer', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock);
expect(textWidgetAnnotation.data.comb).toEqual(true);
var annotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.comb).toEqual(true);
});
it('should only accept comb fields when the flags are valid', function() {
@ -907,10 +940,14 @@ describe('Annotation layer', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var textWidgetAnnotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock);
var annotation = annotationFactory.create(xref, textWidgetRef,
pdfManagerMock,
idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
var valid = (invalidFieldFlags.length === 0);
expect(textWidgetAnnotation.data.comb).toEqual(valid);
expect(data.comb).toEqual(valid);
// Remove the last invalid flag for the next iteration.
if (!valid) {
@ -944,11 +981,14 @@ describe('Annotation layer', function() {
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
]);
var buttonWidgetAnnotation =
annotationFactory.create(xref, buttonWidgetRef);
expect(buttonWidgetAnnotation.data.checkBox).toEqual(true);
expect(buttonWidgetAnnotation.data.fieldValue).toEqual('1');
expect(buttonWidgetAnnotation.data.radioButton).toEqual(false);
var annotation = annotationFactory.create(xref, buttonWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(true);
expect(data.fieldValue).toEqual('1');
expect(data.radioButton).toEqual(false);
});
it('should handle radio buttons', function() {
@ -970,12 +1010,15 @@ describe('Annotation layer', function() {
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
]);
var buttonWidgetAnnotation =
annotationFactory.create(xref, buttonWidgetRef);
expect(buttonWidgetAnnotation.data.checkBox).toEqual(false);
expect(buttonWidgetAnnotation.data.radioButton).toEqual(true);
expect(buttonWidgetAnnotation.data.fieldValue).toEqual('1');
expect(buttonWidgetAnnotation.data.buttonValue).toEqual('2');
var annotation = annotationFactory.create(xref, buttonWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(false);
expect(data.radioButton).toEqual(true);
expect(data.fieldValue).toEqual('1');
expect(data.buttonValue).toEqual('2');
});
});
@ -1001,11 +1044,11 @@ describe('Annotation layer', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var choiceWidgetAnnotation = annotationFactory.create(xref,
choiceWidgetRef,
pdfManagerMock);
var data = choiceWidgetAnnotation.data;
var annotation = annotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.options).toEqual([]);
});
@ -1036,11 +1079,11 @@ describe('Annotation layer', function() {
{ ref: optionOneRef, data: optionOneArr, },
]);
var choiceWidgetAnnotation = annotationFactory.create(xref,
choiceWidgetRef,
pdfManagerMock);
var data = choiceWidgetAnnotation.data;
var annotation = annotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.options).toEqual(expected);
});
@ -1068,11 +1111,11 @@ describe('Annotation layer', function() {
{ ref: optionBarRef, data: optionBarStr, }
]);
var choiceWidgetAnnotation = annotationFactory.create(xref,
choiceWidgetRef,
pdfManagerMock);
var data = choiceWidgetAnnotation.data;
var annotation = annotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.options).toEqual(expected);
});
@ -1086,11 +1129,11 @@ describe('Annotation layer', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var choiceWidgetAnnotation = annotationFactory.create(xref,
choiceWidgetRef,
pdfManagerMock);
var data = choiceWidgetAnnotation.data;
var annotation = annotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldValue).toEqual(fieldValue);
});
@ -1104,11 +1147,11 @@ describe('Annotation layer', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var choiceWidgetAnnotation = annotationFactory.create(xref,
choiceWidgetRef,
pdfManagerMock);
var data = choiceWidgetAnnotation.data;
var annotation = annotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.fieldValue).toEqual([fieldValue]);
});
@ -1118,11 +1161,11 @@ describe('Annotation layer', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var choiceWidgetAnnotation = annotationFactory.create(xref,
choiceWidgetRef,
pdfManagerMock);
var data = choiceWidgetAnnotation.data;
var annotation = annotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.readOnly).toEqual(false);
expect(data.combo).toEqual(false);
expect(data.multiSelect).toEqual(false);
@ -1136,11 +1179,11 @@ describe('Annotation layer', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var choiceWidgetAnnotation = annotationFactory.create(xref,
choiceWidgetRef,
pdfManagerMock);
var data = choiceWidgetAnnotation.data;
var annotation = annotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.readOnly).toEqual(false);
expect(data.combo).toEqual(false);
expect(data.multiSelect).toEqual(false);
@ -1156,11 +1199,11 @@ describe('Annotation layer', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var choiceWidgetAnnotation = annotationFactory.create(xref,
choiceWidgetRef,
pdfManagerMock);
var data = choiceWidgetAnnotation.data;
var annotation = annotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.readOnly).toEqual(true);
expect(data.combo).toEqual(true);
expect(data.multiSelect).toEqual(true);
@ -1217,15 +1260,15 @@ describe('Annotation layer', function() {
{ ref: popupRef, data: popupDict, }
]);
var popupAnnotation = annotationFactory.create(xref, popupRef,
pdfManagerMock);
var data = popupAnnotation.data;
var annotation = annotationFactory.create(xref, popupRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.POPUP);
// Should not modify the `annotationFlags` returned e.g. through the API.
expect(data.annotationFlags).toEqual(25);
// The Popup should inherit the `viewable` property of the parent.
expect(popupAnnotation.viewable).toEqual(true);
expect(annotation.viewable).toEqual(true);
});
});
});

View File

@ -3,6 +3,7 @@
"spec_files": [
"cff_parser_spec.js",
"crypto_spec.js",
"document_spec.js",
"dom_utils_spec.js",
"evaluator_spec.js",
"fonts_spec.js",

View File

@ -0,0 +1,56 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-test/unit/document_spec', ['exports', 'pdfjs/core/document'],
factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../../src/core/document.js'));
} else {
factory((root.pdfjsTestUnitDocumentSpec = {}),
root.pdfjsCoreDocument);
}
}(this, function (exports, coreDocument) {
var Page = coreDocument.Page;
describe('document', function () {
describe('Page', function () {
it('should create correct objId using the idFactory', function () {
var page1 = new Page(/* pdfManager = */ { }, /* xref = */ null,
/* pageIndex = */ 0,
/* pageDict = */ null, /* ref = */ null,
/* fontCache = */ null);
var page2 = new Page(/* pdfManager = */ { }, /* xref = */ null,
/* pageIndex = */ 1,
/* pageDict = */ null, /* ref = */ null,
/* fontCache = */ null);
var idFactory1 = page1.idFactory, idFactory2 = page2.idFactory;
expect(idFactory1.createObjId()).toEqual('p0_1');
expect(idFactory1.createObjId()).toEqual('p0_2');
expect(idFactory2.createObjId()).toEqual('p1_1');
expect(idFactory2.createObjId()).toEqual('p1_2');
expect(idFactory1.createObjId()).toEqual('p0_3');
expect(idFactory1.createObjId()).toEqual('p0_4');
});
});
});
}));

View File

@ -48,23 +48,22 @@ function initializePDFJS(callback) {
require(['pdfjs/display/global', 'pdfjs-test/unit/annotation_layer_spec',
'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/cff_parser_spec',
'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/crypto_spec',
'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec',
'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec',
'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec',
'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec',
'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec',
'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec',
'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec'],
function (displayGlobal, testUnitAnnotationLayerSpec,
testUnitApiSpec, testUnitCFFParserSpec,
testUnitCMapSpec, testUnitCryptoSpec,
testUnitDOMUtilsSpec, testUnitEvaluatorSpec,
testUnitFontsSpec, testUnitFunctionSpec,
testUnitMetadataSpec, testUnitMurmurHash3Spec,
testUnitNetworkSpec, testUnitParserSpec,
'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec',
'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec',
'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/metadata_spec',
'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec',
'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/primitives_spec',
'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec',
'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec',
'pdfjs-test/unit/util_spec'],
function (displayGlobal, testUnitAnnotationLayerSpec, testUnitApiSpec,
testUnitCFFParserSpec, testUnitCMapSpec, testUnitCryptoSpec,
testUnitDocumentSpec, testUnitDOMUtilsSpec, testUnitEvaluatorSpec,
testUnitFontsSpec, testUnitFunctionSpec, testUnitMetadataSpec,
testUnitMurmurHash3Spec, testUnitNetworkSpec, testUnitParserSpec,
testUnitPrimitivesSpec, testUnitStreamSpec,
testUnitType1ParserSpec, testUnitUiUtilsSpec,
testUnitUnicodeSpec, testUnitUtilSpec) {
testUnitType1ParserSpec, testUnitUiUtilsSpec, testUnitUnicodeSpec,
testUnitUtilSpec) {
// Configure the worker.
displayGlobal.PDFJS.workerSrc = '../../src/worker_loader.js';