Skip to content

Commit

Permalink
Merge pull request #7647 from Snuffleupagus/Annotation_appendToOperat…
Browse files Browse the repository at this point in the history
…orList-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)
  • Loading branch information
timvandermeij committed Sep 21, 2016
2 parents 431af8c + 5f16cbd commit 7820f58
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
24 changes: 11 additions & 13 deletions src/core/annotation.js
Expand Up @@ -68,12 +68,10 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
* @param {Object} ref
* @param {string} uniquePrefix
* @param {Object} idCounters
* @param {boolean} renderInteractiveForms
* @returns {Annotation}
*/
create: function AnnotationFactory_create(xref, ref,
uniquePrefix, idCounters,
renderInteractiveForms) {
uniquePrefix, idCounters) {
var dict = xref.fetchIfRef(ref);
if (!isDict(dict)) {
return;
Expand All @@ -92,7 +90,6 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
ref: isRef(ref) ? ref : null,
subtype: subtype,
id: id,
renderInteractiveForms: renderInteractiveForms,
};

switch (subtype) {
Expand Down Expand Up @@ -417,7 +414,8 @@ var Annotation = (function AnnotationClosure() {
}.bind(this));
},

getOperatorList: function Annotation_getOperatorList(evaluator, task) {
getOperatorList: function Annotation_getOperatorList(evaluator, task,
renderForms) {
if (!this.appearance) {
return Promise.resolve(new OperatorList());
}
Expand Down Expand Up @@ -454,13 +452,13 @@ var Annotation = (function AnnotationClosure() {
};

Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
annotations, opList, partialEvaluator, task, intent) {
annotations, opList, partialEvaluator, task, intent, renderForms) {
var annotationPromises = [];
for (var i = 0, n = annotations.length; i < n; ++i) {
if ((intent === 'display' && annotations[i].viewable) ||
(intent === 'print' && annotations[i].printable)) {
annotationPromises.push(
annotations[i].getOperatorList(partialEvaluator, task));
annotations[i].getOperatorList(partialEvaluator, task, renderForms));
}
}
return Promise.all(annotationPromises).then(function(operatorLists) {
Expand Down Expand Up @@ -696,8 +694,6 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
function TextWidgetAnnotation(params) {
WidgetAnnotation.call(this, params);

this.renderInteractiveForms = params.renderInteractiveForms;

// Determine the alignment of text in the field.
var alignment = Util.getInheritableProperty(params.dict, 'Q');
if (!isInt(alignment) || alignment < 0 || alignment > 2) {
Expand All @@ -718,18 +714,20 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
}

Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
task) {
getOperatorList:
function TextWidgetAnnotation_getOperatorList(evaluator, task,
renderForms) {
var operatorList = new OperatorList();

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

if (this.appearance) {
return Annotation.prototype.getOperatorList.call(this, evaluator, task);
return Annotation.prototype.getOperatorList.call(this, evaluator, task,
renderForms);
}

// Even if there is an appearance stream, ignore it. This is the
Expand Down
8 changes: 3 additions & 5 deletions src/core/document.js
Expand Up @@ -246,8 +246,6 @@ var Page = (function PageClosure() {
});
});

this.renderInteractiveForms = renderInteractiveForms;

var annotationsPromise = pdfManager.ensure(this, 'annotations');
return Promise.all([pageListPromise, annotationsPromise]).then(
function(datas) {
Expand All @@ -260,7 +258,8 @@ var Page = (function PageClosure() {
}

var annotationsReadyPromise = Annotation.appendToOperatorList(
annotations, pageOpList, partialEvaluator, task, intent);
annotations, pageOpList, partialEvaluator, task, intent,
renderInteractiveForms);
return annotationsReadyPromise.then(function () {
pageOpList.flush(true);
return pageOpList;
Expand Down Expand Up @@ -331,8 +330,7 @@ var Page = (function PageClosure() {
var annotationRef = annotationRefs[i];
var annotation = annotationFactory.create(this.xref, annotationRef,
this.uniquePrefix,
this.idCounters,
this.renderInteractiveForms);
this.idCounters);
if (annotation) {
annotations.push(annotation);
}
Expand Down
6 changes: 5 additions & 1 deletion src/display/annotation_layer.js
Expand Up @@ -448,14 +448,18 @@ var TextWidgetAnnotationElement = (

var element = null;
if (this.renderInteractiveForms) {
// NOTE: We cannot set the values using `element.value` below, since it
// prevents the AnnotationLayer rasterizer in `test/driver.js`
// from parsing the elements correctly for the reference tests.
if (this.data.multiLine) {
element = document.createElement('textarea');
element.textContent = this.data.fieldValue;
} else {
element = document.createElement('input');
element.type = 'text';
element.setAttribute('value', this.data.fieldValue);
}

element.value = this.data.fieldValue;
element.disabled = this.data.readOnly;

if (this.data.maxLen !== null) {
Expand Down
15 changes: 11 additions & 4 deletions test/driver.js
Expand Up @@ -459,6 +459,9 @@ var Driver = (function DriverClosure() {
self.canvas.height = viewport.height;
self._clearCanvas();

// Initialize various `eq` test subtypes, see comment below.
var renderAnnotations = false, renderForms = false;

var textLayerCanvas, annotationLayerCanvas;
var initPromise;
if (task.type === 'text') {
Expand All @@ -483,9 +486,13 @@ var Driver = (function DriverClosure() {
});
} else {
textLayerCanvas = null;
// We fetch the `eq` specific test subtypes here, to avoid
// accidentally changing the behaviour for other types of tests.
renderAnnotations = !!task.annotations;
renderForms = !!task.forms;

// Render the annotation layer if necessary.
if (task.annotations || task.forms) {
if (renderAnnotations || renderForms) {
// Create a dummy canvas for the drawing operations.
annotationLayerCanvas = self.annotationLayerCanvas;
if (!annotationLayerCanvas) {
Expand All @@ -503,10 +510,9 @@ var Driver = (function DriverClosure() {
initPromise =
page.getAnnotations({ intent: 'display' }).then(
function(annotations) {
var forms = task.forms || false;
return rasterizeAnnotationLayer(annotationLayerContext,
viewport, annotations,
page, forms);
page, renderForms);
});
} else {
annotationLayerCanvas = null;
Expand All @@ -516,7 +522,8 @@ var Driver = (function DriverClosure() {

var renderContext = {
canvasContext: ctx,
viewport: viewport
viewport: viewport,
renderInteractiveForms: renderForms,
};
var completeRender = (function(error) {
// if text layer is present, compose it on top of the page
Expand Down

0 comments on commit 7820f58

Please sign in to comment.