1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
41using TheArtOfDev . HtmlRenderer . Core . Dom ;
52
63namespace TheArtOfDev . HtmlRenderer . Core . Fragmentation
74{
85 /// <summary>
96 /// A resumption record: where layout stopped in one fragmentainer, so the next one can pick up from
107 /// exactly that point (https://www.w3.org/TR/css-break-3/#breaking-controls, CSS Fragmentation Level 3
11- /// §2/§4.4). Ported from PeachPDF's <c>BreakToken</c>, reduced to the two token kinds this port's
12- /// block/inline scope needs (<see cref="TableBreakToken"/> is added in the table-fragmentation stage).
8+ /// §2/§4.4). Ported from PeachPDF's <c>BreakToken</c>, reduced to what this port's driver loop
9+ /// actually needs: only forced <c>break-before</c>/<c>break-after: page</c> ever produces a real
10+ /// cross-pass token here (see <see cref="BlockFragmentation.TryGetForcedBreakTarget"/>) - overflow,
11+ /// <c>break-inside:avoid</c>, keep-with-next, widows/orphans, and table-row breaks all turned out to
12+ /// be same-pass local corrections instead (confirmed empirically stage by stage while investigating
13+ /// the fragmentation-engine-parity plan's R2-R9), so PeachPDF's inline and table token kinds - and its
14+ /// per-token <c>FanOutContinuations</c> "parallel flows" mechanism, which only those kinds ever used -
15+ /// have no counterpart in this port and were never added.
1316 /// </summary>
1417 /// <remarks>
1518 /// Tokens form a chain, one link per ancestor between the fragmentation-context root and the box that
@@ -24,16 +27,7 @@ namespace TheArtOfDev.HtmlRenderer.Core.Fragmentation
2427 /// after this one": a box can be placed far down the document, so the fragmentainer it overflows is
2528 /// not in general the one after the fragmentainer the pass nominally started in.
2629 /// </param>
27- internal abstract record BreakToken ( CssBox Box , int ResumeSlotIndex )
28- {
29- /// <summary>
30- /// This token's per-child continuations, for a token naming more than one -
31- /// https://www.w3.org/TR/css-break-3/#parallel-flows (§2.1 parallel-flows), the shape
32- /// <see cref="TableBreakToken"/> uses. Empty for every other kind, whose one child (if any) is
33- /// <see cref="BlockBreakToken.ChildToken"/> instead.
34- /// </summary>
35- internal virtual IReadOnlyList < BreakToken > FanOutContinuations => Array . Empty < BreakToken > ( ) ;
36- }
30+ internal abstract record BreakToken ( CssBox Box , int ResumeSlotIndex ) ;
3731
3832 /// <summary>A block container stopped part-way through its in-flow children.</summary>
3933 /// <param name="Box">the block container to resume</param>
@@ -60,53 +54,4 @@ internal sealed record BlockBreakToken(
6054 BreakToken ChildToken ,
6155 bool IsBreakBefore ,
6256 double ? ResumeTopOverride ) : BreakToken ( Box , ResumeSlotIndex ) ;
63-
64- /// <summary>A block container's inline flow stopped part-way through its content.</summary>
65- /// <remarks>
66- /// <see cref="ResumePath"/> is a path rather than a single index because inline layout walks the
67- /// inline box tree recursively: resuming means descending the same path again and fast-forwarding to
68- /// the word that did not fit, rather than replaying the walk from the top.
69- /// </remarks>
70- /// <param name="Box">the block container whose inline flow stopped</param>
71- /// <param name="ResumeSlotIndex">the pagination slot the resumed pass fills</param>
72- /// <param name="ResumePath">child indices from <paramref name="Box"/> down to the inline box owning the word</param>
73- /// <param name="ResumeWordIndex">the index into that box's words to resume at</param>
74- /// <param name="CompletedLineCount">
75- /// how many line boxes the container had already produced when the break was taken. Everything below
76- /// this index has been emitted into an earlier fragmentainer and must not be re-aligned or re-measured
77- /// by the resumed pass.
78- /// </param>
79- /// <param name="LinesKeptHere">
80- /// how many line boxes this fragmentainer kept - <see cref="CompletedLineCount"/> minus what the pass
81- /// began with. This is the quantity <c>orphans</c> is defined over
82- /// (https://www.w3.org/TR/css-break-3/#widows-orphans, §5.4: line boxes left in a fragment before the
83- /// break), which the cumulative count cannot answer for any fragment but the first.
84- /// </param>
85- internal sealed record InlineBreakToken (
86- CssBox Box ,
87- int ResumeSlotIndex ,
88- IReadOnlyList < int > ResumePath ,
89- int ResumeWordIndex ,
90- int CompletedLineCount ,
91- int LinesKeptHere = 0 ) : BreakToken ( Box , ResumeSlotIndex )
92- {
93- /// <summary>
94- /// Compared by contents, because the driver's no-progress backstop is an equality test. The
95- /// compiler-generated record equality would compare <see cref="ResumePath"/> - an
96- /// <see cref="IReadOnlyList{T}"/> - by reference, so two passes that legitimately stopped at the
97- /// same word would compare unequal and the loop would spin to its pass-count cap instead of
98- /// recognizing no progress was made. See the plan's "break-token equality footgun" risk note.
99- /// </summary>
100- public bool Equals ( InlineBreakToken other ) =>
101- other is not null
102- && ReferenceEquals ( Box , other . Box )
103- && ResumeSlotIndex == other . ResumeSlotIndex
104- && ResumeWordIndex == other . ResumeWordIndex
105- && CompletedLineCount == other . CompletedLineCount
106- && LinesKeptHere == other . LinesKeptHere
107- && ResumePath . SequenceEqual ( other . ResumePath ) ;
108-
109- public override int GetHashCode ( ) =>
110- HashCode . Combine ( Box , ResumeSlotIndex , ResumeWordIndex , CompletedLineCount , LinesKeptHere , ResumePath . Count ) ;
111- }
11257}
0 commit comments