[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegraphics/kpdf
From:       Albert Astals Cid <tsdgeos () terra ! es>
Date:       2005-08-28 10:53:53
Message-ID: 1125226433.210872.20005.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 454213 by aacid:

Fordward port fix for bug 110666


 M  +50 -29    core/generator_pdf/generator_pdf.cpp  
 M  +3 -0      core/generator_pdf/generator_pdf.h  
 M  +21 -16    ui/toc.cpp  
 M  +2 -0      ui/toc.h  


--- trunk/KDE/kdegraphics/kpdf/core/generator_pdf/generator_pdf.cpp #454212:454213
@@ -482,13 +482,7 @@
         LinkDest * destination = pdfdoc->findDest( namedDest );
         if ( destination )
         {
-            if ( !destination->isPageRef() )
-                viewport.pageNumber = destination->getPageNum() - 1;
-            else
-            {
-                Ref ref = destination->getPageRef();
-                viewport.pageNumber = pdfdoc->findPage( ref.num, ref.gen ) - 1;
-            }
+            fillViewportFromLink( viewport, destination );
         }
         docLock.unlock();
         delete namedDest;
@@ -783,7 +777,7 @@
 
         // 2. find the page the link refers to
         LinkAction * a = outlineItem->getAction();
-        if ( a && a->getKind() == actionGoTo )
+        if ( a && ( a->getKind() == actionGoTo || a->getKind() == actionGoToR ) )
         {
             // page number is contained/referenced in a LinkGoTo
             LinkGoTo * g = static_cast< LinkGoTo * >( a );
@@ -798,30 +792,14 @@
             }
             else if ( destination->isOk() )
             {
-                // we have valid 'destination' -> get page number
-                int pageNumber = destination->getPageNum() - 1;
-                if ( destination->isPageRef() )
-                {
-                    Ref ref = destination->getPageRef();
-                    pageNumber = pdfdoc->findPage( ref.num, ref.gen ) - 1;
-                }
-                // set page as attribute to node
-                // TODO add other attributes to the viewport (taken from link)
-                item.setAttribute( "Viewport", DocumentViewport( pageNumber \
).toString() ); +                DocumentViewport vp;
+                fillViewportFromLink( vp, destination );
+                item.setAttribute( "Viewport", vp.toString() );
             }
+            if ( a->getKind() == actionGoToR )
+                item.setAttribute( "ExternalFileName", \
g->getFileName()->getCString() );  }
-        else if ( a && a->getKind() == actionGoToR )
-        {
-            LinkGoToR * g = static_cast< LinkGoToR * >( a );
-            LinkDest * destination = g->getDest();
-            if ( !destination && g->getNamedDest() )
-            {
-                item.setAttribute( "ViewportName", g->getNamedDest()->getCString() \
                );
-            }
 
-            item.setAttribute( "ExternalFileName", g->getFileName()->getCString() );
-        }
-
         // 3. recursively descend over children
         outlineItem->open();
         GList * children = outlineItem->getKids();
@@ -830,6 +808,49 @@
     }
 }
 
+void PDFGenerator::fillViewportFromLink( DocumentViewport &viewport, LinkDest \
*destination ) +{
+    if ( !destination->isPageRef() )
+        viewport.pageNumber = destination->getPageNum() - 1;
+    else
+    {
+        Ref ref = destination->getPageRef();
+        viewport.pageNumber = pdfdoc->findPage( ref.num, ref.gen ) - 1;
+    }
+
+    // get destination position
+    // TODO add other attributes to the viewport (taken from link)
+    switch ( destination->getKind() )
+    {
+        case destXYZ:
+            if (destination->getChangeLeft() || destination->getChangeTop())
+            {
+                double CTM[6];
+                Page *page = pdfdoc->getCatalog()->getPage( viewport.pageNumber + 1 \
); +                // TODO remember to change this if we implement DPI and/or \
rotation +                page->getDefaultCTM(CTM, 72.0, 72.0, 0, gTrue);
+
+                int left, top;
+                // this is OutputDev::cvtUserToDev
+                left = (int)(CTM[0] * destination->getLeft() + CTM[2] * \
destination->getTop() + CTM[4] + 0.5); +                top = (int)(CTM[1] * \
destination->getLeft() + CTM[3] * destination->getTop() + CTM[5] + 0.5); +
+                viewport.rePos.normalizedX = (double)left / \
(double)page->getCropWidth(); +                viewport.rePos.normalizedY = \
(double)top / (double)page->getCropHeight(); +                viewport.rePos.enabled \
= true; +                viewport.rePos.pos = DocumentViewport::TopLeft;
+            }
+            /* TODO
+            if ( dest->getChangeZoom() )
+                make zoom change*/
+        break;
+
+        default:
+            // implement the others cases
+        break;
+    }
+}
+
 void PDFGenerator::addTransition( int pageNumber, KPDFPage * page )
 {
     Page *pdfPage = pdfdoc->getCatalog()->getPage( pageNumber + 1 );
--- trunk/KDE/kdegraphics/kpdf/core/generator_pdf/generator_pdf.h #454212:454213
@@ -22,6 +22,7 @@
 
 class Dict;
 class GfxFont;
+class LinkDest;
 class Ref;
 class PDFDoc;
 class GList;
@@ -89,6 +90,8 @@
         void scanFonts(Dict *resDict, KListView *list, Ref **fonts, int &fontsLen, \
                int &fontsSize);
         void scanFont(GfxFont *font, KListView *list, Ref **fonts, int &fontsLen, \
int &fontsSize);  
+        void fillViewportFromLink( DocumentViewport &viewport, LinkDest *destination \
); +
         // private functions for accessing document informations via PDFDoc
         QString getDocumentInfo( const QString & data ) const;
         QString getDocumentDate( const QString & data ) const;
--- trunk/KDE/kdegraphics/kpdf/ui/toc.cpp #454212:454213
@@ -13,7 +13,6 @@
 
 // local includes
 #include "toc.h"
-#include "core/document.h"
 #include "core/link.h"
 #include "core/page.h"
 
@@ -73,7 +72,7 @@
     return TOC_ID;
 }
 
-void TOC::notifySetup( const QVector< KPDFPage * > & pages, bool documentChanged )
+void TOC::notifySetup( const QVector< KPDFPage * > & /*pages*/, bool documentChanged \
)  {
     if ( !documentChanged )
         return;
@@ -130,25 +129,31 @@
     QString externalFileName = e.attribute( "ExternalFileName" );
     if ( !externalFileName.isEmpty() )
     {
-        KPDFLinkGoto link( externalFileName, DocumentViewport() );
+        KPDFLinkGoto link( externalFileName, getViewport( e ) );
         m_document->processLink( &link );
     }
     else
     {
-        if ( e.hasAttribute( "Viewport" ) )
-        {
-            // if the node has a viewport, set it
-            m_document->setViewport( DocumentViewport( e.attribute( "Viewport" ) ), \
                TOC_ID );
-        }
-        else if ( e.hasAttribute( "ViewportName" ) )
-        {
-            // if the node references a viewport, get the reference and set it
-            const QString & page = e.attribute( "ViewportName" );
-            const QString & viewport = m_document->getMetaData( "NamedViewport", \
                page );
-            if ( !viewport.isNull() )
-                m_document->setViewport( DocumentViewport( viewport ), TOC_ID );
-        }
+        m_document->setViewport( getViewport( e ), TOC_ID );
     }
 }
 
+DocumentViewport TOC::getViewport( const QDomElement &e ) const
+{
+    if ( e.hasAttribute( "Viewport" ) )
+    {
+        // if the node has a viewport, set it
+        return DocumentViewport( e.attribute( "Viewport" ) );
+    }
+    else if ( e.hasAttribute( "ViewportName" ) )
+    {
+        // if the node references a viewport, get the reference and set it
+        const QString & page = e.attribute( "ViewportName" );
+        const QString & viewport = m_document->getMetaData( "NamedViewport", page );
+        if ( !viewport.isNull() )
+            return DocumentViewport( viewport );
+    }
+    return DocumentViewport();
+}
+
 #include "toc.moc"
--- trunk/KDE/kdegraphics/kpdf/ui/toc.h #454212:454213
@@ -12,6 +12,7 @@
 
 #include <qdom.h>
 #include <klistview.h>
+#include "core/document.h"
 #include "core/observer.h"
 
 class KPDFDocument;
@@ -34,6 +35,7 @@
 
     private:
         void addChildren( const QDomNode & parentNode, KListViewItem * parentItem = \
0 ); +        DocumentViewport getViewport( const QDomElement &e ) const;
         KPDFDocument *m_document;
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic