Browse Source

Text widget annotations: do not render on canvas as well

If interactive forms are enabled, then the display layer takes care of
rendering the form elements. There is no need to draw them on the canvas
as well. This also leads to issues when values are prefilled, because
the text fields are transparent, so the contents that have been rendered
onto the canvas will be visible too.

We address this issue by passing the `renderInteractiveForms` parameter
to the render task and handling it when the page is rendered (i.e., when
the canvas is rendered).
Tim van der Meij 9 years ago
parent
commit
dbea302a6e
  1. 17
      src/core/annotation.js
  2. 8
      src/core/document.js
  3. 3
      src/core/worker.js
  4. 8
      src/display/api.js
  5. 1
      web/pdf_page_view.js

17
src/core/annotation.js

@ -68,10 +68,12 @@ 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;
@ -90,6 +92,7 @@ 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) {
@ -693,6 +696,8 @@ 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) {
@ -715,12 +720,18 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, { Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
task) { task) {
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) {
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);
} }
var operatorList = new OperatorList();
// Even if there is an appearance stream, ignore it. This is the // Even if there is an appearance stream, ignore it. This is the
// behaviour used by Adobe Reader. // behaviour used by Adobe Reader.
if (!this.data.defaultAppearance) { if (!this.data.defaultAppearance) {

8
src/core/document.js

@ -205,7 +205,8 @@ var Page = (function PageClosure() {
}.bind(this)); }.bind(this));
}, },
getOperatorList: function Page_getOperatorList(handler, task, intent) { getOperatorList: function Page_getOperatorList(handler, task, intent,
renderInteractiveForms) {
var self = this; var self = this;
var pdfManager = this.pdfManager; var pdfManager = this.pdfManager;
@ -245,6 +246,8 @@ 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) {
@ -328,7 +331,8 @@ 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);
} }

3
src/core/worker.js

@ -839,7 +839,8 @@ var WorkerMessageHandler = {
var pageNum = pageIndex + 1; var pageNum = pageIndex + 1;
var start = Date.now(); var start = Date.now();
// Pre compile the pdf page and fetch the fonts/images. // Pre compile the pdf page and fetch the fonts/images.
page.getOperatorList(handler, task, data.intent).then( page.getOperatorList(handler, task, data.intent,
data.renderInteractiveForms).then(
function(operatorList) { function(operatorList) {
finishWorkerTask(task); finishWorkerTask(task);

8
src/display/api.js

@ -656,6 +656,9 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* calling of PDFPage.getViewport method. * calling of PDFPage.getViewport method.
* @property {string} intent - Rendering intent, can be 'display' or 'print' * @property {string} intent - Rendering intent, can be 'display' or 'print'
* (default value is 'display'). * (default value is 'display').
* @property {boolean} renderInteractiveForms - (optional) Whether or not
* interactive form elements are rendered in the display
* layer. If so, we do not render them on canvas as well.
* @property {Array} transform - (optional) Additional transform, applied * @property {Array} transform - (optional) Additional transform, applied
* just before viewport transform. * just before viewport transform.
* @property {Object} imageLayer - (optional) An object that has beginLayout, * @property {Object} imageLayer - (optional) An object that has beginLayout,
@ -764,6 +767,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
this.pendingCleanup = false; this.pendingCleanup = false;
var renderingIntent = (params.intent === 'print' ? 'print' : 'display'); var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
var renderInteractiveForms = (params.renderInteractiveForms === true ?
true : /* Default */ false);
if (!this.intentStates[renderingIntent]) { if (!this.intentStates[renderingIntent]) {
this.intentStates[renderingIntent] = Object.create(null); this.intentStates[renderingIntent] = Object.create(null);
@ -784,7 +789,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
this.stats.time('Page Request'); this.stats.time('Page Request');
this.transport.messageHandler.send('RenderPageRequest', { this.transport.messageHandler.send('RenderPageRequest', {
pageIndex: this.pageNumber - 1, pageIndex: this.pageNumber - 1,
intent: renderingIntent intent: renderingIntent,
renderInteractiveForms: renderInteractiveForms,
}); });
} }

1
web/pdf_page_view.js

@ -498,6 +498,7 @@ var PDFPageView = (function PDFPageViewClosure() {
canvasContext: ctx, canvasContext: ctx,
transform: transform, transform: transform,
viewport: this.viewport, viewport: this.viewport,
renderInteractiveForms: pdfjsLib.PDFJS.renderInteractiveForms,
// intent: 'default', // === 'display' // intent: 'default', // === 'display'
}; };
var renderTask = this.renderTask = this.pdfPage.render(renderContext); var renderTask = this.renderTask = this.pdfPage.render(renderContext);

Loading…
Cancel
Save