Skip to content

Commit 6916f7e

Browse files
committed
XFA - Remove empty pages
- it aims to fix #13583; - fix the switch to breakBefore target; - force the layout of an unsplittable element on an empty page; - don't fail when there is horizontal overflow (except in lr-tb); - fix a typo in radial gradient first argument.
1 parent 9de0916 commit 6916f7e

File tree

7 files changed

+231
-99
lines changed

7 files changed

+231
-99
lines changed

src/core/xfa/layout.js

+44-30
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,30 @@ function getTransformedBBox(node) {
257257
* in case of lr-tb or changing content area...).
258258
*/
259259
function checkDimensions(node, space) {
260+
if (node[$getTemplateRoot]()[$extra].firstUnsplittable === null) {
261+
return true;
262+
}
263+
260264
if (node.w === 0 || node.h === 0) {
261265
return true;
262266
}
263267

264268
if (space.width <= 0 || space.height <= 0) {
265-
return false;
269+
return node[$getTemplateRoot]()[$extra].noLayoutFailure;
266270
}
267271

268272
const parent = node[$getParent]();
269-
const attempt = (node[$extra] && node[$extra].attempt) || 0;
273+
const attempt = (parent[$extra] && parent[$extra].attempt) || 0;
270274
switch (parent.layout) {
271275
case "lr-tb":
272276
case "rl-tb":
273-
switch (attempt) {
274-
case 0: {
275-
let w, h;
276-
if (node.w !== "" || node.h !== "") {
277-
[, , w, h] = getTransformedBBox(node);
278-
}
277+
if (attempt === 0) {
278+
let w, h;
279+
if (node.w !== "" || node.h !== "") {
280+
[, , w, h] = getTransformedBBox(node);
281+
}
282+
283+
if (!node[$getTemplateRoot]()[$extra].noLayoutFailure) {
279284
if (node.h !== "" && Math.round(h - space.height) > 1) {
280285
return false;
281286
}
@@ -285,42 +290,51 @@ function checkDimensions(node, space) {
285290

286291
return node.minW <= space.width;
287292
}
288-
case 1: {
289-
if (node.h !== "" && !node[$isSplittable]()) {
290-
const [, , , h] = getTransformedBBox(node);
291-
if (Math.round(h - space.height) > 1) {
292-
return false;
293-
}
294-
}
295-
return true;
293+
if (node.w !== "") {
294+
return Math.round(w - space.width) <= 1;
296295
}
297-
default:
298-
return true;
296+
return true;
299297
}
300-
case "table":
301-
case "tb":
302-
if (attempt !== 1 && node.h !== "" && !node[$isSplittable]()) {
298+
if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
299+
return true;
300+
}
301+
302+
if (node.h !== "" && !node[$isSplittable]()) {
303303
const [, , , h] = getTransformedBBox(node);
304304
if (Math.round(h - space.height) > 1) {
305305
return false;
306306
}
307307
}
308308
return true;
309-
case "position":
310-
const [x, y, w, h] = getTransformedBBox(node);
311-
const isWidthOk = node.w === "" || Math.round(w + x - space.width) <= 1;
312-
const isHeightOk = node.h === "" || Math.round(h + y - space.height) <= 1;
313309

314-
if (isWidthOk && isHeightOk) {
310+
case "table":
311+
case "tb":
312+
if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
315313
return true;
316314
}
317315

318-
const area = node[$getTemplateRoot]()[$extra].currentContentArea;
319-
if (isWidthOk) {
320-
return h + y > area.h;
316+
// If the node has a height then check
317+
// if it's fine with available height. If the node
318+
// is breakable then we can return true.
319+
if (node.h !== "" && !node[$isSplittable]()) {
320+
const [, , , h] = getTransformedBBox(node);
321+
return Math.round(h - space.height) <= 1;
322+
}
323+
// Else wait and see: this node will be layed out itself
324+
// in the provided space and maybe a children won't fit.
325+
return true;
326+
case "position":
327+
if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
328+
return true;
329+
}
330+
331+
const [, y, , h] = getTransformedBBox(node);
332+
if (node.h === "" || Math.round(h + y - space.height) <= 1) {
333+
return true;
321334
}
322335

323-
return w + x > area.w;
336+
const area = node[$getTemplateRoot]()[$extra].currentContentArea;
337+
return h + y > area.h;
324338
case "rl-row":
325339
case "row":
326340
default:

0 commit comments

Comments
 (0)