qt4: Keep page rotation into account when normalizing annotation coords

If the page is rotated by 90 or 270 degrees, width and height need to be 
swapped ( just like in Page::pageSizeF() ).

Fabio
From 65f1b855e0422358917b6b183afedc0d1f8530ec Mon Sep 17 00:00:00 2001
From: Fabio D'Urso <[email protected]>
Date: Thu, 24 May 2012 23:17:27 +0200
Subject: [PATCH] qt4: Keep page rotation into account when normalizing
 annotation coords

If the page is rotated by 90 or 270 degrees, width and height need to be swapped
---
 qt4/src/poppler-annotation.cc |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/qt4/src/poppler-annotation.cc b/qt4/src/poppler-annotation.cc
index 4d7cd84..7ad328e 100644
--- a/qt4/src/poppler-annotation.cc
+++ b/qt4/src/poppler-annotation.cc
@@ -203,10 +203,22 @@ void AnnotationPrivate::fillMTX(double MTX[6]) const
     // build a normalized transform matrix for this page at 100% scale
     GfxState * gfxState = new GfxState( 72.0, 72.0, pdfPage->getCropBox(), pdfPage->getRotate(), gTrue );
     double * gfxCTM = gfxState->getCTM();
+
+    double w = pdfPage->getCropWidth();
+    double h = pdfPage->getCropHeight();
+
+    // Swap width and height if the page is rotated landscape or seascape
+    if ( pdfPage->getRotate() == 90 || pdfPage->getRotate() == 270 )
+    {
+        double t = w;
+        w = h;
+        h = t;
+    }
+
     for ( int i = 0; i < 6; i+=2 )
     {
-        MTX[i] = gfxCTM[i] / pdfPage->getCropWidth();
-        MTX[i+1] = gfxCTM[i+1] / pdfPage->getCropHeight();
+        MTX[i] = gfxCTM[i] / w;
+        MTX[i+1] = gfxCTM[i+1] / h;
     }
     delete gfxState;
 }
-- 
1.7.6.5

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to