Skip to content

Fix text clipping and paragraph spacing in paginated rendering#117

Merged
JSv4 merged 1 commit intomainfrom
claude/investigate-issue-114-5wWPb
Mar 21, 2026
Merged

Fix text clipping and paragraph spacing in paginated rendering#117
JSv4 merged 1 commit intomainfrom
claude/investigate-issue-114-5wWPb

Conversation

@JSv4
Copy link
Copy Markdown
Owner

@JSv4 JSv4 commented Mar 21, 2026

Summary

This PR fixes three related issues affecting paginated rendering that caused text to be clipped at page bottoms and inconsistent paragraph spacing:

  1. Line height calculation: Fixed lineRule default handling per OOXML spec (ISO/IEC 29500)
  2. Contextual spacing: Properly suppress spacing for consecutive same-style paragraphs
  3. Pagination logic: Corrected bottom margin accounting in page break calculations

Key Changes

WmlToHtmlConverter.cs

  • Added suppressLeadingWhiteSpace parameter to ConvertToHtmlTransform(), ProcessParagraph(), ConvertParagraph(), DefineParagraphStyle(), and CreateStyleFromSpacing() methods to enable suppression of leading whitespace in paragraphs
  • Modified CreateStyleFromSpacing() to:
    • Set spacingBefore to 0 when suppressLeadingWhiteSpace is true
    • Fixed lineRule default: when w:lineRule attribute is absent but w:line is present, treat as "auto" per OOXML spec (previously the line value was ignored)
  • Updated GroupAndVerticallySpaceNumberedParagraphs() to:
    • Identify contextual spacing groups (those with "sty:" prefix)
    • Suppress both trailing whitespace for non-last paragraphs AND leading whitespace for non-first paragraphs in contextual groups
    • This matches Word's behavior of removing all inter-paragraph spacing for same-style contextualSpacing paragraphs
  • Updated comment for contextualSpacing to note it's handled via GroupAndVerticallySpaceNumberedParagraphs

pagination.ts

  • Fixed bottom margin over-reservation in page break calculations:
    • Removed block.marginBottomPt from blockSpace calculation since the last block's bottom margin extends beyond the content area and is clipped by overflow: hidden
    • Updated keepWithNext logic to exclude bottom margin from the next block's space calculation
    • Corrected two conditional checks that were incorrectly including bottom margins in fit calculations
    • Bottom margin is still tracked in remainingHeight for correct margin collapsing with subsequent blocks

CHANGELOG.md

  • Documented all three fixes with detailed explanations of root causes and solutions

Implementation Details

The contextual spacing fix leverages the existing grouping mechanism in GroupAndVerticallySpaceNumberedParagraphs() which already groups paragraphs by style. The new suppressLeadingWhiteSpace parameter threads through the conversion pipeline to suppress margin-top at the CSS level for non-first paragraphs in contextual groups, while the existing suppressTrailingWhiteSpace parameter handles margin-bottom for non-last paragraphs.

The pagination fix recognizes that in a paginated layout with overflow: hidden, the last block's bottom margin is invisible and should not count against available page space, preventing unnecessary page breaks when content would actually be visible.

https://claude.ai/code/session_01VoQ3xgQrJ1H1xe9t76GeoT

…cing (#114)

Three root causes addressed:

1. lineRule default: when w:lineRule is absent but w:line is present,
   now defaults to "auto" per OOXML spec (ISO/IEC 29500). Previously
   the line value was silently ignored, causing accumulated line-height
   mismatches that clipped the last line on pages.

2. contextualSpacing: now suppresses both spacingAfter (margin-bottom)
   AND spacingBefore (margin-top) for consecutive same-style paragraphs.
   Previously only spacingAfter was suppressed, leaving incorrect
   inter-paragraph gaps where Word shows zero spacing.

3. Pagination engine: the last block's bottom margin is no longer
   counted against available page space since it's invisible (clipped
   by overflow:hidden). This prevents premature page breaks.

https://claude.ai/code/session_01VoQ3xgQrJ1H1xe9t76GeoT
@JSv4 JSv4 merged commit d5c0684 into main Mar 21, 2026
10 checks passed
@JSv4 JSv4 deleted the claude/investigate-issue-114-5wWPb branch March 21, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paginated rendering: text clipped at page bottom + inconsistent paragraph spacing

2 participants