Repository navigation
feat(layout): an opt-in cut of a long address or path after a slash or hyphen - #733
Merged
Merged
Conversation
A word wider than its line was cut at a glyph, so a web address or a path ended a line anywhere. It is now cut after the last solidus, reverse solidus or hyphen-minus that leaves the line no wider than its width, and at a glyph only when it has none. No hyphen or other glyph is added. One function decides the places, from UAX #14, and the paragraph, heading and list-item wrap and the table cell wrap, as a string and as runs, all call it. The cell's line-count cache reads the same walk, so its width intervals stay exact.
…594, #687) A paragraph, heading, list item or table cell whose new wrap would change whether the element reaches the continuation limit now lays out the way 2.3.3 did, through the shared limit decision. The twin of a paragraph is 2.3.3's word split, where a word never continues over a run boundary and U+202F and U+2007 are spaces, with a cut at the glyph. The twin of a table cuts at the glyph too. A paragraph reports only when its two wraps give a different number of lines, so a document far from the limit keeps the cut after a solidus or hyphen and pays for no extra pass. A renderer a caller holds, and a start line a caller made, read 2.3.3's wrap, as the table and the list already do.
…st the boundaries (#687) The paragraph guessed where its two wraps differ and missed a run boundary that holds U+00A0 and an empty run. It now reports the bound every wrap meets, wherever 2.3.3's wrap applies, and the limit decision probes exactly, only where that bound passes what the limit leaves. The second wrap that only compared line counts is gone. The place characters have one definition, the tier tests read the word through the same analysis the wrap does, and the rows the review named are tests.
… differ (#687) A list adds up the lines of its entries, and that bound has to hold for 2.3.3's wrap too. Counting the characters of every entry made lists that no wrap can change reach the limit decision for nothing. The entry now reads whether its wraps can differ from the tokeniser's own decision and from whether its wrap cut at a place.
…es it (#687) The wrap of 2.3.3 was applied wherever a twin or a forwarded renderer was used: a list sent to its twin for an undrawable font, a renderer of the caller's in the document or an entry that fits no empty page, a forwarded table and a paragraph with a start line. The rulings of #682 say those lists are placed as main places them, and nothing about them concerns the limit, so they changed output for no verdict's sake. The 2.3.3 wrap now applies to the twin the document chose or is probing, to the entries of a list laid out as its twin for the limit, and to the entries of every list of a document in which an element after a list comes near the limit. A context says so (WrapAsBefore); the table twin cuts at the glyph under the same condition. The list's bound for an entry reads the join of runs from the tokeniser itself, so runs that share one style instance count, and the cut no longer appends a rune through a boxing call, which allocated more than main did per character. The rows that pin the verdict of 2.3.3 are taken from a v2.3.3 build, one line to a page, with runs that share a style instance and runs that do not.
…#687) The CHANGELOG listed places where text wraps as 2.3.3 did that the code no longer treats so: a list sent to its twin for an undrawable font, a renderer of the caller's or an entry no page holds, a forwarded table, and a renderer of the caller's laying out a library renderer. Each review round found another place the prose left out, because the rule was written as a list of populations. It is now one condition, that the continuation limit chose the layout, stated once in IRenderer.Layout, and the entries for #562, #590 and #594 point to it. The entry also says what the probe costs in the terms measured: a paragraph longer than the continuations left is probed, whatever its page count.
…om v2.3.3 The list entry's bound reads a cut and the white-space normalisation as well as the join of runs, and each read needs a row at one line to a page, where the bound is the lines and a wrong answer lets the current wrap decide. The pages come from a v2.3.3 build.
…twin's reads (#687) A cut after a place never gives fewer lines than a cut at the glyph for the same words, because each glyph line starts no earlier and reaches at least as far. The current lines therefore already bound the twin's, and the list entry needs to read only the joins and the white-space normalisation. The thread-static counter that told the wrap whether it had cut at a place goes with it. A run with no style that holds no word was exempted from the twin wrap, although 2.3.3 read it as nothing and wrapped the paragraph; one that holds a word is refused by the current wrap before any decision. The exemption only changed a verdict. Rows for the no-break spaces in the direction where 2.3.3 refuses, and for the empty run with no style, pin what is left.
… or probes (#687) A document that holds a renderer of the caller's lays every list out as its twin and places the pieces of that twin with no report, which sets the session's mode to Twin without a decision of the limit's. The entries of those pieces took 2.3.3's wrap, so a list on the pages after the first changed the bytes of a document that is nowhere near the limit, against the ruling that such a list is placed as main places it. The condition is now the limit's own: the twin the decision chose (TwinChosen) or one a probe is measuring. The paragraph, the heading, the list and the table read it through one method on the context. The list test spans pages, with a renderer of the caller's before the list, and the byte sets with a renderer of the caller's equal main again.
…out itself (#594) The cut after a solidus or hyphen took more lines than the cut at the glyph on every path, including the ones the continuation-limit decision cannot see: a library renderer that a renderer of the caller's lays out, a table it forwards to, a renderer built with a start line, and the lists the document lays out as their twin for another cause. A text that 2.3.3 and main save at the limit was refused there, and nothing could probe it. Those paths now wrap as main does: main's tokenisation and the cut at the glyph, so main's bytes and main's verdict. A paragraph cuts after a place when the document, or a built-in parent the document addressed, calls it, or when a note block says so; a table does when it is the one the document called, not its twin and not one a caller forwards. A renderer with a start line reports nothing to the decision, because the start indexes lines of main's wrap. A note block is new, so its paragraphs take the cut with no twin. The rows that keep main's verdict, one for each such path, the third case of the limit (the entries of a list before an element near the limit, on the first page and the pages after it), the note block near the limit and the forwarded table's Draw are tests.
…'s wrap The entry for #687 claimed the limit verdict of 2.3.3 for every element and said the cut applied wherever text wraps, while the two entries contradicted each other and the code kept main's wrap on some paths. The rule is now one entry: the cut applies to the text the document lays out itself, the paths the limit decision cannot see wrap exactly as before, and the decision keeps 2.3.3's verdict only for what it can see. A paragraph a renderer of the caller's lays out keeps the word split of #562, which #687 still records.
…else (#594) The field that carried "this table cuts at the glyph" from Layout to Draw always held whether the table is the twin: a table laid out under a context that does not address it goes to its twin, and the twin cuts at the glyph, so the New table is only ever laid out addressed. The forwarded table's Draw still needs the scope, and a test draws one. A renderer built with a start line must not report to the limit decision either; the row for one added directly now asserts no probe.
# Conflicts: # CHANGELOG.md
This was referenced Nov 27, 2026
…594) Five review rounds kept finding paths where the cut, which can take more lines than a cut at the glyph, turned a document that saved into a refusal: at the continuation limit, and as a table header row or row-span group that no longer fits a page. The cut now ships as Document.BreakLongWordsAtPlaces, off by default. Off, every wrap is the one on main, byte for byte and verdict for verdict. On, every wrap the document performs cuts after the last solidus, reverse solidus or hyphen-minus that fits: paragraph, heading, list item, note block, table cell string and runs, and a built-in renderer that a caller's renderer lays out during the save. The save sets a thread scope for the duration of its layout; a wrap made outside a save reads nothing and cuts at the glyph. The setting is new API, so it needs no compatibility twin, and its remarks name the refusals it can cause. Removed with it: the 2.3.3-wrap twins of the paragraph, heading, list and table that #687 needed to keep the limit's verdict, IsLimitTwin, the path classification, the list-entry pre-check, the Tokenise join flag and the glyph-cut scopes. Tokenise is as on main, and #687 is not touched.
The save sets the cut on its own thread for the length of its layout. A document that has it on, one that has it off after it, a layout that throws, and a wrap outside any save are read in turn, so a scope that is not restored fails here.
…all directly (#594) The cut tests call the string and run wraps of a table cell without a save, which sets the cut on its own thread, so they read it off. A helper that forwarded to itself instead of to the wrap also overflowed the stack in one test host; it forwards to the wrap now.
… formatter does (#594) dotnet format --verify-no-changes failed on the new test file, which CI gates.
# Conflicts: # CHANGELOG.md # src/VellumPdf.Layout/PublicAPI.Unshipped.txt
…follow the document (#594) A paragraph or table renderer that one document laid out with the setting on and a second one laid out with it off kept the first wrap, so the second document was not what main gives. The paragraph now keeps the setting beside its wrapped lines and its split pieces copy it, and wraps again when the save that reads it differs. The table holds the setting in the key of its layout decision and draws under the setting its layout used, so the heights it measured and the lines it draws cannot disagree. The setting was thread-static, so a built-in renderer that a caller's renderer laid out on a task or a new thread during the save read off. It is an AsyncLocal now, as ListLayoutRun is, and flows to both; work queued with the execution context suppressed still reads off. The remarks of the setting, IRenderer.Layout and the CHANGELOG follow what the code does: an exception tag naming every save, the ignore set, no claim that a renderer keeps its first wrap, and 2.3 instead of "every version before 2.4".
…nd a renderer to one value (#594) The setting was read from an AsyncLocal that the save set, so a renderer laid out in another flow, a worker that outlived the save, or a piece re-wrapped under the other value read or drew something other than what the document said. Each fix added another way for a renderer's own state and the ambient value to disagree. The value is now LayoutContext.BreakLongWordsAtPlaces. The document sets it on every context it makes, WithArea and the internal derivations copy it, and a context a caller builds has it false. A paragraph or table renderer fixes the value at its first layout that wraps, and its pieces copy it; Draw, line counts, resumed rows and every later wrap use that value. A later layout under the other value throws InvalidOperationException naming the property, so a piece never mixes line numbers of two wraps and nothing re-wraps. The refusal is reachable only when some context has the value true, so a program that never sets either property sees main's behaviour. The static wraps take no value. The wrap helpers take the value as a parameter, the scope and the per-setting caches are gone, and the docs, the tests and the CHANGELOG state the mechanism once.
…ong-word value (#594) A ListRenderer builds its entries again for each save, so the same instance laid out by two documents with different values follows each and is refused only within one save, where a paragraph or table renderer and every piece are bound to their first value. The remarks of LayoutContext.BreakLongWordsAtPlaces now say so and the remarks of the document property, IRenderer.Layout and the CHANGELOG point to it. Preformatted does not read the value and cuts at the glyph, which the summaries and the sentences about "every wrap" now say. Paragraph, Cell and NoteBlock name the context value instead of the document setting. Tests pin the list rule, a table row cut across four pages with the setting on, and a list entry that moves to the next page with it on.
…tting on (#594) The earlier case moved an entry to the next page and passed with the child context losing the value, because that layout and the one a list falls back to saved the same bytes. A gutter that leaves the text narrower than its word is laid out differently by the two, so the test fails when the context a list makes for its entries drops the value.
…t context case (#594) The previous indent left the text a width, which the layout a list falls back to also draws, so the case could not tell the two apart. With an indent wider than the list the document's own layout draws the text and the fallback discards it.
… code makes them (#594) The document reads its property when a save lays out and at no other time, and the value is not read from the thread, a task or an earlier save. A test pins that a list piece, which shares the entries of the layout that cut it, is refused under the other value.
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.
What
Document.BreakLongWordsAtPlaces, a new setting, off by default. With it set, a word wider than its line is cut after the last/,\or-that leaves the line no wider than its width, and at the glyph only when it has no such place that fits. No hyphen or other glyph is added. A word that fits is never cut. This is the cut that #594 asks for.Off, every wrap is main's: the same bytes and the same verdict for every document of a program that never sets the value true, whatever it forwards, splits or reuses. With the value false, every wrap takes main's own path: each one tests a parameter and runs the code main has.
On, the cut applies to the paragraph, heading, list item, note block and table cell wraps: a table cell given as a string or as runs, the line-count cache and the draw included.
Preformatteddoes not read the value and cuts at the glyph, as on main. The setting is new API, so a program that sets it gets the new behaviour with no compatibility path, and its remarks give the refused set: a document that turns it on can take more lines and pages, can be refused at the 50,000-continuation limit, can be refused as too tall (a header row, a row-span group, any element), and a paragraph or table renderer, or a piece, refuses to be laid out under the other value.Closes #594. #750 tracks making the cut the default. The PR does not touch #687, which is what main has.
Mechanism, stated once
LayoutContext.BreakLongWordsAtPlaces { get; init; }is new public API, false by default.DocumentRenderersets it fromDocument.BreakLongWordsAtPlaceson every context it makes;WithAreaand the internal derivations copy it; a context a caller builds withnew LayoutContext(area)has it false unless the caller sets it. A renderer of yours that lays a built-in renderer out passes the value on by deriving the child's context withWithArea, on any thread or task. There is no thread-static,AsyncLocalor per-save state.ParagraphRendererorTableRendererfixes the value at its firstLayoutthat wraps text, and every piece it splits into copies it. Draw, the line counts, row resumption and every later wrap use that value, never the context's. A laterLayoutof the renderer or of a piece with a context whose value differs throwsInvalidOperationExceptionnamingLayoutContext.BreakLongWordsAtPlaces, from thatLayoutand so from the save. Nothing wraps again, so a piece never mixes the line numbers of two wraps.ListRendererbuilds its entries again whenever a new save lays it out, so the same instance laid out by two documents follows each document and is not refused; its pieces share the entries of the layout that cut them and are refused under the other value, as is a second value within one save. The rule is onLayoutContext.BreakLongWordsAtPlaces.TextStylemember. A per-run need was not measured, and the effects that make the cut risky are document-level: the continuation limit and a table's header rows are read over a whole save. A value set on the document after a save is never used, as forMirrorMargins.The rule
/,\and-.\is this library's own tailoring, read as/(UAX Deterministic output: DocumentId pin + determinism tests #14 gives it class PR).?,&,=,.,_and#are not places.=,&,_,#are AL and.is IS. Before a letter LB28 (AL x AL) and LB29 (IS x AL) keep them joined, and before a digit LB23 (AL x NU) and LB25 (IS x NU) do.?is EX; LB31 would allow a break after it, but the held text gives guidance for web addresses only for the solidus.--before a letter, so this one is a coarsening).SY x HL, LB21a holdsHL (HY | HH) x non-HL; applying both to all three characters is coarser than the rules). A Hebrew letter before a solidus is a place. Kana (U+3000 to U+30FF, the small kana extensions U+31F0 to U+31FF, halfwidth katakana U+FF66 to U+FF9F) after the place character is no place, because LB21 holds the small kana and the other nonstarters once CJ resolves to NS.HY x NUandNU (SY | IS)* x NU. A place of that kind is used only when no other place fits on the line, and before a glyph cut; the URL note in section 8 of the annex suppressesSY x NUfor web addresses. For exampleab12/34cdef...cuts afterab12/;ab-cd12/34eee...cuts afterab-first.UAX #14 clauses used (held copy, tr14-55):
//is cut only after the second slash)x IS)HY x NU,NU ( SY | IS )* x NUOff equals main
Measured against origin/main at 33d423a with the head at 5522f61, both built Release net10.0 (the commits since change comments and tests only: the diff of the source folders with comment lines removed is empty), with the setting never set true anywhere. Each set is 150 documents from a generator that hashes the decompressed content, and every set is identical to main (3,300 documents, 0 differ); documents that throw throw the same message in both.
Real-limit rows (50,000 continuations, Courier 10, one line a page, page 80 x 37, 100 x 37 for lists): 40 rows give main's verdict and main's page count in both builds: 33 save and 7 are refused with the limit's message. Four of the saving rows are a table with a header row or a row-span cell. The rows are paragraph, heading, list item, a list in a renderer of yours, a list after a renderer of yours, start lines, a paragraph handed over as an overflow, page references, tab stops, headers and footers, a list near the limit, a list with an entry no page holds, and one renderer laid out in two documents, with texts of
urlwords, no-break spaces and glued runs. The table rows, 70,000 rows of oneurlon a 92 x 180 page: forwarded by a renderer of yours, main saves 35,000 pages (136 s) and the head 35,000 (132 s); added directly, main 35,000 (335 s) and the head 35,000 (346 s).Allocation with the setting off,
GC.GetAllocatedBytesForCurrentThreadover a save, same runtime, main against head: one paragraph 32,864 B and 32,864 B; one one-row table 24,488 B and 24,496 B; 500 tables 3,425,456 B and 3,429,456 B; a 2,000-row table (about 1,000 pages) 97,534,816 B and 97,550,808 B. The difference is 8 bytes for eachTableRendererand each piece it splits into (twoboolfields), and nothing per draw or per wrap.On and the refusals
LongWordBreakTestsholds the cut tests and passes the value to each wrap: the exact index, the last place that fits, the LB25 fallback,//, no glyph added, a word that fits never cut, the interval a cell's cached line count holds over, link rectangles per piece, extraction, and PDF/A-2u (veraPDF 1.30.4).LongWordSettingTestspins the setting on the document;LongWordReuseTestspins the context and the binding.TheSettingIsOffByDefaultWithTheSettingOff_everyWrapCutsAtTheGlyph,WithTheSettingOn_everyWrapCutsAfterThePlace(7 kinds each)ATabbedParagraphCutsAfterThePlaceWhenOn_andAtTheGlyphWhenOff,ACellOfRunsHoldingACharacterOutsideTheBasicPlane_isCutAtTheOffsetsOfItsCharactersWithTheSettingOn_aParagraphThatTakesMoreThanTheLimitIsRefused_andSavesWithItOffWithTheSettingOn_aHeaderRowThatNoLongerFitsIsRefusedAsTooTall_andSavesWithItOff,WithTheSettingOn_aRowSpanGroupThatNoLongerFitsIsRefusedAsTooTall_andSavesWithItOffTask.Run, a newThread,Parallel.Forand underSuppressFlow; with a freshnew LayoutContext(area)the child reads falseAParagraphLaidOutThroughADerivedContext_readsTheDocumentsValueOnAnyFlow,ATableLaidOutThroughADerivedContext_isMeasuredAndDrawnWithTheDocumentsValueOnAnyFlow,AParagraphLaidOutThroughAFreshContext_readsFalse_whateverTheDocumentSays,ATableLaidOutThroughAFreshContext_readsFalse_whateverTheDocumentSaysAParagraphRendererLaidOutInADocumentWithTheOtherValue_isRefused,ATableRendererLaidOutInADocumentWithTheOtherValue_isRefused,APieceOfAParagraphIsBoundToTheValueItWasCutUnder,APieceOfATableThatResumesACutRowIsBoundToTheValueItWasCutUnderAListRendererLaidOutByTwoDocuments_followsEachDocumentAndIsNotRefused,APieceOfAListIsBoundToTheValueItWasCutUnder,AListWhoseIndentLeavesTheTextNoWidth_isLaidOutWithTheTextWithTheSettingOn,ATableRowCutAcrossPages_drawsEveryLineOfEveryPageAfterThePlaceAWorkerThatAnOnSaveStarted_readsTheLaterOffDocumentsValue,WorkThatOutlivesTheSave_readsTheContextItWasGiven_andNothingTheSaveLeft,TwoSavesInARow_eachReadItsOwnDocumentsValueATableThatSplitsOverPages_drawsEveryLineOfEveryPieceAfterThePlace,ADocumentThatLeavesTheSettingOff_savesWhatAFreshOneDoes_afterAnOnDocumentWasRefusedTheStaticWraps_takeNoValueAndCutAtTheGlyphMutations
Run in a detached worktree, net10.0, the three test classes; each fails at least one named test.
AParagraphRendererLaidOutInADocumentWithTheOtherValue_isRefusedAPieceOfATableThatResumesACutRowIsBoundToTheValueItWasCutUnderAPieceOfAParagraphIsBoundToTheValueItWasCutUnderATableThatSplitsOverPages_drawsEveryLineOfEveryPieceAfterThePlaceATableCellStringIsCutAtThePlaceWithAreadoes not copy the valueAParagraphLaidOutThroughADerivedContext_readsTheDocumentsValueOnAnyFlow(Inline)ATableRowCutAcrossPages_drawsEveryLineOfEveryPageAfterThePlaceLayoutContext.Addressdoes not copy the valueAListWhoseIndentLeavesTheTextNoWidth_isLaidOutWithTheTextWithTheSettingOnWithTheSettingOn_everyWrapCutsAfterThePlace(NoteBlock)WithTheSettingOn_aHeaderRowThatNoLongerFitsIsRefusedAsTooTall_andSavesWithItOffATabbedParagraphCutsAfterThePlaceWhenOn_andAtTheGlyphWhenOffACellOfRunsHoldingACharacterOutsideTheBasicPlane_isCutAtTheOffsetsOfItsCharactersNot killed: the bind of each list entry's content before its line count is read. By reading the code, no program reaches it: the one line count that can precede an entry's first layout is
UnitBound, which runs only under a context the document addressed, afterTryEntriesOnAnEmptyPagehas laid every entry out under the same value. It is a guard, kept for that reason.Not changed
The continuation-limit decision, the list, heading and table twins,
Tokeniseand the word split of #562 and #590 are as on main.Extraction, links
No glyph is added, so a cut address extracts as written with the extractor's line separator between the pieces. Reading a cut address back as one token needs marked content (
/ActualText), which is #588 (v2.5). ALinkUriorLinkAnchorrun that wraps gets one rectangle per piece, and a test checks that each covers its piece.