Skip to content

Commit 3e23573

Browse files
authored
Merge pull request #2775 from fe-cj/fix/issues-1959-2625
Fixes issues #1959 and #2625
2 parents 1077279 + 2e58c8b commit 3e23573

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/DocumentContext.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class DocumentContext extends EventEmitter {
6565
}
6666
}
6767

68-
markEnding(endingCell) {
68+
markEnding(endingCell, originalXOffset) {
6969
this.page = endingCell._columnEndingContext.page;
70-
this.x = endingCell._columnEndingContext.x;
70+
this.x = endingCell._columnEndingContext.x + originalXOffset;
7171
this.y = endingCell._columnEndingContext.y;
7272
this.availableWidth = endingCell._columnEndingContext.availableWidth;
7373
this.availableHeight = endingCell._columnEndingContext.availableHeight;

src/LayoutBuilder.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ class LayoutBuilder {
579579
if (startingSpanCell && startingSpanCell._endingCell) {
580580
// Reference to the last cell of the rowspan
581581
endingSpanCell = startingSpanCell._endingCell;
582+
// Store if we are in an unbreakable block when we save the context and the originalX
583+
if (this.writer.transactionLevel > 0) {
584+
endingSpanCell._isUnbreakableContext = true;
585+
endingSpanCell._originalXOffset = this.writer.originalX;
586+
}
582587
}
583588

584589
// We pass the endingSpanCell reference to store the context just after processing rowspan cell
@@ -587,9 +592,15 @@ class LayoutBuilder {
587592
this.processNode(column);
588593
addAll(positions, column.positions);
589594
} else if (column._columnEndingContext) {
595+
let originalXOffset = 0;
596+
// If context was saved from an unbreakable block and we are not in an unbreakable block anymore
597+
// We have to sum the originalX (X before starting unbreakable block) to X
598+
if (column._isUnbreakableContext && !this.writer.transactionLevel) {
599+
originalXOffset = column._originalXOffset;
600+
}
590601
// row-span ending
591602
// Recover the context after processing the rowspanned cell
592-
this.writer.context().markEnding(column);
603+
this.writer.context().markEnding(column, originalXOffset);
593604
}
594605
}
595606

@@ -607,6 +618,11 @@ class LayoutBuilder {
607618
if (startingSpanCell) {
608619
// Context will be stored here (ending cell)
609620
endingSpanCell = startingSpanCell._endingCell;
621+
// Store if we are in an unbreakable block when we save the context and the originalX
622+
if (this.writer.transactionLevel > 0) {
623+
endingSpanCell._isUnbreakableContext = true;
624+
endingSpanCell._originalXOffset = this.writer.originalX;
625+
}
610626
}
611627
}
612628
}

0 commit comments

Comments
 (0)