Repository navigation
Let the :first, :left and :right pages set the side margins text flows into (#476) - #510
Merged
Merged
Conversation
jakejackson1
force-pushed
the
feature/476-page-frame-per-page
branch
2 times, most recently
from
September 28, 2026 23:47
1678071 to
8b2a26c
Compare
This was referenced Sep 28, 2026
jakejackson1
force-pushed
the
feature/476-page-frame-per-page
branch
2 times, most recently
from
September 29, 2026 03:05
2bef63d to
623dc33
Compare
…s into (#476) SetPagedMediaCSS() dropped margin-left and margin-right from every pseudo page, so all pages of a named page shared one page area width. They are now kept. A side margin on a pseudo page is the margin of that side of the physical page: with mirrorMargins it is not swapped on an even page, while a side it leaves unset keeps the mirrored margin of the plain @page rule. Text carrying on over an automatic page break moves into the page area of the new page: MarginCorrection becomes how far the page area moved rather than the mirrored difference, open blocks are widened or narrowed with the page area (a block with a set width keeps it), and columns are laid out from the physical margins of each page. When the page areas of a flow differ, a line that cannot fit turns the page before it is filled, so it is measured against the page area it is set in. The page area methods are in a PageAreas trait that Mpdf uses, as they read and write its layout state. The @page rule lookups read only the style sheet, so they are on CssManager and tested there without a document. The pseudo-page-areas snapshot sets a story over :first, :left and :right pages with their own side margins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakejackson1
force-pushed
the
feature/476-page-frame-per-page
branch
from
September 29, 2026 03:13
623dc33 to
c0d1f83
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.
Closes #476.
SetPagedMediaCSS()droppedmargin-leftandmargin-rightfrom every:first,:leftand:rightpage, so every page of a named page had the same page area: the space between its side margins, where text is set. This PR keeps those margins, so text flowing from page to page is set in the page area of each page. For example, a story can start in a narrow page area under its title on the first page and carry on at full width on the pages after it.Mirroring. A side margin on a pseudo page is the margin of that side of the physical page, as in CSS Paged Media. With
mirrorMarginsit is not swapped on an even page.pseudoPageProperties()passes it in pre-swapped so the swap inpageSideMargins()puts it back. A side the pseudo page leaves unset keeps the plain@pagemargin, mirrored as before. Documents that set no side margins on pseudo pages are unchanged: every snapshot is byte-identical.Text carried over a page break
AddPage()records the page area text leaves from, andmoveIntoPageArea()moves the text into the page area of the new page:MarginCorrectionbecomes how far the page area moved.SetColumns()lays columns out from the page's physical margins throughpageSideMargins().ResetMargins()now uses the same helper, andSetCol()no longer adds the even-page correction. Both askmarginsForcedPortrait()whether a landscape page keeps the portrait margins.turnPageAheadOfLine()turns the page before a line that can't fit is filled, so the line is measured against the page area it is set in. It is gated byCssManager::pseudoPagesSetSideMargins(), and it only fires where a break was already certain.Cell,finishFlowingBlock,WriteFlowingBlockand the new look-ahead) are now one helper,turnPageKeepingPlace().Where the code lives
pageSideMargins(),marginsForcedPortrait(),pageArea(),moveIntoPageArea(),turnPageKeepingPlace()andturnPageAheadOfLine()) are in a newPageAreastrait thatMpdfuses. They read and writeMpdf's layout state, so they stay part of it, in a file of their own. The PRs stacked on this one add their methods there too.@pagelookups read only the style sheet, so they are onCssManager:pseudoPageProperties(), andpseudoPagesSetSideMargins(), which says whether a pseudo page of the plain or current named page sets a side margin.Not in this PR
column-countin@page(the other option in Let text that flows onto a new page take that page's column count and frame #476). Every page-turn site computes the new x asMarginCorrection + ChangeColumn * (ColWidth + ColGap), and blockx0isn't kept up to date inside columns. Changing the count mid-flow needs deeper work in the column code.Tests
PseudoPageAreaTestchecks the x span of every line drawn on each page::firstagainst later pages:left/:rightmargins as written:firstTextRecordingMpdfalso records each drawn line's page and edges.CssManagerTestcovers the two lookups without rendering: which pseudo pages apply, the sheet size left out, the side margins swapped on an even page, and which rules count as setting a side margin.pseudo-page-areas: a story on a named page, set between 100 and 195mm on its first page, 15 and 180mm on left pages and 30 and 195mm on right pages, with two columns after it. Ongravitypdfevery page differs, and the document is a page shorter.composer testpasses (4441 tests, 31 skipped). phpcs and PHPStan are clean.CHANGELOG-GRAVITYPDF.mdgets a New features entry under a new Paged media heading.I also checked it against a 48-page magazine template. The template renders pixel-identical on this branch, and one article's opening and body pages, previously split with an explicit
<pagebreak>, can now be one flow.Text beside a float that runs over pages of different widths is fixed separately in #549, which is stacked on this one.
🤖 Generated with Claude Code