Hi,

the attached patch adds table of contents support the the Qt3 bindings.
It is a direct port of the equivalent Qt4 code.

Greetings,
Wilfried Huss
Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-document.cc,v
retrieving revision 1.11
diff -u -b -r1.11 poppler-document.cc
--- poppler-document.cc	25 Jun 2006 16:59:31 -0000	1.11
+++ poppler-document.cc	26 Jul 2006 15:32:43 -0000
@@ -20,6 +20,7 @@
 #include <qfile.h>
 #include <qimage.h>
 #include <GlobalParams.h>
+#include <Outline.h>
 #include <PDFDoc.h>
 #include <PSOutputDev.h>
 #include <Catalog.h>
@@ -284,6 +285,23 @@
   return data->doc.getPDFVersion();
 }
 
+QDomDocument *Document::toc() const
+{
+  Outline * outline = data->doc.getOutline();
+  if ( !outline )
+    return NULL;
+
+  GooList * items = outline->getItems();
+  if ( !items || items->getLength() < 1 )
+    return NULL;
+
+  QDomDocument *toc = new QDomDocument();
+  if ( items->getLength() > 0 )
+    data->addTocChildren( toc, toc, items );
+
+  return toc;
+}
+
 LinkDestination *Document::linkDestination( const QString &name )
 {
   UGooString * namedDest = QStringToUGooString( name );
Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-private.h,v
retrieving revision 1.7
diff -u -b -r1.7 poppler-private.h
--- poppler-private.h	25 Jun 2006 10:29:22 -0000	1.7
+++ poppler-private.h	26 Jul 2006 15:32:43 -0000
@@ -16,7 +16,10 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <qdom.h>
+
 #include <Object.h>
+#include <Outline.h>
 #include <SplashOutputDev.h>
 #include <Link.h>
 #include <PDFDoc.h>
@@ -78,6 +81,61 @@
         return m_outputDev;
     }
 
+    void addTocChildren( QDomDocument * docSyn, QDomNode * parent, GooList * items )
+    {
+        int numItems = items->getLength();
+        for ( int i = 0; i < numItems; ++i )
+        {
+            // iterate over every object in 'items'
+            OutlineItem * outlineItem = (OutlineItem *)items->get( i );
+
+            // 1. create element using outlineItem's title as tagName
+            QString name;
+            Unicode * uniChar = outlineItem->getTitle();
+            int titleLength = outlineItem->getTitleLength();
+            name = unicodeToQString(uniChar, titleLength);
+            if ( name.isEmpty() )
+                continue;
+
+            QDomElement item = docSyn->createElement( name );
+            parent->appendChild( item );
+
+            // 2. find the page the link refers to
+            ::LinkAction * a = outlineItem->getAction();
+            if ( a && ( a->getKind() == actionGoTo || a->getKind() == actionGoToR ) )
+            {
+                // page number is contained/referenced in a LinkGoTo
+                LinkGoTo * g = static_cast< LinkGoTo * >( a );
+                LinkDest * destination = g->getDest();
+                if ( !destination && g->getNamedDest() )
+                {
+                    // no 'destination' but an internal 'named reference'. we could
+                    // get the destination for the page now, but it's VERY time consuming,
+                    // so better storing the reference and provide the viewport on demand
+                    UGooString *s = g->getNamedDest();
+                    QString aux = unicodeToQString( s->unicode(), s->getLength() );
+                    item.setAttribute( "DestinationName", aux );
+                }
+                else if ( destination && destination->isOk() )
+                {
+                    LinkDestinationData ldd(destination, NULL, this);
+                    item.setAttribute( "Destination", LinkDestination(ldd).toString() );
+                }
+                if ( a->getKind() == actionGoToR )
+                {
+                    LinkGoToR * g2 = static_cast< LinkGoToR * >( a );
+                    item.setAttribute( "ExternalFileName", g2->getFileName()->getCString() );
+                }
+            }
+
+            // 3. recursively descend over children
+            outlineItem->open();
+            GooList * children = outlineItem->getKids();
+            if ( children )
+                addTocChildren( docSyn, &item, children );
+        }
+    }
+
   class PDFDoc doc;
   bool locked;
   FontInfoScanner *m_fontInfoScanner;
Index: poppler-qt.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-qt.h,v
retrieving revision 1.20
diff -u -b -r1.20 poppler-qt.h
--- poppler-qt.h	25 Jun 2006 16:59:31 -0000	1.20
+++ poppler-qt.h	26 Jul 2006 15:32:43 -0000
@@ -22,6 +22,7 @@
 
 #include <qcstring.h>
 #include <qdatetime.h>
+#include <qdom.h>
 #include <qpixmap.h>
 
 #include <poppler-link-qt3.h>
@@ -262,6 +263,21 @@
   */
   bool scanForFonts( int numPages, QValueList<FontInfo> *fontList ) const;
 
+  /**
+    Gets the TOC of the Document, it is application responsabiliy to delete
+    it when no longer needed
+
+    * In the tree the tag name is the 'screen' name of the entry. A tag can have
+    * attributes. Here follows the list of tag attributes with meaning:
+    * - Destination: A string description of the referred destination
+    * - DestinationName: A 'named reference' to the viewport that must be converted
+    *      using linkDestination( *destination_name* )
+    * - ExternalFileName: A link to a external filename
+
+     \returns NULL if the Document does not have TOC
+  */
+  QDomDocument *toc() const;
+
   LinkDestination *linkDestination( const QString &name );
 
   ~Document();
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to