Skip to content

Commit

Permalink
fix: Table cell with rowspan may disappear after page break
Browse files Browse the repository at this point in the history
- fix #1403
  • Loading branch information
MurakamiShinyu committed Jan 9, 2025
1 parent ef3387f commit 690b3de
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/vivliostyle/repetitive-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ export class RepetitiveElements
if (nodeContext && !this.affectTo(nodeContext)) {
return offset;
}
if (nodeContext && this.isAfterLastContent(nodeContext)) {
if (
!this.enableSkippingFooter &&
nodeContext &&
this.isAfterLastContent(nodeContext)
) {
offset += this.footerHeight;
}
if (!this.enableSkippingHeader) {
Expand Down
43 changes: 40 additions & 3 deletions packages/core/src/vivliostyle/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,48 @@ export class InsideTableRowBreakPosition extends BreakPosition.AbstractBreakPosi
const formattingContext = this.formattingContext;
const row = formattingContext.getRowByIndex(this.rowIndex);
let penalty = 0;
if (!formattingContext.isFreelyFragmentableRow(row)) {

const breakPositions = this.getAcceptableCellBreakPositions();
const cellFragments = this.getCellFragments();

// If there is a box break in a row-spanning cell, do not add penalty.
// This is to prevent the cell content from disappearing due to the situation
// that a box break occurs in a row-spanning cell but the row break fails.
// (Issue #1403)
const foundBoxBreakInRowSpanningCell = breakPositions.some(
(bp, i) =>
bp.breakPosition instanceof Layout.BoxBreakPosition &&
(cellFragments[i].cellNodeContext.sourceNode as HTMLTableCellElement)
.rowSpan > 1,
);
if (
!foundBoxBreakInRowSpanningCell &&
!formattingContext.isFreelyFragmentableRow(row)
) {
penalty += 10;
}
this.getAcceptableCellBreakPositions().forEach((bp) => {
penalty += bp.breakPosition.getMinBreakPenalty();

breakPositions.forEach((bp, i) => {
let penalty1 = bp.breakPosition.getMinBreakPenalty();
if (
foundBoxBreakInRowSpanningCell &&
bp.breakPosition instanceof BreakPosition.EdgeBreakPosition &&
bp.breakPosition.overflows &&
penalty1 >= 3
) {
// When a box break occurs in a row-spanning cell, the height of the row group decreases,
// and the overflows flag that was set before the box break may be no longer valid.
// So,check the overflow again, and if the cell does not overflow, reduce the penalty.
// (Issue #1403)
const overflows = cellFragments[i].column.checkOverflowAndSaveEdge(
bp.nodeContext,
null,
);
if (!overflows) {
penalty1 -= 3;
}
}
penalty += penalty1;
});
return penalty;
}
Expand Down

0 comments on commit 690b3de

Please sign in to comment.