QPagedPaintDevice: Fix setPageSize() to set correct metrics
Use the correct metrics for the requested PageSize instead of always defaulting to A4. Task-number: QTBUG-30494 Change-Id: Ia3978afe3f7cc9b1ded1065416e5c3def44e7a05 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>bb10
parent
47ce14cf74
commit
839a9c11de
|
|
@ -169,7 +169,7 @@ void QPagedPaintDevice::setPageSize(PageSize size)
|
|||
if (size >= Custom)
|
||||
return;
|
||||
d->pageSize = size;
|
||||
d->pageSizeMM = QSizeF(pageSizes[A4].width, pageSizes[A4].height);
|
||||
d->pageSizeMM = QSizeF(pageSizes[size].width, pageSizes[size].height);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -119,6 +119,8 @@ private slots:
|
|||
|
||||
void taskQTBUG4497_reusePrinterOnDifferentFiles();
|
||||
void testPdfTitle();
|
||||
void testPageMetrics_data();
|
||||
void testPageMetrics();
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
@ -1108,6 +1110,42 @@ void tst_QPrinter::testPdfTitle()
|
|||
const char *expected = reinterpret_cast<const char*>(expectedBuf);
|
||||
QVERIFY(file.readAll().contains(QByteArray(expected, 26)));
|
||||
}
|
||||
|
||||
void tst_QPrinter::testPageMetrics_data()
|
||||
{
|
||||
QTest::addColumn<int>("pageSize");
|
||||
QTest::addColumn<int>("widthMM");
|
||||
QTest::addColumn<int>("heightMM");
|
||||
QTest::addColumn<float>("widthMMf");
|
||||
QTest::addColumn<float>("heightMMf");
|
||||
|
||||
QTest::newRow("A4") << int(QPrinter::A4) << 210 << 297 << 210.0f << 297.0f;
|
||||
QTest::newRow("A5") << int(QPrinter::A5) << 148 << 210 << 148.0f << 210.0f;
|
||||
QTest::newRow("Letter") << int(QPrinter::Letter) << 216 << 279 << 215.9f << 279.4f;
|
||||
}
|
||||
|
||||
void tst_QPrinter::testPageMetrics()
|
||||
{
|
||||
QFETCH(int, pageSize);
|
||||
QFETCH(int, widthMM);
|
||||
QFETCH(int, heightMM);
|
||||
QFETCH(float, widthMMf);
|
||||
QFETCH(float, heightMMf);
|
||||
|
||||
QPrinter printer(QPrinter::HighResolution);
|
||||
printer.setFullPage(true);
|
||||
printer.setPageSize(QPrinter::PageSize(pageSize));
|
||||
|
||||
if (printer.pageSize() != pageSize) {
|
||||
QSKIP("Current page size is not supported on this printer");
|
||||
return;
|
||||
}
|
||||
|
||||
QCOMPARE(printer.widthMM(), int(widthMM));
|
||||
QCOMPARE(printer.heightMM(), int(heightMM));
|
||||
QCOMPARE(printer.pageSizeMM(), QSizeF(widthMMf, heightMMf));
|
||||
}
|
||||
|
||||
#endif // QT_NO_PRINTER
|
||||
|
||||
QTEST_MAIN(tst_QPrinter)
|
||||
|
|
|
|||
Loading…
Reference in New Issue