-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic AcroForms input controls rendering #6172
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ var CustomStyle = displayDOMUtils.CustomStyle; | |
* @property {PageViewport} viewport | ||
* @property {IPDFLinkService} linkService | ||
* @property {DownloadManager} downloadManager | ||
* @property {IPDFStorageService} storageService | ||
*/ | ||
|
||
/** | ||
|
@@ -68,6 +69,13 @@ AnnotationElementFactory.prototype = | |
return new TextAnnotationElement(parameters); | ||
|
||
case AnnotationType.WIDGET: | ||
switch (parameters.data.fieldType) { | ||
case 'Tx': | ||
return new TextWidgetAnnotationElement(parameters); | ||
} | ||
warn('Unimplemented Widget annotation type: ' + | ||
parameters.data.fieldType); | ||
// Fallback to default one, which does not render anything. | ||
return new WidgetAnnotationElement(parameters); | ||
|
||
case AnnotationType.POPUP: | ||
|
@@ -107,6 +115,7 @@ var AnnotationElement = (function AnnotationElementClosure() { | |
this.viewport = parameters.viewport; | ||
this.linkService = parameters.linkService; | ||
this.downloadManager = parameters.downloadManager; | ||
this.storageService = parameters.storageService; | ||
|
||
if (isRenderable) { | ||
this.container = this._createContainer(); | ||
|
@@ -386,9 +395,7 @@ var TextAnnotationElement = (function TextAnnotationElementClosure() { | |
* @alias WidgetAnnotationElement | ||
*/ | ||
var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() { | ||
function WidgetAnnotationElement(parameters) { | ||
var isRenderable = !parameters.data.hasAppearance && | ||
!!parameters.data.fieldValue; | ||
function WidgetAnnotationElement(parameters, isRenderable) { | ||
AnnotationElement.call(this, parameters, isRenderable); | ||
} | ||
|
||
|
@@ -401,19 +408,94 @@ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() { | |
* @returns {HTMLSectionElement} | ||
*/ | ||
render: function WidgetAnnotationElement_render() { | ||
var content = document.createElement('div'); | ||
content.textContent = this.data.fieldValue; | ||
return this.container; | ||
}, | ||
|
||
/** | ||
* Check bit value for given position in fieldFlags. | ||
* Note: position is 1 based index. | ||
* | ||
* @private | ||
* @memberof WidgetAnnotationElement | ||
* @returns {boolean} | ||
*/ | ||
_hasFlag: function WidgetAnnotationElement_hasFlag(position) { | ||
return !!(this.data.fieldFlags & (1 << (position - 1))); | ||
} | ||
}); | ||
|
||
return WidgetAnnotationElement; | ||
})(); | ||
|
||
/** | ||
* @class | ||
* @alias TextWidgetAnnotationElement | ||
*/ | ||
var TextWidgetAnnotationElement = | ||
(function TextWidgetAnnotationElementClosure() { | ||
|
||
var READONLY_BIT = 1; | ||
var MULTILINE_BIT = 13; | ||
|
||
function TextWidgetAnnotationElement(parameters) { | ||
WidgetAnnotationElement.call(this, parameters, true); | ||
} | ||
|
||
Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, { | ||
/** | ||
* Render the text widget annotation's HTML element. | ||
* | ||
* @public | ||
* @memberof TextWidgetAnnotationElement | ||
* @returns {HTMLSectionElement} | ||
*/ | ||
render: function TextWidgetAnnotationElement_render() { | ||
var container = WidgetAnnotationElement.prototype.render.call(this); | ||
|
||
var isReadonly = this._hasFlag(READONLY_BIT); | ||
var isMultiline = this._hasFlag(MULTILINE_BIT); | ||
|
||
var content; | ||
if (isMultiline) { | ||
content = document.createElement('textarea'); | ||
} else { | ||
content = document.createElement('input'); | ||
content.type = 'text'; | ||
} | ||
|
||
content.disabled = isReadonly; | ||
content.value = this.storageService.get(this.data.fullName) || | ||
this.data.fieldValue; | ||
var textAlignment = this.data.textAlignment; | ||
content.style.textAlign = ['left', 'center', 'right'][textAlignment]; | ||
content.style.verticalAlign = 'middle'; | ||
content.style.display = 'table-cell'; | ||
if (this.data.maxLen !== null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0 is a valid maxLen |
||
content.maxLength = this.data.maxLen; | ||
} | ||
|
||
var font = (this.data.fontRefName ? | ||
this.page.commonObjs.getData(this.data.fontRefName) : null); | ||
this._setTextStyle(content, font); | ||
|
||
this.container.appendChild(content); | ||
return this.container; | ||
if (!isMultiline && !('fontSize' in this.data)) { | ||
// Hack to guess font size based on content height | ||
// so small text fields are rendered correctly. | ||
// TODO: remove this when we can apply the default appearance. | ||
var height = this.data.rect[3] - this.data.rect[1]; | ||
if (height < 15) { | ||
content.style.fontSize = (height - 1) + 'px'; | ||
} | ||
} | ||
|
||
content.onchange = this._onchange.bind(this); | ||
|
||
container.appendChild(content); | ||
|
||
container.className = 'widgetAnnotation'; | ||
return container; | ||
}, | ||
|
||
_onchange: function(evt) { | ||
this.storageService.set(this.data.fullName, evt.target.value); | ||
}, | ||
|
||
/** | ||
|
@@ -422,14 +504,18 @@ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() { | |
* @private | ||
* @param {HTMLDivElement} element | ||
* @param {Object} font | ||
* @memberof WidgetAnnotationElement | ||
* @memberof TextWidgetAnnotationElement | ||
*/ | ||
_setTextStyle: | ||
function WidgetAnnotationElement_setTextStyle(element, font) { | ||
function TextWidgetAnnotationElement_setTextStyle(element, font) { | ||
// TODO: This duplicates some of the logic in CanvasGraphics.setFont(). | ||
var style = element.style; | ||
style.fontSize = this.data.fontSize + 'px'; | ||
style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr'); | ||
if ('fontSize' in this.data) { | ||
style.fontSize = this.data.fontSize + 'px'; | ||
} | ||
if ('fontDirection' in this.data) { | ||
style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr'); | ||
} | ||
|
||
if (!font) { | ||
return; | ||
|
@@ -447,7 +533,7 @@ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() { | |
} | ||
}); | ||
|
||
return WidgetAnnotationElement; | ||
return TextWidgetAnnotationElement; | ||
})(); | ||
|
||
/** | ||
|
@@ -868,7 +954,8 @@ var AnnotationLayer = (function AnnotationLayerClosure() { | |
page: parameters.page, | ||
viewport: parameters.viewport, | ||
linkService: parameters.linkService, | ||
downloadManager: parameters.downloadManager | ||
downloadManager: parameters.downloadManager, | ||
storageService: parameters.storageService | ||
}; | ||
var element = annotationElementFactory.create(properties); | ||
if (element.isRenderable) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing file: https://drive.google.com/file/d/0B6YhVF9p-y2AbS1wY3drMDdGRVE/view?usp=sharing