From 51181bd30be17b7b41540fda9eb56b71512c8ebd Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Thu, 27 Jul 2023 12:46:44 +0200 Subject: [PATCH] Issue #71: Pages are "mirrored" --- Pdf4QtLib/sources/pdfannotation.cpp | 8 ++++---- Pdf4QtLib/sources/pdfdrawspacecontroller.cpp | 7 ++++++- Pdf4QtLib/sources/pdfrenderer.cpp | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Pdf4QtLib/sources/pdfannotation.cpp b/Pdf4QtLib/sources/pdfannotation.cpp index 6dd96ca..b41f4cf 100644 --- a/Pdf4QtLib/sources/pdfannotation.cpp +++ b/Pdf4QtLib/sources/pdfannotation.cpp @@ -1205,10 +1205,10 @@ PDFAnnotationManager::~PDFAnnotationManager() } QTransform PDFAnnotationManager::prepareTransformations(const QTransform& pagePointToDevicePointMatrix, - QPaintDevice* device, - const PDFAnnotation::Flags annotationFlags, - const PDFPage* page, - QRectF& annotationRectangle) const + QPaintDevice* device, + const PDFAnnotation::Flags annotationFlags, + const PDFPage* page, + QRectF& annotationRectangle) const { // "Unrotate" user coordinate space, if NoRotate flag is set QTransform userSpaceToDeviceSpace = pagePointToDevicePointMatrix; diff --git a/Pdf4QtLib/sources/pdfdrawspacecontroller.cpp b/Pdf4QtLib/sources/pdfdrawspacecontroller.cpp index d2dce86..a565a3e 100644 --- a/Pdf4QtLib/sources/pdfdrawspacecontroller.cpp +++ b/Pdf4QtLib/sources/pdfdrawspacecontroller.cpp @@ -709,10 +709,15 @@ QTransform PDFDrawWidgetProxy::createPagePointToDevicePointMatrix(const PDFPage* case PageRotation::Rotate180: { - matrix.translate(0, rectangle.top() + rectangle.bottom()); + matrix.translate(rectangle.left(), rectangle.top() + rectangle.bottom()); matrix.scale(1.0, -1.0); + matrix.translate(rectangle.width(), 0); + matrix.scale(-1.0, 1.0); + matrix.translate(-rectangle.left(), 0); Q_ASSERT(qFuzzyCompare(matrix.map(rectangle.topLeft()).y(), rectangle.bottom())); Q_ASSERT(qFuzzyCompare(matrix.map(rectangle.bottomLeft()).y(), rectangle.top())); + Q_ASSERT(qFuzzyCompare(matrix.map(rectangle.topLeft()).x(), rectangle.right())); + Q_ASSERT(qFuzzyCompare(matrix.map(rectangle.bottomRight()).x(), rectangle.left())); break; } diff --git a/Pdf4QtLib/sources/pdfrenderer.cpp b/Pdf4QtLib/sources/pdfrenderer.cpp index ecef9ad..cf64e44 100644 --- a/Pdf4QtLib/sources/pdfrenderer.cpp +++ b/Pdf4QtLib/sources/pdfrenderer.cpp @@ -52,8 +52,8 @@ PDFRenderer::PDFRenderer(const PDFDocument* document, } QTransform PDFRenderer::createPagePointToDevicePointMatrix(const PDFPage* page, - const QRectF& rectangle, - PageRotation extraRotation) + const QRectF& rectangle, + PageRotation extraRotation) { PageRotation pageRotation = getPageRotationCombined(page->getPageRotation(), extraRotation); QRectF mediaBox = page->getRotatedBox(page->getMediaBox(), pageRotation); @@ -72,6 +72,7 @@ QTransform PDFRenderer::createMediaBoxToDevicePointMatrix(const QRectF& mediaBox { matrix.translate(rectangle.left(), rectangle.bottom()); matrix.scale(rectangle.width() / mediaBox.width(), -rectangle.height() / mediaBox.height()); + matrix.translate(-mediaBox.left(), -mediaBox.top()); break; } @@ -80,6 +81,7 @@ QTransform PDFRenderer::createMediaBoxToDevicePointMatrix(const QRectF& mediaBox matrix.translate(rectangle.left(), rectangle.top()); matrix.rotate(90); matrix.scale(rectangle.width() / mediaBox.width(), -rectangle.height() / mediaBox.height()); + matrix.translate(-mediaBox.left(), -mediaBox.top()); break; } @@ -89,6 +91,7 @@ QTransform PDFRenderer::createMediaBoxToDevicePointMatrix(const QRectF& mediaBox matrix.rotate(-90); matrix.translate(-rectangle.height(), 0); matrix.scale(rectangle.width() / mediaBox.width(), -rectangle.height() / mediaBox.height()); + matrix.translate(-mediaBox.left(), -mediaBox.top()); break; } @@ -96,6 +99,9 @@ QTransform PDFRenderer::createMediaBoxToDevicePointMatrix(const QRectF& mediaBox { matrix.translate(rectangle.left(), rectangle.top()); matrix.scale(rectangle.width() / mediaBox.width(), rectangle.height() / mediaBox.height()); + matrix.translate(mediaBox.width(), 0); + matrix.translate(-mediaBox.left(), -mediaBox.top()); + matrix.scale(-1.0, 1.0); break; } @@ -106,8 +112,6 @@ QTransform PDFRenderer::createMediaBoxToDevicePointMatrix(const QRectF& mediaBox } } - matrix.translate(-mediaBox.left(), -mediaBox.top()); - return matrix; }