Put a landscape folio on its standard sheet in --export-pdf

The PDF export sizes each page to its folio, and QPageSize rounds a size
within 3 pt of a standard sheet to the sheet. QPageSize knows the sheets
upright only (bar Ledger), so only portrait folios snapped: an A3 landscape
folio came out as a 1190 x 841 pt page, while an A3 portrait one was
842 x 1191, the sheet. A wide folio is now matched upright and turned.

tst_pdfpagesize exports a fixture with an A3 folio each way and checks both
pages are A3; it fails without the change (1190 x 841).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-02 22:53:13 +13:00
parent 808d6a3c5b
commit 797d502c0a
4 changed files with 171 additions and 5 deletions
+12 -5
View File
@@ -171,11 +171,18 @@ int exportPdf(QETProject &project, const QString &output,
for (Diagram *diagram : diagrams) {
const QRect r = diagramRect(diagram);
// Match the page to the diagram (in points: 1px @ 96dpi = 0.75pt).
const QPageSize page(QSizeF(r.width() * 72.0 / 96.0,
r.height() * 72.0 / 96.0),
QPageSize::Point);
writer.setPageSize(page);
writer.setPageMargins(QMarginsF(0, 0, 0, 0));
// QPageSize rounds a size within 3 pt of a standard sheet to the
// sheet, but knows the sheets upright only (bar Ledger), so a wide
// folio is matched upright and turned: otherwise an A3 landscape
// folio became a 1190 x 841 pt page while an A3 portrait one was
// 842 x 1191, the sheet.
QSizeF points(r.width() * 72.0 / 96.0, r.height() * 72.0 / 96.0);
const bool wide = points.width() > points.height();
if (wide) points.transpose();
writer.setPageLayout(QPageLayout(QPageSize(points, QPageSize::Point),
wide ? QPageLayout::Landscape
: QPageLayout::Portrait,
QMarginsF(0, 0, 0, 0)));
if (first) {
if (!painter.begin(&writer)) {