summaryrefslogtreecommitdiffstats
path: root/src/pdf/qpdfdocument.cpp
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig@kdab.com>2016-08-22 20:09:38 +0200
committerMichal Klocek <michal.klocek@qt.io>2019-11-25 12:01:39 +0100
commit9bfe4bf9802281fabc5b9e607621ea4cb5e9bd39 (patch)
treea82d2b7ab462b424784b58154f340c33acd818ad /src/pdf/qpdfdocument.cpp
parent44abdb16fcff4898dc81ea3ed4b65b92c4f19d7a (diff)
Add support for render rotation and flags
Extend the QPdfDocument::render() method with a parameter of new type QPdfDocumentRenderOptions to specify the rotation and additional render flags. Change-Id: I354acc7fad4d094a96cefcea4dfa3513f4955c47 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/pdf/qpdfdocument.cpp')
-rw-r--r--src/pdf/qpdfdocument.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp
index c737ca036..1dd6f4027 100644
--- a/src/pdf/qpdfdocument.cpp
+++ b/src/pdf/qpdfdocument.cpp
@@ -546,7 +546,17 @@ QSizeF QPdfDocument::pageSize(int page) const
return result;
}
-QImage QPdfDocument::render(int page, const QSizeF &pageSize)
+/*!
+ Renders the \a page into a QImage of size \a imageSize according to the
+ provided \a renderOptions.
+
+ Returns the rendered page or an empty image in case of an error.
+
+ Note: If the \a imageSize does not match the aspect ratio of the page in the
+ PDF document, the page is rendered scaled, so that it covers the
+ complete \a imageSize.
+*/
+QImage QPdfDocument::render(int page, QSize imageSize, QPdfDocumentRenderOptions renderOptions)
{
if (!d->doc)
return QImage();
@@ -557,11 +567,44 @@ QImage QPdfDocument::render(int page, const QSizeF &pageSize)
if (!pdfPage)
return QImage();
- QImage result(pageSize.toSize(), QImage::Format_ARGB32);
+ QImage result(imageSize, QImage::Format_ARGB32);
result.fill(Qt::transparent);
FPDF_BITMAP bitmap = FPDFBitmap_CreateEx(result.width(), result.height(), FPDFBitmap_BGRA, result.bits(), result.bytesPerLine());
- FPDF_RenderPageBitmap(bitmap, pdfPage, 0, 0, result.width(), result.height(), 0, 0);
+ int rotation = 0;
+ switch (renderOptions.rotation()) {
+ case QPdf::Rotate0:
+ rotation = 0;
+ break;
+ case QPdf::Rotate90:
+ rotation = 1;
+ break;
+ case QPdf::Rotate180:
+ rotation = 2;
+ break;
+ case QPdf::Rotate270:
+ rotation = 3;
+ break;
+ }
+
+ const QPdf::RenderFlags renderFlags = renderOptions.renderFlags();
+ int flags = 0;
+ if (renderFlags & QPdf::RenderAnnotations)
+ flags |= FPDF_ANNOT;
+ if (renderFlags & QPdf::RenderOptimizedForLcd)
+ flags |= FPDF_LCD_TEXT;
+ if (renderFlags & QPdf::RenderGrayscale)
+ flags |= FPDF_GRAYSCALE;
+ if (renderFlags & QPdf::RenderForceHalftone)
+ flags |= FPDF_RENDER_FORCEHALFTONE;
+ if (renderFlags & QPdf::RenderTextAliased)
+ flags |= FPDF_RENDER_NO_SMOOTHTEXT;
+ if (renderFlags & QPdf::RenderImageAliased)
+ flags |= FPDF_RENDER_NO_SMOOTHIMAGE;
+ if (renderFlags & QPdf::RenderPathAliased)
+ flags |= FPDF_RENDER_NO_SMOOTHPATH;
+
+ FPDF_RenderPageBitmap(bitmap, pdfPage, 0, 0, result.width(), result.height(), rotation, flags);
FPDFBitmap_Destroy(bitmap);