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

List:       kde-commits
Subject:    KDE/kdegraphics/kviewshell/plugins/pdf
From:       Wilfried Huss <Wilfried.Huss () gmx ! at>
Date:       2006-07-26 10:36:26
Message-ID: 1153910186.279813.5639.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 566490 by whuss:

Add table of contents support for PDF files.

 M  +76 -0     pdfRenderer.cpp  
 M  +3 -0      pdfRenderer.h  


--- trunk/KDE/kdegraphics/kviewshell/plugins/pdf/pdfRenderer.cpp #566489:566490
@@ -35,6 +35,7 @@
 #include <kvbox.h>
 
 #include <QCheckBox>
+#include <QDomDocument>
 #include <QFileInfo>
 #include <QLayout>
 #include <QLabel>
@@ -368,6 +369,9 @@
   // Store path to current file
   path = fi.absolutePath();
 
+  // Build the table of contents
+  getOutline();
+  
   // Load pdfsync file if available
   QString pdfsync_filename = path + "/" + fi.baseName() + ".pdfsync";
   kDebug(kvs::pdf) << "search for pdfsync file " << pdfsync_filename << endl;
@@ -399,6 +403,78 @@
 }
 
 
+void PdfRenderer::getOutline()
+{
+  if (document == 0)
+    return;
+
+  bookmarks.clear();
+
+  QDomDocument* toc = document->toc();
+
+  // not all documents have a table of content
+  if (!toc)
+    return;
+
+  //kDebug() << toc->toString() << endl;
+  
+  QDomElement root = toc->documentElement();
+
+  QDomNode topLevelNode = root;
+  while (topLevelNode.isElement())
+  {
+    QString name = topLevelNode.toElement().tagName();
+    QString destinationName = topLevelNode.toElement().attribute("DestinationName"); 
+    Poppler::LinkDestination* destination = document->linkDestination(destinationName);
+
+    int pageNumber = 1;
+    if (destination)
+    {
+      pageNumber = destination->pageNumber();
+    }
+ 
+    Bookmark* bookmarkEntry = new Bookmark(name, pageNumber, Length());
+    bookmarks.append(bookmarkEntry);
+
+    getOutlineSub(&topLevelNode, bookmarkEntry);
+    
+    topLevelNode = topLevelNode.nextSibling();
+  }
+
+  delete toc;
+}
+
+
+void PdfRenderer::getOutlineSub(QDomNode* tocParent, Bookmark* bookmarkParent)
+{
+  if (!tocParent || !bookmarkParent)
+    return;
+
+  QDomNode n = tocParent->firstChild();
+  while (n.isElement())
+  {
+    QDomElement e = n.toElement();
+    QString name = e.tagName();
+    QString destinationName = e.attribute("DestinationName"); 
+    
+    Poppler::LinkDestination* destination = document->linkDestination(destinationName);
+    int pageNumber = 1;
+    if (destination)
+    {
+      pageNumber = destination->pageNumber();
+    }
+ 
+    Bookmark* bookmarkEntry = new Bookmark(name, pageNumber, Length());
+
+    bookmarkParent->subordinateBookmarks.append(bookmarkEntry);
+    
+    getOutlineSub(&n, bookmarkEntry);
+
+    n = n.nextSibling();
+  }
+}
+
+
 void PdfRenderer::clear(void)
 {
   DocumentRenderer::clear();
--- trunk/KDE/kdegraphics/kviewshell/plugins/pdf/pdfRenderer.h #566489:566490
@@ -185,6 +185,9 @@
 private:
   void fillInText(RenderedDocumentPagePixmap* page, Poppler::Page* pdfPage, double res);
 
+  void getOutline();
+  void getOutlineSub(QDomNode* tocParent, Bookmark* bookmarkParent);
+	  
   bool parsePdfSync(QString basename, QTextStream& stream);
 
   KShellProcess* proc;
[prev in list] [next in list] [prev in thread] [next in thread] 

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