From 1f07ccd8de25939b2616c9ab4f4d318bd6de51fd Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Wed, 4 Sep 2024 17:37:40 +0200 Subject: [PATCH] backport PR #2775 --- src/documentContext.js | 4 ++-- src/layoutBuilder.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/documentContext.js b/src/documentContext.js index c422743d3..3e337a38b 100644 --- a/src/documentContext.js +++ b/src/documentContext.js @@ -68,9 +68,9 @@ DocumentContext.prototype.calculateBottomMost = function (destContext, endingCel } }; -DocumentContext.prototype.markEnding = function (endingCell) { +DocumentContext.prototype.markEnding = function (endingCell, originalXOffset) { this.page = endingCell._columnEndingContext.page; - this.x = endingCell._columnEndingContext.x; + this.x = endingCell._columnEndingContext.x + originalXOffset; this.y = endingCell._columnEndingContext.y; this.availableWidth = endingCell._columnEndingContext.availableWidth; this.availableHeight = endingCell._columnEndingContext.availableHeight; diff --git a/src/layoutBuilder.js b/src/layoutBuilder.js index bdc54910f..b6d7270df 100644 --- a/src/layoutBuilder.js +++ b/src/layoutBuilder.js @@ -559,6 +559,11 @@ LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, if (startingSpanCell && startingSpanCell._endingCell) { // Reference to the last cell of the rowspan endingSpanCell = startingSpanCell._endingCell; + // Store if we are in an unbreakable block when we save the context and the originalX + if (this.writer.transactionLevel > 0) { + endingSpanCell._isUnbreakableContext = true; + endingSpanCell._originalXOffset = this.writer.originalX; + } } // We pass the endingSpanCell reference to store the context just after processing rowspan cell @@ -567,9 +572,15 @@ LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, self.processNode(column); addAll(positions, column.positions); } else if (column._columnEndingContext) { + var originalXOffset = 0; + // If context was saved from an unbreakable block and we are not in an unbreakable block anymore + // We have to sum the originalX (X before starting unbreakable block) to X + if (column._isUnbreakableContext && !this.writer.transactionLevel) { + originalXOffset = column._originalXOffset; + } // row-span ending // Recover the context after processing the rowspanned cell - self.writer.context().markEnding(column); + self.writer.context().markEnding(column, originalXOffset); } } @@ -587,6 +598,11 @@ LayoutBuilder.prototype.processRow = function (columns, widths, gaps, tableBody, if (startingSpanCell) { // Context will be stored here (ending cell) endingSpanCell = startingSpanCell._endingCell; + // Store if we are in an unbreakable block when we save the context and the originalX + if (this.writer.transactionLevel > 0) { + endingSpanCell._isUnbreakableContext = true; + endingSpanCell._originalXOffset = this.writer.originalX; + } } } }