Skip to content

refactor(layout): move the page-flow cursor helpers onto CompilerState#352

Merged
DemchaAV merged 1 commit into
2.0-devfrom
refactor/compilerstate-cursor-methods
Jul 10, 2026
Merged

refactor(layout): move the page-flow cursor helpers onto CompilerState#352
DemchaAV merged 1 commit into
2.0-devfrom
refactor/compilerstate-cursor-methods

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

Why

First step of the stateful LayoutCompiler decomposition. advanceSpace / closeBottomSpace lived on LayoutCompiler but only read and mutate the page-flow cursor (pageIndex, usedHeight) that CompilerState already owns — so they belong on the state object, not the compiler.

What

  • Move advanceSpace(double) and closeBottomSpace(double) onto CompilerState (the , CompilerState state parameter becomes the receiver). Bodies are verbatim; EPS now comes from the shared NodeDefinitionSupport.EPS (same 1e-6) instead of LayoutCompiler's private copy.
  • The three call sites become state.advanceSpace(...) / state.closeBottomSpace(...).
  • No public API change (document.layout is @Internal); layout output is unchanged.

Tests

  • New 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, and closeBottomSpace positive-advance / negative-pull-up-clamped-at-zero.
  • Core suite (411) and the qa byte-identity gate (642 → 643 with the earlier scale-smoke; PageMarginTest, PaginationEdgeCaseTest, PdfVisualRegressionTest, all *VisualParityTest, LayoutSnapshotRegressionDemoTest) green: renders are byte-identical.

Follow-up

The remaining LayoutCompiler methods (compileComposite / compileHorizontalRow / stack + splittable placement) are mutually recursive through the dispatch and more entangled with CompilerState; further decomposition there is a separate, larger step.

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.
@DemchaAV DemchaAV merged commit 43a23d7 into 2.0-dev Jul 10, 2026
12 checks passed
@DemchaAV DemchaAV deleted the refactor/compilerstate-cursor-methods branch July 10, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant