feat(document): fit a printed sheet to the paper the file states - #820
Merged
Conversation
andiwand
force-pushed
the
feat/fit-a-sheet-to-the-paper-it-states
branch
from
September 5, 2026 20:20
7571d4d to
9fccbc5
Compare
andiwand
force-pushed
the
fix/print-a-sheet-onto-the-page
branch
2 times, most recently
from
September 5, 2026 20:22
ee58f5c to
3813aaa
Compare
andiwand
force-pushed
the
feat/fit-a-sheet-to-the-paper-it-states
branch
2 times, most recently
from
September 5, 2026 20:23
ef95563 to
5f79400
Compare
A sheet's page style — the paper it is printed on — was neither parsed nor exposed, so the print stylesheet had nothing to fit against and left the browser to squeeze the sheet to the page, which distorts the column widths the file gives it. New `Sheet::page_layout()`, read for ods from the master page the table style names, the way a paragraph's page is; empty for the formats whose print setup is unparsed. `translate_sheet` states the factor the paper asks for per sheet, and the print stylesheet applies it as a `zoom`, so the sheet prints at the file's own proportions. Only ever down, and the stylesheet's cap stays as the guard for paper the file did not expect. Towards #816. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fp26La4hFAu9VRMHPjKmXd
andiwand
force-pushed
the
feat/fit-a-sheet-to-the-paper-it-states
branch
from
September 5, 2026 20:38
5f79400 to
375cd9c
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.
🤖 Generated with Claude Code
Stacked on #817 — review that first; this branch contains it.
The second part of #816: the file's own paper reaches the printed page. #817 fits the sheet to whatever paper it lands on, by capping the table's width — which never clips, but squeezes the column widths unevenly. This reads the paper the file states and scales the sheet by it, so the printed sheet keeps the proportions the document has.
What was missing
Sheethad no page layout, and no engine parsed one. The paper, orientation and margins an ods states for a sheet live on the master page its table style names — the same indirection a paragraph's page uses, andStyleRegistry::master_page_of_stylealready walked it for text roots, slides and drawing pages. Nothing asked it for a sheet.What this adds
Sheet::page_layout()— new on the public API, a new virtual onabstract::SheetAdapter, implemented by all five engines that provide sheets, and mirrored in the Python, JNI and Apple bindings (wasm binds no document elements). Real for ods; empty, with the reason, for xlsx, xls,.numbersand csv.translate_sheetstates the factor the paper asks for, per sheet, as--odr-print-fiton the sheet's own table: the printable width (page less its side margins) over the sum of the column widths. Only ever down — a sheet that already fits is printed at its size, never enlarged.zoom, which scales the layout, so rows still break across pages. fix(html): print a sheet onto the page, without our ruler #817'smax-widthcap stays behind it, as the guard for paper the file did not expect.Measured
A 6-column sheet of
3in,1in,3in,1in,3in,1inon Letter with 1in margins, rendered bytranslate, printed with Chrome headless, columns measured from the PDF text positions:117pt is 216pt × 0.5417, and 0.5417 is exactly the 6.5in printable width over the 12in the sheet is wide — so the sheet prints at the scale the file's paper implies, undistorted.
What it does not do
Half the corpus states no paper. 22 of the 52 ods here carry
fo:page-width; the rest state margins only and leave the paper to the printer. Those get no factor and keep #817's behaviour exactly. Reading a frontend-supplied paper fromHtmlConfig— the Android side knows itsPrintAttributes— is the obvious next increment, and would cover them.No
@pagerule. Declaring the file's paper to the printer would want one, but a print path that honours CSS page size over the framework's own attributes has to be established per frontend first, and a view that renders several sheets has several answers. Left out deliberately.xlsx is not wired up, and its
pageSetupalone would buy nothing: a column width there is ach, so no absolute content width can be summed to compare against the paper. Both halves are one follow-up.Pagination — a wide sheet continuing onto further pages at full size, the way a spreadsheet application prints it — remains the open half of #816.
Tests
Document.ods_sheet_page_layoutreads the paper off a real ods;Document.ods_sheet_page_layout_without_a_paper_sizepins the common margins-only case. On the renderer,html.a_sheet_is_fitted_to_the_paper_the_file_stateschecks the factor against the file's numbers, andhtml.a_sheet_is_only_ever_fitted_downdrives three inline flat-ods sheets — narrower than, exactly, and twice its paper.Reference output is unchanged in what it renders: the new attribute is inert outside print, so no pixel moves and no pin advances.