Browse Source

Render interactive form (AcroForm) text widget annotations

This patch is the first step towards implementing support for
interactive forms (AcroForms). It makes it possible to render text
widget annotations exactly like Adobe Reader/Acrobat.

Everything we implement for AcroForms is disabled by default using a
preference, mainly because it is not ready to use yet, but has to
implemented in many steps to avoid complexity. The preference allows us
to work with the code while not exposing the behavior by default. Mainly
storing entered values and printing them is still absent, which would be
minimal requirements for enabling this by default.
Tim van der Meij 9 years ago
parent
commit
e686db250c
  1. 4
      extensions/chromium/preferences_schema.json
  2. 17
      src/display/annotation_layer.js
  3. 7
      src/display/global.js
  4. 20
      web/annotation_layer_builder.css
  5. 3
      web/annotation_layer_builder.js
  6. 3
      web/app.js
  7. 3
      web/default_preferences.json

4
extensions/chromium/preferences_schema.json

@ -94,6 +94,10 @@
"type": "boolean", "type": "boolean",
"description": "Whether to prevent the extension from reporting the extension and browser version to the extension developers.", "description": "Whether to prevent the extension from reporting the extension and browser version to the extension developers.",
"default": false "default": false
},
"renderInteractiveForms": {
"type": "boolean",
"default": false
} }
} }
} }

17
src/display/annotation_layer.js

@ -45,6 +45,8 @@ var getDefaultSetting = displayDOMUtils.getDefaultSetting;
* @property {PageViewport} viewport * @property {PageViewport} viewport
* @property {IPDFLinkService} linkService * @property {IPDFLinkService} linkService
* @property {DownloadManager} downloadManager * @property {DownloadManager} downloadManager
* @property {string} imageResourcesPath
* @property {boolean} renderInteractiveForms
*/ */
/** /**
@ -115,6 +117,7 @@ var AnnotationElement = (function AnnotationElementClosure() {
this.linkService = parameters.linkService; this.linkService = parameters.linkService;
this.downloadManager = parameters.downloadManager; this.downloadManager = parameters.downloadManager;
this.imageResourcesPath = parameters.imageResourcesPath; this.imageResourcesPath = parameters.imageResourcesPath;
this.renderInteractiveForms = parameters.renderInteractiveForms;
if (isRenderable) { if (isRenderable) {
this.container = this._createContainer(); this.container = this._createContainer();
@ -437,6 +440,15 @@ var TextWidgetAnnotationElement = (
* @returns {HTMLSectionElement} * @returns {HTMLSectionElement}
*/ */
render: function TextWidgetAnnotationElement_render() { render: function TextWidgetAnnotationElement_render() {
this.container.className = 'textWidgetAnnotation';
if (this.renderInteractiveForms) {
var input = document.createElement('input');
input.type = 'text';
input.value = this.data.fieldValue;
this.container.appendChild(input);
} else {
var content = document.createElement('div'); var content = document.createElement('div');
content.textContent = this.data.fieldValue; content.textContent = this.data.fieldValue;
var textAlignment = this.data.textAlignment; var textAlignment = this.data.textAlignment;
@ -449,6 +461,7 @@ var TextWidgetAnnotationElement = (
this._setTextStyle(content, font); this._setTextStyle(content, font);
this.container.appendChild(content); this.container.appendChild(content);
}
return this.container; return this.container;
}, },
@ -875,6 +888,7 @@ var FileAttachmentAnnotationElement = (
* @property {PDFPage} page * @property {PDFPage} page
* @property {IPDFLinkService} linkService * @property {IPDFLinkService} linkService
* @property {string} imageResourcesPath * @property {string} imageResourcesPath
* @property {boolean} renderInteractiveForms
*/ */
/** /**
@ -907,7 +921,8 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
linkService: parameters.linkService, linkService: parameters.linkService,
downloadManager: parameters.downloadManager, downloadManager: parameters.downloadManager,
imageResourcesPath: parameters.imageResourcesPath || imageResourcesPath: parameters.imageResourcesPath ||
getDefaultSetting('imageResourcesPath') getDefaultSetting('imageResourcesPath'),
renderInteractiveForms: parameters.renderInteractiveForms || false,
}; };
var element = annotationElementFactory.create(properties); var element = annotationElementFactory.create(properties);
if (element.isRenderable) { if (element.isRenderable) {

7
src/display/global.js

@ -243,6 +243,13 @@
PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ? PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
true : PDFJS.isEvalSupported); true : PDFJS.isEvalSupported);
/**
* Renders interactive form elements.
* @var {boolean}
*/
PDFJS.renderInteractiveForms = (PDFJS.renderInteractiveForms === undefined ?
false : PDFJS.renderInteractiveForms);
//#if !MOZCENTRAL //#if !MOZCENTRAL
var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow; var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
delete PDFJS.openExternalLinksInNewWindow; delete PDFJS.openExternalLinksInNewWindow;

20
web/annotation_layer_builder.css

@ -41,6 +41,26 @@
cursor: pointer; cursor: pointer;
} }
.annotationLayer .textWidgetAnnotation input {
background-color: rgba(0, 54, 255, 0.13);
border: 1px solid transparent;
box-sizing: border-box;
font-size: 9px;
height: 100%;
padding: 0 3px;
vertical-align: top;
width: 100%;
}
.annotationLayer .textWidgetAnnotation input:hover {
border: 1px solid #000;
}
.annotationLayer .textWidgetAnnotation input:focus {
background: none;
border: 1px solid transparent;
}
.annotationLayer .popupWrapper { .annotationLayer .popupWrapper {
position: absolute; position: absolute;
width: 20em; width: 20em;

3
web/annotation_layer_builder.js

@ -78,7 +78,8 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
annotations: annotations, annotations: annotations,
page: self.pdfPage, page: self.pdfPage,
linkService: self.linkService, linkService: self.linkService,
downloadManager: self.downloadManager downloadManager: self.downloadManager,
renderInteractiveForms: pdfjsLib.PDFJS.renderInteractiveForms,
}; };
if (self.div) { if (self.div) {

3
web/app.js

@ -359,6 +359,9 @@ var PDFViewerApplication = {
} }
PDFJS.externalLinkTarget = value; PDFJS.externalLinkTarget = value;
}), }),
Preferences.get('renderInteractiveForms').then(function resolved(value) {
PDFJS.renderInteractiveForms = value;
}),
// TODO move more preferences and other async stuff here // TODO move more preferences and other async stuff here
]).catch(function (reason) { }); ]).catch(function (reason) { });

3
web/default_preferences.json

@ -11,5 +11,6 @@
"disableFontFace": false, "disableFontFace": false,
"disableTextLayer": false, "disableTextLayer": false,
"useOnlyCssZoom": false, "useOnlyCssZoom": false,
"externalLinkTarget": 0 "externalLinkTarget": 0,
"renderInteractiveForms": false
} }

Loading…
Cancel
Save