feat(avalonia): paged rendering mode for print-like preview - #80
Merged
Conversation
added 2 commits
July 16, 2026 16:58
LayoutBuilder silently dropped <<< page breaks, so Layout consumers (the Avalonia preview among them) could never see them. Add PageBreakLayout — a marker block mirroring ThematicBreakLayout — and map the node in BuildBlock, carrying its SourceRange. Continuous renderers may keep ignoring it (it has no visual form, matching HTML's invisible page-break-after); paged renderers use it to force a page boundary.
PagedAvaloniaRenderer wraps an AvaloniaRenderer (the IncrementalAvaloniaRenderer pattern), renders per-block controls, measures them at the page content width via Avalonia's Measure pass, and flows them greedily into fixed-size pages: a block that doesn't fit starts the next page, an over-tall block gets a page of its own and clips, and a PageBreakLayout (<<<) forces a boundary. Inline SourceRange stamps are preserved, so source mapping keeps working in pages. PageLayoutOptions carries page geometry and paper chrome in DIPs, with A4 and Letter presets and FromPdfPoints() to mirror a PdfRenderOptions page setup (points x 96/72) exactly. Scope: a print-like preview at block granularity — not PDF-identical pagination; on-screen metrics differ from the PDF renderer's font metrics by design. Nine headless tests cover multi-page flow, forced/leading breaks, over-tall blocks, title placement, unit conversion, and degenerate margins.
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 #79.
What
Two additive pieces enabling a print-layout (PDF-like) preview for AdocNet.Avalonia consumers:
AdocNet.Layout— stop dropping<<<.LayoutBuilder.BuildBlocksilently skippedPageBreakNode, so Layout consumers never saw explicit page breaks. NewPageBreakLayoutmarker (mirrorsThematicBreakLayout), mapped with itsSourceRange.AvaloniaRenderercontinues to render it as nothing in the continuous preview — same effect as HTML's invisiblepage-break-after— so existing consumers are unaffected.AdocNet.Avalonia—PagedAvaloniaRenderer+PageLayoutOptions. Wraps anAvaloniaRenderer(theIncrementalAvaloniaRendererpattern), renders per-block controls, measures them at the page content width via Avalonia's Measure pass, and flows them greedily into fixed-size pages:PageBreakLayoutforces a boundary (no blank leading page for a break at page start)RenderPages()returns the individual pageBorders;Render()stacks them ready for a scrollerPageLayoutOptions: geometry + paper chrome in DIPs,A4/Letterpresets, andFromPdfPoints()(points × 96/72) so a preview can mirror aPdfRenderOptionspage setup exactlySourceRangestamps are preserved — click-to-source keeps working inside pagesScope (stated plainly)
This is a print-like preview at block granularity, not PDF-identical pagination: on-screen text metrics differ from the PDF renderer's Helvetica/TTF metrics by design. The PDF cursor model in
AdocNet.Converters.Pdfremains the authority for actual PDF page breaks.Tests
LayoutBuilderTests:<<<→PageBreakLayout(+ source range carried) — 53 layout tests passPagedAvaloniaRendererTests(headless): multi-page flow without block loss, forced break, leading-break suppression, over-tall block isolation + clipping, title on first page, points→DIPs conversion, degenerate-margin rejection — 72 headless tests passTreatWarningsAsErrorsMotivation
Lets editor hosts (e.g. Ascolotl's planned page view) offer a paper-layout preview without a PDF-rasterizer dependency, keeping the pure-managed ethos.