2014-01-05 17:51:32 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-01-05 17:51:32 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2014-01-05 17:51:32 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-01-05 17:51:32 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-01-05 17:51:32 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QtAlgorithms>
|
2017-03-27 13:48:37 +00:00
|
|
|
#include <QtGui/QAbstractTextDocumentLayout>
|
2014-01-05 17:51:32 +00:00
|
|
|
#include <QtGui/QPageLayout>
|
|
|
|
#include <QtGui/QPdfWriter>
|
2017-03-27 13:48:37 +00:00
|
|
|
#include <QtGui/QTextCursor>
|
|
|
|
#include <QtGui/QTextDocument>
|
2014-01-05 17:51:32 +00:00
|
|
|
|
|
|
|
class tst_QPdfWriter : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void basics();
|
|
|
|
void testPageMetrics_data();
|
|
|
|
void testPageMetrics();
|
2017-03-27 13:48:37 +00:00
|
|
|
void qtbug59443();
|
2014-01-05 17:51:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QPdfWriter::basics()
|
|
|
|
{
|
|
|
|
QTemporaryFile file;
|
2015-09-24 13:56:57 +00:00
|
|
|
QVERIFY2(file.open(), qPrintable(file.errorString()));
|
2014-01-05 17:51:32 +00:00
|
|
|
QPdfWriter writer(file.fileName());
|
|
|
|
|
|
|
|
QCOMPARE(writer.title(), QString());
|
|
|
|
writer.setTitle(QString("Test Title"));
|
|
|
|
QCOMPARE(writer.title(), QString("Test Title"));
|
|
|
|
|
|
|
|
QCOMPARE(writer.creator(), QString());
|
|
|
|
writer.setCreator(QString("Test Creator"));
|
|
|
|
QCOMPARE(writer.creator(), QString("Test Creator"));
|
|
|
|
|
|
|
|
QCOMPARE(writer.resolution(), 1200);
|
|
|
|
writer.setResolution(600);
|
|
|
|
QCOMPARE(writer.resolution(), 600);
|
|
|
|
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(210, 297));
|
2014-01-05 17:51:32 +00:00
|
|
|
|
|
|
|
writer.setPageSize(QPageSize(QPageSize::A5));
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A5);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(148, 210));
|
2014-01-05 17:51:32 +00:00
|
|
|
|
2019-09-05 11:11:54 +00:00
|
|
|
writer.setPageSize(QPageSize(QPageSize::A3));
|
2014-01-05 17:51:32 +00:00
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3);
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(297, 420));
|
2014-01-05 17:51:32 +00:00
|
|
|
|
2019-09-05 11:11:54 +00:00
|
|
|
writer.setPageSize(QPageSize(QSize(210, 297), QPageSize::Millimeter));
|
2014-01-05 17:51:32 +00:00
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(210, 297));
|
2014-01-05 17:51:32 +00:00
|
|
|
|
|
|
|
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait);
|
|
|
|
writer.setPageOrientation(QPageLayout::Landscape);
|
|
|
|
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(210, 297));
|
2014-01-05 17:51:32 +00:00
|
|
|
|
|
|
|
QCOMPARE(writer.pageLayout().margins(), QMarginsF(10, 10, 10, 10));
|
|
|
|
QCOMPARE(writer.pageLayout().units(), QPageLayout::Point);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).left(), 3.53); // mm
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), 3.53);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), 3.53);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), 3.53);
|
2014-01-05 17:51:32 +00:00
|
|
|
writer.setPageMargins(QMarginsF(20, 20, 20, 20), QPageLayout::Millimeter);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(), QMarginsF(20, 20, 20, 20));
|
|
|
|
QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().margins().left(), 20.0);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().right(), 20.0);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().top(), 20.0);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().bottom(), 20.0);
|
2019-09-05 11:11:54 +00:00
|
|
|
const QMarginsF margins = {50, 50, 50, 50};
|
|
|
|
writer.setPageMargins(margins, QPageLayout::Millimeter);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(), margins);
|
2014-01-05 17:51:32 +00:00
|
|
|
QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().margins().left(), 50.0);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().right(), 50.0);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().top(), 50.0);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().bottom(), 50.0);
|
2014-01-05 17:51:32 +00:00
|
|
|
|
|
|
|
QCOMPARE(writer.pageLayout().fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
|
|
|
|
QCOMPARE(writer.pageLayout().paintRect(QPageLayout::Millimeter), QRectF(50, 50, 197, 110));
|
2019-12-13 13:27:11 +00:00
|
|
|
|
|
|
|
QByteArray metadata (
|
|
|
|
"<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>\n"
|
|
|
|
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n"
|
|
|
|
" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\"\n"
|
|
|
|
" <rdf:Description xmlns:dc=\"http://purl.org/dc/elements/1.1/\" rdf:about=\"\">\n"
|
|
|
|
" <dc:title>\n"
|
|
|
|
" <rdf:Alt>\n"
|
|
|
|
" <rdf:li xml:lang=\"x-default\">TITLE</rdf:li>\n"
|
|
|
|
" </rdf:Alt>\n"
|
|
|
|
" </dc:title>\n"
|
|
|
|
" </rdf:Description>\n"
|
|
|
|
" <rdf:Description xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\" rdf:about="" xmp:CreatorTool=\"OUR_OWN_XMP\" xmp:CreateDate=\"2019-12-16T00:00:00+01:00\" xmp:ModifyDate=\"2019-12-16T00:00:00+01:00\"/>\n"
|
|
|
|
" <rdf:Description xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\" rdf:about="" pdf:Producer=\"MetaType Info Producer\"/>\n"
|
|
|
|
" <rdf:Description xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\" rdf:about=\"THI IS ALL ABOUT\" pdfaid:part=\"1\" pdfaid:conformance=\"B\"/>\n"
|
|
|
|
" </rdf:RDF>\n"
|
|
|
|
"</x:xmpmeta>\n"
|
|
|
|
"<?xpacket end='w'?>\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
QCOMPARE(writer.documentXmpMetadata(), QByteArray());
|
|
|
|
writer.setDocumentXmpMetadata(metadata);
|
|
|
|
QCOMPARE(writer.documentXmpMetadata(), metadata);
|
2014-01-05 17:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the old page metrics methods, see also QPrinter tests for the same.
|
|
|
|
void tst_QPdfWriter::testPageMetrics_data()
|
|
|
|
{
|
2019-09-05 11:11:54 +00:00
|
|
|
QTest::addColumn<QPageSize::PageSizeId>("pageSizeId");
|
2014-01-05 17:51:32 +00:00
|
|
|
QTest::addColumn<qreal>("widthMMf");
|
|
|
|
QTest::addColumn<qreal>("heightMMf");
|
|
|
|
QTest::addColumn<bool>("setMargins");
|
|
|
|
QTest::addColumn<qreal>("leftMMf");
|
|
|
|
QTest::addColumn<qreal>("rightMMf");
|
|
|
|
QTest::addColumn<qreal>("topMMf");
|
|
|
|
QTest::addColumn<qreal>("bottomMMf");
|
|
|
|
|
2019-09-05 11:11:54 +00:00
|
|
|
QTest::newRow("A4") << QPageSize::A4 << 210.0 << 297.0 << false
|
|
|
|
<< 3.53 << 3.53 << 3.53 << 3.53;
|
|
|
|
QTest::newRow("A4 Margins") << QPageSize::A4 << 210.0 << 297.0 << true
|
|
|
|
<< 20.0 << 30.0 << 40.0 << 50.0;
|
|
|
|
|
|
|
|
QTest::newRow("Portrait") << QPageSize::Custom << 345.0 << 678.0 << false
|
|
|
|
<< 3.53 << 3.53 << 3.53 << 3.53;
|
|
|
|
QTest::newRow("Portrait Margins") << QPageSize::Custom << 345.0 << 678.0 << true
|
|
|
|
<< 20.0 << 30.0 << 40.0 << 50.0;
|
|
|
|
QTest::newRow("Landscape") << QPageSize::Custom << 678.0 << 345.0 << false
|
|
|
|
<< 3.53 << 3.53 << 3.53 << 3.53;
|
|
|
|
QTest::newRow("Landscape Margins") << QPageSize::Custom << 678.0 << 345.0 << true
|
|
|
|
<< 20.0 << 30.0 << 40.0 << 50.0;
|
2014-01-05 17:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QPdfWriter::testPageMetrics()
|
|
|
|
{
|
2019-09-05 11:11:54 +00:00
|
|
|
QFETCH(QPageSize::PageSizeId, pageSizeId);
|
2014-01-05 17:51:32 +00:00
|
|
|
QFETCH(qreal, widthMMf);
|
|
|
|
QFETCH(qreal, heightMMf);
|
|
|
|
QFETCH(bool, setMargins);
|
|
|
|
QFETCH(qreal, leftMMf);
|
|
|
|
QFETCH(qreal, rightMMf);
|
|
|
|
QFETCH(qreal, topMMf);
|
|
|
|
QFETCH(qreal, bottomMMf);
|
|
|
|
|
|
|
|
QSizeF sizeMMf = QSizeF(widthMMf, heightMMf);
|
|
|
|
|
|
|
|
QTemporaryFile file;
|
2015-09-24 13:56:57 +00:00
|
|
|
QVERIFY2(file.open(), qPrintable(file.errorString()));
|
2014-01-05 17:51:32 +00:00
|
|
|
QPdfWriter writer(file.fileName());
|
|
|
|
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait);
|
|
|
|
|
|
|
|
if (setMargins) {
|
|
|
|
// Setup the given margins
|
Tests: Fix some warnings about deprecated functions not under test
Fix warnings like:
baselineserver/shared/baselineprotocol.cpp:295:72: warning: ‘int QImage::byteCount() const’ is deprecated: Use sizeInBytes [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:1560:17: warning: ‘static QList<QSslCertificate> QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:1560:39: warning: ‘static QList<QSslCertificate> QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:8153:60: warning: ‘T* QWeakPointer<T>::data() const [with T = const QNetworkSession]’ is deprecated: Use toStrongRef() instead, and data() on the returned QSharedPointer [-Wdeprecated-declarations].
...
st_qprinter.cpp:1318:74: warning: ‘QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations]
tst_qprinter.cpp:1362:74: warning: ‘QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations]
tst_largefile.cpp:492:85: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations]
tst_largefile.cpp:498:91: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations]
tst_qabstractitemmodel.cpp:312:25: warning: ‘void QAbstractItemModel::reset()’ is deprecated [-Wdeprecated-declarations]
...
tst_qabstractitemmodel.cpp:1793:28: warning: ‘void QAbstractItemModel::setRoleNames(const QHash<int, QByteArray>&)’ is deprecated [-Wdeprecated-declarations]
...
tst_qcolor.cpp:1425:33: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
tst_qcolor.cpp:1432:31: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
tst_qprinterinfo.cpp:303:61: warning: 'QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const' is deprecated [-Wdeprecated-declarations]
tst_qprinterinfo.cpp:304:65: warning: 'QList<QPair<QString, QSizeF> > QPrinterInfo::supportedSizesWithNames() const' is deprecated [-Wdeprecated-declarations]
tst_qtextdocumentfragment.cpp:947:52: warning: ‘QString QTextCharFormat::anchorName() const’ is deprecated: Use anchorNames() instead [-Wdeprecated-declarations]
tst_qtextlayout.cpp:2261:61: warning: ‘void QTextLayout::setAdditionalFormats(const QList<QTextLayout::FormatRange>&)’ is deprecated: Use setFormats() [-Wdeprecated-declarations]
tst_qtextlayout.cpp:2330:42: warning: ‘int QFontMetrics::width(const QString&, int) const’ is deprecated: Use QFontMetrics::horizontalAdvance [-Wdeprecated-declarations]
tst_qitemselectionmodel.cpp:2214:37: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations]
...
tst_qtextlist.cpp:317:68: warning: 'bool QTextList::isEmpty() const' is deprecated: Use count() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:373:32: warning: ‘void QPainter::setMatrixEnabled(bool)’ is deprecated: Use setWorldMatrixEnabled() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:374:40: warning: ‘bool QPainter::matrixEnabled() const’ is deprecated: Use worldMatrixEnabled() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:702:45: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:1573:29: warning: ‘void QPainter::drawRoundRect(const QRect&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:76:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:81:41: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:105:30: warning: ‘virtual void QPdfWriter::setMargins(const QPagedPaintDevice::Margins&)’ is deprecated: Use setPageMargins(QMarginsF(l, t, r, b), QPageLayout::Millimeter) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:172:37: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:258:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations]
qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp:3980:54: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations]
tst_qlocale.cpp:434:26: warning: 'QString::null' is deprecated: use QString() [-Wdeprecated-declarations]
...
Change-Id: I77c1a934b27119eedeb26a77c913686314a2a5c7
Reviewed-by: David Faure <david.faure@kdab.com>
2019-05-23 11:55:23 +00:00
|
|
|
writer.setPageMargins({leftMMf, topMMf, rightMMf, bottomMMf}, QPageLayout::Millimeter);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().margins().left(), leftMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().right(), rightMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().top(), topMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins().bottom(), bottomMMf);
|
2014-01-05 17:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the given size, in Portrait mode
|
2019-09-05 11:11:54 +00:00
|
|
|
const QPageSize pageSize = pageSizeId == QPageSize::Custom
|
|
|
|
? QPageSize(sizeMMf, QPageSize::Millimeter) : QPageSize(pageSizeId);
|
|
|
|
writer.setPageSize(pageSize);
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(int(writer.pageLayout().pageSize().id()), int(pageSizeId));
|
2019-09-05 11:11:54 +00:00
|
|
|
|
2014-01-05 17:51:32 +00:00
|
|
|
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
|
2014-01-05 17:51:32 +00:00
|
|
|
|
2020-09-03 16:42:30 +00:00
|
|
|
// QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
|
2014-01-05 17:51:32 +00:00
|
|
|
|
|
|
|
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
|
|
|
|
QCOMPARE(writer.widthMM(), qRound(widthMMf - leftMMf - rightMMf));
|
|
|
|
QCOMPARE(writer.heightMM(), qRound(heightMMf - topMMf - bottomMMf));
|
|
|
|
|
|
|
|
// Now switch to Landscape mode, size should be unchanged, but rect and metrics should change
|
|
|
|
writer.setPageOrientation(QPageLayout::Landscape);
|
2019-09-05 11:11:54 +00:00
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(int(writer.pageLayout().pageSize().id()), int(pageSizeId));
|
2014-01-05 17:51:32 +00:00
|
|
|
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
|
2014-01-05 17:51:32 +00:00
|
|
|
|
2020-09-03 16:42:30 +00:00
|
|
|
// QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
|
2014-01-05 17:51:32 +00:00
|
|
|
|
|
|
|
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
|
|
|
|
QCOMPARE(writer.widthMM(), qRound(heightMMf - leftMMf - rightMMf));
|
|
|
|
QCOMPARE(writer.heightMM(), qRound(widthMMf - topMMf - bottomMMf));
|
|
|
|
|
|
|
|
// QPdfWriter::fullRect() always returns set orientation
|
|
|
|
QCOMPARE(writer.pageLayout().fullRect(QPageLayout::Millimeter), QRectF(0, 0, heightMMf, widthMMf));
|
|
|
|
|
|
|
|
// QPdfWriter::paintRect() always returns set orientation
|
|
|
|
QCOMPARE(writer.pageLayout().paintRect(QPageLayout::Millimeter), QRectF(leftMMf, topMMf, heightMMf - leftMMf - rightMMf, widthMMf - topMMf - bottomMMf));
|
|
|
|
|
|
|
|
|
|
|
|
// Now while in Landscape mode, set the size again, results should be the same
|
2019-09-05 11:11:54 +00:00
|
|
|
writer.setPageSize(pageSize);
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(int(writer.pageLayout().pageSize().id()), int(pageSizeId));
|
2014-01-05 17:51:32 +00:00
|
|
|
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape);
|
2020-09-03 16:42:30 +00:00
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
|
|
|
|
QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
|
2014-01-05 17:51:32 +00:00
|
|
|
|
2020-09-03 16:42:30 +00:00
|
|
|
// QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
|
|
|
|
QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
|
2014-01-05 17:51:32 +00:00
|
|
|
|
|
|
|
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
|
|
|
|
QCOMPARE(writer.widthMM(), qRound(heightMMf - leftMMf - rightMMf));
|
|
|
|
QCOMPARE(writer.heightMM(), qRound(widthMMf - topMMf - bottomMMf));
|
|
|
|
|
|
|
|
// QPdfWriter::fullRect() always returns set orientation
|
|
|
|
QCOMPARE(writer.pageLayout().fullRect(QPageLayout::Millimeter), QRectF(0, 0, heightMMf, widthMMf));
|
|
|
|
|
|
|
|
// QPdfWriter::paintRect() always returns set orientation
|
|
|
|
QCOMPARE(writer.pageLayout().paintRect(QPageLayout::Millimeter), QRectF(leftMMf, topMMf, heightMMf - leftMMf - rightMMf, widthMMf - topMMf - bottomMMf));
|
|
|
|
}
|
|
|
|
|
2017-03-27 13:48:37 +00:00
|
|
|
void tst_QPdfWriter::qtbug59443()
|
|
|
|
{
|
|
|
|
// Do not crash or assert
|
|
|
|
QTemporaryFile file;
|
|
|
|
QVERIFY2(file.open(), qPrintable(file.errorString()));
|
|
|
|
QPdfWriter writer(file.fileName());
|
Tests: Fix some warnings about deprecated functions not under test
Fix warnings like:
baselineserver/shared/baselineprotocol.cpp:295:72: warning: ‘int QImage::byteCount() const’ is deprecated: Use sizeInBytes [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:1560:17: warning: ‘static QList<QSslCertificate> QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:1560:39: warning: ‘static QList<QSslCertificate> QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:8153:60: warning: ‘T* QWeakPointer<T>::data() const [with T = const QNetworkSession]’ is deprecated: Use toStrongRef() instead, and data() on the returned QSharedPointer [-Wdeprecated-declarations].
...
st_qprinter.cpp:1318:74: warning: ‘QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations]
tst_qprinter.cpp:1362:74: warning: ‘QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations]
tst_largefile.cpp:492:85: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations]
tst_largefile.cpp:498:91: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations]
tst_qabstractitemmodel.cpp:312:25: warning: ‘void QAbstractItemModel::reset()’ is deprecated [-Wdeprecated-declarations]
...
tst_qabstractitemmodel.cpp:1793:28: warning: ‘void QAbstractItemModel::setRoleNames(const QHash<int, QByteArray>&)’ is deprecated [-Wdeprecated-declarations]
...
tst_qcolor.cpp:1425:33: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
tst_qcolor.cpp:1432:31: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
tst_qprinterinfo.cpp:303:61: warning: 'QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const' is deprecated [-Wdeprecated-declarations]
tst_qprinterinfo.cpp:304:65: warning: 'QList<QPair<QString, QSizeF> > QPrinterInfo::supportedSizesWithNames() const' is deprecated [-Wdeprecated-declarations]
tst_qtextdocumentfragment.cpp:947:52: warning: ‘QString QTextCharFormat::anchorName() const’ is deprecated: Use anchorNames() instead [-Wdeprecated-declarations]
tst_qtextlayout.cpp:2261:61: warning: ‘void QTextLayout::setAdditionalFormats(const QList<QTextLayout::FormatRange>&)’ is deprecated: Use setFormats() [-Wdeprecated-declarations]
tst_qtextlayout.cpp:2330:42: warning: ‘int QFontMetrics::width(const QString&, int) const’ is deprecated: Use QFontMetrics::horizontalAdvance [-Wdeprecated-declarations]
tst_qitemselectionmodel.cpp:2214:37: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations]
...
tst_qtextlist.cpp:317:68: warning: 'bool QTextList::isEmpty() const' is deprecated: Use count() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:373:32: warning: ‘void QPainter::setMatrixEnabled(bool)’ is deprecated: Use setWorldMatrixEnabled() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:374:40: warning: ‘bool QPainter::matrixEnabled() const’ is deprecated: Use worldMatrixEnabled() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:702:45: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:1573:29: warning: ‘void QPainter::drawRoundRect(const QRect&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:76:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:81:41: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:105:30: warning: ‘virtual void QPdfWriter::setMargins(const QPagedPaintDevice::Margins&)’ is deprecated: Use setPageMargins(QMarginsF(l, t, r, b), QPageLayout::Millimeter) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:172:37: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:258:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations]
qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp:3980:54: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations]
tst_qlocale.cpp:434:26: warning: 'QString::null' is deprecated: use QString() [-Wdeprecated-declarations]
...
Change-Id: I77c1a934b27119eedeb26a77c913686314a2a5c7
Reviewed-by: David Faure <david.faure@kdab.com>
2019-05-23 11:55:23 +00:00
|
|
|
writer.setPageSize(QPageSize(QPageSize::A4));
|
2017-03-27 13:48:37 +00:00
|
|
|
QTextDocument doc;
|
|
|
|
doc.documentLayout()->setPaintDevice(&writer);
|
|
|
|
|
|
|
|
doc.setUndoRedoEnabled(false);
|
|
|
|
QTextCursor cursor(&doc);
|
|
|
|
QFont font = doc.defaultFont();
|
|
|
|
font.setFamily("Calibri");
|
|
|
|
font.setPointSize(8);
|
|
|
|
doc.setDefaultFont(font);
|
|
|
|
|
|
|
|
cursor.insertText(QString::fromStdWString(L"기초하며, 베어링제조업체와 타\n"));
|
|
|
|
doc.print(&writer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-05 17:51:32 +00:00
|
|
|
QTEST_MAIN(tst_QPdfWriter)
|
|
|
|
|
|
|
|
#include "tst_qpdfwriter.moc"
|