Skip to content

Commit

Permalink
Added MaxLen, Comb support to text fields
Browse files Browse the repository at this point in the history
Also cleaned up some styling code.

For mozilla#1459
  • Loading branch information
1ec5 committed Mar 14, 2015
1 parent 72cfa36 commit 4f99480
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
34 changes: 17 additions & 17 deletions examples/acroforms/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,22 @@ function setupForm(div, content, viewport) {
element.style.top = Math.floor(rect[1]) + 'px';
element.style.width = Math.ceil(rect[2] - rect[0]) + 'px';
element.style.height = Math.ceil(rect[3] - rect[1]) + 'px';
if (item.fieldType === 'Tx' && item.fieldFlags & (1 << 24) &&
item.maxLength !== null) {
// Comb
element.style.fontFamily = 'monospace';
var combSpacing = (rect[2] - rect[0]) / parseInt(item.maxLength);
element.style.letterSpacing = 'calc(' + combSpacing + 'px - 1ch)';
}
return element;
}
function assignFontStyle(element, item) {
var fontStyles = '';
if ('fontSize' in item) {
fontStyles += 'font-size: ' + Math.round(item.fontSize *
viewport.fontScale) + 'px;';
}
switch (item.textAlignment) {
case 0:
fontStyles += 'text-align: left;';
break;
case 1:
fontStyles += 'text-align: center;';
break;
case 2:
fontStyles += 'text-align: right;';
break;
if (item.fontSize) {
element.fontSize = Math.round(item.fontSize * viewport.fontScale) + 'px';
}
element.setAttribute('style', element.getAttribute('style') + fontStyles);
element.style.textAlign = ['left', 'center', 'right'][item.textAlignment];
element.style.verticalAlign = 'middle';
element.style.display = 'table-cell';
}

content.getAnnotations().then(function(items) {
Expand All @@ -72,6 +68,10 @@ function setupForm(div, content, viewport) {
var input;
if (item.fieldType == 'Tx') {
input = createElementWithStyle('input', item);
input.text = 'text';
if (item.maxLength !== null) {
input.maxLength = parseInt(item.maxLength);
}
}
if (item.fieldType == 'Btn') {
input = createElementWithStyle('input', item);
Expand Down Expand Up @@ -137,7 +137,7 @@ function renderPage(div, pdf, pageNumber, callback) {
});
}

// Fetch the PDF document from the URL using promices
// Fetch the PDF document from the URL using promises
PDFJS.getDocument(pdfWithFormsPath).then(function getPdfForm(pdf) {
// Rendering all pages starting from first
var viewer = document.getElementById('viewer');
Expand Down
1 change: 1 addition & 0 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
WidgetAnnotation.call(this, params);

this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
this.data.maxLength = params.dict.get('MaxLen');
this.data.annotationType = AnnotationType.WIDGET;
this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
}
Expand Down

0 comments on commit 4f99480

Please sign in to comment.