From 3813aaa8c7168509fbc5b3650cc218462897b3ae Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Sat, 5 Sep 2026 21:26:24 +0200 Subject: [PATCH] fix(html): print a sheet onto the page, without our ruler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A spreadsheet is laid out at the width the file states — one `` per column carrying the document's own width, under `table-layout:fixed`. Paper cannot scroll, so what did not fit was cut off along the right edge once the browser's own shrink-to-fit gave up: silent, bounded, and different per browser and print path. A phone print has no scale control to correct it with, which is where it was reported. `@media print` fits the sheet to the page instead, and leaves off the row and column ruler, which is ours rather than the file's and took about a centimetre a page has none of to spare. The screen view is untouched. Towards #816, opendocument-app/OpenDocument.droid#644. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01Fp26La4hFAu9VRMHPjKmXd --- CHANGELOG.md | 4 ++++ src/odr/internal/html/frontend.cpp | 11 +++++++++++ test/src/html_test.cpp | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7981b7ea4..5c26a6ae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ The release run heads these entries with the version and opens a fresh ## Unreleased +- A printed sheet drops our row/column ruler and is capped to the page width + rather than cut off at the right edge. Print only; the on-screen view is + unchanged. Towards #816. + - New `File::name()`: the file name on disk, the entry name inside an archive, or the name `File::from_memory(data, name)` was given. A named in-memory file gets the same name-derived type candidate a path does, so `notes.md` bytes diff --git a/src/odr/internal/html/frontend.cpp b/src/odr/internal/html/frontend.cpp index 246b67dc9..12ed40a13 100644 --- a/src/odr/internal/html/frontend.cpp +++ b/src/odr/internal/html/frontend.cpp @@ -112,6 +112,17 @@ body{margin:0;background:var(--odr-sheet-canvas)} .odr-sheet-sort:hover{background:var(--odr-sheet-wash-ruler)} .odr-sheet-sort::after{content:"\25BE";font-size:15px;line-height:1} .odr-sheet-sort-asc::after{content:"\25B4"} +/* Paper cannot scroll, so a sheet wider than the page is cut off; only + `!important` beats the inline column width. The ruler collapses rather than + `display:none`, which would take the cells out of their rows and shift every + column left. */ +@media print{ +.odr-sheet thead{display:none} +.odr-sheet-gutter{visibility:collapse;width:0} +.odr-sheet-row-header{visibility:collapse;padding:0;box-shadow:none} +.odr-sheet{max-width:100%} +.odr-sheet col{min-width:0!important} +} )css"; constexpr std::string_view spreadsheet_dark_css = R"css( diff --git a/test/src/html_test.cpp b/test/src/html_test.cpp index 7e63a3fd5..e76d7aad1 100644 --- a/test/src/html_test.cpp +++ b/test/src/html_test.cpp @@ -728,6 +728,24 @@ TEST(html, the_cell_budget_bounds_the_rows_by_the_width) { EXPECT_EQ(rendered(30, 3).rows, 5); } +// #816 +TEST(html, a_printed_sheet_drops_the_ruler_and_fits_the_page) { + const std::string sheet = + render("odr-public/ods/file_example_ODS_10.ods", HtmlConfig()); + + // on screen the sheet keeps its stated width and its ruler + EXPECT_NE(sheet.find("c"), FileType::xml); const HtmlService service = html::translate(file, HtmlConfig());