Repository navigation
fix(layout): bookmark a split heading where it starts, and let a heading bookmark be closed (#464, #609) - #637
Merged
Merged
Conversation
Heading.BookmarkExpanded and a four-argument DrawContext.AddOutlineEntry carry the entry's open or closed state to the outline writer, which already honours it. The new overload refuses a null title and a non-finite destination at the call; headings go through an internal core so their refusals stay as they were.
#609) Write the four-argument AddOutlineEntry's own remarks instead of inheriting the three-argument overload's, which said a null title and a non-finite position are accepted. Name the level -1 case, where level 0 is always top-level and the entry never gets children, and add the null page tag. Cover a split piece that starts above layout y 0 and the level -1 case in tests, and word the #464 entry to match.
…kmark # Conflicts: # CHANGELOG.md # src/VellumPdf.Layout/PublicAPI.Unshipped.txt
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.
Closes #464
Closes #609
Three commits: one per issue, then a follow-up that corrects the documentation and adds two tests after review. They share a PR because both change the one outline call
HeadingRenderer.Drawmakes.#464: a split heading's bookmark
HeadingRenderer.Layoutstores the box it was placed in onthis, then returns a newHeadingRendererfor the split piece. That copy was built without the box, so itsDrawpassed layout y 0 toAddOutlineEntry, andToPdfY(0)is the page height: the bookmark pointed at the top of the page, above the heading. The split copy now carries the box, asParagraphRenderer's split does.Sweep of every
LayoutResult.Partialsite (git grep -n "LayoutResult.Partial(" -- srcat 2027421), against the fields eachDrawreads:DrawreadsParagraphRenderer.cs_para,_startLine,_endLine,_lines,_lineHeight,_occupied,StructType,ParentStructElem,ElementLanguage,RunOwnerHeadingRenderer.cs_heading,_inner,_occupied_heading,_inner;_occupiedwas missing (this fix)ListRenderer.cs(two sites)_list,_items,_startItem,_endItem,_partialContentOverrideAtStart,_occupied,_offeredTable/TableRenderer.cs_table,_startRow,_rowHeights,_occupied(the split also copies_colWidths)Deliberate output change (CHANGELOG,
### Fixed): only the/XYZtop value of the bookmark of a heading whose split piece does not start at layout y 0. A split piece that starts above y 0, through a negative document or heading top margin, is part of the change: on a page 300 high with a document top margin of -20 the top moves from 300 to 320. The byte offsets that follow the value move too. Nothing else changes: page count, content streams, titles and exceptions are equal.#609:
Heading.BookmarkExpandedand a four-argumentAddOutlineEntryHeading.BookmarkExpanded { get; init; }, defaulttrue.DrawContext.AddOutlineEntry(string title, int level, double layoutY, bool expanded). The three-argument overload keeps its behaviour and forwards to an internal core withexpanded: true.ArgumentNullException) and a destination whose Y is not finite (ArgumentOutOfRangeException) at the call (new API refuses non-compliant input from the start). Its refusals are raised from theDrawof the renderer that calls it, whichDocumentruns inside its save, so a throw leaves that document unable to be saved again. It has its own remarks and exception tags, including the null-pageArgumentNullExceptionraised from the save (ParamNameiskey).BuildOutlineTreeapplies it: level 0 is always top-level, any other level goes under the most recent earlier entry at exactly one level less, and top-level when there is none. So a level -1 entry never gets children, andBookmarkExpanded = falseon it writes no/Count(tested).HeadingRenderer.Drawcalls the internal core, not the validating overload, so every heading keeps its exception type, message and timing.PdfOutlineEntry.IsExpandedandBuildOutlineTreealready wrote a negative/Countfor a closed entry; no Kernel change. An entry without children has no/Count, as ISO 32000-2:2020 Table 151 requires it only for an item with descendants, so the value is not written there.Heading.BookmarkExpandeddocuments that as the rule for when it takes effect.Evidence
Differential runner against 2.3.3 and the base commit (2027421), then the PR head (869d360). Both assembly informational versions are printed in each run's
versions.txt:2.3.3+1c61fa6...for 2.3.3 and2.3.3+<head sha>for the head builds. The probe also prints each Layout DLL's path and md5.DELIBERATE-464(34 probe rows, among them the two negative-margin rows, and 1 fuzz row, all holding a split heading), plus one cancel-scan row whose verdict depends on timingrows\*.txtfile=,skel=,tfile=,tskel=andodest=differ;pages=,content=,norm=,ttl=equal); 43 probe rows (the split-heading rows, and the rows for the new members, which the base lacks); 1invrow,L2.retry.objstmEncrypt-then-fixed, an encrypted file whose bytes change from run to run (itsfile=andcontent=hashes also differ between two runs of 2.3.3, in `mainof the base and PR-head runs); and 131 rows from the timing-driven cancel scans and the rows that print the run's output directory (r6a-cancel,r6c-cancel,r6a-links,r6a-hidden,r6a-foreignfonts`)The runner gained an
odest=field (the outline/Destarrays in object order) and aDELIBERATE-464rule: the file with every outline destination top blanked has an equal skeleton, the plan holds a heading, and each changed top was the page height on the 2.3.3 side (read from the file's/MediaBox) and is something else on the PR side, in either direction. The two negative-margin rows classify asDELIBERATE-464and nothing else moved between the earlier run and this one except that timing row.Probe rows (page 200x300, margins 10, a filler paragraph of 120 words, then a heading; all on 2.3.3, base and PR head):
p1@30.8p1@30.8p1@300(page top)p1@30.8(equals the control's top)p1@300p1@300p1@300p1@320Nothing, moves to page 2 (sweep 19 to 22)p2@290,p2@275.6, ...p1@300p2@300p2@242.8(equals the fits row)BookmarkExpanded = falsewith two level-1 headings/Count -2/Countabsent: bytes equal to expanded (byte-pinned in a test)/Count -, root/Count 2/Count -; the level-2 entry is top-level/Count -1/Count 1on the parentNullReferenceExceptionfrom the saveArgumentException(PDF does not support NaN)ArgumentNullException/ArgumentOutOfRangeExceptionfrom the save; the next save says it cannot be saved againdouble)ArgumentException, PDF does not support NaN or Infinity∞on 2.3.3 and asInfinityon the base and the PR head (the cause was not investigated; base and PR head agree)ArgumentExceptionInvalidOperationException: boomagainA NaN top margin is not a route to a non-finite heading position: the document refuses it as "too tall" before any heading draws. The overflowing-destination row above is the input that reaches the outline write.
Tests
OutlineBookmarkSplitTests(16 tests, intests/VellumPdf.Layout.Tests). The split cases parse the outline item's/Destarray and assert the exact numbers against the same-filler control; one case sweeps 1 to 40 preceding paragraphs and asserts the bookmark never sits above the top margin, and that both the "split on page 1" and "moved to page 2" shapes occur. One test pins collapsed-without-children bytes throughDocumentRendererwith a fixed timestamp and document id. One test runs qpdf--check("No syntax or stream encoding errors found"), reads the item back withqpdf --json --json-key=outlines, and checkspdftotexton the page the bookmark names.Also clean: Release build of the solution (0 warnings),
dotnet format --verify-no-changes,eng/clean-room-check.ps1,python eng/generate-roadmap.py --check.Mutations
Each run on the committed head, with
git diff --statand a-U0diff shown before the build, the Layout DLL rebuilt, and the sources restored withgit checkout -- src.default(LayoutBox)(revert the #464 fix)SplitHeading_bookmarkIsAtTheSplitPieceNotThePageTop,Heading_movedToTheNextPageOrSplit_neverTargetsAboveTheTopMargin,SplitHeading_collapsed_hasOneEntryAtTheSplitPiece,SplitHeadingStartingAboveLayoutYZero_hasItsBookmarkAboveThePageHeight; the y-0 control passesexpanded(IsExpanded = true)CollapsedParentWithChildren_writesNegativeCount_andRootCountsVisibleItems,FourArgumentOverload_collapsed_writesNegativeCount,SplitHeading_collapsed_hasOneEntryAtTheSplitPiecefalseThreeArgumentOverload_staysExpanded_withChildrenHeadingRenderer.Drawcalls the validating overloadHeadingAtANonFinitePosition_isRefusedByTheWriterWithArgumentException(the exception becomesArgumentOutOfRangeException)FourArgumentOverload_refusesNullTitle_andTheDocumentCannotBeSavedAgainNot done
Heading; a custom renderer uses the four-argument overload.