diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2013-07-09 14:01:02 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-10 13:05:27 +0200 |
commit | 3dde073269b059aa238f3cd104a10d2fdb90c350 (patch) | |
tree | 4d20ada71d827f2c3f4917e6fd8b618350285dbb /src/gui | |
parent | aae0a2144d2ad62f7bdf83e5c3161e66d9a7016d (diff) |
QPdfWriter: Fix setting of paper size.
Introduce setter for converting mm to Postscript points.
Task-number: QTBUG-31443
Change-Id: I032118322657ae2a8b3b457010218d6ea3f3e720
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qpdf.cpp | 12 | ||||
-rw-r--r-- | src/gui/painting/qpdf_p.h | 1 | ||||
-rw-r--r-- | src/gui/painting/qpdfwriter.cpp | 4 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 1ca54f0432..9105e8b396 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1469,7 +1469,12 @@ int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const return val; } +static inline QSizeF pageSizeToPostScriptPoints(const QSizeF &pageSizeMM) +{ #define Q_MM(n) int((n * 720 + 127) / 254) + return QSizeF(Q_MM(pageSizeMM.width()), Q_MM(pageSizeMM.height())); +#undef Q_MM +} QPdfEnginePrivate::QPdfEnginePrivate() : clipEnabled(false), allClipped(false), hasPen(true), hasBrush(false), simplePen(false), @@ -1477,7 +1482,7 @@ QPdfEnginePrivate::QPdfEnginePrivate() fullPage(false), embedFonts(true), landscape(false), grayscale(false), - paperSize(Q_MM(210), Q_MM(297)), // A4 + paperSize(pageSizeToPostScriptPoints(QSizeF(210, 297))), // A4 leftMargin(10), topMargin(10), rightMargin(10), bottomMargin(10) // ~3.5 mm { resolution = 1200; @@ -1491,6 +1496,11 @@ QPdfEnginePrivate::QPdfEnginePrivate() stream = new QDataStream; } +void QPdfEnginePrivate::setPaperSize(const QSizeF &pageSizeMM) +{ + paperSize = pageSizeToPostScriptPoints(pageSizeMM); +} + bool QPdfEngine::begin(QPaintDevice *pdev) { Q_D(QPdfEngine); diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h index 560621775b..54530d0f78 100644 --- a/src/gui/painting/qpdf_p.h +++ b/src/gui/painting/qpdf_p.h @@ -226,6 +226,7 @@ public: QRect paperRect() const; QRect pageRect() const; + void setPaperSize(const QSizeF &pageSizeMM); int width() const { QRect r = paperRect(); diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp index 136654cb5d..a783aad66a 100644 --- a/src/gui/painting/qpdfwriter.cpp +++ b/src/gui/painting/qpdfwriter.cpp @@ -166,7 +166,7 @@ void QPdfWriter::setPageSize(PageSize size) Q_D(const QPdfWriter); QPagedPaintDevice::setPageSize(size); - d->engine->d_func()->paperSize = pageSizeMM() * 25.4/72.; + d->engine->d_func()->setPaperSize(pageSizeMM()); } /*! @@ -177,7 +177,7 @@ void QPdfWriter::setPageSizeMM(const QSizeF &size) Q_D(const QPdfWriter); QPagedPaintDevice::setPageSizeMM(size); - d->engine->d_func()->paperSize = pageSizeMM() * 25.4/72.; + d->engine->d_func()->setPaperSize(pageSizeMM()); } /*! |