Pass in the renderInteractiveForms parameter to Annotation_appendToOperatorList, in Page_getOperatorList, instead of to the Annotation constructor (PR 7633 follow-up)

When debugging issue 7643, I noticed that the `forms` tests currently doesn't look like the rendering in the viewer (with `renderInteractiveForms = true` set).
After scratching my head for a little while, I realized that PR 7633 make the implicit assumption that `Page_getOperatorList` (in `core/document.js`) is called *before* fetching the annotation with `PDFPageProxy_getAnnotations` (in `display/api.js`).

Hence this patch, that changes it so that we instead pass in the `renderInteractiveForms` parameter to `Annotation_appendToOperatorList` to ensure that it's always correctly set.
This commit is contained in:
Jonas Jenwald 2016-09-18 22:31:08 +02:00
parent 15e1ae4e3f
commit ded01356c7
2 changed files with 14 additions and 18 deletions

View File

@ -68,12 +68,10 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
* @param {Object} ref * @param {Object} ref
* @param {string} uniquePrefix * @param {string} uniquePrefix
* @param {Object} idCounters * @param {Object} idCounters
* @param {boolean} renderInteractiveForms
* @returns {Annotation} * @returns {Annotation}
*/ */
create: function AnnotationFactory_create(xref, ref, create: function AnnotationFactory_create(xref, ref,
uniquePrefix, idCounters, uniquePrefix, idCounters) {
renderInteractiveForms) {
var dict = xref.fetchIfRef(ref); var dict = xref.fetchIfRef(ref);
if (!isDict(dict)) { if (!isDict(dict)) {
return; return;
@ -92,7 +90,6 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
ref: isRef(ref) ? ref : null, ref: isRef(ref) ? ref : null,
subtype: subtype, subtype: subtype,
id: id, id: id,
renderInteractiveForms: renderInteractiveForms,
}; };
switch (subtype) { switch (subtype) {
@ -417,7 +414,8 @@ var Annotation = (function AnnotationClosure() {
}.bind(this)); }.bind(this));
}, },
getOperatorList: function Annotation_getOperatorList(evaluator, task) { getOperatorList: function Annotation_getOperatorList(evaluator, task,
renderForms) {
if (!this.appearance) { if (!this.appearance) {
return Promise.resolve(new OperatorList()); return Promise.resolve(new OperatorList());
} }
@ -454,13 +452,13 @@ var Annotation = (function AnnotationClosure() {
}; };
Annotation.appendToOperatorList = function Annotation_appendToOperatorList( Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
annotations, opList, partialEvaluator, task, intent) { annotations, opList, partialEvaluator, task, intent, renderForms) {
var annotationPromises = []; var annotationPromises = [];
for (var i = 0, n = annotations.length; i < n; ++i) { for (var i = 0, n = annotations.length; i < n; ++i) {
if ((intent === 'display' && annotations[i].viewable) || if ((intent === 'display' && annotations[i].viewable) ||
(intent === 'print' && annotations[i].printable)) { (intent === 'print' && annotations[i].printable)) {
annotationPromises.push( annotationPromises.push(
annotations[i].getOperatorList(partialEvaluator, task)); annotations[i].getOperatorList(partialEvaluator, task, renderForms));
} }
} }
return Promise.all(annotationPromises).then(function(operatorLists) { return Promise.all(annotationPromises).then(function(operatorLists) {
@ -696,8 +694,6 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
function TextWidgetAnnotation(params) { function TextWidgetAnnotation(params) {
WidgetAnnotation.call(this, params); WidgetAnnotation.call(this, params);
this.renderInteractiveForms = params.renderInteractiveForms;
// Determine the alignment of text in the field. // Determine the alignment of text in the field.
var alignment = Util.getInheritableProperty(params.dict, 'Q'); var alignment = Util.getInheritableProperty(params.dict, 'Q');
if (!isInt(alignment) || alignment < 0 || alignment > 2) { if (!isInt(alignment) || alignment < 0 || alignment > 2) {
@ -718,18 +714,20 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
} }
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, { Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, getOperatorList:
task) { function TextWidgetAnnotation_getOperatorList(evaluator, task,
renderForms) {
var operatorList = new OperatorList(); var operatorList = new OperatorList();
// Do not render form elements on the canvas when interactive forms are // Do not render form elements on the canvas when interactive forms are
// enabled. The display layer is responsible for rendering them instead. // enabled. The display layer is responsible for rendering them instead.
if (this.renderInteractiveForms) { if (renderForms) {
return Promise.resolve(operatorList); return Promise.resolve(operatorList);
} }
if (this.appearance) { 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 // Even if there is an appearance stream, ignore it. This is the

View File

@ -246,8 +246,6 @@ var Page = (function PageClosure() {
}); });
}); });
this.renderInteractiveForms = renderInteractiveForms;
var annotationsPromise = pdfManager.ensure(this, 'annotations'); var annotationsPromise = pdfManager.ensure(this, 'annotations');
return Promise.all([pageListPromise, annotationsPromise]).then( return Promise.all([pageListPromise, annotationsPromise]).then(
function(datas) { function(datas) {
@ -260,7 +258,8 @@ var Page = (function PageClosure() {
} }
var annotationsReadyPromise = Annotation.appendToOperatorList( var annotationsReadyPromise = Annotation.appendToOperatorList(
annotations, pageOpList, partialEvaluator, task, intent); annotations, pageOpList, partialEvaluator, task, intent,
renderInteractiveForms);
return annotationsReadyPromise.then(function () { return annotationsReadyPromise.then(function () {
pageOpList.flush(true); pageOpList.flush(true);
return pageOpList; return pageOpList;
@ -331,8 +330,7 @@ var Page = (function PageClosure() {
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.uniquePrefix,
this.idCounters, this.idCounters);
this.renderInteractiveForms);
if (annotation) { if (annotation) {
annotations.push(annotation); annotations.push(annotation);
} }