Skip to content

Commit

Permalink
pageBreakBeforeFct performance improvement (#1718)
Browse files Browse the repository at this point in the history
master commit: 2c1efd6
  • Loading branch information
liborm85 committed Feb 9, 2020
1 parent a4f04a5 commit 38f92c2
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions src/layoutBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,40 +92,35 @@ LayoutBuilder.prototype.layoutDocument = function (docStructure, fontProvider, s
node.nodeInfo = nodeInfo;
});

return linearNodeList.some(function (node, index, followingNodeList) {
for (var index = 0; index < linearNodeList.length; index++) {
var node = linearNodeList[index];
if (node.pageBreak !== 'before' && !node.pageBreakCalculated) {
node.pageBreakCalculated = true;
var pageNumber = node.nodeInfo.pageNumbers[0];

var followingNodesOnPage = followingNodeList.slice(index + 1).filter(function (node0) {
return node0.nodeInfo.pageNumbers.indexOf(pageNumber) > -1;
});

var nodesOnNextPage = followingNodeList.slice(index + 1).filter(function (node0) {
return node0.nodeInfo.pageNumbers.indexOf(pageNumber + 1) > -1;
});

var previousNodesOnPage = followingNodeList.slice(0, index).filter(function (node0) {
return node0.nodeInfo.pageNumbers.indexOf(pageNumber) > -1;
});

if (
pageBreakBeforeFct(
node.nodeInfo,
followingNodesOnPage.map(function (node) {
return node.nodeInfo;
}),
nodesOnNextPage.map(function (node) {
return node.nodeInfo;
}),
previousNodesOnPage.map(function (node) {
return node.nodeInfo;
}))) {
var followingNodesOnPage = [];
var nodesOnNextPage = [];
var previousNodesOnPage = [];
for (var ii = index + 1, l = linearNodeList.length; ii < l; ii++) {
if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber) > -1) {
followingNodesOnPage.push(linearNodeList[ii].nodeInfo);
}
if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber + 1) > -1) {
nodesOnNextPage.push(linearNodeList[ii].nodeInfo);
}
}
for (var ii = 0; ii < index; ii++) {
if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber) > -1) {
previousNodesOnPage.push(linearNodeList[ii].nodeInfo);
}
}
if (pageBreakBeforeFct(node.nodeInfo, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage)) {
node.pageBreak = 'before';
return true;
}
}
});
}

return false;
}

this.docPreprocessor = new DocPreprocessor();
Expand Down

0 comments on commit 38f92c2

Please sign in to comment.