fix(api): honor negative bottom margin, reject negative page margin#232
Merged
Conversation
A negative bottom margin on a composite was silently dropped by the vertical flow — its bottom-edge advance early-returned on a non-positive amount — while a negative page margin was accepted and silently overflowed the sheet. Composites now close their bottom edge through closeBottomSpace, which lets a negative bottom margin pull the following sibling up, symmetric with a negative top margin (which already offsets via placementTopY). The top-of-node reservation and the row/leaf paths are untouched, so existing layouts are byte-identical. DocumentSession now rejects a negative page margin with IllegalArgumentException pointing to bleed(); node margins still allow negatives for overlap tricks. Tests: NegativeMarginTest covers the page margin rejected via the builder and via the session setter, zero/positive accepted, and a negative bottom margin shifting the following section up by the margin. Full suite green, no visual baselines changed.
71e7cd0 to
d85fc12
Compare
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
Two sides of the same gap in how the layout flow treats a negative margin:
What changed
closeBottomSpace. A positive bottom inset advances the flow as before; a negative one pulls the following sibling up — symmetric with a negative top margin, which already offsets viaplacementTopY. The top-of-node reservation, the inter-child spacing, and the row/leaf paths are untouched (rows/leaves already fold the bottom inset into their positive content height), so every existing layout is byte-identical.DocumentSession.margin(...)(and the builder'smargin(...)) now reject a negative page margin withIllegalArgumentException, pointing the caller at a node'sbleed(...)to reach the page edge. Node margins still allow negatives — they're a legitimate overlap/inset trick (e.g. a widget pulling up over the band above it).Lane: shared-engine (
LayoutCompiler) + canonical (DocumentSession). Purely additive at the signature level → japicmp-safe.Verification
./mvnw test -pl .— 1530 green, 0 visual baselines changed (the engine change is byte-identical for all existing content; the EPS boundary was checked to confirm no divergence for non-negative bottom insets).NegativeMarginTest: negative page margin rejected via the builder and via the session setter, zero/positive accepted, and a section with a negative bottom margin shifts the following section up by exactly that margin.Behavior note: callers that previously passed a negative page margin (and got silent overflow) now get a clear exception — intended, and called out in the CHANGELOG.