summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-12-23 07:34:16 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2020-01-30 15:50:44 +0100
commit4f5f0705bc161ff95899fdb2c5fcdb4581bf15bb (patch)
tree39e1f225a24d893176b9d22bc46bddacaadfca38 /src/plugins
parentd1749c375ea924390d19225b40ef2631b524849b (diff)
QPdfDocument and QPdfIOHandler: add scale and clip features
Like some other image plugins, the PDF plugin now supports ImageOption::ScaledClipRect and ScaledSize. Change-Id: Ie7278752e49c885cc4580f30af1ec5e6310f8334 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/imageformats/pdf/qpdfiohandler.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/plugins/imageformats/pdf/qpdfiohandler.cpp b/src/plugins/imageformats/pdf/qpdfiohandler.cpp
index 9df85cf08..739e8b34c 100644
--- a/src/plugins/imageformats/pdf/qpdfiohandler.cpp
+++ b/src/plugins/imageformats/pdf/qpdfiohandler.cpp
@@ -98,7 +98,8 @@ bool QPdfIOHandler::read(QImage *image)
if (m_page < 0)
m_page = 0;
const bool xform = (m_clipRect.isValid() || m_scaledSize.isValid() || m_scaledClipRect.isValid());
- QSize finalSize = m_doc.pageSize(m_page).toSize();
+ QSize pageSize = m_doc.pageSize(m_page).toSize();
+ QSize finalSize = pageSize;
QRectF bounds;
if (xform && !finalSize.isEmpty()) {
bounds = QRectF(QPointF(0,0), QSizeF(finalSize));
@@ -112,6 +113,7 @@ bool QPdfIOHandler::read(QImage *image)
sc = QSizeF(qreal(m_scaledSize.width()) / finalSize.width(),
qreal(m_scaledSize.height()) / finalSize.height());
finalSize = m_scaledSize;
+ pageSize = m_scaledSize;
}
if (m_scaledClipRect.isValid()) {
tr2 = -m_scaledClipRect.topLeft();
@@ -133,9 +135,13 @@ bool QPdfIOHandler::read(QImage *image)
}
}
if (!finalSize.isEmpty()) {
+ QPdfDocumentRenderOptions options;
+ if (m_scaledClipRect.isValid())
+ options.setScaledClipRect(m_scaledClipRect);
+ options.setScaledSize(pageSize);
image->fill(m_backColor.rgba());
QPainter p(image);
- QImage pageImage = m_doc.render(m_page, finalSize);
+ QImage pageImage = m_doc.render(m_page, finalSize, options);
p.drawImage(0, 0, pageImage);
p.end();
}