From c47f0f0f407b04bb18cd13977b7dc42a43dcafe5 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 6 Jul 2021 17:52:05 +0200 Subject: [PATCH] XFA - Default background in rectangle is white - Fix a typo in order to open the pdf in issue #13679 - After fixing the fill default color there wer some regressions because of z-index and when fixing z-index there were some regressions because of borders - So fix the borders rendering. --- src/core/xfa/config.js | 2 +- src/core/xfa/html_utils.js | 40 ++++++++++++++++++++----------- src/core/xfa/template.js | 2 +- test/pdfs/xfa_issue13679.pdf.link | 1 + test/test_manifest.json | 8 +++++++ web/xfa_layer_builder.css | 21 ---------------- 6 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 test/pdfs/xfa_issue13679.pdf.link diff --git a/src/core/xfa/config.js b/src/core/xfa/config.js index 1f8894e8a..f82e79ea6 100644 --- a/src/core/xfa/config.js +++ b/src/core/xfa/config.js @@ -171,7 +171,7 @@ class BehaviorOverride extends ContentObject { this[$content] .trim() .split(/\s+/) - .filter(x => !!x && x.include(":")) + .filter(x => x.includes(":")) .map(x => x.split(":", 2)) ); } diff --git a/src/core/xfa/html_utils.js b/src/core/xfa/html_utils.js index 708e1e344..644e0c0ed 100644 --- a/src/core/xfa/html_utils.js +++ b/src/core/xfa/html_utils.js @@ -420,40 +420,50 @@ function createWrapper(node, html) { class: ["xfaWrapper"], style: Object.create(null), }, - children: [html], + children: [], }; attributes.class.push("xfaWrapped"); if (node.border) { const { widths, insets } = node.border[$extra]; - let shiftH = 0; - let shiftW = 0; + let width, height; + let top = insets[0]; + let left = insets[3]; + const insetsH = insets[0] + insets[2]; + const insetsW = insets[1] + insets[3]; switch (node.border.hand) { case "even": - shiftW = widths[0] / 2; - shiftH = widths[3] / 2; + top -= widths[0] / 2; + left -= widths[3] / 2; + width = `calc(100% + ${(widths[1] + widths[3]) / 2 - insetsW}px)`; + height = `calc(100% + ${(widths[0] + widths[2]) / 2 - insetsH}px)`; break; case "left": - shiftW = widths[0]; - shiftH = widths[3]; + top -= widths[0]; + left -= widths[3]; + width = `calc(100% + ${widths[1] + widths[3] - insetsW}px)`; + height = `calc(100% + ${widths[0] + widths[2] - insetsH}px)`; + break; + case "right": + width = insetsW ? `calc(100% - ${insetsW}px)` : "100%"; + height = insetsH ? `calc(100% - ${insetsH}px)` : "100%"; break; } - const insetsW = insets[1] + insets[3]; - const insetsH = insets[0] + insets[2]; const classNames = ["xfaBorder"]; if (isPrintOnly(node.border)) { classNames.push("xfaPrintOnly"); } + const border = { name: "div", attributes: { class: classNames, style: { - top: `${insets[0] - widths[0] + shiftW}px`, - left: `${insets[3] - widths[3] + shiftH}px`, - width: insetsW ? `calc(100% - ${insetsW}px)` : "100%", - height: insetsH ? `calc(100% - ${insetsH}px)` : "100%", + top: `${top}px`, + left: `${left}px`, + width, + height, }, }, children: [], @@ -471,7 +481,9 @@ function createWrapper(node, html) { delete style[key]; } } - wrapper.children.push(border); + wrapper.children.push(border, html); + } else { + wrapper.children.push(html); } for (const key of [ diff --git a/src/core/xfa/template.js b/src/core/xfa/template.js index b3b87f930..a97a9b2fe 100644 --- a/src/core/xfa/template.js +++ b/src/core/xfa/template.js @@ -2689,7 +2689,7 @@ class Fill extends XFAObject { } if (parent instanceof Rectangle || parent instanceof Arc) { propName = "fill"; - style.fill = "transparent"; + style.fill = "white"; } for (const name of Object.getOwnPropertyNames(this)) { diff --git a/test/pdfs/xfa_issue13679.pdf.link b/test/pdfs/xfa_issue13679.pdf.link new file mode 100644 index 000000000..368a8c2ec --- /dev/null +++ b/test/pdfs/xfa_issue13679.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/6768253/Form_MGT-7.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 3917bf409..68412257e 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1138,6 +1138,14 @@ "enableXfa": true, "type": "eq" }, + { "id": "xfa_issue13679", + "file": "pdfs/xfa_issue13679.pdf", + "md5": "b7231495f0c063435e7cfb92b4f281a3", + "link": true, + "rounds": 1, + "enableXfa": true, + "type": "eq" + }, { "id": "xfa_issue13633", "file": "pdfs/xfa_issue13633.pdf", "md5": "e5b0d09285ca6a140eba08d740be0ea0", diff --git a/web/xfa_layer_builder.css b/web/xfa_layer_builder.css index 6e95ca33f..bc6c11048 100644 --- a/web/xfa_layer_builder.css +++ b/web/xfa_layer_builder.css @@ -31,7 +31,6 @@ text-align: initial; top: 0; left: 0; - z-index: 200; transform-origin: 0 0; line-height: 1.2; } @@ -76,26 +75,6 @@ vertical-align: 0; } -.xfaDraw { - z-index: 100; -} - -.xfaExclgroup { - z-index: 200; -} - -.xfaField { - z-index: 300; -} - -.xfaRich { - z-index: 300; -} - -.xfaSubform { - z-index: 200; -} - .xfaCaption { overflow: hidden; flex: 0 1 auto;