From 793a0156ce7af80050cbb2209734842a001a6b42 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 16 Jun 2021 20:15:24 +0200 Subject: [PATCH] XFA - By default a text ui has only one line when in a field element - it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1716809. --- src/core/xfa/template.js | 18 ++++++++---- test/pdfs/xfa_bug1716809.pdf.link | 1 + test/test_manifest.json | 8 +++++ test/unit/xfa_tohtml_spec.js | 49 +++++++++++++++++++++++++++++-- 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 test/pdfs/xfa_bug1716809.pdf.link diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index 04428554e0249..ec1cae0514796 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -18,6 +18,7 @@ import { $addHTML, $appendChild, $childrenToHTML, + $clean, $content, $extra, $finalize, @@ -4820,11 +4821,7 @@ class TextEdit extends XFAObject { "on", ]); this.id = attributes.id || ""; - this.multiLine = getInteger({ - data: attributes.multiLine, - defaultValue: 1, - validate: x => x === 0, - }); + this.multiLine = attributes.multiLine || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.vScrollPolicy = getStringOption(attributes.vScrollPolicy, [ @@ -4838,6 +4835,17 @@ class TextEdit extends XFAObject { this.margin = null; } + [$clean](builder) { + super[$clean](builder); + const parent = this[$getParent](); + const defaultValue = parent instanceof Draw ? 1 : 0; + this.multiLine = getInteger({ + data: this.multiLine, + defaultValue, + validate: x => x === 0 || x === 1, + }); + } + [$toHTML](availableSpace) { // TODO: incomplete. const style = toStyle(this, "border", "font", "margin"); diff --git a/test/pdfs/xfa_bug1716809.pdf.link b/test/pdfs/xfa_bug1716809.pdf.link new file mode 100644 index 0000000000000..6539633cb2324 --- /dev/null +++ b/test/pdfs/xfa_bug1716809.pdf.link @@ -0,0 +1 @@ +https://bugzilla.mozilla.org/attachment.cgi?id=9227437 diff --git a/test/test_manifest.json b/test/test_manifest.json index cbcc0874368bc..b85eff257a2a2 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -938,6 +938,14 @@ "enableXfa": true, "type": "eq" }, + { "id": "xfa_bug1716809", + "file": "pdfs/xfa_bug1716809.pdf", + "md5": "7192f9e27e8b84776d107f57cbe353d5", + "link": true, + "rounds": 1, + "enableXfa": true, + "type": "eq" + }, { "id": "xfa_annual_expense_report", "file": "pdfs/xfa_annual_expense_report.pdf", "md5": "06866e7a6bbc0346789208ef5f6e885c", diff --git a/test/unit/xfa_tohtml_spec.js b/test/unit/xfa_tohtml_spec.js index 14bc28da646f8..b076c2447db97 100644 --- a/test/unit/xfa_tohtml_spec.js +++ b/test/unit/xfa_tohtml_spec.js @@ -137,7 +137,7 @@ describe("XFAFactory", function () { - + @@ -160,9 +160,54 @@ describe("XFAFactory", function () { expect(factory.numberPages).toEqual(1); const pages = factory.getPages(); - const field = searchHtmlNode(pages, "name", "textarea"); + const field = searchHtmlNode(pages, "name", "input"); expect(field.attributes.maxLength).toEqual(123); }); + + it("should have an input or textarea", function () { + const xml = ` + + + + + + + + + `; + const factory = new XFAFactory({ "xdp:xdp": xml }); + + expect(factory.numberPages).toEqual(1); + + const pages = factory.getPages(); + const field1 = searchHtmlNode(pages, "name", "input"); + expect(field1).not.toEqual(null); + + const field2 = searchHtmlNode(pages, "name", "textarea"); + expect(field2).not.toEqual(null); + }); }); });