[poppler] 4 commits - qt4/src qt4/tests

Pino Toscano pino at kemper.freedesktop.org
Wed May 13 09:38:45 PDT 2009


 qt4/src/poppler-document.cc |    5 --
 qt4/src/poppler-link.cc     |    9 ++--
 qt4/src/poppler-page.cc     |    6 +-
 qt4/src/poppler-private.cc  |    4 -
 qt4/src/poppler-private.h   |    5 +-
 qt4/tests/CMakeLists.txt    |    1 
 qt4/tests/Makefile.am       |    5 ++
 qt4/tests/check_links.cpp   |   96 ++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 117 insertions(+), 14 deletions(-)

New commits:
commit e237d8b5c2ae8805487a0790d9fb218263686712
Author: Pino Toscano <pino at kde.org>
Date:   Wed May 13 18:37:07 2009 +0200

    [Qt4] we don't need an output device anymore (since long, even) for resolving destinations

diff --git a/qt4/src/poppler-document.cc b/qt4/src/poppler-document.cc
index 8494fb8..877db52 100644
--- a/qt4/src/poppler-document.cc
+++ b/qt4/src/poppler-document.cc
@@ -412,9 +412,6 @@ namespace Poppler {
 
     LinkDestination *Document::linkDestination( const QString &name )
     {
-        if ( m_doc->getOutputDev() == NULL )
-            return NULL;
-
         GooString * namedDest = QStringToGooString( name );
         LinkDestinationData ldd(NULL, namedDest, m_doc, false);
         LinkDestination *ld = new LinkDestination(ldd);
commit 9a2a851da93ef1a0c291fc9523a468e808ffd08e
Author: Pino Toscano <pino at kde.org>
Date:   Wed May 13 18:19:11 2009 +0200

    [Qt4] Do not try to resolve named destinations for GoTo links pointing to external documents.
    
    In such cases, the named destination is a destination in the external document, so we would try to look up a destination which is not in the current document (thus the look up is unuseful).
    It is task of the users of poppler-qt4 detect such situations, and resolve the named when necessary, using Document::linkDestination(QString).

diff --git a/qt4/src/poppler-document.cc b/qt4/src/poppler-document.cc
index 2892df0..8494fb8 100644
--- a/qt4/src/poppler-document.cc
+++ b/qt4/src/poppler-document.cc
@@ -416,7 +416,7 @@ namespace Poppler {
             return NULL;
 
         GooString * namedDest = QStringToGooString( name );
-        LinkDestinationData ldd(NULL, namedDest, m_doc);
+        LinkDestinationData ldd(NULL, namedDest, m_doc, false);
         LinkDestination *ld = new LinkDestination(ldd);
         delete namedDest;
         return ld;
diff --git a/qt4/src/poppler-link.cc b/qt4/src/poppler-link.cc
index 2507871..de06242 100644
--- a/qt4/src/poppler-link.cc
+++ b/qt4/src/poppler-link.cc
@@ -193,7 +193,7 @@ class LinkMoviePrivate : public LinkPrivate
 		bool deleteDest = false;
 		LinkDest *ld = data.ld;
 		
-		if ( data.namedDest && !ld )
+		if ( data.namedDest && !ld && !data.externalDest )
 		{
 			deleteDest = true;
 			ld = data.doc->doc->findDest( data.namedDest );
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 07e7304..9a27538 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -80,8 +80,9 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
     case actionGoTo:
     {
       LinkGoTo * g = (LinkGoTo *) a;
+      const LinkDestinationData ldd( g->getDest(), g->getNamedDest(), parentDoc, false );
       // create link: no ext file, namedDest, object pointer
-      popplerLink = new LinkGoto( linkArea, QString::null, LinkDestination( LinkDestinationData(g->getDest(), g->getNamedDest(), parentDoc ) ) );
+      popplerLink = new LinkGoto( linkArea, QString::null, LinkDestination( ldd ) );
     }
     break;
 
@@ -90,8 +91,9 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
       LinkGoToR * g = (LinkGoToR *) a;
       // copy link file
       const QString fileName = UnicodeParsedString( g->getFileName() );
+      const LinkDestinationData ldd( g->getDest(), g->getNamedDest(), parentDoc, !fileName.isEmpty() );
       // ceate link: fileName, namedDest, object pointer
-      popplerLink = new LinkGoto( linkArea, fileName, LinkDestination( LinkDestinationData(g->getDest(), g->getNamedDest(), parentDoc ) ) );
+      popplerLink = new LinkGoto( linkArea, fileName, LinkDestination( ldd ) );
     }
     break;
 
diff --git a/qt4/src/poppler-private.cc b/qt4/src/poppler-private.cc
index d5a0191..4612fcf 100644
--- a/qt4/src/poppler-private.cc
+++ b/qt4/src/poppler-private.cc
@@ -145,7 +145,7 @@ namespace Poppler {
                 }
                 else if ( destination && destination->isOk() )
                 {
-                    LinkDestinationData ldd(destination, NULL, doc);
+                    LinkDestinationData ldd(destination, NULL, doc, false);
                     e->setAttribute( "Destination", LinkDestination(ldd).toString() );
                 }
                 break;
@@ -169,7 +169,7 @@ namespace Poppler {
                 }
                 else if ( destination && destination->isOk() )
                 {
-                    LinkDestinationData ldd(destination, NULL, doc);
+                    LinkDestinationData ldd(destination, NULL, doc, g->getFileName() != 0);
                     e->setAttribute( "Destination", LinkDestination(ldd).toString() );
                 }
                 e->setAttribute( "ExternalFileName", g->getFileName()->getCString() );
diff --git a/qt4/src/poppler-private.h b/qt4/src/poppler-private.h
index 3173b71..acf3124 100644
--- a/qt4/src/poppler-private.h
+++ b/qt4/src/poppler-private.h
@@ -60,14 +60,15 @@ namespace Poppler {
     class LinkDestinationData
     {
         public:
-            LinkDestinationData( LinkDest *l, GooString *nd, Poppler::DocumentData *pdfdoc )
-             : ld(l), namedDest(nd), doc(pdfdoc)
+            LinkDestinationData( LinkDest *l, GooString *nd, Poppler::DocumentData *pdfdoc, bool external )
+             : ld(l), namedDest(nd), doc(pdfdoc), externalDest(external)
             {
             }
 
             LinkDest *ld;
             GooString *namedDest;
             Poppler::DocumentData *doc;
+            bool externalDest;
     };
 
     class DocumentData {
commit 51f6cc26fc5fdccce1ba4d4816dec374ce85d67a
Author: Pino Toscano <pino at kde.org>
Date:   Wed May 13 17:38:00 2009 +0200

    [Qt4] start a (basic) unit test for links & destinations

diff --git a/qt4/tests/CMakeLists.txt b/qt4/tests/CMakeLists.txt
index 3faa28d..892ec66 100644
--- a/qt4/tests/CMakeLists.txt
+++ b/qt4/tests/CMakeLists.txt
@@ -45,6 +45,7 @@ qt4_add_simpletest(stress-poppler-dir stress-poppler-dir.cpp)
 qt4_add_qtest(check_attachments check_attachments.cpp)
 qt4_add_qtest(check_dateConversion check_dateConversion.cpp)
 qt4_add_qtest(check_fonts check_fonts.cpp)
+qt4_add_qtest(check_links check_links.cpp)
 qt4_add_qtest(check_metadata check_metadata.cpp)
 qt4_add_qtest(check_optcontent check_optcontent.cpp)
 qt4_add_qtest(check_pagelayout check_pagelayout.cpp)
diff --git a/qt4/tests/Makefile.am b/qt4/tests/Makefile.am
index 99c35ef..ac8213c 100644
--- a/qt4/tests/Makefile.am
+++ b/qt4/tests/Makefile.am
@@ -64,6 +64,7 @@ TESTS = \
 	check_actualtext	\
 	check_dateConversion 	\
 	check_fonts		\
+	check_links		\
 	check_metadata         	\
 	check_optcontent	\
 	check_permissions      	\
@@ -90,6 +91,10 @@ check_fonts_SOURCES = check_fonts.cpp
 check_fonts.$(OBJEXT): check_fonts.moc
 check_fonts_LDADD = $(LDADDS) $(POPPLER_QT4_TEST_LIBS)
 
+check_links_SOURCES = check_links.cpp
+check_links.$(OBJEXT): check_links.moc
+check_links_LDADD = $(LDADDS) $(POPPLER_QT4_TEST_LIBS)
+
 check_metadata_SOURCES = check_metadata.cpp
 check_metadata.$(OBJEXT): check_metadata.moc
 check_metadata_LDADD = $(LDADDS) $(POPPLER_QT4_TEST_LIBS)
diff --git a/qt4/tests/check_links.cpp b/qt4/tests/check_links.cpp
new file mode 100644
index 0000000..2f69a82
--- /dev/null
+++ b/qt4/tests/check_links.cpp
@@ -0,0 +1,96 @@
+#include <QtTest/QtTest>
+
+#include <poppler-qt4.h>
+
+#include <memory>
+
+class TestLinks : public QObject
+{
+    Q_OBJECT
+private slots:
+    void checkDocumentWithNoDests();
+    void checkDests_xr01();
+    void checkDests_xr02();
+};
+
+bool isDestinationValid_pageNumber( const Poppler::LinkDestination *dest, const Poppler::Document *doc )
+{
+    return dest->pageNumber() > 0 && dest->pageNumber() <= doc->numPages();
+}
+
+bool isDestinationValid_name( const Poppler::LinkDestination *dest )
+{
+    return !dest->destinationName().isEmpty();
+}
+
+
+void TestLinks::checkDocumentWithNoDests()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load("../../../test/unittestcases/WithAttachments.pdf");
+    QVERIFY( doc );
+
+    std::auto_ptr< Poppler::LinkDestination > dest;
+    dest.reset( doc->linkDestination("no.dests.in.this.document") );
+    QVERIFY( !isDestinationValid_pageNumber( dest.get(), doc ) );
+    QVERIFY( isDestinationValid_name( dest.get() ) );
+
+    delete doc;
+}
+
+void TestLinks::checkDests_xr01()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load("../../../test/unittestcases/xr01.pdf");
+    QVERIFY( doc );
+
+    Poppler::Page *page = doc->page(0);
+    QVERIFY( page );
+
+    QList< Poppler::Link* > links = page->links();
+    QCOMPARE( links.count(), 2 );
+
+    {
+    QCOMPARE( links.at(0)->linkType(), Poppler::Link::Goto );
+    Poppler::LinkGoto *link = static_cast< Poppler::LinkGoto * >( links.at(0) );
+    const Poppler::LinkDestination dest = link->destination();
+    QVERIFY( !isDestinationValid_pageNumber( &dest, doc ) );
+    QVERIFY( isDestinationValid_name( &dest ) );
+    QCOMPARE( dest.destinationName(), QString::fromLatin1("section.1") );
+    }
+
+    {
+    QCOMPARE( links.at(1)->linkType(), Poppler::Link::Goto );
+    Poppler::LinkGoto *link = static_cast< Poppler::LinkGoto * >( links.at(1) );
+    const Poppler::LinkDestination dest = link->destination();
+    QVERIFY( !isDestinationValid_pageNumber( &dest, doc ) );
+    QVERIFY( isDestinationValid_name( &dest ) );
+    QCOMPARE( dest.destinationName(), QString::fromLatin1("section.2") );
+    }
+
+    delete doc;
+}
+
+void TestLinks::checkDests_xr02()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load("../../../test/unittestcases/xr02.pdf");
+    QVERIFY( doc );
+
+    std::auto_ptr< Poppler::LinkDestination > dest;
+    dest.reset( doc->linkDestination("section.1") );
+    QVERIFY( isDestinationValid_pageNumber( dest.get(), doc ) );
+    QVERIFY( !isDestinationValid_name( dest.get() ) );
+    dest.reset( doc->linkDestination("section.2") );
+    QVERIFY( isDestinationValid_pageNumber( dest.get(), doc ) );
+    QVERIFY( !isDestinationValid_name( dest.get() ) );
+    dest.reset( doc->linkDestination("section.3") );
+    QVERIFY( !isDestinationValid_pageNumber( dest.get(), doc ) );
+    QVERIFY( isDestinationValid_name( dest.get() ) );
+
+    delete doc;
+}
+
+QTEST_MAIN(TestLinks)
+
+#include "check_links.moc"
commit 174f8087f5e09c5d1915de128b7a15acf47c1e13
Author: Pino Toscano <pino at kde.org>
Date:   Wed May 13 16:44:59 2009 +0200

    [Qt4] set the destination name only when it is not resolved

diff --git a/qt4/src/poppler-link.cc b/qt4/src/poppler-link.cc
index 231c5e3..2507871 100644
--- a/qt4/src/poppler-link.cc
+++ b/qt4/src/poppler-link.cc
@@ -193,15 +193,16 @@ class LinkMoviePrivate : public LinkPrivate
 		bool deleteDest = false;
 		LinkDest *ld = data.ld;
 		
-		if ( data.namedDest )
-		{
-			d->name = QString::fromLatin1( data.namedDest->getCString() );
-		}
 		if ( data.namedDest && !ld )
 		{
 			deleteDest = true;
 			ld = data.doc->doc->findDest( data.namedDest );
 		}
+		// in case this destination was named one, and it was not resolved
+		if ( data.namedDest && !ld )
+		{
+			d->name = QString::fromLatin1( data.namedDest->getCString() );
+		}
 		
 		if (!ld) return;
 		


More information about the poppler mailing list