Skip to content

Commit e660a96

Browse files
committed
XFA - Paragraphes must take their style values from the containing container (bug 1722003)
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1722003 - some containers have a para element which contains the default values to apply to paragraph they contain, these values are correctly set in the container but they aren't applied to children.
1 parent 6a15973 commit e660a96

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

src/core/xfa/html_utils.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,27 @@ function getCurrentPara(node) {
565565
return stack.length ? stack[stack.length - 1] : null;
566566
}
567567

568+
function setParaStyle(node, nodeStyle) {
569+
const para = getCurrentPara(node);
570+
if (!para) {
571+
return;
572+
}
573+
574+
const paraStyle = para[$toStyle]();
575+
for (const key of [
576+
"paddingLeft",
577+
"paddingRight",
578+
"paddingTop",
579+
"paddingBottom",
580+
"textIndent",
581+
"tabSize",
582+
]) {
583+
if (!(key in nodeStyle) && key in paraStyle) {
584+
nodeStyle[key] = paraStyle[key];
585+
}
586+
}
587+
}
588+
568589
function setPara(node, nodeStyle, value) {
569590
if (value.attributes.class && value.attributes.class.includes("xfaRich")) {
570591
if (nodeStyle) {
@@ -596,9 +617,9 @@ function setPara(node, nodeStyle, value) {
596617
}
597618

598619
const paraStyle = para[$toStyle]();
599-
for (const [key, val] of Object.entries(paraStyle)) {
600-
if (!(key in valueStyle)) {
601-
valueStyle[key] = val;
620+
for (const key of ["lineHeight", "textAlign"]) {
621+
if (!(key in valueStyle) && key in paraStyle) {
622+
valueStyle[key] = paraStyle[key];
602623
}
603624
}
604625
}
@@ -661,5 +682,6 @@ export {
661682
setFontFamily,
662683
setMinMaxDimensions,
663684
setPara,
685+
setParaStyle,
664686
toStyle,
665687
};

src/core/xfa/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4289,7 +4289,7 @@ class Para extends XFAObject {
42894289
style.paddingLeft = measureToString(this.marginLeft);
42904290
}
42914291
if (this.marginRight !== "") {
4292-
style.paddingight = measureToString(this.marginRight);
4292+
style.paddingRight = measureToString(this.marginRight);
42934293
}
42944294
if (this.spaceAbove !== "") {
42954295
style.paddingTop = measureToString(this.spaceAbove);

src/core/xfa/xhtml.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
fixURL,
3636
measureToString,
3737
setFontFamily,
38+
setParaStyle,
3839
} from "./html_utils.js";
3940
import { getMeasurement, HTMLResult, stripQuotes } from "./utils.js";
4041

@@ -481,6 +482,19 @@ class P extends XhtmlObject {
481482
}
482483
return super[$text]() + "\n";
483484
}
485+
486+
[$toHTML](availableSpace) {
487+
const res = super[$toHTML](availableSpace);
488+
const { html } = res;
489+
if (!html) {
490+
return HTMLResult.EMPTY;
491+
}
492+
if (!html.attributes.style) {
493+
html.attributes.style = Object.create(null);
494+
}
495+
setParaStyle(this, html.attributes.style);
496+
return res;
497+
}
484498
}
485499

486500
class Span extends XhtmlObject {

test/pdfs/xfa_bug1722003.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://bugzilla.mozilla.org/attachment.cgi?id=9232818

test/test_manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,15 @@
10091009
"enableXfa": true,
10101010
"type": "eq"
10111011
},
1012+
{ "id": "xfa_bug1722003",
1013+
"file": "pdfs/xfa_bug1722003.pdf",
1014+
"md5": "47453e6ea9426d22108c6307805464a2",
1015+
"link": true,
1016+
"lastPage": 1,
1017+
"rounds": 1,
1018+
"enableXfa": true,
1019+
"type": "eq"
1020+
},
10121021
{ "id": "issue14164",
10131022
"file": "pdfs/issue14164.pdf",
10141023
"md5": "feb444c716b0337efff8094b156def32",

0 commit comments

Comments
 (0)