summaryrefslogtreecommitdiff
path: root/src/pdf
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-02-09 14:33:54 +0100
committerAxel Spoerl <axel.spoerl@qt.io>2023-02-14 16:15:30 +0100
commit21c11e817478f440e32a82f20b964b285339e939 (patch)
tree5e4601489a2384d16358a271799c2e466c5202a2 /src/pdf
parentc008999211d1afa028cc3ab83b9418e4bffa8313 (diff)
downloadqtwebengine-21c11e817478f440e32a82f20b964b285339e939.tar.gz
Define an enum for FPDF rotation int values
FPDF uses int values defined in fpdfview.h:955ff, representing page rotation. Respecting coding style, this patch adds an enum in QPdfDocumentPrivate to introduce meaningful names instead of int values. Pick-to: 6.5 Change-Id: I54cefe336de3670026cfc4d7f4436e5898e43b54 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/qpdfdocument.cpp17
-rw-r--r--src/pdf/qpdfdocument_p.h25
2 files changed, 26 insertions, 16 deletions
diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp
index a3e412c5c..268389f4a 100644
--- a/src/pdf/qpdfdocument.cpp
+++ b/src/pdf/qpdfdocument.cpp
@@ -824,22 +824,6 @@ QImage QPdfDocument::render(int page, QSize imageSize, QPdfDocumentRenderOptions
result.fill(Qt::transparent);
FPDF_BITMAP bitmap = FPDFBitmap_CreateEx(result.width(), result.height(), FPDFBitmap_BGRA, result.bits(), result.bytesPerLine());
- int rotation = 0;
- switch (renderOptions.rotation()) {
- case QPdfDocumentRenderOptions::Rotation::None:
- rotation = 0;
- break;
- case QPdfDocumentRenderOptions::Rotation::Clockwise90:
- rotation = 1;
- break;
- case QPdfDocumentRenderOptions::Rotation::Clockwise180:
- rotation = 2;
- break;
- case QPdfDocumentRenderOptions::Rotation::Clockwise270:
- rotation = 3;
- break;
- }
-
const QPdfDocumentRenderOptions::RenderFlags renderFlags = renderOptions.renderFlags();
int flags = 0;
if (renderFlags & QPdfDocumentRenderOptions::RenderFlag::Annotations)
@@ -885,6 +869,7 @@ QImage QPdfDocument::render(int page, QSize imageSize, QPdfDocumentRenderOptions
qCDebug(qLcDoc) << "page" << page << "region" << renderOptions.scaledClipRect()
<< "size" << imageSize << "took" << timer.elapsed() << "ms";
} else {
+ const auto rotation = QPdfDocumentPrivate::toFPDFRotation(renderOptions.rotation());
FPDF_RenderPageBitmap(bitmap, pdfPage, 0, 0, result.width(), result.height(), rotation, flags);
qCDebug(qLcDoc) << "page" << page << "size" << imageSize << "took" << timer.elapsed() << "ms";
}
diff --git a/src/pdf/qpdfdocument_p.h b/src/pdf/qpdfdocument_p.h
index 973dc1d4a..d52aabe4b 100644
--- a/src/pdf/qpdfdocument_p.h
+++ b/src/pdf/qpdfdocument_p.h
@@ -81,6 +81,31 @@ public:
QPointF getCharPosition(FPDF_TEXTPAGE textPage, double pageHeight, int charIndex);
QRectF getCharBox(FPDF_TEXTPAGE textPage, double pageHeight, int charIndex);
+ // FPDF takes the rotation parameter as an int.
+ // This enum is mapping the int values defined in fpdfview.h:956.
+ // (not using enum class to ensure int convertability)
+ enum QFPDFRotation {
+ Normal = 0,
+ ClockWise90 = 1,
+ ClockWise180 = 2,
+ CounterClockWise90 = 3
+ };
+
+ static constexpr QFPDFRotation toFPDFRotation(QPdfDocumentRenderOptions::Rotation rotation)
+ {
+ switch (rotation) {
+ case QPdfDocumentRenderOptions::Rotation::None:
+ return QFPDFRotation::Normal;
+ case QPdfDocumentRenderOptions::Rotation::Clockwise90:
+ return QFPDFRotation::ClockWise90;
+ case QPdfDocumentRenderOptions::Rotation::Clockwise180:
+ return QFPDFRotation::ClockWise180;
+ case QPdfDocumentRenderOptions::Rotation::Clockwise270:
+ return QFPDFRotation::CounterClockWise90;
+ }
+ Q_UNREACHABLE();
+ }
+
struct TextPosition {
QPointF position;
qreal height = 0;