From 9fc18cf6a21c032f393d1623ae88dab4f9fb6e30 Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 8 Nov 2023 10:03:12 +0330 Subject: [PATCH 01/24] just use beginColumn functionality --- src/documentContext.js | 81 +++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/documentContext.js b/src/documentContext.js index 2f0d2f4a0..268ed7334 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -227,47 +227,48 @@ var getPageSize = function (currentPage, newPageOrientation) { // Write a moveToNextColumn method that will move to the next column in the current page, or the first column of the next page if the current page is full DocumentContext.prototype.moveToNextColumn = function () { var prevY = this.y; - - var newSnapshots = this.snapshots.flatMap((originalSnapshot, i, allSnapshots) => { - //if (i === 0) return [originalSnapshot]; - - var newSnapshot = Object.assign({}, originalSnapshot); - newSnapshot.overflowed = true; // IMPORTANT - - // FIXME: Calculate "x" and "availableWidth" properly - //newSnapshot.x += this.availableWidth - this.pageMargins.left; // for basic text - newSnapshot.x += originalSnapshot.availableWidth; // for tables - newSnapshot.y = allSnapshots[0].y; // 40 or 43 ??? - newSnapshot.page = originalSnapshot.page; - newSnapshot.availableHeight = allSnapshots[0].availableHeight; // -6 - newSnapshot.availableWidth = this.availableWidth; - - newSnapshot.bottomMost = { - x: newSnapshot.x, - y: newSnapshot.y, - page: newSnapshot.page, - availableHeight: newSnapshot.availableHeight, - availableWidth5: newSnapshot.availableWidth, - }; - newSnapshot.endingCell = originalSnapshot.endingCell; - newSnapshot.lastColumnWidth = originalSnapshot.lastColumnWidth; // Flexible width? - - return [originalSnapshot, newSnapshot]; - }); + this.beginColumn(this.availableWidth, 0, this.endingCell) + + // var newSnapshots = this.snapshots.flatMap((originalSnapshot, i, allSnapshots) => { + // //if (i === 0) return [originalSnapshot]; + + // var newSnapshot = Object.assign({}, originalSnapshot); + // newSnapshot.overflowed = true; // IMPORTANT + + // // FIXME: Calculate "x" and "availableWidth" properly + // //newSnapshot.x += this.availableWidth - this.pageMargins.left; // for basic text + // newSnapshot.x += originalSnapshot.availableWidth; // for tables + // newSnapshot.y = allSnapshots[0].y; // 40 or 43 ??? + // newSnapshot.page = originalSnapshot.page; + // newSnapshot.availableHeight = allSnapshots[0].availableHeight; // -6 + // newSnapshot.availableWidth = this.availableWidth; + + // newSnapshot.bottomMost = { + // x: newSnapshot.x, + // y: newSnapshot.y, + // page: newSnapshot.page, + // availableHeight: newSnapshot.availableHeight, + // availableWidth5: newSnapshot.availableWidth, + // }; + // newSnapshot.endingCell = originalSnapshot.endingCell; + // newSnapshot.lastColumnWidth = originalSnapshot.lastColumnWidth; // Flexible width? + + // return [originalSnapshot, newSnapshot]; + // }); - this.snapshots = newSnapshots; - - // FIXME: Replace hardcoded values with proper variables - var yOffset = 0; // 0 for text, 3 for tables, -5 for tables with repeatble headers - var colLeftOffset = 0; // default = 0 for tables, 5 in LayoutBuilder - - this.x += this.snapshots.at(-1).x + colLeftOffset; - this.y = this.snapshots.at(-1).y + yOffset; - //this.page = this.snapshots.at(-1).page; - this.availableHeight = this.snapshots.at(-1).availableHeight - (yOffset * 2); - this.availableWidth = this.snapshots.at(-1).availableWidth; - //this.lastColumnWidth = this.snapshots.at(-1).lastColumnWidth; - //this.endingCell = this.snapshots.at(-1).endingCell; + // this.snapshots = newSnapshots; + + // // FIXME: Replace hardcoded values with proper variables + // var yOffset = 0; // 0 for text, 3 for tables, -5 for tables with repeatble headers + // var colLeftOffset = 0; // default = 0 for tables, 5 in LayoutBuilder + + // this.x += this.snapshots.at(-1).x + colLeftOffset; + // this.y = this.snapshots.at(-1).y + yOffset; + // //this.page = this.snapshots.at(-1).page; + // this.availableHeight = this.snapshots.at(-1).availableHeight - (yOffset * 2); + // this.availableWidth = this.snapshots.at(-1).availableWidth; + // //this.lastColumnWidth = this.snapshots.at(-1).lastColumnWidth; + // //this.endingCell = this.snapshots.at(-1).endingCell; return { containerX: this.snapshots.at(-1).x, From 0c50aa2b9754fe7d6499e22fc9c8b7fda6a22665 Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 8 Nov 2023 10:04:10 +0330 Subject: [PATCH 02/24] on this step don't need overflowed --- src/documentContext.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/documentContext.js b/src/documentContext.js index 268ed7334..6038b173f 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -95,7 +95,7 @@ DocumentContext.prototype.saveContextInEndingCell = function (endingCell) { DocumentContext.prototype.completeColumnGroup = function (height) { var saved = this.snapshots.pop(); - if (saved.overflowed) this.snapshots.pop(); + // if (saved.overflowed) this.snapshots.pop(); this.calculateBottomMost(saved); From e8ccc1d935f0d043d7615addcdf24ebabf24b579 Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 8 Nov 2023 10:04:51 +0330 Subject: [PATCH 03/24] detect width overflow on context --- src/documentContext.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/documentContext.js b/src/documentContext.js index 6038b173f..01a014f11 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -62,6 +62,8 @@ DocumentContext.prototype.beginColumn = function (width, offset, endingCell) { this.availableHeight = saved.availableHeight; this.lastColumnWidth = width; + var contextWidthOverflow = this.x > this.snapshots[0].availableWidth; + if (contextWidthOverflow) console.log({ contextWidthOverflow }) }; DocumentContext.prototype.calculateBottomMost = function (destContext) { From c213f19e90de6e5f6aa72755ce07920e978cf50a Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 8 Nov 2023 10:07:07 +0330 Subject: [PATCH 04/24] just use original version --- src/layoutBuilder.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/layoutBuilder.js b/src/layoutBuilder.js index c7e44ed2e..f707d09df 100644 --- a/src/layoutBuilder.js +++ b/src/layoutBuilder.js @@ -513,11 +513,9 @@ LayoutBuilder.prototype.processColumns = function (columnNode) { LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, tableRow, height) { var self = this; - var pageBreaks = [], columnBreaks = [], positions = []; + var pageBreaks = [], positions = []; - // FIXME: Currently the `TraversalTracker.auto` method only supports ONE event and ONE callback, maybe expand to add support for multiple events and callbacks - //this.tracker.auto('pageChanged', storePageBreakData, function () { - this.tracker.auto('columnChanged', storeColumnBreakData, function () { + this.tracker.auto('pageChanged', storePageBreakData, function () { widths = widths || columns; self.writer.context().beginColumnGroup(); @@ -546,11 +544,7 @@ LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, self.writer.context().completeColumnGroup(height); }); - return { pageBreaks: pageBreaks, positions: positions, columnBreaks: columnBreaks }; - - function storeColumnBreakData(data) { - columnBreaks.push(data); - } + return { pageBreaks: pageBreaks, positions: positions }; function storePageBreakData(data) { var pageDesc; From 8e69aa8baa618671f636cb210e43f17966451e82 Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 8 Nov 2023 10:08:09 +0330 Subject: [PATCH 05/24] detect width overflow on process row --- src/layoutBuilder.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/layoutBuilder.js b/src/layoutBuilder.js index f707d09df..17b348ece 100644 --- a/src/layoutBuilder.js +++ b/src/layoutBuilder.js @@ -518,12 +518,16 @@ LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, this.tracker.auto('pageChanged', storePageBreakData, function () { widths = widths || columns; + var pageAvailableWidth = self.writer.context().availableWidth; self.writer.context().beginColumnGroup(); for (var i = 0, l = columns.length; i < l; i++) { var column = columns[i]; var width = widths[i]._calcWidth; var leftOffset = colLeftOffset(i); + var context = self.writer.context(); + var widthOverflow = context.x + width > pageAvailableWidth + if (widthOverflow) console.log({ widthOverflow }) if (column.colSpan && column.colSpan > 1) { for (var j = 1; j < column.colSpan; j++) { From aaa4acd00b6e0487bf1a9420175c73cd7cd59afc Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 8 Nov 2023 10:09:06 +0330 Subject: [PATCH 06/24] just use move next column functionality --- src/pageElementWriter.js | 67 +++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/src/pageElementWriter.js b/src/pageElementWriter.js index b4a9665e9..fce986a65 100644 --- a/src/pageElementWriter.js +++ b/src/pageElementWriter.js @@ -21,39 +21,50 @@ function PageElementWriter(context, tracker) { function fitOnPage(self, addFct) { var position = addFct(self); + const sneakyColumn = true; if (!position) { - // TODO: Swap the hardcoded boolean check below with an option flag inside columns - // eslint-disable-next-line no-constant-condition - if (true) { - if (!self.writer.context.snapshots.at(-1).overflowed) { - - // BUG: Only works with table columns - self.moveToNextColumn(); - - position = addFct(self); - } else { - position = addFct(self); - } - } - - - if (!position) { - while (self.writer.context.snapshots.at(-1).overflowed) { - var popped = self.writer.context.snapshots.pop(); - - var snap = self.writer.context.snapshots.at(-1); - self.writer.context.x = snap.x; - self.writer.context.y = snap.y; - self.writer.context.availableHeight = snap.availableHeight; - self.writer.context.availableWidth = popped.availableWidth; - self.writer.context.lastColumnWidth = snap.lastColumnWidth; - self.writer.context.endingCell = snap.endingCell; - //self.writer.context.page = snap.page; - } + if (sneakyColumn) { + self.moveToNextColumn(); + position = addFct(self); + } else { self.moveToNextPage(); position = addFct(self); } } + + // if (!position) { + // // TODO: Swap the hardcoded boolean check below with an option flag inside columns + // // eslint-disable-next-line no-constant-condition + // if (false) { + // if (!self.writer.context.snapshots.at(-1).overflowed) { + + // // BUG: Only works with table columns + // self.moveToNextColumn(); + + // position = addFct(self); + // } else { + // position = addFct(self); + // } + // } + + + // if (!position) { + // // while (self.writer.context.snapshots.at(-1).overflowed) { + // // var popped = self.writer.context.snapshots.pop(); + + // // var snap = self.writer.context.snapshots.at(-1); + // // self.writer.context.x = snap.x; + // // self.writer.context.y = snap.y; + // // self.writer.context.availableHeight = snap.availableHeight; + // // self.writer.context.availableWidth = popped.availableWidth; + // // self.writer.context.lastColumnWidth = snap.lastColumnWidth; + // // self.writer.context.endingCell = snap.endingCell; + // // //self.writer.context.page = snap.page; + // // } + // self.moveToNextPage(); + // position = addFct(self); + // } + // } return position; } From fb42ff95c4eab81e30bdf2167b429ba88ac038a0 Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 8 Nov 2023 10:09:40 +0330 Subject: [PATCH 07/24] original functionality --- src/tableProcessor.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tableProcessor.js b/src/tableProcessor.js index 4ad093f92..da6234b27 100644 --- a/src/tableProcessor.js +++ b/src/tableProcessor.js @@ -351,7 +351,7 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks, column var ys = []; - var hasColumnBreaks = columnBreaks && columnBreaks.length > 0; + // var hasColumnBreaks = columnBreaks && columnBreaks.length > 0; var hasPageBreaks = pageBreaks && pageBreaks.length > 0; var body = this.tableNode.table.body; @@ -360,10 +360,10 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks, column page: hasPageBreaks ? pageBreaks[0].prevPage : endingPage }); - if (hasColumnBreaks) { - ys[ys.length - 1].y1 = columnBreaks[0].prevY; - ys.push({ y0: columnBreaks[0][this.headerRows > 0 ? 'contentY' : 'containerY'], page: ys[0].page }); - } + // if (hasColumnBreaks) { + // ys[ys.length - 1].y1 = columnBreaks[0].prevY; + // ys.push({ y0: columnBreaks[0][this.headerRows > 0 ? 'contentY' : 'containerY'], page: ys[0].page }); + // } if (hasPageBreaks) { for (i = 0, l = pageBreaks.length; i < l; i++) { From 552ae4a7876c1ba4161b7d7f07f375588011ab25 Mon Sep 17 00:00:00 2001 From: farzin Date: Tue, 14 Nov 2023 08:12:02 +0330 Subject: [PATCH 08/24] handle page width overflow --- src/documentContext.js | 7 +++++++ src/pageElementWriter.js | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/documentContext.js b/src/documentContext.js index 01a014f11..464690e75 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -228,6 +228,13 @@ var getPageSize = function (currentPage, newPageOrientation) { // FIXME: Complete the function // Write a moveToNextColumn method that will move to the next column in the current page, or the first column of the next page if the current page is full DocumentContext.prototype.moveToNextColumn = function () { + + const pageSnapshot = this.pageSnapshot(); + const pageAvailableWidth = pageSnapshot.availableWidth; + const nextColumnWidth = this.x + this.availableWidth; + const pageOverflow = nextColumnWidth > pageAvailableWidth + if (pageOverflow) return false; + var prevY = this.y; this.beginColumn(this.availableWidth, 0, this.endingCell) diff --git a/src/pageElementWriter.js b/src/pageElementWriter.js index fce986a65..973b78eb0 100644 --- a/src/pageElementWriter.js +++ b/src/pageElementWriter.js @@ -24,8 +24,13 @@ function fitOnPage(self, addFct) { const sneakyColumn = true; if (!position) { if (sneakyColumn) { - self.moveToNextColumn(); - position = addFct(self); + const nextColumn = self.moveToNextColumn(); + if (nextColumn === false) { + self.moveToNextPage(); + position = addFct(self); + } else { + position = addFct(self); + } } else { self.moveToNextPage(); position = addFct(self); @@ -116,7 +121,9 @@ PageElementWriter.prototype.addFragment = function (fragment, useBlockXOffset, u }; PageElementWriter.prototype.moveToNextColumn = function () { + var nextColumn = this.writer.context.moveToNextColumn(); + if (nextColumn == false) return nextColumn; this.repeatables.forEach(function (rep) { rep.xOffset = nextColumn.containerX; From f242e5f2b2899c45f96d2005a04e600bae31a7f4 Mon Sep 17 00:00:00 2001 From: farzin Date: Tue, 14 Nov 2023 19:52:40 +0330 Subject: [PATCH 09/24] remove log and whitespace --- src/documentContext.js | 8 +++----- src/layoutBuilder.js | 3 --- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/documentContext.js b/src/documentContext.js index 464690e75..e904dd789 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -62,8 +62,6 @@ DocumentContext.prototype.beginColumn = function (width, offset, endingCell) { this.availableHeight = saved.availableHeight; this.lastColumnWidth = width; - var contextWidthOverflow = this.x > this.snapshots[0].availableWidth; - if (contextWidthOverflow) console.log({ contextWidthOverflow }) }; DocumentContext.prototype.calculateBottomMost = function (destContext) { @@ -234,7 +232,7 @@ DocumentContext.prototype.moveToNextColumn = function () { const nextColumnWidth = this.x + this.availableWidth; const pageOverflow = nextColumnWidth > pageAvailableWidth if (pageOverflow) return false; - + var prevY = this.y; this.beginColumn(this.availableWidth, 0, this.endingCell) @@ -264,7 +262,7 @@ DocumentContext.prototype.moveToNextColumn = function () { // return [originalSnapshot, newSnapshot]; // }); - + // this.snapshots = newSnapshots; // // FIXME: Replace hardcoded values with proper variables @@ -278,7 +276,7 @@ DocumentContext.prototype.moveToNextColumn = function () { // this.availableWidth = this.snapshots.at(-1).availableWidth; // //this.lastColumnWidth = this.snapshots.at(-1).lastColumnWidth; // //this.endingCell = this.snapshots.at(-1).endingCell; - + return { containerX: this.snapshots.at(-1).x, containerY: this.snapshots.at(-1).y, diff --git a/src/layoutBuilder.js b/src/layoutBuilder.js index 17b348ece..3a465c9b7 100644 --- a/src/layoutBuilder.js +++ b/src/layoutBuilder.js @@ -525,9 +525,6 @@ LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, var column = columns[i]; var width = widths[i]._calcWidth; var leftOffset = colLeftOffset(i); - var context = self.writer.context(); - var widthOverflow = context.x + width > pageAvailableWidth - if (widthOverflow) console.log({ widthOverflow }) if (column.colSpan && column.colSpan > 1) { for (var j = 1; j < column.colSpan; j++) { From 1d23add3dd2d80bb231a906ae1a8522b4b4ea5d7 Mon Sep 17 00:00:00 2001 From: farzin Date: Tue, 14 Nov 2023 19:53:05 +0330 Subject: [PATCH 10/24] don't need currently --- src/pageElementWriter.js | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/pageElementWriter.js b/src/pageElementWriter.js index 973b78eb0..6233f3c63 100644 --- a/src/pageElementWriter.js +++ b/src/pageElementWriter.js @@ -124,28 +124,28 @@ PageElementWriter.prototype.moveToNextColumn = function () { var nextColumn = this.writer.context.moveToNextColumn(); if (nextColumn == false) return nextColumn; - - this.repeatables.forEach(function (rep) { - rep.xOffset = nextColumn.containerX; - rep.yOffset = nextColumn.containerY; - // FIXME: This number is currently set based on limited trial and error. Try to set it dynamically. - rep.height -= 1; - if (isUndefined(rep.insertedOnPages[this.writer.context.page])) { - // FIXME: Make sure the line below can be removed safely without affecting the functionality of repeatables such as table header rows. - //rep.insertedOnPages[this.writer.context.page] = true; - this.writer.addFragment(rep, true, true); - } else { - this.writer.context.moveDown(rep.height); - } - }, this); - - this.writer.tracker.emit('columnChanged', { - containerX: nextColumn.containerX, - containerY: nextColumn.containerY, - contentX: nextColumn.contentX, - contentY: nextColumn.contentY, - prevY: nextColumn.prevY, - }); + + // this.repeatables.forEach(function (rep) { + // rep.xOffset = nextColumn.containerX; + // rep.yOffset = nextColumn.containerY; + // // FIXME: This number is currently set based on limited trial and error. Try to set it dynamically. + // rep.height -= 1; + // if (isUndefined(rep.insertedOnPages[this.writer.context.page])) { + // // FIXME: Make sure the line below can be removed safely without affecting the functionality of repeatables such as table header rows. + // //rep.insertedOnPages[this.writer.context.page] = true; + // this.writer.addFragment(rep, true, true); + // } else { + // this.writer.context.moveDown(rep.height); + // } + // }, this); + + // this.writer.tracker.emit('columnChanged', { + // containerX: nextColumn.containerX, + // containerY: nextColumn.containerY, + // contentX: nextColumn.contentX, + // contentY: nextColumn.contentY, + // prevY: nextColumn.prevY, + // }); }; PageElementWriter.prototype.moveToNextPage = function (pageOrientation) { From f7163448033565a4c574ad2c0ea56b4241407ad8 Mon Sep 17 00:00:00 2001 From: farzin Date: Tue, 14 Nov 2023 19:54:45 +0330 Subject: [PATCH 11/24] handled column in new page when width overflow happen --- src/pageElementWriter.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pageElementWriter.js b/src/pageElementWriter.js index 6233f3c63..098b3c0cf 100644 --- a/src/pageElementWriter.js +++ b/src/pageElementWriter.js @@ -26,8 +26,18 @@ function fitOnPage(self, addFct) { if (sneakyColumn) { const nextColumn = self.moveToNextColumn(); if (nextColumn === false) { + const context = self.writer.context; + const columnWidth = context.availableWidth; + const endingCell = context.endingCell; + // TODO: offset have to calculate from page snapshot, if offset set in + // document definition column then in new column don't be applied. + const offset = undefined; + + context.completeColumnGroup(); self.moveToNextPage(); position = addFct(self); + context.beginColumnGroup(); + context.beginColumn(columnWidth, offset ,endingCell); } else { position = addFct(self); } From 7b8b8545ff3c30a532385eb5c5c5082457c8762e Mon Sep 17 00:00:00 2001 From: farzin Date: Sun, 19 Nov 2023 19:32:30 +0330 Subject: [PATCH 12/24] throw column break event --- src/documentContext.js | 6 ++++-- src/pageElementWriter.js | 15 ++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/documentContext.js b/src/documentContext.js index e904dd789..66f776264 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -234,6 +234,7 @@ DocumentContext.prototype.moveToNextColumn = function () { if (pageOverflow) return false; var prevY = this.y; + var prevX = this.x; this.beginColumn(this.availableWidth, 0, this.endingCell) // var newSnapshots = this.snapshots.flatMap((originalSnapshot, i, allSnapshots) => { @@ -278,11 +279,12 @@ DocumentContext.prototype.moveToNextColumn = function () { // //this.endingCell = this.snapshots.at(-1).endingCell; return { - containerX: this.snapshots.at(-1).x, - containerY: this.snapshots.at(-1).y, + containerX: pageSnapshot.x, + containerY: pageSnapshot.y, contentX: this.x, contentY: this.y, prevY: prevY, + prevX: prevX, }; }; diff --git a/src/pageElementWriter.js b/src/pageElementWriter.js index 098b3c0cf..b78c01036 100644 --- a/src/pageElementWriter.js +++ b/src/pageElementWriter.js @@ -149,13 +149,14 @@ PageElementWriter.prototype.moveToNextColumn = function () { // } // }, this); - // this.writer.tracker.emit('columnChanged', { - // containerX: nextColumn.containerX, - // containerY: nextColumn.containerY, - // contentX: nextColumn.contentX, - // contentY: nextColumn.contentY, - // prevY: nextColumn.prevY, - // }); + this.writer.tracker.emit('columnChanged', { + containerX: nextColumn.containerX, + containerY: nextColumn.containerY, + contentX: nextColumn.contentX, + contentY: nextColumn.contentY, + prevY: nextColumn.prevY, + prevX: nextColumn.prevX, + }); }; PageElementWriter.prototype.moveToNextPage = function (pageOrientation) { From 57081df0cc9eba3ebd4efef5229ae812e663b406 Mon Sep 17 00:00:00 2001 From: farzin Date: Sun, 19 Nov 2023 19:32:58 +0330 Subject: [PATCH 13/24] listen to column break --- src/tableProcessor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tableProcessor.js b/src/tableProcessor.js index da6234b27..0c7bd97ce 100644 --- a/src/tableProcessor.js +++ b/src/tableProcessor.js @@ -135,6 +135,7 @@ TableProcessor.prototype.beginRow = function (rowIndex, writer) { this.rowCallback = this.onRowBreak(rowIndex, writer); writer.tracker.startTracking('pageChanged', this.rowCallback); + writer.tracker.startTracking('columnChanged', this.rowCallback); if (this.dontBreakRows) { writer.beginUnbreakableBlock(); } From 7f0dff65c20563b360fde6dee5e2cfefdbd1074e Mon Sep 17 00:00:00 2001 From: farzin Date: Sun, 19 Nov 2023 19:33:15 +0330 Subject: [PATCH 14/24] listen to column change --- src/tableProcessor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tableProcessor.js b/src/tableProcessor.js index 0c7bd97ce..1ddc7adb0 100644 --- a/src/tableProcessor.js +++ b/src/tableProcessor.js @@ -342,6 +342,7 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks, column var l, i; var self = this; writer.tracker.stopTracking('pageChanged', this.rowCallback); + writer.tracker.stopTracking('columnChanged', this.rowCallback); writer.context().moveDown(this.layout.paddingBottom(rowIndex, this.tableNode)); writer.context().availableHeight += this.reservedAtBottom; From 50407c5007ea73c029cfd7fdeb7ffb8661f7d015 Mon Sep 17 00:00:00 2001 From: farzin Date: Sun, 19 Nov 2023 19:33:50 +0330 Subject: [PATCH 15/24] handel column change break --- src/tableProcessor.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tableProcessor.js b/src/tableProcessor.js index 1ddc7adb0..ffe75828f 100644 --- a/src/tableProcessor.js +++ b/src/tableProcessor.js @@ -353,7 +353,7 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks, column var ys = []; - // var hasColumnBreaks = columnBreaks && columnBreaks.length > 0; + var hasColumnBreaks = columnBreaks && columnBreaks.length > 0; var hasPageBreaks = pageBreaks && pageBreaks.length > 0; var body = this.tableNode.table.body; @@ -362,10 +362,10 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks, column page: hasPageBreaks ? pageBreaks[0].prevPage : endingPage }); - // if (hasColumnBreaks) { - // ys[ys.length - 1].y1 = columnBreaks[0].prevY; - // ys.push({ y0: columnBreaks[0][this.headerRows > 0 ? 'contentY' : 'containerY'], page: ys[0].page }); - // } + if (hasColumnBreaks) { + ys[ys.length - 1].y1 = columnBreaks[0].prevY; + ys.push({ y0: columnBreaks[0][this.headerRows > 0 ? 'contentY' : 'containerY'], page: ys[0].page }); + } if (hasPageBreaks) { for (i = 0, l = pageBreaks.length; i < l; i++) { From bfb3c1388b98c8890f274360e584224cca4afbe3 Mon Sep 17 00:00:00 2001 From: farzin Date: Sun, 19 Nov 2023 19:34:46 +0330 Subject: [PATCH 16/24] Add snapshot type --- src/documentContext.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/documentContext.js b/src/documentContext.js index 66f776264..4c855ce32 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -28,7 +28,7 @@ function DocumentContext(pageSize, pageMargins) { this.addPage(pageSize); } -DocumentContext.prototype.beginColumnGroup = function () { +DocumentContext.prototype.beginColumnGroup = function ({ type }) { this.snapshots.push({ x: this.x, y: this.y, @@ -43,7 +43,8 @@ DocumentContext.prototype.beginColumnGroup = function () { page: this.page }, endingCell: this.endingCell, - lastColumnWidth: this.lastColumnWidth + lastColumnWidth: this.lastColumnWidth, + type, }); this.lastColumnWidth = 0; From 639e1cb36f6e9d64b78e14c2f6f7ab6e1c3dc798 Mon Sep 17 00:00:00 2001 From: farzin Date: Sun, 19 Nov 2023 19:35:52 +0330 Subject: [PATCH 17/24] Set snapshot type when create new column group --- src/pageElementWriter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pageElementWriter.js b/src/pageElementWriter.js index b78c01036..258a98fb5 100644 --- a/src/pageElementWriter.js +++ b/src/pageElementWriter.js @@ -32,12 +32,12 @@ function fitOnPage(self, addFct) { // TODO: offset have to calculate from page snapshot, if offset set in // document definition column then in new column don't be applied. const offset = undefined; - + context.completeColumnGroup(); self.moveToNextPage(); - position = addFct(self); - context.beginColumnGroup(); - context.beginColumn(columnWidth, offset ,endingCell); + position = addFct(self); + context.beginColumnGroup({ type: 'column' }); + context.beginColumn(columnWidth, offset, endingCell); } else { position = addFct(self); } From 325b787b013c0e8b7210b410c52474459a46e09a Mon Sep 17 00:00:00 2001 From: farzin Date: Sun, 19 Nov 2023 19:36:51 +0330 Subject: [PATCH 18/24] listen to column change event --- src/layoutBuilder.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/layoutBuilder.js b/src/layoutBuilder.js index 3a465c9b7..0dbb1a6c5 100644 --- a/src/layoutBuilder.js +++ b/src/layoutBuilder.js @@ -513,13 +513,19 @@ LayoutBuilder.prototype.processColumns = function (columnNode) { LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, tableRow, height) { var self = this; - var pageBreaks = [], positions = []; + var pageBreaks = [], columnBreaks = [], positions = []; - this.tracker.auto('pageChanged', storePageBreakData, function () { + // FIXME: Currently the `TraversalTracker.auto` method only supports ONE event and ONE callback, maybe expand to add support for multiple events and callbacks + // this.tracker.auto('pageChanged', storePageBreakData, newFuncProcess); + this.tracker.auto('columnChanged', storeColumnBreakData, newFuncProcess); + + return { pageBreaks: pageBreaks, positions: positions, columnBreaks: columnBreaks }; + + function newFuncProcess() { widths = widths || columns; - var pageAvailableWidth = self.writer.context().availableWidth; - self.writer.context().beginColumnGroup(); + const columnType = tableBody ? 'table' : 'column'; + self.writer.context().beginColumnGroup({ type: columnType }); for (var i = 0, l = columns.length; i < l; i++) { var column = columns[i]; @@ -543,9 +549,11 @@ LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, } self.writer.context().completeColumnGroup(height); - }); + } - return { pageBreaks: pageBreaks, positions: positions }; + function storeColumnBreakData(data) { + columnBreaks.push(data); + } function storePageBreakData(data) { var pageDesc; From d019761f61507e1cd4d4a73b368e9fb2fe3a571e Mon Sep 17 00:00:00 2001 From: farzin Date: Sun, 19 Nov 2023 19:37:36 +0330 Subject: [PATCH 19/24] handel overflow on table --- src/documentContext.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/documentContext.js b/src/documentContext.js index 4c855ce32..6ba5509b3 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -229,6 +229,11 @@ var getPageSize = function (currentPage, newPageOrientation) { DocumentContext.prototype.moveToNextColumn = function () { const pageSnapshot = this.pageSnapshot(); + const currentSnapshot = this.snapshots[this.snapshots.length - 1]; + + if (currentSnapshot.type == 'table') { + this.completeColumnGroup(); + } const pageAvailableWidth = pageSnapshot.availableWidth; const nextColumnWidth = this.x + this.availableWidth; const pageOverflow = nextColumnWidth > pageAvailableWidth @@ -238,6 +243,11 @@ DocumentContext.prototype.moveToNextColumn = function () { var prevX = this.x; this.beginColumn(this.availableWidth, 0, this.endingCell) + if (currentSnapshot.type == 'table') { + this.beginColumnGroup({type: 'table' }); + this.beginColumn(currentSnapshot.availableWidth, 0, this.endingCell) + } + // var newSnapshots = this.snapshots.flatMap((originalSnapshot, i, allSnapshots) => { // //if (i === 0) return [originalSnapshot]; From 92e8da81b92b71ddb6def8266381ddf0d32b7aa3 Mon Sep 17 00:00:00 2001 From: farzin Date: Tue, 21 Nov 2023 18:52:24 +0330 Subject: [PATCH 20/24] fix first column and next page crash --- src/documentContext.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/documentContext.js b/src/documentContext.js index 6ba5509b3..bd8938471 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -96,7 +96,6 @@ DocumentContext.prototype.saveContextInEndingCell = function (endingCell) { DocumentContext.prototype.completeColumnGroup = function (height) { var saved = this.snapshots.pop(); - // if (saved.overflowed) this.snapshots.pop(); this.calculateBottomMost(saved); @@ -229,23 +228,32 @@ var getPageSize = function (currentPage, newPageOrientation) { DocumentContext.prototype.moveToNextColumn = function () { const pageSnapshot = this.pageSnapshot(); - const currentSnapshot = this.snapshots[this.snapshots.length - 1]; - - if (currentSnapshot.type == 'table') { + const currentSnapshot = this.snapshots[this.snapshots.length - 1]; + const isTable = currentSnapshot.type == 'table'; + let tableWidth; + if (isTable) { + tableWidth = this.availableWidth; this.completeColumnGroup(); } const pageAvailableWidth = pageSnapshot.availableWidth; const nextColumnWidth = this.x + this.availableWidth; const pageOverflow = nextColumnWidth > pageAvailableWidth - if (pageOverflow) return false; + if (pageOverflow) { + if (isTable) { + this.beginColumnGroup({ type: 'table' }); + this.beginColumn(currentSnapshot.availableWidth, undefined, this.endingCell); + } + return false + }; var prevY = this.y; var prevX = this.x; - this.beginColumn(this.availableWidth, 0, this.endingCell) - if (currentSnapshot.type == 'table') { - this.beginColumnGroup({type: 'table' }); - this.beginColumn(currentSnapshot.availableWidth, 0, this.endingCell) + this.beginColumn(this.availableWidth, undefined, this.endingCell) + + if (isTable) { + this.beginColumnGroup({ type: 'table' }); + this.beginColumn(tableWidth, undefined, this.endingCell); } // var newSnapshots = this.snapshots.flatMap((originalSnapshot, i, allSnapshots) => { From 248d36430ea6902f4e761a1f834eac45fb17d853 Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 22 Nov 2023 17:43:00 +0330 Subject: [PATCH 21/24] set table offset --- src/documentContext.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/documentContext.js b/src/documentContext.js index bd8938471..494ee089f 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -231,8 +231,11 @@ DocumentContext.prototype.moveToNextColumn = function () { const currentSnapshot = this.snapshots[this.snapshots.length - 1]; const isTable = currentSnapshot.type == 'table'; let tableWidth; + let tableOffset; if (isTable) { tableWidth = this.availableWidth; + // TODO: default offset must be replace with set value + tableOffset = 5 this.completeColumnGroup(); } const pageAvailableWidth = pageSnapshot.availableWidth; @@ -241,7 +244,7 @@ DocumentContext.prototype.moveToNextColumn = function () { if (pageOverflow) { if (isTable) { this.beginColumnGroup({ type: 'table' }); - this.beginColumn(currentSnapshot.availableWidth, undefined, this.endingCell); + this.beginColumn(currentSnapshot.availableWidth, tableOffset, this.endingCell); } return false }; @@ -253,7 +256,7 @@ DocumentContext.prototype.moveToNextColumn = function () { if (isTable) { this.beginColumnGroup({ type: 'table' }); - this.beginColumn(tableWidth, undefined, this.endingCell); + this.beginColumn(tableWidth, tableOffset, this.endingCell); } // var newSnapshots = this.snapshots.flatMap((originalSnapshot, i, allSnapshots) => { From 7f2e29a7fb10d5ad7da7db4f603137c203755108 Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 22 Nov 2023 17:44:25 +0330 Subject: [PATCH 22/24] set table width when overflow happen --- src/documentContext.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/documentContext.js b/src/documentContext.js index 494ee089f..3f5bf082d 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -244,7 +244,7 @@ DocumentContext.prototype.moveToNextColumn = function () { if (pageOverflow) { if (isTable) { this.beginColumnGroup({ type: 'table' }); - this.beginColumn(currentSnapshot.availableWidth, tableOffset, this.endingCell); + this.beginColumn(tableWidth, tableOffset, this.endingCell); } return false }; From 56a6f1750856ab49dfc486cc4348be497a9bc2be Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 22 Nov 2023 17:45:47 +0330 Subject: [PATCH 23/24] handel table when page change --- src/pageElementWriter.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/pageElementWriter.js b/src/pageElementWriter.js index 258a98fb5..a61d80926 100644 --- a/src/pageElementWriter.js +++ b/src/pageElementWriter.js @@ -27,17 +27,33 @@ function fitOnPage(self, addFct) { const nextColumn = self.moveToNextColumn(); if (nextColumn === false) { const context = self.writer.context; - const columnWidth = context.availableWidth; - const endingCell = context.endingCell; // TODO: offset have to calculate from page snapshot, if offset set in // document definition column then in new column don't be applied. const offset = undefined; + const currentSnapshot = context.snapshots[context.snapshots.length - 1]; + const isTable = currentSnapshot.type == 'table'; + let tableWidth; + let tableOffset; + if (isTable) { + tableWidth = context.availableWidth; + tableOffset = 5 + context.completeColumnGroup(); + } + + const columnWidth = context.availableWidth; + const endingCell = context.endingCell; + context.completeColumnGroup(); self.moveToNextPage(); - position = addFct(self); context.beginColumnGroup({ type: 'column' }); context.beginColumn(columnWidth, offset, endingCell); + + if (isTable) { + context.beginColumnGroup({ type: 'table' }); + context.beginColumn(tableWidth, tableOffset, endingCell); + } + position = addFct(self); } else { position = addFct(self); } @@ -134,7 +150,7 @@ PageElementWriter.prototype.moveToNextColumn = function () { var nextColumn = this.writer.context.moveToNextColumn(); if (nextColumn == false) return nextColumn; - + // this.repeatables.forEach(function (rep) { // rep.xOffset = nextColumn.containerX; // rep.yOffset = nextColumn.containerY; From 7abe4631e9a063dbc5717f4a2f525e56fc7e624d Mon Sep 17 00:00:00 2001 From: farzin Date: Wed, 22 Nov 2023 17:49:11 +0330 Subject: [PATCH 24/24] use Y position with out condition --- src/tableProcessor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tableProcessor.js b/src/tableProcessor.js index ffe75828f..380c69879 100644 --- a/src/tableProcessor.js +++ b/src/tableProcessor.js @@ -364,7 +364,7 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks, column if (hasColumnBreaks) { ys[ys.length - 1].y1 = columnBreaks[0].prevY; - ys.push({ y0: columnBreaks[0][this.headerRows > 0 ? 'contentY' : 'containerY'], page: ys[0].page }); + ys.push({ y0: columnBreaks[0].contentY, page: ys[0].page }); } if (hasPageBreaks) {