refactor(layout): move the page-flow cursor helpers onto CompilerState#352
Merged
Merged
Conversation
Move advanceSpace and closeBottomSpace off LayoutCompiler onto CompilerState — they only read and mutate the page-flow cursor (page index, used height), so they belong on the state object they operate on. Callers now invoke state.advanceSpace(...) / state.closeBottomSpace(...). Layout output is unchanged; the cursor arithmetic is now unit-testable in isolation. Add CompilerStateTest covering advance / spill-to-new-page / cap-at-content and the closeBottomSpace positive-advance / negative-pull-up-clamped cases.
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.
Why
First step of the stateful
LayoutCompilerdecomposition.advanceSpace/closeBottomSpacelived onLayoutCompilerbut only read and mutate the page-flow cursor (pageIndex,usedHeight) thatCompilerStatealready owns — so they belong on the state object, not the compiler.What
advanceSpace(double)andcloseBottomSpace(double)ontoCompilerState(the, CompilerState stateparameter becomes the receiver). Bodies are verbatim;EPSnow comes from the sharedNodeDefinitionSupport.EPS(same1e-6) instead ofLayoutCompiler's private copy.state.advanceSpace(...)/state.closeBottomSpace(...).document.layoutis@Internal); layout output is unchanged.Tests
CompilerStateTest(6): the cursor arithmetic in isolation — advance-when-it-fits, spill-to-new-page on overflow, drop-non-positive, cap-at-content-height on a fresh page, andcloseBottomSpacepositive-advance / negative-pull-up-clamped-at-zero.PageMarginTest,PaginationEdgeCaseTest,PdfVisualRegressionTest, all*VisualParityTest,LayoutSnapshotRegressionDemoTest) green: renders are byte-identical.Follow-up
The remaining
LayoutCompilermethods (compileComposite/compileHorizontalRow/ stack + splittable placement) are mutually recursive through the dispatch and more entangled withCompilerState; further decomposition there is a separate, larger step.