[poppler] poppler/qt: poppler-document.cc, 1.11,
1.12 poppler-private.h, 1.7, 1.8 poppler-qt.h, 1.20, 1.21
Albert Astals Cid
aacid at kemper.freedesktop.org
Wed Jul 26 11:16:03 PDT 2006
Update of /cvs/poppler/poppler/qt
In directory kemper:/tmp/cvs-serv10450/qt
Modified Files:
poppler-document.cc poppler-private.h poppler-qt.h
Log Message:
2006-07-26 Albert Astals Cid <aacid at kde.org>
* qt/poppler-document.cc:
* qt/poppler-private.h:
* qt/poppler-qt.h: Port the QDomDocument *Document::toc() const method
from the qt4 frontend to the qt frontend. Patch by Wilfried Huss
Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-document.cc,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- poppler-document.cc 25 Jun 2006 16:59:31 -0000 1.11
+++ poppler-document.cc 26 Jul 2006 18:16:01 -0000 1.12
@@ -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
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- poppler-private.h 25 Jun 2006 10:29:22 -0000 1.7
+++ poppler-private.h 26 Jul 2006 18:16:01 -0000 1.8
@@ -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
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- poppler-qt.h 25 Jun 2006 16:59:31 -0000 1.20
+++ poppler-qt.h 26 Jul 2006 18:16:01 -0000 1.21
@@ -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();
More information about the poppler
mailing list