[poppler] poppler/qt4/src: Makefile.am, 1.7, 1.8 poppler-document.cc, 1.16, 1.17 poppler-link.cc, NONE, 1.1 poppler-page.cc, 1.14, 1.15 poppler-private.h, 1.5, 1.6 poppler-qt4.h, 1.26, 1.27

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Apr 2 11:08:01 PDT 2006


Update of /cvs/poppler/poppler/qt4/src
In directory kemper:/tmp/cvs-serv4977/qt4/src

Modified Files:
	Makefile.am poppler-document.cc poppler-page.cc 
	poppler-private.h poppler-qt4.h 
Added Files:
	poppler-link.cc 
Log Message:
Improvements to the Qt4 frontend, comments welcome


Index: Makefile.am
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Makefile.am	16 Feb 2006 19:28:54 -0000	1.7
+++ Makefile.am	2 Apr 2006 18:07:59 -0000	1.8
@@ -19,6 +19,7 @@
 	poppler-fontinfo.cc			\
 	poppler-embeddedfile.cc			\
 	poppler-textbox.cc			\
+	poppler-link.cc				\
 	../../qt/poppler-page-transition.cc	\
 	poppler-private.h
 

Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-document.cc,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- poppler-document.cc	20 Mar 2006 20:07:36 -0000	1.16
+++ poppler-document.cc	2 Apr 2006 18:07:59 -0000	1.17
@@ -18,19 +18,26 @@
  */
 
 #define UNSTABLE_POPPLER_QT4
-#include <poppler-qt4.h>
-#include <QtCore/QFile>
-#include <QtGui/QImage>
-#include <QtCore/QByteArray>
+
+#include "poppler-qt4.h"
+
+#include <ErrorCodes.h>
 #include <GlobalParams.h>
+#include <Outline.h>
 #include <PDFDoc.h>
+#include <PSOutputDev.h>
+#include <Stream.h>
+#include <UGooString.h>
 #include <Catalog.h>
-#include "UGooString.h"
-#include <ErrorCodes.h>
+
 #include <splash/SplashBitmap.h>
-#include "poppler-private.h"
-#include <Stream.h>
+
 #include <QtCore/QDebug>
+#include <QtCore/QFile>
+#include <QtGui/QImage>
+#include <QtCore/QByteArray>
+
+#include "poppler-private.h"
 
 namespace Poppler {
 
@@ -182,16 +189,6 @@
 
 
     /* borrowed from kpdf */
-    static QString unicodeToQString(Unicode* u, int len) {
-	QString ret;
-	ret.resize(len);
-	QChar* qch = (QChar*) ret.unicode();
-	for (;len;--len)
-	    *qch++ = (QChar) *u++;
-	return ret;
-    }
-
-    /* borrowed from kpdf */
     QString Document::info( const QString & type ) const
     {
 	// [Albert] Code adapted from pdfinfo.cc on xpdf
@@ -371,6 +368,58 @@
     {
 	return (!(0 == m_doc->doc.getCatalog()->numEmbeddedFiles()));
     }
+    
+    QDomDocument *Document::toc() const
+    {
+        Outline * outline = m_doc->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 )
+           m_doc->addTocChildren( toc, toc, items );
+
+        return toc;
+    }
+
+    LinkDestination *Document::linkDestination( const QString &name )
+    {
+        UGooString * namedDest = QStringToUGooString( name );
+        LinkDest * destination = m_doc->doc.findDest( namedDest );
+        if ( destination )
+        {
+            LinkDestinationData ldd(destination, &m_doc->doc);
+            LinkDestination *ld = new LinkDestination(ldd);
+            delete namedDest;
+            return ld;
+        }
+        else return NULL;
+    }
+    
+    bool Document::print(const QString &file, const QList<int> pageList, double hDPI, double vDPI, int rotate)
+    {
+        PSOutputDev *psOut = new PSOutputDev(file.toLatin1().data(), m_doc->doc.getXRef(), m_doc->doc.getCatalog(), 1, m_doc->doc.getNumPages(), psModePS);
+
+        if (psOut->isOk())
+        {
+            foreach(int page, pageList)
+            {
+                m_doc->doc.displayPage(psOut, page, hDPI, vDPI, rotate, gFalse, globalParams->getPSCrop(), gFalse);
+            }
+
+            delete psOut;
+            return true;
+        }
+        else
+        {
+            delete psOut;
+            return false;
+        }
+    }
 
     QDateTime convertDate( char *dateString )
     {

--- NEW FILE: poppler-link.cc ---
/* poppler-page.cc: qt interface to poppler
 * Copyright (C) 2006, Albert Astals Cid
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#define UNSTABLE_POPPLER_QT4

#include <poppler-qt4.h>
#include <poppler-private.h>

#include <QtCore/QStringList>

#include "Link.h"

namespace Poppler {

	LinkDestination::LinkDestination(const LinkDestinationData &data)
	{
		LinkDest *ld = data.ld;
		
		if (ld->getKind() == ::destXYZ) m_kind = destXYZ;
		else if (ld->getKind() == ::destFit) m_kind = destFit;
		else if (ld->getKind() == ::destFitH) m_kind = destFitH;
		else if (ld->getKind() == ::destFitV) m_kind = destFitV;
		else if (ld->getKind() == ::destFitR) m_kind = destFitR;
		else if (ld->getKind() == ::destFitB) m_kind = destFitB;
		else if (ld->getKind() == ::destFitBH) m_kind = destFitBH;
		else if (ld->getKind() == ::destFitBV) m_kind = destFitBV;

		if ( !ld->isPageRef() ) m_pageNum = ld->getPageNum();
		else
		{
			Ref ref = ld->getPageRef();
			m_pageNum = data.doc->findPage( ref.num, ref.gen );
		}
		m_left = ld->getLeft();
		m_bottom = ld->getBottom();
		m_right = ld->getRight();
		m_top = ld->getTop();
		m_zoom = ld->getZoom();
		m_changeLeft = ld->getChangeLeft();
		m_changeTop = ld->getChangeTop();
		m_changeZoom = ld->getChangeZoom();
	}
	
	LinkDestination::LinkDestination(const QString &description)
	{
		QStringList tokens = description.split( ';' );
		m_kind = static_cast<Kind>(tokens.at(0).toInt());
		m_pageNum = tokens.at(1).toInt();
		m_left = tokens.at(2).toDouble();
		m_bottom = tokens.at(3).toDouble();
		m_top = tokens.at(4).toDouble();
		m_zoom = tokens.at(5).toDouble();
		m_changeLeft = static_cast<bool>(tokens.at(6).toInt());
		m_changeTop = static_cast<bool>(tokens.at(7).toInt());
		m_changeZoom = static_cast<bool>(tokens.at(8).toInt());
	}
	
	LinkDestination::Kind LinkDestination::kind() const
	{
		return m_kind;
	}
	
	int LinkDestination::pageNumber() const
	{
		return m_pageNum;
	}
	
	double LinkDestination::left() const
	{
		return m_left;
	}
	
	double LinkDestination::bottom() const
	{
		return m_bottom;
	}
	
	double LinkDestination::right() const
	{
		return m_right;
	}
	
	double LinkDestination::top() const
	{
		return m_top;
	}
	
	double LinkDestination::zoom() const
	{
		return m_zoom;
	}
	
	bool LinkDestination::isChangeLeft() const
	{
		return m_changeLeft;
	}
	
	bool LinkDestination::isChangeTop() const
	{
		return m_changeTop;
	}
	
	bool LinkDestination::isChangeZoom() const
	{
		return m_changeZoom;
	}
	
	QString LinkDestination::toString() const
	{
		QString s = QString::number( (qint8)m_kind );
		s += ";" + QString::number( m_pageNum );
		s += ";" + QString::number( m_left );
		s += ";" + QString::number( m_bottom );
		s += ";" + QString::number( m_right );
		s += ";" + QString::number( m_top );
		s += ";" + QString::number( m_zoom );
		s += ";" + QString::number( (qint8)m_changeLeft );
		s += ";" + QString::number( (qint8)m_changeTop );
		s += ";" + QString::number( (qint8)m_changeZoom );
		return s;
	}

}

Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-page.cc,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- poppler-page.cc	10 Jan 2006 21:57:28 -0000	1.14
+++ poppler-page.cc	2 Apr 2006 18:07:59 -0000	1.15
@@ -194,7 +194,7 @@
     Object o;
     PageTransitionParams params;
     params.dictObj = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1)->getTrans(&o);
-    m_page->transition = new PageTransition(params);
+    if (params.dictObj->isDict()) m_page->transition = new PageTransition(params);
     o.free();
   }
   return m_page->transition;
@@ -235,4 +235,11 @@
   }
 }
 
+void Page::defaultCTM(double *CTM, double dpiX, double dpiY, int rotate, bool upsideDown)
+{
+  ::Page *p;
+  p = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1);
+  p->getDefaultCTM(CTM, dpiX, dpiY, rotate, upsideDown);
+}
+
 }

Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-private.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- poppler-private.h	11 Mar 2006 15:19:02 -0000	1.5
+++ poppler-private.h	2 Apr 2006 18:07:59 -0000	1.6
@@ -1,5 +1,9 @@
 /* poppler-private.h: qt interface to poppler
  * Copyright (C) 2005, Net Integration Technologies, Inc.
+ * Copyright (C) 2006 by Albert Astals Cid <aacid at kde.org>
+ * Inspired on code by
+ * Copyright (C) 2004 by Albert Astals Cid <tsdgeos at terra.es>
+ * Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,13 +20,47 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#include <PDFDoc.h>
 #include <GfxState.h>
+#include <Link.h>
+#include <Outline.h>
+#include <PDFDoc.h>
 #include <FontInfo.h>
 #include <SplashOutputDev.h>
+#include <UGooString.h>
+
+
 
 namespace Poppler {
 
+    /* borrowed from kpdf */
+    static QString unicodeToQString(Unicode* u, int len) {
+	QString ret;
+	ret.resize(len);
+	QChar* qch = (QChar*) ret.unicode();
+	for (;len;--len)
+	    *qch++ = (QChar) *u++;
+	return ret;
+    }
+
+    static UGooString *QStringToUGooString(const QString &s) {
+	int len = s.length();
+	Unicode *u = (Unicode *)gmallocn(s.length(), sizeof(Unicode));
+	for (int i = 0; i < len; ++i)
+		u[i] = s.at(i).unicode();
+	return new UGooString(u, len);
+    }
+
+    class LinkDestinationData
+    {
+        public:
+		LinkDestinationData( LinkDest *l, PDFDoc *pdfdoc ) : ld(l), doc(pdfdoc)
+		{
+		}
+	
+	LinkDest *ld;
+	PDFDoc *doc;
+    };
+
     class DocumentData {
     public:
 	DocumentData(GooString *filePath, GooString *ownerPassword, GooString *userPassword) :
@@ -54,6 +92,61 @@
 		return m_splashOutputDev;
 	}
 	
+	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->isOk() )
+				{
+					LinkDestinationData ldd(destination, &doc);
+					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-qt4.h
===================================================================
RCS file: /cvs/poppler/poppler/qt4/src/poppler-qt4.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- poppler-qt4.h	14 Mar 2006 19:34:10 -0000	1.26
+++ poppler-qt4.h	2 Apr 2006 18:07:59 -0000	1.27
@@ -25,6 +25,7 @@
 #include <QtCore/QByteArray>
 #include <QtCore/QDateTime>
 #include <QtGui/QPixmap>
+#include <QtXml/QDomDocument>
 
 #include <poppler-page-transition.h>
 
@@ -83,14 +84,14 @@
     class FontInfo {
     public:
 	enum Type {
-	    unknown,
-	    Type1,
-	    Type1C,
-	    Type3,
-	    TrueType,
-	    CIDType0,
-	    CIDType0C,
-	    CIDTrueType
+	    unknown = 0,
+	    Type1 = 1,
+	    Type1C = 2,
+	    Type3 = 3,
+	    TrueType = 4,
+	    CIDType0 = 5,
+	    CIDType0C = 6,
+	    CIDTrueType = 7
 	};
 	
 	/**
@@ -356,11 +357,61 @@
 	   The orientation of the page
 	*/
 	Orientation orientation() const;
+	
+	/**
+	  The default CTM
+	*/
+	void defaultCTM(double *CTM, double dpiX, double dpiY, int rotate, bool upsideDown);
+	
     private:
 	Page(const Document *doc, int index);
 	PageData *m_page;
     };
 
+    class LinkDestinationData;
+    
+    class LinkDestination
+    {
+        public:
+            enum Kind
+            {
+                destXYZ = 1,
+                destFit = 2,
+                destFitH = 3,
+                destFitV = 4,
+                destFitR = 5,
+                destFitB = 6,
+                destFitBH = 7,
+                destFitBV = 8
+            };
+
+            LinkDestination(const LinkDestinationData &data);
+            LinkDestination(const QString &description);
+
+            // Accessors.
+            Kind kind() const;
+            int pageNumber() const;
+            double left() const;
+            double bottom() const;
+            double right() const;
+            double top() const;
+            double zoom() const;
+            bool isChangeLeft() const;
+            bool isChangeTop() const;
+            bool isChangeZoom() const;
+
+            QString toString() const;
+
+        private:
+            Kind m_kind; // destination type
+            int m_pageNum; // page number
+            double m_left, m_bottom; // position
+            double m_right, m_top;
+            double m_zoom; // zoom factor
+            bool m_changeLeft, m_changeTop; // for destXYZ links, which position
+            bool m_changeZoom; //   components to change
+    };
+
     class DocumentData;
 
 /**
@@ -615,6 +666,25 @@
 	   Whether there are any documents embedded in this PDF document.
 	*/
 	bool hasEmbeddedFiles() 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 );
+	
+	bool print(const QString &fileName, const QList<int> pageList, double hDPI, double vDPI, int rotate);
 
 	~Document();
   



More information about the poppler mailing list