Skip to content

Commit

Permalink
Merge pull request #2775 from fe-cj/fix/issues-1959-2625
Browse files Browse the repository at this point in the history
Fixes issues #1959 and #2625
  • Loading branch information
liborm85 authored Sep 4, 2024
2 parents 1077279 + 2e58c8b commit 3e23573
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 @@ -65,9 +65,9 @@ class DocumentContext extends EventEmitter {
}
}

markEnding(endingCell) {
markEnding(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 @@ -579,6 +579,11 @@ class LayoutBuilder {
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 @@ -587,9 +592,15 @@ class LayoutBuilder {
this.processNode(column);
addAll(positions, column.positions);
} else if (column._columnEndingContext) {
let 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
this.writer.context().markEnding(column);
this.writer.context().markEnding(column, originalXOffset);
}
}

Expand All @@ -607,6 +618,11 @@ class LayoutBuilder {
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 3e23573

Please sign in to comment.