From 3396ba5612c1047d1b21a90c4996dff848c00114 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 13 Sep 2013 23:20:38 +0200 Subject: Match up the specified paper size to an existing one if possible When EnumForms was used then the dmPaperSize was not always correct for the custom paper sizes available on some printers. By using DeviceCapabilities we can be sure that the information is correct in this respect. This also fixes respecting of the custom paper size if one is given and there is no corresponding existing paper size for it. Task-number: QTBUG-34276 Change-Id: I9924d5be8527027fc434261e37f6c7aae66210c3 Reviewed-by: Friedemann Kleint --- .../printsupport/kernel/qprinter/tst_qprinter.cpp | 79 +++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index 7251cca528..644cd33e5c 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -113,6 +113,8 @@ private slots: void testCustomPageSizes(); void customPaperSizeAndMargins_data(); void customPaperSizeAndMargins(); + void customPaperNameSettingBySize(); + void customPaperNameSettingByName(); #if !defined(QT_NO_COMPLETER) && !defined(QT_NO_FILEDIALOG) void printDialogCompleter(); #endif @@ -967,6 +969,13 @@ void tst_QPrinter::errorReporting() painter.end(); } +static QByteArray msgSizeMismatch(const QSizeF &actual, const QSizeF &expected) +{ + QString result; + QDebug(&result) << "Paper size mismatch" << actual << "!=" << expected; + return result.toLocal8Bit(); +} + void tst_QPrinter::testCustomPageSizes() { QPrinter p; @@ -975,12 +984,16 @@ void tst_QPrinter::testCustomPageSizes() p.setPaperSize(customSize, QPrinter::Inch); QSizeF paperSize = p.paperSize(QPrinter::Inch); - QCOMPARE(paperSize, customSize); + // Due to the different calculations, the sizes may be off by a fraction so we have to check it manually + // instead of relying on QSizeF comparison + QVERIFY2(sqrt(pow(paperSize.width() - customSize.width(), 2.0) + pow(paperSize.height() - customSize.height(), 2.0)) < 0.01, + msgSizeMismatch(paperSize, customSize)); QPrinter p2(QPrinter::HighResolution); p2.setPaperSize(customSize, QPrinter::Inch); paperSize = p.paperSize(QPrinter::Inch); - QCOMPARE(paperSize, customSize); + QVERIFY2(sqrt(pow(paperSize.width() - customSize.width(), 2.0) + pow(paperSize.height() - customSize.height(), 2.0)) < 0.01, + msgSizeMismatch(paperSize, customSize)); } void tst_QPrinter::customPaperSizeAndMargins_data() @@ -1193,6 +1206,68 @@ void tst_QPrinter::testPageMetrics() QCOMPARE(printer.pageSizeMM(), QSizeF(widthMMf, heightMMf)); } +void tst_QPrinter::customPaperNameSettingBySize() +{ +#ifndef Q_OS_WIN + QSKIP("Currently this triggers a problem on non Windows platforms, this will be fixed separately - QTBUG-34521"); +#endif + QPrinter printer(QPrinter::HighResolution); + QPrinterInfo info(printer); + QList > sizes = info.supportedSizesWithNames(); + if (sizes.size() == 0) + QSKIP("No printers installed on this machine"); + for (int i=0; i > sizes = info.supportedSizesWithNames(); + if (sizes.size() == 0) + QSKIP("No printers installed on this machine"); + for (int i=0; i