fix: honor requested PDF page dimensions - #3
Conversation
kolkov
left a comment
There was a problem hiding this comment.
Real bug — the backend accepted width/height but always created A4 pages. NewPageWithDimensions is the right fix.
Good defensive detail: staging new state before mutation so a failed Begin leaves the prior page coherent. Non-positive dimension rejection is delegated to gxpdf's own validation rather than duplicated — reasonable since NewPageWithDimensions already guards this. The MediaBox serialization tests verify the actual PDF output, not just internal state.
gxpdf v0.4.0 bump is required for NewPageWithDimensions — confirmed available.
LGTM, merging.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
This PR has a merge conflict after #1, #2, and #4 were merged. The conflict is in Could you rebase on the updated main? The conflicts should be straightforward — the flip transform is now |
1f52dc6 to
7acf334
Compare
Summary
Backend.BeginDocument.NewPageNewPageWithDimensionsBeginleaves the prior page coherentWhy
The backend accepted width and height but always created an A4 page. For example,
Begin(320, 240)serialized/MediaBox [0 0 595 842]instead of320 x 240. Recording playback passes its canvas dimensions directly toBackend.Begin, so the output page size must preserve them.gxpdf v0.2.0 has no public arbitrary-page-size API. v0.4.0 is the first release with
Creator.NewPageWithDimensions, making it the smallest dependency update that can implement the contract cleanly.Verification
Begin(320, 240)produces A4 MediaBoxBeginpreserves the previously initialized pagego test -count=1 ./...go test -race -count=1 ./...go test -count=1 -coverprofile=coverage.out ./...go build ./...go vet ./...go mod tidy -diffgofmtandgit diff --checkUpstream GitHub Actions and
codecov/patchare configured but await maintainer approval of the fork workflow run.Coordination
This is independent of #2, although both patches touch page initialization and may need a trivial rebase depending on merge order.
Review follow-up (2026-08-12)
Rebased onto the merged lifecycle/y-flip work. The combined implementation preserves
Scale(1, -1).Then(Translate(0, height)), retains the injectable page-creation failure seam, and creates every page with its exact requested dimensions.