Skip to content

feat: named page templates, print preview and user stylesheet - #157

Merged
gnacho merged 3 commits into
masterfrom
feat/153-page-templates
Oct 27, 2026
Merged

gnacho merged 3 commits into
masterfrom
feat/153-page-templates

Conversation

@gnacho

@gnacho gnacho commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Closes #153.
Closes #156.

What changed

Named page templates (#153). A template groups margins, body and monospace typography, line height, heading scale and spacing, colour scheme, header and footer, and a title block built from the document title. Four built-ins ship: Article (today's defaults), Manuscript, Letter and Compact. Custom keeps the granular controls exactly as they were.

The selector lives in Preferences > Export and the choice persists in GSettings (export-template). The granular rows are insensitive unless Custom is selected, because the template would override them anyway. Page size and orientation stay independent: they describe the paper, not the layout.

Print preview (#153). A new "Print Preview…" menu item next to "Export to PDF…" runs the same GtkPrintOperation with PrintOperationAction::Preview, so the preview is drawn by the export pipeline itself and is WYSIWYG by construction.

User stylesheet (#156). A CSS file can be loaded in Preferences > Export and is applied on top of the selected template. It is a mapped subset, not a CSS engine: @page margins, and on body/html/:root, p, h1-h4, pre/code, blockquote, a and table the properties font-family, font-size, line-height, color, background-color, margin-bottom and the custom property --block-spacing. Unknown selectors and properties are ignored with a one-line warning on stderr, never aborting the export. Removing the file restores the template output byte for byte.

Notes

  • No new dependencies. The layout is still src/export_pdf.rs and its pagination rules; the CSS parser is a new src/export_css.rs with no GTK in it.
  • Custom reproduces the previous output exactly: same margins (paper defaults), 1.4 line height, 10 pt block spacing, current heading scale, no header, footer or title block.
  • Header and footer are drawn inside the page margins at 8 pt in the muted colour, so they do not eat into the text area.
  • Page backgrounds, including those set from CSS, now cover the whole sheet rather than only the printable area.

Testing

  • xvfb-run -a make check green: fmt, clippy with -D warnings, and every suite (export_pdf 135, tabs_smoke 165, plus the rest), 0 failures.
  • New unit tests for the four presets (margins, line height, spacing, ornaments, title block), for the CSS parser (units, 1 to 4 value margins, colours, line height, family mapping, invalid input, comments, unknown properties reported once) and for the stylesheet overriding the template.
  • An ignored integration test exports the same document without a stylesheet, with one, and without it again, rasterises page 1 with pdftoppm and asserts the first and third are identical and the second differs.
  • The five presets were exported to PDF and reviewed as images: Custom and Article are identical, Manuscript gets 72 pt margins with a running title and page number, Letter 54 pt, Compact 36 pt with tighter spacing.

@gnacho
gnacho merged commit 15b345e into master Oct 27, 2026
3 checks passed
@gnacho
gnacho deleted the feat/153-page-templates branch October 27, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF export: user CSS subset Preview and PDF export: named page templates

1 participant