A Dimarts, 8 de novembre de 2011, Michel Ludwig vàreu escriure:
> > On Nov. 8, 2011, 5:10 p.m., Albert Astals Cid wrote:
> > > I'm not convinced by this patch, as far as i understood what you
> > > wanted to do is get the generators assume everything was on
> > > Rotate0, which is what it actually is, so i don't think the
> > > generators should be querying the page rotation at all. That seems
> > > wrong.
> > > 
> > > Personally i think that what is wrong is
> > > 
> > >   const Okular::SourceReference * ref =
> > >   d->document->dynamicSourceReference( pageItem->  pageNumber(),
> > >   nX * pageItem->page()->width(), nY * pageItem->page()->height()
> > >   );> > 
> > > That is using width and height indiscriminately when it is there at
> > > the UI level where i think makes more sense to compensate for the
> > > rotation of the page.
> > > 
> > > I'd certainly prefer a patch that does not touch generator
> > > implementation at all.
> > > 
> > > If you need help i might give it a go if you give me some sample
> > > files to test.
> There is one problem with the Okular::Page, namely in the
> 'PagePrivate::rotateAt' method, which swaps the width and height of the
> page depending on the rotation (line 339). In order to compensate for that,
> I had to ask for the rotation of the page in the generators to compute the
> correct viewport location relative to Rotation0. Of course, if one doesn't
> do that, one gets the wrong location.
> 
> I've attached a example LaTeX file and its corresponding synctex file. I
> guess the most convenient way would simply be to open the LaTeX file in the
> live preview branch of Kile:
> 
> http://sourceforge.net/apps/mediawiki/kile/index.php?title=Live_Preview
> 
> The rotation can be changed in the View / Document Viewer menu.
> 
> And yes, I would be happy if you could have a look at it :)

Ok, here comes my suggestion. It is basically veeeeery similar to your patch 
but touches [almost] no generator code.

What do you think?

Albert

P.S: It seems there is a kind of "refresh" problem after the rotation is 
switched but that should be hopefully easy to fix for you?
diff --git a/core/document.cpp b/core/document.cpp
index b3ddb46..420c4e5 100644
--- a/core/document.cpp
+++ b/core/document.cpp
@@ -760,6 +760,44 @@ DocumentViewport DocumentPrivate::nextDocumentViewport() const
         DocumentViewport vp( m_generator->metaData( "NamedViewport", m_nextDocumentDestination ).toString() );
         if ( vp.isValid() )
         {
+            // NamedViewport are given unrotated, thus modify them if needed 
+            if (vp.rePos.enabled)
+            {
+                const double oldX = vp.rePos.normalizedX;
+                const double oldY = vp.rePos.normalizedY;
+                switch( m_rotation )
+                {
+                    case Okular::Rotation0:
+                            // nothing to be done
+                    break;
+                    case Okular::Rotation90:
+                        vp.rePos.normalizedX = 1.0 - oldY;
+                        vp.rePos.normalizedY = oldX;
+                    break;
+                    case Okular::Rotation180:
+                        vp.rePos.normalizedX = 1.0 - oldX;
+                        vp.rePos.normalizedY = 1.0 - oldY;
+                    break;
+                    case Okular::Rotation270:
+                        vp.rePos.normalizedX = oldY;
+                        vp.rePos.normalizedY = 1.0 - oldX;
+                    break;
+                }
+            }
+            if (vp.autoFit.enabled)
+            {
+                switch( m_rotation )
+                {
+                    case Okular::Rotation0:
+                    case Okular::Rotation180:
+                            // nothing to be done
+                    break;
+                    case Okular::Rotation90:
+                    case Okular::Rotation270:
+                        qSwap(vp.autoFit.width, vp.autoFit.height);
+                    break;
+                }
+            }
             ret = vp;
         }
     }
diff --git a/core/page.cpp b/core/page.cpp
index bb3dbbd..9bbaa5a 100644
--- a/core/page.cpp
+++ b/core/page.cpp
@@ -175,6 +175,21 @@ double Page::ratio() const
     return d->m_height / d->m_width;
 }
 
+double Page::unrotatedWidth() const
+{
+    return ( rotation() == Okular::Rotation0 || rotation() == Okular::Rotation180 ) ? width() : height();
+}
+
+double Page::unrotatedHeight() const
+{
+    return ( rotation() == Okular::Rotation0 || rotation() == Okular::Rotation180 ) ? height() : width();
+}
+
+double Page::unrotatedRatio() const
+{
+	return unrotatedHeight() / unrotatedWidth();
+}
+
 NormalizedRect Page::boundingBox() const
 {
     return d->m_boundingBox;
@@ -946,3 +961,5 @@ const QPixmap * Page::_o_nearestPixmap( int pixID, int w, int h ) const
 
     return pixmap;
 }
+
+/* kate: replace-tabs on; indent-width 4; */
diff --git a/core/page.h b/core/page.h
index 46fba72..e445dcd 100644
--- a/core/page.h
+++ b/core/page.h
@@ -94,20 +94,44 @@ class OKULAR_EXPORT Page
 
         /**
          * Returns the width of the page.
+         * Changes depending of the user on screen rotation
          */
         double width() const;
 
         /**
          * Returns the height of the page.
+         * Changes depending of the user on screen rotation
          */
         double height() const;
 
         /**
          * Returns the ration (height / width) of the page.
+         * Changes depending of the user on screen rotation
          */
         double ratio() const;
 
         /**
+         * Returns the real width of the page.
+         * Does not take into account user on screen rotation
+         * @since 0.14 (KDE 4.8)
+         */
+        double unrotatedWidth() const;
+
+        /**
+         * Returns the real height of the page.
+         * Does not take into account user on screen rotation
+         * @since 0.14 (KDE 4.8)
+         */
+        double unrotatedHeight() const;
+
+        /**
+         * Returns the real ration (height / width) of the page.
+         * Does not take into account user on screen rotation
+         * @since 0.14 (KDE 4.8)
+         */
+        double unrotatedRatio() const;
+
+        /**
          * Returns the bounding box of the page content in normalized [0,1] coordinates,
          * in terms of the upright orientation (Rotation0).
          * If it has not been computed yet, returns the full page (i.e., (0, 0, 1, 1)).
@@ -375,3 +399,5 @@ class OKULAR_EXPORT Page
 }
 
 #endif
+
+/* kate: replace-tabs on; indent-width 4; */
diff --git a/generators/dvi/generator_dvi.cpp b/generators/dvi/generator_dvi.cpp
index 2bc8641..c9cd63f3 100644
--- a/generators/dvi/generator_dvi.cpp
+++ b/generators/dvi/generator_dvi.cpp
@@ -145,7 +145,7 @@ bool DviGenerator::doCloseDocument()
 void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp,
                                            const Anchor &anch, const Okular::Page *page ) const
 {
-    fillViewportFromAnchor( vp, anch, page->width(), page->height() );
+    fillViewportFromAnchor( vp, anch, page->unrotatedWidth(), page->unrotatedHeight() );
 }
 
 void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp,
diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp
index d88da80..633e427 100644
--- a/generators/poppler/generator_pdf.cpp
+++ b/generators/poppler/generator_pdf.cpp
@@ -1581,8 +1581,8 @@ void PDFGenerator::fillViewportFromSourceReference( Okular::DocumentViewport & v
             // TeX small points ...
             double px = (synctex_node_visible_h( node ) * dpiX) / 72.27;
             double py = (synctex_node_visible_v( node ) * dpiY) / 72.27;
-            viewport.rePos.normalizedX = px / document()->page(viewport.pageNumber)->width();
-            viewport.rePos.normalizedY = ( py + 0.5 ) / document()->page(viewport.pageNumber)->height();
+            viewport.rePos.normalizedX = px / document()->page(viewport.pageNumber)->unrotatedWidth();
+            viewport.rePos.normalizedY = ( py + 0.5 ) / document()->page(viewport.pageNumber)->unrotatedHeight();
             viewport.rePos.enabled = true;
             viewport.rePos.pos = Okular::DocumentViewport::Center;
            
diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp
index ca55e81..af76a05 100644
--- a/ui/pagepainter.cpp
+++ b/ui/pagepainter.cpp
@@ -529,26 +529,17 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula
             QPainter painter(&backImage);
             painter.translate( -limits.left(), -limits.top() );
             painter.setPen( QApplication::palette().color( QPalette::Active, QPalette::Highlight ) );
-            painter.drawLine( 0, viewPortPoint->y * scaledHeight + 1, scaledWidth - 1, viewPortPoint->y * scaledHeight + 1 );
-// ROTATION CURRENTLY NOT IMPLEMENTED
-/*
-            if( page->rotation() == Okular::Rotation0)
+            switch (page->rotation())
             {
-
-            }
-            else if(page->rotation() == Okular::Rotation270)
-            {
-                painter.drawLine( viewPortPoint->y * scaledHeight + 1, 0, viewPortPoint->y * scaledHeight + 1, scaledWidth - 1);
-            }
-            else if(page->rotation() == Okular::Rotation180)
-            {
-                painter.drawLine( 0, (1.0 - viewPortPoint->y) * scaledHeight - 1, scaledWidth - 1, (1.0 - viewPortPoint->y) * scaledHeight - 1 );
-            }
-            else if(page->rotation() == Okular::Rotation90) // not right, rotation clock-wise
-            {
-                painter.drawLine( scaledWidth - (viewPortPoint->y * scaledHeight + 1), 0, scaledWidth - (viewPortPoint->y * scaledHeight + 1), scaledWidth - 1);
+                case Okular::Rotation0:
+                case Okular::Rotation180:
+                    painter.drawLine( 0, viewPortPoint->y * scaledHeight + 1, scaledWidth - 1, viewPortPoint->y * scaledHeight + 1 );
+                break;
+                case Okular::Rotation90:
+                case Okular::Rotation270:
+                    painter.drawLine( viewPortPoint->x * scaledWidth + 1, 0, viewPortPoint->x * scaledWidth + 1, scaledWidth - 1);
+                break;
             }
-*/
         }
 
         // 4B.5. create the back pixmap converting from the local image
diff --git a/ui/pageview.cpp b/ui/pageview.cpp
index 0c0ff98..403aa30 100644
--- a/ui/pageview.cpp
+++ b/ui/pageview.cpp
@@ -2176,7 +2176,32 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
                     }
                     else
                     {
-                        const Okular::SourceReference * ref = d->document->dynamicSourceReference( pageItem->  pageNumber(), nX * pageItem->page()->width(), nY * pageItem->page()->height() );
+                        // Take page rotation into account since dynamicSourceReference knows nothing about rotations
+                        const double absX = nX * pageItem->page()->width();
+                        const double absY = nY * pageItem->page()->height();
+                        double absXRot0 = absX;
+                        double absYRot0 = absY;
+                        const Okular::Page* page = d->document->page( pageItem->pageNumber() );
+                        switch( page->rotation() )
+                        {
+                            case Okular::Rotation0:
+                            // nothing to be done
+                            break;
+                            case Okular::Rotation90:
+                                absXRot0 = absY;
+                                absYRot0 = page->width() - absX;
+                            break;
+                            case Okular::Rotation180:
+                                absXRot0 = page->width() - absX;
+                                absYRot0 = page->height() - absY;
+                            break;
+                            case Okular::Rotation270:
+                                absXRot0 = page->height() - absY;
+                                absYRot0 = absX;
+                            break;
+                        }
+
+                        const Okular::SourceReference * ref = d->document->dynamicSourceReference( pageItem->pageNumber(), absXRot0, absYRot0 );
                         if ( ref )
                         {
                             d->document->processSourceReference( ref );
_______________________________________________
Okular-devel mailing list
Okular-devel@kde.org
https://mail.kde.org/mailman/listinfo/okular-devel

Reply via email to