Skip to content

Commit

Permalink
backport PR #2775
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Sep 4, 2024
1 parent c6d5d51 commit 1f07ccd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/documentContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion src/layoutBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

Expand All @@ -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;
}
}
}
}
Expand Down

0 comments on commit 1f07ccd

Please sign in to comment.