Repository navigation
feat(layout): let a Preformatted block carry an Anchor - #694
Merged
Merged
Conversation
A code listing or command block could not be the target of a link, a page reference or a named destination, unlike a paragraph, heading, list, table or image. Preformatted.Anchor takes the name rule, the refusals and the destination of Paragraph.Anchor, and joins the document's anchor walk, so a name held by a block and by another element is refused before any layout. Only the piece of a split block that starts at line 0 reports it, so the destination is on the page of the first line. A block with no anchor saves to the same bytes as before.
…raph Preformatted.Anchor inherited the exception tags of Paragraph.Anchor, which list causes a block cannot have: its Margins refuse negative and non-finite edges, and every block is drawn. The one cause that can happen was missing: a page taller than 3.403 x 10^38 points makes the save throw ArgumentOutOfRangeException naming top. The block now has its own tags, and Paragraph.Anchor names the same page-height cause. The case-sensitivity note is a plain statement, not a deferred refusal, and the changelog entry no longer reads as if a valid name throws.
The anchor must be reported under the element, since a page reference resolves its target by that object. A labelled page break followed only by an anchored block must save, which depends on the plan clearing the pending break when it meets a block.
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 #693.
What changed
Preformatted.Anchor { get; init; }gives a code block the same named destination the otherelements already have, so a code listing or command block can be the target of an internal link,
a page reference or
file.pdf#nameddest=name.Paragraph.Anchor's: theinitaccessor goes throughAnchorNames.Validate, so an empty name, one longer than 127 characters, or one with a characteroutside
A-Z a-z 0-9 . _ - :throwsArgumentException(ParamNamevalue), with the samemessage.
PreformattedRendererimplementsIPlacementSourceand reports the anchor throughPlacementSink.ReportAnchor, as the paragraph, table and list renderers do. Only the piece thatstarts at line 0 reports it, so a block that splits across pages reports once, on the page of its
first line.
edge of the page,
[page /XYZ 0 top null]. It is the occupied box'sY, the same valueParagraphRendererreports for a paragraph (its occupied box has the top margin alreadydeducted).
NavigationPlan.BuildwalksPreformattedRenderer, so a name held by a block and by any otherelement is refused by the save before any layout, naming both ("Paragraph 0 and Preformatted 1"),
and the document stays saveable. The same instance added twice holds its anchor twice.
its own boundary documentation: a bold refusal sentence and its own
<exception>tags, whichlist the causes a block can have (see below).
PublicAPI.Unshipped.txtgains the getter and the init accessor. CHANGELOG entry underUnreleased, Added.
Paragraph.Anchor'sArgumentExceptiontag gains one cause it was missing, a page taller than3.403 x 10^38 points (doc-only change).
No other renderer, option or default changed.
Document.Add(IRenderer)is unchanged becausePreformattedRendereris internal.Refused set
ArgumentExceptionfrom theinitaccessor, same message asParagraph.AnchorInvalidOperationExceptionfrom the save, before any layout; the document stays saveableArgumentOutOfRangeExceptionnamingtopfrom the save, after layout started, so the document cannot be saved againThe last row is not new behaviour of a block: a paragraph with an anchor does the same. Measured
with a 300 pt wide page and one block (or one paragraph) with an anchor: a page height of
3.403 x 10^38 saves, the next double above it throws, 3.5e38 and 1e39 throw, and the same block with
no anchor saves at 3.5e38 and 1e39. A block's
Marginsrefuse negative and non-finite edges, sothey cannot cause it; the
<exception>tags onPreformatted.Anchorsay so and name only thecauses a block can have.
Document.Add(Preformatted)still does not mention the repeated-anchorrefusal, as none of the other
Addoverloads does; theSavetags carry it.Nothing that saved before is refused: the property is new, and a block without an anchor takes none
of these paths.
Byte comparison against 215ba05
A probe program built once against a detached worktree of 215ba05 and once against this branch
(both with
TimestampandDocumentIdfixed, so no normalisation is applied), five documents thathold
Preformattedblocks and no anchor. All five compare equal withcmp:TabWidth4BreakBeforeA sixth document, with
Anchorset, is built only under the branch and its file holds/Dests;that confirms the branch build under test contains the change. Documents with no anchor hold no
/Destsin either build.Limit of the claim: these are five documents, not every input. A block with no anchor reports
nothing (
ReportPlacementsreturns without reporting, andNavigationPlan.Addreturns on a nullname). When another anchor or a labelled break is in the document, the renderer still calls
ReportPlacementsfor each block piece, which reports nothing for it; seven of thirteen furtherdocuments compared byte for byte during review took that path, all identical.
Tests
PreformattedAnchorTests(14 tests, each on net10.0 and net11.0):/Destsname tree holds the name and its array has the page object and the top derived fromthe geometry: top of the content box, below a filler paragraph, below a 7 pt top margin, on the
second page after a full page, and after
BreakBefore;20 + 3 x 12, counted from the draw plan and read back from the file;pdfinfo -destsresolves the name to the expected page and top (the by-name check; Layout has nolink-by-name member yet (Layout: internal links and destinations, not just URIs #299), although the Kernel has
PdfLinkAnnotation.DestNameandPdfDocument.AddNamedDestination, and neither the Reader norqpdf --jsonresolves nameddestinations);
Paragraph.Anchor;and top of the first line (
TryGetTargeton the element);PageBreakfollowed only by an anchored block saves, and the destination is on the newpage;
layout and a second save meets the same refusal; the same instance added twice.
Mutations
Run in a detached worktree at the commit, one at a time, source restored after each. The first five ran against the 12 tests of the first commit, the last two against the 14 now.
false &&inReportPlacements)pdfinfotest_startLine == 0removed)pdfinfotestinit => _anchor = value)NavigationPlanthis) instead of the elementcontinuein place ofbreakin the newNavigationPlancaseGates
Run after the last code commit (a CHANGELOG rewrap followed), on a single machine, Release,
REQUIRE_ORACLES=1:VellumPdf.Layout.Testson net10.0 and net11.0 together: 4,950 run, 4,946 passed, 0 failed, 4 skippeddotnet format VellumPdf.slnx --verify-no-changespwsh eng/clean-room-check.ps1Removed in 3.0
Nothing: no compatibility device was added.