summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qpdf.cpp
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2013-12-29 20:19:48 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-17 13:45:49 +0100
commit0c04b31d2715f68aa883107b4aa593fd95aefdfe (patch)
treeb882b4835f0acd3b188e473c99170ac12951eacc /src/gui/painting/qpdf.cpp
parent4ab55a01e96b6ac398d3a9afa2c93032e305f30b (diff)
QPdfPaintEngine - Use QPageLayout and QPageSize
Switch internals of QPdfPageEngine and derived classes to use QPageLayout and QPageSize to make handling of page layout and size more consistent by removing multiple implementations. In particular remove all use of the QPdf namespace version of page size. Change-Id: Ie820340015e8812c8162bd1a257dd0f51f4f0b85 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/gui/painting/qpdf.cpp')
-rw-r--r--src/gui/painting/qpdf.cpp104
1 files changed, 53 insertions, 51 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index 147fa3f561..56cfc0f707 100644
--- a/src/gui/painting/qpdf.cpp
+++ b/src/gui/painting/qpdf.cpp
@@ -1425,19 +1425,60 @@ QPaintEngine::Type QPdfEngine::type() const
return QPaintEngine::Pdf;
}
+void QPdfEngine::setResolution(int resolution)
+{
+ Q_D(QPdfEngine);
+ d->resolution = resolution;
+}
+
+int QPdfEngine::resolution() const
+{
+ Q_D(const QPdfEngine);
+ return d->resolution;
+}
+
+void QPdfEngine::setPageLayout(const QPageLayout &pageLayout)
+{
+ Q_D(QPdfEngine);
+ d->m_pageLayout = pageLayout;
+}
+void QPdfEngine::setPageSize(const QPageSize &pageSize)
+{
+ Q_D(QPdfEngine);
+ d->m_pageLayout.setPageSize(pageSize);
+}
+
+void QPdfEngine::setPageOrientation(QPageLayout::Orientation orientation)
+{
+ Q_D(QPdfEngine);
+ d->m_pageLayout.setOrientation(orientation);
+}
+
+void QPdfEngine::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)
+{
+ Q_D(QPdfEngine);
+ d->m_pageLayout.setUnits(units);
+ d->m_pageLayout.setMargins(margins);
+}
+QPageLayout QPdfEngine::pageLayout() const
+{
+ Q_D(const QPdfEngine);
+ return d->m_pageLayout;
+}
+
+// Metrics are in Device Pixels
int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const
{
Q_D(const QPdfEngine);
int val;
- QRect r = d->pageRect();
switch (metricType) {
case QPaintDevice::PdmWidth:
- val = r.width();
+ val = d->m_pageLayout.paintRectPixels(d->resolution).width();
break;
case QPaintDevice::PdmHeight:
- val = r.height();
+ val = d->m_pageLayout.paintRectPixels(d->resolution).height();
break;
case QPaintDevice::PdmDpiX:
case QPaintDevice::PdmDpiY:
@@ -1448,10 +1489,10 @@ int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const
val = 1200;
break;
case QPaintDevice::PdmWidthMM:
- val = qRound(r.width()*25.4/d->resolution);
+ val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).width());
break;
case QPaintDevice::PdmHeightMM:
- val = qRound(r.height()*25.4/d->resolution);
+ val = qRound(d->m_pageLayout.paintRect(QPageLayout::Millimeter).height());
break;
case QPaintDevice::PdmNumColors:
val = INT_MAX;
@@ -1469,21 +1510,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),
outDevice(0), ownsDevice(false),
- fullPage(false), embedFonts(true),
- landscape(false),
+ embedFonts(true),
grayscale(false),
- paperSize(pageSizeToPostScriptPoints(QSizeF(210, 297))), // A4
- leftMargin(10), topMargin(10), rightMargin(10), bottomMargin(10) // ~3.5 mm
+ m_pageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(10, 10, 10, 10))
{
resolution = 1200;
currentObject = 1;
@@ -1495,11 +1527,6 @@ QPdfEnginePrivate::QPdfEnginePrivate()
stream = new QDataStream;
}
-void QPdfEnginePrivate::setPaperSize(const QSizeF &pageSizeMM)
-{
- paperSize = pageSizeToPostScriptPoints(pageSizeMM);
-}
-
bool QPdfEngine::begin(QPaintDevice *pdev)
{
Q_D(QPdfEngine);
@@ -1581,31 +1608,6 @@ QPdfEnginePrivate::~QPdfEnginePrivate()
delete stream;
}
-QRect QPdfEnginePrivate::paperRect() const
-{
- int w = qRound(paperSize.width()*resolution/72.);
- int h = qRound(paperSize.height()*resolution/72.);
-
- if (!landscape)
- return QRect(0, 0, w, h);
- else
- return QRect(0, 0, h, w);
-}
-
-QRect QPdfEnginePrivate::pageRect() const
-{
- QRect r = paperRect();
-
- if(!fullPage)
- r.adjust(qRound(leftMargin*(resolution/72.)),
- qRound(topMargin*(resolution/72.)),
- -qRound(rightMargin*(resolution/72.)),
- -qRound(bottomMargin*(resolution/72.)));
-
- return r;
-}
-
-
void QPdfEnginePrivate::writeHeader()
{
addXrefEntry(0,false);
@@ -2615,9 +2617,9 @@ void QPdfEnginePrivate::drawTextItem(const QPointF &p, const QTextItemInt &ti)
QTransform QPdfEnginePrivate::pageMatrix() const
{
qreal scale = 72./resolution;
- QTransform tmp(scale, 0.0, 0.0, -scale, 0.0, height());
- if (!fullPage) {
- QRect r = pageRect();
+ QTransform tmp(scale, 0.0, 0.0, -scale, 0.0, m_pageLayout.fullRectPoints().height());
+ if (m_pageLayout.mode() != QPageLayout::FullPageMode) {
+ QRect r = m_pageLayout.paintRectPixels(resolution);
tmp.translate(r.left(), r.top());
}
return tmp;
@@ -2626,12 +2628,12 @@ QTransform QPdfEnginePrivate::pageMatrix() const
void QPdfEnginePrivate::newPage()
{
if (currentPage && currentPage->pageSize.isEmpty())
- currentPage->pageSize = QSize(width(), height());
+ currentPage->pageSize = m_pageLayout.fullRectPoints().size();
writePage();
delete currentPage;
currentPage = new QPdfPage;
- currentPage->pageSize = QSize(width(), height());
+ currentPage->pageSize = m_pageLayout.fullRectPoints().size();
stroker.stream = currentPage;
pages.append(requestObject());