Fix page overflow: add bounds checking and content splitting for multi-page songs #17

Closed
opened 2026-03-17 14:08:33 +01:00 by shahondin1624 · 0 comments

Description

The PDF renderer (PdfBookRenderer) has no bounds checking when placing content on pages. The y coordinate decreases as content is added, but nothing prevents it from going below the bottom margin, causing text and images to render outside the visible page area.

Additionally, 2-page songs currently render all content on page 0 and leave page 1 blank (see comment at PdfBookRenderer.kt:160). There is no content splitting across pages.

The measurement engine's height estimates are also approximate (line height = 1.2 × fontSize), so even songs classified as 1-page may overflow if the estimate diverges from actual rendering.

Root Causes

  1. No bounds checking: renderSongPage() never checks if y has gone below the bottom margin
  2. No content splitting: 2-page songs put everything on page 0; page 1 is blank
  3. Approximate measurement: PdfFontMetrics estimates may diverge from actual rendered sizes

Acceptance Criteria

  • The renderer tracks the current y position against the bottom margin during song page rendering
  • For 2-page songs, content is split across pages when it exceeds the available space on page 0 — remaining sections continue on page 1
  • Content that would be rendered below the bottom margin (minus space reserved for bottom metadata/references) is moved to the next page
  • If metadata is configured for "bottom" position, sufficient space is reserved at the bottom of the last page before rendering content
  • No text or images are rendered outside the printable page area
  • Existing tests continue to pass
  • New tests verify that content splitting works correctly for songs that exceed one page

Implementation Hints

  • In PdfBookRenderer.renderSongPage(), track y and compare against a yMin (bottom margin + reserved footer space)
  • When y would drop below yMin on page 0 of a 2-page song, stop rendering on page 0 and continue remaining sections on page 1
  • Consider splitting at section boundaries (between verses/choruses) rather than mid-section for cleaner page breaks
  • The measurement engine may also need adjustment if the split logic reveals measurement inaccuracies
## Description The PDF renderer (`PdfBookRenderer`) has no bounds checking when placing content on pages. The `y` coordinate decreases as content is added, but nothing prevents it from going below the bottom margin, causing text and images to render outside the visible page area. Additionally, 2-page songs currently render **all content on page 0** and leave page 1 blank (see comment at `PdfBookRenderer.kt:160`). There is no content splitting across pages. The measurement engine's height estimates are also approximate (line height = `1.2 × fontSize`), so even songs classified as 1-page may overflow if the estimate diverges from actual rendering. ## Root Causes 1. **No bounds checking**: `renderSongPage()` never checks if `y` has gone below the bottom margin 2. **No content splitting**: 2-page songs put everything on page 0; page 1 is blank 3. **Approximate measurement**: `PdfFontMetrics` estimates may diverge from actual rendered sizes ## Acceptance Criteria - [ ] The renderer tracks the current `y` position against the bottom margin during song page rendering - [ ] For 2-page songs, content is split across pages when it exceeds the available space on page 0 — remaining sections continue on page 1 - [ ] Content that would be rendered below the bottom margin (minus space reserved for bottom metadata/references) is moved to the next page - [ ] If metadata is configured for "bottom" position, sufficient space is reserved at the bottom of the last page before rendering content - [ ] No text or images are rendered outside the printable page area - [ ] Existing tests continue to pass - [ ] New tests verify that content splitting works correctly for songs that exceed one page ## Implementation Hints - In `PdfBookRenderer.renderSongPage()`, track `y` and compare against a `yMin` (bottom margin + reserved footer space) - When `y` would drop below `yMin` on page 0 of a 2-page song, stop rendering on page 0 and continue remaining sections on page 1 - Consider splitting at section boundaries (between verses/choruses) rather than mid-section for cleaner page breaks - The measurement engine may also need adjustment if the split logic reveals measurement inaccuracies
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shahondin1624/songbook#17