Skip to content

Commit a53cd1c

Browse files
authored
Merge pull request #13141 from calixteman/xfa_text
XFA -- Display text content
2 parents a3669a4 + a4c9865 commit a53cd1c

File tree

9 files changed

+550
-162
lines changed

9 files changed

+550
-162
lines changed

src/core/xfa/html_utils.js

+83-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { $getParent, $toStyle, XFAObject } from "./xfa_object.js";
16+
import { $extra, $getParent, $toStyle, XFAObject } from "./xfa_object.js";
1717
import { warn } from "../../shared/util.js";
1818

1919
function measureToString(m) {
@@ -56,8 +56,17 @@ const converters = {
5656
}
5757
},
5858
dimensions(node, style) {
59-
if (node.w) {
60-
style.width = measureToString(node.w);
59+
const parent = node[$getParent]();
60+
const extra = parent[$extra];
61+
let width = node.w;
62+
if (extra && extra.columnWidths) {
63+
width = extra.columnWidths[extra.currentColumn];
64+
extra.currentColumn =
65+
(extra.currentColumn + 1) % extra.columnWidths.length;
66+
}
67+
68+
if (width !== "") {
69+
style.width = measureToString(width);
6170
} else {
6271
style.width = "auto";
6372
if (node.maxW > 0) {
@@ -66,7 +75,7 @@ const converters = {
6675
style.minWidth = measureToString(node.minW);
6776
}
6877

69-
if (node.h) {
78+
if (node.h !== "") {
7079
style.height = measureToString(node.h);
7180
} else {
7281
style.height = "auto";
@@ -108,6 +117,53 @@ const converters = {
108117
break;
109118
}
110119
},
120+
hAlign(node, style) {
121+
switch (node.hAlign) {
122+
case "justifyAll":
123+
style.textAlign = "justify-all";
124+
break;
125+
case "radix":
126+
// TODO: implement this correctly !
127+
style.textAlign = "left";
128+
break;
129+
default:
130+
style.textAlign = node.hAlign;
131+
}
132+
},
133+
borderMarginPadding(node, style) {
134+
// Get border width in order to compute margin and padding.
135+
const borderWidths = [0, 0, 0, 0];
136+
const marginWidths = [0, 0, 0, 0];
137+
const marginNode = node.margin
138+
? [
139+
node.margin.topInset,
140+
node.margin.rightInset,
141+
node.margin.bottomInset,
142+
node.margin.leftInset,
143+
]
144+
: [0, 0, 0, 0];
145+
if (node.border) {
146+
Object.assign(style, node.border[$toStyle](borderWidths, marginWidths));
147+
}
148+
149+
if (borderWidths.every(x => x === 0)) {
150+
// No border: margin & padding are padding
151+
if (node.margin) {
152+
Object.assign(style, node.margin[$toStyle]());
153+
}
154+
style.padding = style.margin;
155+
delete style.margin;
156+
} else {
157+
style.padding =
158+
measureToString(marginNode[0] - borderWidths[0] - marginWidths[0]) +
159+
" " +
160+
measureToString(marginNode[1] - borderWidths[1] - marginWidths[1]) +
161+
" " +
162+
measureToString(marginNode[2] - borderWidths[2] - marginWidths[2]) +
163+
" " +
164+
measureToString(marginNode[3] - borderWidths[3] - marginWidths[3]);
165+
}
166+
},
111167
};
112168

113169
function layoutClass(node) {
@@ -155,4 +211,26 @@ function toStyle(node, ...names) {
155211
return style;
156212
}
157213

158-
export { layoutClass, measureToString, toStyle };
214+
function addExtraDivForMargin(html) {
215+
const style = html.attributes.style;
216+
if (style.margin) {
217+
const padding = style.margin;
218+
delete style.margin;
219+
const width = style.width || "auto";
220+
const height = style.height || "auto";
221+
222+
style.width = "100%";
223+
style.height = "100%";
224+
225+
return {
226+
name: "div",
227+
attributes: {
228+
style: { padding, width, height },
229+
},
230+
children: [html],
231+
};
232+
}
233+
return html;
234+
}
235+
236+
export { addExtraDivForMargin, layoutClass, measureToString, toStyle };

src/core/xfa/parser.js

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
import {
17+
$acceptWhitespace,
1718
$clean,
1819
$finalize,
1920
$nsAttributes,
@@ -49,6 +50,11 @@ class XFAParser extends XMLParserBase {
4950
}
5051

5152
onText(text) {
53+
if (this._current[$acceptWhitespace]()) {
54+
this._current[$onText](text);
55+
return;
56+
}
57+
5258
if (this._whiteRegex.test(text)) {
5359
return;
5460
}

0 commit comments

Comments
 (0)