Skip to content

Commit a74b6be

Browse files
author
Ihsan Nurul Iman
committed
f/dynamic-page-margin: add fix when applied to snaking columns
1 parent 15bdfbd commit a74b6be

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/LayoutBuilder.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,17 @@ class LayoutBuilder {
13641364
}
13651365

13661366
let positions = this.writer.addLine(line);
1367+
if (!positions && this.writer.context().inSnakingColumns() && !this.writer.context().isInNestedNonSnakingGroup()) {
1368+
this.snakingAwarePageBreak(node.pageOrientation);
1369+
1370+
if (line.inlines && line.inlines.length > 0) {
1371+
node._inlines.unshift(...line.inlines);
1372+
}
1373+
1374+
line = this.buildNextLine(node);
1375+
continue;
1376+
}
1377+
13671378
node.positions.push(positions);
13681379
line = this.buildNextLine(node);
13691380
if (line) {

src/PageElementWriter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class PageElementWriter extends ElementWriter {
2222
}
2323

2424
addLine(line, dontUpdateContextPosition, index) {
25+
// Outer snaking text needs LayoutBuilder to rebuild the line after a column/page
26+
// break so the first carried line wraps to the new column width correctly.
27+
if (this.context().inSnakingColumns() && !this.context().isInNestedNonSnakingGroup()) {
28+
return super.addLine(line, dontUpdateContextPosition, index);
29+
}
30+
2531
return this._fitOnPage(() => super.addLine(line, dontUpdateContextPosition, index));
2632
}
2733

tests/integration/snaking_columns.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,42 @@ describe('Integration test: snaking columns', function () {
10321032
assert.ok(lineWidth > 150, 'Page 2 separate column should have reset to wide width (>150), found: ' + lineWidth);
10331033
});
10341034

1035+
it('should reflow the first carried line when dynamic margins snake into a narrower column', function () {
1036+
var dd = {
1037+
pageMargins: function (currentPage) {
1038+
return {
1039+
left: currentPage % 2 === 0 ? 100 : 20,
1040+
top: 20,
1041+
right: currentPage % 2 === 0 ? 20 : 100,
1042+
bottom: 20
1043+
};
1044+
},
1045+
content: [
1046+
{
1047+
columns: [
1048+
{ text: 'Wide content ' + 'text '.repeat(2000), width: 300, fontSize: 10 },
1049+
{ text: '', width: '*' }
1050+
],
1051+
columnGap: 10,
1052+
snakingColumns: true
1053+
}
1054+
]
1055+
};
1056+
1057+
var pages = testHelper.renderPages('A4', dd);
1058+
var page1 = pages[0];
1059+
var lines = page1.items.filter(function (item) { return item.type === 'line'; }).map(function (item) { return item.item; });
1060+
var secondColumnLines = lines.filter(function (line) { return line.x > 320; });
1061+
var firstSecondColumnLine = secondColumnLines[0];
1062+
var rightLimit = page1.pageSize.width - page1.pageMargins.right;
1063+
1064+
assert.ok(firstSecondColumnLine, 'Page 1 should continue into the second snaking column');
1065+
assert.ok(
1066+
firstSecondColumnLine.x + firstSecondColumnLine.getWidth() <= rightLimit + 0.5,
1067+
'The first carried line in the second column should respect the page right margin'
1068+
);
1069+
});
1070+
10351071
describe('snaking columns nested checks', function () {
10361072

10371073
it('should respect left margin when snaking columns break to next page', function () {

0 commit comments

Comments
 (0)