feat(api): addTableOfContents(...) — native clickable table of contents#237
Merged
Conversation
A table of contents had to be hand-assembled: a row per entry, a leader sized by hand, and a manual two-pass to resolve the page numbers. addTableOfContents(toc -> toc.entry(label, anchor)) builds it natively — each entry becomes a row whose label links to the chapter, a dotted or dashed leader fills the gap, and the page number is resolved automatically from the laid-out document. It is assembled entirely from existing primitives — auto/weight columns, a fill leader line, and a page reference — with no new engine code; the numbers resolve through the existing page-reference two-pass. The entry rows are added to the surrounding flow rather than wrapped in one block, so a long table of contents paginates across pages. TocBuilder configures the title, leader (DocumentLeader NONE/DOTS/DASHES), and text styles; a blank entry label or anchor is rejected at the call site. Tests: TocTest renders a contents page and asserts each entry prints its resolved page, each label is a clickable go-to link to its anchor's page, and a 30-entry contents paginates across pages; TocBuilderTest covers the blank label/anchor rejection. Example: TocExample (a contents page plus five chapters). Full suite green, no visual baselines changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A table of contents had to be hand-assembled: a row per entry, a leader sized by hand, and a manual two-pass to resolve the page numbers.
addTableOfContents(...)makes it native — and is the payoff of the table-of-contents groundwork (pageIndex()#231,line().fill()#234,columns()#235,addPageReference#236).What changed
addTableOfContents(toc -> toc.entry(label, anchor))on every flow. Each entry becomes a row whose label links to the chapter (clickable), a dotted/dashed leader fills the gap, and the page number is resolved automatically from the laid-out document.TocBuilderconfigures the title,leader(DocumentLeader.{NONE,DOTS,DASHES}), leader color, and entry/page-number/title text styles. A blank entry label or anchor is rejected at the call site.columns(auto(), weight(1), auto()), aline().fill()leader, and anaddPageReferencenumber; the numbers resolve through the already-merged page-reference two-pass.Section/Containerwrapper is atomic and would force the whole TOC onto one page.Lane: canonical DSL (
TocBuilder,addTableOfContents) + style (DocumentLeader). Purely additive → japicmp-safe; documents without a TOC are byte-identical.Verification
./mvnw test -pl .— green, 0 visual baselines changed.TocTest: each entry prints its resolved page (PDFTextStripper), each label is a clickable go-to link to its anchor's page (PDActionGoTodestination ==pageOf), and a 30-entry contents paginates across pages (builds without atomic-too-large,totalPages > 1).TocBuilderTest: blank label/anchor rejected.entry(...)at the call site instead of a late generic error).TocExample(a Contents page + five chapters) with a committed preview — labels auto-size, dotted leaders fill, page numbers resolve.This closes the native table-of-contents gap: pageIndex → fill → columns → page reference → TOC.