1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-28 23:28:16 +02:00

XFA - Fix layout issues

- PR #13554 is buggy, so this patch aims to fix bugs.
  - check if a component fits into its parent in taking into account the parent layout.
  - introduce method isSplittable for template nodes to know if a component can be splitted in case of overflow.
This commit is contained in:
Calixte Denizet 2021-06-16 16:02:41 +02:00
parent 326226df45
commit df08b1548b
7 changed files with 337 additions and 232 deletions

View file

@ -102,24 +102,12 @@ const converters = {
style.width = measureToString(width);
} else {
style.width = "auto";
if (node.maxW > 0) {
style.maxWidth = measureToString(node.maxW);
}
if (parent.layout === "position") {
style.minWidth = measureToString(node.minW);
}
}
if (height !== "") {
style.height = measureToString(height);
} else {
style.height = "auto";
if (node.maxH > 0) {
style.maxHeight = measureToString(node.maxH);
}
if (parent.layout === "position") {
style.minHeight = measureToString(node.minH);
}
}
},
position(node, style) {
@ -188,6 +176,20 @@ const converters = {
},
};
function setMinMaxDimensions(node, style) {
const parent = node[$getParent]();
if (parent.layout === "position") {
style.minWidth = measureToString(node.minW);
if (node.maxW) {
style.maxWidth = measureToString(node.maxW);
}
style.minHeight = measureToString(node.minH);
if (node.maxH) {
style.maxHeight = measureToString(node.maxH);
}
}
}
function layoutText(text, xfaFont, fonts, width) {
const measure = new TextMeasure(xfaFont, fonts);
if (typeof text === "string") {
@ -283,16 +285,9 @@ function fixDimensions(node) {
}
}
if (node.layout === "position") {
// Acrobat doesn't take into account min, max values
// for containers with positioned layout (which makes sense).
node.minW = node.minH = 0;
node.maxW = node.maxH = Infinity;
} else {
if (node.layout === "table") {
if (node.w === "" && Array.isArray(node.columnWidths)) {
node.w = node.columnWidths.reduce((a, x) => a + x, 0);
}
if (node.layout === "table") {
if (node.w === "" && Array.isArray(node.columnWidths)) {
node.w = node.columnWidths.reduce((a, x) => a + x, 0);
}
}
}
@ -471,5 +466,6 @@ export {
layoutClass,
layoutText,
measureToString,
setMinMaxDimensions,
toStyle,
};