Repository navigation
refactor(layout): place elements through one loop and report heading placements - #644
Merged
Merged
Conversation
…e merging the passes (#288) Records the normalised bytes, the order and areas of every Layout call, the pages a caller-owned PdfDocument holds after a caught too-tall or cap exception, and the call counts of a 1,000 paragraph and a 1,000 row document, on the commit before the placement loop changes. Each value was recorded on the base commit, on net10.0 and net11.0.
…placements (#288) The counting pass and the drawing pass were two copies of the same branching. One routine now runs both, so the too-tall refusal, the continuation cap and later placement rules exist once; each pass keeps its own side effects at the points it had them. Headings report where they landed from the loop, in both passes, into a plan that dependent renderers resolve against over at most five counting runs. No public renderer is such a dependent yet, so no existing document is affected. Removes PendingBookmarks and BookmarkEntry, which nothing used.
…ring cap (#288) Headings plan against the outline destinations the drawing pass writes, in both passes and with a split heading; counters pin the layout calls and measuring runs; a test dependent pins convergence, the five-run refusal and the determinism guard; retries through Document; qpdf and pdftotext check the file.
…ge is committed (#288) A heading that answers Nothing is planned where the retry placed it, and a too-tall refusal in the drawing pass leaves every page finished.
…er review (#288) Makes the PDF/A-2u pin independent of the operating system by folding CR LF to LF inside ToUnicode streams only (#630), and makes its second heading really split across two pages. Adds a seeded generated-document check that measured and drawn pages agree, the counter reset check, the four-dependents and settled-beside-moving cases, and the page-count cause. Reports are collected only when a dependent or a test reads them. The refusal messages no longer say the passes alternate or that a DocumentRenderer cannot be saved again, and the stack-depth tests name the single loop.
The placement collector is now _placements, beside the diagnostics sink _sink. The diagnostics location is set inside the loop's drawing pass only, and the band truncation reports follow that pass, as in the loop this branch replaced; the measuring pass reports nothing. ParagraphRenderer keeps the nullStyleRuns out parameter and counts successful wraps.
A cut footer is reported once with a dependent that forces three measuring runs, as with one run.
The measuring-pass comments said reports come from the drawing pass only when only diagnostics do, and described a check as future work while the code below it already walks the elements. The two refusal messages assumed a Document, which a direct renderer caller does not have. Comment lines added by #288 are rewrapped to 100 columns.
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 #288
What changed
The page-counting pass and the drawing pass were two copies of the same branching (
CountPlaceRenderer,PlaceRenderer). One routine,PlaceRenderer, now runs both. The too-tall refusal, the 50,000-continuation cap and every later placement rule are written once. Each pass keeps its own side effects at the points it had them: the drawing pass commits the open page before a too-tall or cap throw, the counting pass creates no page and starts at one page.Internal only, no
PublicAPIchange, no output change.IPlacementSource(internal, implemented explicitly): a renderer reports a key and a box. The loop calls it on the renderer whose result it accepted (Fullthe renderer,Partialits split piece), in both passes, before the cursor moves. OnlyHeadingRendererreports; the key is theHeading, the y is the one its outline entry uses.RecordPlacements. Without either, nothing is collected. Measured warm, 1,000 headings saved throughDocument.Saveallocate 128 bytes more than on main without a band and 528 bytes more with a footer. That is under one byte per heading, so it is not an allocation per heading; other document sizes were not measured._pdf.Pages.Count.PaginationPlan(target to page and y, page count,LabelOf) andIPlanDependent(Resolve(plan), plusTargetNameandResolvedTextfor the refusal message).MaxMeasureRuns = 5. Past it the save throwsInvalidOperationExceptionnaming up to three unstable targets and their strings per run, or the page counts when no dependent changed in the last run. The throw comes after the layout started, so aDocumentthat raised it cannot be saved again.MeasureRuns,LayoutCalls,ParagraphRenderer.WrapCalls.Document.CreateRendereris nowinternalso a test can read the plans of a generated document.DocumentRenderer.PendingBookmarksandBookmarkEntry.git grepoversrc tests docs README.mdfinds no other use and noAddBookmark.No public renderer is a dependent, so no existing document reaches the five-run cap or the guard.
Merge with the diagnostics channel (#642)
The two changes touched the same loop, so the merge is part of this review.
_sinkinDocumentRenderer_sink; the placement collector is_placements.ReportBandTruncations()runs after the drawing pass, as before.ParagraphRenderer.Layoutoutparameter ofWordWrapand its field, and counts a wrap only when one is made, so a paragraph still wraps once with a footer.CHANGELOG.mdgit diff origin/main -- CHANGELOG.mdhas no removed line); this entry sits after main's entries under Changed.A test (
MeasuringRunsReportNoDiagnostics_soACutFooterIsReportedOnce) pins that a cut footer is reported once, with a count of one, whether or not a dependent forces three measuring runs.Commits
Pins recorded on the base, the loop, tests for the new internals, review fixes, the merge of main, and a diagnostics test.
git log origin/main..lists them.Evidence
Heads: before the merge
e3a55cd, after it the head of this branch. Both assemblies were printed with different md5s in every probe and runner run.Pins recorded on base, unchanged on head (net10.0 and net11.0). Normalised bytes and a hash of the order and areas of every
Layoutcall for: plain, footer, header and footer with{pages}, a caller-ownedPdfDocumentwith an existing page and a footer, a custom renderer that answers differently per call with a band. Too-tall and cap messages and the pages left in the caller'sPdfDocumentafter a caughtRender, in each pass.PDF/A-2u pin and the operating system. The document is saved on a Windows machine and a Linux CI runner, and the embedded font's ToUnicode map has CR LF line ends on Windows (#630). The pin hashes with CR LF folded to LF inside every Flate stream whose inflated text contains
begincmap, which in this document is the one ToUnicode stream; the fold does nothing once #647 merges. Proof: CI on Linux printedFBA23BB8...E21Afor the previous document; the same previous document, hashed here on Windows with the fold, prints the same 64 digits. The new pin (DD46E610...) was recorded on the base commit and holds on head, on both target frameworks. The document's second heading now really splits:pdftotext -layoutshows it across pages 1 and 2.Measured pages against drawn pages.
GeneratedDocuments_measureTheSamePagesAndPlacementsAsTheyDrawlays out 200 seeded documents from the existing generator (built-in elements, a footer on every one, a heading at the end) and asserts equal page counts and equal placements; refusals are counted, and more than half must lay out.Differential runner (net10.0), base = main with #642, head = this branch.
#lines and the commit in pathsThe fuzz row that earlier differed from 2.3.3 is a heading split over two pages whose outline destination is now at the heading top (
/XYZ 0 841.89becomes/XYZ 0 769.89); the CHANGELOG entry for #464 declares it, and the comparison against 2.3.3 now treats it as deliberate.Probe, base against head (public API, 27 rows, 2.3.3 is not compared again because main moved). Equal on all rows: call count and order, a renderer that answers differently per call with and without a band, too-tall and cap in each pass (message, pages left, unfinished pages, saving the caller's
PdfDocumentafterwards), a NaN draw followed by a too-tall element, layout-validation refusals first and later, an existing page with a footer, the retry rows, and three rows that printDocument.Diagnosticsin order (a cut footer with unencodable characters, headings with unencodable characters).Cost (
GC.GetAllocatedBytesForCurrentThread, warm, from the probe; bytes):Document.Save, no bandDocument.Save, footerLayout calls on 1,000 paragraphs: 1,076 without a band, 2,116 with a footer, on both. Measuring runs: 0 without a band, 1 with a footer. A review measured +1.57% (no band) and +3.06% (footer) for 1,000 headings before reports were made conditional; the table above is after. Table allocation with a footer is about twice that without in both builds (1.96 measured by a reviewer without a logging wrapper, 2.00 by the probe's table render); table cost belongs to #517.
Mutations (each run in a detached worktree, restored afterwards; full Layout suite for the three re-run this round)
Nothingretry reported as a placementFinishCurrentPagebefore the drawing-pass too-tall throwPaginationDepthTests.PlaceRenderer_tooTallElement_throwsInvalidOperation)HasStartedLayoutset after the measuring runsDocument,SaveLifecycleTests.TooTallElementWithAHeader_isRefusedByTheCountingPass_andTheRetryIsRefusedToo)_pdf.Pages.CountRunLayoutLayoutCallsAndMeasureRuns_startOverOnEveryRunLayout, which now lays out twice)Review round (two reviews of
e3a55cdand CI)pdftotext -layout; pin re-recorded on base.DocumentRendererDocument; theDocumenttest still sees its own message on a second save.Placement.Y, the guard messageGates
Release solution build 0 warnings; the full Layout suite in Release on net10.0 and net11.0 (1,199 tests, 0 failed, 2 skipped: the named-pipe tests, which skip on Windows) and in Debug on net10.0, with oracles required (
REQUIRE_ORACLES,REQUIRE_VERAPDF: veraPDF 1.30.4 2u, qpdf 12.4.2--checkand--json,pdftotext -layout); the diagnostics tests (65) run on both frameworks;dotnet format --verify-no-changes, clean-room check andgenerate-roadmap.py --checkexit 0.Not done