Added field align property support.

Fixed string field values so that they use CosString and not CosName.
This commit is contained in:
Jim Pravetz 2019-07-18 17:33:05 -07:00
parent 9d6f6f7d1f
commit b53c6a7dd3
2 changed files with 37 additions and 1 deletions

View File

@ -13,6 +13,11 @@ const FIELD_FLAGS = {
edit: 0x40000,
sort: 0x80000
};
const FIELD_JUSTIFY = {
left: 0,
center: 1,
right: 2
};
export default {
@ -63,7 +68,9 @@ export default {
}
let opts = Object.assign({}, options);
opts = this._resolveFlags(opts);
opts = this._resolveJustify(opts);
opts = this._resolveFont(opts);
opts = this._resolveStrings(opts);
opts = Object.assign(opts, {
Subtype: 'Widget',
F: 4,
@ -92,6 +99,14 @@ export default {
return options;
},
_resolveJustify (options) {
if (options.align && FIELD_JUSTIFY[options.align]) {
options.Q = FIELD_JUSTIFY[options.align];
delete options.align;
}
return options;
},
_resolveFont (options) {
// add current font to document-level AcroForm dict if necessary
if (this._acroform.fonts[this._font.id] == null) {
@ -106,6 +121,27 @@ export default {
return options;
},
_resolveStrings (options) {
if (Array.isArray(options.Opt)) {
let arr = [];
for (let idx = 0; idx < options.Opt.length; idx++) {
if (typeof options.Opt[idx] === 'string') {
arr.push(new String(options.Opt[idx]))
} else {
arr.push(options.Opt[idx])
}
arr.push(new String(options.Opt[idx]));
}
options.Opt = arr;
}
['V', 'DV'].forEach(key => {
if (typeof options[key] === 'string') {
options[key] = new String(options[key]);
}
});
return options;
},
formButton (name, x, y, w, h, options = {}) {
options.FT = 'Btn';
return this.formAnnot(name, x, y, w, h, options)

View File

@ -36,7 +36,7 @@ describe('AcroForm', () => {
test('standard fonts', () => {
// const docData = logData(doc);
const docData = logData(doc);
doc.registerFont('myfont1', 'tests/fonts/Roboto-Regular.ttf')