Skip to content

Commit 7820f58

Browse files
Merge pull request mozilla#7647 from Snuffleupagus/Annotation_appendToOperatorList-pass-in-forms
Ensure that `test/driver.js` actually takes the same `Annotation` code-path as the viewer when running `forms` tests (PR 7633 follow-up)
2 parents 431af8c + 5f16cbd commit 7820f58

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

src/core/annotation.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
6868
* @param {Object} ref
6969
* @param {string} uniquePrefix
7070
* @param {Object} idCounters
71-
* @param {boolean} renderInteractiveForms
7271
* @returns {Annotation}
7372
*/
7473
create: function AnnotationFactory_create(xref, ref,
75-
uniquePrefix, idCounters,
76-
renderInteractiveForms) {
74+
uniquePrefix, idCounters) {
7775
var dict = xref.fetchIfRef(ref);
7876
if (!isDict(dict)) {
7977
return;
@@ -92,7 +90,6 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
9290
ref: isRef(ref) ? ref : null,
9391
subtype: subtype,
9492
id: id,
95-
renderInteractiveForms: renderInteractiveForms,
9693
};
9794

9895
switch (subtype) {
@@ -417,7 +414,8 @@ var Annotation = (function AnnotationClosure() {
417414
}.bind(this));
418415
},
419416

420-
getOperatorList: function Annotation_getOperatorList(evaluator, task) {
417+
getOperatorList: function Annotation_getOperatorList(evaluator, task,
418+
renderForms) {
421419
if (!this.appearance) {
422420
return Promise.resolve(new OperatorList());
423421
}
@@ -454,13 +452,13 @@ var Annotation = (function AnnotationClosure() {
454452
};
455453

456454
Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
457-
annotations, opList, partialEvaluator, task, intent) {
455+
annotations, opList, partialEvaluator, task, intent, renderForms) {
458456
var annotationPromises = [];
459457
for (var i = 0, n = annotations.length; i < n; ++i) {
460458
if ((intent === 'display' && annotations[i].viewable) ||
461459
(intent === 'print' && annotations[i].printable)) {
462460
annotationPromises.push(
463-
annotations[i].getOperatorList(partialEvaluator, task));
461+
annotations[i].getOperatorList(partialEvaluator, task, renderForms));
464462
}
465463
}
466464
return Promise.all(annotationPromises).then(function(operatorLists) {
@@ -696,8 +694,6 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
696694
function TextWidgetAnnotation(params) {
697695
WidgetAnnotation.call(this, params);
698696

699-
this.renderInteractiveForms = params.renderInteractiveForms;
700-
701697
// Determine the alignment of text in the field.
702698
var alignment = Util.getInheritableProperty(params.dict, 'Q');
703699
if (!isInt(alignment) || alignment < 0 || alignment > 2) {
@@ -718,18 +714,20 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
718714
}
719715

720716
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
721-
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
722-
task) {
717+
getOperatorList:
718+
function TextWidgetAnnotation_getOperatorList(evaluator, task,
719+
renderForms) {
723720
var operatorList = new OperatorList();
724721

725722
// Do not render form elements on the canvas when interactive forms are
726723
// enabled. The display layer is responsible for rendering them instead.
727-
if (this.renderInteractiveForms) {
724+
if (renderForms) {
728725
return Promise.resolve(operatorList);
729726
}
730727

731728
if (this.appearance) {
732-
return Annotation.prototype.getOperatorList.call(this, evaluator, task);
729+
return Annotation.prototype.getOperatorList.call(this, evaluator, task,
730+
renderForms);
733731
}
734732

735733
// Even if there is an appearance stream, ignore it. This is the

src/core/document.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ var Page = (function PageClosure() {
246246
});
247247
});
248248

249-
this.renderInteractiveForms = renderInteractiveForms;
250-
251249
var annotationsPromise = pdfManager.ensure(this, 'annotations');
252250
return Promise.all([pageListPromise, annotationsPromise]).then(
253251
function(datas) {
@@ -260,7 +258,8 @@ var Page = (function PageClosure() {
260258
}
261259

262260
var annotationsReadyPromise = Annotation.appendToOperatorList(
263-
annotations, pageOpList, partialEvaluator, task, intent);
261+
annotations, pageOpList, partialEvaluator, task, intent,
262+
renderInteractiveForms);
264263
return annotationsReadyPromise.then(function () {
265264
pageOpList.flush(true);
266265
return pageOpList;
@@ -331,8 +330,7 @@ var Page = (function PageClosure() {
331330
var annotationRef = annotationRefs[i];
332331
var annotation = annotationFactory.create(this.xref, annotationRef,
333332
this.uniquePrefix,
334-
this.idCounters,
335-
this.renderInteractiveForms);
333+
this.idCounters);
336334
if (annotation) {
337335
annotations.push(annotation);
338336
}

src/display/annotation_layer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,18 @@ var TextWidgetAnnotationElement = (
448448

449449
var element = null;
450450
if (this.renderInteractiveForms) {
451+
// NOTE: We cannot set the values using `element.value` below, since it
452+
// prevents the AnnotationLayer rasterizer in `test/driver.js`
453+
// from parsing the elements correctly for the reference tests.
451454
if (this.data.multiLine) {
452455
element = document.createElement('textarea');
456+
element.textContent = this.data.fieldValue;
453457
} else {
454458
element = document.createElement('input');
455459
element.type = 'text';
460+
element.setAttribute('value', this.data.fieldValue);
456461
}
457462

458-
element.value = this.data.fieldValue;
459463
element.disabled = this.data.readOnly;
460464

461465
if (this.data.maxLen !== null) {

test/driver.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ var Driver = (function DriverClosure() {
459459
self.canvas.height = viewport.height;
460460
self._clearCanvas();
461461

462+
// Initialize various `eq` test subtypes, see comment below.
463+
var renderAnnotations = false, renderForms = false;
464+
462465
var textLayerCanvas, annotationLayerCanvas;
463466
var initPromise;
464467
if (task.type === 'text') {
@@ -483,9 +486,13 @@ var Driver = (function DriverClosure() {
483486
});
484487
} else {
485488
textLayerCanvas = null;
489+
// We fetch the `eq` specific test subtypes here, to avoid
490+
// accidentally changing the behaviour for other types of tests.
491+
renderAnnotations = !!task.annotations;
492+
renderForms = !!task.forms;
486493

487494
// Render the annotation layer if necessary.
488-
if (task.annotations || task.forms) {
495+
if (renderAnnotations || renderForms) {
489496
// Create a dummy canvas for the drawing operations.
490497
annotationLayerCanvas = self.annotationLayerCanvas;
491498
if (!annotationLayerCanvas) {
@@ -503,10 +510,9 @@ var Driver = (function DriverClosure() {
503510
initPromise =
504511
page.getAnnotations({ intent: 'display' }).then(
505512
function(annotations) {
506-
var forms = task.forms || false;
507513
return rasterizeAnnotationLayer(annotationLayerContext,
508514
viewport, annotations,
509-
page, forms);
515+
page, renderForms);
510516
});
511517
} else {
512518
annotationLayerCanvas = null;
@@ -516,7 +522,8 @@ var Driver = (function DriverClosure() {
516522

517523
var renderContext = {
518524
canvasContext: ctx,
519-
viewport: viewport
525+
viewport: viewport,
526+
renderInteractiveForms: renderForms,
520527
};
521528
var completeRender = (function(error) {
522529
// if text layer is present, compose it on top of the page

0 commit comments

Comments
 (0)